00001
00034 #ifndef YASM_EXPR_H
00035 #define YASM_EXPR_H
00036
00037 #ifndef YASM_LIB_DECL
00038 #define YASM_LIB_DECL
00039 #endif
00040
00046 typedef enum yasm_expr__type {
00047 YASM_EXPR_NONE = 0,
00048 YASM_EXPR_REG = 1<<0,
00049 YASM_EXPR_INT = 1<<1,
00050 YASM_EXPR_SUBST = 1<<2,
00051 YASM_EXPR_FLOAT = 1<<3,
00052 YASM_EXPR_SYM = 1<<4,
00053 YASM_EXPR_PRECBC = 1<<5,
00054 YASM_EXPR_EXPR = 1<<6
00055 } yasm_expr__type;
00056
00058 typedef struct yasm_expr__item {
00059 yasm_expr__type type;
00062 union {
00063 yasm_bytecode *precbc;
00064 yasm_symrec *sym;
00065 yasm_expr *expn;
00066 yasm_intnum *intn;
00067 yasm_floatnum *flt;
00068 uintptr_t reg;
00069 unsigned int subst;
00070 } data;
00071 } yasm_expr__item;
00072
00074 struct yasm_expr {
00075 yasm_expr_op op;
00076 unsigned long line;
00077 int numterms;
00083 yasm_expr__item terms[2];
00084 };
00085
00093 YASM_LIB_DECL
00094 yasm_expr *yasm_expr_create
00095 (yasm_expr_op op, yasm_expr__item *a,
00096 yasm_expr__item *b, unsigned long line);
00097
00102 YASM_LIB_DECL
00103 yasm_expr__item *yasm_expr_precbc( yasm_bytecode *precbc);
00104
00109 YASM_LIB_DECL
00110 yasm_expr__item *yasm_expr_sym( yasm_symrec *sym);
00111
00116 YASM_LIB_DECL
00117 yasm_expr__item *yasm_expr_expr( yasm_expr *e);
00118
00123 YASM_LIB_DECL
00124 yasm_expr__item *yasm_expr_int( yasm_intnum *intn);
00125
00130 YASM_LIB_DECL
00131 yasm_expr__item *yasm_expr_float( yasm_floatnum *flt);
00132
00137 YASM_LIB_DECL
00138 yasm_expr__item *yasm_expr_reg(uintptr_t reg);
00139
00147 #define yasm_expr_create_tree(l,o,r,i) \
00148 yasm_expr_create ((o), yasm_expr_expr(l), yasm_expr_expr(r), i)
00149
00156 #define yasm_expr_create_branch(o,r,i) \
00157 yasm_expr_create ((o), yasm_expr_expr(r), (yasm_expr__item *)NULL, i)
00158
00164 #define yasm_expr_create_ident(r,i) \
00165 yasm_expr_create (YASM_EXPR_IDENT, (r), (yasm_expr__item *)NULL, i)
00166
00171 yasm_expr *yasm_expr_copy(const yasm_expr *e);
00172 #ifndef YASM_DOXYGEN
00173 #define yasm_expr_copy(e) yasm_expr__copy_except(e, -1)
00174 #endif
00175
00179 YASM_LIB_DECL
00180 void yasm_expr_destroy( yasm_expr *e);
00181
00188 YASM_LIB_DECL
00189 int yasm_expr_is_op(const yasm_expr *e, yasm_expr_op op);
00190
00197 typedef yasm_expr * (*yasm_expr_xform_func)
00198 ( yasm_expr *e, void *d);
00199
00212 YASM_LIB_DECL
00213 yasm_expr *yasm_expr__level_tree
00214 ( yasm_expr *e, int fold_const,
00215 int simplify_ident, int simplify_reg_mul, int calc_bc_dist,
00216 yasm_expr_xform_func expr_xform_extra,
00217 void *expr_xform_extra_data);
00218
00226 #define yasm_expr_simplify(e, cbd) \
00227 yasm_expr__level_tree(e, 1, 1, 1, cbd, NULL, NULL)
00228
00237 YASM_LIB_DECL
00238 yasm_expr *yasm_expr_extract_deep_segoff(yasm_expr **ep);
00239
00247 YASM_LIB_DECL
00248 yasm_expr *yasm_expr_extract_segoff(yasm_expr **ep);
00249
00258 YASM_LIB_DECL
00259 yasm_expr *yasm_expr_extract_wrt(yasm_expr **ep);
00260
00269 YASM_LIB_DECL
00270 yasm_intnum *yasm_expr_get_intnum
00271 (yasm_expr **ep, int calc_bc_dist);
00272
00279 YASM_LIB_DECL
00280 const yasm_symrec *yasm_expr_get_symrec
00281 (yasm_expr **ep, int simplify);
00282
00289 YASM_LIB_DECL
00290 const uintptr_t *yasm_expr_get_reg
00291 (yasm_expr **ep, int simplify);
00292
00297 YASM_LIB_DECL
00298 void yasm_expr_print( const yasm_expr *e, FILE *f);
00299
00303 unsigned int yasm_expr_size(const yasm_expr *e);
00304
00308 const char *yasm_expr_segment(const yasm_expr *e);
00309
00318 YASM_LIB_DECL
00319 int yasm_expr__traverse_leaves_in_const
00320 (const yasm_expr *e, void *d,
00321 int (*func) ( const yasm_expr__item *ei, void *d));
00322
00331 YASM_LIB_DECL
00332 int yasm_expr__traverse_leaves_in
00333 (yasm_expr *e, void *d,
00334 int (*func) ( yasm_expr__item *ei, void *d));
00335
00344 YASM_LIB_DECL
00345 void yasm_expr__order_terms(yasm_expr *e);
00346
00352 YASM_LIB_DECL
00353 yasm_expr *yasm_expr__copy_except(const yasm_expr *e, int except);
00354
00361 YASM_LIB_DECL
00362 int yasm_expr__contains(const yasm_expr *e, yasm_expr__type t);
00363
00372 YASM_LIB_DECL
00373 int yasm_expr__bc_dist_subst(yasm_expr **ep, void *cbd,
00374 void (*callback) (unsigned int subst,
00375 yasm_bytecode *precbc,
00376 yasm_bytecode *precbc2,
00377 void *cbd));
00378
00386 YASM_LIB_DECL
00387 int yasm_expr__subst(yasm_expr *e, unsigned int num_items,
00388 const yasm_expr__item *items);
00389
00390 #endif