From f9feb2541ca285cffbe5cf2de70843633c3dc2c2 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 2 Mar 2020 23:27:41 -0600 Subject: [PATCH] added lines between callee/caller functions --- conf.lua | 3 ++- data/main.wasm | Bin 1052 -> 1072 bytes docs/todo | 5 ++++- main.lua | 42 ++++++++++++++++++++++++++++++++++++++++- src/ui/ui.lua | 26 ++++++++++++++++++++----- src/utils.lua | 4 ++++ src/wasm/analyze.lua | 42 +++++++++++++++++++++++++++++++++++++++++ src/wasm/decompile.lua | 6 ++++-- testing.lua | 2 ++ 9 files changed, 120 insertions(+), 10 deletions(-) create mode 100644 src/wasm/analyze.lua diff --git a/conf.lua b/conf.lua index a97a94b..8b13689 100644 --- a/conf.lua +++ b/conf.lua @@ -43,7 +43,8 @@ function love.conf(t) t.window.title = "TBD" t.window.width = 1200 t.window.height = 900 - t.window.resizable = false + t.window.resizable = true + t.window.vsync = true end return { diff --git a/data/main.wasm b/data/main.wasm index 2e254e94444efadbbcdd2a9b0dfa6e11d7a88244..39e07ae3327cac8fdba142156e1d1022713b2d64 100755 GIT binary patch delta 258 zcmbQkv4LZP3G)O-&WUCFnt_`ALa6#mw~#6E`(PG5QrLFgh}L07+#g zzanlK1_cHMMgdM12Yzm#5Mz!4LzXgYmI9L%0|SzzBLj-GE>KdRk*Qu8Xh;rFxgwJ? z>*O9reO)FuUZClU3``Ep4hjs)j6g1usX%RxjBYFr$}9rRtjf%jUoh%wvtaf95W%$5Zc6@ZBv=({;!8>>=3pbFE zW|;Z-AM^Gf{(VPRzujNjZ?lG?)|kQ3O~#^D5opjD2Er_rLr`h3EV>F;(XiVDK&41G z2F8kojmZg~m?oGnTvQBXJfnfZol`__%P<#)z0i|P-4Bz4EJKyyNtg^Z)iJ5QoTVLU hI8v6S`)bfOG~rK4TU4^L@mvcXu 0 and 1.05 or (1 / 1.05)) - -- if self.zoom >= 1 then self.zoom = 1 end - if self.zoom <= 0.2 then self.zoom = 0.2 end + self:change_zoom(dy > 0 and 1.05 or (1 / 1.05)) end end; + change_zoom = function(self, multiplier) + self.zoom = self.zoom * multiplier + -- if self.zoom >= 1 then self.zoom = 1 end + if self.zoom <= 0.2 then self.zoom = 0.2 end + end; + update = function(self, dt) UiRegion.update(self, dt) if self.active then - local speed = 300 / self.zoom + local speed = 600 / self.zoom if love.keyboard.isDown "left" then self.offset.x = self.offset.x + speed * dt end @@ -331,6 +340,13 @@ class "ScrollingUiRegion" [UiRegion] { if love.keyboard.isDown "down" then self.offset.y = self.offset.y - speed * dt end + + if love.keyboard.isDown "q" then + self:change_zoom(1 + 0.5 * dt) + end + if love.keyboard.isDown "a" then + self:change_zoom(1 - 0.5 * dt) + end end end; diff --git a/src/utils.lua b/src/utils.lua index 07f3235..812847a 100644 --- a/src/utils.lua +++ b/src/utils.lua @@ -94,6 +94,10 @@ class "Rectangle" { and self.y + self.h >= other.y end; + center = function(self) + return self.x + self.w / 2, self.y + self.h / 2 + end; + __lt = function(self, other) return self:intersects(other) end } diff --git a/src/wasm/analyze.lua b/src/wasm/analyze.lua new file mode 100644 index 0000000..52fe537 --- /dev/null +++ b/src/wasm/analyze.lua @@ -0,0 +1,42 @@ +import {} + +function add_function_relations(wasm_funcs) + function func_rel_helper(callees, instrs) + for _, instr in ipairs(instrs) do + if instr[1] == "call" then + callees[instr.x] = true + elseif instr[1] == "block" or instr[1] == "loop" then + func_rel_helper(callees, instr.instrs) + elseif instr[1] == "if" then + func_rel_helper(callees, instr.instrs) + if instr.else_instrs then + func_rel_helper(callees, instr.else_instrs) + end + end + end + end + + for _, func in ipairs(wasm_funcs) do + if not func.imported then + func.callees = {} + local callees = {} + + func_rel_helper(callees, func.body) + + for callee, _ in pairs(callees) do + wasm_funcs[callee].callers = wasm_funcs[callee].callers or {} + table.insert(wasm_funcs[callee].callers, func.funcidx) + + table.insert(func.callees, callee) + end + end + end +end + +function analyze(wasm_mod) + add_function_relations(wasm_mod.funcs) + + return wasm_mod +end + +return module { analyze } diff --git a/src/wasm/decompile.lua b/src/wasm/decompile.lua index 512d686..b67f973 100644 --- a/src/wasm/decompile.lua +++ b/src/wasm/decompile.lua @@ -642,6 +642,7 @@ function parse_module(r) name = build_str(v.mod) .. "." .. build_str(v.name); funcidx = funcidx; type_ = functypes.contents[v.desc.x + 1]; + imported = true; } funcidx = funcidx + 1 end @@ -675,7 +676,8 @@ function parse_module(r) name = "func" .. funcidx; type_ = functypes.contents[typeidxs.contents[i] + 1]; locals = new_locals; - body = codes.contents[i].body + body = codes.contents[i].body; + imported = false; } funcidx = funcidx + 1 end @@ -697,7 +699,7 @@ function parse_module(r) end --- Reader util class used for interfacing +-- Parser util class used for interfacing -- with the parse_helper c library class "Parser" { init = function(self, filename) diff --git a/testing.lua b/testing.lua index 6823349..935dc9c 100644 --- a/testing.lua +++ b/testing.lua @@ -2,10 +2,12 @@ require "lualib.oop" import { decompile = "src.wasm.decompile:"; + analyze = "src.wasm.analyze:"; build_str = "src.utils:build_str"; pprint = "lualib.pprint"; } local mod = decompile(arg[1]) +analyze(mod) pprint(mod) -- 2.25.1