Use constant instead of magic number
260e2e2f61398081ae97df2134399c293e6932cbaa8e8bf29f32f41a80ec4ed2
1 parent
30d36e9f
lib/std/arch/rv64.rad
+3 -1
| 78 | 78 | // Architecture constants // |
|
| 79 | 79 | //////////////////////////// |
|
| 80 | 80 | ||
| 81 | 81 | /// Total number of general-purpose registers. |
|
| 82 | 82 | pub const NUM_REGISTERS: u8 = 32; |
|
| 83 | + | /// Number of saved registers. |
|
| 84 | + | pub const NUM_SAVED_REGISTERS: u8 = 11; |
|
| 83 | 85 | /// Word size in bytes (32-bit). |
|
| 84 | 86 | pub const WORD_SIZE: i32 = 4; |
|
| 85 | 87 | /// Doubleword size in bytes (64-bit). |
|
| 86 | 88 | pub const DWORD_SIZE: i32 = 8; |
|
| 87 | 89 | /// Instruction size in bytes. |
| 106 | 108 | /// values and never used for operand materialization, so it can never |
|
| 107 | 109 | /// conflict with `rd`, `rs`, or `base` in load/store helpers. |
|
| 108 | 110 | pub const ADDR_SCRATCH: Reg = { n: 29 }; |
|
| 109 | 111 | ||
| 110 | 112 | /// Callee-saved registers that need save/restore if used. |
|
| 111 | - | pub const CALLEE_SAVED: [Reg; 11] = [S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11]; |
|
| 113 | + | pub const CALLEE_SAVED: [Reg; NUM_SAVED_REGISTERS] = [S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11]; |
|
| 112 | 114 | ||
| 113 | 115 | /// Maximum 12-bit signed immediate value. |
|
| 114 | 116 | pub const MAX_IMM: i32 = 2047; |
|
| 115 | 117 | ||
| 116 | 118 | /// Minimum 12-bit signed immediate value. |
lib/std/arch/rv64/emit.rad
+1 -1
| 115 | 115 | pub record Frame { |
|
| 116 | 116 | /// Total frame size in bytes (aligned). |
|
| 117 | 117 | totalSize: i32, |
|
| 118 | 118 | /// Callee-saved registers and their offsets. |
|
| 119 | 119 | // TODO: Use constant length when language supports it. |
|
| 120 | - | savedRegs: [SavedReg; 11], |
|
| 120 | + | savedRegs: [SavedReg; super::NUM_SAVED_REGISTERS], |
|
| 121 | 121 | /// Number of saved registers. |
|
| 122 | 122 | savedRegsLen: u32, |
|
| 123 | 123 | /// Epilogue block index for return jumps. |
|
| 124 | 124 | epilogueBlock: u32, |
|
| 125 | 125 | /// Whether this is a leaf function. Leaf functions |