1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-03 12:07:26 +00:00

Expanded "used" logic of inine ASM to include procedure refs.

This commit is contained in:
jespergravgaard 2019-08-10 18:27:05 +02:00
parent 074826fb1f
commit ffa75b1732
10 changed files with 277 additions and 302 deletions

View File

@ -410,7 +410,7 @@ public interface ProgramValue {
@Override
public void set(Value value) {
statementAsm.getReferenced().put(label, (SymbolVariableRef) value);
statementAsm.getReferenced().put(label, (SymbolRef) value);
}
}

View File

@ -151,7 +151,7 @@ public class ProgramValueIterator {
}
} else if(statement instanceof StatementAsm) {
StatementAsm statementAsm = (StatementAsm) statement;
Map<String, SymbolVariableRef> referenced = statementAsm.getReferenced();
Map<String, SymbolRef> referenced = statementAsm.getReferenced();
for(String label : referenced.keySet()) {
execute(new ProgramValue.ProgramValueAsmReferenced(statementAsm, label), handler, statement, statementsIt, block);
}

View File

@ -4,6 +4,7 @@ import dk.camelot64.kickc.AsmParser;
import dk.camelot64.kickc.asm.AsmClobber;
import dk.camelot64.kickc.model.Comment;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.values.SymbolRef;
import dk.camelot64.kickc.model.values.SymbolVariableRef;
import dk.camelot64.kickc.parser.KickCParser;
@ -20,12 +21,12 @@ public class StatementAsm extends StatementBase {
private transient KickCParser.AsmLinesContext asmLines;
/** All variables/constants referenced in the inline assembler. */
private Map<String, SymbolVariableRef> referenced;
private Map<String, SymbolRef> referenced;
/** Declared clobber for the inline ASM. */
private AsmClobber declaredClobber;
public StatementAsm(String asmBody, Map<String, SymbolVariableRef> referenced, AsmClobber declaredClobber, StatementSource source, List<Comment> comments) {
public StatementAsm(String asmBody, Map<String, SymbolRef> referenced, AsmClobber declaredClobber, StatementSource source, List<Comment> comments) {
super(null, source, comments);
this.asmBody = asmBody;
this.referenced = referenced;
@ -54,11 +55,11 @@ public class StatementAsm extends StatementBase {
return asmLines;
}
public void setReferenced(Map<String, SymbolVariableRef> referenced) {
public void setReferenced(Map<String, SymbolRef> referenced) {
this.referenced = referenced;
}
public Map<String, SymbolVariableRef> getReferenced() {
public Map<String, SymbolRef> getReferenced() {
return referenced;
}

View File

@ -1157,7 +1157,7 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
// Find all defined labels in the ASM
List<String> definedLabels = getAsmDefinedLabels(ctx);
// Find all referenced symbols in the ASM
Map<String, SymbolVariableRef> referenced = getAsmReferencedSymbolVariables(ctx, definedLabels);
Map<String, SymbolRef> referenced = getAsmReferencedSymbolVariables(ctx, definedLabels);
List<Comment> comments = ensureUnusedComments(getCommentsSymbol(ctx));
AsmClobber declaredClobber = null;
@ -1199,8 +1199,8 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
* @param definedLabels All labels defined in the ASM
* @return All variables/constants referenced in the ASM. Some may be ForwardVariableRefs to be resolved later.
*/
private Map<String, SymbolVariableRef> getAsmReferencedSymbolVariables(KickCParser.StmtAsmContext ctx, List<String> definedLabels) {
Map<String, SymbolVariableRef> referenced = new LinkedHashMap<>();
private Map<String, SymbolRef> getAsmReferencedSymbolVariables(KickCParser.StmtAsmContext ctx, List<String> definedLabels) {
Map<String, SymbolRef> referenced = new LinkedHashMap<>();
KickCBaseVisitor<Void> findReferenced = new KickCBaseVisitor<Void>() {
@Override
@ -1221,9 +1221,8 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
if(!definedLabels.contains(label)) {
// Look for the symbol
Symbol symbol = getCurrentScope().getSymbol(ctxLabel.NAME().getText());
if(symbol instanceof Variable) {
Variable variable = (Variable) symbol;
referenced.put(label, variable.getRef());
if(symbol!=null) {
referenced.put(label, symbol.getRef());
} else {
// Either forward reference or a non-existing variable. Create a forward reference for later resolving.
referenced.put(label, new ForwardVariableRef(ctxLabel.NAME().getText()));

View File

@ -44,10 +44,10 @@ public class Pass3AssertConstants extends Pass2SsaAssertion {
}
} else if(statement instanceof StatementAsm) {
StatementAsm statementAsm = (StatementAsm) statement;
Map<String, SymbolVariableRef> referenced = statementAsm.getReferenced();
Map<String, SymbolRef> referenced = statementAsm.getReferenced();
for(String label : referenced.keySet()) {
SymbolVariableRef symbolRef = referenced.get(label);
if(!(symbolRef instanceof ConstantRef)) {
SymbolRef symbolRef = referenced.get(label);
if(!(symbolRef instanceof ConstantRef) && !(symbolRef instanceof ProcedureRef)) {
throw new CompileError("Error! Inline ASM reference is not constant " + label, statement);
}
}

View File

@ -20,7 +20,6 @@ char[] MESSAGE = "hello world!";
void main() {
// Initialize screen memory
*VIC_MEMORY = 0x14;
*BGCOL = 0x0f;
// Init screen/colors
memset(SCREEN, ' ', 40*25);
memset(COLS, WHITE, 40*25);
@ -40,15 +39,12 @@ void main() {
}
}
void syscall1() {
const char* BORDERCOL = $d020;
(*BORDERCOL)++;
*(SCREEN+79) = '>';
}
void syscall2() {
const char* BGCOL = $d021;
(*BGCOL)++;
*(SCREEN+78) = '<';
}
#pragma data_seg(Syscall)

View File

@ -24,8 +24,6 @@ main: {
// Initialize screen memory
lda #$14
sta VIC_MEMORY
lda #$f
sta BGCOL
ldx #' '
lda #<SCREEN
sta.z memset.str
@ -126,13 +124,13 @@ memset: {
jmp b2
}
syscall2: {
.label BGCOL = $d021
inc BGCOL
lda #'<'
sta SCREEN+$4e
rts
}
syscall1: {
.label BORDERCOL = $d020
inc BORDERCOL
lda #'>'
sta SCREEN+$4f
rts
}
.segment Data

View File

@ -9,65 +9,64 @@
[3] phi()
main: scope:[main] from @1
[4] *((const byte*) VIC_MEMORY#0) ← (byte) $14
[5] *((const byte*) BGCOL#0) ← (byte) $f
[6] call memset
[5] call memset
to:main::@6
main::@6: scope:[main] from main
[7] phi()
[8] call memset
[6] phi()
[7] call memset
to:main::@1
main::@1: scope:[main] from main::@2 main::@6
[9] (byte*) main::sc#2 ← phi( main::@6/(const byte*) SCREEN#0+(byte) $28 main::@2/(byte*) main::sc#1 )
[9] (byte*) main::msg#2 ← phi( main::@6/(const byte[]) MESSAGE#0 main::@2/(byte*) main::msg#1 )
[10] if((byte) 0!=*((byte*) main::msg#2)) goto main::@2
[8] (byte*) main::sc#2 ← phi( main::@6/(const byte*) SCREEN#0+(byte) $28 main::@2/(byte*) main::sc#1 )
[8] (byte*) main::msg#2 ← phi( main::@6/(const byte[]) MESSAGE#0 main::@2/(byte*) main::msg#1 )
[9] if((byte) 0!=*((byte*) main::msg#2)) goto main::@2
to:main::@3
main::@3: scope:[main] from main::@1 main::@4 main::@5
[11] if(*((const byte*) RASTER#0)==(byte) $36) goto main::@4
[10] if(*((const byte*) RASTER#0)==(byte) $36) goto main::@4
to:main::@7
main::@7: scope:[main] from main::@3
[12] if(*((const byte*) RASTER#0)==(byte) $42) goto main::@4
[11] if(*((const byte*) RASTER#0)==(byte) $42) goto main::@4
to:main::@5
main::@5: scope:[main] from main::@7
[13] *((const byte*) BGCOL#0) ← (const byte) BLACK#0
[12] *((const byte*) BGCOL#0) ← (const byte) BLACK#0
to:main::@3
main::@4: scope:[main] from main::@3 main::@7
[14] *((const byte*) BGCOL#0) ← (const byte) WHITE#0
[13] *((const byte*) BGCOL#0) ← (const byte) WHITE#0
to:main::@3
main::@2: scope:[main] from main::@1
[15] *((byte*) main::sc#2) ← *((byte*) main::msg#2)
[16] (byte*) main::sc#1 ← ++ (byte*) main::sc#2
[17] (byte*) main::msg#1 ← ++ (byte*) main::msg#2
[14] *((byte*) main::sc#2) ← *((byte*) main::msg#2)
[15] (byte*) main::sc#1 ← ++ (byte*) main::sc#2
[16] (byte*) main::msg#1 ← ++ (byte*) main::msg#2
to:main::@1
memset: scope:[memset] from main main::@6
[18] (byte) memset::c#4 ← phi( main/(byte) ' ' main::@6/(const byte) WHITE#0 )
[18] (void*) memset::str#3 ← phi( main/(void*)(const byte*) SCREEN#0 main::@6/(void*)(const byte*) COLS#0 )
[18] (word) memset::num#2 ← phi( main/(word)(number) $28*(number) $19 main::@6/(word)(number) $28*(number) $19 )
[19] if((word) memset::num#2<=(byte) 0) goto memset::@return
[17] (byte) memset::c#4 ← phi( main/(byte) ' ' main::@6/(const byte) WHITE#0 )
[17] (void*) memset::str#3 ← phi( main/(void*)(const byte*) SCREEN#0 main::@6/(void*)(const byte*) COLS#0 )
[17] (word) memset::num#2 ← phi( main/(word)(number) $28*(number) $19 main::@6/(word)(number) $28*(number) $19 )
[18] if((word) memset::num#2<=(byte) 0) goto memset::@return
to:memset::@1
memset::@1: scope:[memset] from memset
[20] (byte*) memset::end#0 ← (byte*)(void*) memset::str#3 + (word) memset::num#2
[21] (byte*~) memset::dst#4 ← (byte*)(void*) memset::str#3
[19] (byte*) memset::end#0 ← (byte*)(void*) memset::str#3 + (word) memset::num#2
[20] (byte*~) memset::dst#4 ← (byte*)(void*) memset::str#3
to:memset::@2
memset::@2: scope:[memset] from memset::@1 memset::@3
[22] (byte*) memset::dst#2 ← phi( memset::@1/(byte*~) memset::dst#4 memset::@3/(byte*) memset::dst#1 )
[23] if((byte*) memset::dst#2!=(byte*) memset::end#0) goto memset::@3
[21] (byte*) memset::dst#2 ← phi( memset::@1/(byte*~) memset::dst#4 memset::@3/(byte*) memset::dst#1 )
[22] if((byte*) memset::dst#2!=(byte*) memset::end#0) goto memset::@3
to:memset::@return
memset::@return: scope:[memset] from memset memset::@2
[24] return
[23] return
to:@return
memset::@3: scope:[memset] from memset::@2
[25] *((byte*) memset::dst#2) ← (byte) memset::c#4
[26] (byte*) memset::dst#1 ← ++ (byte*) memset::dst#2
[24] *((byte*) memset::dst#2) ← (byte) memset::c#4
[25] (byte*) memset::dst#1 ← ++ (byte*) memset::dst#2
to:memset::@2
syscall2: scope:[syscall2] from
[27] *((const byte*) syscall2::BGCOL#0) ← ++ *((const byte*) syscall2::BGCOL#0)
[26] *((const byte*) SCREEN#0+(byte) $4e) ← (byte) '<'
to:syscall2::@return
syscall2::@return: scope:[syscall2] from syscall2
[28] return
[27] return
to:@return
syscall1: scope:[syscall1] from
[29] *((const byte*) syscall1::BORDERCOL#0) ← ++ *((const byte*) syscall1::BORDERCOL#0)
[28] *((const byte*) SCREEN#0+(byte) $4f) ← (byte) '>'
to:syscall1::@return
syscall1::@return: scope:[syscall1] from syscall1
[30] return
[29] return
to:@return

File diff suppressed because it is too large Load Diff

View File

@ -62,12 +62,8 @@
(void*) memset::str#3 str zp ZP_WORD:4
(void()) syscall1()
(label) syscall1::@return
(byte*) syscall1::BORDERCOL
(const byte*) syscall1::BORDERCOL#0 BORDERCOL = (byte*) 53280
(void()) syscall2()
(label) syscall2::@return
(byte*) syscall2::BGCOL
(const byte*) syscall2::BGCOL#0 BGCOL = (byte*) 53281
zp ZP_WORD:2 [ memset::num#2 memset::end#0 main::msg#2 main::msg#1 ]
zp ZP_WORD:4 [ memset::str#3 memset::dst#2 memset::dst#4 memset::dst#1 main::sc#2 main::sc#1 ]