From ae0fda3384acfbaeda11bd62ef8c073aeee5afaf Mon Sep 17 00:00:00 2001 From: overflowerror Date: Wed, 5 May 2021 22:45:22 +0200 Subject: [PATCH] restructure; added marshaller to root tree --- .gitignore | 8 ++- Makefile | 79 +++++++++++++-------- {marshaller/demo => demo}/demo.h | 0 src/demo.c => demo/json.c | 0 marshaller/demo/demo.c => demo/marshaller.c | 0 marshaller/Makefile | 24 ------- marshaller/{src => }/codegen.c | 0 marshaller/{src => }/codegen.h | 0 marshaller/{src => }/helper.h | 0 marshaller/{src => }/parser.y | 2 + marshaller/{src => }/scanner.l | 0 {marshaller/lib => src}/marshaller.c | 3 +- {marshaller/lib => src}/marshaller.h | 0 src/test.c => test/json.c | 2 +- marshaller/test/test.c => test/marshaller.c | 0 {marshaller/test => test}/test1.h | 0 {marshaller/test => test}/test2.h | 0 17 files changed, 59 insertions(+), 59 deletions(-) rename {marshaller/demo => demo}/demo.h (100%) rename src/demo.c => demo/json.c (100%) rename marshaller/demo/demo.c => demo/marshaller.c (100%) delete mode 100644 marshaller/Makefile rename marshaller/{src => }/codegen.c (100%) rename marshaller/{src => }/codegen.h (100%) rename marshaller/{src => }/helper.h (100%) rename marshaller/{src => }/parser.y (99%) rename marshaller/{src => }/scanner.l (100%) rename {marshaller/lib => src}/marshaller.c (99%) rename {marshaller/lib => src}/marshaller.h (100%) rename src/test.c => test/json.c (99%) rename marshaller/test/test.c => test/marshaller.c (100%) rename {marshaller/test => test}/test1.h (100%) rename {marshaller/test => test}/test2.h (100%) diff --git a/.gitignore b/.gitignore index b7a7964..529d259 100644 --- a/.gitignore +++ b/.gitignore @@ -51,5 +51,11 @@ Module.symvers Mkfile.old dkms.conf -demo +json-demo marshaller-demo +json-test +marshaller-test +marshaller-gen + +gen/** +obj/** diff --git a/Makefile b/Makefile index 040f555..e835228 100644 --- a/Makefile +++ b/Makefile @@ -5,17 +5,23 @@ LDFLAGS = AR = ar ARFLAGS = rcs -BIN_NAME = demo +LEX = flex +YACC = bison +YFLAGS = -y -d + +MARSHALLER_GEN = marshaller-gen + A_LIB_NAME = libcson.a SO_LIB_NAME = libcson.so -OBJS = obj/base.o obj/parse.o obj/query.o obj/stringify.o +OBJS = obj/base.o obj/parse.o obj/query.o obj/stringify.o obj/marshaller.o DEPS = $(OBJS:%.o=%.d) -all: $(A_LIB_NAME) $(SO_LIB_NAME) $(BIN_NAME) +all: $(A_LIB_NAME) $(SO_LIB_NAME) tests -$(BIN_NAME): obj/demo.o $(OBJS) - $(LD) $(LDFLAGS) -o $@ $^ +tests: json-test marshaller-test + ./json-test + ./marshaller-test $(A_LIB_NAME): CFLAGS += -fPIC $(A_LIB_NAME): $(OBJS) @@ -25,46 +31,57 @@ $(SO_LIB_NAME): CFLAGS += -fPIC $(SO_LIB_NAME): $(OBJS) $(LD) -shared -o $@ $^ -marshaller-lib: $(A_LIB_NAME) obj/marshaller.o - $(AR) rs $(A_LIB_NAME) obj/marshaller.o - -test: obj/test.o $(OBJS) - $(LD) $(LDFLAGS) -o $@ $^ - -include $(DEPS) -obj/marshaller.o: CFLAGS += -Isrc/ -obj/marshaller.o: marshaller/lib/marshaller.c - $(CC) $(CFLAGS) -MMD -c -o $@ $< - obj/%.o: src/%.c obj $(CC) $(CFLAGS) -MMD -c -o $@ $< obj: - @mkdir -p obj + mkdir -p obj -marshaller-demo: marshaller/gen/demo.tab.c marshaller/demo/demo.c marshaller/lib/marshaller.c $(A_LIB_NAME) - $(CC) $(CFLAGS) -Imarshaller/demo/ -Isrc/ -Imarshaller/lib/ -o $@ $^ +$(MARSHALLER_GEN): marshaller/codegen.c gen/lex.yy.c gen/y.tab.c + $(CC) $(CFLAGS) -Imarshaller/ -o $@ $^ -marshaller/gen/demo.tab.c: marshaller/demo/demo.h marshaller/marshaller-gen - ./marshaller/marshaller-gen -o $@ $< - -marshaller/marshaller-gen: - $(MAKE) -C marshaller/ marshaller-gen +gen/y.tab.c gen/y.tab.h: marshaller/parser.y gen + $(YACC) $(YFLAGS) $< + mv y.tab.c gen/ + mv y.tab.h gen/ -marshaller-test: marshaller/gen/test.tab.c marshaller/test/test.c marshaller/lib/marshaller.c $(A_LIB_NAME) - $(CC) -g -Imarshaller/test/ -Isrc/ -Imarshaller/lib/ -o $@ $^ +gen/lex.yy.c: marshaller/scanner.l gen/y.tab.h gen + $(LEX) $< + mv lex.yy.c gen/ -marshaller/gen/test.tab.c: marshaller/test/test*.h marshaller/marshaller-gen - ./marshaller/marshaller-gen -o $@ marshaller/test/test*.h +gen: + mkdir -p gen/ + + +json-demo: demo/json.c $(A_LIB_NAME) + $(CC) $(CFLAGS) -Isrc/ -o $@ $^ + +marshaller-demo: gen/demo.tab.c demo/marshaller.c $(A_LIB_NAME) + $(CC) $(CFLAGS) -Isrc/ -Idemo/ -Isrc/ -o $@ $^ + +gen/demo.tab.c: demo/demo.h $(MARSHALLER_GEN) + $(MARSHALLER_GEN) -o $@ $< + + +json-test: test/json.c $(A_LIB_NAME) + $(CC) $(CFLAGS) -Isrc/ -o $@ $^ + +marshaller-test: gen/test.tab.c test/marshaller.c $(A_LIB_NAME) + $(CC) -g -Itest/ -Isrc/ -o $@ $^ + +gen/test.tab.c: test/test*.h $(MARSHALLER_GEN) + ./$(MARSHALLER_GEN) -o $@ test/test*.h clean: @echo "Cleaning up..." @rm -f obj/*.o @rm -f obj/*.d - @rm -f test - @rm -f $(BIN_NAME) + @rm -f gen/*.c @rm -f $(A_LIB_NAME) @rm -f $(SO_LIB_NAME) - @rm -f marshaller-demo marshaller-test - $(MAKE) -C marshaller/ clean + @rm -f json-demo + @rm -f json-test + @rm -f marshaller-demo + @rm -f marshaller-test diff --git a/marshaller/demo/demo.h b/demo/demo.h similarity index 100% rename from marshaller/demo/demo.h rename to demo/demo.h diff --git a/src/demo.c b/demo/json.c similarity index 100% rename from src/demo.c rename to demo/json.c diff --git a/marshaller/demo/demo.c b/demo/marshaller.c similarity index 100% rename from marshaller/demo/demo.c rename to demo/marshaller.c diff --git a/marshaller/Makefile b/marshaller/Makefile deleted file mode 100644 index f58633d..0000000 --- a/marshaller/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -LEX = flex -YACC = bison -YFLAGS = -y -d -CC = gcc - -BIN_NAME = marshaller-gen - -$(BIN_NAME): src/codegen.c gen/lex.yy.c gen/y.tab.c - $(CC) -Isrc/ -o $@ $^ - -gen/y.tab.c gen/y.tab.h: src/parser.y gen - $(YACC) $(YFLAGS) $< - mv y.tab.c gen/ - mv y.tab.h gen/ - -gen/lex.yy.c: src/scanner.l gen/y.tab.h gen - $(LEX) $< - mv lex.yy.c gen/ - -gen: - mkdir -p gen/ - -clean: - rm -f gen/* $(BIN_NAME) diff --git a/marshaller/src/codegen.c b/marshaller/codegen.c similarity index 100% rename from marshaller/src/codegen.c rename to marshaller/codegen.c diff --git a/marshaller/src/codegen.h b/marshaller/codegen.h similarity index 100% rename from marshaller/src/codegen.h rename to marshaller/codegen.h diff --git a/marshaller/src/helper.h b/marshaller/helper.h similarity index 100% rename from marshaller/src/helper.h rename to marshaller/helper.h diff --git a/marshaller/src/parser.y b/marshaller/parser.y similarity index 99% rename from marshaller/src/parser.y rename to marshaller/parser.y index cb1e3c8..bee151d 100644 --- a/marshaller/src/parser.y +++ b/marshaller/parser.y @@ -193,6 +193,8 @@ struct structinfo* newStructInfo() { info->names[1] = NULL; info->memberno = 0; info->members = NULL; + + return info; } struct declarsinfo* newDeclarsInfo() { diff --git a/marshaller/src/scanner.l b/marshaller/scanner.l similarity index 100% rename from marshaller/src/scanner.l rename to marshaller/scanner.l diff --git a/marshaller/lib/marshaller.c b/src/marshaller.c similarity index 99% rename from marshaller/lib/marshaller.c rename to src/marshaller.c index 2c92e52..83bb229 100644 --- a/marshaller/lib/marshaller.c +++ b/src/marshaller.c @@ -3,8 +3,7 @@ #include #include -#include - +#include "json.h" #include "marshaller.h" void _marshallPanic(const char* name, const char* reason) { diff --git a/marshaller/lib/marshaller.h b/src/marshaller.h similarity index 100% rename from marshaller/lib/marshaller.h rename to src/marshaller.h diff --git a/src/test.c b/test/json.c similarity index 99% rename from src/test.c rename to test/json.c index df89b11..975f30a 100644 --- a/src/test.c +++ b/test/json.c @@ -5,7 +5,7 @@ #include #include -#include "json.h" +#include bool global = true; diff --git a/marshaller/test/test.c b/test/marshaller.c similarity index 100% rename from marshaller/test/test.c rename to test/marshaller.c diff --git a/marshaller/test/test1.h b/test/test1.h similarity index 100% rename from marshaller/test/test1.h rename to test/test1.h diff --git a/marshaller/test/test2.h b/test/test2.h similarity index 100% rename from marshaller/test/test2.h rename to test/test2.h