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 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) ( 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
00095 int (*elem_size) (yasm_bytecode *bc);
00096
00112 int (*calc_len) (yasm_bytecode *bc, yasm_bc_add_span_func add_span,
00113 void *add_span_data);
00114
00136 int (*expand) (yasm_bytecode *bc, int span, long old_val, long new_val,
00137 long *neg_thres, long *pos_thres);
00138
00161 int (*tobytes) (yasm_bytecode *bc, unsigned char **bufp, void *d,
00162 yasm_output_value_func output_value,
00163 yasm_output_reloc_func output_reloc);
00164
00169 enum yasm_bytecode_special_type {
00170 YASM_BC_SPECIAL_NONE = 0,
00171
00173 YASM_BC_SPECIAL_RESERVE,
00174
00176 YASM_BC_SPECIAL_OFFSET,
00177
00179 YASM_BC_SPECIAL_INSN
00180 } special;
00181 } yasm_bytecode_callback;
00182
00184 struct yasm_bytecode {
00188 STAILQ_ENTRY(yasm_bytecode) link;
00189
00193 const yasm_bytecode_callback *callback;
00194
00198 yasm_section *section;
00199
00203 yasm_expr *multiple;
00204
00206 unsigned long len;
00207
00209 long mult_int;
00210
00212 unsigned long line;
00213
00217 unsigned long offset;
00218
00220 unsigned long bc_index;
00221
00225 yasm_symrec **symrecs;
00226
00228 void *contents;
00229 };
00230
00238 YASM_LIB_DECL
00239 yasm_bytecode *yasm_bc_create_common
00240 ( const yasm_bytecode_callback *callback,
00241 void *contents, unsigned long line);
00242
00248 YASM_LIB_DECL
00249 void yasm_bc_transform(yasm_bytecode *bc,
00250 const yasm_bytecode_callback *callback,
00251 void *contents);
00252
00256 YASM_LIB_DECL
00257 void yasm_bc_finalize_common(yasm_bytecode *bc, yasm_bytecode *prev_bc);
00258
00262 YASM_LIB_DECL
00263 int yasm_bc_calc_len_common(yasm_bytecode *bc, yasm_bc_add_span_func add_span,
00264 void *add_span_data);
00265
00270 YASM_LIB_DECL
00271 int yasm_bc_expand_common
00272 (yasm_bytecode *bc, int span, long old_val, long new_val,
00273 long *neg_thres, long *pos_thres);
00274
00278 YASM_LIB_DECL
00279 int yasm_bc_tobytes_common
00280 (yasm_bytecode *bc, unsigned char **bufp, void *d,
00281 yasm_output_value_func output_value,
00282 yasm_output_reloc_func output_reloc);
00283
00288 #define yasm_bc__next(bc) STAILQ_NEXT(bc, link)
00289
00296 YASM_LIB_DECL
00297 void yasm_bc_set_multiple(yasm_bytecode *bc, yasm_expr *e);
00298
00309 YASM_LIB_DECL
00310 yasm_bytecode *yasm_bc_create_data
00311 (yasm_datavalhead *datahead, unsigned int size, int append_zero,
00312 yasm_arch *arch, unsigned long line);
00313
00320 YASM_LIB_DECL
00321 yasm_bytecode *yasm_bc_create_leb128
00322 (yasm_datavalhead *datahead, int sign, unsigned long line);
00323
00330 YASM_LIB_DECL
00331 yasm_bytecode *yasm_bc_create_reserve
00332 ( yasm_expr *numitems, unsigned int itemsize,
00333 unsigned long line);
00334
00342 YASM_LIB_DECL
00343 const yasm_expr *yasm_bc_reserve_numitems
00344 (yasm_bytecode *bc, unsigned int *itemsize);
00345
00356 YASM_LIB_DECL
00357 yasm_bytecode *yasm_bc_create_incbin
00358 ( char *filename, yasm_expr *start,
00359 yasm_expr *maxlen, yasm_linemap *linemap,
00360 unsigned long line);
00361
00374 YASM_LIB_DECL
00375 yasm_bytecode *yasm_bc_create_align
00376 ( yasm_expr *boundary, yasm_expr *fill,
00377 yasm_expr *maxskip,
00378 const unsigned char **code_fill, unsigned long line);
00379
00387 YASM_LIB_DECL
00388 yasm_bytecode *yasm_bc_create_org
00389 (unsigned long start, unsigned long fill, unsigned long line);
00390
00396 YASM_LIB_DECL
00397 yasm_section *yasm_bc_get_section
00398 (yasm_bytecode *bc);
00399
00405 YASM_LIB_DECL
00406 void yasm_bc__add_symrec(yasm_bytecode *bc, yasm_symrec *sym);
00407
00411 YASM_LIB_DECL
00412 void yasm_bc_destroy( yasm_bytecode *bc);
00413
00419 YASM_LIB_DECL
00420 void yasm_bc_print(const yasm_bytecode *bc, FILE *f, int indent_level);
00421
00426 YASM_LIB_DECL
00427 void yasm_bc_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc);
00428
00436 YASM_LIB_DECL
00437 yasm_intnum *yasm_calc_bc_dist
00438 (yasm_bytecode *precbc1, yasm_bytecode *precbc2);
00439
00446 YASM_LIB_DECL
00447 unsigned long yasm_bc_next_offset(yasm_bytecode *precbc);
00448
00455 YASM_LIB_DECL
00456 int yasm_bc_elem_size(yasm_bytecode *bc);
00457
00470 YASM_LIB_DECL
00471 int yasm_bc_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span,
00472 void *add_span_data);
00473
00488 YASM_LIB_DECL
00489 int yasm_bc_expand(yasm_bytecode *bc, int span, long old_val, long new_val,
00490 long *neg_thres, long *pos_thres);
00491
00512 YASM_LIB_DECL
00513 unsigned char *yasm_bc_tobytes
00514 (yasm_bytecode *bc, unsigned char *buf, unsigned long *bufsize,
00515 int *gap, void *d, yasm_output_value_func output_value,
00516 yasm_output_reloc_func output_reloc)
00517 ;
00518
00526 YASM_LIB_DECL
00527 int yasm_bc_get_multiple(yasm_bytecode *bc, long *multiple,
00528 int calc_bc_dist);
00529
00534 YASM_LIB_DECL
00535 const yasm_expr *yasm_bc_get_multiple_expr(const yasm_bytecode *bc);
00536
00542 YASM_LIB_DECL
00543 yasm_insn *yasm_bc_get_insn(yasm_bytecode *bc);
00544
00549 YASM_LIB_DECL
00550 yasm_dataval *yasm_dv_create_expr( yasm_expr *expn);
00551
00557 yasm_dataval *yasm_dv_create_string( char *contents, size_t len);
00558
00564 YASM_LIB_DECL
00565 yasm_dataval *yasm_dv_create_raw( unsigned char *contents,
00566 unsigned long len);
00567
00571 yasm_dataval *yasm_dv_create_reserve(void);
00572
00573 #ifndef YASM_DOXYGEN
00574 #define yasm_dv_create_string(s, l) yasm_dv_create_raw((unsigned char *)(s), \
00575 (unsigned long)(l))
00576 #endif
00577
00584 void yasm_dv_set_multiple(yasm_dataval *dv, yasm_expr *e);
00585
00591 int yasm_dv_get_multiple(yasm_dataval *dv, unsigned long *multiple);
00592
00596 void yasm_dvs_initialize(yasm_datavalhead *headp);
00597 #ifndef YASM_DOXYGEN
00598 #define yasm_dvs_initialize(headp) STAILQ_INIT(headp)
00599 #endif
00600
00604 YASM_LIB_DECL
00605 void yasm_dvs_delete(yasm_datavalhead *headp);
00606
00616 YASM_LIB_DECL
00617 yasm_dataval *yasm_dvs_append
00618 (yasm_datavalhead *headp, yasm_dataval *dv);
00619
00625 YASM_LIB_DECL
00626 void yasm_dvs_print(const yasm_datavalhead *headp, FILE *f, int indent_level);
00627
00628 #endif