Skip to content
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
23 changes: 13 additions & 10 deletions src/tools/wasm-ctor-eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ std::unique_ptr<Module> buildEnvModule(Module& wasm) {
// that there are not arguments passed to main, etc.
static bool ignoreExternalInput = false;

// Whether to emit informative logging to stdout about the eval process.
static bool quiet = false;

struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
Module* wasm;
EvallingModuleRunner* instance;
Expand Down Expand Up @@ -328,8 +331,6 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
firstApplication = false;
}

clearApplyState();

// If nothing was ever written to memories then there is nothing to update.
if (!memories.empty()) {
applyMemoryToModule();
Expand Down Expand Up @@ -529,12 +530,12 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
return Bits::readLE<T>(getMemory(address, memoryName, sizeof(T)));
}

public:
// Clear the state of the operation of applying the interpreter's runtime
// information into the module.
//
// This happens each time we apply contents to the module, which is basically
// once per ctor function, but can be more fine-grained also if we execute a
// line at a time.
// information into the module. This must be done before we start to serialize
// content (as the serialization uses this state - defining globals must be
// set and are latter used, etc.). After this, serialization can happen, and
// after that, a call to applyToModule() can be done.
void clearApplyState() {
// The process of allocating "defining globals" begins here, from scratch
// each time (things live before may no longer be).
Expand All @@ -546,6 +547,7 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
clearStartBlock();
}

private:
void applyMemoryToModule() {
// Memory must have already been flattened into the standard form: one
// segment at offset 0, or none.
Expand Down Expand Up @@ -1062,9 +1064,6 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
}
};

// Whether to emit informative logging to stdout about the eval process.
static bool quiet = false;

// The outcome of evalling a ctor is one of three states:
//
// 1. We failed to eval it completely (but perhaps we succeeded partially). In
Expand Down Expand Up @@ -1203,6 +1202,10 @@ EvalCtorOutcome evalCtor(EvallingModuleRunner& instance,
break;
}

// We are about to serialize content (the code paths below call
// getSerialization). Clear the state.
interface.clearApplyState();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make it so getSerialization automatically calls this as necessary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could maintain some global state for it, but that would add complexity I think?

Atm there is one call to this, in the right place.


if (flow.breakTo == RETURN_CALL_FLOW) {
// The return-called function is stored in the last value.
func = wasm.getFunction(flow.values.back().getFunc());
Expand Down
Loading
Loading