(yasm_value_output_func): Remove valsize and shift parameters.
* bytecode.h (yasm_effaddr): Remove disp_len, replacing with
need_nonzero_len.
(yasm_immval): Remove len.
* value.h (yasm_value_initialize): Add size parameter.
(yasm_value_finalize_expr): Likewise.
(yasm_value_output_basic): Remove valsize and shift parameters.
Update all implementations and users for the above.
* intnum.c (yasm_intnum_calc): Fix bug in shift right (was doing a logical
instead of arithmetic shift).
* lc3b-basic.asm, lc3b-basic.errwarn, lc3b-basic.hex: Update based on
fixed warnings.
svn path=/trunk/yasm/; revision=1534
*/
const char *default_machine_keyword;
- /** Canonical "word" size in bytes.
+ /** Canonical "word" size in bits.
* Call yasm_arch_wordsize() to get the word size of a particular
* #yasm_arch.
*/
size_t valsize, int shift,
const yasm_bytecode *bc, int warn);
-/** Get the equivalent byte size of a register.
+/** Get the equivalent size of a register in bits.
* \param arch architecture
* \param reg register
* \return 0 if there is no suitable equivalent size, otherwise the size.
typedef struct bytecode_data {
/* converted data (linked list) */
yasm_datavalhead datahead;
-
- /* final (converted) size of each value element (in bytes) */
- unsigned int size;
} bytecode_data;
static void bc_data_destroy(void *contents);
case DV_EMPTY:
break;
case DV_VALUE:
- bc->len += bc_data->size;
+ bc->len += dv->data.val.size/8;
break;
case DV_RAW:
bc->len += dv->data.raw.len;
yasm_dataval *dv;
unsigned char *bufp_orig = *bufp;
yasm_intnum *intn;
+ unsigned int val_len;
STAILQ_FOREACH(dv, &bc_data->datahead, link) {
switch (dv->type) {
case DV_EMPTY:
break;
case DV_VALUE:
- if (output_value(&dv->data.val, *bufp, bc_data->size,
- (size_t)(bc_data->size*8), 0,
+ val_len = dv->data.val.size/8;
+ if (output_value(&dv->data.val, *bufp, val_len,
(unsigned long)(*bufp-bufp_orig), bc, 1, d))
return 1;
- *bufp += bc_data->size;
+ *bufp += val_len;
break;
case DV_RAW:
memcpy(*bufp, dv->data.raw.contents, dv->data.raw.len);
yasm_dvs_initialize(&data->datahead);
- data->size = size;
/* Prescan input data for length, etc. Careful: this needs to be
* precisely paired with the second loop.
} else {
dvo->type = dv->type;
dvo->data.val = dv->data.val; /* structure copy */
+ dvo->data.val.size = size*8; /* remember size */
dvo = STAILQ_NEXT(dvo, link);
len = 0;
}
yasm_dataval *retval = yasm_xmalloc(sizeof(yasm_dataval));
retval->type = DV_VALUE;
- yasm_value_initialize(&retval->data.val, e);
+ yasm_value_initialize(&retval->data.val, e, 0);
return retval;
}
bytecode_incbin *incbin = (bytecode_incbin *)bc->contents;
yasm_value val;
- if (yasm_value_finalize_expr(&val, incbin->start))
+ if (yasm_value_finalize_expr(&val, incbin->start, 0))
yasm_error_set(YASM_ERROR_TOO_COMPLEX,
N_("start expression too complex"));
else if (val.rel)
N_("start expression not absolute"));
incbin->start = val.abs;
- if (yasm_value_finalize_expr(&val, incbin->maxlen))
+ if (yasm_value_finalize_expr(&val, incbin->maxlen, 0))
yasm_error_set(YASM_ERROR_TOO_COMPLEX,
N_("maximum length expression too complex"));
else if (val.rel)
{
yasm_immval *im = yasm_xmalloc(sizeof(yasm_immval));
- if (yasm_value_finalize_expr(&im->val, e))
+ if (yasm_value_finalize_expr(&im->val, e, 0))
yasm_error_set(YASM_ERROR_TOO_COMPLEX,
N_("immediate expression too complex"));
- im->len = 0;
im->sign = 0;
return im;
* an explicit override, where we expect the user knows what they're doing.
*/
- ptr->disp_len = (unsigned char)len;
+ ptr->disp.size = (unsigned char)len;
}
void
{
fprintf(f, "%*sDisp:\n", indent_level, "");
yasm_value_print(&ea->disp, f, indent_level+1);
- fprintf(f, "%*sLen=%u\n", indent_level, "", (unsigned int)ea->disp_len);
fprintf(f, "%*sNoSplit=%u\n", indent_level, "", (unsigned int)ea->nosplit);
ea->callback->print(ea, f, indent_level);
}
bytecode_reserve *reserve = (bytecode_reserve *)bc->contents;
yasm_value val;
- if (yasm_value_finalize_expr(&val, reserve->numitems))
+ if (yasm_value_finalize_expr(&val, reserve->numitems, 0))
yasm_error_set(YASM_ERROR_TOO_COMPLEX,
N_("reserve expression too complex"));
else if (val.rel)
if (bc->multiple) {
yasm_value val;
- if (yasm_value_finalize_expr(&val, bc->multiple))
+ if (yasm_value_finalize_expr(&val, bc->multiple, 0))
yasm_error_set(YASM_ERROR_TOO_COMPLEX,
N_("multiple expression too complex"));
else if (val.rel)
unsigned long segreg; /**< segment register override (0 if none) */
- unsigned char disp_len; /**< length of disp (in bytes), 0 if unknown,
- * 0xff if unknown and required to be >0.
- */
+ unsigned char need_nonzero_len; /**< 1 if length of disp must be >0. */
unsigned char need_disp; /**< 1 if a displacement should be present
* in the output.
*/
typedef struct yasm_immval {
yasm_value val; /**< the immediate value itself */
- unsigned char len; /**< final length (in bytes), 0 if unknown */
unsigned char sign; /**< 1 if final imm is treated as signed */
} yasm_immval;
/*@observer@*/ const yasm_expr *yasm_ea_get_disp(const yasm_effaddr *ea);
/** Set the length of the displacement portion of an effective address.
- * The length is specified in bytes.
+ * The length is specified in bits.
* \param ea effective address
- * \param len length in bytes
+ * \param len length in bits
*/
void yasm_ea_set_len(yasm_effaddr *ea, unsigned int len);
* section start. Boolean.
*/
unsigned int section_rel : 1;
+
+ /** Size of the value, in bits. */
+ unsigned int size : 8;
} yasm_value;
/** Maximum value of #yasm_value.rshift */
* \param value value
* \param buf buffer for byte representation
* \param destsize destination size (in bytes)
- * \param valsize size (in bits)
- * \param shift left shift (in bits); may be negative to specify right
- * shift (standard warnings include truncation to boundary)
* \param offset offset (in bytes) of the expr contents from the start
* of the bytecode (needed for relative)
* \param bc current bytecode (usually passed into higher-level
*/
typedef int (*yasm_output_value_func)
(yasm_value *value, /*@out@*/ unsigned char *buf, size_t destsize,
- size_t valsize, int shift, unsigned long offset, yasm_bytecode *bc,
- int warn, /*@null@*/ void *d);
+ unsigned long offset, yasm_bytecode *bc, int warn, /*@null@*/ void *d);
/** Convert a symbol reference to its byte representation. Usually implemented
* by object formats and debug formats to keep track of relocations generated
{
boolean carry = 0;
wordptr op1, op2 = NULL;
+ N_int count;
/* Always do computations with in full bit vector.
* Bit vector results must be calculated through intermediate storage.
case YASM_EXPR_SHR:
if (operand->type == INTNUM_UL) {
BitVector_Copy(result, op1);
- BitVector_Move_Right(result, (N_int)operand->val.ul);
+ carry = BitVector_msb_(op1);
+ count = (N_int)operand->val.ul;
+ while (count-- > 0)
+ BitVector_shift_right(result, carry);
} else /* don't even bother, just zero result */
BitVector_Empty(result);
break;
}
int
-yasm_value_finalize_expr(yasm_value *value, yasm_expr *e)
+yasm_value_finalize_expr(yasm_value *value, yasm_expr *e, unsigned int size)
{
if (!e) {
- yasm_value_initialize(value, NULL);
+ yasm_value_initialize(value, NULL, size);
return 0;
}
yasm_value_initialize(value, yasm_expr__level_tree
- (e, 1, 1, 0, NULL, NULL, NULL, NULL));
+ (e, 1, 1, 0, NULL, NULL, NULL, NULL), size);
/* quit early if there was an issue in simplify() */
if (yasm_error_occurred())
return 0;
}
+int
+yasm_value_finalize(yasm_value *value)
+{
+ unsigned int valsize = value->size;
+ return yasm_value_finalize_expr(value, value->abs, valsize);
+}
+
int
yasm_value_output_basic(yasm_value *value, /*@out@*/ unsigned char *buf,
- size_t destsize, size_t valsize, int shift,
- yasm_bytecode *bc, int warn, yasm_arch *arch,
- yasm_calc_bc_dist_func calc_bc_dist)
+ unsigned int destsize, yasm_bytecode *bc, int warn,
+ yasm_arch *arch, yasm_calc_bc_dist_func calc_bc_dist)
{
/*@dependent@*/ /*@null@*/ yasm_intnum *intn = NULL;
/*@only@*/ yasm_intnum *outval;
int sym_local;
int retval = 1;
+ unsigned int valsize = value->size;
if (value->abs) {
/* Handle floating point expressions */
if (!value->rel && value->abs->op == YASM_EXPR_IDENT
&& value->abs->terms[0].type == YASM_EXPR_FLOAT) {
- if (shift < 0)
- yasm_internal_error(N_("attempting to negative shift a float"));
if (yasm_arch_floatnum_tobytes(arch, value->abs->terms[0].data.flt,
- buf, destsize, valsize,
- (unsigned int)shift, warn))
+ buf, destsize, valsize, 0, warn))
return -1;
else
return 1;
if (intn)
yasm_intnum_calc(outval, YASM_EXPR_ADD, intn);
/* Output! */
- if (yasm_arch_intnum_tobytes(arch, outval, buf, destsize, valsize,
- shift, bc, warn))
+ if (yasm_arch_intnum_tobytes(arch, outval, buf, destsize, valsize, 0,
+ bc, warn))
retval = -1;
yasm_intnum_destroy(outval);
} else if (intn) {
/* Output just absolute portion */
- if (yasm_arch_intnum_tobytes(arch, intn, buf, destsize, valsize,
- shift, bc, warn))
+ if (yasm_arch_intnum_tobytes(arch, intn, buf, destsize, valsize, 0, bc,
+ warn))
retval = -1;
} else {
/* No absolute or relative portions: output 0 */
outval = yasm_intnum_create_uint(0);
- if (yasm_arch_intnum_tobytes(arch, outval, buf, destsize, valsize,
- shift, bc, warn))
+ if (yasm_arch_intnum_tobytes(arch, outval, buf, destsize, valsize, 0,
+ bc, warn))
retval = -1;
yasm_intnum_destroy(outval);
}
* the value.
* \param value value to be initialized
* \param e expression (kept)
+ * \param size value size (in bits)
*/
void yasm_value_initialize(/*@out@*/ yasm_value *value,
- /*@null@*/ /*@kept@*/ yasm_expr *e);
+ /*@null@*/ /*@kept@*/ yasm_expr *e,
+ unsigned int size);
/** Initialize a #yasm_value with just a symrec. No processing is performed,
* the symrec is simply stuck into value.rel and the other fields are
* symrec offset within the absolute section.
* \param value value to store split portions into
* \param e expression input
+ * \param size value size (in bits)
* \return Nonzero if the expr could not be split into a value for some
* reason (e.g. the relative portion was not added, but multiplied,
* etc).
* before the parse is complete will usually result in an error return.
*/
int yasm_value_finalize_expr(/*@out@*/ yasm_value *value,
- /*@null@*/ /*@kept@*/ yasm_expr *e);
+ /*@null@*/ /*@kept@*/ yasm_expr *e,
+ unsigned int size);
/** Output value if constant or PC-relative section-local. This should be
* used from objfmt yasm_output_value_func() functions.
* \param value value
* \param buf buffer for byte representation
* \param destsize destination size (in bytes)
- * \param valsize size (in bits)
- * \param shift left shift (in bits); may be negative to specify right
- * shift (standard warnings include truncation to boundary)
* \param bc current bytecode (usually passed into higher-level
* calling function)
* \param warn enables standard warnings: zero for none;
*/
int yasm_value_output_basic
(yasm_value *value, /*@out@*/ unsigned char *buf, size_t destsize,
- size_t valsize, int shift, yasm_bytecode *bc, int warn, yasm_arch *arch,
+ yasm_bytecode *bc, int warn, yasm_arch *arch,
yasm_calc_bc_dist_func calc_bc_dist);
/** Print a value. For debugging purposes.
#ifndef YASM_DOXYGEN
-#define yasm_value_initialize(value, e) \
+#define yasm_value_initialize(value, e, sz) \
do { \
(value)->abs = e; \
(value)->rel = NULL; \
(value)->curpos_rel = 0; \
(value)->ip_rel = 0; \
(value)->section_rel = 0; \
+ (value)->size = sz; \
} while(0)
-#define yasm_value_init_sym(value, sym) \
+#define yasm_value_init_sym(value, sym, sz) \
do { \
(value)->abs = NULL; \
(value)->rel = sym; \
(value)->curpos_rel = 0; \
(value)->ip_rel = 0; \
(value)->section_rel = 0; \
+ (value)->size = sz; \
} while(0)
#define yasm_value_delete(value) \
(value)->abs = NULL; \
(value)->rel = NULL; \
} while(0)
-
-#define yasm_value_finalize(value) \
- yasm_value_finalize_expr(value, (value)->abs)
#endif
#endif
static unsigned int
lc3b_get_reg_size(/*@unused@*/ yasm_arch *arch, /*@unused@*/ unsigned long reg)
{
- return 2;
+ return 16;
}
static unsigned long
lc3b_ea_create_expr,
lc3b_machines,
"lc3b",
- 2,
+ 16,
2
};
case LC3B_IMM_NONE:
break;
case LC3B_IMM_4:
- if (output_value(&insn->imm, *bufp, 2, 4, 0, 0, bc, 1, d))
+ insn->imm.size = 4;
+ if (output_value(&insn->imm, *bufp, 2, 0, bc, 1, d))
return 1;
break;
case LC3B_IMM_5:
- if (output_value(&insn->imm, *bufp, 2, 5, 0, 0, bc, 1, d))
+ insn->imm.size = 5;
+ if (output_value(&insn->imm, *bufp, 2, 0, bc, -1, d))
return 1;
break;
case LC3B_IMM_6_WORD:
- if (output_value(&insn->imm, *bufp, 2, 6, -1, 0, bc, 1, d))
+ insn->imm.size = 6;
+ if (output_value(&insn->imm, *bufp, 2, 0, bc, 1, d))
return 1;
break;
case LC3B_IMM_6_BYTE:
- if (output_value(&insn->imm, *bufp, 2, 6, 0, 0, bc, 1, d))
+ insn->imm.size = 6;
+ if (output_value(&insn->imm, *bufp, 2, 0, bc, -1, d))
return 1;
break;
case LC3B_IMM_8:
- if (output_value(&insn->imm, *bufp, 2, 8, -1, 0, bc, 1, d))
+ insn->imm.size = 8;
+ if (output_value(&insn->imm, *bufp, 2, 0, bc, 1, d))
return 1;
break;
case LC3B_IMM_9_PC:
/* Adjust relative displacement to end of bytecode */
- delta = yasm_intnum_create_int(-(long)bc->len);
+ delta = yasm_intnum_create_int(-1);
if (!insn->imm.abs)
insn->imm.abs = yasm_expr_create_ident(yasm_expr_int(delta),
bc->line);
yasm_expr_expr(insn->imm.abs),
yasm_expr_int(delta), bc->line);
- if (output_value(&insn->imm, *bufp, 2, 9, -1, 0, bc, 1, d))
+ insn->imm.size = 9;
+ if (output_value(&insn->imm, *bufp, 2, 0, bc, -1, d))
return 1;
break;
case LC3B_IMM_9:
- if (output_value(&insn->imm, *bufp, 2, 9, -1, 0, bc, 1, d))
+ insn->imm.size = 9;
+ if (output_value(&insn->imm, *bufp, 2, 0, bc, 1, d))
return 1;
break;
default:
/* Copy what we can from info */
insn = yasm_xmalloc(sizeof(lc3b_insn));
- yasm_value_initialize(&insn->imm, NULL);
+ yasm_value_initialize(&insn->imm, NULL, 0);
insn->imm_type = LC3B_IMM_NONE;
insn->origin_prevbc = NULL;
insn->opcode = info->opcode;
if (operands) {
for(i = 0, op = yasm_ops_first(operands); op && i<info->num_operands;
op = yasm_operand_next(op), i++) {
+
switch ((int)(info->operands[i] & OPA_MASK)) {
case OPA_None:
/* Throw away the operand contents */
insn->opcode |= ((unsigned int)(op->data.reg & 0x7)) << 6;
break;
case OPA_Imm:
+ insn->imm_type = (info->operands[i] & OPI_MASK)>>3;
switch (op->type) {
case YASM_INSN__OPERAND_IMM:
+ if (insn->imm_type == LC3B_IMM_6_WORD
+ || insn->imm_type == LC3B_IMM_8
+ || insn->imm_type == LC3B_IMM_9
+ || insn->imm_type == LC3B_IMM_9_PC)
+ op->data.val = yasm_expr_create(YASM_EXPR_SHR,
+ yasm_expr_expr(op->data.val),
+ yasm_expr_int(yasm_intnum_create_uint(1)),
+ op->data.val->line);
if (yasm_value_finalize_expr(&insn->imm,
- op->data.val))
+ op->data.val, 0))
yasm_error_set(YASM_ERROR_TOO_COMPLEX,
N_("immediate expression too complex"));
break;
if (yasm_value_finalize_expr(&insn->imm,
yasm_expr_create_ident(yasm_expr_int(
yasm_intnum_create_uint(op->data.reg & 0x7)),
- bc->line)))
+ bc->line), 0))
yasm_internal_error(N_("reg expr too complex?"));
break;
default:
default:
yasm_internal_error(N_("unknown operand action"));
}
+ }
- insn->imm_type = (info->operands[i] & OPI_MASK)>>3;
- if (insn->imm_type == LC3B_IMM_9_PC) {
- insn->origin_prevbc = prev_bc;
- if (insn->imm.seg_of || insn->imm.rshift
- || insn->imm.curpos_rel)
- yasm_error_set(YASM_ERROR_VALUE,
- N_("invalid jump target"));
- insn->imm.curpos_rel = 1;
- }
+ if (insn->imm_type == LC3B_IMM_9_PC) {
+ insn->origin_prevbc = prev_bc;
+ if (insn->imm.seg_of || insn->imm.rshift > 1
+ || insn->imm.curpos_rel)
+ yasm_error_set(YASM_ERROR_VALUE, N_("invalid jump target"));
+ insn->imm.curpos_rel = 1;
}
}
add r4, r3, 22
label:
and r2, r1, r0
-and r2, r5, 22
+and r2, r5, 5
brz label
br label2
+-:2: warning: value does not fit in signed 5 bit field
18
40
54
-76
+65
55
fd
05
switch ((x86_expritem_reg_size)(reg & ~0xFUL)) {
case X86_REG8:
case X86_REG8X:
- return 1;
+ return 8;
case X86_REG16:
- return 2;
+ return 16;
case X86_REG32:
case X86_CRREG:
case X86_DRREG:
case X86_TRREG:
- return 4;
+ return 32;
case X86_REG64:
case X86_MMXREG:
- return 8;
+ return 64;
case X86_XMMREG:
- return 16;
+ return 128;
case X86_FPUREG:
- return 10;
+ return 80;
default:
yasm_error_set(YASM_ERROR_VALUE, N_("unknown register size"));
}
yasm_x86__ea_create_expr,
x86_machines,
"x86",
- 2,
+ 16,
1
};
x86_ea = yasm_xmalloc(sizeof(x86_effaddr));
x86_ea->ea.callback = &x86_ea_callback;
- yasm_value_initialize(&x86_ea->ea.disp, NULL);
- x86_ea->ea.disp_len = 0;
+ yasm_value_initialize(&x86_ea->ea.disp, NULL, 0);
+ x86_ea->ea.need_nonzero_len = 0;
x86_ea->ea.need_disp = 0;
x86_ea->ea.nosplit = 0;
x86_ea->ea.strong = 0;
yasm_expr_reg(X86_RIP), e->line);
}
}
- yasm_value_initialize(&x86_ea->ea.disp, e);
- x86_ea->ea.disp_len = 0;
+ yasm_value_initialize(&x86_ea->ea.disp, e, 0);
+ x86_ea->ea.need_nonzero_len = 0;
x86_ea->ea.need_disp = 1;
x86_ea->ea.nosplit = 0;
x86_ea->ea.strong = 0;
x86_ea = yasm_xmalloc(sizeof(x86_effaddr));
x86_ea->ea.callback = &x86_ea_callback;
- yasm_value_initialize(&x86_ea->ea.disp, imm);
- x86_ea->ea.disp_len = (unsigned char)im_len;
+ yasm_value_initialize(&x86_ea->ea.disp, imm, im_len);
x86_ea->ea.need_disp = 1;
x86_ea->ea.nosplit = 0;
x86_ea->ea.strong = 0;
indent_level++;
fprintf(f, "\n");
yasm_value_print(&insn->imm->val, f, indent_level);
- fprintf(f, "%*sLen=%u, Sign=%u\n", indent_level, "",
- (unsigned int)insn->imm->len,
+ fprintf(f, "%*sSign=%u\n", indent_level, "",
(unsigned int)insn->imm->sign);
indent_level--;
}
break;
}
- if (eat.ea.disp_len != 1) {
+ if (eat.ea.disp.size != 8) {
/* Fits into a word/dword, or unknown. */
retval = YASM_BC_RESOLVE_NONE; /* may not be smallest size */
/* Handle unknown case, make displen word-sized */
- if (eat.ea.disp_len == 0xff)
- eat.ea.disp_len = (insn->common.addrsize == 16) ? 2U : 4U;
+ if (eat.ea.need_nonzero_len)
+ eat.ea.disp.size = (insn->common.addrsize == 16) ? 16 : 32;
}
/* Handle address16 postop case */
insn->common.addrsize = 0;
/* If we had forced ea->len but had to override, save it now */
- if (x86_ea->ea.disp_len != 0 && x86_ea->ea.disp_len != eat.ea.disp_len)
- x86_ea->ea.disp_len = eat.ea.disp_len;
+ if (x86_ea->ea.disp.size != 0 &&
+ x86_ea->ea.disp.size != eat.ea.disp.size)
+ x86_ea->ea.disp.size = eat.ea.disp.size;
if (save) {
eat.ea.disp.abs = x86_ea->ea.disp.abs; /* Copy back original */
*x86_ea = eat; /* structure copy */
- if (x86_ea->ea.disp_len == 0) {
+ if (x86_ea->ea.disp.size == 0) {
yasm_value_delete(&x86_ea->ea.disp);
x86_ea->ea.need_disp = 0;
}
}
/* Compute length of ea and add to total */
- bc->len += eat.need_modrm + (eat.need_sib ? 1:0) + eat.ea.disp_len;
+ bc->len += eat.need_modrm + (eat.need_sib ? 1:0) + eat.ea.disp.size/8;
bc->len += (eat.ea.segreg != 0) ? 1 : 0;
}
if (imm) {
/*@null@*/ yasm_expr *temp = NULL;
const yasm_intnum *num = NULL;
- unsigned int immlen = imm->len;
+ unsigned int immlen = imm->val.size;
long val;
if (imm->val.abs) {
/* We can use the sign-extended byte form: shorten
* the immediate length to 1.
*/
- immlen = 1;
+ immlen = 8;
if (save) {
/* Make the byte form permanent. */
insn->opcode.opcode[0] = insn->opcode.opcode[1];
- imm->len = 1;
+ imm->val.size = 8;
if (insn->opcode.opcode[2] != 0) {
insn->opcode.opcode[1] = insn->opcode.opcode[2];
insn->opcode.len++;
/* Handle signext_imm32 postop special-casing */
if (!num || yasm_intnum_check_size(num, 32, 0, 1)) {
bc->len++; /* Due to ModRM byte */
- immlen = 4;
+ immlen = 32;
if (save) {
/* Throwaway REX byte */
unsigned char rex_temp = 0;
/* Make the imm32s form permanent. */
insn->opcode.opcode[0] = insn->opcode.opcode[1];
- imm->len = 4;
+ imm->val.size = 32;
}
}
/* Not really necessary, but saves confusion over it. */
yasm_expr_destroy(temp);
- bc->len += immlen;
+ bc->len += immlen/8;
}
bc->len += insn->opcode.len;
if (x86_ea->ea.need_disp) {
x86_effaddr eat = *x86_ea; /* structure copy */
unsigned char addrsize = insn->common.addrsize;
+ unsigned int disp_len = x86_ea->ea.disp.size/8;
eat.valid_modrm = 0; /* force checkea to actually run */
yasm_expr_expr(x86_ea->ea.disp.abs),
yasm_expr_int(delta), bc->line);
}
- if (output_value(&x86_ea->ea.disp, *bufp, x86_ea->ea.disp_len,
- (size_t)(x86_ea->ea.disp_len*8), 0,
+ if (output_value(&x86_ea->ea.disp, *bufp, disp_len,
(unsigned long)(*bufp-bufp_orig), bc, 1, d))
return 1;
- *bufp += x86_ea->ea.disp_len;
+ *bufp += disp_len;
}
}
/* Immediate (if required) */
if (imm) {
- if (output_value(&imm->val, *bufp, imm->len, (size_t)(imm->len*8), 0,
+ unsigned int imm_len = imm->val.size/8;
+ if (output_value(&imm->val, *bufp, imm_len,
(unsigned long)(*bufp-bufp_orig), bc, imm->sign?-1:1,
d))
return 1;
- *bufp += imm->len;
+ *bufp += imm_len;
}
return 0;
yasm_expr_expr(jmp->target.abs),
yasm_expr_int(delta), bc->line);
- if (output_value(&jmp->target, *bufp, 1, 8, 0,
+ jmp->target.size = 8;
+ if (output_value(&jmp->target, *bufp, 1,
(unsigned long)(*bufp-bufp_orig), bc, -1, d))
return 1;
*bufp += 1;
yasm_expr_expr(jmp->target.abs),
yasm_expr_int(delta), bc->line);
- if (output_value(&jmp->target, *bufp, i, i*8, 0,
+ jmp->target.size = i*8;
+ if (output_value(&jmp->target, *bufp, i,
(unsigned long)(*bufp-bufp_orig), bc, -1, d))
return 1;
*bufp += i;
/* Absolute displacement: segment and offset */
i = (opersize == 16) ? 2 : 4;
- if (output_value(&jmpfar->offset, *bufp, i, i*8, 0,
+ jmpfar->offset.size = i*8;
+ if (output_value(&jmpfar->offset, *bufp, i,
(unsigned long)(*bufp-bufp_orig), bc, 1, d))
return 1;
*bufp += i;
- if (output_value(&jmpfar->segment, *bufp, 2, 2*8, 0,
+ jmpfar->segment.size = 16;
+ if (output_value(&jmpfar->segment, *bufp, 2,
(unsigned long)(*bufp-bufp_orig), bc, 1, d))
return 1;
*bufp += 2;
/* Calculate the displacement length, if possible.
* Takes several extra inputs so it can be used by both 32-bit and 16-bit
* expressions:
- * wordsize=2 for 16-bit, =4 for 32-bit.
+ * wordsize=16 for 16-bit, =32 for 32-bit.
* noreg=1 if the *ModRM byte* has no registers used.
* dispreq=1 if a displacement value is *required* (even if =0).
* Returns 0 if successfully calculated, 1 if not.
x86_ea->valid_modrm = 0; /* default to not yet valid */
- switch (x86_ea->ea.disp_len) {
+ switch (x86_ea->ea.disp.size) {
case 0:
break;
/* If not 0, the displacement length was forced; set the Mod bits
* appropriately and we're done with the ModRM byte.
*/
- case 1:
+ case 8:
/* Byte is not valid override in noreg case; fix it. */
if (noreg) {
- x86_ea->ea.disp_len = 0;
+ x86_ea->ea.disp.size = 0;
yasm_warn_set(YASM_WARN_GENERAL,
N_("invalid displacement size; fixed"));
} else
x86_ea->modrm |= 0100;
x86_ea->valid_modrm = 1;
break;
- case 2:
- case 4:
- if (wordsize != x86_ea->ea.disp_len) {
+ case 16:
+ case 32:
+ if (wordsize != x86_ea->ea.disp.size) {
yasm_error_set(YASM_ERROR_VALUE,
N_("invalid effective address (displacement size)"));
return 1;
}
/* 2/4 is not valid override in noreg case; fix it. */
if (noreg) {
- if (wordsize != x86_ea->ea.disp_len)
+ if (wordsize != x86_ea->ea.disp.size)
yasm_warn_set(YASM_WARN_GENERAL,
N_("invalid displacement size; fixed"));
- x86_ea->ea.disp_len = 0;
+ x86_ea->ea.disp.size = 0;
} else
x86_ea->modrm |= 0200;
x86_ea->valid_modrm = 1;
yasm_internal_error(N_("strange EA displacement size"));
}
- if (x86_ea->ea.disp_len == 0) {
+ if (x86_ea->ea.disp.size == 0) {
/* the displacement length hasn't been forced (or the forcing wasn't
* valid), try to determine what it is.
*/
* and as the Mod bits are set to 0 by the caller, we're done
* with the ModRM byte.
*/
- x86_ea->ea.disp_len = wordsize;
+ x86_ea->ea.disp.size = wordsize;
x86_ea->valid_modrm = 1;
return 0;
} else if (dispreq) {
/* for BP/EBP, there *must* be a displacement value, but we
* may not know the size (8 or 16/32) for sure right now.
- * We can't leave displen at 0, because that just means
- * unknown displacement, including none.
*/
- x86_ea->ea.disp_len = 0xff;
+ x86_ea->ea.need_nonzero_len = 1;
}
if (x86_ea->ea.disp.rel ||
/* expr still has unknown values or is relative:
* assume 16/32-bit disp
*/
- x86_ea->ea.disp_len = wordsize;
+ x86_ea->ea.disp.size = wordsize;
x86_ea->modrm |= 0200;
x86_ea->valid_modrm = 1;
return 0;
/* don't try to find out what size displacement we have if
* displen is known.
*/
- if (x86_ea->ea.disp_len != 0 && x86_ea->ea.disp_len != 0xff) {
- if (x86_ea->ea.disp_len == 1)
+ if (x86_ea->ea.disp.size != 0) {
+ if (x86_ea->ea.disp.size == 8)
x86_ea->modrm |= 0100;
else
x86_ea->modrm |= 0200;
dispval = 0;
/* Figure out what size displacement we will have. */
- if (x86_ea->ea.disp_len != 0xff && dispval == 0) {
+ if (!x86_ea->ea.need_nonzero_len && dispval == 0) {
/* if we know that the displacement is 0 right now,
* go ahead and delete the expr and make it so no
* displacement value is included in the output.
x86_ea->ea.need_disp = 0;
} else if (dispval >= -128 && dispval <= 127) {
/* It fits into a signed byte */
- x86_ea->ea.disp_len = 1;
+ x86_ea->ea.disp.size = 8;
x86_ea->modrm |= 0100;
} else {
/* It's a 16/32-bit displacement */
- x86_ea->ea.disp_len = wordsize;
+ x86_ea->ea.disp.size = wordsize;
x86_ea->modrm |= 0200;
}
x86_ea->valid_modrm = 1; /* We're done with ModRM */
* - what registers are used in the expression
* - the bits setting
*/
- switch (x86_ea->ea.disp_len) {
- case 2:
+ switch (x86_ea->ea.disp.size) {
+ case 16:
/* must be 16-bit */
*addrsize = 16;
break;
- case 8:
+ case 64:
/* We have to support this for the MemOffs case, but it's
* otherwise illegal. It's also illegal in non-64-bit mode.
*/
}
*addrsize = 64;
break;
- case 4:
+ case 32:
/* Must be 32-bit in 16-bit or 32-bit modes. In 64-bit mode,
* we don't know unless we look at the registers, except in the
* MemOffs case (see the end of this function).
x86_ea->need_sib = 0;
/* RIP always requires a 32-bit displacement */
x86_ea->valid_modrm = 1;
- x86_ea->ea.disp_len = 4;
+ x86_ea->ea.disp.size = 32;
return 0;
} else if (indexreg == REG3264_NONE) {
/* basereg only */
/* Calculate displacement length (if possible) */
retval = x86_checkea_calc_displen
- (x86_ea, 4, basereg == REG3264_NONE,
+ (x86_ea, 32, basereg == REG3264_NONE,
basereg == REG3264_EBP || basereg == REG64_R13);
return retval;
} else if (*addrsize == 16 && x86_ea->need_modrm && !x86_ea->valid_modrm) {
/* Calculate displacement length (if possible) */
retval = x86_checkea_calc_displen
- (x86_ea, 2, havereg == HAVE_NONE, havereg == HAVE_BP);
+ (x86_ea, 16, havereg == HAVE_NONE, havereg == HAVE_BP);
return retval;
} else if (!x86_ea->need_modrm && !x86_ea->need_sib) {
/* Special case for MOV MemOffs opcode: displacement but no modrm. */
N_("invalid effective address (64-bit in non-64-bit mode)"));
return 1;
}
- x86_ea->ea.disp_len = 8;
+ x86_ea->ea.disp.size = 64;
break;
case 32:
- x86_ea->ea.disp_len = 4;
+ x86_ea->ea.disp.size = 32;
break;
case 16:
/* 64-bit mode does not allow 16-bit addresses */
N_("16-bit addresses not supported in 64-bit mode"));
return 1;
}
- x86_ea->ea.disp_len = 2;
+ x86_ea->ea.disp.size = 16;
break;
}
}
case X86_FAR:
/* "FAR imm" target needs to become "seg imm:imm". */
if (yasm_value_finalize_expr(&jmpfar->offset,
- yasm_expr_copy(op->data.val))
- || yasm_value_finalize_expr(&jmpfar->segment, op->data.val))
+ yasm_expr_copy(op->data.val), 0)
+ || yasm_value_finalize_expr(&jmpfar->segment, op->data.val, 16))
yasm_error_set(YASM_ERROR_TOO_COMPLEX,
N_("jump target expression too complex"));
jmpfar->segment.seg_of = 1;
segment = yasm_expr_extract_segoff(&op->data.val);
if (!segment)
yasm_internal_error(N_("didn't get SEG:OFF expression in jmpfar"));
- if (yasm_value_finalize_expr(&jmpfar->segment, segment))
+ if (yasm_value_finalize_expr(&jmpfar->segment, segment, 16))
yasm_error_set(YASM_ERROR_TOO_COMPLEX,
N_("jump target segment too complex"));
- if (yasm_value_finalize_expr(&jmpfar->offset, op->data.val))
+ if (yasm_value_finalize_expr(&jmpfar->offset, op->data.val, 0))
yasm_error_set(YASM_ERROR_TOO_COMPLEX,
N_("jump target offset too complex"));
break;
jmp = yasm_xmalloc(sizeof(x86_jmp));
x86_finalize_common(&jmp->common, jinfo, mode_bits);
- if (yasm_value_finalize_expr(&jmp->target, op->data.val))
+ if (yasm_value_finalize_expr(&jmp->target, op->data.val, 0))
yasm_error_set(YASM_ERROR_TOO_COMPLEX,
N_("jump target expression too complex"));
if (jmp->target.seg_of || jmp->target.rshift || jmp->target.curpos_rel)
unsigned char im_sign;
unsigned char spare;
int i;
- unsigned int size_lookup[] = {0, 1, 2, 4, 8, 10, 16, 0};
+ unsigned int size_lookup[] = {0, 8, 16, 32, 64, 80, 128, 0};
- size_lookup[7] = mode_bits>>3;
+ size_lookup[7] = mode_bits;
if (!info) {
num_info = 1;
/* Check for 64-bit effective address size in NASM mode */
if (suffix == 0 && op->type == YASM_INSN__OPERAND_MEMORY) {
if ((info->operands[i] & OPEAS_MASK) == OPEAS_64) {
- if (op->data.ea->disp_len != 8)
+ if (op->data.ea->disp.size != 64)
mismatch = 1;
- } else if (op->data.ea->disp_len == 8)
+ } else if (op->data.ea->disp.size == 64)
mismatch = 1;
}
if (info->modifiers & MOD_Imm8) {
imm = yasm_expr_create_ident(yasm_expr_int(
yasm_intnum_create_uint(mod_data & 0xFF)), bc->line);
- im_len = 1;
+ im_len = 8;
mod_data >>= 8;
}
if (info->modifiers & MOD_DOpS64R) {
}
if (imm) {
insn->imm = yasm_imm_create_expr(imm);
- insn->imm->len = im_len;
+ insn->imm->val.size = im_len;
insn->imm->sign = im_sign;
} else
insn->imm = NULL;
yasm_value val;
/* sym in its section */
- yasm_value_init_sym(&val, sym);
+ yasm_value_init_sym(&val, sym, 32);
val.section_rel = 1;
- output_value(&val, *bufp, 4, 32, 0, off, bc, 0, d);
+ output_value(&val, *bufp, 4, off, bc, 0, d);
*bufp += 4;
/* section index */
- yasm_value_init_sym(&val, sym);
+ yasm_value_init_sym(&val, sym, 16);
val.seg_of = 1;
- output_value(&val, *bufp, 2, 16, 0, off+4, bc, 0, d);
+ output_value(&val, *bufp, 2, off+4, bc, 0, d);
*bufp += 2;
}
yasm_value value;
yasm_value_init_sym(&value,
yasm_dwarf2__bc_sym(dbgfmt_dwarf2->symtab,
- yasm_section_bcs_first(head->debug_ptr)));
+ yasm_section_bcs_first(head->debug_ptr)),
+ dbgfmt_dwarf2->sizeof_offset*8);
output_value(&value, buf, dbgfmt_dwarf2->sizeof_offset,
- dbgfmt_dwarf2->sizeof_offset*8, 0,
(unsigned long)(buf-*bufp), bc, 0, d);
buf += dbgfmt_dwarf2->sizeof_offset;
}
YASM_WRITE_8(buf, line_op->ext_opcode);
if (line_op->ext_operand) {
yasm_value value;
- yasm_value_init_sym(&value, line_op->ext_operand);
+ yasm_value_init_sym(&value, line_op->ext_operand,
+ line_op->ext_operandsize*8);
output_value(&value, buf, line_op->ext_operandsize,
- line_op->ext_operandsize*8, 0,
(unsigned long)(buf-*bufp), bc, 0, d);
buf += line_op->ext_operandsize;
}
static int
nasm_listfmt_output_value(yasm_value *value, unsigned char *buf,
- size_t destsize, size_t valsize, int shift,
- unsigned long offset, yasm_bytecode *bc, int warn,
- /*@null@*/ void *d)
+ size_t destsize, unsigned long offset,
+ yasm_bytecode *bc, int warn, /*@null@*/ void *d)
{
/*@null@*/ nasm_listfmt_output_info *info = (nasm_listfmt_output_info *)d;
/*@dependent@*/ /*@null@*/ yasm_intnum *intn;
+ unsigned int valsize = value->size;
assert(info != NULL);
/* Output */
- switch (yasm_value_output_basic(value, buf, destsize, valsize, shift, bc,
- warn, info->arch, NULL)) {
+ switch (yasm_value_output_basic(value, buf, destsize, bc, warn, info->arch,
+ NULL)) {
case -1:
return 1;
case 0:
intn = yasm_expr_get_intnum(&value->abs, NULL);
if (intn)
return yasm_arch_intnum_tobytes(info->arch, intn, buf, destsize,
- valsize, shift, bc, 0);
+ valsize, 0, bc, 0);
else {
yasm_error_set(YASM_ERROR_TOO_COMPLEX,
N_("relocation too complex"));
int retval;
intn = yasm_intnum_create_uint(0);
retval = yasm_arch_intnum_tobytes(info->arch, intn, buf, destsize,
- valsize, shift, bc, 0);
+ valsize, 0, bc, 0);
yasm_intnum_destroy(intn);
return retval;
}
static int
bin_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize,
- size_t valsize, int shift,
/*@unused@*/ unsigned long offset, yasm_bytecode *bc,
int warn, /*@null@*/ void *d)
{
(value->abs, 1, 1, 1, NULL, bin_objfmt_expr_xform, NULL, NULL);
/* Output */
- switch (yasm_value_output_basic(value, buf, destsize, valsize, shift,
- bc, warn, info->objfmt_bin->arch, NULL)) {
+ switch (yasm_value_output_basic(value, buf, destsize, bc, warn,
+ info->objfmt_bin->arch, NULL)) {
case -1:
return 1;
case 0:
static int
coff_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize,
- size_t valsize, int shift, unsigned long offset,
- yasm_bytecode *bc, int warn, /*@null@*/ void *d)
+ unsigned long offset, yasm_bytecode *bc, int warn,
+ /*@null@*/ void *d)
{
/*@null@*/ coff_objfmt_output_info *info = (coff_objfmt_output_info *)d;
yasm_objfmt_coff *objfmt_coff;
/*@dependent@*/ /*@null@*/ yasm_intnum *intn;
unsigned long intn_val, intn_minus;
int retval;
+ unsigned int valsize = value->size;
assert(info != NULL);
objfmt_coff = info->objfmt_coff;
* 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, valsize, shift, bc,
- warn, info->objfmt_coff->arch,
+ switch (yasm_value_output_basic(value, buf, destsize, bc, warn,
+ info->objfmt_coff->arch,
yasm_common_calc_bc_dist)) {
case -1:
return 1;
}
retval = yasm_arch_intnum_tobytes(objfmt_coff->arch, intn, buf, destsize,
- valsize, shift, bc, warn);
+ valsize, 0, bc, warn);
yasm_intnum_destroy(intn);
return retval;
}
static int
elf_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize,
- size_t valsize, int shift, unsigned long offset,
- yasm_bytecode *bc, int warn, /*@null@*/ void *d)
+ unsigned long offset, yasm_bytecode *bc, int warn,
+ /*@null@*/ void *d)
{
/*@null@*/ elf_objfmt_output_info *info = (elf_objfmt_output_info *)d;
/*@dependent@*/ /*@null@*/ yasm_intnum *intn;
unsigned long intn_val;
/*@null@*/ elf_reloc_entry *reloc = NULL;
int retval;
+ unsigned int valsize = value->size;
if (info == NULL)
yasm_internal_error("null info struct");
* 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, valsize, shift, bc,
- warn, info->objfmt_elf->arch,
+ switch (yasm_value_output_basic(value, buf, destsize, bc, warn,
+ info->objfmt_elf->arch,
yasm_common_calc_bc_dist)) {
case -1:
return 1;
if (reloc)
elf_handle_reloc_addend(intn, reloc);
retval = yasm_arch_intnum_tobytes(info->objfmt_elf->arch, intn, buf,
- destsize, valsize, shift, bc, warn);
+ destsize, valsize, 0, bc, warn);
yasm_intnum_destroy(intn);
return retval;
}
static int
xdf_objfmt_output_value(yasm_value *value, unsigned char *buf, size_t destsize,
- size_t valsize, int shift, unsigned long offset,
- yasm_bytecode *bc, int warn, /*@null@*/ void *d)
+ unsigned long offset, yasm_bytecode *bc, int warn,
+ /*@null@*/ void *d)
{
/*@null@*/ xdf_objfmt_output_info *info = (xdf_objfmt_output_info *)d;
yasm_objfmt_xdf *objfmt_xdf;
/*@dependent@*/ /*@null@*/ yasm_intnum *intn;
unsigned long intn_minus;
int retval;
+ unsigned int valsize = value->size;
assert(info != NULL);
objfmt_xdf = info->objfmt_xdf;
* 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, valsize, shift, bc,
- warn, info->objfmt_xdf->arch,
+ switch (yasm_value_output_basic(value, buf, destsize, bc, warn,
+ info->objfmt_xdf->arch,
yasm_common_calc_bc_dist)) {
case -1:
return 1;
}
retval = yasm_arch_intnum_tobytes(objfmt_xdf->arch, intn, buf, destsize,
- valsize, shift, bc, warn);
+ valsize, 0, bc, warn);
yasm_intnum_destroy(intn);
return retval;
}
$$ = yasm_bc_create_data(&$2, 2, 0, parser_gas->arch, cur_line);
}
| DIR_WORD datavals {
- $$ = yasm_bc_create_data(&$2, yasm_arch_wordsize(parser_gas->arch), 0,
+ $$ = yasm_bc_create_data(&$2, yasm_arch_wordsize(parser_gas->arch)/8, 0,
parser_gas->arch, cur_line);
}
| DIR_INT datavals {
exp: instr
| DECLARE_DATA datavals {
- $$ = yasm_bc_create_data(&$2, $1, 0, parser_nasm->arch, cur_line);
+ $$ = yasm_bc_create_data(&$2, $1/8, 0, parser_nasm->arch, cur_line);
}
| RESERVE_SPACE expr {
- $$ = yasm_bc_create_reserve($2, $1, cur_line);
+ $$ = yasm_bc_create_reserve($2, $1/8, cur_line);
}
| INCBIN STRING {
$$ = yasm_bc_create_incbin($2.contents, NULL, NULL, cur_line);
}
/* size specifiers */
- 'byte' { lvalp->int_info = 1; RETURN(SIZE_OVERRIDE); }
+ 'byte' { lvalp->int_info = 8; RETURN(SIZE_OVERRIDE); }
'hword' {
lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)/2;
RETURN(SIZE_OVERRIDE);
lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*4;
RETURN(SIZE_OVERRIDE);
}
- 'tword' { lvalp->int_info = 10; RETURN(SIZE_OVERRIDE); }
+ 'tword' { lvalp->int_info = 80; RETURN(SIZE_OVERRIDE); }
'dqword' {
lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*8;
RETURN(SIZE_OVERRIDE);
}
/* pseudo-instructions */
- 'db' { lvalp->int_info = 1; RETURN(DECLARE_DATA); }
+ 'db' { lvalp->int_info = 8; RETURN(DECLARE_DATA); }
'dhw' {
lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)/2;
RETURN(DECLARE_DATA);
lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*4;
RETURN(DECLARE_DATA);
}
- 'dt' { lvalp->int_info = 10; RETURN(DECLARE_DATA); }
+ 'dt' { lvalp->int_info = 80; RETURN(DECLARE_DATA); }
'ddq' {
lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*8;
RETURN(DECLARE_DATA);
}
- 'resb' { lvalp->int_info = 1; RETURN(RESERVE_SPACE); }
+ 'resb' { lvalp->int_info = 8; RETURN(RESERVE_SPACE); }
'reshw' {
lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)/2;
RETURN(RESERVE_SPACE);
lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*4;
RETURN(RESERVE_SPACE);
}
- 'rest' { lvalp->int_info = 10; RETURN(RESERVE_SPACE); }
+ 'rest' { lvalp->int_info = 80; RETURN(RESERVE_SPACE); }
'resdq' {
lvalp->int_info = yasm_arch_wordsize(parser_nasm->arch)*8;
RETURN(RESERVE_SPACE);
unsigned int curpos_rel
unsigned int ip_rel
unsigned int section_rel
+ unsigned int size
cdef struct yasm_linemap
cdef struct yasm_valparam
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, size_t valsize, int shift, unsigned
- long offset, yasm_bytecode *bc, int warn, void *d)
+ *buf, size_t destsize, unsigned long offset, yasm_bytecode *bc,
+ int warn, void *d)
ctypedef int(*yasm_output_reloc_func)(yasm_symrec *sym,
yasm_bytecode *bc, unsigned char *buf, size_t destsize,
size_t valsize, int warn, void *d)
# POSSIBILITY OF SUCH DAMAGE.
cdef extern from "libyasm/value.h":
- cdef void yasm_value_initialize(yasm_value *value, yasm_expr *e)
- cdef void yasm_value_init_sym(yasm_value *value, yasm_symrec *sym)
+ cdef void yasm_value_initialize(yasm_value *value, yasm_expr *e,
+ unsigned int size)
+ cdef void yasm_value_init_sym(yasm_value *value, yasm_symrec *sym,
+ unsigned int size)
cdef void yasm_value_delete(yasm_value *value)
cdef int yasm_value_finalize(yasm_value *value)
- cdef int yasm_value_finalize_expr(yasm_value *value, yasm_expr *e)
+ 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, size_t valsize, int shift, 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,
+ yasm_calc_bc_dist_func calc_bc_dist)
cdef void yasm_value_print(yasm_value *value, FILE *f, int indent_level)
cdef class Value:
cdef yasm_value value
- def __new__(self, value=None):
- yasm_value_initialize(&self.value, NULL)
+ def __new__(self, value=None, size=None):
+ cdef unsigned int sz
+ if size is None:
+ sz = 0
+ else:
+ sz = size;
+
+ yasm_value_initialize(&self.value, NULL, sz)
if value is None:
pass
elif isinstance(value, Expression):
yasm_value_initialize(&self.value,
- yasm_expr_copy((<Expression>value).expr))
+ yasm_expr_copy((<Expression>value).expr), sz)
elif isinstance(value, Symbol):
- yasm_value_init_sym(&self.value, (<Symbol>value).sym)
+ yasm_value_init_sym(&self.value, (<Symbol>value).sym, sz)
else:
raise ValueError("Invalid value type '%s'" % type(value))