mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-11 20:30:08 +00:00
Added __KICKC__ define. Closes #523
This commit is contained in:
parent
8ec4831541
commit
d64faa132d
@ -352,6 +352,7 @@ public class KickC implements Callable<Integer> {
|
||||
cFiles.stream().forEach(path -> CFileNames.append(path.toString()).append(" "));
|
||||
|
||||
Map<String, String> effectiveDefines = new LinkedHashMap<>();
|
||||
effectiveDefines.put("__KICKC__", "1");
|
||||
if(defines != null)
|
||||
effectiveDefines.putAll(defines);
|
||||
if(program.getTargetPlatform().getDefines() != null)
|
||||
|
@ -24,6 +24,8 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
@ -664,6 +666,11 @@ public class TestPrograms {
|
||||
compileAndCompare("cstyle-decl-function.c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreprocessor14() throws IOException, URISyntaxException {
|
||||
compileAndCompare("preprocessor-14.c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreprocessor13() throws IOException, URISyntaxException {
|
||||
compileAndCompare("preprocessor-13.c");
|
||||
@ -4759,7 +4766,11 @@ public class TestPrograms {
|
||||
final TargetPlatform targetPlatform = CTargetPlatformParser.parseTargetPlatformFile(TargetPlatform.DEFAULT_NAME, platformFile, filePath, program.getTargetPlatformPaths());
|
||||
program.setTargetPlatform(targetPlatform);
|
||||
program.addReservedZps(program.getTargetPlatform().getReservedZps());
|
||||
compiler.compile(files, program.getTargetPlatform().getDefines());
|
||||
|
||||
final Map<String, String> defines = new HashMap<>();
|
||||
defines.put("__KICKC__", "1");
|
||||
defines.putAll(program.getTargetPlatform().getDefines());
|
||||
compiler.compile(files, defines);
|
||||
compileAsm(fileName, program);
|
||||
boolean success = true;
|
||||
ReferenceHelper helper = new ReferenceHelperFolder(refPath);
|
||||
|
9
src/test/kc/preprocessor-14.c
Normal file
9
src/test/kc/preprocessor-14.c
Normal file
@ -0,0 +1,9 @@
|
||||
// Test the preprocessor
|
||||
// Test for existence of the __KICKC__ define
|
||||
|
||||
void main() {
|
||||
char * const SCREEN = 0x0400;
|
||||
#ifdef __KICKC__
|
||||
*SCREEN = 1;
|
||||
#endif
|
||||
}
|
13
src/test/ref/preprocessor-14.asm
Normal file
13
src/test/ref/preprocessor-14.asm
Normal file
@ -0,0 +1,13 @@
|
||||
// Test the preprocessor
|
||||
// Test for existence of the __KICKC__ define
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
// *SCREEN = 1
|
||||
lda #1
|
||||
sta SCREEN
|
||||
// }
|
||||
rts
|
||||
}
|
8
src/test/ref/preprocessor-14.cfg
Normal file
8
src/test/ref/preprocessor-14.cfg
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
(void()) main()
|
||||
main: scope:[main] from
|
||||
[0] *((const nomodify byte*) main::SCREEN) ← (byte) 1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main
|
||||
[1] return
|
||||
to:@return
|
160
src/test/ref/preprocessor-14.log
Normal file
160
src/test/ref/preprocessor-14.log
Normal file
@ -0,0 +1,160 @@
|
||||
|
||||
CONTROL FLOW GRAPH SSA
|
||||
|
||||
(void()) main()
|
||||
main: scope:[main] from __start
|
||||
*((const nomodify byte*) main::SCREEN) ← (number) 1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main
|
||||
return
|
||||
to:@return
|
||||
|
||||
(void()) __start()
|
||||
__start: scope:[__start] from
|
||||
call main
|
||||
to:__start::@1
|
||||
__start::@1: scope:[__start] from __start
|
||||
to:__start::@return
|
||||
__start::@return: scope:[__start] from __start::@1
|
||||
return
|
||||
to:@return
|
||||
|
||||
SYMBOL TABLE SSA
|
||||
(void()) __start()
|
||||
(label) __start::@1
|
||||
(label) __start::@return
|
||||
(void()) main()
|
||||
(label) main::@return
|
||||
(const nomodify byte*) main::SCREEN = (byte*)(number) $400
|
||||
|
||||
Adding number conversion cast (unumber) 1 in *((const nomodify byte*) main::SCREEN) ← (number) 1
|
||||
Successful SSA optimization PassNAddNumberTypeConversions
|
||||
Inlining cast *((const nomodify byte*) main::SCREEN) ← (unumber)(number) 1
|
||||
Successful SSA optimization Pass2InlineCast
|
||||
Simplifying constant pointer cast (byte*) 1024
|
||||
Simplifying constant integer cast 1
|
||||
Successful SSA optimization PassNCastSimplification
|
||||
Finalized unsigned number type (byte) 1
|
||||
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
||||
Removing unused procedure __start
|
||||
Removing unused procedure block __start
|
||||
Removing unused procedure block __start::@1
|
||||
Removing unused procedure block __start::@return
|
||||
Successful SSA optimization PassNEliminateEmptyStart
|
||||
CALL GRAPH
|
||||
|
||||
Created 0 initial phi equivalence classes
|
||||
Coalesced down to 0 phi equivalence classes
|
||||
|
||||
FINAL CONTROL FLOW GRAPH
|
||||
|
||||
(void()) main()
|
||||
main: scope:[main] from
|
||||
[0] *((const nomodify byte*) main::SCREEN) ← (byte) 1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main
|
||||
[1] return
|
||||
to:@return
|
||||
|
||||
|
||||
VARIABLE REGISTER WEIGHTS
|
||||
(void()) main()
|
||||
|
||||
Initial phi equivalence classes
|
||||
Complete equivalence classes
|
||||
|
||||
INITIAL ASM
|
||||
Target platform is c64basic / MOS6502X
|
||||
// File Comments
|
||||
// Test the preprocessor
|
||||
// Test for existence of the __KICKC__ define
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
// main
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
// [0] *((const nomodify byte*) main::SCREEN) ← (byte) 1 -- _deref_pbuc1=vbuc2
|
||||
lda #1
|
||||
sta SCREEN
|
||||
jmp __breturn
|
||||
// main::@return
|
||||
__breturn:
|
||||
// [1] return
|
||||
rts
|
||||
}
|
||||
// File Data
|
||||
|
||||
REGISTER UPLIFT POTENTIAL REGISTERS
|
||||
Statement [0] *((const nomodify byte*) main::SCREEN) ← (byte) 1 [ ] ( [ ] { } ) always clobbers reg byte a
|
||||
|
||||
REGISTER UPLIFT SCOPES
|
||||
Uplift Scope [main]
|
||||
Uplift Scope []
|
||||
|
||||
Uplifting [main] best 15 combination
|
||||
Uplifting [] best 15 combination
|
||||
|
||||
ASSEMBLER BEFORE OPTIMIZATION
|
||||
// File Comments
|
||||
// Test the preprocessor
|
||||
// Test for existence of the __KICKC__ define
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
// main
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
// [0] *((const nomodify byte*) main::SCREEN) ← (byte) 1 -- _deref_pbuc1=vbuc2
|
||||
lda #1
|
||||
sta SCREEN
|
||||
jmp __breturn
|
||||
// main::@return
|
||||
__breturn:
|
||||
// [1] return
|
||||
rts
|
||||
}
|
||||
// File Data
|
||||
|
||||
ASSEMBLER OPTIMIZATIONS
|
||||
Removing instruction jmp __breturn
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Removing instruction __breturn:
|
||||
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||
|
||||
FINAL SYMBOL TABLE
|
||||
(void()) main()
|
||||
(label) main::@return
|
||||
(const nomodify byte*) main::SCREEN = (byte*) 1024
|
||||
|
||||
|
||||
|
||||
FINAL ASSEMBLER
|
||||
Score: 12
|
||||
|
||||
// File Comments
|
||||
// Test the preprocessor
|
||||
// Test for existence of the __KICKC__ define
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
// main
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
// *SCREEN = 1
|
||||
// [0] *((const nomodify byte*) main::SCREEN) ← (byte) 1 -- _deref_pbuc1=vbuc2
|
||||
lda #1
|
||||
sta SCREEN
|
||||
// main::@return
|
||||
// }
|
||||
// [1] return
|
||||
rts
|
||||
}
|
||||
// File Data
|
||||
|
4
src/test/ref/preprocessor-14.sym
Normal file
4
src/test/ref/preprocessor-14.sym
Normal file
@ -0,0 +1,4 @@
|
||||
(void()) main()
|
||||
(label) main::@return
|
||||
(const nomodify byte*) main::SCREEN = (byte*) 1024
|
||||
|
Loading…
x
Reference in New Issue
Block a user