@@ -34,7 +34,6 @@ class WasmBuilder {
34
34
35
35
def transformTopLevelExport (export : LinkedTopLevelExport )(implicit ctx : WasmContext ): Unit = {
36
36
implicit val fctx = WasmFunctionContext ()
37
- val expressionBuilder = new WasmExpressionBuilder (ctx, fctx)
38
37
export.tree match {
39
38
case d : IRTrees .TopLevelFieldExportDef => ???
40
39
case d : IRTrees .TopLevelJSClassExportDef => ???
@@ -295,7 +294,6 @@ class WasmBuilder {
295
294
private def transformToplevelMethodExportDef (
296
295
exportDef : IRTrees .TopLevelMethodExportDef
297
296
)(implicit ctx : WasmContext , fctx : WasmFunctionContext ) = {
298
- val builder = new WasmExpressionBuilder (ctx, fctx)
299
297
val method = exportDef.methodDef
300
298
val methodName = method.name match {
301
299
case lit : IRTrees .StringLiteral => lit
@@ -363,15 +361,12 @@ class WasmBuilder {
363
361
}
364
362
params.foreach(fctx.locals.define)
365
363
366
- val instrs = newBody match {
367
- case t : IRTrees .Block => t.stats.flatMap(builder.transformTree)
368
- case _ => builder.transformTree(newBody)
369
- }
364
+ val expr = WasmExpressionBuilder .transformBody(newBody, resultType)
370
365
val func = WasmFunction (
371
366
Names .WasmFunctionName (methodName),
372
367
functionType,
373
368
fctx.locals.all,
374
- WasmExpr (instrs)
369
+ expr
375
370
)
376
371
ctx.addFunction(func)
377
372
@@ -417,18 +412,10 @@ class WasmBuilder {
417
412
}).foreach(fctx.locals.define)
418
413
419
414
// build function body
420
- val builder = new WasmExpressionBuilder (ctx, fctx)
421
415
val body = method.body.getOrElse(throw new Exception (" abstract method cannot be transformed" ))
422
416
// val prefix =
423
417
// if (method.flags.namespace.isConstructor) builder.objectCreationPrefix(clazz, method) else Nil
424
- val instrs = body match {
425
- case t : IRTrees .Block => t.stats.flatMap(builder.transformTree)
426
- case _ => builder.transformTree(body)
427
- }
428
- val expr = method.resultType match {
429
- case IRTypes .NoType => WasmExpr (instrs)
430
- case _ => WasmExpr (instrs :+ RETURN )
431
- }
418
+ val expr = WasmExpressionBuilder .transformBody(body, method.resultType)
432
419
433
420
val func = WasmFunction (
434
421
Names .WasmFunctionName (clazz.name.name, method.name.name),
0 commit comments