summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-binary.cpp4
-rw-r--r--src/wasm/wasm-s-parser.cpp4
-rw-r--r--src/wasm/wasm.cpp8
3 files changed, 9 insertions, 7 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index af42ed8a4..a78636c92 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -937,7 +937,7 @@ void WasmBinaryBuilder::readSignatures() {
if (debug) std::cerr << "num: " << numTypes << std::endl;
for (size_t i = 0; i < numTypes; i++) {
if (debug) std::cerr << "read one" << std::endl;
- auto curr = new FunctionType;
+ auto curr = make_unique<FunctionType>();
auto form = getS32LEB();
if (form != BinaryConsts::EncodedType::Func) {
throwError("bad signature form " + std::to_string(form));
@@ -957,7 +957,7 @@ void WasmBinaryBuilder::readSignatures() {
curr->result = getType();
}
curr->name = Name::fromInt(wasm.functionTypes.size());
- wasm.addFunctionType(curr);
+ wasm.addFunctionType(std::move(curr));
}
}
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 0dfea962b..f5280bc33 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -421,7 +421,7 @@ void SExpressionWasmBuilder::preParseFunctionType(Element& s) {
functionType->name = Name::fromInt(wasm.functionTypes.size());
functionTypeNames.push_back(functionType->name);
if (wasm.getFunctionTypeOrNull(functionType->name)) throw ParseException("duplicate function type", s.line, s.col);
- wasm.addFunctionType(functionType.release());
+ wasm.addFunctionType(std::move(functionType));
}
}
}
@@ -1828,7 +1828,7 @@ void SExpressionWasmBuilder::parseType(Element& s) {
}
functionTypeNames.push_back(type->name);
if (wasm.getFunctionTypeOrNull(type->name)) throw ParseException("duplicate function type", s.line, s.col);
- wasm.addFunctionType(type.release());
+ wasm.addFunctionType(std::move(type));
}
} // namespace wasm
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index cfee4f3c4..757bc1828 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -809,15 +809,17 @@ Global* Module::getGlobalOrNull(Name name) {
return iter->second;
}
-void Module::addFunctionType(FunctionType* curr) {
+FunctionType* Module::addFunctionType(std::unique_ptr<FunctionType> curr) {
if (!curr->name.is()) {
Fatal() << "Module::addFunctionType: empty name";
}
if (getFunctionTypeOrNull(curr->name)) {
Fatal() << "Module::addFunctionType: " << curr->name << " already exists";
}
- functionTypes.push_back(std::unique_ptr<FunctionType>(curr));
- functionTypesMap[curr->name] = curr;
+ auto* p = curr.get();
+ functionTypes.emplace_back(std::move(curr));
+ functionTypesMap[p->name] = p;
+ return p;
}
void Module::addExport(Export* curr) {