Created by: HugoPhi
This pull request introduces updates to the compiler's codebase to improve functionality, enhance parameter handling, and refine backend code generation. Key changes include adjustments to command-line argument parsing, improved handling of immediate values, better alignment for stack parameters, and fixes to function call generation.
Command-line argument parsing improvements:
-
main.cpp: Expanded accepted command-line arguments to include flags for displaying tokens, AST, IR, and executing IR. Added logic to parse and handle these flags. [1] [2] [3] [4]
Immediate value handling fixes:
-
src/backend/generator.cpp: Corrected the range checks for immediate values to include-2048to2047instead of-2048to2048. This ensures compatibility with RISC-V instruction encoding. [1] [2] [3] [4]
Stack parameter alignment improvements:
-
src/backend/generator.cpp: Enhanced stack parameter layout calculations to ensure proper alignment based on parameter types (integer, pointer, float). Introduced logic to dynamically calculate offsets for stack parameters and align them to appropriate boundaries.
Function call generation fixes:
-
src/backend/generator.cpp: Improved function call handling by aligning stack space to a 16-byte boundary for ABI compliance and fixing the placement of arguments in registers and on the stack. Added logic to calculate stack offsets for parameters exceeding register limits. [1] [2]
Miscellaneous updates:
-
Makefile: Changed the C compiler toriscv64-linux-gnu-gccand removed unnecessary architecture-specific flags. -
src/backend/generator.cpp: Updated function prologue alignment from 2 to 4 for improved safety.