summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-01-13 12:57:41 -0800
committerGitHub <noreply@github.com>2022-01-13 12:57:41 -0800
commit6d92ba9ceb14563fb4d1e573f8644eb06a8cea2a (patch)
treebe2f0163eabae3c0506854b9aa7f65332e4599c5 /src
parent3168fa227eeb3b964b6d3c773d95e0a2014b396a (diff)
downloadbinaryen-6d92ba9ceb14563fb4d1e573f8644eb06a8cea2a.tar.gz
binaryen-6d92ba9ceb14563fb4d1e573f8644eb06a8cea2a.tar.bz2
binaryen-6d92ba9ceb14563fb4d1e573f8644eb06a8cea2a.zip
LiteralList => Literals (#4451)
LiteralList overlaps with Literals, but is less efficient as it is not a SmallVector. Add reserve/capacity methods to SmallVector which are now necessary to compile.
Diffstat (limited to 'src')
-rw-r--r--src/shell-interface.h4
-rw-r--r--src/support/small_vector.h8
-rw-r--r--src/tools/execution-results.h4
-rw-r--r--src/tools/wasm-ctor-eval.cpp6
-rw-r--r--src/tools/wasm-shell.cpp2
-rw-r--r--src/wasm-interpreter.h32
6 files changed, 30 insertions, 26 deletions
diff --git a/src/shell-interface.h b/src/shell-interface.h
index 8c3109787..4fea7f8a6 100644
--- a/src/shell-interface.h
+++ b/src/shell-interface.h
@@ -133,7 +133,7 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface {
});
}
- Literals callImport(Function* import, LiteralList& arguments) override {
+ Literals callImport(Function* import, Literals& arguments) override {
if (import->module == SPECTEST && import->base.startsWith(PRINT)) {
for (auto argument : arguments) {
std::cout << argument << " : " << argument.type << '\n';
@@ -153,7 +153,7 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface {
Literals callTable(Name tableName,
Index index,
HeapType sig,
- LiteralList& arguments,
+ Literals& arguments,
Type results,
ModuleInstance& instance) override {
diff --git a/src/support/small_vector.h b/src/support/small_vector.h
index 8ab10c05b..e2c865b8f 100644
--- a/src/support/small_vector.h
+++ b/src/support/small_vector.h
@@ -119,6 +119,14 @@ public:
}
}
+ void reserve(size_t reservedSize) {
+ if (reservedSize > N) {
+ flexible.reserve(reservedSize - N);
+ }
+ }
+
+ size_t capacity() const { return N + flexible.capacity(); }
+
bool operator==(const SmallVector<T, N>& other) const {
if (usedFixed != other.usedFixed) {
return false;
diff --git a/src/tools/execution-results.h b/src/tools/execution-results.h
index afd7a78c1..94447ab4d 100644
--- a/src/tools/execution-results.h
+++ b/src/tools/execution-results.h
@@ -39,7 +39,7 @@ struct LoggingExternalInterface : public ShellExternalInterface {
LoggingExternalInterface(Loggings& loggings) : loggings(loggings) {}
- Literals callImport(Function* import, LiteralList& arguments) override {
+ Literals callImport(Function* import, Literals& arguments) override {
if (import->module == "fuzzing-support") {
std::cout << "[LoggingExternalInterface logging";
loggings.push_back(Literal()); // buffer with a None between calls
@@ -239,7 +239,7 @@ struct ExecutionResults {
FunctionResult run(Function* func, Module& wasm, ModuleInstance& instance) {
try {
- LiteralList arguments;
+ Literals arguments;
// init hang support, if present
if (auto* ex = wasm.getExportOrNull("hangLimitInitializer")) {
instance.callFunction(ex->value, arguments);
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp
index f49a54833..5699ae37a 100644
--- a/src/tools/wasm-ctor-eval.cpp
+++ b/src/tools/wasm-ctor-eval.cpp
@@ -256,7 +256,7 @@ struct CtorEvalExternalInterface : EvallingModuleInstance::ExternalInterface {
});
}
- Literals callImport(Function* import, LiteralList& arguments) override {
+ Literals callImport(Function* import, Literals& arguments) override {
Name WASI("wasi_snapshot_preview1");
if (ignoreExternalInput) {
@@ -324,7 +324,7 @@ struct CtorEvalExternalInterface : EvallingModuleInstance::ExternalInterface {
Literals callTable(Name tableName,
Index index,
HeapType sig,
- LiteralList& arguments,
+ Literals& arguments,
Type result,
EvallingModuleInstance& instance) override {
@@ -524,7 +524,7 @@ EvalCtorOutcome evalCtor(EvallingModuleInstance& instance,
// 1. Statically or dynamically stop evalling when a param is actually
// used, or
// 2. Split out --ignore-external-input into separate flags.
- LiteralList params;
+ Literals params;
for (Index i = 0; i < func->getNumParams(); i++) {
auto type = func->getLocalType(i);
if (!LiteralUtils::canMakeZero(type)) {
diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp
index 6a780dd9e..4243b00a9 100644
--- a/src/tools/wasm-shell.cpp
+++ b/src/tools/wasm-shell.cpp
@@ -179,7 +179,7 @@ protected:
Name base = s[i++]->str();
if (s[0]->str() == INVOKE) {
- LiteralList args;
+ Literals args;
while (i < s.size()) {
Expression* argument = builders[moduleName]->parseExpression(*s[i++]);
args.push_back(getLiteralFromConstExpression(argument));
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 02710d4b3..64dc824f6 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -98,9 +98,6 @@ public:
}
};
-// A list of literals, for function calls
-typedef std::vector<Literal> LiteralList;
-
// Debugging helpers
#ifdef WASM_INTERPRETER_DEBUG
class Indenter {
@@ -165,8 +162,7 @@ protected:
// Maximum iterations before giving up on a loop.
Index maxLoopIterations;
- Flow generateArguments(const ExpressionList& operands,
- LiteralList& arguments) {
+ Flow generateArguments(const ExpressionList& operands, Literals& arguments) {
NOTE_ENTER_("generateArguments");
arguments.reserve(operands.size());
for (auto expression : operands) {
@@ -1284,7 +1280,7 @@ public:
}
Flow visitTupleMake(TupleMake* curr) {
NOTE_ENTER("tuple.make");
- LiteralList arguments;
+ Literals arguments;
Flow flow = generateArguments(curr->operands, arguments);
if (flow.breaking()) {
return flow;
@@ -1384,7 +1380,7 @@ public:
Flow visitTry(Try* curr) { WASM_UNREACHABLE("unimp"); }
Flow visitThrow(Throw* curr) {
NOTE_ENTER("Throw");
- LiteralList arguments;
+ Literals arguments;
Flow flow = generateArguments(curr->operands, arguments);
if (flow.breaking()) {
return flow;
@@ -2306,11 +2302,11 @@ public:
virtual ~ExternalInterface() = default;
virtual void init(Module& wasm, SubType& instance) {}
virtual void importGlobals(GlobalManager& globals, Module& wasm) = 0;
- virtual Literals callImport(Function* import, LiteralList& arguments) = 0;
+ virtual Literals callImport(Function* import, Literals& arguments) = 0;
virtual Literals callTable(Name tableName,
Index index,
HeapType sig,
- LiteralList& arguments,
+ Literals& arguments,
Type result,
SubType& instance) = 0;
virtual bool growMemory(Address oldSize, Address newSize) = 0;
@@ -2510,13 +2506,13 @@ public:
// run start, if present
if (wasm.start.is()) {
- LiteralList arguments;
+ Literals arguments;
callFunction(wasm.start, arguments);
}
}
// call an exported function
- Literals callExport(Name name, const LiteralList& arguments) {
+ Literals callExport(Name name, const Literals& arguments) {
Export* export_ = wasm.getExportOrNull(name);
if (!export_) {
externalInterface->trap("callExport not found");
@@ -2524,7 +2520,7 @@ public:
return callFunction(export_->value, arguments);
}
- Literals callExport(Name name) { return callExport(name, LiteralList()); }
+ Literals callExport(Name name) { return callExport(name, Literals()); }
// get an exported global
Literals getExport(Name name) {
@@ -2659,7 +2655,7 @@ public:
std::vector<Literals> locals;
Function* function;
- FunctionScope(Function* function, const LiteralList& arguments)
+ FunctionScope(Function* function, const Literals& arguments)
: function(function) {
if (function->getParams().size() != arguments.size()) {
std::cerr << "Function `" << function->name << "` expects "
@@ -2731,7 +2727,7 @@ public:
Flow visitCall(Call* curr) {
NOTE_ENTER("Call");
NOTE_NAME(curr->target);
- LiteralList arguments;
+ Literals arguments;
Flow flow = this->generateArguments(curr->operands, arguments);
if (flow.breaking()) {
return flow;
@@ -2755,7 +2751,7 @@ public:
Flow visitCallIndirect(CallIndirect* curr) {
NOTE_ENTER("CallIndirect");
- LiteralList arguments;
+ Literals arguments;
Flow flow = this->generateArguments(curr->operands, arguments);
if (flow.breaking()) {
return flow;
@@ -2780,7 +2776,7 @@ public:
}
Flow visitCallRef(CallRef* curr) {
NOTE_ENTER("CallRef");
- LiteralList arguments;
+ Literals arguments;
Flow flow = this->generateArguments(curr->operands, arguments);
if (flow.breaking()) {
return flow;
@@ -3555,7 +3551,7 @@ public:
};
// Call a function, starting an invocation.
- Literals callFunction(Name name, const LiteralList& arguments) {
+ Literals callFunction(Name name, const Literals& arguments) {
// if the last call ended in a jump up the stack, it might have left stuff
// for us to clean up here
callDepth = 0;
@@ -3565,7 +3561,7 @@ public:
// Internal function call. Must be public so that callTable implementations
// can use it (refactor?)
- Literals callFunctionInternal(Name name, const LiteralList& arguments) {
+ Literals callFunctionInternal(Name name, const Literals& arguments) {
if (callDepth > maxDepth) {
externalInterface->trap("stack limit");
}