3333// disallow f32s. TODO: an option to not do that, if it matters?
3434//
3535
36+ #include < utility>
3637#include " wasm.h"
3738#include " pass.h"
3839#include " asm_v_wasm.h"
@@ -85,7 +86,7 @@ struct LegalizeJSInterface : public Pass {
8586 }
8687 }
8788 }
88- if (illegalImportsToLegal.size () > 0 ) {
89+ if (! illegalImportsToLegal.empty () ) {
8990 for (auto & pair : illegalImportsToLegal) {
9091 module ->removeFunction (pair.first );
9192 }
@@ -126,8 +127,7 @@ struct LegalizeJSInterface : public Pass {
126127 for (auto param : t->params ) {
127128 if (param == i64 || param == f32 ) return true ;
128129 }
129- if (t->result == i64 || t->result == f32 ) return true ;
130- return false ;
130+ return t->result == i64 || t->result == f32 ;
131131 }
132132
133133 // Check if an export should be legalized.
@@ -171,7 +171,7 @@ struct LegalizeJSInterface : public Pass {
171171 if (func->result == i64 ) {
172172 Function* f = getFunctionOrImport (module , SET_TEMP_RET0, " vi" );
173173 legal->result = i32 ;
174- auto index = builder. addVar (legal, Name (), i64 );
174+ auto index = Builder:: addVar (legal, Name (), i64 );
175175 auto * block = builder.makeBlock ();
176176 block->list .push_back (builder.makeSetLocal (index, call));
177177 block->list .push_back (builder.makeCall (f->name , {I64Utilities::getI64High (builder, index)}, none));
@@ -198,12 +198,12 @@ struct LegalizeJSInterface : public Pass {
198198 Builder builder (*module );
199199 auto type = make_unique<FunctionType>();
200200 type->name = Name (std::string (" legaltype$" ) + im->name .str );
201- auto * legal = new Function;
201+ auto legal = make_unique< Function>() ;
202202 legal->name = Name (std::string (" legalimport$" ) + im->name .str );
203203 legal->module = im->module ;
204204 legal->base = im->base ;
205205 legal->type = type->name ;
206- auto * func = new Function;
206+ auto func = make_unique< Function>() ;
207207 func->name = Name (std::string (" legalfunc$" ) + im->name .str );
208208
209209 auto * call = module ->allocator .alloc <Call>();
@@ -243,18 +243,19 @@ struct LegalizeJSInterface : public Pass {
243243 type->result = imFunctionType->result ;
244244 }
245245 func->result = imFunctionType->result ;
246- FunctionTypeUtils::fillFunction (legal, type.get ());
246+ FunctionTypeUtils::fillFunction (legal. get () , type.get ());
247247
248- if (!module ->getFunctionOrNull (func->name )) {
249- module ->addFunction (func);
248+ const auto & funcName = func->name ;
249+ if (!module ->getFunctionOrNull (funcName)) {
250+ module ->addFunction (std::move (func));
250251 }
251252 if (!module ->getFunctionTypeOrNull (type->name )) {
252253 module ->addFunctionType (std::move (type));
253254 }
254255 if (!module ->getFunctionOrNull (legal->name )) {
255- module ->addFunction (legal);
256+ module ->addFunction (std::move ( legal) );
256257 }
257- return func-> name ;
258+ return funcName ;
258259 }
259260
260261 static Function* getFunctionOrImport (Module* module , Name name, std::string sig) {
@@ -272,7 +273,7 @@ struct LegalizeJSInterface : public Pass {
272273 import ->name = name;
273274 import ->module = ENV;
274275 import ->base = name;
275- auto * functionType = ensureFunctionType (sig, module );
276+ auto * functionType = ensureFunctionType (std::move ( sig) , module );
276277 import ->type = functionType->name ;
277278 FunctionTypeUtils::fillFunction (import , functionType);
278279 module ->addFunction (import );
0 commit comments