Skip to content

Refactor ExpressionRunner #2804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4998,16 +4998,18 @@ BinaryenExpressionRef RelooperRenderAndDispose(RelooperRef relooper,

namespace wasm {

class CExpressionRunner final : public ExpressionRunner<CExpressionRunner> {
// Evaluates a suspected constant expression via the C-API. Inherits most of its
// functionality from ConstantExpressionRunner, which it shares with the
// precompute pass, but must be `final` so we can `delete` its instances.
class CExpressionRunner final
: public ConstantExpressionRunner<CExpressionRunner> {
public:
CExpressionRunner(Module* module,
CExpressionRunner::Flags flags,
Index maxDepth,
Index maxLoopIterations)
: ExpressionRunner<CExpressionRunner>(
: ConstantExpressionRunner<CExpressionRunner>(
module, flags, maxDepth, maxLoopIterations) {}

void trap(const char* why) override { throw NonconstantException(); }
};

} // namespace wasm
Expand Down
13 changes: 7 additions & 6 deletions src/passes/Precompute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ namespace wasm {
typedef std::unordered_map<LocalGet*, Literals> GetValues;

// Precomputes an expression. Errors if we hit anything that can't be
// precomputed.
// precomputed. Inherits most of its functionality from
// ConstantExpressionRunner, which it shares with the C-API, but adds handling
// of GetValues computed during the precompute pass.
class PrecomputingExpressionRunner
: public ExpressionRunner<PrecomputingExpressionRunner> {
: public ConstantExpressionRunner<PrecomputingExpressionRunner> {

// Concrete values of gets computed during the pass, which the runner does not
// know about since it only records values of sets it visits.
Expand All @@ -66,7 +68,7 @@ class PrecomputingExpressionRunner
PrecomputingExpressionRunner(Module* module,
GetValues& getValues,
bool replaceExpression)
: ExpressionRunner<PrecomputingExpressionRunner>(
: ConstantExpressionRunner<PrecomputingExpressionRunner>(
module,
replaceExpression ? FlagValues::PRESERVE_SIDEEFFECTS
: FlagValues::DEFAULT,
Expand All @@ -82,10 +84,9 @@ class PrecomputingExpressionRunner
return Flow(values);
}
}
return ExpressionRunner<PrecomputingExpressionRunner>::visitLocalGet(curr);
return ConstantExpressionRunner<
PrecomputingExpressionRunner>::visitLocalGet(curr);
}

void trap(const char* why) override { throw NonconstantException(); }
};

struct Precompute
Expand Down
Loading