libyasm

libyasm/expr.h

Go to the documentation of this file.
00001 
00030 #ifndef YASM_EXPR_H
00031 #define YASM_EXPR_H
00032 
00033 #ifndef YASM_LIB_DECL
00034 #define YASM_LIB_DECL
00035 #endif
00036 
00042 typedef enum yasm_expr__type {
00043     YASM_EXPR_NONE = 0,     
00044     YASM_EXPR_REG = 1<<0,   
00045     YASM_EXPR_INT = 1<<1,   
00046     YASM_EXPR_SUBST = 1<<2, 
00047     YASM_EXPR_FLOAT = 1<<3, 
00048     YASM_EXPR_SYM = 1<<4,   
00049     YASM_EXPR_PRECBC = 1<<5,
00050     YASM_EXPR_EXPR = 1<<6   
00051 } yasm_expr__type;
00052 
00054 typedef struct yasm_expr__item {
00055     yasm_expr__type type;   
00058     union {
00059         yasm_bytecode *precbc;  
00060         yasm_symrec *sym;       
00061         yasm_expr *expn;        
00062         yasm_intnum *intn;      
00063         yasm_floatnum *flt;     
00064         uintptr_t reg;          
00065         unsigned int subst;     
00066     } data;
00067 } yasm_expr__item;
00068 
00070 struct yasm_expr {
00071     yasm_expr_op op;    
00072     unsigned long line; 
00073     int numterms;       
00079     yasm_expr__item terms[2];
00080 };
00081 
00089 YASM_LIB_DECL
00090 /*@only@*/ yasm_expr *yasm_expr_create
00091     (yasm_expr_op op, /*@only@*/ yasm_expr__item *a,
00092      /*@only@*/ /*@null@*/ yasm_expr__item *b, unsigned long line);
00093 
00098 YASM_LIB_DECL
00099 /*@only@*/ yasm_expr__item *yasm_expr_precbc(/*@keep@*/ yasm_bytecode *precbc);
00100 
00105 YASM_LIB_DECL
00106 /*@only@*/ yasm_expr__item *yasm_expr_sym(/*@keep@*/ yasm_symrec *sym);
00107 
00112 YASM_LIB_DECL
00113 /*@only@*/ yasm_expr__item *yasm_expr_expr(/*@keep@*/ yasm_expr *e);
00114 
00119 YASM_LIB_DECL
00120 /*@only@*/ yasm_expr__item *yasm_expr_int(/*@keep@*/ yasm_intnum *intn);
00121 
00126 YASM_LIB_DECL
00127 /*@only@*/ yasm_expr__item *yasm_expr_float(/*@keep@*/ yasm_floatnum *flt);
00128 
00133 YASM_LIB_DECL
00134 /*@only@*/ yasm_expr__item *yasm_expr_reg(uintptr_t reg);
00135 
00143 #define yasm_expr_create_tree(l,o,r,i) \
00144     yasm_expr_create ((o), yasm_expr_expr(l), yasm_expr_expr(r), i)
00145 
00152 #define yasm_expr_create_branch(o,r,i) \
00153     yasm_expr_create ((o), yasm_expr_expr(r), (yasm_expr__item *)NULL, i)
00154 
00160 #define yasm_expr_create_ident(r,i) \
00161     yasm_expr_create (YASM_EXPR_IDENT, (r), (yasm_expr__item *)NULL, i)
00162 
00167 yasm_expr *yasm_expr_copy(const yasm_expr *e);
00168 #ifndef YASM_DOXYGEN
00169 #define yasm_expr_copy(e)   yasm_expr__copy_except(e, -1)
00170 #endif
00171 
00175 YASM_LIB_DECL
00176 void yasm_expr_destroy(/*@only@*/ /*@null@*/ yasm_expr *e);
00177 
00184 YASM_LIB_DECL
00185 int yasm_expr_is_op(const yasm_expr *e, yasm_expr_op op);
00186 
00193 typedef /*@only@*/ yasm_expr * (*yasm_expr_xform_func)
00194     (/*@returned@*/ /*@only@*/ yasm_expr *e, /*@null@*/ void *d);
00195 
00208 YASM_LIB_DECL
00209 /*@only@*/ /*@null@*/ yasm_expr *yasm_expr__level_tree
00210     (/*@returned@*/ /*@only@*/ /*@null@*/ yasm_expr *e, int fold_const,
00211      int simplify_ident, int simplify_reg_mul, int calc_bc_dist,
00212      /*@null@*/ yasm_expr_xform_func expr_xform_extra,
00213      /*@null@*/ void *expr_xform_extra_data);
00214 
00222 #define yasm_expr_simplify(e, cbd) \
00223     yasm_expr__level_tree(e, 1, 1, 1, cbd, NULL, NULL)
00224 
00233 YASM_LIB_DECL
00234 /*@only@*/ /*@null@*/ yasm_expr *yasm_expr_extract_deep_segoff(yasm_expr **ep);
00235 
00243 YASM_LIB_DECL
00244 /*@only@*/ /*@null@*/ yasm_expr *yasm_expr_extract_segoff(yasm_expr **ep);
00245 
00254 YASM_LIB_DECL
00255 /*@only@*/ /*@null@*/ yasm_expr *yasm_expr_extract_wrt(yasm_expr **ep);
00256 
00265 YASM_LIB_DECL
00266 /*@dependent@*/ /*@null@*/ yasm_intnum *yasm_expr_get_intnum
00267     (yasm_expr **ep, int calc_bc_dist);
00268 
00275 YASM_LIB_DECL
00276 /*@dependent@*/ /*@null@*/ const yasm_symrec *yasm_expr_get_symrec
00277     (yasm_expr **ep, int simplify);
00278 
00285 YASM_LIB_DECL
00286 /*@dependent@*/ /*@null@*/ const uintptr_t *yasm_expr_get_reg
00287     (yasm_expr **ep, int simplify);
00288 
00293 YASM_LIB_DECL
00294 void yasm_expr_print(/*@null@*/ const yasm_expr *e, FILE *f);
00295 
00299 unsigned int yasm_expr_size(const yasm_expr *e);
00300 
00304 const char *yasm_expr_segment(const yasm_expr *e);
00305 
00314 YASM_LIB_DECL
00315 int yasm_expr__traverse_leaves_in_const
00316     (const yasm_expr *e, /*@null@*/ void *d,
00317      int (*func) (/*@null@*/ const yasm_expr__item *ei, /*@null@*/ void *d));
00318 
00327 YASM_LIB_DECL
00328 int yasm_expr__traverse_leaves_in
00329     (yasm_expr *e, /*@null@*/ void *d,
00330      int (*func) (/*@null@*/ yasm_expr__item *ei, /*@null@*/ void *d));
00331 
00340 YASM_LIB_DECL
00341 void yasm_expr__order_terms(yasm_expr *e);
00342 
00348 YASM_LIB_DECL
00349 yasm_expr *yasm_expr__copy_except(const yasm_expr *e, int except);
00350 
00357 YASM_LIB_DECL
00358 int yasm_expr__contains(const yasm_expr *e, yasm_expr__type t);
00359 
00368 YASM_LIB_DECL
00369 int yasm_expr__bc_dist_subst(yasm_expr **ep, void *cbd,
00370                              void (*callback) (unsigned int subst,
00371                                                yasm_bytecode *precbc,
00372                                                yasm_bytecode *precbc2,
00373                                                void *cbd));
00374 
00382 YASM_LIB_DECL
00383 int yasm_expr__subst(yasm_expr *e, unsigned int num_items,
00384                      const yasm_expr__item *items);
00385 
00386 #endif