From 2b523602df55f803763e44f978645301fe0dc499 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Mon, 1 Oct 2018 04:17:33 +0330 Subject: fixed some more bugs on tablegen and faultreiber's side. you can run the demo file called wasmtest under lua-scripts if you wanna see what we have so far. --- bruiser/autogen/wasm/ltg/luwasm.xml | 4 +- bruiser/faultreiber | 2 +- bruiser/lua-scripts/regtest.lua | 2 + bruiser/lua-scripts/wasmtest.lua | 120 ++++++++++++++++++++++++++++-------- bruiser/tablegen | 2 +- 5 files changed, 100 insertions(+), 30 deletions(-) (limited to 'bruiser') diff --git a/bruiser/autogen/wasm/ltg/luwasm.xml b/bruiser/autogen/wasm/ltg/luwasm.xml index 8d6efe0..5ccd054 100644 --- a/bruiser/autogen/wasm/ltg/luwasm.xml +++ b/bruiser/autogen/wasm/ltg/luwasm.xml @@ -152,7 +152,7 @@ - + @@ -162,7 +162,7 @@ - + diff --git a/bruiser/faultreiber b/bruiser/faultreiber index aa60b19..bddc410 160000 --- a/bruiser/faultreiber +++ b/bruiser/faultreiber @@ -1 +1 @@ -Subproject commit aa60b19995fb0100ee16d57265e4096566b22226 +Subproject commit bddc4103d3f56cd25017f6948ea6a5eaa146bef6 diff --git a/bruiser/lua-scripts/regtest.lua b/bruiser/lua-scripts/regtest.lua index 9cb1250..c45c2ce 100644 --- a/bruiser/lua-scripts/regtest.lua +++ b/bruiser/lua-scripts/regtest.lua @@ -7,6 +7,7 @@ function reg_test() local jmp_table = require("demo2") local asm_rewriter = require("asmtest") local wasm_import = require("demo3") + local libwasm = require("wasmtest") local argparse = require("argparse") @@ -15,6 +16,7 @@ function reg_test() parser:flag("-j --jmpt") parser:flag("-a --asm") parser:flag("-w --wasm") + --libwasm.demo("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm") end diff --git a/bruiser/lua-scripts/wasmtest.lua b/bruiser/lua-scripts/wasmtest.lua index 32c8442..dec8d66 100644 --- a/bruiser/lua-scripts/wasmtest.lua +++ b/bruiser/lua-scripts/wasmtest.lua @@ -1,15 +1,29 @@ colors = require("ansicolors") --- aka dump wasm -function demo4() - local a = getwasmobj("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm") +local libwasm = {} + +function libwasm.demo(wasm_path) + local a = getwasmobj(wasm_path) print(a) print(type(a)) for k, v in pairs(a) do print(k, v, type(k), type(v)) end + libwasm.dump_import_section(a) + libwasm.dump_type_section(a) + libwasm.dump_function_section(a) + libwasm.dump_table_section(a) + libwasm.dump_memory_section(a) + libwasm.dump_global_section(a) + libwasm.dump_export_section(a) + libwasm.dump_start_section(a) + libwasm.dump_element_section(a) + libwasm.dump_code_section(a) + libwasm.dump_data_section(a) +end +function libwasm.dump_type_section(a) print(colors("%{green}".."\ntype section:")) if a["type_section"] ~= nil then io.write(tostring("id:"..a["type_section"]:id()).."\n") @@ -28,7 +42,9 @@ function demo4() else print(colors("%{red}".."section doesnt exist.")) end +end +function libwasm.dump_import_section(a) print(colors("%{green}".."\nimport section:")) if a["import_section"] ~= nil then io.write("id:"..tostring(a["import_section"]:id()).."\n") @@ -39,16 +55,19 @@ function demo4() io.write("entries"..tostring(a["import_section"]:entries()).."\n") for k, v in pairs(a["import_section"]:entries()) do --print(k, v, type(v)) - io.write(v:module_length().."\t") - io.write(v:module_str().."\t") - io.write(v:field_len().."\t") - io.write(v:field_str().."\t") - io.write(v:kind().."\n") + io.write("module length:"..v:module_length().."\t") + io.write("module str:"..v:module_str().."\t") + io.write("field len:"..v:field_len().."\t") + io.write("field str:"..v:field_str().."\t") + io.write("kind:"..v:kind().."\t") + io.write("type:"..v:type().."\n") end else print(colors("%{red}".."section doesnt exist.")) end +end +function libwasm.dump_function_section(a) print(colors("%{green}".."\nfunction section:")) if a["function_section"] ~= nil then io.write("id:"..tostring(a["function_section"]:id()).."\n") @@ -60,7 +79,9 @@ function demo4() else print(colors("%{red}".."section doesnt exist.")) end +end +function libwasm.dump_table_section(a) print(colors("%{green}".."\ntable section:")) if a["table_section"] ~= nil then io.write("id:"..tostring(a["table_section"]:id()).."\n") @@ -79,7 +100,10 @@ function demo4() else print(colors("%{red}".."section doesnt exist.")) end +end + +function libwasm.dump_memory_section(a) print(colors("%{green}".."\nmemory section:")) if a["memory_section"] ~= nil then io.write("id:"..tostring(a["memory_section"]:id()).."\n") @@ -95,7 +119,9 @@ function demo4() else print(colors("%{red}".."section doesnt exist.")) end +end +function libwasm.dump_global_section(a) print(colors("%{green}".."\nglobal section:")) if (a["global_section"] ~= nil) then io.write("id:"..tostring(a["global_section"]:id()).."\n") @@ -112,7 +138,9 @@ function demo4() else print(colors("%{red}".."section doesnt exist.")) end +end +function libwasm.dump_export_section(a) print(colors("%{green}".."\nexport section:")) if (a["export_section"] ~= nil) then io.write("id:"..tostring(a["export_section"]:id()).."\n") @@ -130,7 +158,9 @@ function demo4() else print(colors("%{red}".."section doesnt exist.")) end +end +function libwasm.dump_start_section(a) print(colors("%{green}".."\nstart section:")) if (a["start_section"] ~= nil) then io.write("id:"..tostring(a["start_section"]:id()).."\n") @@ -141,7 +171,9 @@ function demo4() else print(colors("%{red}".."section doesnt exist.")) end +end +function libwasm.dump_element_section(a) print(colors("%{green}".."\nelement section:")) if (a["element_section"] ~= nil) then io.write("id:"..tostring(a["element_section"]:id()).."\n") @@ -149,19 +181,28 @@ function demo4() io.write("namelength:"..tostring(a["element_section"]:namelength()).."\n") io.write("name:"..tostring(a["element_section"]:name()).."\n") io.write("count:"..tostring(a["element_section"]:count()).."\n") - io.write("entries:"..tostring(a["element_section"]:entries()).."\n") + io.write(colors("%{cyan}".."entries:"..tostring(a["element_section"]:entries()).."\n")) for k, v in pairs(a["element_section"]:entries()) do - io.write(v:index().."\t") - io.write(tostring(v:init()).."\t") - io.write(v:init():code().."\t") - io.write(v:num_length().."\t") - -- FIXME - io.write(v:elems().."\n") + io.write("index:"..v:index().."\t") + io.write("init:") + for i = 1, #v:init():code() do + local c = v:init():code():sub(i,i) + io.write(colors("%{red}"..string.byte(c)).." ") + end + io.write("\n") + io.write("number of elements:"..v:num_length().."\t") + io.write("elems:") + for i, j in pairs(v:elems()) do + io.write(colors("%{red}"..j.." ")) + end + io.write("\n") end else print(colors("%{red}".."section doesnt exist.")) end +end +function libwasm.dump_code_section(a) print(colors("%{green}".."\ncode section:")) if (a["code_section"] ~= nil) then io.write("id:"..tostring(a["code_section"]:id()).."\n") @@ -171,20 +212,26 @@ function demo4() io.write("count:"..tostring(a["code_section"]:count()).."\n") io.write("bodies:"..tostring(a["code_section"]:bodies()).."\n") for k,v in pairs(a["code_section"]:bodies()) do - io.write(v:body_size().."\t") - io.write(v:local_count().."\t") + io.write(colors("\n%{cyan}".."entry:\n")) + io.write("body_size:"..v:body_size().."\t") + io.write("local_count:"..v:local_count().."\t") io.write(tostring(v:locals()).."\t") - print("number of locals:"..#v:locals()) for i, j in pairs(v:locals()) do io.write("locals count:"..j:count().."\t") io.write("locals type:"..j:type().."\t") end - io.write(v:code().."\n") + io.write("function body:\n") + for i,j in pairs(v:code()) do + io.write(colors("%{red}"..j.." ")) + end + io.write("\n") end else print(colors("%{red}".."section doesnt exist.")) end +end +function libwasm.dump_data_section(a) print(colors("%{green}".."\ndata section:")) if (a["data_section"] ~= nil) then io.write("id:"..tostring(a["data_section"]:id()).."\n") @@ -194,17 +241,16 @@ function demo4() io.write("count:"..tostring(a["data_section"]:count()).."\n") io.write("entries:"..tostring(a["data_section"]:entries()).."\n") if type(a["data_section"]:entries()) == "table" then + io.write(colors("%{cyan}".."entries:").."\n") for k,v in pairs(a["data_section"]:entries()) do - io.write(v:index().."\t") - io.write(tostring(v:offset()).."\t") - print(colors("%{red}"..tostring(#v:offset():code()))) + io.write("index:"..v:index().."\n") + io.write("offset: ") for i = 1, #v:offset():code() do local c = v:offset():code():sub(i,i) - print(colors("%{red}"..string.byte(c))) + io.write(colors("%{red}"..string.byte(c)).." ") end - --io.write(colors("%{yellow}"..v:offset():code())) + io.write("\n") io.write("size:"..v:size().."\n") - io.write(tostring(v:data()).."\n") for i, j in pairs(v:data()) do io.write(colors("%{blue}"..string.char(j))) end @@ -214,7 +260,29 @@ function demo4() else print(colors("%{red}".."section doesnt exist.")) end +end + +function libwasm.dump_all(wasm_path) + local a = getwasmobj(wasm_path) + libwasm.dump_import_section(a) + libwasm.dump_type_section(a) + libwasm.dump_function_section(a) + libwasm.dump_table_section(a) + libwasm.dump_memory_section(a) + libwasm.dump_global_section(a) + libwasm.dump_export_section(a) + libwasm.dump_start_section(a) + libwasm.dump_element_section(a) + libwasm.dump_code_section(a) + libwasm.dump_data_section(a) +end +function libwasm.dev(wasm_path) + local a = getwasmobj(wasm_path) + libwasm.dump_import_section(a) end -demo4() +--libwasm.dev("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm") +libwasm.demo("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm") +--libwasm.dump_all("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm") +return libwasm diff --git a/bruiser/tablegen b/bruiser/tablegen index c0eda3b..ec0f1d8 160000 --- a/bruiser/tablegen +++ b/bruiser/tablegen @@ -1 +1 @@ -Subproject commit c0eda3bcb258278bba83b6d3d26d5d7f4b65ef4c +Subproject commit ec0f1d881c9f0da07e57f1c4a307fbc4e96313c2 -- cgit v1.2.3