fix compiler crash when taking address of label

This commit is contained in:
Irmen de Jong 2021-05-15 23:58:48 +02:00
parent ae5d7705bb
commit bc731e6f8e
3 changed files with 8 additions and 13 deletions

View File

@ -493,8 +493,11 @@ internal class AsmGen(private val program: Program,
return newName return newName
} }
internal fun asmSymbolName(identifier: IdentifierReference) = internal fun asmSymbolName(identifier: IdentifierReference): String {
fixNameSymbols(identifier.nameInSource.joinToString(".")) val target = identifier.targetStatement(program)
val prefix = if(target is Label) "_" else ""
return fixNameSymbols(prefix+identifier.nameInSource.joinToString("."))
}
internal fun asmSymbolName(regs: RegisterOrPair): String = internal fun asmSymbolName(regs: RegisterOrPair): String =
if (regs in Cx16VirtualRegisters) if (regs in Cx16VirtualRegisters)
@ -1264,14 +1267,7 @@ $label nop""")
val label = jump.generatedLabel val label = jump.generatedLabel
val addr = jump.address val addr = jump.address
return when { return when {
ident!=null -> { ident!=null -> asmSymbolName(ident)
val target = ident.targetStatement(program)
val asmName = asmSymbolName(ident)
if(target is Label)
"_$asmName" // prefix with underscore to jump to local label
else
asmName
}
label!=null -> label label!=null -> label
addr!=null -> addr.toHex() addr!=null -> addr.toHex()
else -> "????" else -> "????"

View File

@ -145,7 +145,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
SourceStorageKind.EXPRESSION -> { SourceStorageKind.EXPRESSION -> {
when(val value = assign.source.expression!!) { when(val value = assign.source.expression!!) {
is AddressOf -> { is AddressOf -> {
val sourceName = asmgen.asmVariableName(value.identifier) val sourceName = asmgen.asmSymbolName(value.identifier)
assignAddressOf(assign.target, sourceName) assignAddressOf(assign.target, sourceName)
} }
is NumericLiteralValue -> throw AssemblyError("source kind should have been literalnumber") is NumericLiteralValue -> throw AssemblyError("source kind should have been literalnumber")

View File

@ -59,8 +59,7 @@ internal class StatementOptimizer(private val program: Program,
// TODO: only do this optimization if the arg is a known-constant string literal instead of a user defined variable. We can't see the difference here yet. // TODO: only do this optimization if the arg is a known-constant string literal instead of a user defined variable. We can't see the difference here yet.
val vardecl = stringVar.targetVarDecl(program)!! val string = stringVar.targetVarDecl(program)?.value as? StringLiteralValue
val string = vardecl.value as? StringLiteralValue
if(string!=null) { if(string!=null) {
val pos = functionCallStatement.position val pos = functionCallStatement.position
if (string.value.length == 1) { if (string.value.length == 1) {