diff options
author | bloodstalker <thabogre@gmail.com> | 2018-08-06 22:33:24 +0000 |
---|---|---|
committer | bloodstalker <thabogre@gmail.com> | 2018-08-06 22:33:24 +0000 |
commit | c2f25957235be95ff66100b2b6b735d58a46575c (patch) | |
tree | a02ff00f95caf79fe926c4151c0cce5e96b5a2b9 /main.py | |
parent | update (diff) | |
download | faultreiber-c2f25957235be95ff66100b2b6b735d58a46575c.tar.gz faultreiber-c2f25957235be95ff66100b2b6b735d58a46575c.zip |
update
Diffstat (limited to '')
-rwxr-xr-x | main.py | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -296,6 +296,55 @@ class CodeGen(object): if size == -1: ref_size = "dummy->" + get_node_name(child.attrib["size"][6:], elem) + if "conditional" in child.attrib: + cond_name = get_node_name(child.attrib["condition"][6:], elem) + for cond in child: + child_count = get_elem_count(cond) + ref_node_name = type_resolver(cond, self.def_elems) + ref_node = get_def_node(ref_node_name, self.def_elems) + if ref_node: + read_source.write("if (dummy->" + cond_name + "==" + str(cond.text) + "){\n") + read_source.write("dummy->" + cond.attrib["name"] + "=malloc(sizeof(" + ref_node.attrib["name"] + "));") + if child_count == 1: + for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"]) + ";\n" + read_source.write(for_read) + elif child_count > 1: + for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"] + "[i]") + ";\n" + read_source.write(for_read) + else: # child_count == -1 + count_name_str = cond.attrib["count"][6:] + read_source.write("if (" + "dummy->" + get_node_name(count_name_str, elem) + ")\n") + read_source.write("dummy->" + cond.attrib["name"] + " = " + "malloc(sizeof(void*)*" + "dummy->" + get_node_name(count_name_str, child) + ");\n") + for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"] + "[i]") + ";\n" + read_source.write(text.simple_loop.replace("YYY", for_read).replace("XXX", "dummy->" + get_node_name(count_name_str, child))) + read_source.write("}\n") + else: + read_source.write("if (dummy->" + cond_name + "==" + str(cond.text) + "){\n") + read_source.write("dummy->" + cond.attrib["name"] + "=malloc(sizeof(" + ref_node_name + "));") + for_read = str() + if child_count == 1: array_subscript = "" + elif child_count > 1: array_subscript = "[i]" + else: array_subscript = "[i]" + if "size" in cond.attrib: + if "encoding" in cond.attrib: + for_read = "dummy->" + cond.attrib["name"] + array_subscript + "=" + get_encoding_read(cond.attrib["encoding"]) + else: + for_read = text.c_read_gen_2.replace("XXX", "dummy" + "->"+ cond.attrib["name"] + array_subscript).replace("YYY", ref_size) + else: + if "encoding" in cond.attrib: + for_read = "dummy->" + cond.attrib["name"] + array_subscript + " = " + get_encoding_read(cond.attrib["encoding"]) + else: + for_read = text.c_read_gen.replace("XXX", "dummy" + "->" + cond.attrib["name"] + array_subscript).replace("YYY", ref_node_name) + if child_count == 1: + read_source.write(for_read) + elif child_count > 1: + read_source.write(text.simple_loop.replace("YYY", for_read).replace("XXX", str(child_count))) + else: # child_count = -1 + count_name_str = cond.attrib["count"][6:] + read_source.write("dummy->" + cond.attrib["name"] + " = " + "malloc(sizeof(" + type_resolver(cond, self.def_elems + self.read_elems) + ")*" + "dummy->" + get_node_name(count_name_str, elem) + ");\n") + read_source.write("if (" + "dummy->" + get_node_name(count_name_str, child) + ")\n") + read_source.write(text.simple_loop.replace("YYY", for_read).replace("XXX", "dummy->" + get_node_name(count_name_str, elem))) + read_source.write("}\n") if ref_node: ref_node_name = pointer_remover(ref_node.attrib["name"]) if child_count == 1: @@ -344,6 +393,7 @@ class CodeGen(object): 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_read_gen.replace("XXX", "dummy->" + elem.attrib["name"]).replace("YYY", type_resolver(elem, self.def_elems))) #read_source.write(text.c_function_return_type) + read_source.write("return dummy;\n") read_source.write(text.c_function_close + "\n") read_source_header = open(self.argparser.args.outdir + "/read.h", "w") read_source_header.write("#ifndef FT_READ_H\n#define FT_READ_H\n") |