allow assigns to asmsub parameters (registers), but this is not very useful in practice.

This commit is contained in:
Irmen de Jong 2021-11-27 15:41:44 +01:00
parent 54025d2bf5
commit 62485b6851
2 changed files with 30 additions and 24 deletions

View File

@ -56,7 +56,8 @@ internal class AsmAssignTarget(val kind: TargetStorageKind,
} }
companion object { companion object {
fun fromAstAssignment(assign: Assignment, program: Program, asmgen: AsmGen): AsmAssignTarget = with(assign.target) { fun fromAstAssignment(assign: Assignment, program: Program, asmgen: AsmGen): AsmAssignTarget {
with(assign.target) {
val idt = inferType(program) val idt = inferType(program)
if(!idt.isKnown) if(!idt.isKnown)
throw AssemblyError("unknown dt") throw AssemblyError("unknown dt")
@ -64,16 +65,24 @@ internal class AsmAssignTarget(val kind: TargetStorageKind,
when { when {
identifier != null -> { identifier != null -> {
val parameter = identifier!!.targetVarDecl(program)?.subroutineParameter val parameter = identifier!!.targetVarDecl(program)?.subroutineParameter
if(parameter!=null && parameter.definingSubroutine!!.isAsmSubroutine) { if (parameter!=null) {
TODO("ASSIGNTARGET ASMPARAM $parameter :: $assign") val sub = parameter.definingSubroutine!!
if (sub.isAsmSubroutine) {
val reg = sub.asmParameterRegisters[sub.parameters.indexOf(parameter)]
if(reg.statusflag!=null)
throw AssemblyError("can't assign value to processor statusflag directly")
else
return AsmAssignTarget(TargetStorageKind.REGISTER, program, asmgen, dt, assign.definingSubroutine, register=reg.registerOrPair, origAstTarget = this)
} }
AsmAssignTarget(TargetStorageKind.VARIABLE, program, asmgen, dt, assign.definingSubroutine, variableAsmName = asmgen.asmVariableName(identifier!!), origAstTarget = this)
} }
arrayindexed != null -> AsmAssignTarget(TargetStorageKind.ARRAY, program, asmgen, dt, assign.definingSubroutine, array = arrayindexed, origAstTarget = this) return AsmAssignTarget(TargetStorageKind.VARIABLE, program, asmgen, dt, assign.definingSubroutine, variableAsmName = asmgen.asmVariableName(identifier!!), origAstTarget = this)
memoryAddress != null -> AsmAssignTarget(TargetStorageKind.MEMORY, program, asmgen, dt, assign.definingSubroutine, memory = memoryAddress, origAstTarget = this) }
arrayindexed != null -> return AsmAssignTarget(TargetStorageKind.ARRAY, program, asmgen, dt, assign.definingSubroutine, array = arrayindexed, origAstTarget = this)
memoryAddress != null -> return AsmAssignTarget(TargetStorageKind.MEMORY, program, asmgen, dt, assign.definingSubroutine, memory = memoryAddress, origAstTarget = this)
else -> throw AssemblyError("weird target") else -> throw AssemblyError("weird target")
} }
} }
}
fun fromRegisters(registers: RegisterOrPair, signed: Boolean, scope: Subroutine?, program: Program, asmgen: AsmGen): AsmAssignTarget = fun fromRegisters(registers: RegisterOrPair, signed: Boolean, scope: Subroutine?, program: Program, asmgen: AsmGen): AsmAssignTarget =
when(registers) { when(registers) {
@ -140,9 +149,8 @@ internal class AsmAssignSource(val kind: SourceStorageKind,
is ArrayLiteralValue -> throw AssemblyError("array literal value should not occur anymore for asm generation") is ArrayLiteralValue -> throw AssemblyError("array literal value should not occur anymore for asm generation")
is IdentifierReference -> { is IdentifierReference -> {
val parameter = value.targetVarDecl(program)?.subroutineParameter val parameter = value.targetVarDecl(program)?.subroutineParameter
if(parameter!=null && parameter.definingSubroutine!!.isAsmSubroutine) { if(parameter!=null && parameter.definingSubroutine!!.isAsmSubroutine)
TODO("ASSIGNSOURCE ASMPARAM $parameter :: $value") throw AssemblyError("can't assign from a asmsub register parameter")
}
val dt = value.inferType(program).getOr(DataType.UNDEFINED) val dt = value.inferType(program).getOr(DataType.UNDEFINED)
val varName=asmgen.asmVariableName(value) val varName=asmgen.asmVariableName(value)
// special case: "cx16.r[0-15]" are 16-bits virtual registers of the commander X16 system // special case: "cx16.r[0-15]" are 16-bits virtual registers of the commander X16 system

View File

@ -2,21 +2,19 @@
main { main {
sub start() { sub start() {
uword ww
&ubyte derp = $c000 main.routine2.num = ww+1
main.routine2.switch=true
@($c000) = not @($c000) routine2(ww+1, true)
@($c000) = ~ @($c000)
ubyte uu
uu = abs(uu)
routine2(12345, true)
repeat { repeat {
} }
} }
asmsub routine2(uword num @AY, ubyte switch @Pc) { asmsub routine2(uword num @AY, ubyte switch @X) {
%asm {{ %asm {{
adc #20 adc #20
rts rts