1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-06-11 17:29:39 +00:00
Commit Graph

273 Commits

Author SHA1 Message Date
Flight_Control
1a53d6a913 - Refer .asm library imported global variables to the the namespace where the global variable resides.
- Generalized the AsmLibrary procedures to symbols, to also allow exporting variables.
- Removed the initialization part of .asm library header generation for global exported variables.
- The directive __asm_export can now also be used to indicate global variables exporting within C libraries (for potential .asm library generation).
- Converted the usage of typedef to struct for __conio global variable in cx16_conio.c
- Updated example code.
- Fixed a bug where for exported structs and imported structs, the variables were defined as volatile to non-volatile.
- VariableBuilder constructor now also received the program variable to refer to program level configurations defined.
- Remove to declare string constants as .asm library exported global variables.
- Removed the optimization PassNAsmLibraryGlobalVarsExport. It is not needed. Each global variable export must be explicitly declared using asm_export or __asm_export.
- Improved naming of variables and procedures to retrieve and manage import and export libraries within the program.
2024-04-26 12:44:28 +03:00
Flight_Control
00df07b7bf - Fixed test cases. Full retest of all test cases.
- Treat global variables of libraries, as part of the .asm library .namespace.
- Fix bugs.
- Assign meaningful struct names to .asm internal variables and labels. (Remove the $x notation).
2024-04-20 07:03:31 +03:00
Sven Van de Velde
e371d304f6 - Fixed test cases. Full retest of all test cases.
- Create the possibility of forward declaration of structs as part of the language.
- Generation of forward declarations in the .asm header files.
- Treat global variables as part of global memory, even in libraries. Ensure that globals are not overwritten when importing.
- Ensure that the various compilation models (stack, var, phi) in combination with the memory models (zp, mem) result in proper execution of code and proper memory allocation etc, etc.
- Added the lru-cache logic to properly test the compilation and memory model combinations. (A lot of bugfixes as a result!)
2024-01-16 08:06:14 +03:00
Sven Van de Velde
fab740f797 - Fix earlier manual merge mistakes.
- Fixed a couple of issues with AsmIdentifier.
- Global variables exported are volatile.
- Created proper generation of the protypes for exported global variables in _asm.h.
- Created new test cases.
- Struggled with the proper export of global struct variables, first version of it implemented but this will require rework ...
- There are issues with "types" of structures, will need more work in the future and a strategy for it...
- Made AsmLibrary functions as AsmExportLibrary to make the code more clear.
- Created isAsmExportLibraryGlobal and isAsmImportLibrary global functions.
2024-01-02 19:41:03 +01:00
Sven Van de Velde
d477cb9eae - New AsmImportLibrary class, for generating the #import statements.
- New AsmIdentifier class that replaces unallowed kickasm characters to an _.
- New AsmIgnoredImportInlinedKickAsm class, for creating the construct to ignore the body lines when the library is imported (used), and removed the #else clause (was confusing).
- Export of global variable in .asm Libraries (first version).
- Removal of constructor_for in .asm libraries.
- Reworked the way in assembler generation how link files are treated.
- Reworked all `replace("-","_")` areas using AsmIdentifier properly.
2024-01-01 16:57:48 +01:00
Sven Van de Velde
88dfeec3de - Now nesting of libraries works. Had to take care of the zero-page usage of nested procedures. The _asm.h file, containing the exported procedures contains the full zero-page usage, including the used (nested) procedures in the call graph of each exported procedure.
- Proper import mechanisms and naming.
- Ensure that .asm library files are imported only once!
- Added a new asm directory in kc folder, that contains library stub C files for .asm library generation.
- Fixed library startup initialization. .asm libraries are now also calling correctly the library init routines etc.
- Added new test cases.
2023-12-30 20:33:13 +01:00
Sven Van de Velde
8cf479d458 - Fixed an issue where for main programs (so non-library programs), also the link script conditional include would be defined in pass4 for in the assembler generation. 2023-12-17 11:42:27 +01:00
Sven Van de Velde
46321d47f4 - Bugfix of link file. Must be properly included and defined in all cases. With or without .asm library. 2023-12-16 13:45:38 +01:00
Sven Van de Velde
acb385094b - Documentation for .asm libraries.
- Preparing source file identification routines for later usage during linking.
- Refining the code generation routines in pass4.
2023-12-14 22:27:25 +01:00
Sven Van de Velde
5436877fa0 Many Fixes and Additions:
- #820/29 - ensure that during pass4, namespaces are correctly labelled for variables.
- #820/30 - added option to only having to specify #pragma asm_library and the source file name will be used as the library name.
- #820/31 - remove the need for link files for libraries.
- #820/1 - Lots of optimizations
- Added lru-cache as a library in the library tests. It works!
- Added many tests
- Added conio example
- Added eightqueens example.
2023-12-12 08:21:28 +01:00
Sven Van de Velde
fcd38d0a19 - Now compiling the eight queens example with conio asm library.
- Added proper return value handling for __varcall functions.
- Added many fixes concerning start functions.
- Optimized asm library examples.
- Added a return value asm library example.
2023-11-29 14:27:59 +01:00
Sven Van de Velde
77eb2f7bcb - only call namespaced procedures when the library is import. For export, just call the procedure without the library prefix. (KickAsm does not support it). 2023-11-27 15:35:30 +01:00
Sven Van de Velde
f98424ed97 - First well improved version for exporting and importing .asm library functions.
- Full documentation in the new manual directory containing the kickc.md markup manual file.
- library folder containing a concrete example.
2023-11-24 16:05:02 +01:00
Sven Van de Velde
1209353803 - Successful export and import of conio.
- TODO: Create header file for import.
- TODO: Resolve coalesce of exported procedure parameters.
- TODO: Remove constant optimizations for exported procedure parameters.
2023-11-18 10:40:50 +01:00
Sven Van de Velde
eb6324356a - Added #pragma asm_import(...)
- Renamed #pragma asm_library(...)
- Automated *.asm inclusion when generating assembler.
- Supports kickc source code libraries too.
  Procedures declared in the asm_import are considered to be
  part of an external library, so any definition of that procedure
  is ignored, and changed as an external __stackcall __library(...) declaration!
  Also considered inline procedures following this behaviour.
  This allows printf functions to call conio pre-compiled routines
  to be called in the assembler.
