diff options
-rwxr-xr-x | main.py | 25 | ||||
-rw-r--r-- | resources/wasm.xml | 2 | ||||
-rwxr-xr-x | run.sh | 5 | ||||
-rw-r--r-- | test/autowasm.c | 4 |
4 files changed, 25 insertions, 11 deletions
@@ -16,6 +16,7 @@ from misc import * import datetime # TODO-doesnt support non-byte-sized reads +# TODO-doesnt support big-endian normal reads def type_resolver(elem, elem_list): type_str = elem.attrib["type"] type_name = elem.attrib["name"] @@ -166,21 +167,23 @@ class CodeGen(object): temp_dec_list = [] read_source = open(self.argparser.args.outdir + "/read.c", "w") read_source.write("\n// automatically generated by faultrieber\n") - read_source.write("// " + self.dnt + "\n") + read_source.write("// " + self.dnt + "\n\n") read_source.write(text.header_list) - read_source.write('#include "./structs.h"\n') + read_source.write('#include "./structs.h"\n\n') inline = "inline " if self.argparser.args.inline else "" static = "static " if self.argparser.args.static else "" - for elem in self.def_elems+ self.read_elems: + for elem in self.def_elems + self.read_elems: dummy_list = [] pointer = str() access = "." + dummy_static = str() if "isaggregate" in elem.attrib: pointer = "*" access = "->" - 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_function_dummy_dec.replace("XXX", elem.attrib["name"] + pointer)) + dummy_static = "static " if "isaggregate" in elem.attrib: + read_source.write(static + inline + text.c_read_elem_sig.replace("YYY", elem.attrib["name"]).replace("XXX", elem.attrib["name"]+pointer)) + read_source.write("static " + text.c_function_dummy_dec.replace("XXX", elem.attrib["name"] + pointer)) count = get_elem_count(elem, self.read_elems+self.def_elems) if count == 1: for child in elem: @@ -227,7 +230,7 @@ class CodeGen(object): for_read = text.c_read_gen_2.replace("XXX", pointer_remover(ref_node_name)+"_ins").replace("YYY", read_size_replacement) else: if "encoding" in child.attrib: - for_read = get_encoding_read(child.attrib["encoding"]) + for_read = ref_node_name + "_ins = " + get_encoding_read(child.attrib["encoding"]) else: for_read = text.c_read_gen.replace("XXX", pointer_remover(ref_node_name)+"_ins").replace("YYY", ref_node_name) if child_count == 1: @@ -246,8 +249,16 @@ class CodeGen(object): read_source.write(text.simple_loop.replace("YYY", for_dummy_declare+for_read+for_dummy_assign).replace("XXX", replacement)) else: pass + # if not aggregate + # if its an aggregate type there is only a single element in the + # read funtion so we dont really need to worry about multiple + # instances with the same name else: + read_source.write(static + inline + text.c_read_elem_sig.replace("YYY", elem.attrib["name"]).replace("XXX", type_resolver(elem, self.def_elems)+pointer)) + read_source.write(text.c_function_dummy_dec.replace("XXX", type_resolver(elem, self.def_elems) + pointer)) read_source.write(type_resolver(elem, self.elems) + " " + elem.attrib["name"] + ";\n") + read_source.write(text.c_read_gen.replace("XXX", elem.attrib["name"]).replace("YYY", type_resolver(elem, self.def_elems))) + read_source.write("dummy = " + elem.attrib["name"] + ";\n") read_source.write(text.c_function_return_type) read_source.write(text.c_function_close + "\n") @@ -323,7 +334,7 @@ class CodeGen(object): struct_source.write(ref_type + pointer + " " + childer.attrib["name"] + ";\n") struct_source.write("}" + child.attrib["name"] + ";\n\n") struct_source.write(text.pragma_endif) - struct_source.write(text.last_comment) + #struct_source.write(text.last_comment) def gen_struct_header(self): struct_source = open(get_full_path(self.argparser.args.outdir, "structs.h"), "w") diff --git a/resources/wasm.xml b/resources/wasm.xml index 2ab77ec..890a119 100644 --- a/resources/wasm.xml +++ b/resources/wasm.xml @@ -2,7 +2,7 @@ <wasm:Structure xmlns:wasm="http://www.w3.org/2001/XMLSchema"> <Read> <Magic_Number name="magic_number" type="uint32" count="1"></Magic_Number> - <Version name="version" type="uint32" encoding="leb128u" count="1"></Version> + <Version name="version" type="uint32" count="1"></Version> <Type_Section name="W_Type_Section" count="1" type="" isaggregate="true"> <Count name="count" encoding="leb128u" type="uint32" count="1"/> <Type_Section_Entry count="self::Count" type="self::Type_Section_Entry" name="entries"/> @@ -1,4 +1,5 @@ #!/bin/sh cd $(dirname $0) -"./faultreiber.py" --targetname autowasm --outdir ./test/ --structs ./test/struct.json --datetime --structsinclude ./resources/structsinclude.h --xml ./resources/wasm.xml --inline -"less" ./test/structs.h +"./faultreiber.py" --targetname autowasm --outdir ./test/ --structs ./test/struct.json --datetime --structsinclude ./resources/structsinclude.h --xml ./resources/wasm.xml --inline --static +"clang-format" -i ./test/read.c ./test/structs.h +#"less" ./test/structs.h diff --git a/test/autowasm.c b/test/autowasm.c index 5151898..84cdf9d 100644 --- a/test/autowasm.c +++ b/test/autowasm.c @@ -5,6 +5,8 @@ #include <stdlib.h> #include <unistd.h> +#include "./read.c" + uint64_t read_leb128_u(int _fd, int max_size) { uint8_t read_bytes = 0U; uint8_t byte = 0; @@ -64,7 +66,7 @@ int main (int argc, char** argv) { printf("read u res is: %lu.\n", test_u); lseek(wasm, 0, SEEK_SET); while(read(wasm, &word, sizeof(uint32_t))) { - //printf("%d:%02x\t", counter, word); + printf("%d:%02x\t", counter, word); counter++; } printf("\n"); |