@@ -68,40 +68,6 @@ bool isNullableAndMutable(Expression* ref, Index fieldIndex) {
6868// the output.
6969#define RECOMMENDATION " \n recommendation: "
7070
71- class EvallingImportResolver : public ImportResolver {
72- public:
73- EvallingImportResolver () : stubLiteral({Literal (0 )}) {};
74-
75- // Return an unused stub value. We throw FailToEvalException on reading any
76- // imported globals. We ignore the type and return an i32 literal since some
77- // types can't be created anyway (e.g. ref none).
78- Literals* getGlobalOrNull (ImportNames name, Type type) const override {
79- return &stubLiteral;
80- }
81-
82- RuntimeTable* getTableOrNull (ImportNames name,
83- const Table& type) const override {
84- throw FailToEvalException{" Imported table access." };
85- }
86-
87- // We assume that each tag import is distinct. This is wrong if the same tag
88- // instantiation is imported twice with different import names.
89- Tag* getTagOrNull (ImportNames name,
90- const Signature& signature) const override {
91- auto [it, inserted] = importedTags.try_emplace (name, Tag{});
92- if (inserted) {
93- auto & tag = it->second ;
94- tag.type = HeapType (signature);
95- }
96-
97- return &it->second ;
98- }
99-
100- private:
101- mutable Literals stubLiteral;
102- mutable std::unordered_map<ImportNames, Tag> importedTags;
103- };
104-
10571class EvallingRuntimeTable : public RuntimeTable {
10672public:
10773 // TODO: putting EvallingModuleRunner into its own header would allow us to
@@ -180,6 +146,53 @@ class EvallingRuntimeTable : public RuntimeTable {
180146 const std::function<Literal(Name, Type)> makeFuncData;
181147};
182148
149+ class EvallingImportResolver : public ImportResolver {
150+ public:
151+ EvallingImportResolver (const bool & instanceInitialized,
152+ const Module& wasm,
153+ std::function<Literal(Name, Type)> makeFuncData)
154+ : stubLiteral({Literal (0 )}), instanceInitialized(instanceInitialized),
155+ wasm (wasm), makeFuncData(makeFuncData) {};
156+
157+ // Return an unused stub value. We throw FailToEvalException on reading any
158+ // imported globals. We ignore the type and return an i32 literal since some
159+ // types can't be created anyway (e.g. ref none).
160+ Literals* getGlobalOrNull (ImportNames name, Type type) const override {
161+ return &stubLiteral;
162+ }
163+
164+ RuntimeTable* getTableOrNull (ImportNames name,
165+ const Table& type) const override {
166+ auto [it, inserted] =
167+ tables.emplace (name,
168+ std::make_unique<EvallingRuntimeTable>(
169+ type, instanceInitialized, wasm, makeFuncData));
170+ return it->second .get ();
171+ }
172+
173+ // We assume that each tag import is distinct. This is wrong if the same tag
174+ // instantiation is imported twice with different import names.
175+ Tag* getTagOrNull (ImportNames name,
176+ const Signature& signature) const override {
177+ auto [it, inserted] = importedTags.try_emplace (name, Tag{});
178+ if (inserted) {
179+ auto & tag = it->second ;
180+ tag.type = HeapType (signature);
181+ }
182+
183+ return &it->second ;
184+ }
185+
186+ private:
187+ mutable Literals stubLiteral;
188+ mutable std::unordered_map<ImportNames, std::unique_ptr<EvallingRuntimeTable>>
189+ tables;
190+ const bool & instanceInitialized;
191+ const Module& wasm;
192+ const std::function<Literal(Name, Type)> makeFuncData;
193+ mutable std::unordered_map<ImportNames, Tag> importedTags;
194+ };
195+
183196class EvallingModuleRunner : public ModuleRunnerBase <EvallingModuleRunner> {
184197public:
185198 EvallingModuleRunner (
@@ -190,17 +203,11 @@ class EvallingModuleRunner : public ModuleRunnerBase<EvallingModuleRunner> {
190203 : ModuleRunnerBase(
191204 wasm,
192205 externalInterface,
193- std::make_shared<EvallingImportResolver>(),
194- linkedInstances_,
195- // TODO: Only use EvallingRuntimeTable for table imports. We can use
196- // RealRuntimeTable for non-imported tables.
197- [this , &instanceInitialized](Literal initial, Table table) {
198- return std::make_unique<EvallingRuntimeTable>(
199- table,
200- instanceInitialized,
201- this ->wasm ,
202- [this ](Name name, Type type) { return makeFuncData (name, type); });
203- }) {}
206+ std::make_shared<EvallingImportResolver>(
207+ instanceInitialized,
208+ wasm,
209+ [this ](Name name, Type type) { return makeFuncData (name, type); }),
210+ linkedInstances_) {}
204211
205212 Flow visitGlobalGet (GlobalGet* curr) {
206213 // Error on reads of imported globals.
@@ -1166,6 +1173,11 @@ EvalCtorOutcome evalCtor(EvallingModuleRunner& instance,
11661173 std::cout << " ...stopping due to non-constant func\n " ;
11671174 }
11681175 break ;
1176+ } catch (TrapException& trap) {
1177+ if (!quiet) {
1178+ std::cout << " ...stopping due to trap\n " ;
1179+ }
1180+ break ;
11691181 }
11701182
11711183 if (flow.breakTo == NONCONSTANT_FLOW) {
0 commit comments