- Internals for Libraries working for conio.asm.
- Added a demo program demonstrating the asm_import.
- Lot's of minor fixes and additions, added a new AsmLibrary class
  and the handling of it in program.
- Added an AsmLibraries object
- Recompile the whole test cases and updated references for a good comparison. Changes should be cosmetic.
2023-11-05 19:06:41 +01:00
Sven Van de Velde
1f0bddc768 Libraries 2023-10-27 15:31:51 +02:00
Sven Van de Velde
1025aa5b00 - Implementation of a new #pragma library(name) in parser and statement sequence generation.
- Added at specific locations different compilation logic when a library is created.
- Added a .namespace library { } which encapsulates the whole library asm output.
- Added 2 new classes for .namespace creation in the Asm generation logic.
- Added as part of the program the asmLibrary, which contains the library name set through the #pragma.
2023-10-27 13:19:27 +02:00
jespergravgaard
2ee4e5c14a main merged 2023-05-21 19:16:51 +02:00
jespergravgaard
a20fd82d2d Merge branch 'master' into 815-procedure-compilation
# Conflicts:
#	src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java
#	src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java
#	src/test/ref/printf-17.log
#	src/test/ref/printf-18.log
#	src/test/ref/printf-19.log
2023-05-21 19:01:30 +02:00
jespergravgaard
d4040e30a0 Moved handling of banked param/return to pass 1. 2023-04-24 00:36:36 +02:00
jespergravgaard
11c86793d3 Ensured we do not coalesce across segments. 2023-04-23 23:25:28 +02:00
jespergravgaard
606ea29132 Moved calling distance to bank. 2023-04-23 22:20:13 +02:00
jespergravgaard
8b7afa4ad0 Procedure.bank is now never null. 2023-04-23 22:04:23 +02:00
jespergravgaard
8c7a144579 Refactored calling distance. 2023-04-23 21:07:16 +02:00
jespergravgaard
eb69af8fe7 Refactored calling convention. 2023-04-23 20:54:22 +02:00
jespergravgaard
9f3ca81e6a Refactored proximity. 2023-04-23 20:37:37 +02:00
jespergravgaard
291ce871c4 Working on far call merge. 2023-04-23 11:54:47 +02:00
Flight_Control
4aeed59d0e - Code improvements for CallingDistance and CallingProximity 2023-04-18 10:15:23 +02:00
Flight_Control
23903b34c6 - Removed TODO 2023-04-18 08:02:39 +02:00
Sven Van de Velde
02d9eaf081 - Added banking signature to procedures in the comments of the assembler output file.
- Update test cases and reference data.
- Cleaned old test cases for stack calls.
2023-04-12 06:57:25 +02:00
Sven Van de Velde
8bb0ae904f - processed some of the comments.
- documentation fixes.
2023-04-11 10:13:41 +02:00
Sven Van de Velde
f2bf3484ad - testing and regeneration of fragment references
- implementation of near, close, far through AsmFragmentSignature
- fragment consolidation (removal of prepare, execute, finalize)
- stackcall banked throws error + test cases
- overall test cases for phi
- implementation of fragments
2023-04-11 08:35:53 +02:00
Sven Van de Velde
a52b5dc4a9 Banking progress
(cherry picked from commit d0abf45529c34e14ed3ce43b9be3a140f78bc4a9)
2023-04-10 07:22:06 +02:00
jespergravgaard
5a74d14b41 #815 working on generalizing the control flow graph and control flow block into an interface. 2023-04-08 22:52:15 +02:00
Flight_Control
a6b021aaf0 Merge branch 'jesper_baseline' into far-call-isolated-#508
# Conflicts:
#	src/main/java/dk/camelot64/kickc/model/symbols/Procedure.java
#	src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java
2023-04-04 20:03:15 +02:00
Flight_Control
4706611564 - Mem[x] parameters in a banked function are always allocated in main memory.
- Mem[x] return value(s) in banked functions are always allocated in main memory.
- Mem[x] intermediate value(s) in banked functions are always placed in the designated data segment.

