libyasm/expr.h File Reference

YASM expression interface. More...

Go to the source code of this file.

Data Structures

struct  yasm_expr__item
 Expression item. More...
struct  yasm_expr
 Expression. More...

Defines

#define yasm_expr_create_tree(l, o, r, i)   yasm_expr_create ((o), yasm_expr_expr(l), yasm_expr_expr(r), i)
 Create a new expression tree e=l op r.
#define yasm_expr_create_branch(o, r, i)   yasm_expr_create ((o), yasm_expr_expr(r), (yasm_expr__item *)NULL, i)
 Create a new expression branch e=op r.
#define yasm_expr_create_ident(r, i)   yasm_expr_create (YASM_EXPR_IDENT, (r), (yasm_expr__item *)NULL, i)
 Create a new expression identity e=r.
#define yasm_expr_simplify(e, cbd)   yasm_expr__level_tree(e, 1, 1, 1, cbd, NULL, NULL)
 Simplify an expression as much as possible.

Typedefs

typedef yasm_expr *(*) yasm_expr_xform_func (yasm_expr *e, void *d)
 Extra transformation function for yasm_expr__level_tree().

Enumerations

enum  yasm_expr__type {
  YASM_EXPR_NONE = 0, YASM_EXPR_REG = 1<<0, YASM_EXPR_INT = 1<<1, YASM_EXPR_SUBST = 1<<2,
  YASM_EXPR_FLOAT = 1<<3, YASM_EXPR_SYM = 1<<4, YASM_EXPR_PRECBC = 1<<5, YASM_EXPR_EXPR = 1<<6
}
 Type of an expression item. More...

Functions

YASM_LIB_DECL yasm_expryasm_expr_create (yasm_expr_op op, yasm_expr__item *a, yasm_expr__item *b, unsigned long line)
 Create a new expression e=a op b.
YASM_LIB_DECL yasm_expr__itemyasm_expr_precbc (yasm_bytecode *precbc)
 Create a new preceding-bytecode expression item.
YASM_LIB_DECL yasm_expr__itemyasm_expr_sym (yasm_symrec *sym)
 Create a new symbol expression item.
YASM_LIB_DECL yasm_expr__itemyasm_expr_expr (yasm_expr *e)
 Create a new expression expression item.
YASM_LIB_DECL yasm_expr__itemyasm_expr_int (yasm_intnum *intn)
 Create a new intnum expression item.
YASM_LIB_DECL yasm_expr__itemyasm_expr_float (yasm_floatnum *flt)
 Create a new floatnum expression item.
YASM_LIB_DECL yasm_expr__itemyasm_expr_reg (uintptr_t reg)
 Create a new register expression item.
yasm_expryasm_expr_copy (const yasm_expr *e)
 Duplicate an expression.
YASM_LIB_DECL void yasm_expr_destroy (yasm_expr *e)
 Destroy (free allocated memory for) an expression.
YASM_LIB_DECL int yasm_expr_is_op (const yasm_expr *e, yasm_expr_op op)
 Determine if an expression is a specified operation (at the top level).
YASM_LIB_DECL yasm_expryasm_expr__level_tree (yasm_expr *e, int fold_const, int simplify_ident, int simplify_reg_mul, int calc_bc_dist, yasm_expr_xform_func expr_xform_extra, void *expr_xform_extra_data)
 Level an entire expression tree.
YASM_LIB_DECL yasm_expryasm_expr_extract_deep_segoff (yasm_expr **ep)
 Extract the segment portion of an expression containing SEG:OFF, leaving the offset.
YASM_LIB_DECL yasm_expryasm_expr_extract_segoff (yasm_expr **ep)
 Extract the segment portion of a SEG:OFF expression, leaving the offset.
YASM_LIB_DECL yasm_expryasm_expr_extract_wrt (yasm_expr **ep)
 Extract the right portion (y) of a x WRT y expression, leaving the left portion (x).
YASM_LIB_DECL yasm_intnumyasm_expr_get_intnum (yasm_expr **ep, int calc_bc_dist)
 Get the integer value of an expression if it's just an integer.
YASM_LIB_DECL const yasm_symrecyasm_expr_get_symrec (yasm_expr **ep, int simplify)
 Get the symbol value of an expression if it's just a symbol.
