From: Peter Johnson Date: Tue, 20 Jun 2006 06:23:07 +0000 (-0000) Subject: In preparation for further work on optimizing multiple, break multiple apart X-Git-Tag: v0.6.0~172^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9445734d22710c5de63e9656be60fd312da78235;p=yasm In preparation for further work on optimizing multiple, break multiple apart from bytecode.len into bytecode.mult_int. Add new function yasm_bc_next_offset() to handle the most common use case of bytecode.len, figuring out the following bytecode's offset. svn path=/branches/new-optimizer/; revision=1586 --- diff --git a/libyasm/bc-int.h b/libyasm/bc-int.h index 198ca2d9..c93b28ee 100644 --- a/libyasm/bc-int.h +++ b/libyasm/bc-int.h @@ -58,6 +58,7 @@ struct yasm_bytecode { unsigned long len; /* total length of entire bytecode (not including multiple copies) */ + unsigned long mult_int; /* number of copies: integer version */ /* where it came from */ unsigned long line; @@ -66,9 +67,6 @@ struct yasm_bytecode { unsigned long offset; /* ~0UL if unknown */ unsigned long bc_index; - /* optimizer info */ - unsigned long opt_flags; - /* NULL-terminated array of labels that point to this bytecode (as the * bytecode previous to the label). NULL if no labels point here. */ /*@null@*/ yasm_symrec **symrecs; diff --git a/libyasm/bytecode.c b/libyasm/bytecode.c index 49eea7fd..52c039cd 100644 --- a/libyasm/bytecode.c +++ b/libyasm/bytecode.c @@ -86,9 +86,9 @@ yasm_bc_create_common(const yasm_bytecode_callback *callback, void *contents, bc->section = NULL; bc->multiple = (yasm_expr *)NULL; bc->len = 0; + bc->mult_int = 1; bc->line = line; bc->offset = ~0UL; /* obviously incorrect / uninitialized value */ - bc->opt_flags = 0; bc->symrecs = NULL; bc->contents = contents; @@ -174,20 +174,27 @@ yasm_bc_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc) /*@null@*/ yasm_intnum * yasm_calc_bc_dist(yasm_bytecode *precbc1, yasm_bytecode *precbc2) { - unsigned long dist; + unsigned long dist2, dist1; yasm_intnum *intn; if (precbc1->section != precbc2->section) return NULL; - dist = precbc2->offset + precbc2->len; - if (dist < precbc1->offset + precbc1->len) { - intn = yasm_intnum_create_uint(precbc1->offset + precbc1->len - dist); + dist1 = yasm_bc_next_offset(precbc1); + dist2 = yasm_bc_next_offset(precbc2); + if (dist2 < dist1) { + intn = yasm_intnum_create_uint(dist1 - dist2); yasm_intnum_calc(intn, YASM_EXPR_NEG, NULL); return intn; } - dist -= precbc1->offset + precbc1->len; - return yasm_intnum_create_uint(dist); + dist2 -= dist1; + return yasm_intnum_create_uint(dist2); +} + +unsigned long +yasm_bc_next_offset(yasm_bytecode *precbc) +{ + return precbc->offset + precbc->len*precbc->mult_int; } int @@ -204,13 +211,18 @@ yasm_bc_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, retval = bc->callback->calc_len(bc, add_span, add_span_data); /* Check for multiples */ + bc->mult_int = 1; if (bc->multiple) { /*@dependent@*/ /*@null@*/ const yasm_intnum *num; num = yasm_expr_get_intnum(&bc->multiple, 0); - if (num) - bc->len *= yasm_intnum_get_uint(num); - else { + if (num) { + if (yasm_intnum_sign(num) < 0) { + yasm_error_set(YASM_ERROR_VALUE, N_("multiple is negative")); + retval = -1; + } else + bc->mult_int = yasm_intnum_get_uint(num); + } else { if (yasm_expr__contains(bc->multiple, YASM_EXPR_FLOAT)) { yasm_error_set(YASM_ERROR_VALUE, N_("expression must not contain floating point value")); @@ -219,7 +231,7 @@ yasm_bc_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, yasm_value value; yasm_value_initialize(&value, bc->multiple, 0); add_span(add_span_data, bc, 0, &value, 0, 0); - bc->len = 0; + bc->mult_int = 0; /* assume 0 to start */ } } } @@ -235,12 +247,15 @@ int yasm_bc_expand(yasm_bytecode *bc, int span, long old_val, long new_val, /*@out@*/ long *neg_thres, /*@out@*/ long *pos_thres) { - if (span == 0) + if (span == 0) { yasm_internal_error(N_("cannot expand multiple yet")); + + return 1; + } if (!bc->callback) { yasm_internal_error(N_("got empty bytecode in yasm_bc_expand")); /*@unreached@*/ - return 0; + return -1; } else return bc->callback->expand(bc, span, old_val, new_val, neg_thres, pos_thres); @@ -255,39 +270,38 @@ yasm_bc_tobytes(yasm_bytecode *bc, unsigned char *buf, unsigned long *bufsize, { /*@only@*/ /*@null@*/ unsigned char *mybuf = NULL; unsigned char *origbuf, *destbuf; - unsigned long datasize, multiple, i; + unsigned long i; int error = 0; - if (yasm_bc_get_multiple(bc, &multiple, 1) || multiple == 0) { + if (yasm_bc_get_multiple(bc, &bc->mult_int, 1) || bc->mult_int == 0) { *bufsize = 0; return NULL; } /* special case for reserve bytecodes */ if (bc->callback->special == YASM_BC_SPECIAL_RESERVE) { - *bufsize = bc->len; + *bufsize = bc->len*bc->mult_int; *gap = 1; return NULL; /* we didn't allocate a buffer */ } *gap = 0; - if (*bufsize < bc->len) { - mybuf = yasm_xmalloc(bc->len); + if (*bufsize < bc->len*bc->mult_int) { + mybuf = yasm_xmalloc(bc->len*bc->mult_int); destbuf = mybuf; } else destbuf = buf; - *bufsize = bc->len; - datasize = bc->len / multiple; + *bufsize = bc->len*bc->mult_int; if (!bc->callback) yasm_internal_error(N_("got empty bytecode in bc_tobytes")); - else for (i=0; imult_int; i++) { origbuf = destbuf; error = bc->callback->tobytes(bc, &destbuf, d, output_value, output_reloc); - if (!error && ((unsigned long)(destbuf - origbuf) != datasize)) + if (!error && ((unsigned long)(destbuf - origbuf) != bc->len)) yasm_internal_error( N_("written length does not match optimized length")); } diff --git a/libyasm/bytecode.h b/libyasm/bytecode.h index 299bd4d6..2b12a8fd 100644 --- a/libyasm/bytecode.h +++ b/libyasm/bytecode.h @@ -302,12 +302,21 @@ void yasm_bc_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); /** Determine the distance between the starting offsets of two bytecodes. * \param precbc1 preceding bytecode to the first bytecode * \param precbc2 preceding bytecode to the second bytecode + * \caution Only valid /after/ optimization. * \return Distance in bytes between the two bytecodes (bc2-bc1), or NULL if * the distance was indeterminate. */ /*@null@*/ /*@only@*/ yasm_intnum *yasm_calc_bc_dist (yasm_bytecode *precbc1, yasm_bytecode *precbc2); +/** Get the offset of the next bytecode (the next bytecode doesn't have to + * actually exist). + * \caution Only valid /after/ optimization. + * \param precbc preceding bytecode + * \return Offset of the next bytecode in bytes. + */ +unsigned long yasm_bc_next_offset(yasm_bytecode *precbc); + /** Add a dependent span for a bytecode. * \param add_span_data add_span_data passed into bc_calc_len() * \param bc bytecode containing span diff --git a/libyasm/section.c b/libyasm/section.c index 3fd1e13a..40fbad38 100644 --- a/libyasm/section.c +++ b/libyasm/section.c @@ -866,8 +866,8 @@ span_create_terms(yasm_span *span) span->rel_term->subst = ~0U; span->rel_term->cur_val = 0; - span->rel_term->new_val = - rel_precbc->offset + rel_precbc->len - span->bc->offset; + span->rel_term->new_val = yasm_bc_next_offset(rel_precbc) - + span->bc->offset; } } @@ -940,16 +940,16 @@ update_all_bc_offsets(yasm_object *object, yasm_errwarns *errwarns) if (bc->callback->special == YASM_BC_SPECIAL_OFFSET) { /* Recalculate/adjust len of offset-based bytecodes here */ long neg_thres = 0; - long pos_thres = bc->offset+bc->len; + long pos_thres = (long)yasm_bc_next_offset(bc); int retval = yasm_bc_expand(bc, 1, 0, - (long)(prevbc->offset+prevbc->len), + (long)yasm_bc_next_offset(prevbc), &neg_thres, &pos_thres); yasm_errwarn_propagate(errwarns, bc->line); if (retval < 0) saw_error = 1; } bc->offset = offset; - offset += bc->len; + offset += bc->len*bc->mult_int; prevbc = bc; bc = STAILQ_NEXT(bc, link); } @@ -1079,7 +1079,7 @@ yasm_object_optimize(yasm_object *object, yasm_arch *arch, else { if (bc->callback->special == YASM_BC_SPECIAL_OFFSET) { span = create_span(bc, 1, NULL, SPECIAL_BC_OFFSET, 0, - (long)(bc->offset+bc->len)); + (long)yasm_bc_next_offset(bc)); TAILQ_INSERT_TAIL(&optd.spans, span, link); if (bc->multiple) { yasm_error_set(YASM_ERROR_VALUE, @@ -1089,7 +1089,7 @@ yasm_object_optimize(yasm_object *object, yasm_arch *arch, } } - offset += bc->len; + offset += bc->len*bc->mult_int; } prevbc = bc; @@ -1174,12 +1174,12 @@ yasm_object_optimize(yasm_object *object, yasm_arch *arch, if (span->rel_term) { span->rel_term->cur_val = span->rel_term->new_val; if (span->rel_term->precbc2) - span->rel_term->new_val = span->rel_term->precbc2->offset - + span->rel_term->precbc2->len - span->bc->offset; + span->rel_term->new_val = + yasm_bc_next_offset(span->rel_term->precbc2) - + span->bc->offset; else span->rel_term->new_val = span->bc->offset - - (span->rel_term->precbc->offset + - span->rel_term->precbc->len); + yasm_bc_next_offset(span->rel_term->precbc); } switch (span->special) { @@ -1195,7 +1195,7 @@ yasm_object_optimize(yasm_object *object, yasm_arch *arch, * span values and thresholds. */ span->new_val = span->rel_term->new_val; - span->pos_thres = (long)(span->bc->offset+span->bc->len); + span->pos_thres = (long)yasm_bc_next_offset(span->bc); span->rel_term->cur_val = span->rel_term->new_val; span->cur_val = span->new_val; @@ -1252,7 +1252,7 @@ yasm_object_optimize(yasm_object *object, yasm_arch *arch, if (!recalc_normal_span(span)) continue; - orig_len = span->bc->len; + orig_len = span->bc->len * span->bc->mult_int; retval = yasm_bc_expand(span->bc, span->id, span->cur_val, span->new_val, &span->neg_thres, @@ -1273,7 +1273,7 @@ yasm_object_optimize(yasm_object *object, yasm_arch *arch, } else span->active = 0; /* we're done with this span */ - optd.len_diff = span->bc->len - orig_len; + optd.len_diff = span->bc->len * span->bc->mult_int - orig_len; if (optd.len_diff == 0) continue; /* didn't increase in size */ diff --git a/libyasm/value.c b/libyasm/value.c index 94726d13..50b5482c 100644 --- a/libyasm/value.c +++ b/libyasm/value.c @@ -512,7 +512,7 @@ yasm_value_get_intnum(yasm_value *value, yasm_bytecode *bc, int calc_bc_dist) return NULL; /* not PC-relative */ /* Calculate value relative to current assembly position */ - dist = rel_prevbc->offset + rel_prevbc->len; + dist = yasm_bc_next_offset(rel_prevbc); if (dist < bc->offset) { outval = yasm_intnum_create_uint(bc->offset - dist); yasm_intnum_calc(outval, YASM_EXPR_NEG, NULL); @@ -594,7 +594,7 @@ yasm_value_output_basic(yasm_value *value, /*@out@*/ unsigned char *buf, return 0; /* not PC-relative */ /* Calculate value relative to current assembly position */ - dist = rel_prevbc->offset + rel_prevbc->len; + dist = yasm_bc_next_offset(rel_prevbc); if (dist < bc->offset) { outval = yasm_intnum_create_uint(bc->offset - dist); yasm_intnum_calc(outval, YASM_EXPR_NEG, NULL); diff --git a/modules/dbgfmts/codeview/cv-dbgfmt.c b/modules/dbgfmts/codeview/cv-dbgfmt.c index c42db191..d17f6089 100644 --- a/modules/dbgfmts/codeview/cv-dbgfmt.c +++ b/modules/dbgfmts/codeview/cv-dbgfmt.c @@ -92,7 +92,7 @@ yasm_bytecode * yasm_cv__append_bc(yasm_section *sect, yasm_bytecode *bc) { yasm_bytecode *precbc = yasm_section_bcs_last(sect); - bc->offset = precbc ? precbc->offset + precbc->len : 0; + bc->offset = yasm_bc_next_offset(precbc); yasm_section_bcs_append(sect, bc); return precbc; } diff --git a/modules/dbgfmts/dwarf2/dwarf2-aranges.c b/modules/dbgfmts/dwarf2/dwarf2-aranges.c index 7ce85553..dd82e491 100644 --- a/modules/dbgfmts/dwarf2/dwarf2-aranges.c +++ b/modules/dbgfmts/dwarf2/dwarf2-aranges.c @@ -28,7 +28,6 @@ /*@unused@*/ RCSID("$Id$"); #define YASM_LIB_INTERNAL -#define YASM_BC_INTERNAL #include #include "dwarf2-dbgfmt.h" diff --git a/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c b/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c index c5f807fd..d6ed56ea 100644 --- a/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c +++ b/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c @@ -148,7 +148,7 @@ yasm_bytecode * yasm_dwarf2__append_bc(yasm_section *sect, yasm_bytecode *bc) { yasm_bytecode *precbc = yasm_section_bcs_last(sect); - bc->offset = precbc ? precbc->offset + precbc->len : 0; + bc->offset = yasm_bc_next_offset(precbc); yasm_section_bcs_append(sect, bc); return precbc; } diff --git a/modules/dbgfmts/dwarf2/dwarf2-line.c b/modules/dbgfmts/dwarf2/dwarf2-line.c index 85e860e5..44d117a8 100644 --- a/modules/dbgfmts/dwarf2/dwarf2-line.c +++ b/modules/dbgfmts/dwarf2/dwarf2-line.c @@ -596,7 +596,7 @@ dwarf2_generate_line_section(yasm_section *sect, /*@null@*/ void *d) if (!state.precbc) state.precbc = yasm_section_bcs_first(sect); bc = yasm_section_bcs_last(sect); - addr_delta = bc->offset + bc->len - state.precbc->offset; + addr_delta = yasm_bc_next_offset(bc) - state.precbc->offset; if (addr_delta == DWARF2_MAX_SPECIAL_ADDR_DELTA) dwarf2_dbgfmt_append_line_op(info->debug_line, DW_LNS_const_add_pc, NULL); diff --git a/modules/dbgfmts/stabs/stabs-dbgfmt.c b/modules/dbgfmts/stabs/stabs-dbgfmt.c index 66c2dde5..2274a0d7 100644 --- a/modules/dbgfmts/stabs/stabs-dbgfmt.c +++ b/modules/dbgfmts/stabs/stabs-dbgfmt.c @@ -188,12 +188,11 @@ stabs_dbgfmt_destroy(/*@only@*/ yasm_dbgfmt *dbgfmt) static yasm_bytecode * stabs_dbgfmt_append_bcstr(yasm_section *sect, const char *str) { - yasm_bytecode *bc, *precbc; + yasm_bytecode *bc; - precbc = yasm_section_bcs_last(sect); bc = yasm_bc_create_common(&stabs_bc_str_callback, yasm__xstrdup(str), 0); bc->len = strlen(str)+1; - bc->offset = precbc ? precbc->offset + precbc->len : 0; + bc->offset = yasm_bc_next_offset(yasm_section_bcs_last(sect)); yasm_section_bcs_append(sect, bc); @@ -209,7 +208,7 @@ stabs_dbgfmt_append_stab(stabs_info *info, yasm_section *sect, unsigned long desc, /*@null@*/ yasm_symrec *symvalue, /*@null@*/ yasm_bytecode *bcvalue, unsigned long value) { - yasm_bytecode *bc, *precbc; + yasm_bytecode *bc; stabs_stab *stab = yasm_xmalloc(sizeof(stabs_stab)); stab->other = 0; @@ -220,11 +219,10 @@ stabs_dbgfmt_append_stab(stabs_info *info, yasm_section *sect, stab->bcvalue = bcvalue; stab->value = value; - precbc = yasm_section_bcs_last(sect); bc = yasm_bc_create_common(&stabs_bc_stab_callback, stab, bcvalue ? bcvalue->line : 0); bc->len = info->stablen; - bc->offset = precbc ? precbc->offset + precbc->len : 0; + bc->offset = yasm_bc_next_offset(yasm_section_bcs_last(sect)); yasm_section_bcs_append(sect, bc); @@ -405,7 +403,7 @@ stabs_dbgfmt_generate(yasm_dbgfmt *dbgfmt, yasm_errwarns *errwarns) stab->bcvalue = NULL; stab->symvalue = NULL; - stab->value = laststr->offset + laststr->len; + stab->value = yasm_bc_next_offset(laststr); stab->bcstr = filebc; stab->type = N_UNDF; stab->other = 0; diff --git a/modules/objfmts/bin/bin-objfmt.c b/modules/objfmts/bin/bin-objfmt.c index 6e8954fd..9d9114ee 100644 --- a/modules/objfmts/bin/bin-objfmt.c +++ b/modules/objfmts/bin/bin-objfmt.c @@ -67,18 +67,13 @@ bin_objfmt_align_section(yasm_section *sect, yasm_section *prevsect, /*@out@*/ unsigned long *prevsectlen, /*@out@*/ unsigned long *padamt) { - /*@dependent@*/ /*@null@*/ yasm_bytecode *last; unsigned long start; unsigned long align; /* Figure out the size of .text by looking at the last bytecode's offset * plus its length. Add the start and size together to get the new start. */ - last = yasm_section_bcs_last(prevsect); - if (last) - *prevsectlen = last->offset + last->len; - else - *prevsectlen = 0; + *prevsectlen = yasm_bc_next_offset(yasm_section_bcs_last(prevsect)); start = base + *prevsectlen; /* Round new start up to alignment of .data section, and adjust textlen to diff --git a/modules/objfmts/coff/coff-objfmt.c b/modules/objfmts/coff/coff-objfmt.c index 1a328ab0..ad67543a 100644 --- a/modules/objfmts/coff/coff-objfmt.c +++ b/modules/objfmts/coff/coff-objfmt.c @@ -406,7 +406,6 @@ coff_objfmt_set_section_addr(yasm_section *sect, /*@null@*/ void *d) { /*@null@*/ coff_objfmt_output_info *info = (coff_objfmt_output_info *)d; /*@dependent@*/ /*@null@*/ coff_section_data *csd; - /*@null@*/ yasm_bytecode *last; /* Don't output absolute sections */ if (yasm_section_is_absolute(sect)) @@ -417,9 +416,7 @@ coff_objfmt_set_section_addr(yasm_section *sect, /*@null@*/ void *d) assert(csd != NULL); csd->addr = info->addr; - last = yasm_section_bcs_last(sect); - if (last) - info->addr += last->offset + last->len; + info->addr += yasm_bc_next_offset(yasm_section_bcs_last(sect)); return 0; } @@ -530,7 +527,7 @@ coff_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, &coff_section_data_cb); assert(sym_csd != NULL); sym = sym_csd->sym; - intn_val = sym_precbc->offset + sym_precbc->len; + intn_val = yasm_bc_next_offset(sym_precbc); if (COFF_SET_VMA) intn_val += sym_csd->addr; } @@ -545,7 +542,7 @@ coff_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, * taken care of by special relocation types. */ if (objfmt_coff->win64 && value->ip_rel) - intn_val += bc->len; + intn_val += bc->len*bc->mult_int; else if (objfmt_coff->win32) intn_val += offset+destsize; else @@ -583,7 +580,7 @@ coff_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, } if (!value->ip_rel) reloc->type = COFF_RELOC_AMD64_REL32; - else switch (bc->len - (offset+destsize)) { + else switch (bc->len*bc->mult_int - (offset+destsize)) { case 0: reloc->type = COFF_RELOC_AMD64_REL32; break; @@ -761,16 +758,12 @@ coff_objfmt_output_section(yasm_section *sect, /*@null@*/ void *d) csd->addr = info->addr; if ((csd->flags & COFF_STYP_STD_MASK) == COFF_STYP_BSS) { - yasm_bytecode *last = yasm_section_bcs_last(sect); - /* Don't output BSS sections. * TODO: Check for non-reserve bytecodes? */ pos = 0; /* position = 0 because it's not in the file */ - csd->size = last->offset + last->len; + csd->size = yasm_bc_next_offset(yasm_section_bcs_last(sect)); } else { - yasm_bytecode *last = yasm_section_bcs_last(sect); - pos = ftell(info->f); if (pos == -1) { yasm__fatal(N_("could not get file position on output file")); @@ -784,7 +777,7 @@ coff_objfmt_output_section(yasm_section *sect, /*@null@*/ void *d) coff_objfmt_output_bytecode); /* Sanity check final section size */ - if (csd->size != (last->offset + last->len)) + if (csd->size != yasm_bc_next_offset(yasm_section_bcs_last(sect))) yasm_internal_error( N_("coff: section computed size did not match actual size")); } @@ -1022,7 +1015,7 @@ coff_objfmt_output_sym(yasm_symrec *sym, /*@null@*/ void *d) } else yasm_internal_error(N_("didn't understand section")); if (precbc) - value += precbc->offset + precbc->len; + value += yasm_bc_next_offset(precbc); } } else if ((equ_val = yasm_symrec_get_equ(sym))) { yasm_expr *equ_val_copy = yasm_expr_copy(equ_val); diff --git a/modules/objfmts/elf/elf-objfmt.c b/modules/objfmts/elf/elf-objfmt.c index 4f08ec92..e82b574d 100644 --- a/modules/objfmts/elf/elf-objfmt.c +++ b/modules/objfmts/elf/elf-objfmt.c @@ -152,7 +152,7 @@ elf_objfmt_append_local_sym(yasm_symrec *sym, /*@null@*/ void *d) } if (precbc) - value = precbc->offset + precbc->len; + value = yasm_bc_next_offset(precbc); elf_symtab_set_nonzero(entry, sect, 0, 0, 0, NULL, &value); return 0; @@ -357,7 +357,7 @@ elf_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, assert(sym_shead != NULL); sym = elf_secthead_get_sym(sym_shead); - intn_val = sym_precbc->offset + sym_precbc->len; + intn_val = yasm_bc_next_offset(sym_precbc); } } @@ -518,7 +518,7 @@ elf_objfmt_output_section(yasm_section *sect, /*@null@*/ void *d) yasm_bytecode *last = yasm_section_bcs_last(sect); if (last) { yasm_intnum *sectsize; - sectsize = yasm_intnum_create_uint(last->offset + last->len); + sectsize = yasm_intnum_create_uint(yasm_bc_next_offset(last)); elf_secthead_add_size(shead, sectsize); yasm_intnum_destroy(sectsize); } diff --git a/modules/objfmts/xdf/xdf-objfmt.c b/modules/objfmts/xdf/xdf-objfmt.c index 543c9d09..ee12b08c 100644 --- a/modules/objfmts/xdf/xdf-objfmt.c +++ b/modules/objfmts/xdf/xdf-objfmt.c @@ -300,7 +300,6 @@ xdf_objfmt_output_section(yasm_section *sect, /*@null@*/ void *d) /*@dependent@*/ /*@null@*/ xdf_section_data *xsd; long pos; xdf_reloc *reloc; - yasm_bytecode *last; /* FIXME: Don't output absolute sections into the section table */ if (yasm_section_is_absolute(sect)) @@ -310,13 +309,12 @@ xdf_objfmt_output_section(yasm_section *sect, /*@null@*/ void *d) xsd = yasm_section_get_data(sect, &xdf_section_data_cb); assert(xsd != NULL); - last = yasm_section_bcs_last(sect); if (xsd->flags & XDF_SECT_BSS) { /* Don't output BSS sections. * TODO: Check for non-reserve bytecodes? */ pos = 0; /* position = 0 because it's not in the file */ - xsd->size = last->offset + last->len; + xsd->size = yasm_bc_next_offset(yasm_section_bcs_last(sect)); } else { pos = ftell(info->f); if (pos == -1) { @@ -331,7 +329,7 @@ xdf_objfmt_output_section(yasm_section *sect, /*@null@*/ void *d) xdf_objfmt_output_bytecode); /* Sanity check final section size */ - if (xsd->size != (last->offset + last->len)) + if (xsd->size != yasm_bc_next_offset(yasm_section_bcs_last(sect))) yasm_internal_error( N_("xdf: section computed size did not match actual size")); } @@ -513,7 +511,7 @@ xdf_objfmt_output_sym(yasm_symrec *sym, /*@null@*/ void *d) } else yasm_internal_error(N_("didn't understand section")); if (precbc) - value += precbc->offset + precbc->len; + value += yasm_bc_next_offset(precbc); } } else if ((equ_val = yasm_symrec_get_equ(sym))) { yasm_expr *equ_val_copy = yasm_expr_copy(equ_val); diff --git a/tools/python-yasm/bytecode.pxi b/tools/python-yasm/bytecode.pxi index 6cb47042..57c181a9 100644 --- a/tools/python-yasm/bytecode.pxi +++ b/tools/python-yasm/bytecode.pxi @@ -135,9 +135,10 @@ cdef extern from "libyasm/bc-int.h": yasm_section *section yasm_expr *multiple unsigned long len + unsigned long mult_int unsigned long line unsigned long offset - unsigned long opt_flags + unsigned long bc_index yasm_symrec **symrecs void *contents @@ -172,15 +173,18 @@ cdef class Bytecode: property len: def __get__(self): return self.bc.len def __set__(self, value): self.bc.len = value + property mult_int: + def __get__(self): return self.bc.mult_int + def __set__(self, value): self.bc.mult_int = value property line: def __get__(self): return self.bc.line def __set__(self, value): self.bc.line = value property offset: def __get__(self): return self.bc.offset def __set__(self, value): self.bc.offset = value - property opt_flags: - def __get__(self): return self.bc.opt_flags - def __set__(self, value): self.bc.opt_flags = value + property bc_index: + def __get__(self): return self.bc.bc_index + def __set__(self, value): self.bc.bc_index = value property symbols: # Someday extend this to do something modifiable, e.g. return a # list-like object.