summaryrefslogtreecommitdiff
path: root/src/ast_utils.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-10-26 20:24:09 -0700
committerGitHub <noreply@github.com>2016-10-26 20:24:09 -0700
commit7047ed25b3ca34aeddb67d0082a998fec0841372 (patch)
tree13be5c1c8bcc780347480f373c88cd1c3f2eb34b /src/ast_utils.h
parentcf80d22442549707fb748e81028f41c88d41cb87 (diff)
downloadbinaryen-7047ed25b3ca34aeddb67d0082a998fec0841372.tar.gz
binaryen-7047ed25b3ca34aeddb67d0082a998fec0841372.tar.bz2
binaryen-7047ed25b3ca34aeddb67d0082a998fec0841372.zip
Code pushing (#807)
Push code forward, potentially letting it not execute
Diffstat (limited to 'src/ast_utils.h')
-rw-r--r--src/ast_utils.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h
index 9dfacb972..f10fb40eb 100644
--- a/src/ast_utils.h
+++ b/src/ast_utils.h
@@ -102,6 +102,11 @@ struct DirectCallGraphAnalyzer : public PostWalker<DirectCallGraphAnalyzer, Visi
struct EffectAnalyzer : public PostWalker<EffectAnalyzer, Visitor<EffectAnalyzer>> {
EffectAnalyzer() {}
EffectAnalyzer(Expression *ast) {
+ analyze(ast);
+ }
+
+ void analyze(Expression *ast) {
+ breakNames.clear();
walk(ast);
// if we are left with breaks, they are external
if (breakNames.size() > 0) branches = true;
@@ -151,6 +156,17 @@ struct EffectAnalyzer : public PostWalker<EffectAnalyzer, Visitor<EffectAnalyzer
return false;
}
+ void mergeIn(EffectAnalyzer& other) {
+ branches = branches || other.branches;
+ calls = calls || other.calls;
+ readsMemory = readsMemory || other.readsMemory;
+ writesMemory = writesMemory || other.writesMemory;
+ for (auto i : other.localsRead) localsRead.insert(i);
+ for (auto i : other.localsWritten) localsWritten.insert(i);
+ for (auto i : other.globalsRead) globalsRead.insert(i);
+ for (auto i : other.globalsWritten) globalsWritten.insert(i);
+ }
+
// the checks above happen after the node's children were processed, in the order of execution
// we must also check for control flow that happens before the children, i.e., loops
bool checkPre(Expression* curr) {