aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2018-07-10 01:01:38 +0000
committerbloodstalker <thabogre@gmail.com>2018-07-10 01:01:38 +0000
commitc149ee9895bcc2d39c836468a3ddc3a2250da98a (patch)
tree0e5e069231a49b4326b897a3fab5422739c30c29
parentupdate (diff)
downloadfaultreiber-c149ee9895bcc2d39c836468a3ddc3a2250da98a.tar.gz
faultreiber-c149ee9895bcc2d39c836468a3ddc3a2250da98a.zip
update
-rwxr-xr-xmain.py75
-rw-r--r--resources/wasm.xml50
2 files changed, 88 insertions, 37 deletions
diff --git a/main.py b/main.py
index 46d550e..d9eb369 100755
--- a/main.py
+++ b/main.py
@@ -14,6 +14,50 @@ import datetime
import xml.etree.ElementTree
from misc import *
+def type_resolver(elem, elem_list):
+ type_str = elem.attrib["type"]
+ type_name = elem.attrib["name"]
+ if type_str == "int8":
+ return "int8_t"
+ elif type_str == "uint8":
+ return "uint8_t"
+ elif type_str == "int16":
+ return "int16_t"
+ elif type_str == "uint16":
+ return "uint16_t"
+ elif type_str == "int32":
+ return "int32_t"
+ elif type_str == "uint32":
+ return "uint32_t"
+ elif type_str == "int64":
+ return "int64_t"
+ elif type_str == "uint64":
+ return "uint64_t"
+ elif type_str == "int128":
+ return "int128_t"
+ elif type_str == "uint128":
+ return "uint128_t"
+ elif type_str == "float":
+ return "float"
+ elif type_str == "double":
+ return "double"
+ elif type_str == "bool":
+ return "unsigned char"
+ elif type_str == "uchar":
+ return "unsigned char"
+ elif type_str == "schar":
+ return "signed char"
+ elif type_str == "string":
+ return "char*"
+ elif type_str == "FT::conditional":
+ return "void*"
+ elif type_str.find("self::") == 0:
+ for node in elem_list:
+ if elem.attrib["type"][6:] == node.tag:
+ print(node.tag)
+ return node.attrib["name"]
+ else: return type_str
+
def SigHandler_SIGINT(signum, frame):
print()
sys.exit(0)
@@ -33,6 +77,7 @@ class Argparser(object):
parser.add_argument("--dbg", action="store_true", help="debug", default=False)
parser.add_argument("--datetime", action="store_true", help="print date and time in autogen files", default=False)
parser.add_argument("--inline", action="store_true", help="put all reads in sequentially", default=False)
+ parser.add_argument("--verbose", action="store_true", help="verbose", default=False)
self.args = parser.parse_args()
def dupemake(path, main_name):
@@ -48,6 +93,7 @@ class CodeGen(object):
self.argparser = argparser
self.struct_json = json.load(open(self.argparser.args.structs))
self.dnt = datetime.datetime.now().isoformat()
+ self.elems = []
def init_hook(self):
pass
@@ -60,32 +106,37 @@ class CodeGen(object):
def read_xml(self):
if self.argparser.args.xml:
+ def_header = open(self.argparser.args.outdir + "/defines.h", "w")
+ def_header.write(text.header_inttype + "\n")
tree = xml.etree.ElementTree.parse(self.argparser.args.xml)
root = tree.getroot()
- print(root.tag)
- print(root.attrib)
read_tree = xml.etree.ElementTree.Element("read")
def_tree = xml.etree.ElementTree.Element("def")
for child in root:
print(child.tag + "--" + repr(child.attrib))
if child.tag == "Read":
read_tree = child
- print(type(child))
if child.tag == "Definition":
def_tree = child
- print(type(child))
- print(read_tree.tag)
- print(def_tree.tag)
read_iter = read_tree.iter(tag=None)
def_iter = def_tree.iter(tag=None)
for child in def_iter:
- print(child.attrib)
- for childer in child.iter(tag=None):
- print("\t" + childer.tag + "--" + repr(childer.attrib))
+ self.elems.append(child)
+ if "isaggregate" in child.attrib:
+ def_header.write("typedef struct {\n")
+ for childerer in child:
+ c_type = type_resolver(childerer, self.elems)
+ def_header.write("\t" + c_type + " " + childerer.attrib["name"] + ";\n")
+ def_header.write("}" + child.attrib["name"] + ";\n\n")
for child in read_iter:
- print(child.attrib)
- for childer in child.iter(tag=None):
- print("\t" + childer.tag + "--" + repr(childer.attrib))
+ self.elems.append(child)
+ if "isaggregate" in child.attrib:
+ def_header.write("typedef struct {\n")
+ for childerer in child:
+ print(childerer.tag)
+ c_type = type_resolver(childerer, self.elems)
+ def_header.write("\t" + c_type + " " + childerer.attrib["name"] + ";\n")
+ def_header.write("}" + child.attrib["name"] + ";\n\n")
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 5c436cf..5b1220c 100644
--- a/resources/wasm.xml
+++ b/resources/wasm.xml
@@ -1,52 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<wasm:Structure xmlns:wasm="http://www.w3.org/2001/XMLSchema">
<Read>
- <Magic_Number size="4"></Magic_Number>
- <Version size="4"></Version>
- <Type_Section count="1" type="" isaggregate="true">
+ <Magic_Number name="magic_number" encoding="leb128u" type="uint32" size="4"></Magic_Number>
+ <Version name="version" type="uint32" encoding="leb128u" size="4"></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_Section_Entry count="self::Count" type="self::Type_Section_Entry" name="entries"/>
</Type_Section>
- <Import_Section count="1" type="" isaggregate="true">
+ <Import_Section name="W_Import_Section" count="1" type="" isaggregate="true">
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Entries name="entries" type="self::Import_Section_Entry" count="self::Count"/>
</Import_Section>
- <Function_Section count="1" type="" isaggregate="true">
+ <Function_Section name="W_Function_Section" count="1" type="" isaggregate="true">
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Types name="types" encoding="leb128u" type="uint32" count="self::Count"/>
</Function_Section>
- <Table_Section count="1" type="" isaggregate="true">
+ <Table_Section name="W_Table_Section" count="1" type="" isaggregate="true">
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Entries name="entries" type="self::Table_Type" count="self::Count"/>
</Table_Section>
- <Memory_Section count="1" type="" isaggregate="true">
+ <Memory_Section name="W_Memory_Section" count="1" type="" isaggregate="true">
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Entries name="entries" type="self::Memory_Type" count="self::Count"/>
</Memory_Section>
- <Global_Section count="1" type="" isaggregate="true">
+ <Global_Section name="W_Global_Section" count="1" type="" isaggregate="true">
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Globals name="globals" type="this::Global_Entry" count="self::Count"/>
</Global_Section>
- <Export_Section count="1" type="" isaggregate="true">
+ <Export_Section name="W_Export_Section" count="1" type="" isaggregate="true">
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Entries name="entries" type="self::Export_Entry" count="self::Count"/>
</Export_Section>
- <Start_Section count="1" type="" isaggregate="true">
+ <Start_Section name="W_Start_Section" count="1" isaggregate="true">
<Index name="index" encoding="leb128u" type="uint32" count="1"/>
</Start_Section>
- <Element_Section count="1" type="" isaggregate="true">
+ <Element_Section name="W_Element_Section" count="1" isaggregate="true">
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Entries name="entries" type="self::Element_Segment" count="self::Count"/>
</Element_Section>
- <Code_Section count="1" type="" isaggregate="true">
+ <Code_Section name="W_Code_Section" count="1" isaggregate="true">
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Bodies name="bodies" type="self::Function_Body" count="self::Count"/>
</Code_Section>
- <Data_Section count="1" type="" isaggregate="true">
+ <Data_Section name="W_Data_Section" count="1" isaggregate="true">
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Entries name="entries" type="self::Data_Segment" count="self::Count"/>
</Data_Section>
- <Custom_Section count="1" type="" isaggregate="true"></Custom_Section>
+ <Custom_Section name="W_Custom_Section" count="1" isaggregate="true"></Custom_Section>
</Read>
<Definition>
<Init_Expr name="init_expr_t" isaggregate="true">
@@ -64,10 +64,10 @@
</Global_Type>
<Table_Type name="table_type_t" isaggregate="true">
<Element_Type name="element_type" encoding="leb128s" type="int8" count="1"></Element_Type>
- <Resizable_Limit count="1"></Resizable_Limit>
+ <Resizable_Limit name="resizable_limit" count="1" type="self::Resizable_Limit"></Resizable_Limit>
</Table_Type>
<Memory_Type name="memory_type_t" isaggregate="true">
- <Resizable_Limit count="1"></Resizable_Limit>
+ <Resizable_Limit count="1" type="self::Resizable_Limit" name="resizable_limit"></Resizable_Limit>
</Memory_Type>
<Type_Section_Entry name="W_Type_Section_Entry" isaggregate="true">
<Form name="form" encoding="leb128s" type="int8" count="1"/>
@@ -82,14 +82,14 @@
<Field_Len name="field_len" encoding="leb128u" type="uint32" couny="1"/>
<Field_Str name="field_str" type="string" count="1" size="self::Field_Len"/>
<Kind name="kind" encoding="leb128u" type="uint8" count="1"/>
- <Type name="type" conditional="true" condition="self::Kind">
- <condition0 encoding="leb128u" type="uint32">0</condition0>
- <condition1 type="Table_Type">1</condition1>
- <condition2 type="Memory_Type">2</condition2>
- <condition3 type="Global_Type">3</condition3>
+ <Type name="type" conditional="true" condition="self::Kind" type="FT::conditional">
+ <condition0 name="type" encoding="leb128u" type="uint32">0</condition0>
+ <condition1 name="type" type="self::Table_Type">1</condition1>
+ <condition2 name="type" type="self::Memory_Type">2</condition2>
+ <condition3 name="type" type="self::Global_Type">3</condition3>
</Type>
</Import_Section_Entry>
- <Global_Entry name="global_type_t" isaggregate="true">
+ <Global_Entry name="W_Global_Entry" isaggregate="true">
<Global_Type name="type" type="self::Global_Type" count="1"/>
<Init name="init" type="self::Init_Expr" count="1"/>
</Global_Entry>
@@ -112,10 +112,10 @@
<Function_Body name="W_Function_Body" isaggregate="true">
<Body_size name="body_size" encoding="leb128u" type="uint32" count="1"/>
<Local_Count name="local_count" encoding="leb128u" type="uint32" count="1"/>
- <Local_Entries name="locals" type="Local_Entry" count="self::Local_Count"/>
+ <Local_Entries name="locals" type="self::Local_Entry" count="self::Local_Count"/>
<Code name="code" type="uchar" count="self::Body_size"/>
</Function_Body>
- <Data_Segment>
+ <Data_Segment name="W_Data_Segment" isaggregate="true">
<Index name="index" encoding="leb128u" type="uint32" count="1"/>
<Offset name="offset" type="self::Init_Expr" count="1"/>
<Size name="size" encoding="leb128u" type="uint32" count="1"/>