[Wasm] Require location for buildRefNull and fix all usages
This commit is contained in:
+5
-4
@@ -287,8 +287,9 @@ class BodyGenerator(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val location = expression.getSourceLocation()
|
||||||
|
|
||||||
if (expression.symbol.owner.hasWasmPrimitiveConstructorAnnotation()) {
|
if (expression.symbol.owner.hasWasmPrimitiveConstructorAnnotation()) {
|
||||||
val location = expression.getSourceLocation()
|
|
||||||
generateAnyParameters(klassSymbol, location)
|
generateAnyParameters(klassSymbol, location)
|
||||||
for (i in 0 until expression.valueArgumentsCount) {
|
for (i in 0 until expression.valueArgumentsCount) {
|
||||||
generateExpression(expression.getValueArgument(i)!!)
|
generateExpression(expression.getValueArgument(i)!!)
|
||||||
@@ -298,7 +299,7 @@ class BodyGenerator(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
body.buildRefNull(WasmHeapType.Simple.NullNone) // this = null
|
body.buildRefNull(WasmHeapType.Simple.NullNone, location) // this = null
|
||||||
generateCall(expression)
|
generateCall(expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +310,7 @@ class BodyGenerator(
|
|||||||
if (klassSymbol.owner.hasInterfaceSuperClass()) {
|
if (klassSymbol.owner.hasInterfaceSuperClass()) {
|
||||||
body.buildGetGlobal(context.referenceGlobalClassITable(klassSymbol), location)
|
body.buildGetGlobal(context.referenceGlobalClassITable(klassSymbol), location)
|
||||||
} else {
|
} else {
|
||||||
body.buildRefNull(WasmHeapType.Simple.Data)
|
body.buildRefNull(WasmHeapType.Simple.Data, location)
|
||||||
}
|
}
|
||||||
|
|
||||||
body.buildConstI32Symbol(context.referenceClassId(klassSymbol), location)
|
body.buildConstI32Symbol(context.referenceClassId(klassSymbol), location)
|
||||||
@@ -721,7 +722,7 @@ class BodyGenerator(
|
|||||||
if (actualType.isNullableNothing() && expectedType.isNullable()) {
|
if (actualType.isNullableNothing() && expectedType.isNullable()) {
|
||||||
if (expectedType.getClass()?.isExternal == true) {
|
if (expectedType.getClass()?.isExternal == true) {
|
||||||
body.buildDrop()
|
body.buildDrop()
|
||||||
body.buildRefNull(WasmHeapType.Simple.NullNoExtern)
|
body.buildRefNull(WasmHeapType.Simple.NullNoExtern, location)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-9
@@ -258,6 +258,7 @@ class DeclarationGenerator(
|
|||||||
val vTableRefGcType = WasmRefType(WasmHeapType.Type(vTableTypeReference))
|
val vTableRefGcType = WasmRefType(WasmHeapType.Type(vTableTypeReference))
|
||||||
|
|
||||||
val initVTableGlobal = buildWasmExpression {
|
val initVTableGlobal = buildWasmExpression {
|
||||||
|
val location = SourceLocation.NoLocation("Create instance of vtable struct")
|
||||||
metadata.virtualMethods.forEachIndexed { i, method ->
|
metadata.virtualMethods.forEachIndexed { i, method ->
|
||||||
if (method.function.modality != Modality.ABSTRACT) {
|
if (method.function.modality != Modality.ABSTRACT) {
|
||||||
buildInstr(WasmOp.REF_FUNC, WasmImmediate.FuncIdx(context.referenceFunction(method.function.symbol)))
|
buildInstr(WasmOp.REF_FUNC, WasmImmediate.FuncIdx(context.referenceFunction(method.function.symbol)))
|
||||||
@@ -266,10 +267,10 @@ class DeclarationGenerator(
|
|||||||
"Cannot find class implementation of method ${method.signature} in class ${klass.fqNameWhenAvailable}"
|
"Cannot find class implementation of method ${method.signature} in class ${klass.fqNameWhenAvailable}"
|
||||||
}
|
}
|
||||||
//This erased by DCE so abstract version appeared in non-abstract class
|
//This erased by DCE so abstract version appeared in non-abstract class
|
||||||
buildRefNull(vtableStruct.fields[i].type.getHeapType())
|
buildRefNull(vtableStruct.fields[i].type.getHeapType(), location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildStructNew(vTableTypeReference, SourceLocation.NoLocation("Create instance of vtable struct"))
|
buildStructNew(vTableTypeReference, location)
|
||||||
}
|
}
|
||||||
context.defineGlobalVTable(
|
context.defineGlobalVTable(
|
||||||
irClass = symbol,
|
irClass = symbol,
|
||||||
@@ -294,7 +295,7 @@ class DeclarationGenerator(
|
|||||||
val iFaceVTableGcNullHeapType = WasmHeapType.Type(iFaceVTableGcType)
|
val iFaceVTableGcNullHeapType = WasmHeapType.Type(iFaceVTableGcType)
|
||||||
|
|
||||||
if (!metadata.interfaces.contains(iFace.owner)) {
|
if (!metadata.interfaces.contains(iFace.owner)) {
|
||||||
buildRefNull(iFaceVTableGcNullHeapType)
|
buildRefNull(iFaceVTableGcNullHeapType, location)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +312,7 @@ class DeclarationGenerator(
|
|||||||
buildInstr(WasmOp.REF_FUNC, WasmImmediate.FuncIdx(functionTypeReference))
|
buildInstr(WasmOp.REF_FUNC, WasmImmediate.FuncIdx(functionTypeReference))
|
||||||
} else {
|
} else {
|
||||||
//This erased by DCE so abstract version appeared in non-abstract class
|
//This erased by DCE so abstract version appeared in non-abstract class
|
||||||
buildRefNull(WasmHeapType.Type(context.referenceFunctionType(method.function.symbol)))
|
buildRefNull(WasmHeapType.Type(context.referenceFunctionType(method.function.symbol)), location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildStructNew(iFaceVTableGcType, location)
|
buildStructNew(iFaceVTableGcType, location)
|
||||||
@@ -482,11 +483,11 @@ fun generateDefaultInitializerForType(type: WasmType, g: WasmExpressionBuilder)
|
|||||||
WasmI64 -> g.buildConstI64(0, location)
|
WasmI64 -> g.buildConstI64(0, location)
|
||||||
WasmF32 -> g.buildConstF32(0f, location)
|
WasmF32 -> g.buildConstF32(0f, location)
|
||||||
WasmF64 -> g.buildConstF64(0.0, location)
|
WasmF64 -> g.buildConstF64(0.0, location)
|
||||||
is WasmRefNullType -> g.buildRefNull(type.heapType)
|
is WasmRefNullType -> g.buildRefNull(type.heapType, location)
|
||||||
is WasmRefNullNoneType -> g.buildRefNull(WasmHeapType.Simple.NullNone)
|
is WasmRefNullNoneType -> g.buildRefNull(WasmHeapType.Simple.NullNone, location)
|
||||||
is WasmRefNullExternrefType -> g.buildRefNull(WasmHeapType.Simple.NullNoExtern)
|
is WasmRefNullExternrefType -> g.buildRefNull(WasmHeapType.Simple.NullNoExtern, location)
|
||||||
is WasmAnyRef -> g.buildRefNull(WasmHeapType.Simple.Any)
|
is WasmAnyRef -> g.buildRefNull(WasmHeapType.Simple.Any, location)
|
||||||
is WasmExternRef -> g.buildRefNull(WasmHeapType.Simple.Extern)
|
is WasmExternRef -> g.buildRefNull(WasmHeapType.Simple.Extern, location)
|
||||||
WasmUnreachableType -> error("Unreachable type can't be initialized")
|
WasmUnreachableType -> error("Unreachable type can't be initialized")
|
||||||
else -> error("Unknown value type ${type.name}")
|
else -> error("Unknown value type ${type.name}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,8 +175,8 @@ abstract class WasmExpressionBuilder {
|
|||||||
buildInstr(WasmOp.REF_TEST_DEPRECATED, location, WasmImmediate.TypeIdx(toType))
|
buildInstr(WasmOp.REF_TEST_DEPRECATED, location, WasmImmediate.TypeIdx(toType))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildRefNull(type: WasmHeapType) {
|
fun buildRefNull(type: WasmHeapType, location: SourceLocation) {
|
||||||
buildInstr(WasmOp.REF_NULL, WasmImmediate.HeapType(WasmRefType(type)))
|
buildInstr(WasmOp.REF_NULL, location, WasmImmediate.HeapType(WasmRefType(type)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildDrop() {
|
fun buildDrop() {
|
||||||
|
|||||||
Reference in New Issue
Block a user