matter.c

Cross-platform minimalist libc
git clone git://git.finwo.net/lib/matter.c
Log | Files | Refs | README | LICENSE

commit 7a69b58f612e296d4bb562780cda8629f09ae032
parent 088fc3afdcb26c9901daa9a26fb4b203dc262f40
Author: Yersa Nordman <finwo@pm.me>
Date:   Thu, 21 May 2020 23:36:49 +0200

Prepared for multiple targets

Diffstat:
MMakefile | 15+++++----------
Aarch/wasm32/config.mk | 3+++
Rsrc/malloc/malloc.c -> arch/wasm32/malloc/malloc.c | 0
Dsrc/arch/wasm/malloc | 2--
Dsrc/arch/wasm/string | 2--
Dsrc/arch/wasm32 | 2--
Dsrc/arch/wasm64 | 2--
Msrc/string/memcmp.c | 9+++++----
Msrc/string/memcpy.c | 6+++---
9 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,22 +1,17 @@ - TARGET ?= wasm32 -AR_wasm=llvm-ar -AR_wasm32=${AR_wasm} -AR_wasm64=${AR_wasm} - -AR=${AR_${TARGET}} +include arch/$(TARGET)/config.mk -SRC=$(shell find -L src/arch/$(TARGET) -type f -name *.c) +SRC=$(shell find -L arch/$(TARGET) -type f -name *.c) +SRC+=$(shell find -L src -type f -name *.c) OBJ=$(SRC:.c=.o) libmatter.a: $(OBJ) $(AR) -cvq libmatter.a $(OBJ) %.o: %.c - clang -Os -S -emit-llvm $(CFLAGS) --target=$(TARGET) -nostdinc -fno-builtin -Iinclude -c $< -o $(@:.o=.ll) - llc -march=$(TARGET) -filetype=obj -O3 $(@:.o=.ll) - + $(LLE) -Os -S $(CFLAGS) -nostdinc -fno-builtin -Iinclude -c $< -o $(@:.o=.ll) + $(LLC) -filetype=obj -O3 $(@:.o=.ll) .PHONY: clean clean: diff --git a/arch/wasm32/config.mk b/arch/wasm32/config.mk @@ -0,0 +1,3 @@ +LLE=clang -emit-llvm --target=wasm32 +LLC=llc -march=wasm32 +AR=llvm-ar diff --git a/src/malloc/malloc.c b/arch/wasm32/malloc/malloc.c diff --git a/src/arch/wasm/malloc b/src/arch/wasm/malloc @@ -1 +0,0 @@ -../../malloc -\ No newline at end of file diff --git a/src/arch/wasm/string b/src/arch/wasm/string @@ -1 +0,0 @@ -../../string -\ No newline at end of file diff --git a/src/arch/wasm32 b/src/arch/wasm32 @@ -1 +0,0 @@ -wasm -\ No newline at end of file diff --git a/src/arch/wasm64 b/src/arch/wasm64 @@ -1 +0,0 @@ -wasm -\ No newline at end of file diff --git a/src/string/memcmp.c b/src/string/memcmp.c @@ -7,11 +7,12 @@ int memcmp (const void *str1, const void *str2, int count) { const unsigned char *s1 = str1; const unsigned char *s2 = str2; - while (count-- > 0) - { - if (*s1++ != *s2++) + while (count-- > 0) { + if (*s1++ != *s2++) { return s1[-1] < s2[-1] ? -1 : 1; - } + } + } + return 0; } diff --git a/src/string/memcpy.c b/src/string/memcpy.c @@ -3,12 +3,12 @@ #include <string.h> -void * memcpy (void *dest, const void *src, int len) -{ +void * memcpy (void *dest, const void *src, int len) { char *d = dest; const char *s = src; - while (len--) + while (len--) { *d++ = *s++; + } return dest; }