This to accommodate better banking logic for far function calls. (There might be more complexity for other type of variables, but for equinoxe it's working!).

(cherry picked from commit 649a187d7e9290b630a951d8968ce5ece6ba2216)
2023-03-27 21:42:52 +02:00
Flight_Control
2513e59266 - Inline code can never be banked.
(cherry picked from commit 249b7600a9262ea673e63d133db75690af43ca05)
2023-03-26 18:30:53 +02:00
Flight_Control
db49ca6aab Major changes:
- Renamed #pragma far() to #pragma bank() upon design recommendations of @jesper.
- renamed #pragma near to #pragma nobank, to avoid using bank(-1).
- renamed __far directive to __bank directive.
- introduced bank area upon design recommendation of jesper, and replaced this with the already present code segment linkage to banking. So the structured stayed the same, only the naming changed! This unlink from segment indeed makes things easier when no segments are in scope of the program.
- added bank area as part of the fragment signature, so now call_far_[platform]_[bankarea]_prepare.asm, call_far_[platform]_[bankarea]_execute.asm, call_far_[platform]_[bankarea]_finalize.asm are expected to be present in the compiler.
- removed the c code prepare, execute, finalize idea. The fragments seem to be enough for the moment.
- added ram and rom fragments for far calls for the cx16.
- Cleaned banking logic from Statement level.
2022-11-21 18:17:35 +01:00
Flight_Control
1a63d437a0 - Refactored far call logic during parsing. The pragmaFarSegs hash table has been removed from the Pass0GenerateStatementSequence. Instead, a currentFarSegment is controlling the #pragma logic.
- Refactored pragmaCodeSegs HashMap, which has been removed from Pass0GenerateStatementSequence and moved to Program. It controls which code segment have been defined, and a validation is implemented in the far_seg pragmas.
- Refactored __far() to use the code segments, in analogy to far_seg pragmas.
- Refactored Procedure, which implements functions to use the FarSegment to decide on far declaration and far bank retrieval.
- refactored CallingConvention. Removed earlier quick implementation of bankFar variable as a local property, and declaredFar in the Procedure class. Now everyting is controlled through the farSegment.
- Refactored Procedure, the removal of FAR_CALL calling convention. It is wrong to implement FAR_CALL calling convention, because far and near calls can be stack calls, phi calls and even a varcall can be near of far.
- Removed the Pass1ProcedureFar because far and near implementation is not defined in statement level, it is defined on procedure level. But I've kept Pass1ProcedureFar to suppor the logic for inline prepare, execute, finalize routines during further implementation.
- Refactored directive FAR to match the directive far_seg() structure.
- Refactored complete logic during Pass4CodeGeneration to process statement call fragment generation to decide on near or far calls within the logic, taking into account the calling convention used.
- Added new fragments call_far[platform]_prepare.asm, call_far[platform]_execute.asm, call_far[platform]_finalize.asm and deleted call_far[platform]_entry.asm, call_far[platform]_exit.asm
- Renamed pragmas far_seg and near_seg to simply far and near respectively. Updated test cases with this change.
- Added test cases.

TODO: The actual inline implementation of prepare, execute, finalize functions when platform .asm fragments are not used.
TODO: Implementation of the near directive.
2022-11-20 09:56:10 +01:00
Flight_Control
379a3c1999 Catching a RunTimeException only when there is no UnknownFragmentException ...
and throw either
- Compile Error
- UnknownFragmentException (passing through).
2022-11-16 22:30:37 +01:00
Flight_Control
8801a3e5e2 Fixing bugs:
- far calls are now ALL iterated and flagged with a bank!
- procedure objects are taken as the base for far call asm generation, not the call objects anymore (too tricky). But i have kept the call objects to be also updated with the bank for any reference later!
2022-11-16 22:19:22 +01:00
Sven Van de Velde
4a4d6f72d0 far calls for __stackcall calling convention functions. 2022-11-16 17:11:18 +01:00
Flight_Control
828e38a8b3 far calls 2022-11-16 06:54:44 +01:00
jespergravgaard
4964a44660 turned fragment synthesis into interface. 2021-12-28 14:41:00 +01:00
jespergravgaard
40919842e2 Removed the ALU subsystem. It was providing too little value for the complexity. 2021-12-27 01:16:04 +01:00
jespergravgaard
44ec5be5e8 Moved ASM code gen and ASM encoding handling into separate util classes. 2021-12-27 00:33:30 +01:00
jespergravgaard
0152ecd0eb improved code using ASM fragment instance spec builder. 2021-12-24 09:48:11 +01:00
jespergravgaard
f962948ef8 Upgraded ANTLR. Improved clobber handling in inline kickasm. 2021-10-19 10:10:47 +02:00
jespergravgaard
e826accb9c Fixed problem where constant bool return causes ASM compile error. Closes #719 2021-10-14 08:02:06 +02:00
jespergravgaard
1f133e34e9 Added very naive support for zeropage overflow to main memory upon exhaust. TODO - overflow low priority variables. #712 2021-08-17 07:48:58 +02:00