Commit cc6eab4 1 parent 5b82363 commit cc6eab4 Copy full SHA for cc6eab4
File tree 3 files changed +25
-15
lines changed
3 files changed +25
-15
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ impl BootRom {
55
55
56
56
// Calculate the position of the start of the interrupt vector.
57
57
let mut next_handler_pos =
58
- BOOT_MEMORY_START + BootRom :: total_size_of_instructions ( & boot_instructions) ;
58
+ BOOT_MEMORY_START + Instruction :: total_size_of_instructions ( & boot_instructions) ;
59
59
60
60
// NOTE - in the instances where we are building a custom interrupt handler
61
61
// we would need to use the intret instruction to mark the end of the handler subroutine.
@@ -107,7 +107,7 @@ impl BootRom {
107
107
final_instructions. extend_from_slice ( & instructions) ;
108
108
109
109
// Advance the next handler location.
110
- next_handler_pos += BootRom :: total_size_of_instructions ( & instructions) ;
110
+ next_handler_pos += Instruction :: total_size_of_instructions ( & instructions) ;
111
111
}
112
112
113
113
// Add the return instruction from our IVT initialization subroutine and add
@@ -130,13 +130,4 @@ impl BootRom {
130
130
// Return the compiled bytecode.
131
131
Compiler :: new ( ) . compile ( & final_instructions) . to_vec ( )
132
132
}
133
-
134
- /// Compute the total size of an [`Instruction`] slice.
135
- fn total_size_of_instructions ( instructions : & [ Instruction ] ) -> usize {
136
- let mut size = 0 ;
137
- for ins in instructions {
138
- size += ins. get_total_instruction_size ( ) ;
139
- }
140
- size
141
- }
142
133
}
Original file line number Diff line number Diff line change @@ -79,11 +79,13 @@ impl Compiler {
79
79
// TODO - this is because the instructions may have changed, altering the relative positions of the labels.
80
80
}
81
81
82
- // We now need to preemptively compile the core data. This is because we need to know the length
83
- // of the code segment.
84
- self . compile ( & instructions) ;
85
- let code_segment_len = self . bytes . len ( ) ;
82
+ // We now need to calculate the length of the instructions.
83
+ let code_segment_len = Instruction :: total_size_of_instructions ( & instructions) ;
84
+
85
+ // TODO - this is a placeholder for the moment.
86
+ self . calculate_data_label_positions ( code_segment_len) ;
86
87
88
+ // TODO - do we care enough to do this?
87
89
if optimize {
88
90
// TODO - a second optimization pass should go here to optimize any labels
89
91
// TODO - related to the data section.
@@ -101,6 +103,14 @@ impl Compiler {
101
103
& self . bytes
102
104
}
103
105
106
+ /// Calculate the positions of the local data labels within the provided instruction list.
107
+ ///
108
+ /// # Arguments
109
+ ///
110
+ /// * `instructions` - A slice of [`Instruction`]s that correspond to the instructions to be compiled.
111
+ #[ inline]
112
+ fn calculate_data_label_positions ( & mut self , data_segment_len : usize ) { }
113
+
104
114
/// Calculate the positions of the local labels within the provided instruction list.
105
115
///
106
116
/// # Arguments
Original file line number Diff line number Diff line change @@ -622,4 +622,13 @@ impl Instruction {
622
622
} ;
623
623
instruction_size + self . get_instruction_arg_size ( )
624
624
}
625
+
626
+ /// Compute the total size of an [`Instruction`] slice.
627
+ pub fn total_size_of_instructions ( instructions : & [ Instruction ] ) -> usize {
628
+ let mut size = 0 ;
629
+ for ins in instructions {
630
+ size += ins. get_total_instruction_size ( ) ;
631
+ }
632
+ size
633
+ }
625
634
}
You can’t perform that action at this time.
0 commit comments