aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2019-01-20 10:35:16 +0000
committerbloodstalker <thabogre@gmail.com>2019-01-20 10:35:16 +0000
commitf49cec66f5afbfd549903c023dad179c01dc4bd1 (patch)
tree4acc89b8ba5f7b4e80b8c4582284d6b12f1bbd59
parentupdate (diff)
downloadfaultreiber-f49cec66f5afbfd549903c023dad179c01dc4bd1.tar.gz
faultreiber-f49cec66f5afbfd549903c023dad179c01dc4bd1.zip
update
Diffstat (limited to '')
-rwxr-xr-xmain.py44
-rw-r--r--text.py12
2 files changed, 36 insertions, 20 deletions
diff --git a/main.py b/main.py
index 348d37e..3572c28 100755
--- a/main.py
+++ b/main.py
@@ -290,8 +290,13 @@ class CodeGen(object):
if self.argparser.args.calloc: read_source.write(text.ft_calloc_def)
if self.argparser.args.luaalloc: read_source.write(text.ft_luanewuserdata_def)
read_sig_zzz = str()
- if self.argparser.args.luaalloc: read_sig_zzz = ", lua_State* __ls"
- else: read_sig_zzz = ""
+ read_proto_zzz = str()
+ if self.argparser.args.luaalloc:
+ read_sig_zzz = "lua_State* __ls"
+ read_proto_zzz = "__ls"
+ else:
+ read_sig_zzz = "void*** void_train"
+ read_proto_zzz = "void_train"
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:
@@ -362,12 +367,12 @@ class CodeGen(object):
else: read_source.write(text.lua_udata_regindex.replace("XXX", elem.attrib["name"]).replace("YYY", "(*dummy)"))
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"]).replace("ZZZ", "void_train").replace("WWW", read_sig_zzz) + ";\n"
+ for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + cond.attrib["name"]).replace("ZZZ", read_proto_zzz) + ";\n"
read_source.write(for_read)
if count_version:
count_version_buffer += 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]").replace("ZZZ", "void_train").replace("WWW", read_sig_zzz) + ";\n"
+ for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + cond.attrib["name"] + "[i]").replace("ZZZ", read_proto_zzz) + ";\n"
if count_version:
count_version_buffer += for_read
read_source.write(for_read)
@@ -377,7 +382,7 @@ class CodeGen(object):
read_source.write("(*dummy)->" + cond.attrib["name"] + " = " + alloc+"(sizeof(void*)*" + "(*dummy)->" + get_node_name(count_name_str, child) + ");\n")
if not lua_udata_set: 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]").replace("ZZZ", "void_train").replace("WWW", read_sig_zzz) + ";\n"
+ for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + cond.attrib["name"] + "[i]").replace("ZZZ", read_proto_zzz) + ";\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")
if count_version:
@@ -426,18 +431,18 @@ class CodeGen(object):
if child_count == 1:
if "sizeconst" in child.attrib:
if "sizeconst" != "end":
- for_read = text.c_read_elem_sig_2_c.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + child.attrib["name"]).replace("ZZZ", "void_train").replace("WWW", read_sig_zzz) + ";\n"
+ for_read = text.c_read_elem_sig_2_c.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + child.attrib["name"]).replace("ZZZ", read_proto_zzz) + ";\n"
else:
- for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + child.attrib["name"]).replace("ZZZ", "void_train").replace("WWW", read_sig_zzz) + ";\n"
+ for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + child.attrib["name"]).replace("ZZZ", read_proto_zzz) + ";\n"
read_source.write("(*dummy)->" + child.attrib["name"] + "=" + for_read)
if count_version:
count_version_buffer += "(*dummy)->" + child.attrib["name"] + "=" + for_read
elif child_count > 1:
if "sizeconst" in child.attrib:
if "sizeconst" != "end":
- for_read = text.c_read_elem_sig_2_c.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + child.attrib["name"] + "[i]").replace("ZZZ", "void_train").replace("WWW", read_sig_zzz) + ";\n"
+ for_read = text.c_read_elem_sig_2_c.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + child.attrib["name"] + "[i]").replace("ZZZ", read_proto_zzz) + ";\n"
else:
- for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + child.attrib["name"] + "[i]").replace("ZZZ", "void_train").replace("WWW", read_sig_zzz) + ";\n"
+ for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + child.attrib["name"] + "[i]").replace("ZZZ", read_proto_zzz) + ";\n"
read_source.write("(*dummy)->" + child.attrib["name"] + "=" + for_read)
if count_version:
count_version_buffer += "(*dummy)->" + child.attrib["name"] + "=" + for_read
@@ -448,9 +453,9 @@ class CodeGen(object):
if not lua_udata_set: read_source.write(text.c_void_manager_proto.replace("XXX", "(*dummy)->" + child.attrib["name"]));
if "sizeconst" in child.attrib:
if "sizeconst" != "end":
- for_read = text.c_read_elem_sig_2_c.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + child.attrib["name"] + "[i]").replace("ZZZ", "void_train").replace("WWW", read_sig_zzz) + ";\n"
+ for_read = text.c_read_elem_sig_2_c.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + child.attrib["name"] + "[i]").replace("ZZZ", read_proto_zzz)+ ";\n"
else:
- for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + child.attrib["name"] + "[i]").replace("ZZZ", "void_train").replace("WWW", read_sig_zzz) + ";\n"
+ for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "&(*dummy)->" + child.attrib["name"] + "[i]").replace("ZZZ", read_proto_zzz) + ";\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)))
if count_version:
count_version_buffer += text.simple_loop.replace("YYY", "(*dummy)->" + child.attrib["name"] + "[i]=" + for_read).replace("XXX", "(*dummy)->" + get_node_name(count_name_str, elem))
@@ -681,9 +686,15 @@ class CodeGen(object):
agg_source.write("lseek(_fd, -sizeof(" + sign_type + "), SEEK_CUR);\n")
agg_source.write("if (" + sign_name + "==" + child.text + "){\n")
if elem.attrib["count"] != "*":
- 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, &lib_ret->current_void_size, &lib_ret->current_void_count);\n")
+ if self.argparser.args.luaalloc:
+ agg_source.write("lib_ret->obj->"+elem.attrib["name"] + "_container = " + "ft_read_" + elem.attrib["name"] + "(_fd, &lib_ret->obj->" + elem.attrib["name"] + "_container, " + "__ls, &lib_ret->current_void_size, &lib_ret->current_void_count);\n")
+ else:
+ 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, &lib_ret->current_void_size, &lib_ret->current_void_count);\n")
else:
- agg_source.write("lib_ret->obj->" + elem.attrib["name"] + "_container = realloc(lib_ret->obj->"+elem.attrib["name"]+"_container,"+"sizeof("+elem.attrib["name"]+")*("+elem.attrib["name"]+"_agg_count"+" +1));\n")
+ if self.argparser.args.luaalloc:
+ agg_source.write("lib_ret->obj->" + elem.attrib["name"] + "_container = realloc(lib_ret->obj->"+elem.attrib["name"]+"_container,"+"sizeof("+elem.attrib["name"]+")*("+elem.attrib["name"]+"_agg_count"+" +1));\n")
+ else:
+ agg_source.write("lib_ret->obj->" + elem.attrib["name"] + "_container = realloc(lib_ret->obj->"+elem.attrib["name"]+"_container,"+"sizeof("+elem.attrib["name"]+")*("+elem.attrib["name"]+"_agg_count"+" +1));\n")
agg_source.write("lib_ret->obj->"+elem.attrib["name"] + "_container["+elem.attrib["name"]+"_agg_count"+"] = " + "ft_read_" + elem.attrib["name"] + "(_fd, &lib_ret->obj->" + elem.attrib["name"] + "_container["+elem.attrib["name"]+"_agg_count"+"], " + "&lib_ret->void_train, &lib_ret->current_void_size, &lib_ret->current_void_count);\n")
agg_source.write(elem.attrib["name"] + "_agg_count++;\n")
if "unordered" in elem.attrib: agg_source.write("}\n")
@@ -821,7 +832,7 @@ class CodeGen(object):
def run(self):
alloc = str()
if self.argparser.args.calloc: alloc = "ft_calloc"
- if self.argparser.args.luaalloc: alloc = "ft_lua_newuserdata"
+ elif self.argparser.args.luaalloc: alloc = "ft_lua_newuserdata"
else: alloc = "malloc"
self.init()
self.init_hook()
@@ -833,7 +844,12 @@ class CodeGen(object):
pass
else:
self.gen_void_train(alloc)
+ self.gen_void_train(alloc)
self.gen_aggregate_read()
+ if self.argparser.args.luaalloc:
+ pass
+ else:
+ self.gen_release()
self.gen_release()
#self.gen_return()
diff --git a/text.py b/text.py
index e99b78f..b4b937c 100644
--- a/text.py
+++ b/text.py
@@ -11,13 +11,13 @@ class text():
autogen_warning = "// 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 = "void* ft_read_YYY(int _fd, XXX** dummy, void*** void_train, uint64_t* current_void_size, uint64_t* current_void_count ZZZ) {\n"
- c_read_elem_sig_h = "void* ft_read_YYY(int _fd, XXX** dummy, void*** void_train, uint64_t* current_void_size, uint64_t* current_void_count ZZZ);\n"
- c_read_elem_sig_c = "void* ft_read_YYY_c(int _fd, XXX** dummy, void*** void_train, uint64_t* current_void_size, uint64_t* current_void_count, uint64_t* agg_b_count ZZZ) {\n"
- c_read_elem_sig_h_c = "void* ft_read_YYY_c(int _fd, XXX** dummy, void*** void_train, uint64_t* current_void_size, uint64_t* current_void_count, uint64_t* agg_b_count ZZZ);\n"
+ c_read_elem_sig = "void* ft_read_YYY(int _fd, XXX** dummy, ZZZ, uint64_t* current_void_size, uint64_t* current_void_count) {\n"
+ c_read_elem_sig_h = "void* ft_read_YYY(int _fd, XXX** dummy, ZZZ, uint64_t* current_void_size, uint64_t* current_void_count);\n"
+ c_read_elem_sig_c = "void* ft_read_YYY_c(int _fd, XXX** dummy, ZZZ, uint64_t* current_void_size, uint64_t* current_void_count, uint64_t* agg_b_count) {\n"
+ c_read_elem_sig_h_c = "void* ft_read_YYY_c(int _fd, XXX** dummy, ZZZ, uint64_t* current_void_size, uint64_t* current_void_count, uint64_t* agg_b_count);\n"
#c_read_elem_sig_1 = "ft_read_XXX(_fd)"
- c_read_elem_sig_2 = "ft_read_XXX(_fd, YYY, ZZZ, current_void_size, current_void_count WWW)"
- c_read_elem_sig_2_c = "ft_read_XXX_c(_fd, YYY, ZZZ, current_void_size, current_void_count, &agg_b_count WWW)"
+ c_read_elem_sig_2 = "ft_read_XXX(_fd, YYY, ZZZ, current_void_size, current_void_count)"
+ c_read_elem_sig_2_c = "ft_read_XXX_c(_fd, YYY, ZZZ, current_void_size, current_void_count, &agg_b_count)"
c_open_file = "int ft_read_file = open(_ft_file_path, RDONLY);\n"
c_function_close = "}\n"
c_function_dummy_dec = "XXX dummy;\n"