libyasm
Macros | Functions
value.h File Reference

YASM value interface. More...

Go to the source code of this file.

Functions

YASM_LIB_DECL void yasm_value_initialize (yasm_value *value, yasm_expr *e, unsigned int size)
 Initialize a yasm_value with just an expression. More...
 
YASM_LIB_DECL void yasm_value_init_sym (yasm_value *value, yasm_symrec *sym, unsigned int size)
 Initialize a yasm_value with just a symrec. More...
 
YASM_LIB_DECL void yasm_value_init_copy (yasm_value *value, const yasm_value *orig)
 Initialize a yasm_value as a copy of another yasm_value. More...
 
YASM_LIB_DECL void yasm_value_delete (yasm_value *value)
 Frees any memory inside value; does not free value itself. More...
 
YASM_LIB_DECL void yasm_value_set_curpos_rel (yasm_value *value, yasm_bytecode *bc, unsigned int ip_rel)
 Set a value to be relative to the current assembly position rather than relative to the section start. More...
 
YASM_LIB_DECL int yasm_value_finalize (yasm_value *value, yasm_bytecode *precbc)
 Perform yasm_value_finalize_expr() on a value that already exists from being initialized with yasm_value_initialize(). More...
 
YASM_LIB_DECL int yasm_value_finalize_expr (yasm_value *value, yasm_expr *e, yasm_bytecode *precbc, unsigned int size)
 Break a yasm_expr into a yasm_value constituent parts. More...
 
YASM_LIB_DECL yasm_intnumyasm_value_get_intnum (yasm_value *value, yasm_bytecode *bc, int calc_bc_dist)
 Get value if absolute or PC-relative section-local relative. More...
 
YASM_LIB_DECL int yasm_value_output_basic (yasm_value *value, unsigned char *buf, size_t destsize, yasm_bytecode *bc, int warn, yasm_arch *arch)
 Output value if constant or PC-relative section-local. More...
 
YASM_LIB_DECL void yasm_value_print (const yasm_value *value, FILE *f, int indent_level)
 Print a value. More...
 

Detailed Description

YASM value interface.

Definition in file value.h.

Function Documentation

YASM_LIB_DECL void yasm_value_delete ( yasm_value value)

Frees any memory inside value; does not free value itself.

Parameters
valuevalue
YASM_LIB_DECL int yasm_value_finalize ( yasm_value value,
yasm_bytecode precbc 
)

Perform yasm_value_finalize_expr() on a value that already exists from being initialized with yasm_value_initialize().

Parameters
valuevalue
precbcprevious bytecode to bytecode containing value
Returns
Nonzero if value could not be split.
YASM_LIB_DECL int yasm_value_finalize_expr ( yasm_value value,
yasm_expr e,
yasm_bytecode precbc,
unsigned int  size 
)

Break a yasm_expr into a yasm_value constituent parts.

Extracts the relative portion of the value, SEG and WRT portions, and top-level right shift, if any. Places the remaining expr into the absolute portion of the value. Essentially a combination of yasm_value_initialize() and yasm_value_finalize(). First expands references to symrecs in absolute sections by expanding with the absolute section start plus the symrec offset within the absolute section.

Parameters
valuevalue to store split portions into
eexpression input
precbcprevious bytecode to bytecode containing expression
sizevalue size (in bits)
Returns
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).
Warning
Do not use e after this call. Even if an error is returned, e is stored into value.
Note
This should only be called after the parse is complete. Calling before the parse is complete will usually result in an error return.
YASM_LIB_DECL yasm_intnum* yasm_value_get_intnum ( yasm_value value,
yasm_bytecode bc,
int  calc_bc_dist 
)

Get value if absolute or PC-relative section-local relative.

Returns NULL otherwise.

Parameters
valuevalue
bccurrent bytecode (for PC-relative calculation); if NULL, NULL is returned for PC-relative values.
calc_bc_distif nonzero, calculates bytecode distances in absolute portion of value
Note
Adds in value.rel (correctly) if PC-relative and in the same section as bc (and there is no WRT or SEG).
Returns
Intnum if can be resolved to integer value, otherwise NULL.
YASM_LIB_DECL void yasm_value_init_copy ( yasm_value value,
const yasm_value orig 
)

Initialize a yasm_value as a copy of another yasm_value.

Any expressions within orig are copied, so it's safe to delete the copy.

Parameters
valuevalue (copy to create)
origoriginal value
YASM_LIB_DECL void yasm_value_init_sym ( yasm_value value,
yasm_symrec sym,
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 initialized.

Parameters
valuevalue to be initialized
symsymrec
sizevalue size (in bits)
YASM_LIB_DECL void yasm_value_initialize ( yasm_value value,
yasm_expr e,
unsigned int  size 
)

Initialize a yasm_value with just an expression.

No processing is performed, the expression is simply stuck into value.abs and the other fields are initialized. Use yasm_expr_extract_value() to perform "smart" processing into a yasm_value. This function is intended for use during parsing simply to ensure all fields of the value are initialized; after the parse is complete, yasm_value_extract() should be called to finalize the value. The value defaults to unsigned.

Parameters
valuevalue to be initialized
eexpression (kept)
sizevalue size (in bits)
YASM_LIB_DECL int yasm_value_output_basic ( yasm_value value,
unsigned char *  buf,
size_t  destsize,
yasm_bytecode bc,
int  warn,
yasm_arch arch 
)

Output value if constant or PC-relative section-local.

This should be used from objfmt yasm_output_value_func() functions. functions.

Parameters
valuevalue
bufbuffer for byte representation
destsizedestination size (in bytes)
bccurrent bytecode (usually passed into higher-level calling function)
warnenables standard warnings: zero for none; nonzero for overflow/underflow floating point and integer warnings
archarchitecture
Note
Adds in value.rel (correctly) if PC-relative and in the same section as bc (and there is no WRT or SEG); if this is not the desired behavior, e.g. a reloc is needed in this case, don't use this function!
Returns
0 if no value output due to value needing relocation; 1 if value output; -1 if error.
YASM_LIB_DECL void yasm_value_print ( const yasm_value value,
FILE *  f,
int  indent_level 
)

Print a value.

For debugging purposes.

Parameters
valuevalue
indent_levelindentation level
ffile
YASM_LIB_DECL void yasm_value_set_curpos_rel ( yasm_value value,
yasm_bytecode bc,
unsigned int  ip_rel 
)

Set a value to be relative to the current assembly position rather than relative to the section start.

Parameters
valuevalue
bcbytecode containing value
ip_relif nonzero, indicates IP-relative data relocation, sometimes used to generate special relocations
Note
If value is just an absolute value, will get an absolute symrec to reference to (via bc's symbol table).