YASM_LIB_DECL const uintptr_t * yasm_expr_get_reg (yasm_expr **ep, int simplify)
 Get the register value of an expression if it's just a register.
YASM_LIB_DECL void yasm_expr_print (const yasm_expr *e, FILE *f)
 Print an expression.
YASM_LIB_DECL int yasm_expr__traverse_leaves_in_const (const yasm_expr *e, void *d, int(*func)(const yasm_expr__item *ei, void *d))
 Traverse over expression tree in order (const version).
YASM_LIB_DECL int yasm_expr__traverse_leaves_in (yasm_expr *e, void *d, int(*func)(yasm_expr__item *ei, void *d))
 Traverse over expression tree in order.
YASM_LIB_DECL void yasm_expr__order_terms (yasm_expr *e)
 Reorder terms of e into canonical order.
YASM_LIB_DECL yasm_expryasm_expr__copy_except (const yasm_expr *e, int except)
 Copy entire expression EXCEPT for index "except" at *top level only*.
YASM_LIB_DECL int yasm_expr__contains (const yasm_expr *e, yasm_expr__type t)
 Test if expression contains an item.
YASM_LIB_DECL int yasm_expr__bc_dist_subst (yasm_expr **ep, void *cbd, void(*callback)(unsigned int subst, yasm_bytecode *precbc, yasm_bytecode *precbc2, void *cbd))
 Transform symrec-symrec terms in expression into YASM_EXPR_SUBST items.
YASM_LIB_DECL int yasm_expr__subst (yasm_expr *e, unsigned int num_items, const yasm_expr__item *items)
 Substitute items into expr YASM_EXPR_SUBST items (by index).


Detailed Description

YASM expression interface.

Definition in file expr.h.


Define Documentation

#define yasm_expr_create_branch ( o,
r,
 )     yasm_expr_create ((o), yasm_expr_expr(r), (yasm_expr__item *)NULL, i)

Create a new expression branch e=op r.

Parameters:
o operation
r expression for right side of new expression
i line index
Returns:
Newly allocated expression.

Definition at line 156 of file expr.h.

#define yasm_expr_create_ident ( r,
 )     yasm_expr_create (YASM_EXPR_IDENT, (r), (yasm_expr__item *)NULL, i)

Create a new expression identity e=r.

Parameters:
r expression for identity within new expression
i line index
Returns:
Newly allocated expression.

Definition at line 164 of file expr.h.

#define yasm_expr_create_tree ( l,
o,
r,
 )     yasm_expr_create ((o), yasm_expr_expr(l), yasm_expr_expr(r), i)

Create a new expression tree e=l op r.

Parameters:
l expression for left side of new expression
o operation
r expression for right side of new expression
i line index
Returns:
Newly allocated expression.

Definition at line 147 of file expr.h.

#define yasm_expr_simplify ( e,
cbd   )     yasm_expr__level_tree(e, 1, 1, 1, cbd, NULL, NULL)

Simplify an expression as much as possible.

Eliminates extraneous branches and simplifies integer-only subexpressions. Simplified version of yasm_expr__level_tree().

Parameters:
e expression
cbd if distance between bytecodes should be calculated
Returns:
Simplified expression.

Definition at line 226 of file expr.h.


Typedef Documentation

typedef yasm_expr*(*) yasm_expr_xform_func(yasm_expr *e,void *d)

Extra transformation function for yasm_expr__level_tree().

Parameters:
e expression being simplified
d data provided as expr_xform_extra_data to yasm_expr__level_tree()
Returns:
Transformed e.

Definition at line 198 of file expr.h.


Enumeration Type Documentation

enum yasm_expr__type

Type of an expression item.

Types are listed in canonical sorting order. See expr_order_terms(). Note YASM_EXPR_PRECBC must be used carefully (in a-b pairs), as only symrecs can become the relative term in a yasm_value.

Enumerator:
YASM_EXPR_NONE  Nothing.
YASM_EXPR_REG  Register.
YASM_EXPR_INT  Integer value.
YASM_EXPR_SUBST  Substitution placeholder.
YASM_EXPR_FLOAT  Floating point value.
YASM_EXPR_SYM  Symbol.
YASM_EXPR_PRECBC  Direct bytecode ref (rather than via sym).
YASM_EXPR_EXPR  Subexpression.

