aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmain.py8
-rw-r--r--test/autowasm.c2
-rw-r--r--text.py20
3 files changed, 15 insertions, 15 deletions
diff --git a/main.py b/main.py
index d0a3687..76dbe2a 100755
--- a/main.py
+++ b/main.py
@@ -537,7 +537,7 @@ class CodeGen(object):
count_void = 0
#void_source.write("}\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("register " + 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")
@@ -571,7 +571,7 @@ 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("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")
+ 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 "unordered" in elem.attrib: agg_source.write("}\n")
if "unorderedend" in elem.attrib:
@@ -583,8 +583,8 @@ class CodeGen(object):
def gen_release(self):
agg_source = open(self.aggregate_source, "a")
agg_source_h = open(self.aggregate_source_h, "a")
- agg_source_h.write("void release_all(void);\n")
- agg_source.write("void release_all(void) {\n")
+ agg_source_h.write("void release_all(void** void_train, uint64_t current_void_count);\n")
+ agg_source.write("void release_all(void** void_train, uint64_t current_void_count) {\n")
agg_source.write("for (int i=current_void_count-1;i>=0;--i) {\n")
agg_source.write("free(void_train[i]);\n}\n")
agg_source.write("free(void_train);\n")
diff --git a/test/autowasm.c b/test/autowasm.c
index 769cc1e..37bbbe5 100644
--- a/test/autowasm.c
+++ b/test/autowasm.c
@@ -138,6 +138,6 @@ int main (int argc, char** argv) {
printf("\n");
}
- release_all();
+ release_all(lib_ret->void_train, lib_ret->current_void_count);
return 0;
}
diff --git a/text.py b/text.py
index f64e478..15b517d 100644
--- a/text.py
+++ b/text.py
@@ -15,10 +15,10 @@ class text():
#c_read_elem_sig = "void ft_read_YYY(int _fd, XXX* dummyZZZ) {\n"
#c_read_elem_sig = "void ft_read_YYY(int _fd, XXX* dummy) {\n"
#c_read_elem_sig_h = "void ft_read_YYY(int _fd, XXX* dummy);\n"
- c_read_elem_sig = "void* ft_read_YYY(int _fd, XXX* dummy, void** void_train) {\n"
- c_read_elem_sig_h = "void* ft_read_YYY(int _fd, XXX* dummy, void** void_train);\n"
+ 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) {\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);\n"
c_read_elem_sig_1 = "ft_read_XXX(_fd)"
- c_read_elem_sig_2 = "ft_read_XXX(_fd, YYY, ZZZ)"
+ c_read_elem_sig_2 = "ft_read_XXX(_fd, YYY, ZZZ, current_void_size, current_void_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"
@@ -83,28 +83,28 @@ int32_t read_until_delimiter(int _fd, uint8_t delimiter) {
}"""
c_void_manager = """
-void void_manager(void* ptr, void** void_train) {
+void void_manager(void* ptr, void** void_train, uint64_t* current_void_size, uint64_t* current_void_count) {
if (current_void_size == 0) {
void_train = malloc(100*sizeof(void*));
current_void_size = 100;
}
if (current_void_count == current_void_size) {
- current_void_size*=2;
- void_train = realloc(void_train, current_void_size*sizeof(void*));
+ *current_void_size*=2;
+ void_train = realloc(void_train, *current_void_size*sizeof(void*));
if (void_train == NULL) {
printf("void train couldnt allocate more memory.\\n");
}
}
- void_train[current_void_count] = ptr;
- current_void_count++;
+ void_train[*current_void_count] = ptr;
+ *current_void_count++;
}"""
c_read_leb_128_s_sig = "int64_t read_leb_128_s(int _fd, int max_size);\n"
c_read_leb_128_u_sig = "uint64_t read_leb_128_u(int _fd, int max_size);\n"
c_read_until_delimiter_sig = "int32_t read_until_delimiter(int _fd, uint8_t delimiter);\n"
c_read_until_delimiter_proto = "read_until_delimiter(_fd, XXX)"
- c_void_manager_sig = "void void_manager(void* ptr, void** void_train);"
- c_void_manager_proto = "void_manager(XXX, void_train);"
+ c_void_manager_sig = "void void_manager(void* ptr, void** void_train, uint64_t* current_void_size, uint64_t* current_void_count);"
+ c_void_manager_proto = "void_manager(XXX, void_train, current_void_size, current_void_count);"
c_read_leb_macro_defs = """
#define READ_VAR_UINT_1(FD) read_leb128_u(FD, 1)