@@ -819,6 +819,9 @@ impl Assembler
819
819
// List of GC offsets
820
820
let mut gc_offsets: Vec < u32 > = Vec :: new ( ) ;
821
821
822
+ // Buffered list of PosMarker callbacks to fire if codegen is successful
823
+ let mut pos_markers: Vec < ( usize , CodePtr ) > = vec ! [ ] ;
824
+
822
825
// For each instruction
823
826
let start_write_pos = cb. get_write_pos ( ) ;
824
827
let mut insn_idx: usize = 0 ;
@@ -838,8 +841,8 @@ impl Assembler
838
841
cb. write_label ( target. unwrap_label_idx ( ) ) ;
839
842
} ,
840
843
// Report back the current position in the generated code
841
- Insn :: PosMarker ( pos_marker ) => {
842
- pos_marker ( cb. get_write_ptr ( ) ) ;
844
+ Insn :: PosMarker ( .. ) => {
845
+ pos_markers . push ( ( insn_idx , cb. get_write_ptr ( ) ) )
843
846
}
844
847
Insn :: BakeString ( text) => {
845
848
for byte in text. as_bytes ( ) {
@@ -1205,7 +1208,21 @@ impl Assembler
1205
1208
}
1206
1209
}
1207
1210
1208
- Ok ( gc_offsets)
1211
+ // Error out if we couldn't write out everything
1212
+ if cb. has_dropped_bytes ( ) {
1213
+ Err ( EmitError :: OutOfMemory )
1214
+ } else {
1215
+ // No bytes dropped, so the pos markers point to valid code
1216
+ for ( insn_idx, pos) in pos_markers {
1217
+ if let Insn :: PosMarker ( callback) = self . insns . get ( insn_idx) . unwrap ( ) {
1218
+ callback ( pos) ;
1219
+ } else {
1220
+ panic ! ( "non-PosMarker in pos_markers insn_idx={insn_idx} {self:?}" ) ;
1221
+ }
1222
+ }
1223
+
1224
+ Ok ( gc_offsets)
1225
+ }
1209
1226
}
1210
1227
1211
1228
/// Optimize and compile the stored instructions
0 commit comments