|
libyasm
|
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... | |
Macros | |
| #define | YASM_LIB_DECL |
| #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. More... | |
| #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. More... | |
| #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. More... | |
| #define | yasm_expr_simplify(e, cbd) yasm_expr__level_tree(e, 1, 1, 1, cbd, NULL, NULL) |
| Simplify an expression as much as possible. More... | |
Typedefs | |
| typedef enum yasm_expr__type | yasm_expr__type |
| Type of an expression item. More... | |
| typedef struct yasm_expr__item | yasm_expr__item |
| Expression item. More... | |
| typedef yasm_expr *(* | yasm_expr_xform_func )(yasm_expr *e, void *d) |
| Extra transformation function for yasm_expr__level_tree(). More... | |
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_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. More... | |
| YASM_LIB_DECL yasm_expr__item * | yasm_expr_precbc (yasm_bytecode *precbc) |
| Create a new preceding-bytecode expression item. More... | |
| YASM_LIB_DECL yasm_expr__item * | yasm_expr_sym (yasm_symrec *sym) |
| Create a new symbol expression item. More... | |
| YASM_LIB_DECL yasm_expr__item * | yasm_expr_expr (yasm_expr *e) |
| Create a new expression expression item. More... | |
| YASM_LIB_DECL yasm_expr__item * | yasm_expr_int (yasm_intnum *intn) |
| Create a new intnum expression item. More... | |
| YASM_LIB_DECL yasm_expr__item * | yasm_expr_float (yasm_floatnum *flt) |
| Create a new floatnum expression item. More... | |
| YASM_LIB_DECL yasm_expr__item * | yasm_expr_reg (uintptr_t reg) |
| Create a new register expression item. More... | |
| yasm_expr * | yasm_expr_copy (const yasm_expr *e) |
| Duplicate an expression. More... | |
| YASM_LIB_DECL void | yasm_expr_destroy (yasm_expr *e) |
| Destroy (free allocated memory for) an expression. More... | |
| 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). More... | |
| 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. More... | |
| 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. More... | |
| YASM_LIB_DECL yasm_expr * | yasm_expr_extract_segoff (yasm_expr **ep) |
| Extract the segment portion of a SEG:OFF expression, leaving the offset. More... | |
| 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). More... | |
| 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. More... | |
| 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. More... | |
| 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. More... | |
| YASM_LIB_DECL void | yasm_expr_print (const yasm_expr *e, FILE *f) |
| Print an expression. More... | |
| YASM_LIB_DECL unsigned int | yasm_expr_size (const yasm_expr *e) |
| Return the size of an expression, if the user provided it. More... | |
| YASM_LIB_DECL const char * | yasm_expr_segment (const yasm_expr *e) |
| Return the segment of an expression, if the user provided it. More... | |
| 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). More... | |
| 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. More... | |
| YASM_LIB_DECL void | yasm_expr__order_terms (yasm_expr *e) |
| Reorder terms of e into canonical order. More... | |
| 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. More... | |
| YASM_LIB_DECL int | yasm_expr__contains (const yasm_expr *e, yasm_expr__type t) |
| Test if expression contains an item. More... | |
| 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. More... | |
| 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). More... | |
YASM expression interface.
Definition in file expr.h.
| #define yasm_expr_create_branch | ( | o, | |
| r, | |||
| i | |||
| ) | yasm_expr_create ((o), yasm_expr_expr(r), (yasm_expr__item *)NULL, i) |
| #define yasm_expr_create_ident | ( | r, | |
| i | |||
| ) | yasm_expr_create (YASM_EXPR_IDENT, (r), (yasm_expr__item *)NULL, i) |
| #define yasm_expr_create_tree | ( | l, | |
| o, | |||
| r, | |||
| i | |||
| ) | yasm_expr_create ((o), yasm_expr_expr(l), yasm_expr_expr(r), i) |
| #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().
| e | expression |
| cbd | if distance between bytecodes should be calculated |
| typedef struct yasm_expr__item yasm_expr__item |
Expression item.
| typedef enum yasm_expr__type 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.
Extra transformation function for yasm_expr__level_tree().
| e | expression being simplified |
| d | data provided as expr_xform_extra_data to yasm_expr__level_tree() |
| 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.
| 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.
| 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) |
| 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.
| e | expression |
| t | type of item to look for |
Copy entire expression EXCEPT for index "except" at top level only.
| e | expression |
| except | term index not to copy; -1 to copy all terms |
| 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.
| 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 |
| 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.
| e | expression |
| 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.
| e | expression |
| num_items | number of items in items array |
| items | items array |
| 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).
| e | expression |
| d | data passed to each call to func |
| func | callback function |
| 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).
| e | expression |
| d | data passed to each call to func |
| func | callback function |
Duplicate an expression.
| e | expression |
| 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.
| op | operation |
| a | expression item a |
| b | expression item b (optional depending on op) |
| line | virtual line (where expression defined) |
| YASM_LIB_DECL void yasm_expr_destroy | ( | yasm_expr * | e | ) |
Destroy (free allocated memory for) an expression.
| e | expression |
| YASM_LIB_DECL yasm_expr__item* yasm_expr_expr | ( | yasm_expr * | e | ) |
Create a new expression expression item.
| e | expression |
Extract the segment portion of an expression containing SEG:OFF, leaving the offset.
| ep | expression (pointer to) |
Extract the segment portion of a SEG:OFF expression, leaving the offset.
| ep | expression (pointer to) |
Extract the right portion (y) of a x WRT y expression, leaving the left portion (x).
| ep | expression (pointer to) |
| YASM_LIB_DECL yasm_expr__item* yasm_expr_float | ( | yasm_floatnum * | flt | ) |
Create a new floatnum expression item.
| flt | floatnum |
| 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.
| ep | expression (pointer to) |
| calc_bc_dist | nonzero if distances between bytecodes should be calculated, 0 if NULL should be returned in this case |
| 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.
| ep | expression (pointer to) |
| simplify | if nonzero, simplify the expression first |
| 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.
| ep | expression (pointer to) |
| simplify | if nonzero, simplify the expression first |
| YASM_LIB_DECL yasm_expr__item* yasm_expr_int | ( | yasm_intnum * | intn | ) |
Create a new intnum expression item.
| intn | intnum |
| 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).
| e | expression |
| op | operator |
| YASM_LIB_DECL yasm_expr__item* yasm_expr_precbc | ( | yasm_bytecode * | precbc | ) |
Create a new preceding-bytecode expression item.
| precbc | preceding bytecode |
| YASM_LIB_DECL void yasm_expr_print | ( | const yasm_expr * | e, |
| FILE * | f | ||
| ) |
Print an expression.
For debugging purposes.
| e | expression |
| f | file |
| YASM_LIB_DECL yasm_expr__item* yasm_expr_reg | ( | uintptr_t | reg | ) |
Create a new register expression item.
| reg | register |
| YASM_LIB_DECL const char* yasm_expr_segment | ( | const yasm_expr * | e | ) |
Return the segment of an expression, if the user provided it.
| e | expression |
| YASM_LIB_DECL unsigned int yasm_expr_size | ( | const yasm_expr * | e | ) |
Return the size of an expression, if the user provided it.
| e | expression |
| YASM_LIB_DECL yasm_expr__item* yasm_expr_sym | ( | yasm_symrec * | sym | ) |
Create a new symbol expression item.
| sym | symbol |
1.8.3.1