Fixed GC static library

This commit is contained in:
Victor Olin 2023-03-21 13:09:14 +01:00
parent bba6afeff8
commit 75fb24e369
6 changed files with 27 additions and 8 deletions

2
.gitignore vendored
View file

@ -11,4 +11,6 @@ llvm.ll
src/GC/lib/*.o src/GC/lib/*.o
src/GC/lib/*.so src/GC/lib/*.so
src/GC/lib/*.a
src/GC/tests/*.out src/GC/tests/*.out
src/GC/tests/logs

View file

@ -43,9 +43,26 @@ game:
$(CC) $(WFLAGS) $(STDFLAGS) $(LIB_INCL) tests/game.cpp lib/heap.cpp lib/profiler.cpp lib/event.cpp -o tests/game.out $(CC) $(WFLAGS) $(STDFLAGS) $(LIB_INCL) tests/game.cpp lib/heap.cpp lib/profiler.cpp lib/event.cpp -o tests/game.out
extern_lib: extern_lib:
# remove old files
rm -f lib/heap.o lib/libheap.so tests/extern_lib.out rm -f lib/heap.o lib/libheap.so tests/extern_lib.out
# compile heap to object file
$(CC) $(STDFLAGS) -c -fPIC -o lib/heap.o lib/heap.cpp $(CC) $(STDFLAGS) -c -fPIC -o lib/heap.o lib/heap.cpp
$(CC) $(STDFLAGS) -shared -o lib/libheap.so lib/heap.o $(CC) $(STDFLAGS) -shared -o lib/libheap.so lib/heap.o
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -v tests/extern_lib.cpp lib/heap.cpp -o tests/extern_lib.out $(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -v tests/extern_lib.cpp lib/heap.cpp -o tests/extern_lib.out
$(CC) $(STDFLAGS) $(LIB_INCL) $(LIB_SO) -v -Wall -o tests/extern_lib.out tests/extern_lib.cpp -lheap $(CC) $(STDFLAGS) $(LIB_INCL) $(LIB_SO) -v -Wall -o tests/extern_lib.out tests/extern_lib.cpp -lheap
LD_LIBRARY_PATH=$(LIB_LINK) tests/extern_lib.out LD_LIBRARY_PATH=$(LIB_LINK) tests/extern_lib.out
static_lib:
# remove old files
rm -f lib/event.o lib/profiler.o lib/heap.o lib/gcoll.a tests/extern_lib.out
# compile object files
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -c -o lib/event.o lib/event.cpp -fPIC
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -c -o lib/profiler.o lib/profiler.cpp -fPIC
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -c -o lib/heap.o lib/heap.cpp -fPIC
# create static library
ar r lib/gcoll.a lib/event.o lib/profiler.o lib/heap.o
# create test program
static_lib_test: static_lib
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/extern_lib.out tests/extern_lib.cpp lib/gcoll.a

View file

@ -4,7 +4,6 @@
#include "chunk.hpp" #include "chunk.hpp"
#include "event.hpp" #include "event.hpp"
#include "heap.hpp"
namespace GC { namespace GC {

View file

@ -4,7 +4,6 @@
#include "chunk.hpp" #include "chunk.hpp"
#include "event.hpp" #include "event.hpp"
#include "heap.hpp"
namespace GC namespace GC
{ {

View file

@ -9,7 +9,6 @@
#include "chunk.hpp" #include "chunk.hpp"
#include "event.hpp" #include "event.hpp"
#include "heap.hpp"
#include "profiler.hpp" #include "profiler.hpp"
namespace GC namespace GC
@ -69,7 +68,7 @@ namespace GC
<< "\n Size: " << chunk->size << "\n Size: " << chunk->size
<< "\n Mark: " << chunk->marked; << "\n Mark: " << chunk->marked;
} }
fstr << "--------------------------------\n" << std::endl; fstr << "\n--------------------------------" << std::endl;
} }
} }
@ -101,7 +100,7 @@ namespace GC
return fstr; return fstr;
} }
std::string get_log_folder() std::string Profiler::get_log_folder()
{ {
char buffer[1024]; char buffer[1024];
// chars read from path // chars read from path
@ -122,6 +121,6 @@ namespace GC
size_t last_slash = path.find_last_of('/'); size_t last_slash = path.find_last_of('/');
std::string folder = path.substr(0, last_slash); std::string folder = path.substr(0, last_slash);
return folder; return folder + "/logs";
} }
} }

View file

@ -14,6 +14,8 @@ int main() {
init_gc(heap); init_gc(heap);
frame_test(heap); frame_test(heap);
heap->dispose();
return 0; return 0;
} }
@ -52,6 +54,7 @@ void init_gc(GC::Heap *heap){
std::cout << "\n\n INITIALIZING THE HEAP" << std::endl; std::cout << "\n\n INITIALIZING THE HEAP" << std::endl;
std::cout << "===========================" << std::endl; std::cout << "===========================" << std::endl;
heap->init(); heap->init();
heap->set_profiler(true);
std::cout << "===========================" << std::endl; std::cout << "===========================" << std::endl;
} }