WASM: NFC. Move IrBlockBody visit into body builder
This commit is contained in:
committed by
TeamCityServer
parent
a246ec636e
commit
3ecf9306b1
+4
@@ -339,6 +339,10 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
|
||||
return true
|
||||
}
|
||||
|
||||
override fun visitBlockBody(body: IrBlockBody) {
|
||||
body.statements.forEach(::statementToWasmInstruction)
|
||||
}
|
||||
|
||||
override fun visitContainerExpression(expression: IrContainerExpression) {
|
||||
val statements = expression.statements
|
||||
if (statements.isEmpty()) {
|
||||
|
||||
+4
-10
@@ -137,14 +137,8 @@ class DeclarationGenerator(val context: WasmModuleCodegenContext) : IrElementVis
|
||||
val exprGen = functionCodegenContext.bodyGen
|
||||
val bodyBuilder = BodyGenerator(functionCodegenContext)
|
||||
|
||||
when (val body = declaration.body) {
|
||||
is IrBlockBody ->
|
||||
for (statement in body.statements) {
|
||||
bodyBuilder.statementToWasmInstruction(statement)
|
||||
}
|
||||
|
||||
else -> error("Unexpected body $body")
|
||||
}
|
||||
require(declaration.body is IrBlockBody) { "Only IrBlockBody is supported" }
|
||||
declaration.body?.acceptVoid(bodyBuilder)
|
||||
|
||||
// Return implicit this from constructions to avoid extra tmp
|
||||
// variables on constructor call sites.
|
||||
@@ -155,8 +149,8 @@ class DeclarationGenerator(val context: WasmModuleCodegenContext) : IrElementVis
|
||||
}
|
||||
|
||||
// Add unreachable if function returns something but not as a last instruction.
|
||||
if (wasmFunctionType.resultTypes.isNotEmpty() && declaration.body is IrBlockBody) {
|
||||
// TODO: Add unreachable only if needed
|
||||
// We can do a separate lowering which adds explicit returns everywhere instead.
|
||||
if (wasmFunctionType.resultTypes.isNotEmpty()) {
|
||||
exprGen.buildUnreachable()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user