diff options
Diffstat (limited to '')
-rwxr-xr-x | main.py | 50 | ||||
-rw-r--r-- | resources/makefile | 49 | ||||
-rw-r--r-- | test/autowasm.c | 2 | ||||
-rw-r--r-- | test/makefile | 49 | ||||
-rw-r--r-- | text.py | 6 |
5 files changed, 130 insertions, 26 deletions
@@ -296,6 +296,55 @@ class CodeGen(object): if size == -1: ref_size = "dummy->" + get_node_name(child.attrib["size"][6:], elem) + if "conditional" in child.attrib: + cond_name = get_node_name(child.attrib["condition"][6:], elem) + for cond in child: + child_count = get_elem_count(cond) + ref_node_name = type_resolver(cond, self.def_elems) + ref_node = get_def_node(ref_node_name, self.def_elems) + if ref_node: + read_source.write("if (dummy->" + cond_name + "==" + str(cond.text) + "){\n") + read_source.write("dummy->" + cond.attrib["name"] + "=malloc(sizeof(" + ref_node.attrib["name"] + "));") + if child_count == 1: + for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"]) + ";\n" + read_source.write(for_read) + elif child_count > 1: + for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"] + "[i]") + ";\n" + read_source.write(for_read) + else: # child_count == -1 + count_name_str = cond.attrib["count"][6:] + read_source.write("if (" + "dummy->" + get_node_name(count_name_str, elem) + ")\n") + read_source.write("dummy->" + cond.attrib["name"] + " = " + "malloc(sizeof(void*)*" + "dummy->" + get_node_name(count_name_str, child) + ");\n") + for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"] + "[i]") + ";\n" + read_source.write(text.simple_loop.replace("YYY", for_read).replace("XXX", "dummy->" + get_node_name(count_name_str, child))) + read_source.write("}\n") + else: + read_source.write("if (dummy->" + cond_name + "==" + str(cond.text) + "){\n") + read_source.write("dummy->" + cond.attrib["name"] + "=malloc(sizeof(" + ref_node_name + "));") + for_read = str() + if child_count == 1: array_subscript = "" + elif child_count > 1: array_subscript = "[i]" + else: array_subscript = "[i]" + if "size" in cond.attrib: + if "encoding" in cond.attrib: + for_read = "dummy->" + cond.attrib["name"] + array_subscript + "=" + get_encoding_read(cond.attrib["encoding"]) + else: + for_read = text.c_read_gen_2.replace("XXX", "dummy" + "->"+ cond.attrib["name"] + array_subscript).replace("YYY", ref_size) + else: + if "encoding" in cond.attrib: + for_read = "dummy->" + cond.attrib["name"] + array_subscript + " = " + get_encoding_read(cond.attrib["encoding"]) + else: + for_read = text.c_read_gen.replace("XXX", "dummy" + "->" + cond.attrib["name"] + array_subscript).replace("YYY", ref_node_name) + if child_count == 1: + read_source.write(for_read) + elif child_count > 1: + read_source.write(text.simple_loop.replace("YYY", for_read).replace("XXX", str(child_count))) + else: # child_count = -1 + count_name_str = cond.attrib["count"][6:] + read_source.write("dummy->" + cond.attrib["name"] + " = " + "malloc(sizeof(" + type_resolver(cond, self.def_elems + self.read_elems) + ")*" + "dummy->" + get_node_name(count_name_str, elem) + ");\n") + read_source.write("if (" + "dummy->" + get_node_name(count_name_str, child) + ")\n") + read_source.write(text.simple_loop.replace("YYY", for_read).replace("XXX", "dummy->" + get_node_name(count_name_str, elem))) + read_source.write("}\n") if ref_node: ref_node_name = pointer_remover(ref_node.attrib["name"]) if child_count == 1: @@ -344,6 +393,7 @@ class CodeGen(object): read_source.write(static + inline + text.c_read_elem_sig.replace("YYY", elem.attrib["name"]).replace("XXX", elem.attrib["name"]+pointer)) read_source.write(text.c_read_gen.replace("XXX", "dummy->" + elem.attrib["name"]).replace("YYY", type_resolver(elem, self.def_elems))) #read_source.write(text.c_function_return_type) + read_source.write("return dummy;\n") read_source.write(text.c_function_close + "\n") read_source_header = open(self.argparser.args.outdir + "/read.h", "w") read_source_header.write("#ifndef FT_READ_H\n#define FT_READ_H\n") diff --git a/resources/makefile b/resources/makefile index 944bfe1..86f0a6b 100644 --- a/resources/makefile +++ b/resources/makefile @@ -1,3 +1,5 @@ +SHELL=bash +SHELL?=bash TARGET=autowasm CC=clang CC?=clang @@ -12,8 +14,12 @@ MEM_SANITIZERS_CC= -g -fsanitize=memory -fno-omit-frame-pointer MEM_SANITIZERS_LD= -g -fsanitize=memory UB_SANITIZERS_CC= -g -fsanitize=undefined -fno-omit-frame-pointer UB_SANITIZERS_LD= -g -fsanitize=undefined +COV_CC= -fprofile-instr-generate -fcoverage-mapping +COV_LD= -fprofile-instr-generate # BUILD_MODES are=RELEASE(default), DEBUG,ADDSAN,MEMSAN,UBSAN BUILD_MODE?=RELEASE +OBJ_LIST:=$(patsubst %.c, %.o, $(wildcard *.c)) +ASM_LIST:=$(patsubst %.c, %.dis, $(wildcard *.c)) ifeq ($(BUILD_MODE), ADDSAN) ifeq ($(CC), gcc) @@ -49,13 +55,15 @@ LD_FLAGS+=$(EXTRA_LD_FLAGS) all:$(TARGET) -everything:$(TARGET) A ASM SO $(TARGET)-static $(TARGET)-dbg TAGS +everything:$(TARGET) A ASM SO $(TARGET)-static $(TARGET)-dbg TAGS $(TARGET)-cov depend:.depend .depend:$(SRCS) rm -rf .depend $(CC) -MM $(CC_FLAGS) $^ > ./.depend + echo $(patsubst %.o:, %.odbg:, $(shell $(CC) -MM $(CC_FLAGS) $^)) | sed -r 's/[a-z0-9\-\_]+\.odbg/\n&/g' >> ./.depend + echo $(patsubst %.o:, %.ocov:, $(shell $(CC) -MM $(CC_FLAGS) $^)) | sed -r 's/[a-z0-9\-\_]+\.ocov/\n&/g' >> ./.depend -include ./.depend @@ -65,16 +73,30 @@ depend:.depend %.odbg:%.c $(CC) $(CC_FLAGS) -g -c $< -o $@ -$(TARGET): $(TARGET).o read.o structs.o aggregate.o +%.ocov:%.c + $(CC) $(CC_FLAGS) $(COV_CC) -c $< -o $@ + +$(TARGET): $(TARGET).o read.o aggregate.o structs.o $(CC) $^ $(LD_FLAGS) -o $@ -$(TARGET)-static: $(TARGET).o read.o structs.o aggregate.o +$(TARGET)-static: $(TARGET).o read.o aggregate.o structs.o $(CC) $^ $(LD_FLAGS) -static -o $@ -$(TARGET)-dbg: $(TARGET).odbg read.odbg structs.odbg aggregate.odbg +$(TARGET)-dbg: $(TARGET).odbg read.o aggregate.o structs.o $(CC) $^ $(LD_FLAGS) -g -o $@ -ASM:$(TARGET).asm +$(TARGET)-cov: $(TARGET).ocov read.o aggregate.o structs.o + $(CC) $^ $(LD_FLAGS) $(COV_LD) -o $@ + +cov: + @llvm-profdata merge -sparse ./default.profraw -o ./default.profdata + @llvm-cov show $(TARGET)-cov -instr-profile=default.profdata + +covrep: + @llvm-profdata merge -sparse ./default.profraw -o ./default.profdata + @llvm-cov report $(TARGET)-cov -instr-profile=default.profdata + +ASM:$(ASM_LIST) SO:$(TARGET).so @@ -87,20 +109,20 @@ tags:$(SRCS) sed -e 's/[\\ ]/\n/g'|sed -e '/^$$/d' -e '/\.o:[ \t]*$$/d'|\ ctags -L - --c++-kinds=+p --fields=+iaS --extra=+q) -$(TARGET).asm: $(TARGET).o read.o structs.o aggregate.o - objdump -r -d -M intel -S $(TARGET).o > $(TARGET).asm +%.dis: %.o + objdump -r -d -M intel -S $< > $@ -$(TARGET).so: $(TARGET).o read.o structs.o aggregate.o +$(TARGET).so: $(TARGET).o read.o aggregate.o structs.o $(CC) $^ $(LD_FLAGS) -shared -o $@ -$(TARGET).a: $(TARGET).o read.o structs.o aggregate.o +$(TARGET).a: $(TARGET).o read.o aggregate.o structs.o ar rcs $(TARGET).a $(TARGET).o clean: - rm -f *.o *.odbg *~ $(TARGET) $(TARGET).so $(TARGET).asm $(TARGET)-static $(TARGET)-dbg $(TARGET).a + rm -f *.o *.dis *.odbg *.ocov *~ $(TARGET) $(TARGET).so $(TARGET)-static $(TARGET)-dbg $(TARGET).a $(TARGET)-cov deepclean: - rm -f *.o *.odbg *~ $(TARGET) $(TARGET).so $(TARGET).asm tags $(TARGET)-static $(TARGET)-dbg $(TARGET).a + rm -f *.o *.dis *.odbg *.ocov *~ $(TARGET) $(TARGET).so tags $(TARGET)-static $(TARGET)-dbg $(TARGET).a $(TARGET)-cov rm .depend help: @@ -112,7 +134,10 @@ help: @echo "--$(TARGET) builds the dynamically-linked executable" @echo "--$(TARGET)-dbg will generate the debug build. BUILD_MODE should be set to DEBUG to work" @echo "--$(TARGET)-static will statically link the executable to the libraries" + @echo "--$(TARGET)-cov is the coverage build" + @echo "--cov will print the coverage report" + @echo "--covrep will print the coverage report" @echo "--A will build the static library" @echo "--TAGS will build the tags file" @echo "--clean" - @echo "--deepclean will clean almost everything" + @echo "--deepclean$(newline) will clean almost everything" diff --git a/test/autowasm.c b/test/autowasm.c index be2800d..0ea860a 100644 --- a/test/autowasm.c +++ b/test/autowasm.c @@ -17,11 +17,13 @@ int main (int argc, char** argv) { magic_number* mn = ft_ret_magic_number(); version* v = ft_ret_version(); W_Type_Section* ts = ft_ret_W_Type_Section(); +#if 0 printf("magic_number:%x\n", mn->magic_number); printf("version:%d\n", v->version); printf("type section id:%d\n", ts->id); printf("type section payloadlength:%d\n", ts->payloadlength); printf("type_section entry count:%d\n", ts->count); +#endif for (int i=0; i < 7; ++i) { //printf("param_count:%d\n",ts->entries[i]->param_count); //printf("param_count:%d\n",ts->entries[i]); diff --git a/test/makefile b/test/makefile index 944bfe1..86f0a6b 100644 --- a/test/makefile +++ b/test/makefile @@ -1,3 +1,5 @@ +SHELL=bash +SHELL?=bash TARGET=autowasm CC=clang CC?=clang @@ -12,8 +14,12 @@ MEM_SANITIZERS_CC= -g -fsanitize=memory -fno-omit-frame-pointer MEM_SANITIZERS_LD= -g -fsanitize=memory UB_SANITIZERS_CC= -g -fsanitize=undefined -fno-omit-frame-pointer UB_SANITIZERS_LD= -g -fsanitize=undefined +COV_CC= -fprofile-instr-generate -fcoverage-mapping +COV_LD= -fprofile-instr-generate # BUILD_MODES are=RELEASE(default), DEBUG,ADDSAN,MEMSAN,UBSAN BUILD_MODE?=RELEASE +OBJ_LIST:=$(patsubst %.c, %.o, $(wildcard *.c)) +ASM_LIST:=$(patsubst %.c, %.dis, $(wildcard *.c)) ifeq ($(BUILD_MODE), ADDSAN) ifeq ($(CC), gcc) @@ -49,13 +55,15 @@ LD_FLAGS+=$(EXTRA_LD_FLAGS) all:$(TARGET) -everything:$(TARGET) A ASM SO $(TARGET)-static $(TARGET)-dbg TAGS +everything:$(TARGET) A ASM SO $(TARGET)-static $(TARGET)-dbg TAGS $(TARGET)-cov depend:.depend .depend:$(SRCS) rm -rf .depend $(CC) -MM $(CC_FLAGS) $^ > ./.depend + echo $(patsubst %.o:, %.odbg:, $(shell $(CC) -MM $(CC_FLAGS) $^)) | sed -r 's/[a-z0-9\-\_]+\.odbg/\n&/g' >> ./.depend + echo $(patsubst %.o:, %.ocov:, $(shell $(CC) -MM $(CC_FLAGS) $^)) | sed -r 's/[a-z0-9\-\_]+\.ocov/\n&/g' >> ./.depend -include ./.depend @@ -65,16 +73,30 @@ depend:.depend %.odbg:%.c $(CC) $(CC_FLAGS) -g -c $< -o $@ -$(TARGET): $(TARGET).o read.o structs.o aggregate.o +%.ocov:%.c + $(CC) $(CC_FLAGS) $(COV_CC) -c $< -o $@ + +$(TARGET): $(TARGET).o read.o aggregate.o structs.o $(CC) $^ $(LD_FLAGS) -o $@ -$(TARGET)-static: $(TARGET).o read.o structs.o aggregate.o +$(TARGET)-static: $(TARGET).o read.o aggregate.o structs.o $(CC) $^ $(LD_FLAGS) -static -o $@ -$(TARGET)-dbg: $(TARGET).odbg read.odbg structs.odbg aggregate.odbg +$(TARGET)-dbg: $(TARGET).odbg read.o aggregate.o structs.o $(CC) $^ $(LD_FLAGS) -g -o $@ -ASM:$(TARGET).asm +$(TARGET)-cov: $(TARGET).ocov read.o aggregate.o structs.o + $(CC) $^ $(LD_FLAGS) $(COV_LD) -o $@ + +cov: + @llvm-profdata merge -sparse ./default.profraw -o ./default.profdata + @llvm-cov show $(TARGET)-cov -instr-profile=default.profdata + +covrep: + @llvm-profdata merge -sparse ./default.profraw -o ./default.profdata + @llvm-cov report $(TARGET)-cov -instr-profile=default.profdata + +ASM:$(ASM_LIST) SO:$(TARGET).so @@ -87,20 +109,20 @@ tags:$(SRCS) sed -e 's/[\\ ]/\n/g'|sed -e '/^$$/d' -e '/\.o:[ \t]*$$/d'|\ ctags -L - --c++-kinds=+p --fields=+iaS --extra=+q) -$(TARGET).asm: $(TARGET).o read.o structs.o aggregate.o - objdump -r -d -M intel -S $(TARGET).o > $(TARGET).asm +%.dis: %.o + objdump -r -d -M intel -S $< > $@ -$(TARGET).so: $(TARGET).o read.o structs.o aggregate.o +$(TARGET).so: $(TARGET).o read.o aggregate.o structs.o $(CC) $^ $(LD_FLAGS) -shared -o $@ -$(TARGET).a: $(TARGET).o read.o structs.o aggregate.o +$(TARGET).a: $(TARGET).o read.o aggregate.o structs.o ar rcs $(TARGET).a $(TARGET).o clean: - rm -f *.o *.odbg *~ $(TARGET) $(TARGET).so $(TARGET).asm $(TARGET)-static $(TARGET)-dbg $(TARGET).a + rm -f *.o *.dis *.odbg *.ocov *~ $(TARGET) $(TARGET).so $(TARGET)-static $(TARGET)-dbg $(TARGET).a $(TARGET)-cov deepclean: - rm -f *.o *.odbg *~ $(TARGET) $(TARGET).so $(TARGET).asm tags $(TARGET)-static $(TARGET)-dbg $(TARGET).a + rm -f *.o *.dis *.odbg *.ocov *~ $(TARGET) $(TARGET).so tags $(TARGET)-static $(TARGET)-dbg $(TARGET).a $(TARGET)-cov rm .depend help: @@ -112,7 +134,10 @@ help: @echo "--$(TARGET) builds the dynamically-linked executable" @echo "--$(TARGET)-dbg will generate the debug build. BUILD_MODE should be set to DEBUG to work" @echo "--$(TARGET)-static will statically link the executable to the libraries" + @echo "--$(TARGET)-cov is the coverage build" + @echo "--cov will print the coverage report" + @echo "--covrep will print the coverage report" @echo "--A will build the static library" @echo "--TAGS will build the tags file" @echo "--clean" - @echo "--deepclean will clean almost everything" + @echo "--deepclean$(newline) will clean almost everything" @@ -13,8 +13,10 @@ class text(): read_func_sig = "int read_structured_file(char* path)" #c_read_elem_sig = "XXX ft_read_YYY(int _fd) {\n" #c_read_elem_sig = "void ft_read_YYY(int _fd, XXX* dummyZZZ) {\n" - c_read_elem_sig = "void ft_read_YYY(int _fd, XXX* dummy) {\n" - c_read_elem_sig_h = "void ft_read_YYY(int _fd, XXX* dummy);\n" + #c_read_elem_sig = "void ft_read_YYY(int _fd, XXX* dummy) {\n" + #c_read_elem_sig_h = "void ft_read_YYY(int _fd, XXX* dummy);\n" + c_read_elem_sig = "void* ft_read_YYY(int _fd, XXX* dummy) {\n" + c_read_elem_sig_h = "void* ft_read_YYY(int _fd, XXX* dummy);\n" c_read_elem_sig_1 = "ft_read_XXX(_fd)" c_read_elem_sig_2 = "ft_read_XXX(_fd, YYY)" #c_read_elem_sig_2 = "ft_read_XXX(_fd, &YYY)" |