summaryrefslogtreecommitdiff
path: root/src/wasm.h
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-05-12 11:27:29 -0500
committerGitHub <noreply@github.com>2023-05-12 09:27:29 -0700
commit64e5a99ee014af3a138a36f5a87addfacfc95f0c (patch)
treea322095dfe09f1b361964682f56bc5c6f963e46a /src/wasm.h
parent7d5d24f400019ff023b65ccdb3c1d8d07ebb00a5 (diff)
downloadbinaryen-64e5a99ee014af3a138a36f5a87addfacfc95f0c.tar.gz
binaryen-64e5a99ee014af3a138a36f5a87addfacfc95f0c.tar.bz2
binaryen-64e5a99ee014af3a138a36f5a87addfacfc95f0c.zip
[analysis] Add a new iterable CFG utility (#5712)
Add a new "analysis" source directory that will contain the source for a new static program analysis framework. To start the framework, add a CFG utility that provides convenient iterators for iterating through the basic blocks of the CFG as well as the predecessors, successors, and contents of each block. The new CFGs are constructed using the existing CFGWalker, but they are different in that the new utility is meant to provide a usable representation of a CFG whereas CFGWalker is meant to allow collecting arbitrary information about each basic block in a CFG. For testing and debugging purposes, add `print` methods to CFGs and basic blocks. This requires exposing the ability to print expression contents excluding children, which was something we previously did only for StackIR. Also add a new gtest file with a test for constructing and printing a CFG. The test reveals some strange properties of the current CFG construction, including empty blocks and strange placement of `loop` instructions, but fixing these problems is left as future work.
Diffstat (limited to 'src/wasm.h')
-rw-r--r--src/wasm.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/wasm.h b/src/wasm.h
index 474497847..727c9ca30 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -2308,8 +2308,16 @@ public:
void clearDebugInfo();
};
+// Utility for printing an expression with named types.
using ModuleExpression = std::pair<Module&, Expression*>;
+// Utility for printing only the top level of an expression. Named types will be
+// used if `module` is non-null.
+struct ShallowExpression {
+ Expression* expr;
+ Module* module = nullptr;
+};
+
} // namespace wasm
namespace std {
@@ -2322,6 +2330,7 @@ template<> struct hash<wasm::Address> {
std::ostream& operator<<(std::ostream& o, wasm::Module& module);
std::ostream& operator<<(std::ostream& o, wasm::Expression& expression);
std::ostream& operator<<(std::ostream& o, wasm::ModuleExpression pair);
+std::ostream& operator<<(std::ostream& o, wasm::ShallowExpression expression);
std::ostream& operator<<(std::ostream& o, wasm::StackInst& inst);
std::ostream& operator<<(std::ostream& o, wasm::StackIR& ir);