From 75fb24e369bbf932872c5f1abe84cf6d648983f1 Mon Sep 17 00:00:00 2001 From: Victor Olin Date: Tue, 21 Mar 2023 13:09:14 +0100 Subject: [PATCH] Fixed GC static library --- .gitignore | 4 +++- src/GC/Makefile | 19 ++++++++++++++++++- src/GC/include/profiler.hpp | 1 - src/GC/lib/event.cpp | 1 - src/GC/lib/profiler.cpp | 7 +++---- src/GC/tests/extern_lib.cpp | 3 +++ 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 9f824a0..0b0f588 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ llvm.ll src/GC/lib/*.o src/GC/lib/*.so -src/GC/tests/*.out \ No newline at end of file +src/GC/lib/*.a +src/GC/tests/*.out +src/GC/tests/logs \ No newline at end of file diff --git a/src/GC/Makefile b/src/GC/Makefile index 8ce942b..1c82023 100644 --- a/src/GC/Makefile +++ b/src/GC/Makefile @@ -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 extern_lib: +# remove old files 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) -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) $(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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/src/GC/include/profiler.hpp b/src/GC/include/profiler.hpp index ebfd77a..bdf287c 100644 --- a/src/GC/include/profiler.hpp +++ b/src/GC/include/profiler.hpp @@ -4,7 +4,6 @@ #include "chunk.hpp" #include "event.hpp" -#include "heap.hpp" namespace GC { diff --git a/src/GC/lib/event.cpp b/src/GC/lib/event.cpp index 40ab185..9fd01d7 100644 --- a/src/GC/lib/event.cpp +++ b/src/GC/lib/event.cpp @@ -4,7 +4,6 @@ #include "chunk.hpp" #include "event.hpp" -#include "heap.hpp" namespace GC { diff --git a/src/GC/lib/profiler.cpp b/src/GC/lib/profiler.cpp index 1b09fb2..6af632d 100644 --- a/src/GC/lib/profiler.cpp +++ b/src/GC/lib/profiler.cpp @@ -9,7 +9,6 @@ #include "chunk.hpp" #include "event.hpp" -#include "heap.hpp" #include "profiler.hpp" namespace GC @@ -69,7 +68,7 @@ namespace GC << "\n Size: " << chunk->size << "\n Mark: " << chunk->marked; } - fstr << "--------------------------------\n" << std::endl; + fstr << "\n--------------------------------" << std::endl; } } @@ -101,7 +100,7 @@ namespace GC return fstr; } - std::string get_log_folder() + std::string Profiler::get_log_folder() { char buffer[1024]; // chars read from path @@ -122,6 +121,6 @@ namespace GC size_t last_slash = path.find_last_of('/'); std::string folder = path.substr(0, last_slash); - return folder; + return folder + "/logs"; } } \ No newline at end of file diff --git a/src/GC/tests/extern_lib.cpp b/src/GC/tests/extern_lib.cpp index 6c80c32..ef99130 100644 --- a/src/GC/tests/extern_lib.cpp +++ b/src/GC/tests/extern_lib.cpp @@ -14,6 +14,8 @@ int main() { init_gc(heap); frame_test(heap); + heap->dispose(); + return 0; } @@ -52,6 +54,7 @@ void init_gc(GC::Heap *heap){ std::cout << "\n\n INITIALIZING THE HEAP" << std::endl; std::cout << "===========================" << std::endl; heap->init(); + heap->set_profiler(true); std::cout << "===========================" << std::endl; }