Merge branch 'g-collection' of https://github.com/bachelor-group-66-systemf/language into g-collection
This commit is contained in:
commit
cdca49354a
5 changed files with 87 additions and 35 deletions
|
|
@ -66,9 +66,9 @@ static_lib:
|
||||||
# remove old files
|
# remove old files
|
||||||
rm -f lib/event.o lib/profiler.o lib/heap.o lib/gcoll.a tests/extern_lib.out
|
rm -f lib/event.o lib/profiler.o lib/heap.o lib/gcoll.a tests/extern_lib.out
|
||||||
# compile object files
|
# compile object files
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/event.o lib/event.cpp -fPIC
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -c -o lib/event.o lib/event.cpp -fPIC
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/profiler.o lib/profiler.cpp -fPIC
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -c -o lib/profiler.o lib/profiler.cpp -fPIC
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/heap.o lib/heap.cpp -fPIC
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -c -o lib/heap.o lib/heap.cpp -fPIC
|
||||||
# create static library
|
# create static library
|
||||||
ar r lib/gcoll.a lib/event.o lib/profiler.o lib/heap.o
|
ar r lib/gcoll.a lib/event.o lib/profiler.o lib/heap.o
|
||||||
|
|
||||||
|
|
@ -76,13 +76,15 @@ static_lib:
|
||||||
static_lib_test: static_lib
|
static_lib_test: static_lib
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/extern_lib.out tests/extern_lib.cpp lib/gcoll.a
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/extern_lib.out tests/extern_lib.cpp lib/gcoll.a
|
||||||
|
|
||||||
static_lib_c:
|
wrapper:
|
||||||
# remove old files
|
# remove old files
|
||||||
rm -f lib/event.o lib/profiler.o lib/heap.o lib/gcoll.a tests/extern_lib.out
|
rm -f lib/event.o lib/profiler.o lib/heap.o lib/coll.a tests/wrapper.out
|
||||||
# compile object files
|
# compile object files
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/event.o lib/event.cpp -fPIC
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -c -o lib/event.o lib/event.cpp -fPIC
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/profiler.o lib/profiler.cpp -fPIC
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -c -o lib/profiler.o lib/profiler.cpp -fPIC
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/heap.o lib/heap.cpp -fPIC
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -c -o lib/heap.o lib/heap.cpp -fPIC
|
||||||
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/cheap.o lib/cheap.cpp -fPIC
|
$(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -c -o lib/cheap.o lib/cheap.cpp -fPIC
|
||||||
# create static library
|
# compile object files into library
|
||||||
ar r lib/gcoll.a lib/event.o lib/profiler.o lib/heap.o
|
ar rcs lib/gcoll.a lib/event.o lib/profiler.o lib/heap.o lib/cheap.o
|
||||||
|
# compile test program wrapper.c with normal clang
|
||||||
|
clang -stdlib=libc++ $(WFLAGS) $(LIB_INCL) -o tests/wrapper.out tests/wrapper.c lib/gcoll.a -lstdc++
|
||||||
|
|
|
||||||
40
src/GC/docs/lib/cheap.md
Normal file
40
src/GC/docs/lib/cheap.md
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
# cheap.h & cheap.cpp
|
||||||
|
|
||||||
|
A wrapper interface for the class `GC::Heap` for easier use
|
||||||
|
in LLVM (no nasty namespaces). This interface is relatively
|
||||||
|
straight-forward and only defines functions to use the already
|
||||||
|
public functions in the class `GC::Heap`.
|
||||||
|
|
||||||
|
The functions are declared in a normal C-style header and
|
||||||
|
defined as "pure" C-functions. Because the public functions
|
||||||
|
exposed in `GC::Heap` are static, some of the functions
|
||||||
|
just call the static functions but are wrapped as C-functions.
|
||||||
|
|
||||||
|
For the non-static function `GC::Heap::set_profiler()` and the
|
||||||
|
singleton get-instance function `GC::Heap::the()` a struct
|
||||||
|
is used to encapsulate the heap-object. If this library is
|
||||||
|
compiled with `DEBUG` defined a struct is typedef-ed and
|
||||||
|
can be used everywhere, otherwise this struct is opaque
|
||||||
|
and cannot be used explicitly. This struct only contains
|
||||||
|
a pointer to the heap instance and is called `cheap_t`.
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
`cheap_t *cheap_the()`: Returns an encapsulated singleton
|
||||||
|
instance. It is encapsulated in an opaque struct as the
|
||||||
|
instance itself is not meant to be used outside the C++
|
||||||
|
library.
|
||||||
|
|
||||||
|
`void cheap_init()`: Simply calls the `Heap::init()`
|
||||||
|
function.
|
||||||
|
|
||||||
|
`void cheap_dispose()`: Only calls the `Heap::dispose()`
|
||||||
|
function.
|
||||||
|
|
||||||
|
`void *cheap_alloc(unsigned long size)`: Calls `Heap::alloc(size_t size)`
|
||||||
|
and returns whatever `alloc` returns.
|
||||||
|
|
||||||
|
`void cheap_set_profiler(cheap_t *cheap, bool mode)`:
|
||||||
|
The argument `cheap` is the encapsulated Heap singleton instance.
|
||||||
|
`mode` is the same as for `Heap::set_profiler(bool mode)`.
|
||||||
|
|
||||||
|
For more documentation on functionality, see `src/GC/docs/lib/heap.md`.
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEBUG
|
// #define DEBUG
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
typedef struct cheap
|
typedef struct cheap
|
||||||
|
|
@ -19,11 +19,11 @@ struct cheap;
|
||||||
typedef struct cheap cheap_t;
|
typedef struct cheap cheap_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cheap_t *cheap_the() noexcept;
|
cheap_t *cheap_the();
|
||||||
void cheap_init() noexcept;
|
void cheap_init();
|
||||||
void cheap_dispose() noexcept;
|
void cheap_dispose();
|
||||||
void *cheap_alloc(unsigned long size) noexcept;
|
void *cheap_alloc(unsigned long size);
|
||||||
void cheap_set_profiler(cheap_t *cheap, bool mode) noexcept;
|
void cheap_set_profiler(cheap_t *cheap, bool mode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "heap.hpp"
|
#include "heap.hpp"
|
||||||
#include "cheap.h"
|
#include "cheap.h"
|
||||||
|
|
||||||
|
#ifndef DEBUG
|
||||||
struct cheap
|
struct cheap
|
||||||
{
|
{
|
||||||
void *obj;
|
void *obj;
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
cheap_t *cheap_the()
|
cheap_t *cheap_the()
|
||||||
{
|
{
|
||||||
|
|
@ -27,7 +30,9 @@ void cheap_init()
|
||||||
|
|
||||||
void cheap_dispose()
|
void cheap_dispose()
|
||||||
{
|
{
|
||||||
|
std::cout << "In dispose\n";
|
||||||
GC::Heap::dispose();
|
GC::Heap::dispose();
|
||||||
|
std::cout << "Out dispose" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *cheap_alloc(unsigned long size)
|
void *cheap_alloc(unsigned long size)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "cheap.h"
|
#include "cheap.h"
|
||||||
|
|
||||||
|
|
@ -18,23 +19,25 @@ void test_init()
|
||||||
printf("----- EXIT TEST_INIT --------------------------\n");
|
printf("----- EXIT TEST_INIT --------------------------\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
cheap_t *test_the()
|
/* Uncomment ONLY if run with DEBUG defined in cheap.h */
|
||||||
{
|
|
||||||
printf("----- IN TEST_THE -----------------------------\n");
|
|
||||||
|
|
||||||
cheap_t *fst_heap = cheap_the();
|
// cheap_t *test_the()
|
||||||
|
// {
|
||||||
|
// printf("----- IN TEST_THE -----------------------------\n");
|
||||||
|
|
||||||
printf("Heap 1:\t%p\n", fst_heap->obj);
|
// cheap_t *fst_heap = cheap_the();
|
||||||
|
|
||||||
cheap_t *snd_heap = cheap_the();
|
// printf("Heap 1:\t%p\n", fst_heap->obj);
|
||||||
|
|
||||||
printf("Heap 2:\t%p\n", snd_heap->obj);
|
// cheap_t *snd_heap = cheap_the();
|
||||||
|
|
||||||
printf("----- EXIT TEST_THE ---------------------------\n");
|
// printf("Heap 2:\t%p\n", snd_heap->obj);
|
||||||
|
|
||||||
free(snd_heap);
|
// printf("----- EXIT TEST_THE ---------------------------\n");
|
||||||
return fst_heap;
|
|
||||||
}
|
// free(snd_heap);
|
||||||
|
// return fst_heap;
|
||||||
|
// }
|
||||||
|
|
||||||
void test_profiler(cheap_t *heap)
|
void test_profiler(cheap_t *heap)
|
||||||
{
|
{
|
||||||
|
|
@ -71,20 +74,22 @@ void test_dispose()
|
||||||
printf("----- EXIT TEST_DISPOSE -----------------------\n");
|
printf("----- EXIT TEST_DISPOSE -----------------------\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main()
|
||||||
{
|
{
|
||||||
test_init();
|
test_init();
|
||||||
|
|
||||||
cheap_t *heap = test_the();
|
/* Uncomment ONLY if run with DEBUG defined in cheap.h */
|
||||||
|
// cheap_t *heap = test_the();
|
||||||
test_profiler(heap);
|
// test_profiler(heap);
|
||||||
|
|
||||||
Object *o = test_alloc();
|
Object *o = test_alloc();
|
||||||
|
printf("Object size: %lu\n", sizeof(Object));
|
||||||
printf("Object:\n\tx: %d\n\ty: %d\n\tz: %d\n\tvel: %f\n", o->x, o->y, o->z, o->velocity);
|
printf("Object:\n\tx: %d\n\ty: %d\n\tz: %d\n\tvel: %f\n", o->x, o->y, o->z, o->velocity);
|
||||||
|
|
||||||
test_dispose();
|
test_dispose();
|
||||||
|
|
||||||
free(heap);
|
/* Sefault I don't understand, don't uncomment */
|
||||||
free(o);
|
// free(heap);
|
||||||
|
// free(o);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue