@@ -202,19 +202,30 @@ def d_data(self):
202
202
def d_bss (self ):
203
203
self .section = BSS
204
204
205
+ def fill (self , section , amount , fill_byte ):
206
+ if fill_byte is not None and section is BSS :
207
+ raise ValueError ('fill in bss section not allowed' )
208
+ if section is TEXT : # TODO: text section should be filled with NOPs
209
+ raise ValueError ('fill/skip/align in text section not supported' )
210
+ fill = int (fill_byte or 0 ).to_bytes (1 , 'little' ) * amount
211
+ self .offsets [section ] += len (fill )
212
+ if section is not BSS :
213
+ self .sections [section ].append (fill )
214
+
205
215
def d_skip (self , amount , fill = None ):
206
- s = self .section
207
216
amount = int (amount )
208
- if fill is not None and s is BSS :
209
- raise ValueError ('fill not allowed in section %s' % s )
210
- if s is BSS :
211
- self .append_section (amount )
212
- else :
213
- fill = int (fill or 0 ).to_bytes (1 , 'little' ) * amount
214
- self .append_section (fill )
217
+ self .fill (self .section , amount , fill )
215
218
216
219
d_space = d_skip
217
220
221
+ def d_align (self , align = 4 , fill = None ):
222
+ align = int (align )
223
+ offs = self .offsets [self .section ]
224
+ mod = offs % align
225
+ if mod :
226
+ amount = align - mod
227
+ self .fill (self .section , amount , fill )
228
+
218
229
def d_set (self , symbol , expr ):
219
230
value = int (expr ) # TODO: support more than just integers
220
231
self .symbols .set_sym (symbol , ABS , None , value )
0 commit comments