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"));
}
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;
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;
}
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) {
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"));
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 +=
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 +=
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)
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,
/* 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) {
/* 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) {
/* 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"));
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);
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);
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 &&
}
/*@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;
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;
}
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;
*/
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);
/**
/** 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
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,
* 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;
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;
/* 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)
{
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;
}
/*@-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);
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 ||
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);
* \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)
*/
/*@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);
* 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) \
/** 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)
}
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())
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 */
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;
}
/* 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"));
*/
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
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;
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? */
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);
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;
/* 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;
* 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;
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
*/
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;
/* 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;
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;
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);
/* 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,
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);
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"));
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"));
/* 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"));
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"));
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"));
}
/* 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"));
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:
}
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);
*/
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 */
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 =
/* 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:
/* 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"));
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"),
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:
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"));
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"));
}
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"));
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"));
}
} 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,
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"));
} 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"),
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:
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"));
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"),
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"));
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"));
/* 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"));
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,
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:
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"));
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"));
}
} 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,
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"),
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"),
} 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"),
}
/* 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) {
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);
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"));
* 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);
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");
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,
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'");
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'");
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`");
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,
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)
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)
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)
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)
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
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))
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: