OLD | NEW |
1 /** | 1 /** |
2 * \file libyasm/bytecode.h | 2 * \file libyasm/bytecode.h |
3 * \brief YASM bytecode interface. | 3 * \brief YASM bytecode interface. |
4 * | 4 * |
5 * \rcs | |
6 * $Id: bytecode.h 2130 2008-10-07 05:38:11Z peter $ | |
7 * \endrcs | |
8 * | |
9 * \license | 5 * \license |
10 * Copyright (C) 2001-2007 Peter Johnson | 6 * Copyright (C) 2001-2007 Peter Johnson |
11 * | 7 * |
12 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
13 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
14 * are met: | 10 * are met: |
15 * - Redistributions of source code must retain the above copyright | 11 * - Redistributions of source code must retain the above copyright |
16 * notice, this list of conditions and the following disclaimer. | 12 * notice, this list of conditions and the following disclaimer. |
17 * - Redistributions in binary form must reproduce the above copyright | 13 * - Redistributions in binary form must reproduce the above copyright |
18 * notice, this list of conditions and the following disclaimer in the | 14 * notice, this list of conditions and the following disclaimer in the |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 * Called from yasm_bc_tobytes(). | 136 * Called from yasm_bc_tobytes(). |
141 * A generic fill-in for this is yasm_bc_tobytes_common(), but as this | 137 * A generic fill-in for this is yasm_bc_tobytes_common(), but as this |
142 * function internal errors when called, be very careful when using it! | 138 * function internal errors when called, be very careful when using it! |
143 * \param bc bytecode | 139 * \param bc bytecode |
144 * \param bufp byte representation destination buffer; | 140 * \param bufp byte representation destination buffer; |
145 * should be incremented as it's written to, | 141 * should be incremented as it's written to, |
146 * so that on return its delta from the | 142 * so that on return its delta from the |
147 * passed-in buf matches the bytecode length | 143 * passed-in buf matches the bytecode length |
148 * (it's okay not to do this if an error | 144 * (it's okay not to do this if an error |
149 * indication is returned) | 145 * indication is returned) |
| 146 * \param bufstart For calculating the correct offset parameter for |
| 147 * the \a output_value calls: *bufp - bufstart. |
150 * \param d data to pass to each call to | 148 * \param d data to pass to each call to |
151 * output_value/output_reloc | 149 * output_value/output_reloc |
152 * \param output_value function to call to convert values into their byte | 150 * \param output_value function to call to convert values into their byte |
153 * representation | 151 * representation |
154 * \param output_reloc function to call to output relocation entries | 152 * \param output_reloc function to call to output relocation entries |
155 * for a single sym | 153 * for a single sym |
156 * \return Nonzero on error, 0 on success. | 154 * \return Nonzero on error, 0 on success. |
157 * \note May result in non-reversible changes to the bytecode, but it's | 155 * \note May result in non-reversible changes to the bytecode, but it's |
158 * preferable if calling this function twice would result in the | 156 * preferable if calling this function twice would result in the |
159 * same output. | 157 * same output. |
160 */ | 158 */ |
161 int (*tobytes) (yasm_bytecode *bc, unsigned char **bufp, void *d, | 159 int (*tobytes) (yasm_bytecode *bc, unsigned char **bufp, |
| 160 unsigned char *bufstart, void *d, |
162 yasm_output_value_func output_value, | 161 yasm_output_value_func output_value, |
163 /*@null@*/ yasm_output_reloc_func output_reloc); | 162 /*@null@*/ yasm_output_reloc_func output_reloc); |
164 | 163 |
165 /** Special bytecode classifications. Most bytecode types should use | 164 /** Special bytecode classifications. Most bytecode types should use |
166 * #YASM_BC_SPECIAL_NONE. Others cause special handling to kick in | 165 * #YASM_BC_SPECIAL_NONE. Others cause special handling to kick in |
167 * in various parts of yasm. | 166 * in various parts of yasm. |
168 */ | 167 */ |
169 enum yasm_bytecode_special_type { | 168 enum yasm_bytecode_special_type { |
170 YASM_BC_SPECIAL_NONE = 0, | 169 YASM_BC_SPECIAL_NONE = 0, |
171 | 170 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 YASM_LIB_DECL | 269 YASM_LIB_DECL |
271 int yasm_bc_expand_common | 270 int yasm_bc_expand_common |
272 (yasm_bytecode *bc, int span, long old_val, long new_val, | 271 (yasm_bytecode *bc, int span, long old_val, long new_val, |
273 /*@out@*/ long *neg_thres, /*@out@*/ long *pos_thres); | 272 /*@out@*/ long *neg_thres, /*@out@*/ long *pos_thres); |
274 | 273 |
275 /** Common bytecode callback tobytes function, for where the bytecode | 274 /** Common bytecode callback tobytes function, for where the bytecode |
276 * cannot be converted to bytes. Causes an internal error if called. | 275 * cannot be converted to bytes. Causes an internal error if called. |
277 */ | 276 */ |
278 YASM_LIB_DECL | 277 YASM_LIB_DECL |
279 int yasm_bc_tobytes_common | 278 int yasm_bc_tobytes_common |
280 (yasm_bytecode *bc, unsigned char **bufp, void *d, | 279 (yasm_bytecode *bc, unsigned char **bufp, unsigned char *bufstart, void *d, |
281 yasm_output_value_func output_value, | 280 yasm_output_value_func output_value, |
282 /*@null@*/ yasm_output_reloc_func output_reloc); | 281 /*@null@*/ yasm_output_reloc_func output_reloc); |
283 | 282 |
284 /** Get the next bytecode in a linked list of bytecodes. | 283 /** Get the next bytecode in a linked list of bytecodes. |
285 * \param bc bytecode | 284 * \param bc bytecode |
286 * \return Next bytecode. | 285 * \return Next bytecode. |
287 */ | 286 */ |
288 #define yasm_bc__next(bc) STAILQ_NEXT(bc, link) | 287 #define yasm_bc__next(bc) STAILQ_NEXT(bc, link) |
289 | 288 |
290 /** Set multiple field of a bytecode. | 289 /** Set multiple field of a bytecode. |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 /** Create a new uninitialized data value. | 567 /** Create a new uninitialized data value. |
569 * \return Newly allocated data value. | 568 * \return Newly allocated data value. |
570 */ | 569 */ |
571 yasm_dataval *yasm_dv_create_reserve(void); | 570 yasm_dataval *yasm_dv_create_reserve(void); |
572 | 571 |
573 #ifndef YASM_DOXYGEN | 572 #ifndef YASM_DOXYGEN |
574 #define yasm_dv_create_string(s, l) yasm_dv_create_raw((unsigned char *)(s), \ | 573 #define yasm_dv_create_string(s, l) yasm_dv_create_raw((unsigned char *)(s), \ |
575 (unsigned long)(l)) | 574 (unsigned long)(l)) |
576 #endif | 575 #endif |
577 | 576 |
| 577 /** Get the underlying value of a data value. |
| 578 * \param dv data value |
| 579 * \return Value, or null if non-value (e.g. string or raw). |
| 580 */ |
| 581 yasm_value *yasm_dv_get_value(yasm_dataval *dv); |
| 582 |
578 /** Set multiple field of a data value. | 583 /** Set multiple field of a data value. |
579 * A data value can be repeated a number of times when output. This function | 584 * A data value can be repeated a number of times when output. This function |
580 * sets that multiple. | 585 * sets that multiple. |
581 * \param dv data value | 586 * \param dv data value |
582 * \param e multiple (kept, do not free) | 587 * \param e multiple (kept, do not free) |
583 */ | 588 */ |
584 void yasm_dv_set_multiple(yasm_dataval *dv, /*@keep@*/ yasm_expr *e); | 589 void yasm_dv_set_multiple(yasm_dataval *dv, /*@keep@*/ yasm_expr *e); |
585 | 590 |
586 /** Get the data value multiple value as an unsigned long integer. | 591 /** Get the data value multiple value as an unsigned long integer. |
587 * \param dv data value | 592 * \param dv data value |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 | 624 |
620 /** Print a data value list. For debugging purposes. | 625 /** Print a data value list. For debugging purposes. |
621 * \param f file | 626 * \param f file |
622 * \param indent_level indentation level | 627 * \param indent_level indentation level |
623 * \param headp data value list | 628 * \param headp data value list |
624 */ | 629 */ |
625 YASM_LIB_DECL | 630 YASM_LIB_DECL |
626 void yasm_dvs_print(const yasm_datavalhead *headp, FILE *f, int indent_level); | 631 void yasm_dvs_print(const yasm_datavalhead *headp, FILE *f, int indent_level); |
627 | 632 |
628 #endif | 633 #endif |
OLD | NEW |