From: Peter Johnson Date: Wed, 7 Jun 2006 04:01:33 +0000 (-0000) Subject: Get rid of calc_bc_dist_func, the only times this was used was when X-Git-Tag: v0.6.0~172^2~32 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a7b6526ea49ce62b252156a48f56ac24368f442d;p=yasm Get rid of calc_bc_dist_func, the only times this was used was when yasm_common_calc_bc_dist was used. Rename yasm_common_calc_bc_dist to yasm_calc_bc_dist, call it directly from the expr functions, and change higher-level callers to boolean flags of whether to calculate bc distance or not. svn path=/branches/new-optimizer/; revision=1550 --- diff --git a/libyasm/bc-align.c b/libyasm/bc-align.c index 0506a506..152b9625 100644 --- a/libyasm/bc-align.c +++ b/libyasm/bc-align.c @@ -106,13 +106,13 @@ static void bc_align_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc) { bytecode_align *align = (bytecode_align *)bc->contents; - if (!yasm_expr_get_intnum(&align->boundary, NULL)) + if (!yasm_expr_get_intnum(&align->boundary, 0)) yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("align boundary must be a constant")); - if (align->fill && !yasm_expr_get_intnum(&align->fill, NULL)) + if (align->fill && !yasm_expr_get_intnum(&align->fill, 0)) yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("align fill must be a constant")); - if (align->maxskip && !yasm_expr_get_intnum(&align->maxskip, NULL)) + if (align->maxskip && !yasm_expr_get_intnum(&align->maxskip, 0)) yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("align maximum skip must be a constant")); } @@ -165,7 +165,7 @@ bc_align_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, bytecode_align *align = (bytecode_align *)bc->contents; unsigned long len; unsigned long boundary = - yasm_intnum_get_uint(yasm_expr_get_intnum(&align->boundary, NULL)); + yasm_intnum_get_uint(yasm_expr_get_intnum(&align->boundary, 0)); if (boundary == 0) return 0; @@ -178,8 +178,7 @@ bc_align_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, return 0; if (align->maxskip) { unsigned long maxskip = - yasm_intnum_get_uint(yasm_expr_get_intnum(&align->maxskip, - NULL)); + yasm_intnum_get_uint(yasm_expr_get_intnum(&align->maxskip, 0)); if (len > maxskip) return 0; } @@ -187,7 +186,7 @@ bc_align_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, if (align->fill) { unsigned long v; - v = yasm_intnum_get_uint(yasm_expr_get_intnum(&align->fill, NULL)); + v = yasm_intnum_get_uint(yasm_expr_get_intnum(&align->fill, 0)); memset(*bufp, (int)v, len); *bufp += len; } else if (align->code_fill) { diff --git a/libyasm/bc-data.c b/libyasm/bc-data.c index c6913bdc..b58b56bd 100644 --- a/libyasm/bc-data.c +++ b/libyasm/bc-data.c @@ -116,7 +116,7 @@ bc_data_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc) break; case DV_ULEB128: case DV_SLEB128: - intn = yasm_expr_get_intnum(&dv->data.val.abs, NULL); + intn = yasm_expr_get_intnum(&dv->data.val.abs, 0); if (!intn) { yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("LEB128 requires constant values")); @@ -157,7 +157,7 @@ bc_data_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, break; case DV_ULEB128: case DV_SLEB128: - intn = yasm_expr_get_intnum(&dv->data.val.abs, NULL); + intn = yasm_expr_get_intnum(&dv->data.val.abs, 0); if (!intn) yasm_internal_error(N_("non-constant in data_tobytes")); bc->len += @@ -197,7 +197,7 @@ bc_data_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, break; case DV_ULEB128: case DV_SLEB128: - intn = yasm_expr_get_intnum(&dv->data.val.abs, NULL); + intn = yasm_expr_get_intnum(&dv->data.val.abs, 234); if (!intn) yasm_internal_error(N_("non-constant in data_tobytes")); *bufp += @@ -231,7 +231,7 @@ yasm_bc_create_data(yasm_datavalhead *datahead, unsigned int size, case DV_VALUE: case DV_ULEB128: case DV_SLEB128: - intn = yasm_expr_get_intnum(&dv->data.val.abs, NULL); + intn = yasm_expr_get_intnum(&dv->data.val.abs, 0); if (intn && dv->type == DV_VALUE && (arch || size == 1)) len += size; else if (intn && dv->type == DV_ULEB128) @@ -279,7 +279,7 @@ yasm_bc_create_data(yasm_datavalhead *datahead, unsigned int size, case DV_VALUE: case DV_ULEB128: case DV_SLEB128: - intn = yasm_expr_get_intnum(&dv->data.val.abs, NULL); + intn = yasm_expr_get_intnum(&dv->data.val.abs, 0); if (intn && dv->type == DV_VALUE && (arch || size == 1)) { if (size == 1) yasm_intnum_get_sized(intn, diff --git a/libyasm/bc-incbin.c b/libyasm/bc-incbin.c index 7201f8df..cf8dc278 100644 --- a/libyasm/bc-incbin.c +++ b/libyasm/bc-incbin.c @@ -134,7 +134,7 @@ bc_incbin_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, /* Try to convert start to integer value */ if (incbin->start) { - num = yasm_expr_get_intnum(&incbin->start, NULL); + num = yasm_expr_get_intnum(&incbin->start, 0); if (num) start = yasm_intnum_get_uint(num); if (!num) { @@ -147,7 +147,7 @@ bc_incbin_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, /* Try to convert maxlen to integer value */ if (incbin->maxlen) { - num = yasm_expr_get_intnum(&incbin->maxlen, NULL); + num = yasm_expr_get_intnum(&incbin->maxlen, 0); if (num) maxlen = yasm_intnum_get_uint(num); if (!num) { @@ -206,7 +206,7 @@ bc_incbin_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, /* Convert start to integer value */ if (incbin->start) { - num = yasm_expr_get_intnum(&incbin->start, NULL); + num = yasm_expr_get_intnum(&incbin->start, 0); if (!num) yasm_internal_error( N_("could not determine start in bc_tobytes_incbin")); diff --git a/libyasm/bc-insn.c b/libyasm/bc-insn.c index 4d3afacb..6e63e311 100644 --- a/libyasm/bc-insn.c +++ b/libyasm/bc-insn.c @@ -205,7 +205,7 @@ bc_insn_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc) if (op->data.ea) op->data.ea->disp.abs = yasm_expr__level_tree(op->data.ea->disp.abs, 1, 1, 0, - NULL, NULL, NULL, NULL); + 0, NULL, NULL, NULL); if (yasm_error_occurred()) { /* Add a pointer to where it was used to the error */ yasm_error_fetch(&eclass, &str, &xrefline, &xrefstr); @@ -222,8 +222,8 @@ bc_insn_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc) break; case YASM_INSN__OPERAND_IMM: op->data.val = - yasm_expr__level_tree(op->data.val, 1, 1, 1, NULL, NULL, - NULL, NULL); + yasm_expr__level_tree(op->data.val, 1, 1, 1, 0, NULL, NULL, + NULL); if (yasm_error_occurred()) { /* Add a pointer to where it was used to the error */ yasm_error_fetch(&eclass, &str, &xrefline, &xrefstr); diff --git a/libyasm/bc-reserve.c b/libyasm/bc-reserve.c index 03280d18..2be15122 100644 --- a/libyasm/bc-reserve.c +++ b/libyasm/bc-reserve.c @@ -114,7 +114,7 @@ bc_reserve_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, if (!reserve->numitems) return 0; - num = yasm_expr_get_intnum(&reserve->numitems, NULL); + num = yasm_expr_get_intnum(&reserve->numitems, 0); if (!num) { /* Check for use of floats first. */ if (reserve->numitems && diff --git a/libyasm/bytecode.c b/libyasm/bytecode.c index e008da1a..327e8751 100644 --- a/libyasm/bytecode.c +++ b/libyasm/bytecode.c @@ -179,7 +179,7 @@ yasm_bc_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc) } /*@null@*/ yasm_intnum * -yasm_common_calc_bc_dist(yasm_bytecode *precbc1, yasm_bytecode *precbc2) +yasm_calc_bc_dist(yasm_bytecode *precbc1, yasm_bytecode *precbc2) { unsigned long dist; yasm_intnum *intn; @@ -261,7 +261,7 @@ yasm_bc_tobytes(yasm_bytecode *bc, unsigned char *buf, unsigned long *bufsize, unsigned long datasize, multiple, i; int error = 0; - if (yasm_bc_get_multiple(bc, &multiple, NULL) || multiple == 0) { + if (yasm_bc_get_multiple(bc, &multiple, 1) || multiple == 0) { *bufsize = 0; return NULL; } @@ -300,7 +300,7 @@ yasm_bc_tobytes(yasm_bytecode *bc, unsigned char *buf, unsigned long *bufsize, int yasm_bc_get_multiple(yasm_bytecode *bc, unsigned long *multiple, - yasm_calc_bc_dist_func calc_bc_dist) + int calc_bc_dist) { /*@dependent@*/ /*@null@*/ const yasm_intnum *num; diff --git a/libyasm/bytecode.h b/libyasm/bytecode.h index 181d1bb5..3013eb00 100644 --- a/libyasm/bytecode.h +++ b/libyasm/bytecode.h @@ -299,12 +299,13 @@ void yasm_bc_print(const yasm_bytecode *bc, FILE *f, int indent_level); */ void yasm_bc_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); -/** Common version of calc_bc_dist that takes offsets from bytecodes. - * Should be used for the final stages of optimizers as well as in yasm_objfmt - * yasm_expr output functions. - * \see yasm_calc_bc_dist_func for parameter descriptions. +/** 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 + * \return Distance in bytes between the two bytecodes (bc2-bc1), or NULL if + * the distance was indeterminate. */ -/*@null@*/ /*@only@*/ yasm_intnum *yasm_common_calc_bc_dist +/*@null@*/ /*@only@*/ yasm_intnum *yasm_calc_bc_dist (yasm_bytecode *precbc1, yasm_bytecode *precbc2); /** @@ -378,11 +379,12 @@ int yasm_bc_expand(yasm_bytecode *bc, int span, long old_val, long new_val, /** Get the bytecode multiple value as an unsigned long integer. * \param bc bytecode * \param multiple multiple value (output) - * \param calc_bc_dist bytecode distance calculation function (optional) + * \param calc_bc_dist nonzero if distances between bytecodes should be + * calculated, 0 if error should be returned in this case * \return 1 on error (set with yasm_error_set), 0 on success. */ int yasm_bc_get_multiple(yasm_bytecode *bc, /*@out@*/ unsigned long *multiple, - /*@null@*/ yasm_calc_bc_dist_func calc_bc_dist); + int calc_bc_dist); /** Create a new data value from an expression. * \param expn expression diff --git a/libyasm/coretype.h b/libyasm/coretype.h index 89e5ed35..3fed09af 100644 --- a/libyasm/coretype.h +++ b/libyasm/coretype.h @@ -230,15 +230,6 @@ typedef enum { YASM_SYM_DLOCAL = 1 << 3 /**< If symbol is explicitly declared LOCAL */ } yasm_sym_vis; -/** 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 - * \return Distance in bytes between the two bytecodes (bc2-bc1), or NULL if - * the distance was indeterminate. - */ -typedef /*@null@*/ /*@only@*/ yasm_intnum * (*yasm_calc_bc_dist_func) - (yasm_bytecode *precbc1, yasm_bytecode *precbc2); - /** Convert yasm_value to its byte representation. Usually implemented by * object formats to keep track of relocations and verify legal expressions. * Must put the value into the least significant bits of the destination, diff --git a/libyasm/expr.c b/libyasm/expr.c index a0f55693..95522b37 100644 --- a/libyasm/expr.c +++ b/libyasm/expr.c @@ -187,8 +187,7 @@ yasm_expr_reg(unsigned long reg) * possible. Uses a simple n^2 algorithm because n is usually quite small. */ static /*@only@*/ yasm_expr * -expr_xform_bc_dist(/*@returned@*/ /*@only@*/ yasm_expr *e, - yasm_calc_bc_dist_func calc_bc_dist) +expr_xform_bc_dist(/*@returned@*/ /*@only@*/ yasm_expr *e) { int i; /*@dependent@*/ yasm_section *sect; @@ -244,7 +243,7 @@ expr_xform_bc_dist(/*@returned@*/ /*@only@*/ yasm_expr *e, yasm_symrec_get_label(e->terms[j].data.sym, &precbc2) && (sect = yasm_bc_get_section(precbc2)) && sect == sect2 && - (dist = calc_bc_dist(precbc, precbc2))) { + (dist = yasm_calc_bc_dist(precbc, precbc2))) { /* Change the symrec term to an integer */ e->terms[j].type = YASM_EXPR_INT; e->terms[j].data.intn = dist; @@ -731,7 +730,7 @@ typedef struct yasm__exprentry { /* Level an entire expn tree, expanding equ's as we go */ yasm_expr * yasm_expr__level_tree(yasm_expr *e, int fold_const, int simplify_ident, - int simplify_reg_mul, yasm_calc_bc_dist_func calc_bc_dist, + int simplify_reg_mul, int calc_bc_dist, yasm_expr_xform_func expr_xform_extra, void *expr_xform_extra_data, yasm__exprhead *eh) { @@ -838,11 +837,11 @@ yasm_expr__level_tree(yasm_expr *e, int fold_const, int simplify_ident, e = expr_level_op(e, fold_const, simplify_ident, simplify_reg_mul); if (calc_bc_dist || expr_xform_extra) { if (calc_bc_dist) - e = expr_xform_bc_dist(e, calc_bc_dist); + e = expr_xform_bc_dist(e); if (expr_xform_extra) e = expr_xform_extra(e, expr_xform_extra_data); e = yasm_expr__level_tree(e, fold_const, simplify_ident, - simplify_reg_mul, NULL, NULL, NULL, NULL); + simplify_reg_mul, 0, NULL, NULL, NULL); } return e; } @@ -1132,7 +1131,7 @@ yasm_expr_extract_wrt(yasm_expr **ep) /*@-unqualifiedtrans -nullderef -nullstate -onlytrans@*/ yasm_intnum * -yasm_expr_get_intnum(yasm_expr **ep, yasm_calc_bc_dist_func calc_bc_dist) +yasm_expr_get_intnum(yasm_expr **ep, int calc_bc_dist) { *ep = yasm_expr_simplify(*ep, calc_bc_dist); @@ -1148,7 +1147,7 @@ const yasm_symrec * yasm_expr_get_symrec(yasm_expr **ep, int simplify) { if (simplify) - *ep = yasm_expr_simplify(*ep, NULL); + *ep = yasm_expr_simplify(*ep, 0); if ((*ep)->op == YASM_EXPR_IDENT && ((*ep)->terms[0].type == YASM_EXPR_SYM || @@ -1164,7 +1163,7 @@ const unsigned long * yasm_expr_get_reg(yasm_expr **ep, int simplify) { if (simplify) - *ep = yasm_expr_simplify(*ep, NULL); + *ep = yasm_expr_simplify(*ep, 0); if ((*ep)->op == YASM_EXPR_IDENT && (*ep)->terms[0].type == YASM_EXPR_REG) return &((*ep)->terms[0].data.reg); diff --git a/libyasm/expr.h b/libyasm/expr.h index 59b3b5ae..801594eb 100644 --- a/libyasm/expr.h +++ b/libyasm/expr.h @@ -148,7 +148,8 @@ SLIST_HEAD(yasm__exprhead, yasm__exprentry); * \param fold_const enable constant folding if nonzero * \param simplify_ident simplify identities * \param simplify_reg_mul simplify REG*1 identities - * \param calc_bc_dist bytecode distance-calculation function + * \param calc_bc_dist nonzero if distances between bytecodes should be + * calculated, 0 if they should be left intact * \param expr_xform_extra extra transformation function * \param expr_xform_extra_data data to pass to expr_xform_extra * \param eh call with NULL (for internal use in recursion) @@ -156,8 +157,7 @@ SLIST_HEAD(yasm__exprhead, yasm__exprentry); */ /*@only@*/ /*@null@*/ yasm_expr *yasm_expr__level_tree (/*@returned@*/ /*@only@*/ /*@null@*/ yasm_expr *e, int fold_const, - int simplify_ident, int simplify_reg_mul, - /*@null@*/ yasm_calc_bc_dist_func calc_bc_dist, + int simplify_ident, int simplify_reg_mul, int calc_bc_dist, /*@null@*/ yasm_expr_xform_func expr_xform_extra, /*@null@*/ void *expr_xform_extra_data, /*@null@*/ yasm__exprhead *eh); @@ -165,7 +165,7 @@ SLIST_HEAD(yasm__exprhead, yasm__exprentry); * branches and simplifies integer-only subexpressions. Simplified version * of yasm_expr__level_tree(). * \param e expression - * \param cbd bytecode distance-calculation function + * \param cbd if distance between bytecodes should be calculated * \return Simplified expression. */ #define yasm_expr_simplify(e, cbd) \ @@ -192,13 +192,14 @@ SLIST_HEAD(yasm__exprhead, yasm__exprentry); /** Get the integer value of an expression if it's just an integer. * \param ep expression (pointer to) - * \param calc_bc_dist bytecode distance-calculation function + * \param calc_bc_dist nonzero if distances between bytecodes should be + * calculated, 0 if NULL should be returned in this case * \return NULL if the expression is too complex (contains anything other than * integers, ie floats, non-valued labels, registers); otherwise the * intnum value of the expression. */ /*@dependent@*/ /*@null@*/ yasm_intnum *yasm_expr_get_intnum - (yasm_expr **ep, /*@null@*/ yasm_calc_bc_dist_func calc_bc_dist); + (yasm_expr **ep, int calc_bc_dist); /** Get the symbol value of an expression if it's just a symbol. * \param ep expression (pointer to) diff --git a/libyasm/value.c b/libyasm/value.c index 375d3a13..14d4d355 100644 --- a/libyasm/value.c +++ b/libyasm/value.c @@ -416,7 +416,7 @@ yasm_value_finalize_expr(yasm_value *value, yasm_expr *e, unsigned int size) } yasm_value_initialize(value, yasm_expr__level_tree - (e, 1, 1, 0, NULL, NULL, NULL, NULL), size); + (e, 1, 1, 0, 0, NULL, NULL, NULL), size); /* quit early if there was an issue in simplify() */ if (yasm_error_occurred()) @@ -457,7 +457,7 @@ yasm_value_finalize_expr(yasm_value *value, yasm_expr *e, unsigned int size) if (value_finalize_scan(value, value->abs, 0)) return 1; - value->abs = yasm_expr__level_tree(value->abs, 1, 1, 0, NULL, NULL, NULL, + value->abs = yasm_expr__level_tree(value->abs, 1, 1, 0, 0, NULL, NULL, NULL); /* Simplify 0 in abs to NULL */ @@ -480,7 +480,7 @@ yasm_value_finalize(yasm_value *value) int yasm_value_output_basic(yasm_value *value, /*@out@*/ unsigned char *buf, size_t destsize, yasm_bytecode *bc, int warn, - yasm_arch *arch, yasm_calc_bc_dist_func calc_bc_dist) + yasm_arch *arch) { /*@dependent@*/ /*@null@*/ yasm_intnum *intn = NULL; /*@only@*/ yasm_intnum *outval; @@ -507,7 +507,7 @@ yasm_value_output_basic(yasm_value *value, /*@out@*/ unsigned char *buf, } /* Handle integer expressions */ - intn = yasm_expr_get_intnum(&value->abs, calc_bc_dist); + intn = yasm_expr_get_intnum(&value->abs, 1); if (!intn) { yasm_error_set(YASM_ERROR_TOO_COMPLEX, N_("expression too complex")); diff --git a/libyasm/value.h b/libyasm/value.h index 6aef6011..1cde996c 100644 --- a/libyasm/value.h +++ b/libyasm/value.h @@ -123,8 +123,7 @@ int yasm_value_finalize_expr(/*@out@*/ yasm_value *value, */ int yasm_value_output_basic (yasm_value *value, /*@out@*/ unsigned char *buf, size_t destsize, - yasm_bytecode *bc, int warn, yasm_arch *arch, - yasm_calc_bc_dist_func calc_bc_dist); + yasm_bytecode *bc, int warn, yasm_arch *arch); /** Print a value. For debugging purposes. * \param value value diff --git a/modules/arch/x86/x86arch.c b/modules/arch/x86/x86arch.c index 72b2b4da..0089b615 100644 --- a/modules/arch/x86/x86arch.c +++ b/modules/arch/x86/x86arch.c @@ -130,7 +130,7 @@ x86_parse_directive(yasm_arch *arch, const char *name, if (yasm__strcasecmp(name, "bits") == 0) { if ((vp = yasm_vps_first(valparams)) && !vp->val && vp->param != NULL && - (intn = yasm_expr_get_intnum(&vp->param, NULL)) != NULL && + (intn = yasm_expr_get_intnum(&vp->param, 0)) != NULL && (lval = yasm_intnum_get_int(intn)) && (lval == 16 || lval == 32 || lval == 64)) arch_x86->mode_bits = (unsigned char)lval; diff --git a/modules/arch/x86/x86bc.c b/modules/arch/x86/x86bc.c index d5bbfa18..6c56ac4b 100644 --- a/modules/arch/x86/x86bc.c +++ b/modules/arch/x86/x86bc.c @@ -554,7 +554,7 @@ x86_bc_insn_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, long val; if (imm->val.abs) - num = yasm_expr_get_intnum(&imm->val.abs, NULL); + num = yasm_expr_get_intnum(&imm->val.abs, 0); /* TODO: check imm->len vs. sized len from expr? */ diff --git a/modules/arch/x86/x86expr.c b/modules/arch/x86/x86expr.c index 01a1cb45..8f62158c 100644 --- a/modules/arch/x86/x86expr.c +++ b/modules/arch/x86/x86expr.c @@ -259,8 +259,7 @@ x86_expr_checkea_getregusage(yasm_expr **ep, /*@null@*/ int *indexreg, yasm_expr *e, *wrt; /*@-unqualifiedtrans@*/ - *ep = yasm_expr__level_tree(*ep, 1, 1, indexreg == 0, NULL, NULL, NULL, - NULL); + *ep = yasm_expr__level_tree(*ep, 1, 1, indexreg == 0, 0, NULL, NULL, NULL); /* Check for WRT rip first */ wrt = yasm_expr_extract_wrt(ep); @@ -295,7 +294,7 @@ x86_expr_checkea_getregusage(yasm_expr **ep, /*@null@*/ int *indexreg, return 1; case 2: /* Need to simplify again */ - *ep = yasm_expr__level_tree(*ep, 1, 1, indexreg == 0, NULL, NULL, + *ep = yasm_expr__level_tree(*ep, 1, 1, indexreg == 0, 0, NULL, NULL, NULL); e = *ep; break; @@ -386,7 +385,7 @@ x86_expr_checkea_getregusage(yasm_expr **ep, /*@null@*/ int *indexreg, /* Simplify expr, which is now really just the displacement. This * should get rid of the 0's we put in for registers in the callback. */ - *ep = yasm_expr_simplify(*ep, NULL); + *ep = yasm_expr_simplify(*ep, 0); /* e = *ep; */ return 0; @@ -499,7 +498,7 @@ x86_checkea_calc_displen(x86_effaddr *x86_ea, unsigned int wordsize, int noreg, * equaling zero is probably a rare case, so we ignore it for now. */ if (x86_ea->ea.disp.abs && - !(intn = yasm_expr_get_intnum(&x86_ea->ea.disp.abs, NULL))) { + !(intn = yasm_expr_get_intnum(&x86_ea->ea.disp.abs, 0))) { /* expr still has unknown values: treat like BP/EBP above */ x86_ea->ea.need_nonzero_len = 1; x86_ea->modrm |= 0100; diff --git a/modules/arch/x86/x86id.c b/modules/arch/x86/x86id.c index f0245707..514cc28d 100644 --- a/modules/arch/x86/x86id.c +++ b/modules/arch/x86/x86id.c @@ -2513,7 +2513,7 @@ yasm_x86__finalize_insn(yasm_arch *arch, yasm_bytecode *bc, case OPT_Imm1: if (op->type == YASM_INSN__OPERAND_IMM) { const yasm_intnum *num; - num = yasm_expr_get_intnum(&op->data.val, NULL); + num = yasm_expr_get_intnum(&op->data.val, 0); if (!num || !yasm_intnum_is_pos1(num)) mismatch = 1; } else @@ -2918,8 +2918,7 @@ yasm_x86__finalize_insn(yasm_arch *arch, yasm_bytecode *bc, */ if (!insn->imm->val.abs || yasm_intnum_check_size( - yasm_expr_get_intnum(&insn->imm->val.abs, NULL), - 32, 0, 1)) { + yasm_expr_get_intnum(&insn->imm->val.abs, 0), 32, 0, 1)) { /* Throwaway REX byte */ unsigned char rex_temp = 0; diff --git a/modules/dbgfmts/codeview/cv-symline.c b/modules/dbgfmts/codeview/cv-symline.c index 78c1059a..44e59973 100644 --- a/modules/dbgfmts/codeview/cv-symline.c +++ b/modules/dbgfmts/codeview/cv-symline.c @@ -753,7 +753,7 @@ cv8_symhead_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, /* Total length of info (following this field) - 4 bytes */ yasm_intnum_set_uint(cval, bc->len); - intn = yasm_common_calc_bc_dist(head->start_prevbc, head->end_prevbc); + intn = yasm_calc_bc_dist(head->start_prevbc, head->end_prevbc); yasm_intnum_calc(intn, YASM_EXPR_SUB, cval); yasm_arch_intnum_tobytes(dbgfmt_cv->arch, intn, buf, 4, 32, 0, bc, 0); buf += 4; @@ -891,8 +891,8 @@ cv8_lineinfo_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, YASM_WRITE_8(buf, 0); /* Section length covered by line number info */ - cval = yasm_common_calc_bc_dist(yasm_section_bcs_first(li->sect), - yasm_section_bcs_last(li->sect)); + cval = yasm_calc_bc_dist(yasm_section_bcs_first(li->sect), + yasm_section_bcs_last(li->sect)); yasm_arch_intnum_tobytes(dbgfmt_cv->arch, cval, buf, 4, 32, 0, bc, 0); buf += 4; diff --git a/modules/dbgfmts/dwarf2/dwarf2-aranges.c b/modules/dbgfmts/dwarf2/dwarf2-aranges.c index b8056fd6..7ce85553 100644 --- a/modules/dbgfmts/dwarf2/dwarf2-aranges.c +++ b/modules/dbgfmts/dwarf2/dwarf2-aranges.c @@ -71,8 +71,8 @@ dwarf2_generate_aranges_section(yasm_section *sect, /*@null@*/ void *d) yasm_expr_sym(yasm_dwarf2__bc_sym(dbgfmt_dwarf2->symtab, yasm_section_bcs_first(sect))), 0); length = yasm_expr_create_ident( - yasm_expr_int(yasm_common_calc_bc_dist( - yasm_section_bcs_first(sect), yasm_section_bcs_last(sect))), 0); + yasm_expr_int(yasm_calc_bc_dist(yasm_section_bcs_first(sect), + yasm_section_bcs_last(sect))), 0); dwarf2_append_arange(info->debug_aranges, start, length, dbgfmt_dwarf2->sizeof_address); diff --git a/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c b/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c index 54f10f4f..c5f807fd 100644 --- a/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c +++ b/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c @@ -274,7 +274,7 @@ dwarf2_head_bc_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, /* Total length of aranges info (following this field) */ cval = yasm_intnum_create_uint(dbgfmt_dwarf2->sizeof_offset); - intn = yasm_common_calc_bc_dist(head->start_prevbc, head->end_prevbc); + intn = yasm_calc_bc_dist(head->start_prevbc, head->end_prevbc); yasm_intnum_calc(intn, YASM_EXPR_SUB, cval); yasm_arch_intnum_tobytes(dbgfmt_dwarf2->arch, intn, buf, dbgfmt_dwarf2->sizeof_offset, diff --git a/modules/dbgfmts/dwarf2/dwarf2-info.c b/modules/dbgfmts/dwarf2/dwarf2-info.c index 11ac620b..99bef0f8 100644 --- a/modules/dbgfmts/dwarf2/dwarf2-info.c +++ b/modules/dbgfmts/dwarf2/dwarf2-info.c @@ -333,7 +333,7 @@ yasm_dwarf2__generate_info(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, abc->len += dwarf2_add_abbrev_attr(abbrev, DW_AT_high_pc, DW_FORM_addr); dwarf2_append_expr(debug_info, yasm_expr_create(YASM_EXPR_ADD, yasm_expr_sym(first), - yasm_expr_int(yasm_common_calc_bc_dist( + yasm_expr_int(yasm_calc_bc_dist( yasm_section_bcs_first(main_code), yasm_section_bcs_last(main_code))), 0), dbgfmt_dwarf2->sizeof_address, 0); diff --git a/modules/dbgfmts/dwarf2/dwarf2-line.c b/modules/dbgfmts/dwarf2/dwarf2-line.c index e4c35fdc..85e860e5 100644 --- a/modules/dbgfmts/dwarf2/dwarf2-line.c +++ b/modules/dbgfmts/dwarf2/dwarf2-line.c @@ -837,7 +837,7 @@ yasm_dwarf2__line_directive(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, yasm_xfree(loc); return 0; } - intn = yasm_expr_get_intnum(&vp->param, NULL); + intn = yasm_expr_get_intnum(&vp->param, 0); if (!intn) { yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("file number is not a constant")); @@ -859,7 +859,7 @@ yasm_dwarf2__line_directive(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, yasm_xfree(loc); return 0; } - intn = yasm_expr_get_intnum(&vp->param, NULL); + intn = yasm_expr_get_intnum(&vp->param, 0); if (!intn) { yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("file number is not a constant")); @@ -888,7 +888,7 @@ yasm_dwarf2__line_directive(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, /* Optional column number */ vp = yasm_vps_next(vp); if (vp && vp->param) { - intn = yasm_expr_get_intnum(&vp->param, NULL); + intn = yasm_expr_get_intnum(&vp->param, 0); if (!intn) { yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("column number is not a constant")); @@ -914,7 +914,7 @@ yasm_dwarf2__line_directive(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, yasm_xfree(loc); return 0; } - intn = yasm_expr_get_intnum(&vp->param, NULL); + intn = yasm_expr_get_intnum(&vp->param, 0); if (!intn) { yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("is_stmt value is not a constant")); @@ -937,7 +937,7 @@ yasm_dwarf2__line_directive(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, yasm_xfree(loc); return 0; } - intn = yasm_expr_get_intnum(&vp->param, NULL); + intn = yasm_expr_get_intnum(&vp->param, 0); if (!intn) { yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("isa value is not a constant")); @@ -977,7 +977,7 @@ yasm_dwarf2__line_directive(yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, } /* Otherwise.. first vp is the file number */ - file_intn = yasm_expr_get_intnum(&vp->param, NULL); + file_intn = yasm_expr_get_intnum(&vp->param, 0); if (!file_intn) { yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("file number is not a constant")); diff --git a/modules/listfmts/nasm/nasm-listfmt.c b/modules/listfmts/nasm/nasm-listfmt.c index 0f197234..427ffa35 100644 --- a/modules/listfmts/nasm/nasm-listfmt.c +++ b/modules/listfmts/nasm/nasm-listfmt.c @@ -92,8 +92,8 @@ nasm_listfmt_output_value(yasm_value *value, unsigned char *buf, assert(info != NULL); /* Output */ - switch (yasm_value_output_basic(value, buf, destsize, bc, warn, info->arch, - NULL)) { + switch (yasm_value_output_basic(value, buf, destsize, bc, warn, + info->arch)) { case -1: return 1; case 0: @@ -121,7 +121,7 @@ nasm_listfmt_output_value(yasm_value *value, unsigned char *buf, } if (value->abs) { - intn = yasm_expr_get_intnum(&value->abs, NULL); + intn = yasm_expr_get_intnum(&value->abs, 0); if (intn) return yasm_arch_intnum_tobytes(info->arch, intn, buf, destsize, valsize, 0, bc, 0); @@ -216,7 +216,7 @@ nasm_listfmt_output(yasm_listfmt *listfmt, FILE *f, yasm_linemap *linemap, */ bigbuf = yasm_bc_tobytes(bc, buf, &size, &gap, &info, nasm_listfmt_output_value, NULL); - yasm_bc_get_multiple(bc, &multiple, NULL); + yasm_bc_get_multiple(bc, &multiple, 1); size /= multiple; /* output bytes with reloc information */ diff --git a/modules/objfmts/bin/bin-objfmt.c b/modules/objfmts/bin/bin-objfmt.c index da84defd..6e8954fd 100644 --- a/modules/objfmts/bin/bin-objfmt.c +++ b/modules/objfmts/bin/bin-objfmt.c @@ -120,8 +120,7 @@ bin_objfmt_expr_xform(/*@returned@*/ /*@only@*/ yasm_expr *e, e->terms[i].type == YASM_EXPR_SYMEXP) && yasm_symrec_get_label(e->terms[i].data.sym, &precbc) && (sect = yasm_bc_get_section(precbc)) && - (dist = yasm_common_calc_bc_dist(yasm_section_bcs_first(sect), - precbc))) { + (dist = yasm_calc_bc_dist(yasm_section_bcs_first(sect), precbc))) { const yasm_expr *start = yasm_section_get_start(sect); e->terms[i].type = YASM_EXPR_EXPR; e->terms[i].data.expn = @@ -162,11 +161,11 @@ bin_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, /* Simplify absolute portion of value, transforming symrecs */ if (value->abs) value->abs = yasm_expr__level_tree - (value->abs, 1, 1, 1, NULL, bin_objfmt_expr_xform, NULL, NULL); + (value->abs, 1, 1, 1, 0, bin_objfmt_expr_xform, NULL, NULL); /* Output */ switch (yasm_value_output_basic(value, buf, destsize, bc, warn, - info->objfmt_bin->arch, NULL)) { + info->objfmt_bin->arch)) { case -1: return 1; case 0: @@ -261,7 +260,7 @@ bin_objfmt_output(yasm_objfmt *objfmt, FILE *f, /*@unused@*/ int all_syms, /* Find out the start of .text */ startexpr = yasm_expr_copy(yasm_section_get_start(text)); assert(startexpr != NULL); - startnum = yasm_expr_get_intnum(&startexpr, NULL); + startnum = yasm_expr_get_intnum(&startexpr, 0); if (!startnum) { yasm_error_set(YASM_ERROR_TOO_COMPLEX, N_("ORG expression too complex")); @@ -404,7 +403,7 @@ bin_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, return NULL; } - align_expr = yasm_expr_get_intnum(&vp->param, NULL); + align_expr = yasm_expr_get_intnum(&vp->param, 0); if (!align_expr) { yasm_error_set(YASM_ERROR_VALUE, N_("argument to `%s' is not a power of two"), diff --git a/modules/objfmts/coff/coff-objfmt.c b/modules/objfmts/coff/coff-objfmt.c index 6a3a9957..1a328ab0 100644 --- a/modules/objfmts/coff/coff-objfmt.c +++ b/modules/objfmts/coff/coff-objfmt.c @@ -441,15 +441,14 @@ coff_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, objfmt_coff = info->objfmt_coff; if (value->abs) - value->abs = yasm_expr_simplify(value->abs, yasm_common_calc_bc_dist); + value->abs = yasm_expr_simplify(value->abs, 1); /* Try to output constant and PC-relative section-local first. * Note this does NOT output any value with a SEG, WRT, external, * cross-section, or non-PC-relative reference (those are handled below). */ switch (yasm_value_output_basic(value, buf, destsize, bc, warn, - info->objfmt_coff->arch, - yasm_common_calc_bc_dist)) { + info->objfmt_coff->arch)) { case -1: return 1; case 0: @@ -488,7 +487,7 @@ coff_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, N_("coff: wrt expression too complex")); return 1; } - dist = yasm_common_calc_bc_dist(wrt_precbc, rel_precbc); + dist = yasm_calc_bc_dist(wrt_precbc, rel_precbc); if (!dist) { yasm_error_set(YASM_ERROR_TOO_COMPLEX, N_("coff: cannot wrt across sections")); @@ -505,8 +504,7 @@ coff_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, csymd = yasm_symrec_get_data(sym, &coff_symrec_data_cb); assert(csymd != NULL); - common_size = yasm_expr_get_intnum(&csymd->size, - yasm_common_calc_bc_dist); + common_size = yasm_expr_get_intnum(&csymd->size, 1); if (!common_size) { yasm_error_set(YASM_ERROR_TOO_COMPLEX, N_("coff: common size too complex")); @@ -663,7 +661,7 @@ coff_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, } if (value->abs) { - yasm_intnum *intn2 = yasm_expr_get_intnum(&value->abs, NULL); + yasm_intnum *intn2 = yasm_expr_get_intnum(&value->abs, 0); if (!intn2) { yasm_error_set(YASM_ERROR_TOO_COMPLEX, N_("coff: relocation too complex")); @@ -1010,8 +1008,7 @@ coff_objfmt_output_sym(yasm_symrec *sym, /*@null@*/ void *d) yasm_expr *abs_start; abs_start = yasm_expr_copy(yasm_section_get_start(sect)); - intn = yasm_expr_get_intnum(&abs_start, - yasm_common_calc_bc_dist); + intn = yasm_expr_get_intnum(&abs_start, 1); if (!intn) { yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("absolute section start not an integer expression")); @@ -1029,8 +1026,7 @@ coff_objfmt_output_sym(yasm_symrec *sym, /*@null@*/ void *d) } } else if ((equ_val = yasm_symrec_get_equ(sym))) { yasm_expr *equ_val_copy = yasm_expr_copy(equ_val); - intn = yasm_expr_get_intnum(&equ_val_copy, - yasm_common_calc_bc_dist); + intn = yasm_expr_get_intnum(&equ_val_copy, 1); if (!intn) { if (vis & YASM_SYM_GLOBAL) { yasm_error_set(YASM_ERROR_NOT_CONSTANT, @@ -1044,8 +1040,7 @@ coff_objfmt_output_sym(yasm_symrec *sym, /*@null@*/ void *d) scnum = 0xffff; /* -1 = absolute symbol */ } else { if (vis & YASM_SYM_COMMON) { - intn = yasm_expr_get_intnum(&csymd->size, - yasm_common_calc_bc_dist); + intn = yasm_expr_get_intnum(&csymd->size, 1); if (!intn) { yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("COMMON data size not an integer expression")); @@ -1524,7 +1519,7 @@ coff_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, } else if (yasm__strcasecmp(vp->val, "align") == 0 && vp->param) { if (objfmt_coff->win32) { /*@dependent@*/ /*@null@*/ const yasm_intnum *align_expr; - align_expr = yasm_expr_get_intnum(&vp->param, NULL); + align_expr = yasm_expr_get_intnum(&vp->param, 0); if (!align_expr) { yasm_error_set(YASM_ERROR_VALUE, N_("argument to `%s' is not a power of two"), diff --git a/modules/objfmts/elf/elf-objfmt.c b/modules/objfmts/elf/elf-objfmt.c index 2beeffbf..4f08ec92 100644 --- a/modules/objfmts/elf/elf-objfmt.c +++ b/modules/objfmts/elf/elf-objfmt.c @@ -307,15 +307,14 @@ elf_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, yasm_internal_error("null info struct"); if (value->abs) - value->abs = yasm_expr_simplify(value->abs, yasm_common_calc_bc_dist); + value->abs = yasm_expr_simplify(value->abs, 1); /* Try to output constant and PC-relative section-local first. * Note this does NOT output any value with a SEG, WRT, external, * cross-section, or non-PC-relative reference (those are handled below). */ switch (yasm_value_output_basic(value, buf, destsize, bc, warn, - info->objfmt_elf->arch, - yasm_common_calc_bc_dist)) { + info->objfmt_elf->arch)) { case -1: return 1; case 0: @@ -381,7 +380,7 @@ elf_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, intn = yasm_intnum_create_uint(intn_val); if (value->abs) { - yasm_intnum *intn2 = yasm_expr_get_intnum(&value->abs, NULL); + yasm_intnum *intn2 = yasm_expr_get_intnum(&value->abs, 0); if (!intn2) { yasm_error_set(YASM_ERROR_TOO_COMPLEX, N_("elf: relocation too complex")); @@ -913,7 +912,7 @@ elf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, else if (yasm__strcasecmp(vp->val, "align") == 0 && vp->param) { /*@dependent@*/ /*@null@*/ const yasm_intnum *align_expr; - align_expr = yasm_expr_get_intnum(&vp->param, NULL); + align_expr = yasm_expr_get_intnum(&vp->param, 0); if (!align_expr) { yasm_error_set(YASM_ERROR_VALUE, N_("argument to `%s' is not a power of two"), @@ -938,7 +937,7 @@ elf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, if (objext_valparams && (vp = yasm_vps_first(objext_valparams)) && vp->param) { - merge_intn = yasm_expr_get_intnum(&vp->param, NULL); + merge_intn = yasm_expr_get_intnum(&vp->param, 0); if (!merge_intn) yasm_warn_set(YASM_WARN_GENERAL, N_("invalid merge entity size")); @@ -1071,7 +1070,7 @@ elf_objfmt_common_declare(yasm_objfmt *objfmt, const char *name, if (!vp->val && vp->param) { /*@dependent@*/ /*@null@*/ const yasm_intnum *align_expr; - align_expr = yasm_expr_get_intnum(&vp->param, NULL); + align_expr = yasm_expr_get_intnum(&vp->param, 0); if (!align_expr) { yasm_error_set(YASM_ERROR_VALUE, N_("alignment constraint is not a power of two")); diff --git a/modules/objfmts/elf/elf.c b/modules/objfmts/elf/elf.c index f2426c01..ce1e9dcb 100644 --- a/modules/objfmts/elf/elf.c +++ b/modules/objfmts/elf/elf.c @@ -441,7 +441,7 @@ elf_symtab_write_to_file(FILE *f, elf_symtab_head *symtab, /* get size (if specified); expr overrides stored integer */ if (entry->xsize) { size_intn = yasm_intnum_copy( - yasm_expr_get_intnum(&entry->xsize, yasm_common_calc_bc_dist)); + yasm_expr_get_intnum(&entry->xsize, 1)); if (!size_intn) { yasm_error_set(YASM_ERROR_VALUE, N_("size specifier not an integer expression")); @@ -459,8 +459,7 @@ elf_symtab_write_to_file(FILE *f, elf_symtab_head *symtab, if (equ_expr_c != NULL) { const yasm_intnum *equ_intn; yasm_expr *equ_expr = yasm_expr_copy(equ_expr_c); - equ_intn = yasm_expr_get_intnum(&equ_expr, - yasm_common_calc_bc_dist); + equ_intn = yasm_expr_get_intnum(&equ_expr, 1); if (equ_intn == NULL) { yasm_error_set(YASM_ERROR_VALUE, diff --git a/modules/objfmts/xdf/xdf-objfmt.c b/modules/objfmts/xdf/xdf-objfmt.c index 56fe213c..543c9d09 100644 --- a/modules/objfmts/xdf/xdf-objfmt.c +++ b/modules/objfmts/xdf/xdf-objfmt.c @@ -173,15 +173,14 @@ xdf_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, objfmt_xdf = info->objfmt_xdf; if (value->abs) - value->abs = yasm_expr_simplify(value->abs, yasm_common_calc_bc_dist); + value->abs = yasm_expr_simplify(value->abs, 1); /* Try to output constant and PC-relative section-local first. * Note this does NOT output any value with a SEG, WRT, external, * cross-section, or non-PC-relative reference (those are handled below). */ switch (yasm_value_output_basic(value, buf, destsize, bc, warn, - info->objfmt_xdf->arch, - yasm_common_calc_bc_dist)) { + info->objfmt_xdf->arch)) { case -1: return 1; case 0: @@ -231,7 +230,7 @@ xdf_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize, intn = yasm_intnum_create_uint(0); if (value->abs) { - yasm_intnum *intn2 = yasm_expr_get_intnum(&value->abs, NULL); + yasm_intnum *intn2 = yasm_expr_get_intnum(&value->abs, 0); if (!intn2) { yasm_error_set(YASM_ERROR_TOO_COMPLEX, N_("xdf: relocation too complex")); @@ -500,8 +499,7 @@ xdf_objfmt_output_sym(yasm_symrec *sym, /*@null@*/ void *d) yasm_expr *abs_start; abs_start = yasm_expr_copy(yasm_section_get_start(sect)); - intn = yasm_expr_get_intnum(&abs_start, - yasm_common_calc_bc_dist); + intn = yasm_expr_get_intnum(&abs_start, 1); if (!intn) { yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("absolute section start not an integer expression")); @@ -519,8 +517,7 @@ xdf_objfmt_output_sym(yasm_symrec *sym, /*@null@*/ void *d) } } else if ((equ_val = yasm_symrec_get_equ(sym))) { yasm_expr *equ_val_copy = yasm_expr_copy(equ_val); - intn = yasm_expr_get_intnum(&equ_val_copy, - yasm_common_calc_bc_dist); + intn = yasm_expr_get_intnum(&equ_val_copy, 1); if (!intn) { if (vis & YASM_SYM_GLOBAL) { yasm_error_set(YASM_ERROR_NOT_CONSTANT, @@ -727,7 +724,7 @@ xdf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, flags |= XDF_SECT_FLAT; } else if (yasm__strcasecmp(vp->val, "absolute") == 0 && vp->param) { flags |= XDF_SECT_ABSOLUTE; - absaddr = yasm_expr_get_intnum(&vp->param, NULL); + absaddr = yasm_expr_get_intnum(&vp->param, 0); if (!absaddr) { yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("argument to `%s' is not an integer"), @@ -735,7 +732,7 @@ xdf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, return NULL; } } else if (yasm__strcasecmp(vp->val, "virtual") == 0 && vp->param) { - vaddr = yasm_expr_get_intnum(&vp->param, NULL); + vaddr = yasm_expr_get_intnum(&vp->param, 0); if (!vaddr) { yasm_error_set(YASM_ERROR_NOT_CONSTANT, N_("argument to `%s' is not an integer"), @@ -745,7 +742,7 @@ xdf_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, } else if (yasm__strcasecmp(vp->val, "align") == 0 && vp->param) { /*@dependent@*/ /*@null@*/ const yasm_intnum *align_expr; - align_expr = yasm_expr_get_intnum(&vp->param, NULL); + align_expr = yasm_expr_get_intnum(&vp->param, 0); if (!align_expr) { yasm_error_set(YASM_ERROR_VALUE, N_("argument to `%s' is not a power of two"), diff --git a/modules/parsers/gas/gas-bison.y b/modules/parsers/gas/gas-bison.y index 0eba1c8f..209b3712 100644 --- a/modules/parsers/gas/gas-bison.y +++ b/modules/parsers/gas/gas-bison.y @@ -200,7 +200,7 @@ lineexp: instr } /* Macro directives */ | DIR_REPT expr { - yasm_intnum *intn = yasm_expr_get_intnum(&$2, NULL); + yasm_intnum *intn = yasm_expr_get_intnum(&$2, 0); $$ = (yasm_bytecode *)NULL; if (!intn) { @@ -932,7 +932,7 @@ gas_parser_align(yasm_parser_gas *parser_gas, yasm_section *sect, yasm_expr_expr(boundval), cur_line); /* Largest .align in the section specifies section alignment. */ - boundintn = yasm_expr_get_intnum(&boundval, NULL); + boundintn = yasm_expr_get_intnum(&boundval, 0); if (boundintn) { unsigned long boundint = yasm_intnum_get_uint(boundintn); @@ -995,7 +995,7 @@ gas_parser_dir_fill(yasm_parser_gas *parser_gas, /*@only@*/ yasm_expr *repeat, if (size) { /*@dependent@*/ /*@null@*/ yasm_intnum *intn; - intn = yasm_expr_get_intnum(&size, NULL); + intn = yasm_expr_get_intnum(&size, 0); if (!intn) { yasm_error_set(YASM_ERROR_NOT_ABSOLUTE, N_("size must be an absolute expression")); diff --git a/modules/parsers/nasm/nasm-bison.y b/modules/parsers/nasm/nasm-bison.y index ab5c0b67..c477e245 100644 --- a/modules/parsers/nasm/nasm-bison.y +++ b/modules/parsers/nasm/nasm-bison.y @@ -621,7 +621,7 @@ nasm_parser_directive(yasm_parser_nasm *parser_nasm, const char *name, * Note: this doesn't match NASM behavior, but is a lot more * intelligent! */ - boundintn = yasm_expr_get_intnum(&boundval, NULL); + boundintn = yasm_expr_get_intnum(&boundval, 0); if (boundintn) { unsigned long boundint = yasm_intnum_get_uint(boundintn); @@ -649,7 +649,7 @@ nasm_parser_directive(yasm_parser_nasm *parser_nasm, const char *name, strlen(vp->val)); else if (vp->param) { const yasm_intnum *intcpu; - intcpu = yasm_expr_get_intnum(&vp->param, NULL); + intcpu = yasm_expr_get_intnum(&vp->param, 0); if (!intcpu) yasm_error_set(YASM_ERROR_SYNTAX, N_("invalid argument to [%s]"), "CPU"); diff --git a/modules/preprocs/nasm/nasm-pp.c b/modules/preprocs/nasm/nasm-pp.c index 81548d6f..823b4bc2 100644 --- a/modules/preprocs/nasm/nasm-pp.c +++ b/modules/preprocs/nasm/nasm-pp.c @@ -1709,7 +1709,7 @@ if_condition(Token * tline, int i) if (tokval.t_type) error(ERR_WARNING, "trailing garbage after expression ignored"); - intn = yasm_expr_get_intnum(&evalresult, NULL); + intn = yasm_expr_get_intnum(&evalresult, 0); if (!intn) { error(ERR_NONFATAL, @@ -2468,7 +2468,7 @@ do_directive(Token * tline) if (tokval.t_type) error(ERR_WARNING, "trailing garbage after expression ignored"); - intn = yasm_expr_get_intnum(&evalresult, NULL); + intn = yasm_expr_get_intnum(&evalresult, 0); if (!intn) { error(ERR_NONFATAL, "non-constant value given to `%%rotate'"); @@ -2529,7 +2529,7 @@ do_directive(Token * tline) if (tokval.t_type) error(ERR_WARNING, "trailing garbage after expression ignored"); - intn = yasm_expr_get_intnum(&evalresult, NULL); + intn = yasm_expr_get_intnum(&evalresult, 0); if (!intn) { error(ERR_NONFATAL, "non-constant value given to `%%rep'"); @@ -2924,7 +2924,7 @@ do_directive(Token * tline) free_tlist(origline); return DIRECTIVE_FOUND; } - intn = yasm_expr_get_intnum(&evalresult, NULL); + intn = yasm_expr_get_intnum(&evalresult, 0); if (!intn) { error(ERR_NONFATAL, "non-constant value given to `%%substr`"); @@ -3028,7 +3028,7 @@ do_directive(Token * tline) error(ERR_WARNING, "trailing garbage after expression ignored"); - intn = yasm_expr_get_intnum(&evalresult, NULL); + intn = yasm_expr_get_intnum(&evalresult, 0); if (!intn) { error(ERR_NONFATAL, diff --git a/tools/python-yasm/bytecode.pxi b/tools/python-yasm/bytecode.pxi index 1c3e5ab4..a3f49594 100644 --- a/tools/python-yasm/bytecode.pxi +++ b/tools/python-yasm/bytecode.pxi @@ -91,16 +91,21 @@ cdef extern from "libyasm/bytecode.h": cdef void yasm_bc_destroy(yasm_bytecode *bc) cdef void yasm_bc_print(yasm_bytecode *bc, FILE *f, int indent_level) cdef void yasm_bc_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc) - cdef yasm_intnum *yasm_common_calc_bc_dist(yasm_bytecode *precbc1, + cdef yasm_intnum *yasm_calc_bc_dist(yasm_bytecode *precbc1, yasm_bytecode *precbc2) - cdef yasm_bc_resolve_flags yasm_bc_resolve(yasm_bytecode *bc, int save, - yasm_calc_bc_dist_func calc_bc_dist) + ctypedef void (*yasm_bc_add_span_func) (void *add_span_data, + yasm_bytecode *bc, int id, yasm_value *value, + yasm_bytecode *origin_prevbc, long neg_thres, long pos_thres) + cdef int yasm_bc_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, + void *add_span_data) + cdef int yasm_bc_expand(yasm_bytecode *bc, int span, long old_val, + long new_val, long *neg_thres, long *pos_thres) cdef unsigned char* yasm_bc_tobytes(yasm_bytecode *bc, unsigned char *buf, unsigned long *bufsize, int *gap, void *d, yasm_output_value_func output_value, yasm_output_reloc_func output_reloc) cdef int yasm_bc_get_multiple(yasm_bytecode *bc, unsigned long *multiple, - yasm_calc_bc_dist_func calc_bc_dist) + int calc_bc_dist) cdef yasm_dataval* yasm_dv_create_expr(yasm_expr *expn) cdef yasm_dataval* yasm_dv_create_string(char *contents, size_t len) @@ -117,8 +122,10 @@ cdef extern from "libyasm/bc-int.h": void (*destroy) (void *contents) void (*c_print "print") (void *contents, FILE *f, int indent_level) void (*finalize) (yasm_bytecode *bc, yasm_bytecode *prev_bc) - yasm_bc_resolve_flags (*resolve) (yasm_bytecode *bc, int save, - yasm_calc_bc_dist_func calc_bc_dist) + int (*calc_len) (yasm_bytecode *bc, yasm_bc_add_span_func add_span, + void *add_span_data) + int (*expand) (yasm_bytecode *bc, int span, long old_val, long new_val, + long *neg_thres, long *pos_thres) int (*tobytes) (yasm_bytecode *bc, unsigned char **bufp, void *d, yasm_output_value_func output_value, yasm_output_reloc_func output_reloc) diff --git a/tools/python-yasm/coretype.pxi b/tools/python-yasm/coretype.pxi index c0aabcad..6146b908 100644 --- a/tools/python-yasm/coretype.pxi +++ b/tools/python-yasm/coretype.pxi @@ -113,8 +113,6 @@ cdef extern from "libyasm/coretype.h": YASM_SYM_EXTERN YASM_SYM_DLOCAL - ctypedef yasm_intnum*(*yasm_calc_bc_dist_func)(yasm_bytecode *precbc1, - yasm_bytecode *precbc2) ctypedef int*(*yasm_output_value_func)(yasm_value *value, unsigned char *buf, size_t destsize, unsigned long offset, yasm_bytecode *bc, int warn, void *d) diff --git a/tools/python-yasm/expr.pxi b/tools/python-yasm/expr.pxi index 64b132d6..a33ce687 100644 --- a/tools/python-yasm/expr.pxi +++ b/tools/python-yasm/expr.pxi @@ -45,15 +45,13 @@ cdef extern from "libyasm/expr.h": cdef struct yasm__exprhead cdef yasm_expr *yasm_expr__level_tree(yasm_expr *e, int fold_const, - int simplify_ident, int simplify_reg_mul, - yasm_calc_bc_dist_func calc_bc_dist, + int simplify_ident, int simplify_reg_mul, int calc_bc_dist, yasm_expr_xform_func expr_xform_extra, void *expr_xform_extra_data, yasm__exprhead *eh, int *error) - cdef yasm_expr *yasm_expr_simplify(yasm_expr *e, yasm_calc_bc_dist_func cbd) + cdef yasm_expr *yasm_expr_simplify(yasm_expr *e, int calc_bc_dist) cdef yasm_expr *yasm_expr_extract_segoff(yasm_expr **ep) cdef yasm_expr *yasm_expr_extract_wrt(yasm_expr **ep) - cdef yasm_intnum *yasm_expr_get_intnum(yasm_expr **ep, - yasm_calc_bc_dist_func calc_bc_dist) + cdef yasm_intnum *yasm_expr_get_intnum(yasm_expr **ep, int calc_bc_dist) cdef yasm_symrec *yasm_expr_get_symrec(yasm_expr **ep, int simplify) cdef unsigned long *yasm_expr_get_reg(yasm_expr **ep, int simplify) cdef void yasm_expr_print(yasm_expr *e, FILE *f) @@ -179,8 +177,8 @@ cdef class Expression: def __dealloc__(self): if self.expr != NULL: yasm_expr_destroy(self.expr) - def simplify(self): - self.expr = yasm_expr_simplify(self.expr, NULL) # TODO: cbd + def simplify(self, calc_bc_dist=False): + self.expr = yasm_expr_simplify(self.expr, calc_bc_dist) def extract_segoff(self): cdef yasm_expr *retval @@ -196,9 +194,9 @@ cdef class Expression: raise ValueError("not a WRT expression") return __make_expression(retval) - def get_intnum(self): + def get_intnum(self, calc_bc_dist=False): cdef yasm_intnum *retval - retval = yasm_expr_get_intnum(&self.expr, NULL) # TODO: cbd + retval = yasm_expr_get_intnum(&self.expr, calc_bc_dist) if retval == NULL: raise ValueError("not an intnum expression") return __make_intnum(yasm_intnum_copy(retval)) diff --git a/tools/python-yasm/value.pxi b/tools/python-yasm/value.pxi index 81b1f2df..11fe0d84 100644 --- a/tools/python-yasm/value.pxi +++ b/tools/python-yasm/value.pxi @@ -33,8 +33,7 @@ cdef extern from "libyasm/value.h": cdef int yasm_value_finalize_expr(yasm_value *value, yasm_expr *e, unsigned int size) cdef int yasm_value_output_basic(yasm_value *value, unsigned char *buf, - size_t destsize, yasm_bytecode *bc, int warn, yasm_arch *arch, - yasm_calc_bc_dist_func calc_bc_dist) + size_t destsize, yasm_bytecode *bc, int warn, yasm_arch *arch) cdef void yasm_value_print(yasm_value *value, FILE *f, int indent_level) cdef class Value: