diff options
author | bloodstalker <thabogre@gmail.com> | 2018-07-01 12:10:17 +0000 |
---|---|---|
committer | bloodstalker <thabogre@gmail.com> | 2018-07-01 12:10:17 +0000 |
commit | 3f7a6e1cb02d2743b8343df21368d2aadfe81d8c (patch) | |
tree | 977f9058136c901d7c5106bb58272d5783365b5e | |
parent | updated the makefiles (diff) | |
download | faultreiber-3f7a6e1cb02d2743b8343df21368d2aadfe81d8c.tar.gz faultreiber-3f7a6e1cb02d2743b8343df21368d2aadfe81d8c.zip |
update
Diffstat (limited to '')
-rwxr-xr-x | main.py | 35 | ||||
-rwxr-xr-x | run.sh | 2 | ||||
-rw-r--r-- | test/makefile | 2 | ||||
-rw-r--r-- | test/struct.json | 51 | ||||
-rw-r--r-- | text.py | 4 |
5 files changed, 90 insertions, 4 deletions
@@ -3,7 +3,10 @@ import argparse import code +import fileinput +import json import readline +from shutil import copy import signal import sys @@ -14,15 +17,43 @@ def SigHandler_SIGINT(signum, frame): class Argparser(object): def __init__(self): parser = argparse.ArgumentParser() - parser.add_argument("--string", type=str, help="string") - parser.add_argument("--bool", action="store_true", help="bool", default=False) + parser.add_argument("--targetname", type=str, help="main target name") + parser.add_argument("--outdir", type=str, help="path to output dir") + parser.add_argument("--structs", type=str, help="the structs json file") parser.add_argument("--dbg", action="store_true", help="debug", default=False) self.args = parser.parse_args() +def dupemake(path, main_name): + copy("./resources/makefile", path) + makefile_path = str() + if path[-1] == "/": makefile_path = path + "makefile" + else: makefile_path = path + "/makefile" + for line in fileinput.input(makefile_path, inplace=True): + if "XXX" in line: + line = line.replace("XXX", main_name) + sys.stdout.write(line) + +class CodeGen(object): + def __init__(self, argparser): + self.argparser = argparser + self.struct_json = json.load(open(self.argparser.args.structs)) + + def init_hook(self): + pass + + def init(self): + dupemake(self.argparser.args.outdir, self.argparser.args.targetname) + + def run(self): + self.init() + self.init_hook() + # write code here def premain(argparser): signal.signal(signal.SIGINT, SigHandler_SIGINT) #here + codegen = CodeGen(argparser) + codegen.run() def main(): argparser = Argparser() @@ -1,2 +1,2 @@ #!/bin/sh -"./main.py" +"./main.py" --targetname autowasm --outdir ./test/ --structs ./test/structs.json diff --git a/test/makefile b/test/makefile index d5598ea..6dec265 100644 --- a/test/makefile +++ b/test/makefile @@ -1,4 +1,4 @@ -TARGET=XXX +TARGET=autowasm CC=clang CC?=clang CC_FLAGS=-fpic diff --git a/test/struct.json b/test/struct.json new file mode 100644 index 0000000..38fe5a7 --- /dev/null +++ b/test/struct.json @@ -0,0 +1,51 @@ +{ "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**"], "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"]} +} @@ -0,0 +1,4 @@ +# _*_ coding=utf-8 _*_ + +class Text(): + main_sig = 'int main(int argc, char** argv)' |