libyasm/bytecode.h

Go to the documentation of this file.
00001 
00034 #ifndef YASM_BYTECODE_H
00035 #define YASM_BYTECODE_H
00036 
00037 #ifndef YASM_LIB_DECL
00038 #define YASM_LIB_DECL
00039 #endif
00040 
00042 typedef struct yasm_dataval yasm_dataval;
00044 typedef struct yasm_datavalhead yasm_datavalhead;
00045 
00047 /*@reldef@*/ STAILQ_HEAD(yasm_datavalhead, yasm_dataval);
00048 
00059 typedef void (*yasm_bc_add_span_func)
00060     (void *add_span_data, yasm_bytecode *bc, int id, const yasm_value *value,
00061      long neg_thres, long pos_thres);
00062 
00067 typedef struct yasm_bytecode_callback {
00072     void (*destroy) (/*@only@*/ void *contents);
00073 
00080     void (*print) (const void *contents, FILE *f, int indent_level);
00081 
00087     void (*finalize) (yasm_bytecode *bc, yasm_bytecode *prev_bc);
00088 
00104     int (*calc_len) (yasm_bytecode *bc, yasm_bc_add_span_func add_span,
00105                      void *add_span_data);
00106 
00128     int (*expand) (yasm_bytecode *bc, int span, long old_val, long new_val,
00129                    /*@out@*/ long *neg_thres, /*@out@*/ long *pos_thres);
00130 
00153     int (*tobytes) (yasm_bytecode *bc, unsigned char **bufp, void *d,
00154                     yasm_output_value_func output_value,
00155                     /*@null@*/ yasm_output_reloc_func output_reloc);
00156 
00161     enum yasm_bytecode_special_type {
00162         YASM_BC_SPECIAL_NONE = 0,
00163 
00165         YASM_BC_SPECIAL_RESERVE,
00166 
00168         YASM_BC_SPECIAL_OFFSET,
00169 
00171         YASM_BC_SPECIAL_INSN
00172     } special;
00173 } yasm_bytecode_callback;
00174 
00176 struct yasm_bytecode {
00180     /*@reldef@*/ STAILQ_ENTRY(yasm_bytecode) link;
00181 
00185     /*@null@*/ const yasm_bytecode_callback *callback;
00186 
00190     /*@dependent@*/ /*@null@*/ yasm_section *section;
00191 
00195     /*@only@*/ /*@null@*/ yasm_expr *multiple;
00196 
00198     unsigned long len;
00199 
00201     long mult_int;
00202 
00204     unsigned long line;
00205 
00209     unsigned long offset;
00210 
00212     unsigned long bc_index;
00213 
00217     /*@null@*/ yasm_symrec **symrecs;
00218 
00220     void *contents;
00221 };
00222 
00230 YASM_LIB_DECL
00231 /*@only@*/ yasm_bytecode *yasm_bc_create_common
00232     (/*@null@*/ const yasm_bytecode_callback *callback,
00233      /*@only@*/ /*@null@*/ void *contents, unsigned long line);
00234 
00240 YASM_LIB_DECL
00241 void yasm_bc_transform(yasm_bytecode *bc,
00242                        const yasm_bytecode_callback *callback,
00243                        void *contents);
00244 
00248 YASM_LIB_DECL
00249 void yasm_bc_finalize_common(yasm_bytecode *bc, yasm_bytecode *prev_bc);
00250 
00254 YASM_LIB_DECL
00255 int yasm_bc_calc_len_common(yasm_bytecode *bc, yasm_bc_add_span_func add_span,
00256                             void *add_span_data);
00257 
00262 YASM_LIB_DECL
00263 int yasm_bc_expand_common
00264     (yasm_bytecode *bc, int span, long old_val, long new_val,
00265      /*@out@*/ long *neg_thres, /*@out@*/ long *pos_thres);
00266 
00270 YASM_LIB_DECL
00271 int yasm_bc_tobytes_common
00272     (yasm_bytecode *bc, unsigned char **bufp, void *d,
00273      yasm_output_value_func output_value,
00274      /*@null@*/ yasm_output_reloc_func output_reloc);
00275 
00280 #define yasm_bc__next(bc)               STAILQ_NEXT(bc, link)
00281 
00288 YASM_LIB_DECL
00289 void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e);
00290 
00301 YASM_LIB_DECL
00302 /*@only@*/ yasm_bytecode *yasm_bc_create_data
00303     (yasm_datavalhead *datahead, unsigned int size, int append_zero,
00304      /*@null@*/ yasm_arch *arch, unsigned long line);
00305 
00312 YASM_LIB_DECL
00313 /*@only@*/ yasm_bytecode *yasm_bc_create_leb128
00314     (yasm_datavalhead *datahead, int sign, unsigned long line);
00315 
00322 YASM_LIB_DECL
00323 /*@only@*/ yasm_bytecode *yasm_bc_create_reserve
00324     (/*@only@*/ yasm_expr *numitems, unsigned int itemsize,
00325      unsigned long line);
00326 
00334 YASM_LIB_DECL
00335 /*@null@*/ const yasm_expr *yasm_bc_reserve_numitems
00336     (yasm_bytecode *bc, /*@out@*/ unsigned int *itemsize);
00337 
00348 YASM_LIB_DECL
00349 /*@only@*/ yasm_bytecode *yasm_bc_create_incbin
00350     (/*@only@*/ char *filename, /*@only@*/ /*@null@*/ yasm_expr *start,
00351      /*@only@*/ /*@null@*/ yasm_expr *maxlen, yasm_linemap *linemap,
00352      unsigned long line);
00353 
00366 YASM_LIB_DECL
00367 /*@only@*/ yasm_bytecode *yasm_bc_create_align
00368     (/*@keep@*/ yasm_expr *boundary, /*@keep@*/ /*@null@*/ yasm_expr *fill,
00369      /*@keep@*/ /*@null@*/ yasm_expr *maxskip,
00370      /*@null@*/ const unsigned char **code_fill, unsigned long line);
00371 
00379 YASM_LIB_DECL
00380 /*@only@*/ yasm_bytecode *yasm_bc_create_org
00381     (unsigned long start, unsigned long fill, unsigned long line);
00382 
00388 YASM_LIB_DECL
00389 /*@dependent@*/ /*@null@*/ yasm_section *yasm_bc_get_section
00390     (yasm_bytecode *bc);
00391 
00397 YASM_LIB_DECL
00398 void yasm_bc__add_symrec(yasm_bytecode *bc, /*@dependent@*/ yasm_symrec *sym);
00399 
00403 YASM_LIB_DECL
00404 void yasm_bc_destroy(/*@only@*/ /*@null@*/ yasm_bytecode *bc);
00405 
00411 YASM_LIB_DECL
00412 void yasm_bc_print(const yasm_bytecode *bc, FILE *f, int indent_level);
00413 
00418 YASM_LIB_DECL
00419 void yasm_bc_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc);
00420 
00428 YASM_LIB_DECL
00429 /*@null@*/ /*@only@*/ yasm_intnum *yasm_calc_bc_dist
00430     (yasm_bytecode *precbc1, yasm_bytecode *precbc2);
00431 
00438 YASM_LIB_DECL
00439 unsigned long yasm_bc_next_offset(yasm_bytecode *precbc);
00440 
00453 YASM_LIB_DECL
00454 int yasm_bc_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span,
00455                      void *add_span_data);
00456 
00471 YASM_LIB_DECL
00472 int yasm_bc_expand(yasm_bytecode *bc, int span, long old_val, long new_val,
00473                    /*@out@*/ long *neg_thres, /*@out@*/ long *pos_thres);
00474 
00495 YASM_LIB_DECL
00496 /*@null@*/ /*@only@*/ unsigned char *yasm_bc_tobytes
00497     (yasm_bytecode *bc, unsigned char *buf, unsigned long *bufsize,
00498      /*@out@*/ int *gap, void *d, yasm_output_value_func output_value,
00499      /*@null@*/ yasm_output_reloc_func output_reloc)
00500     /*@sets *buf@*/;
00501 
00509 YASM_LIB_DECL
00510 int yasm_bc_get_multiple(yasm_bytecode *bc, /*@out@*/ long *multiple,
00511                          int calc_bc_dist);
00512 
00517 YASM_LIB_DECL
00518 const yasm_expr *yasm_bc_get_multiple_expr(const yasm_bytecode *bc);
00519 
00525 YASM_LIB_DECL
00526 /*@dependent@*/ /*@null@*/ yasm_insn *yasm_bc_get_insn(yasm_bytecode *bc);
00527 
00532 YASM_LIB_DECL
00533 yasm_dataval *yasm_dv_create_expr(/*@keep@*/ yasm_expr *expn);
00534 
00540 yasm_dataval *yasm_dv_create_string(/*@keep@*/ char *contents, size_t len);
00541 
00547 YASM_LIB_DECL
00548 yasm_dataval *yasm_dv_create_raw(/*@keep@*/ unsigned char *contents,
00549                                  unsigned long len);
00550 
00551 #ifndef YASM_DOXYGEN
00552 #define yasm_dv_create_string(s, l) yasm_dv_create_raw((unsigned char *)(s), \
00553                                                        (unsigned long)(l))
00554 #endif
00555 
00559 void yasm_dvs_initialize(yasm_datavalhead *headp);
00560 #ifndef YASM_DOXYGEN
00561 #define yasm_dvs_initialize(headp)      STAILQ_INIT(headp)
00562 #endif
00563 
00567 YASM_LIB_DECL
00568 void yasm_dvs_delete(yasm_datavalhead *headp);
00569 
00579 YASM_LIB_DECL
00580 /*@null@*/ yasm_dataval *yasm_dvs_append
00581     (yasm_datavalhead *headp, /*@returned@*/ /*@null@*/ yasm_dataval *dv);
00582 
00588 YASM_LIB_DECL
00589 void yasm_dvs_print(const yasm_datavalhead *headp, FILE *f, int indent_level);
00590 
00591 #endif

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