aboutsummaryrefslogtreecommitdiffstats
path: root/main.py
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2018-07-22 13:01:57 +0000
committerbloodstalker <thabogre@gmail.com>2018-07-22 13:01:57 +0000
commitb88c0585fedfb24e8cee1b763b55dddbdd50e953 (patch)
tree9e201affd6167d01403af3f68aa85f5047f96577 /main.py
parentupdate (diff)
downloadfaultreiber-b88c0585fedfb24e8cee1b763b55dddbdd50e953.tar.gz
faultreiber-b88c0585fedfb24e8cee1b763b55dddbdd50e953.zip
update
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/main.py b/main.py
index c5ff396..25fd6a1 100755
--- a/main.py
+++ b/main.py
@@ -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")