Definition at line 46 of file expr.h.


Function Documentation

YASM_LIB_DECL int yasm_expr__bc_dist_subst ( yasm_expr **  ep,
void *  cbd,
void(*)(unsigned int subst, yasm_bytecode *precbc, yasm_bytecode *precbc2, void *cbd)  callback 
)

Transform symrec-symrec terms in expression into YASM_EXPR_SUBST items.

Calls the callback function for each symrec-symrec term.

Parameters:
ep expression (pointer to)
cbd callback data passed to callback function
callback callback function: given subst index for bytecode pair, bytecode pair (bc2-bc1), and cbd (callback data)
Returns:
Number of transformations made.

YASM_LIB_DECL int yasm_expr__contains ( const yasm_expr e,
yasm_expr__type  t 
)

Test if expression contains an item.

Searches recursively into subexpressions.

Parameters:
e expression
t type of item to look for
Returns:
Nonzero if expression contains an item of type t, zero if not.

YASM_LIB_DECL yasm_expr* yasm_expr__copy_except ( const yasm_expr e,
int  except 
)

Copy entire expression EXCEPT for index "except" at *top level only*.

Parameters:
e expression
except term index not to copy; -1 to copy all terms
Returns:
Newly allocated copy of expression.

YASM_LIB_DECL yasm_expr* yasm_expr__level_tree ( yasm_expr e,
int  fold_const,
int  simplify_ident,
int  simplify_reg_mul,
int  calc_bc_dist,
yasm_expr_xform_func  expr_xform_extra,
void *  expr_xform_extra_data 
)

Level an entire expression tree.

For internal use only.

Parameters:
e expression
fold_const enable constant folding if nonzero
simplify_ident simplify identities
simplify_reg_mul simplify REG*1 identities
calc_bc_dist nonzero if distances between bytecodes should be calculated, 0 if they should be left intact
expr_xform_extra extra transformation function
expr_xform_extra_data data to pass to expr_xform_extra
Returns:
Leveled expression.

YASM_LIB_DECL void yasm_expr__order_terms ( yasm_expr e  ) 

Reorder terms of e into canonical order.

Only reorders if reordering doesn't change meaning of expression. (eg, doesn't reorder SUB). Canonical order: REG, INT, FLOAT, SYM, EXPR. Multiple terms of a single type are kept in the same order as in the original expression.

Parameters:
e expression
Note:
Only performs reordering on *one* level (no recursion).

YASM_LIB_DECL int yasm_expr__subst ( yasm_expr e,
unsigned int  num_items,
const yasm_expr__item items 
)

Substitute items into expr YASM_EXPR_SUBST items (by index).

Items are copied, so caller is responsible for freeing array of items.

Parameters:
e expression
num_items number of items in items array
items items array
Returns:
1 on error (index out of range).

YASM_LIB_DECL int yasm_expr__traverse_leaves_in ( yasm_expr e,
void *  d,
int(*)(yasm_expr__item *ei, void *d)  func 
)

Traverse over expression tree in order.

Calls func for each leaf (non-operation).

Parameters:
e expression
d data passed to each call to func
func callback function
Returns:
Stops early (and returns 1) if func returns 1. Otherwise returns 0.

YASM_LIB_DECL int yasm_expr__traverse_leaves_in_const ( const yasm_expr e,
void *  d,
int(*)(const yasm_expr__item *ei, void *d)  func 
)

Traverse over expression tree in order (const version).

Calls func for each leaf (non-operation).

Parameters:
e expression
d data passed to each call to func
func callback function
Returns:
Stops early (and returns 1) if func returns 1. Otherwise returns 0.

yasm_expr* yasm_expr_copy ( const yasm_expr e  ) 

Duplicate an expression.

Parameters:
e expression
Returns:
Newly allocated expression identical to e.

YASM_LIB_DECL yasm_expr* yasm_expr_create ( yasm_expr_op  op,
yasm_expr__item a,
yasm_expr__item b,
unsigned long  line 
)

Create a new expression e=a op b.

Parameters:
op operation
a expression item a
b expression item b (optional depending on op)
line virtual line (where expression defined)
Returns:
Newly allocated expression.

YASM_LIB_DECL void yasm_expr_destroy ( yasm_expr e  ) 

