diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/python-yasm/bytecode.pxi | 17 | ||||
-rw-r--r-- | tools/python-yasm/value.pxi | 15 |
2 files changed, 22 insertions, 10 deletions
diff --git a/tools/python-yasm/bytecode.pxi b/tools/python-yasm/bytecode.pxi index 913a4081..50c72ae7 100644 --- a/tools/python-yasm/bytecode.pxi +++ b/tools/python-yasm/bytecode.pxi @@ -47,7 +47,7 @@ cdef extern from "libyasm/bytecode.h": cdef struct yasm_dataval cdef struct yasm_datavalhead - cdef yasm_immval* yasm_imm_create_expr(yasm_expr *e) + cdef yasm_immval* yasm_imm_create_expr(yasm_expr *e, yasm_bytecode *precbc) cdef yasm_expr* yasm_ea_get_disp(yasm_effaddr *ea) cdef void yasm_ea_set_len(yasm_effaddr *ea, unsigned int len) cdef void yasm_ea_set_nosplit(yasm_effaddr *ea, unsigned int nosplit) @@ -159,14 +159,21 @@ cdef object __make_immval(yasm_immval *imm): cdef class ImmVal: cdef yasm_immval *imm - def __new__(self, value): + def __new__(self, value, precbc=None): if isinstance(value, Expression): - self.imm = yasm_imm_create_expr( - yasm_expr_copy((<Expression>value).expr)) + if precbc is None: + self.imm = yasm_imm_create_expr( + yasm_expr_copy((<Expression>value).expr), NULL) + elif isinstance(precbc, Bytecode): + self.imm = yasm_imm_create_expr( + yasm_expr_copy((<Expression>value).expr), + (<Bytecode>precbc).bc) + else: + raise TypeError("Invalid precbc type '%s'" % type(precbc)) elif PyCObject_Check(value): self.imm = <yasm_immval *>__get_voidp(value, ImmVal) else: - raise TypeError + raise TypeError("Invalid value type '%s'" % type(value)) cdef class Bytecode: cdef yasm_bytecode *bc diff --git a/tools/python-yasm/value.pxi b/tools/python-yasm/value.pxi index 2e89c0f7..98ba14ea 100644 --- a/tools/python-yasm/value.pxi +++ b/tools/python-yasm/value.pxi @@ -29,9 +29,9 @@ cdef extern from "libyasm/value.h": 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(yasm_value *value, yasm_bytecode *precbc) cdef int yasm_value_finalize_expr(yasm_value *value, yasm_expr *e, - unsigned int size) + yasm_bytecode *precbc, unsigned int size) cdef yasm_intnum *yasm_value_get_intnum(yasm_value *value, yasm_bytecode *bc) cdef int yasm_value_output_basic(yasm_value *value, unsigned char *buf, @@ -56,11 +56,16 @@ cdef class Value: elif isinstance(value, Symbol): yasm_value_init_sym(&self.value, (<Symbol>value).sym, sz) else: - raise ValueError("Invalid value type '%s'" % type(value)) + raise TypeError("Invalid value type '%s'" % type(value)) def __dealloc__(self): yasm_value_delete(&self.value) - def finalize(self): - return yasm_value_finalize(&self.value) + def finalize(self, precbc=None): + if precbc is None: + return yasm_value_finalize(&self.value, NULL) + elif isinstance(precbc, Bytecode): + return yasm_value_finalize(&self.value, (<Bytecode>precbc).bc) + else: + raise TypeError("Invalid precbc type '%s'" % type(precbc)) |