libyasm

libyasm/bytecode.h

Go to the documentation of this file.
00001 
00030 #ifndef YASM_BYTECODE_H
00031 #define YASM_BYTECODE_H
00032 
00033 #ifndef YASM_LIB_DECL
00034 #define YASM_LIB_DECL
00035 #endif
00036 
00038 typedef struct yasm_dataval yasm_dataval;
00040 typedef struct yasm_datavalhead yasm_datavalhead;
00041 
00043 /*@reldef@*/ STAILQ_HEAD(yasm_datavalhead, yasm_dataval);
00044 
00055 typedef void (*yasm_bc_add_span_func)
00056     (void *add_span_data, yasm_bytecode *bc, int id, const yasm_value *value,
00057      long neg_thres, long pos_thres);
00058 
00063 typedef struct yasm_bytecode_callback {
00068     void (*destroy) (/*@only@*/ void *contents);
00069 
00076     void (*print) (const void *contents, FILE *f, int indent_level);
00077 
00083     void (*finalize) (yasm_bytecode *bc, yasm_bytecode *prev_bc);
00084 
00091     int (*elem_size) (yasm_bytecode *bc);
00092 
00108     int (*calc_len) (yasm_bytecode *bc, yasm_bc_add_span_func add_span,
00109                      void *add_span_data);
00110 
00132     int (*expand) (yasm_bytecode *bc, int span, long old_val, long new_val,
00133                    /*@out@*/ long *neg_thres, /*@out@*/ long *pos_thres);
00134 
00159     int (*tobytes) (yasm_bytecode *bc, unsigned char **bufp,
00160                     unsigned char *bufstart, void *d,
00161                     yasm_output_value_func output_value,
00162                     /*@null@*/ yasm_output_reloc_func output_reloc);
00163 
00168     enum yasm_bytecode_special_type {
00169         YASM_BC_SPECIAL_NONE = 0,
00170 
00172         YASM_BC_SPECIAL_RESERVE,
00173 
00175         YASM_BC_SPECIAL_OFFSET,
00176 
00178         YASM_BC_SPECIAL_INSN
00179     } special;
00180 } yasm_bytecode_callback;
00181 
00183 struct yasm_bytecode {
00187     /*@reldef@*/ STAILQ_ENTRY(yasm_bytecode) link;
00188 
00192     /*@null@*/ const yasm_bytecode_callback *callback;
00193 
00197     /*@dependent@*/ /*@null@*/ yasm_section *section;
00198 
00202     /*@only@*/ /*@null@*/ yasm_expr *multiple;
00203 
00205     unsigned long len;
00206 
00208     long mult_int;
00209 
00211     unsigned long line;
00212 
00216     unsigned long offset;
00217 
00219     unsigned long bc_index;
00220 
00224     /*@null@*/ yasm_symrec **symrecs;
00225 
00227     void *contents;
00228 };
00229 
00237 YASM_LIB_DECL
00238 /*@only@*/ yasm_bytecode *yasm_bc_create_common
00239     (/*@null@*/ const yasm_bytecode_callback *callback,
00240      /*@only@*/ /*@null@*/ void *contents, unsigned long line);
00241 
00247 YASM_LIB_DECL
00248 void yasm_bc_transform(yasm_bytecode *bc,
00249                        const yasm_bytecode_callback *callback,
00250                        void *contents);
00251 
00255 YASM_LIB_DECL
00256 void yasm_bc_finalize_common(yasm_bytecode *bc, yasm_bytecode *prev_bc);
00257 
00261 YASM_LIB_DECL
00262 int yasm_bc_calc_len_common(yasm_bytecode *bc, yasm_bc_add_span_func add_span,
00263                             void *add_span_data);
00264 
00269 YASM_LIB_DECL
00270 int yasm_bc_expand_common
00271     (yasm_bytecode *bc, int span, long old_val, long new_val,
00272      /*@out@*/ long *neg_thres, /*@out@*/ long *pos_thres);
00273 
00277 YASM_LIB_DECL
00278 int yasm_bc_tobytes_common
00279     (yasm_bytecode *bc, unsigned char **bufp, unsigned char *bufstart, void *d,
00280      yasm_output_value_func output_value,
00281      /*@null@*/ yasm_output_reloc_func output_reloc);
00282 
00287 #define yasm_bc__next(bc)               STAILQ_NEXT(bc, link)
00288 
00295 YASM_LIB_DECL
00296 void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e);
00297 
00308 YASM_LIB_DECL
00309 /*@only@*/ yasm_bytecode *yasm_bc_create_data
00310     (yasm_datavalhead *datahead, unsigned int size, int append_zero,
00311      /*@null@*/ yasm_arch *arch, unsigned long line);
00312 
00319 YASM_LIB_DECL
00320 /*@only@*/ yasm_bytecode *yasm_bc_create_leb128
00321     (yasm_datavalhead *datahead, int sign, unsigned long line);
00322 
00329 YASM_LIB_DECL
00330 /*@only@*/ yasm_bytecode *yasm_bc_create_reserve
00331     (/*@only@*/ yasm_expr *numitems, unsigned int itemsize,
00332      unsigned long line);
00333 
00341 YASM_LIB_DECL
00342 /*@null@*/ const yasm_expr *yasm_bc_reserve_numitems
00343     (yasm_bytecode *bc, /*@out@*/ unsigned int *itemsize);
00344 
00355 YASM_LIB_DECL
00356 /*@only@*/ yasm_bytecode *yasm_bc_create_incbin
00357     (/*@only@*/ char *filename, /*@only@*/ /*@null@*/ yasm_expr *start,
00358      /*@only@*/ /*@null@*/ yasm_expr *maxlen, yasm_linemap *linemap,
00359      unsigned long line);
00360 
00373 YASM_LIB_DECL
00374 /*@only@*/ yasm_bytecode *yasm_bc_create_align
00375     (/*@keep@*/ yasm_expr *boundary, /*@keep@*/ /*@null@*/ yasm_expr *fill,
00376      /*@keep@*/ /*@null@*/ yasm_expr *maxskip,
00377      /*@null@*/ const unsigned char **code_fill, unsigned long line);
00378 
00386 YASM_LIB_DECL
00387 /*@only@*/ yasm_bytecode *yasm_bc_create_org
00388     (unsigned long start, unsigned long fill, unsigned long line);
00389 
00395 YASM_LIB_DECL
00396 /*@dependent@*/ /*@null@*/ yasm_section *yasm_bc_get_section
00397     (yasm_bytecode *bc);
00398 
00404 YASM_LIB_DECL
00405 void yasm_bc__add_symrec(yasm_bytecode *bc, /*@dependent@*/ yasm_symrec *sym);
00406 
00410 YASM_LIB_DECL
00411 void yasm_bc_destroy(/*@only@*/ /*@null@*/ yasm_bytecode *bc);
00412 
00418 YASM_LIB_DECL
00419 void yasm_bc_print(const yasm_bytecode *bc, FILE *f, int indent_level);
00420 
00425 YASM_LIB_DECL
00426 void yasm_bc_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc);
00427 
00435 YASM_LIB_DECL
00436 /*@null@*/ /*@only@*/ yasm_intnum *yasm_calc_bc_dist
00437     (yasm_bytecode *precbc1, yasm_bytecode *precbc2);
00438 
00445 YASM_LIB_DECL
00446 unsigned long yasm_bc_next_offset(yasm_bytecode *precbc);
00447 
00454 YASM_LIB_DECL
00455 int yasm_bc_elem_size(yasm_bytecode *bc);
00456 
00469 YASM_LIB_DECL
00470 int yasm_bc_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span,
00471                      void *add_span_data);
00472 
00487 YASM_LIB_DECL
00488 int yasm_bc_expand(yasm_bytecode *bc, int span, long old_val, long new_val,
00489                    /*@out@*/ long *neg_thres, /*@out@*/ long *pos_thres);
00490 
00511 YASM_LIB_DECL
00512 /*@null@*/ /*@only@*/ unsigned char *yasm_bc_tobytes
00513     (yasm_bytecode *bc, unsigned char *buf, unsigned long *bufsize,
00514      /*@out@*/ int *gap, void *d, yasm_output_value_func output_value,
00515      /*@null@*/ yasm_output_reloc_func output_reloc)
00516     /*@sets *buf@*/;
00517 
00525 YASM_LIB_DECL
00526 int yasm_bc_get_multiple(yasm_bytecode *bc, /*@out@*/ long *multiple,
00527                          int calc_bc_dist);
00528 
00533 YASM_LIB_DECL
00534 const yasm_expr *yasm_bc_get_multiple_expr(const yasm_bytecode *bc);
00535 
00541 YASM_LIB_DECL
00542 /*@dependent@*/ /*@null@*/ yasm_insn *yasm_bc_get_insn(yasm_bytecode *bc);
00543 
00548 YASM_LIB_DECL
00549 yasm_dataval *yasm_dv_create_expr(/*@keep@*/ yasm_expr *expn);
00550 
00556 yasm_dataval *yasm_dv_create_string(/*@keep@*/ char *contents, size_t len);
00557 
00563 YASM_LIB_DECL
00564 yasm_dataval *yasm_dv_create_raw(/*@keep@*/ unsigned char *contents,
00565                                  unsigned long len);
00566 
00570 yasm_dataval *yasm_dv_create_reserve(void);
00571 
00572 #ifndef YASM_DOXYGEN
00573 #define yasm_dv_create_string(s, l) yasm_dv_create_raw((unsigned char *)(s), \
00574                                                        (unsigned long)(l))
00575 #endif
00576 
00581 yasm_value *yasm_dv_get_value(yasm_dataval *dv);
00582 
00589 void yasm_dv_set_multiple(yasm_dataval *dv, /*@keep@*/ yasm_expr *e);
00590 
00596 int yasm_dv_get_multiple(yasm_dataval *dv, /*@out@*/ unsigned long *multiple);
00597 
00601 void yasm_dvs_initialize(yasm_datavalhead *headp);
00602 #ifndef YASM_DOXYGEN
00603 #define yasm_dvs_initialize(headp)      STAILQ_INIT(headp)
00604 #endif
00605 
00609 YASM_LIB_DECL
00610 void yasm_dvs_delete(yasm_datavalhead *headp);
00611 
00621 YASM_LIB_DECL
00622 /*@null@*/ yasm_dataval *yasm_dvs_append
00623     (yasm_datavalhead *headp, /*@returned@*/ /*@null@*/ yasm_dataval *dv);
00624 
00630 YASM_LIB_DECL
00631 void yasm_dvs_print(const yasm_datavalhead *headp, FILE *f, int indent_level);
00632 
00633 #endif