Destroy (free allocated memory for) an expression.

Parameters:
e expression

YASM_LIB_DECL yasm_expr__item* yasm_expr_expr ( yasm_expr e  ) 

Create a new expression expression item.

Parameters:
e expression
Returns:
Newly allocated expression item.

YASM_LIB_DECL yasm_expr* yasm_expr_extract_deep_segoff ( yasm_expr **  ep  ) 

Extract the segment portion of an expression containing SEG:OFF, leaving the offset.

Parameters:
ep expression (pointer to)
Returns:
NULL if unable to extract a segment (expr does not contain a YASM_EXPR_SEGOFF operator), otherwise the segment expression. The input expression is modified such that on return, it's the offset expression.

YASM_LIB_DECL yasm_expr* yasm_expr_extract_segoff ( yasm_expr **  ep  ) 

Extract the segment portion of a SEG:OFF expression, leaving the offset.

Parameters:
ep expression (pointer to)
Returns:
NULL if unable to extract a segment (YASM_EXPR_SEGOFF not the top-level operator), otherwise the segment expression. The input expression is modified such that on return, it's the offset expression.

YASM_LIB_DECL yasm_expr* yasm_expr_extract_wrt ( yasm_expr **  ep  ) 

Extract the right portion (y) of a x WRT y expression, leaving the left portion (x).

Parameters:
ep expression (pointer to)
Returns:
NULL if unable to extract (YASM_EXPR_WRT not the top-level operator), otherwise the right side of the WRT expression. The input expression is modified such that on return, it's the left side of the WRT expression.

YASM_LIB_DECL yasm_expr__item* yasm_expr_float ( yasm_floatnum flt  ) 

Create a new floatnum expression item.

Parameters:
flt floatnum
Returns:
Newly allocated expression item.

YASM_LIB_DECL yasm_intnum* yasm_expr_get_intnum ( yasm_expr **  ep,
int  calc_bc_dist 
)

Get the integer value of an expression if it's just an integer.

Parameters:
ep expression (pointer to)
calc_bc_dist nonzero if distances between bytecodes should be calculated, 0 if NULL should be returned in this case
Returns:
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.

YASM_LIB_DECL const uintptr_t* yasm_expr_get_reg ( yasm_expr **  ep,
int  simplify 
)

Get the register value of an expression if it's just a register.

Parameters:
ep expression (pointer to)
simplify if nonzero, simplify the expression first
Returns:
NULL if the expression is too complex; otherwise the register value of the expression.

YASM_LIB_DECL const yasm_symrec* yasm_expr_get_symrec ( yasm_expr **  ep,
int  simplify 
)

Get the symbol value of an expression if it's just a symbol.

Parameters:
ep expression (pointer to)
simplify if nonzero, simplify the expression first
Returns:
NULL if the expression is too complex; otherwise the symbol value of the expression.

YASM_LIB_DECL yasm_expr__item* yasm_expr_int ( yasm_intnum intn  ) 

Create a new intnum expression item.

Parameters:
intn intnum
Returns:
Newly allocated expression item.

YASM_LIB_DECL int yasm_expr_is_op ( const yasm_expr e,
yasm_expr_op  op 
)

Determine if an expression is a specified operation (at the top level).

Parameters:
e expression
op operator
Returns:
Nonzero if the expression was the specified operation at the top level, zero otherwise.

YASM_LIB_DECL yasm_expr__item* yasm_expr_precbc ( yasm_bytecode precbc  ) 

Create a new preceding-bytecode expression item.

Parameters:
precbc preceding bytecode
Returns:
Newly allocated expression item.

YASM_LIB_DECL void yasm_expr_print ( const yasm_expr e,
FILE *  f 
)

Print an expression.

For debugging purposes.

Parameters:
e expression
f file

YASM_LIB_DECL yasm_expr__item* yasm_expr_reg ( uintptr_t  reg  ) 

Create a new register expression item.

Parameters:
reg register
Returns:
Newly allocated expression item.

YASM_LIB_DECL yasm_expr__item* yasm_expr_sym ( yasm_symrec sym  ) 

Create a new symbol expression item.

Parameters:
sym symbol
Returns:
Newly allocated expression item.


Generated on Thu Jul 24 01:23:31 2008 for libyasm by  doxygen 1.5.2