diff --git a/Makefile b/Makefile index 89574e9..963ecf0 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,8 @@ all: test CC?=clang LD?=wasm-ld +AR?=llvm-ar +RANLIB?=llvm-ranlib JS?=node .PHONY: test @@ -15,6 +17,10 @@ test: test.js test.wasm test.wasm: test.o walloc.o $(LD) --no-entry --import-memory -o $@ $^ +libwalloc.a: walloc.o + $(AR) rc $@ $< + $(RANLIB) $@ + .PHONY: clean clean: - rm -f *.o *.wasm + rm -f *.o *.a *.wasm diff --git a/walloc.c b/walloc.c index 1f12357..5760c0e 100644 --- a/walloc.c +++ b/walloc.c @@ -38,9 +38,13 @@ typedef __UINT8_TYPE__ uint8_t; static inline size_t max(size_t a, size_t b) { return a < b ? b : a; } +#if __has_constexpr_builtin(__builtin_align_up) +#define align __builtin_align_up +#else static inline uintptr_t align(uintptr_t val, uintptr_t alignment) { return (val + alignment - 1) & ~(alignment - 1); } +#endif #define ASSERT_ALIGNED(x, y) ASSERT((x) == align((x), y)) #define CHUNK_SIZE 256