aboutsummaryrefslogtreecommitdiffstats
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py56
1 files changed, 37 insertions, 19 deletions
diff --git a/main.py b/main.py
index 524a1ac..1802529 100755
--- a/main.py
+++ b/main.py
@@ -329,10 +329,10 @@ class CodeGen(object):
read_source.write(text.c_void_manager_proto.replace("XXX", "dummy->" + cond.attrib["name"]));
self.malloc_list.append(C_Obj(ref_node.attrib["name"], [elem.tag, child.tag]))
if child_count == 1:
- for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"]) + ";\n"
+ for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"]).replace("ZZZ", self.argparser.args.name + "_lib_ret->void_train") + ";\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"
+ for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"] + "[i]").replace("ZZZ", self.argparser.args.name + "_lib_ret->void_train") + ";\n"
read_source.write(for_read)
else: # child_count == -1
count_name_str = cond.attrib["count"][6:]
@@ -340,7 +340,7 @@ class CodeGen(object):
read_source.write("dummy->" + cond.attrib["name"] + " = " + "malloc(sizeof(void*)*" + "dummy->" + get_node_name(count_name_str, child) + ");\n")
read_source.write(text.c_void_manager_proto.replace("XXX", "dummy->" + cond.attri["name"]));
self.malloc_list.append(C_Obj("sizeof(void*)*dummy->"+get_node_name(count_name_str, child), [elem.attrib["name"], child.attrib["name"], cond.arrtib["name"]]))
- for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"] + "[i]") + ";\n"
+ for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"] + "[i]").replace("ZZZ", self.argparser.args.name + "_lib_ret->void_train") + ";\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:
@@ -385,17 +385,17 @@ class CodeGen(object):
if ref_node:
ref_node_name = pointer_remover(ref_node.attrib["name"])
if child_count == 1:
- for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + child.attrib["name"]) + ";\n"
+ for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + child.attrib["name"]).replace("ZZZ", self.argparser.args.name + "_lib_ret->void_train") + ";\n"
read_source.write("dummy->" + child.attrib["name"] + "=" + for_read)
elif child_count > 1:
- for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + child.attrib["name"] + "[i]") + ";\n"
+ for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + child.attrib["name"] + "[i]").replace("ZZZ", self.argparser.args.name + "_lib_ret->void_train") + ";\n"
read_source.write("dummy->" + child.attrib["name"] + "=" + for_read)
else: # child_count == -1
count_name_str = child.attrib["count"][6:]
read_source.write("if (" + "dummy->" + get_node_name(count_name_str, elem) + ")\n")
read_source.write("dummy->" + child.attrib["name"] + " = " + "malloc(sizeof(void*)*" + "dummy->" + get_node_name(count_name_str, elem) + ");\n")
read_source.write(text.c_void_manager_proto.replace("XXX", "dummy->" + child.attrib["name"]));
- for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + child.attrib["name"] + "[i]") + ";\n"
+ for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + child.attrib["name"] + "[i]").replace("ZZZ", self.argparser.args.name + "_lib_ret->void_train") + ";\n"
read_source.write(text.simple_loop.replace("YYY", "dummy->" + child.attrib["name"] + "[i]=" + for_read).replace("XXX", "dummy->" + get_node_name(count_name_str, elem)))
else:
for_read = str()
@@ -464,29 +464,40 @@ class CodeGen(object):
void_source = open(self.aggregate_source, "w")
void_source_h = open(self.aggregate_source_h, "w")
void_source.write("\n// automatically generated by faultreiber\n")
+ void_source_h.write("\n// automatically generated by faultreiber\n")
void_source.write("// " + self.dnt + "\n")
+ void_source_h.write("// " + self.dnt + "\n")
void_source.write('#include "./structs.h"\n')
void_source.write('#include "./read.h"\n')
void_source.write("#include <stdlib.h>\n")
- void_source.write("void** void_train;\n")
- void_source.write("uint64_t current_void_size = 0U;\n")
- void_source.write("uint64_t current_void_count = 0U;\n")
+ #void_source.write("void** void_train;\n")
+ #void_source.write("uint64_t current_void_size = 0U;\n")
+ #void_source.write("uint64_t current_void_count = 0U;\n")
void_source_h.write('#ifndef FT_AGGREGATE_H\n#define FT_AGGREGATE_H\n')
void_source_h.write('#ifdef __cplusplus\nextern "C" {\n#endif\n')
void_source_h.write('#include "./structs.h"\n')
# generating the extern declarations and definitions
+ void_source_h.write("typedef struct {\n")
for elem in self.read_elems:
count = get_elem_count(elem)
size = get_elem_size(elem)
if count != 1:
- void_source_h.write("extern " + elem.attrib["name"] + "** " + elem.attrib["name"] + "_container;\n")
- void_source.write(elem.attrib["name"] + "** " + elem.attrib["name"] + "_container;\n")
+ void_source_h.write(elem.attrib["name"] + "** " + elem.attrib["name"] + "_container;\n")
+ #void_source.write(elem.attrib["name"] + "** " + elem.attrib["name"] + "_container;\n")
else:
- void_source_h.write("extern " + elem.attrib["name"] + "* " + elem.attrib["name"] + "_container;\n")
- void_source.write(elem.attrib["name"] + "* " + elem.attrib["name"] + "_container;\n")
+ void_source_h.write(elem.attrib["name"] + "* " + elem.attrib["name"] + "_container;\n")
+ #void_source.write(elem.attrib["name"] + "* " + elem.attrib["name"] + "_container;\n")
+ void_source_h.write("}" + self.argparser.args.name + "_obj_t;\n")
+ #void_source_h.write(self.argparser.args.name + "_obj_t* obj;\n")
+ void_source_h.write("typedef struct {\n")
+ void_source_h.write(self.argparser.args.name + "_obj_t* obj;\n")
+ void_source_h.write("void** void_train;\n")
+ void_source_h.write("uint64_t* current_void_size;\n")
+ void_source_h.write("uint64_t* current_void_count;\n")
+ void_source_h.write("}" + self.argparser.args.name + "_lib_ret_t;\n")
# end
- void_source.write("void malloc_all(void) {\n")
- void_source_h.write("void malloc_all(void);\n")
+ #void_source.write("void malloc_all(void) {\n")
+ #void_source_h.write("void malloc_all(void);\n")
count_int = int()
count_void = int()
read_count = len(self.read_elems)
@@ -524,7 +535,11 @@ class CodeGen(object):
count_int = 0
count_void = 0
void_source.write("}\n")
- void_source.write("void read_aggr_"+self.argparser.args.name+"(int _fd) {\n")
+ void_source.write(self.argparser.args.name + "_lib_ret_t* read_aggr_"+self.argparser.args.name+"(int _fd) {\n")
+ void_source.write(self.argparser.args.name + "_lib_ret_t* lib_ret = malloc(sizeof("+self.argparser.args.name+"_lib_ret_t"+"));\n")
+ void_source.write("lib_ret->obj = malloc(sizeof("+self.argparser.args.name+"_obj_t"+"));\n")
+ void_source.write("lib_ret->current_void_size = malloc(sizeof(uint64_t*));\n")
+ void_source.write("lib_ret->current_void_count = malloc(sizeof(uint64_t*));\n")
for elem in self.read_elems:
if "isaggregate" in elem.attrib:
for child in elem:
@@ -538,7 +553,7 @@ class CodeGen(object):
agg_source = open(self.aggregate_source, "a")
agg_source_h = open(self.aggregate_source_h, "a")
print(self.argparser.args.name)
- agg_source_h.write("void read_aggr_"+self.argparser.args.name+"(int _fd);\n")
+ agg_source_h.write(self.argparser.args.name + "_lib_ret_t* read_aggr_"+self.argparser.args.name+"(int _fd);\n")
agg_source.write("uint8_t eof = 0U;")
for elem in self.read_elems:
if "unorderedbegin" in elem.attrib:
@@ -554,11 +569,12 @@ class CodeGen(object):
agg_source.write(text.c_read_gen.replace("XXX", sign_name).replace("YYY", sign_type))
agg_source.write("lseek(_fd, -sizeof(" + sign_type + "), SEEK_CUR);\n")
agg_source.write("if (" + sign_name + "==" + child.text + "){\n")
- agg_source.write(elem.attrib["name"] + "_container = " + "ft_read_" + elem.attrib["name"] + "(_fd," + elem.attrib["name"] + "_container" + ");\n")
+ agg_source.write("lib_ret->obj->"+elem.attrib["name"] + "_container = " + "ft_read_" + elem.attrib["name"] + "(_fd, lib_ret->obj->" + elem.attrib["name"] + "_container" + "lib_ret->void_train);\n")
if "unordered" in elem.attrib: agg_source.write("}\n")
if "unorderedend" in elem.attrib:
agg_source.write("}while(0);\n")
+ agg_source.write("return lib_ret;\n")
agg_source.write("}\n")
#FIXME-not handling double pointers
@@ -571,6 +587,8 @@ class CodeGen(object):
agg_source.write("free(void_train[i]);\n}\n")
agg_source.write("free(void_train);\n")
agg_source.write("}\n")
+ agg_source_h.write('#ifdef __cplusplus\n}\n#endif\n')
+ agg_source_h.write("#endif //end of header guard\n\n")
def gen_return(self):
agg_source = open(self.aggregate_source, "a")
@@ -692,7 +710,7 @@ class CodeGen(object):
self.gen_void_train()
self.gen_aggregate_read()
self.gen_release()
- self.gen_return()
+ #self.gen_return()
# write code here
def premain(argparser):