aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2018-08-10 13:46:06 +0000
committerbloodstalker <thabogre@gmail.com>2018-08-10 13:46:06 +0000
commit20dccb3ab45137d504220880020ceb571f0af61d (patch)
tree35e904f284f590ecc079e0dd89abe902a1fe3bf2
parentupdate (diff)
downloadfaultreiber-20dccb3ab45137d504220880020ceb571f0af61d.tar.gz
faultreiber-20dccb3ab45137d504220880020ceb571f0af61d.zip
update
Diffstat (limited to '')
-rwxr-xr-xmain.py12
-rw-r--r--test/autowasm.c61
2 files changed, 31 insertions, 42 deletions
diff --git a/main.py b/main.py
index 4752ce6..9d43c59 100755
--- a/main.py
+++ b/main.py
@@ -358,7 +358,7 @@ class CodeGen(object):
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")
for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + child.attrib["name"] + "[i]") + ";\n"
- read_source.write(text.simple_loop.replace("YYY", for_read).replace("XXX", "dummy->" + get_node_name(count_name_str, elem)))
+ 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()
if child_count == 1: array_subscript = ""
@@ -391,6 +391,7 @@ class CodeGen(object):
# instances with the same name
else:
read_source.write(static + inline + text.c_read_elem_sig.replace("YYY", elem.attrib["name"]).replace("XXX", elem.attrib["name"]+pointer))
+ read_source.write("dummy = malloc(sizeof(" + elem.attrib["name"] + "));\n")
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")
@@ -421,8 +422,10 @@ class CodeGen(object):
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")
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")
for child in elem:
ref_node_name = type_resolver(child, self.def_elems)
@@ -431,8 +434,10 @@ class CodeGen(object):
count = get_elem_count(child)
size = get_elem_size(child)
if count != 1:
+ void_source_h.write("extern " + ref_node.attrib["name"] + "** " + elem.attrib["name"] + "_" + child.attrib["name"] + "_container;\n")
void_source.write(ref_node.attrib["name"] + "** " + elem.attrib["name"] + "_" + child.attrib["name"] + "_container;\n")
else:
+ void_source_h.write("extern " + ref_node.attrib["name"] + "* " + elem.attrib["name"] + "_" + child.attrib["name"] + "_container;\n")
void_source.write(ref_node.attrib["name"] + "* " + elem.attrib["name"] + "_" + child.attrib["name"] + "_container;\n")
void_source.write("void malloc_all(void) {\n")
void_source_h.write("void malloc_all(void);\n")
@@ -490,14 +495,15 @@ 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:
- void_source.write(elem.attrib["name"] + "_container->" + child.attrib["name"] + " = " + elem.attrib["name"] + "_" + child.attrib["name"] + "_container" + ";\n")
+ pass
+ #void_source.write(elem.attrib["name"] + "_container->" + child.attrib["name"] + " = " + elem.attrib["name"] + "_" + child.attrib["name"] + "_container" + ";\n")
def gen_aggregate_read(self):
agg_source = open(self.aggregate_source, "a")
agg_source_h = open(self.aggregate_source_h, "a")
agg_source_h.write("void read_aggr(int _fd);\n")
for elem in self.read_elems:
- agg_source.write("ft_read_" + elem.attrib["name"] + "(_fd," + elem.attrib["name"] + "_container" + ");\n")
+ agg_source.write(elem.attrib["name"] + "_container = " + "ft_read_" + elem.attrib["name"] + "(_fd," + elem.attrib["name"] + "_container" + ");\n")
agg_source.write("}\n")
#FIXME-not handling double pointers
diff --git a/test/autowasm.c b/test/autowasm.c
index 0ea860a..986b1d0 100644
--- a/test/autowasm.c
+++ b/test/autowasm.c
@@ -12,47 +12,30 @@
#pragma weak main
int main (int argc, char** argv) {
int wasm = open("./test.wasm", O_RDONLY);
- malloc_all();
read_aggr(wasm);
- magic_number* mn = ft_ret_magic_number();
- version* v = ft_ret_version();
- W_Type_Section* ts = ft_ret_W_Type_Section();
-#if 0
- printf("magic_number:%x\n", mn->magic_number);
- printf("version:%d\n", v->version);
- printf("type section id:%d\n", ts->id);
- printf("type section payloadlength:%d\n", ts->payloadlength);
- printf("type_section entry count:%d\n", ts->count);
-#endif
- for (int i=0; i < 7; ++i) {
- //printf("param_count:%d\n",ts->entries[i]->param_count);
- //printf("param_count:%d\n",ts->entries[i]);
- }
-
-#if 0
- uint64_t test_u = 0U;
- int64_t test_s = 0;
- unsigned char test_byte;
- unsigned char byte;
- uint32_t word;
- uint32_t counter = 0U;
-
- read(wasm, &word, 8);
- printf("test_byte:%08x\n", word);
- lseek(wasm, 9, SEEK_SET);
- read(wasm, &word, 8);
- printf("test_byte:%08x\n", word);
-
- lseek(wasm, 9, SEEK_SET);
- test_u = read_leb_128_u(wasm, 5);
- printf("read u res is: %lu.\n", test_u);
- lseek(wasm, 0, SEEK_SET);
- while(read(wasm, &word, sizeof(uint32_t))) {
- printf("%d:%02x\t", counter, word);
- counter++;
+ printf("magic_number:%x\n", magic_number_container->magic_number);
+ printf("version:%x\n", version_container->version);
+ printf("type section id:%d\n", W_Type_Section_container->id);
+ printf("type section payloadlength:%d\n", W_Type_Section_container->payloadlength);
+ printf("type_section entry count:%d\n", W_Type_Section_container->count);
+ for (int i=0; i < W_Type_Section_container->count; ++i) {
+ printf("param_count:%d\n",W_Type_Section_container->entries[i]->param_count);
+ for (int j = 0; j < W_Type_Section_container->entries[i]->param_count; ++j)
+ printf("param_types:%d\n",W_Type_Section_container->entries[i]->param_types[j]);
+ printf("return_count:%d\n", W_Type_Section_container->entries[i]->return_count);
+ for (int j = 0; j < W_Type_Section_container->entries[i]->return_count; ++j)
+ printf("param_types:%d\n",W_Type_Section_container->entries[i]->return_types[j]);
+ }
+ printf("import_section_id:%d\n", W_Import_Section_container->id);
+ printf("import_section_payloadlength:%d\n", W_Import_Section_container->payloadlength);
+ printf("import_section_count:%d\n", W_Import_Section_container->count);
+ for(int i = 0; i < W_Import_Section_container->count; ++i) {
+ printf("import_section_entry_module_length:%d\n", W_Import_Section_container->entries[i]->module_length);
+ printf("module_str:%s\n", W_Import_Section_container->entries[i]->module_str);
+ printf("import_section_entry_field_length:%d\n", W_Import_Section_container->entries[i]->field_len);
}
- printf("\n");
-#endif
+
+ release_all();
return 0;
}