comparison lwasm/lwasm.c @ 374:d99322ef6f21

Stage 1: actually do output
author lost@starbug
date Sat, 24 Apr 2010 14:15:18 -0600
parents 9c24d9d485b9
children 3498b2d88376
comparison
equal deleted inserted replaced
373:8f9d72cfb897 374:d99322ef6f21
187 return r; 187 return r;
188 } 188 }
189 189
190 void lwasm_emit(line_t *cl, int byte) 190 void lwasm_emit(line_t *cl, int byte)
191 { 191 {
192 if (cl -> outputl < 0)
193 cl -> outputl = 0;
194
192 if (cl -> outputl == cl -> outputbl) 195 if (cl -> outputl == cl -> outputbl)
193 { 196 {
194 cl -> output = lw_realloc(cl -> output, cl -> outputbl + 8); 197 cl -> output = lw_realloc(cl -> output, cl -> outputbl + 8);
195 cl -> outputbl += 8; 198 cl -> outputbl += 8;
196 } 199 }
603 v = lw_expr_intval(expr); 606 v = lw_expr_intval(expr);
604 } 607 }
605 // handle external/cross-section/incomplete references here 608 // handle external/cross-section/incomplete references here
606 else 609 else
607 { 610 {
611 if (l -> as -> output_format == OUTPUT_OBJ)
612 {
613 reloctab_t *re;
614
615 // add "expression" record to section table
616 v = lw_expr_intval(l -> addr) + l -> outputl;
617 re = lw_alloc(sizeof(reloctab_t));
618 re -> next = l -> csect -> reloctab;
619 l -> csect -> reloctab = re;
620 re -> offset = v;
621 re -> size = size;
622 re -> expr = lw_expr_copy(expr);
623
624 for (v = 0; v < size; v++)
625 lwasm_emit(l, 0);
626 return 0;
627 }
608 lwasm_register_error(l -> as, l, "Expression not fully resolved"); 628 lwasm_register_error(l -> as, l, "Expression not fully resolved");
609 return -1; 629 return -1;
610 } 630 }
611 631
612 switch (size) 632 switch (size)