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

View File

@ -145,7 +145,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
SourceStorageKind.EXPRESSION -> {
when(val value = assign.source.expression!!) {
is AddressOf -> {
val sourceName = asmgen.asmVariableName(value.identifier)
val sourceName = asmgen.asmSymbolName(value.identifier)
assignAddressOf(assign.target, sourceName)
}
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.
val vardecl = stringVar.targetVarDecl(program)!!
val string = vardecl.value as? StringLiteralValue
val string = stringVar.targetVarDecl(program)?.value as? StringLiteralValue
if(string!=null) {
val pos = functionCallStatement.position
if (string.value.length == 1) {