mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-10-11 12:23:45 +00:00
Working on improving constants.kc. Now everything works except allocation to asby (where clobber by a-register is not detected.)
This commit is contained in:
parent
1c59ae231e
commit
6eb54c11a6
@ -20,6 +20,9 @@ public class Pass5NextJumpElimination extends Pass5AsmOptimization {
|
|||||||
AsmInstruction candidate = null;
|
AsmInstruction candidate = null;
|
||||||
for (AsmSegment segment : getAsmProgram().getSegments()) {
|
for (AsmSegment segment : getAsmProgram().getSegments()) {
|
||||||
for (AsmLine line : segment.getLines()) {
|
for (AsmLine line : segment.getLines()) {
|
||||||
|
if(line instanceof AsmScopeBegin || line instanceof AsmScopeEnd) {
|
||||||
|
candidate = null;
|
||||||
|
}
|
||||||
if (candidate != null) {
|
if (candidate != null) {
|
||||||
if (line instanceof AsmLabel) {
|
if (line instanceof AsmLabel) {
|
||||||
if (((AsmLabel) line).getLabel().equals(candidate.getParameter())) {
|
if (((AsmLabel) line).getLabel().equals(candidate.getParameter())) {
|
||||||
|
@ -3,6 +3,7 @@ const byte GREEN = 5;
|
|||||||
const byte RED = 2 ;
|
const byte RED = 2 ;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
print_cls();
|
||||||
*BGCOL = GREEN;
|
*BGCOL = GREEN;
|
||||||
test_bytes();
|
test_bytes();
|
||||||
test_sbytes();
|
test_sbytes();
|
||||||
@ -11,35 +12,72 @@ void main() {
|
|||||||
// Test different byte constants
|
// Test different byte constants
|
||||||
void test_bytes() {
|
void test_bytes() {
|
||||||
byte bb=0;
|
byte bb=0;
|
||||||
assert_byte(bb, 0);
|
assert_byte("0=0@", bb, 0);
|
||||||
byte bc=bb+2;
|
byte bc=bb+2;
|
||||||
assert_byte(bc, 2);
|
assert_byte("0+2=2@", bc, 2);
|
||||||
byte bd=bc-4;
|
byte bd=bc-4;
|
||||||
assert_byte(bd, 254);
|
assert_byte("0+2-4=254@", bd, 254);
|
||||||
}
|
}
|
||||||
|
|
||||||
void assert_byte(byte b, byte c) {
|
void assert_byte(byte* msg, byte b, byte c) {
|
||||||
|
print_str(msg);
|
||||||
|
print_str(" @");
|
||||||
if(b!=c) {
|
if(b!=c) {
|
||||||
*BGCOL = RED;
|
*BGCOL = RED;
|
||||||
|
print_str("fail!@");
|
||||||
|
} else {
|
||||||
|
print_str("ok@");
|
||||||
}
|
}
|
||||||
|
print_ln();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test different signed byte constants
|
// Test different signed byte constants
|
||||||
void test_sbytes() {
|
void test_sbytes() {
|
||||||
signed byte bb=0;
|
signed byte bb=0;
|
||||||
assert_sbyte(bb, 0);
|
assert_sbyte("0=0@", bb, 0);
|
||||||
signed byte bc=bb+2;
|
signed byte bc=bb+2;
|
||||||
assert_sbyte(bc, 2);
|
assert_sbyte("0+2=2@", bc, 2);
|
||||||
signed byte bd=bc-4;
|
signed byte bd=bc-4;
|
||||||
assert_sbyte(bd, -2);
|
assert_sbyte("0+2-4=-2@", bd, -2);
|
||||||
signed byte be=-bd;
|
signed byte be=-bd;
|
||||||
assert_sbyte(be, 2);
|
assert_sbyte("-(0+2-4)=2@", be, 2);
|
||||||
signed byte bf=-127-127;
|
signed byte bf=-127-127;
|
||||||
assert_sbyte(bf, 2);
|
assert_sbyte("-127-127=2@", bf, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void assert_sbyte(signed byte b, signed byte c) {
|
void assert_sbyte(byte* msg, signed byte b, signed byte c) {
|
||||||
|
print_str(msg);
|
||||||
|
print_str(" @");
|
||||||
if(b!=c) {
|
if(b!=c) {
|
||||||
*BGCOL = RED;
|
*BGCOL = RED;
|
||||||
|
print_str("fail!@");
|
||||||
|
} else {
|
||||||
|
print_str("ok@");
|
||||||
|
}
|
||||||
|
print_ln();
|
||||||
|
}
|
||||||
|
|
||||||
|
byte* line_cursor = $0400;
|
||||||
|
byte* char_cursor = line_cursor;
|
||||||
|
|
||||||
|
// Print a zero-terminated string
|
||||||
|
void print_str(byte* str) {
|
||||||
|
while(*str!='@') {
|
||||||
|
*(char_cursor++) = *(str++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print a newline
|
||||||
|
void print_ln() {
|
||||||
|
do {
|
||||||
|
line_cursor = line_cursor + $28;
|
||||||
|
} while (line_cursor<char_cursor);
|
||||||
|
char_cursor = line_cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the screen
|
||||||
|
void print_cls() {
|
||||||
|
for(byte* sc=$0400; sc!=$0400+1000; sc++) {
|
||||||
|
*sc = ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,3 @@ void print_ln() {
|
|||||||
} while (line_cursor<char_cursor);
|
} while (line_cursor<char_cursor);
|
||||||
char_cursor = line_cursor;
|
char_cursor = line_cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user