diff options
-rwxr-xr-x | main.py | 18 | ||||
-rw-r--r-- | resources/makefile | 2 | ||||
-rw-r--r-- | test/autowasm.c | 3 | ||||
-rw-r--r-- | test/makefile | 2 | ||||
-rw-r--r-- | test/struct.json | 51 | ||||
-rw-r--r-- | text.py | 2 |
6 files changed, 19 insertions, 59 deletions
@@ -197,7 +197,7 @@ def dupemake(path, main_name): class CodeGen(object): def __init__(self, argparser): self.argparser = argparser - self.struct_json = json.load(open(self.argparser.args.structs)) + #self.struct_json = json.load(open(self.argparser.args.structs)) self.dnt = datetime.datetime.now().isoformat() self.elems = [] self.def_elems = [] @@ -356,11 +356,12 @@ class CodeGen(object): void_source.write("\n// automatically generated by faultreiber\n") void_source.write("// " + self.dnt + "\n") void_source.write('#include "./structs.h"\n') - void_source.write('#include "./read.c"\n') + void_source.write('#include "./read.h"\n') void_source.write("#include <stdlib.h>\n") #void_source.write("void** void_train(void) {\n") void_source_h.write('#ifndef FT_AGGREGATE_H\n#define FT_AGGREGATE_H\n') void_source_h.write('#ifdef __cplusplus\nextern "C" {\n#endif\n') + void_source_h.write('#include "./structs.h"\n') for elem in self.read_elems: count = get_elem_count(elem) size = get_elem_size(elem) @@ -506,17 +507,21 @@ class CodeGen(object): def_header.write("}" + child.attrib["name"] + ";\n\n") def gen_struct_header_xml(self): - struct_source = open(self.struct_source, "w") + struct_source = open(self.struct_source_h, "w") struct_source_c = open(get_full_path(self.argparser.args.outdir, "structs.c"), "w") + struct_source.write("#ifndef FT_STRUCTS_H\n#define FT_STRUCTS_H\n") struct_source_c.write('#include "structs.h"') + struct_source.write('#include <unistd.h>') struct_source.write(text.pre_header_guard) struct_source.write(text.autogen_warning) if self.argparser.args.datetime: struct_source.write("// " + self.dnt + "\n") struct_source.write(text.header_guard_begin.replace("XXX", "structs".upper())) struct_source.write(text.header_inttype) - struct_source.write(text.c_read_leb_u_def + "\n") - struct_source.write(text.c_read_leb_s_def + "\n") - struct_source.write(text.c_read_leb_macro_defs + "\n") + struct_source_c.write(text.c_read_leb_u_def + "\n") + struct_source_c.write(text.c_read_leb_s_def + "\n") + struct_source.write(text.c_read_leb_128_u_sig + "\n") + struct_source.write(text.c_read_leb_128_s_sig + "\n") + #struct_source.write(text.c_read_leb_macro_defs + "\n") if self.argparser.args.structsinclude: copy(self.argparser.args.structsinclude, self.argparser.args.outdir) pos = self.argparser.args.structsinclude.rfind("/") @@ -548,6 +553,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("#endif //end of header guard\n") #struct_source.write(text.last_comment) def gen_struct_header(self): diff --git a/resources/makefile b/resources/makefile index d5598ea..434dc68 100644 --- a/resources/makefile +++ b/resources/makefile @@ -34,7 +34,7 @@ depend:.depend .c.o: $(CC) $(CC_FLAGS) -c $< -o $@ -$(TARGET): $(TARGET).o +$(TARGET): $(TARGET).o read.o aggregate.o structs.o $(CC) $^ $(LD_FLAGS) -o $@ ASM:$(TARGET).asm diff --git a/test/autowasm.c b/test/autowasm.c index 7e4150a..b62ad34 100644 --- a/test/autowasm.c +++ b/test/autowasm.c @@ -12,6 +12,8 @@ #pragma weak main int main (int argc, char** argv) { int wasm = open("./test.wasm", O_RDONLY); + malloc_all(); +#if 0 uint64_t test_u = 0U; int64_t test_s = 0; unsigned char test_byte; @@ -35,5 +37,6 @@ int main (int argc, char** argv) { counter++; } printf("\n"); +#endif return 0; } diff --git a/test/makefile b/test/makefile index 6dec265..db69aff 100644 --- a/test/makefile +++ b/test/makefile @@ -34,7 +34,7 @@ depend:.depend .c.o: $(CC) $(CC_FLAGS) -c $< -o $@ -$(TARGET): $(TARGET).o +$(TARGET): $(TARGET).o read.o aggregate.o structs.o $(CC) $^ $(LD_FLAGS) -o $@ ASM:$(TARGET).asm diff --git a/test/struct.json b/test/struct.json deleted file mode 100644 index cb7899c..0000000 --- a/test/struct.json +++ /dev/null @@ -1,51 +0,0 @@ -{ "init_expr_t": - {"field_name": ["size", "code"], "field_type": ["varuint32", "char*"], "lua_type": ["integer", "string"], "methods": ["convert", "check", "push_self", "push_args", "new"]}, - "resizable_limit_t": - {"field_name":["flags", "initial", "maximum"], "field_type": ["varuint1", "varuint32", "varuint32"], "lua_type": ["integer", "integer", "integer"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "global_type_t": - {"field_name": ["value_type", "mutability"], "field_type": ["enum value_type_t", "varuint1"], "lua_type":["integer", "integer"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "table_type_t": - {"field_name": ["element_type", "resizable_limit"],"field_type": ["varint7", "resizable_limit_t*"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "memory_type_t": - {"field_name":["resizable_limit"], "field_type":["resizable_limit_t*"], "lua_type":["lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Type_Section_Entry": - {"field_name": ["form", "param_count", "param_types", "return_count", "return_types"], "field_type":["varint7", "varuint32", "varint7*", "varuint1", "varint7*"], "lua_type":["integer", "integer", "lightuserdata", "integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args","new"]}, - "W_Type_Section": - {"field_name":["count", "entries"], "field_type": ["varuint32", "W_Type_Section_Entry**"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Import_Section_Entry": - {"field_name":["module_length", "module_str", "field_len", "field_str", "kind", "type"], "field_type":["varuint32", "char*", "varuint32", "char*", "enum external_kind_t", "void*"], "lua_type": ["integer", "string", "integer", "string", "integer", "lightuserdata"], "methods": ["convert", "check", "push_self", "push_args", "new"]}, - "W_Import_Section": - {"field_name":["count", "entries"], "field_type":["varuint32","W_Import_Section_Entry**"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Function_Section": - {"field_name":["count", "types"], "field_type":["varuint32", "varuint32*"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Table_Section": - {"field_name":["count", "entries"], "field_type":["varuint32", "table_type_t**"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Memory_Section": - {"field_name":["count", "entries"], "field_type":["varuint32", "memory_type_t**"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Global_Entry": - {"field_name":["type", "init"], "field_type":["global_type_t*", "init_expr_t*"], "lua_type":["lightuserdata", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Global_Section": - {"field_name":["count", "globals"], "field_type":["varuint32", "W_Global_Entry**"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Export_Entry": - {"field_name":["field_len", "field_str", "kind", "index"], "field_type":["varuint32", "char*", "enum external_kind_t", "varuint32"], "lua_type":["integer", "string", "integer", "integer"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Export_Section": - {"field_name":["count", "entries"], "field_type": ["varuint32", "W_Export_Entry**"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Start_Section": - {"field_name":["index"], "field_type":["varuint32"], "lua_type":["integer"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Elem_Segment": - {"field_name":["index", "offset", "num_length", "elems"], "field_type":["varuint32", "init_expr_t*", "varuint32", "varuint32*"], "lua_type":["integer", "lightuserdata", "integer", "integer"], "methods": ["convert", "check", "push_self", "push_args", "new"]}, - "W_Element_Section": - {"field_name":["count", "entries"], "field_type":["varuint32", "W_Elem_Segment**"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Local_Entry": - {"field_name":["count", "type"], "field_type":["varuint32", "enum value_type_t"], "lua_type":["integer", "integer"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Function_Body": - {"field_name":["body_size", "local_count", "locals", "code"], "field_type":["varuint32", "varuint32", "W_Local_Entry**", "char*"], "lua_type":["integer", "integer", "lightuserdata", "string"], "methods": ["convert", "check", "push_self", "push_args", "new"]}, - "W_Code_Section": - {"field_name":["count", "bodies"], "field_type":["varuint32", "W_Function_Body**"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Data_Segment": - {"field_name":["index", "offset", "size", "data"], "field_type":["varuint32", "init_expr_t*", "varuint32", "char*"], "lua_type":["integer", "lightuserdata", "integer", "string"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "W_Data_Section": - {"field_name": ["count", "entries"], "field_type":["varuint32", "W_Data_Segment**"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, - "Wasm_Module": - {"field_name":["type_section", "import_section", "function_section", "table_section", "memory_section", "global_section", "export_section", "start_section", "element_section", "code_section", "data_section", "W_Custom_Sections", "name"], "field_type":["W_Type_Section*", "W_Import_Section*", "W_Function_Section*", "W_Table_Section*", "W_Memory_Section*", "W_Global_Section*", "W_Export_Section*", "W_Start_Section*", "W_Element_Section*", "W_Code_Section*", "W_Data_Section*", "void**", "char*"], "lua_type":["lightuserdata", "lightuserdata", "lightuserdata", "lightuserdata", "lightuserdata", "lightuserdata", "lightuserdata", "lightuserdata", "lightuserdata", "lightuserdata", "lightuserdata", "lightuserdata","string"], "methods":["convert", "check", "push_self", "push_args", "new"]} -} @@ -65,6 +65,8 @@ int64_t read_leb_128_s(int _fd, int max_size) { if ((last_byte & 0x40) != 0) result |= -(1 << shift); return result; }""" + c_read_leb_128_s_sig = "int64_t read_leb_128_s(int _fd, int max_size);\n" + c_read_leb_128_u_sig = "uint64_t read_leb_128_u(int _fd, int max_size);\n" c_read_leb_macro_defs = """ #define READ_VAR_UINT_1(FD) read_leb128_u(FD, 1) |