aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmain.py25
-rw-r--r--test/autowasm.c14
-rw-r--r--text.py2
3 files changed, 35 insertions, 6 deletions
diff --git a/main.py b/main.py
index 9d43c59..335935f 100755
--- a/main.py
+++ b/main.py
@@ -329,12 +329,20 @@ class CodeGen(object):
if "encoding" in cond.attrib:
for_read = "dummy->" + cond.attrib["name"] + array_subscript + "=" + get_encoding_read(cond.attrib["encoding"])
else:
- for_read = text.c_read_gen_2.replace("XXX", "dummy" + "->"+ cond.attrib["name"] + array_subscript).replace("YYY", ref_size)
+ if cond.attrib["name"] == "string":
+ for_read = "dummy->" + cond.attrib["name"] + " = " + "malloc(" + ref_size + "+1);\n"
+ for_read += "dummy->" + cond.attrib["name"] + "["+ref_size+"]=" + "0;\n"
+ for_read = text.c_read_gen_2_no.replace("XXX", "dummy" + "->"+ cond.attrib["name"] + array_subscript).replace("YYY", ref_size)
+ else:
+ for_read = text.c_read_gen_2.replace("XXX", "dummy" + "->"+ cond.attrib["name"] + array_subscript).replace("YYY", ref_size)
else:
if "encoding" in cond.attrib:
for_read = "dummy->" + cond.attrib["name"] + array_subscript + " = " + get_encoding_read(cond.attrib["encoding"])
else:
- for_read = text.c_read_gen.replace("XXX", "dummy" + "->" + cond.attrib["name"] + array_subscript).replace("YYY", ref_node_name)
+ if cond.attrib["type"] == "string":
+ for_read = text.c_read_gen_no.replace("XXX", "dummy" + "->" + cond.attrib["name"] + array_subscript).replace("YYY", ref_node_name)
+ else:
+ for_read = text.c_read_gen.replace("XXX", "dummy" + "->" + cond.attrib["name"] + array_subscript).replace("YYY", ref_node_name)
if child_count == 1:
read_source.write(for_read)
elif child_count > 1:
@@ -345,6 +353,7 @@ class CodeGen(object):
read_source.write("if (" + "dummy->" + get_node_name(count_name_str, child) + ")\n")
read_source.write(text.simple_loop.replace("YYY", for_read).replace("XXX", "dummy->" + get_node_name(count_name_str, elem)))
read_source.write("}\n")
+ continue
if ref_node:
ref_node_name = pointer_remover(ref_node.attrib["name"])
if child_count == 1:
@@ -368,12 +377,20 @@ class CodeGen(object):
if "encoding" in child.attrib:
for_read = "dummy->" + child.attrib["name"] + array_subscript + "=" + get_encoding_read(child.attrib["encoding"])
else:
- for_read = text.c_read_gen_2.replace("XXX", "dummy" + "->"+ child.attrib["name"] + array_subscript).replace("YYY", ref_size)
+ if child.attrib["type"] == "string":
+ for_read = "dummy->" + child.attrib["name"] + " = " + "malloc(" + ref_size + "+1);\n"
+ for_read += "dummy->" + child.attrib["name"] + "["+ref_size+"]=" + "0;\n"
+ for_read += text.c_read_gen_2_no.replace("XXX", "dummy" + "->"+ child.attrib["name"] + array_subscript).replace("YYY", ref_size)
+ else:
+ for_read = text.c_read_gen_2.replace("XXX", "dummy" + "->"+ child.attrib["name"] + array_subscript).replace("YYY", ref_size)
else:
if "encoding" in child.attrib:
for_read = "dummy->" + child.attrib["name"] + array_subscript + " = " + get_encoding_read(child.attrib["encoding"])
else:
- for_read = text.c_read_gen.replace("XXX", "dummy" + "->" + child.attrib["name"] + array_subscript).replace("YYY", ref_node_name)
+ if child.attrib["type"] == "string":
+ for_read = text.c_read_gen_no.replace("XXX", "dummy" + "->" + child.attrib["name"] + array_subscript).replace("YYY", ref_node_name)
+ else:
+ for_read = text.c_read_gen.replace("XXX", "dummy" + "->" + child.attrib["name"] + array_subscript).replace("YYY", ref_node_name)
if child_count == 1:
read_source.write(for_read)
elif child_count > 1:
diff --git a/test/autowasm.c b/test/autowasm.c
index 986b1d0..fe3fece 100644
--- a/test/autowasm.c
+++ b/test/autowasm.c
@@ -31,10 +31,20 @@ int main (int argc, char** argv) {
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_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("field_length:%d\n", W_Import_Section_container->entries[i]->field_len);
+ printf("field_str:%s\n", W_Import_Section_container->entries[i]->field_str);
+ printf("kind:%d\n", W_Import_Section_container->entries[i]->kind);
+ if (W_Import_Section_container->entries[i]->kind == 0)
+ printf("type:%d\n", W_Import_Section_container->entries[i]->kind);
+ printf("\n");
}
+ printf("function_section_id:%d\n", W_Function_Section_container->id);
+ printf("function_section_payloadlength:%d\n", W_Function_Section_container->payloadlength);
+ printf("function_section_count:%d\n", W_Function_Section_container->count);
+ for (int i = 0; i < W_Function_Section_container->count; ++i)
+ printf("type:%d\n", W_Function_Section_container->types[i]);
release_all();
return 0;
diff --git a/text.py b/text.py
index 6877897..2562311 100644
--- a/text.py
+++ b/text.py
@@ -33,7 +33,9 @@ class text():
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_read_gen_no = "read(_fd, XXX, sizeof(YYY));\n"
c_read_gen_2 = "read(_fd, &XXX, YYY);\n"
+ c_read_gen_2_no = "read(_fd, XXX, YYY);\n"
c_assign_struct = "XXX.YYY = ZZZ;\n"
simple_loop = "for (int i = 0; i < XXX; ++i) {\nYYY}\n"
c_read_leb_u_def = """