diff options
author | bloodstalker <thabogre@gmail.com> | 2018-07-11 12:42:47 +0000 |
---|---|---|
committer | bloodstalker <thabogre@gmail.com> | 2018-07-11 12:42:47 +0000 |
commit | c3e73915a96783535663aa51dfcbfb494e9b6c1c (patch) | |
tree | 9e807c8ca11dedb591f706ae07abed646104b65f | |
parent | update (diff) | |
download | faultreiber-c3e73915a96783535663aa51dfcbfb494e9b6c1c.tar.gz faultreiber-c3e73915a96783535663aa51dfcbfb494e9b6c1c.zip |
update
-rwxr-xr-x | main.py | 25 | ||||
-rw-r--r-- | text.py | 7 |
2 files changed, 29 insertions, 3 deletions
@@ -131,6 +131,25 @@ class CodeGen(object): def gen_reader_funcs(self): read_source = open(self.argparser.args.outdir + "/read.c", "w") read_source.write(text.header_list) + for elem in self.def_elems: + read_source.write(text.c_read_elem_sig.replace("YYY", elem.attrib["name"]).replace("XXX", elem.attrib["name"])) + read_source.write(text.c_function_dummy_dec.replace("XXX", elem.attrib["name"])) + if "isaggregate" in elem.attrib: + for child in elem: + ref_node_name = type_resolver(child, self.def_elems) + ref_node = get_def_node(ref_node_name, self.def_elems) + if ref_node: + read_source.write(ref_node.attrib["name"] + " " + ref_node.attrib["name"] + "_ins" + "=") + read_source.write(text.c_read_elem_sig_1.replace("XXX", ref_node.attrib["name"]) + ";\n") + read_source.write("dummy." + child.attrib["name"] + "=" +ref_node.attrib["name"]+"_ins" + ";\n") + else: + read_source.write(ref_node_name + " " + ref_node_name+"_ins" + ";\n") + read_source.write(text.c_read_gen.replace("XXX", ref_node_name+"_ins").replace("YYY", ref_node_name)) + read_source.write("dummy." + child.attrib["name"] + "=" +ref_node_name+"_ins" + ";\n") + else: + read_source.write(type_resolver(elem, self.elems) + " " + elem.attrib["name"] + ";\n") + read_source.write(text.c_function_return_type) + read_source.write(text.c_function_close + "\n") for elem in self.read_elems: read_source.write(text.c_read_elem_sig.replace("YYY", elem.attrib["name"]).replace("XXX", elem.attrib["name"])) read_source.write(text.c_function_dummy_dec.replace("XXX", elem.attrib["name"])) @@ -139,7 +158,13 @@ class CodeGen(object): ref_node_name = type_resolver(child, self.def_elems) ref_node = get_def_node(ref_node_name, self.def_elems) if ref_node: + read_source.write(ref_node.attrib["name"] + " " + ref_node.attrib["name"] + "_ins" + "=") read_source.write(text.c_read_elem_sig_1.replace("XXX", ref_node.attrib["name"]) + ";\n") + read_source.write("dummy." + child.attrib["name"] + "=" +ref_node.attrib["name"]+"_ins" + ";\n") + else: + read_source.write(ref_node_name + " " + ref_node_name+"_ins" + ";\n") + read_source.write(text.c_read_gen.replace("XXX", ref_node_name+"_ins").replace("YYY", ref_node_name)) + read_source.write("dummy." + child.attrib["name"] + "=" +ref_node_name+"_ins" + ";\n") else: read_source.write(type_resolver(elem, self.elems) + " " + elem.attrib["name"] + ";\n") read_source.write(text.c_function_return_type) @@ -1,7 +1,7 @@ # _*_ coding=utf-8 _*_ class text(): - header_list = """#include <fcntl.h>\n#include <inttypes.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <unistd.h>\n""" + header_list = """#include <fcntl.h>\n#include <inttypes.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <unistd.h>\n#include <string.h>\n""" header_inttype = "#include <inttypes.h>\n" main_sig = 'int main(int argc, char** argv)' pragma_weak_main = '#pragma weak main' @@ -11,8 +11,8 @@ class text(): autogen_warning = "// this file has been automatically generated by faultreiber\n" last_comment = "// last line intentionally left blank\n\n" read_func_sig = "int read_structured_file(char* path)" - c_read_elem_sig = "XXX ft_read_YYY(char* _ft_file_path, int _fd) {\n" - c_read_elem_sig_1 = "ft_read_XXX(_ft_file_path, _fd)" + c_read_elem_sig = "XXX ft_read_YYY(int _fd) {\n" + c_read_elem_sig_1 = "ft_read_XXX(_fd)" c_open_file = "int ft_read_file = open(_ft_file_path, RDONLY);\n" c_function_close = "}\n" c_function_dummy_dec = "XXX dummy;\n" @@ -25,4 +25,5 @@ class text(): c_read_2 = "read(_fd, &XXX, sizeof(uint16_t));\n" c_read_4 = "read(_fd, &XXX, sizeof(uint32_t));\n" c_read_8 = "read(_fd, &XXX, sizeof(uint64_t));\n" + c_read_gen = "read(_fd, &XXX, sizeof(YYY));\n" c_assign_struct = "XXX.YYY = ZZZ;\n" |