OLD | NEW |
1 /* | 1 /* |
2 * Data (and LEB128) bytecode | 2 * Data (and LEB128) bytecode |
3 * | 3 * |
4 * Copyright (C) 2001-2007 Peter Johnson | 4 * Copyright (C) 2001-2007 Peter Johnson |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
11 * 2. Redistributions in binary form must reproduce the above copyright | 11 * 2. Redistributions in binary form must reproduce the above copyright |
12 * notice, this list of conditions and the following disclaimer in the | 12 * notice, this list of conditions and the following disclaimer in the |
13 * documentation and/or other materials provided with the distribution. | 13 * documentation and/or other materials provided with the distribution. |
14 * | 14 * |
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' | 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' |
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE | 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE |
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 * POSSIBILITY OF SUCH DAMAGE. | 25 * POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 #include "util.h" | 27 #include "util.h" |
28 /*@unused@*/ RCSID("$Id: bc-data.c 2133 2008-10-07 05:59:29Z peter $"); | |
29 | 28 |
30 #include "libyasm-stdint.h" | 29 #include "libyasm-stdint.h" |
31 #include "coretype.h" | 30 #include "coretype.h" |
32 | 31 |
33 #include "errwarn.h" | 32 #include "errwarn.h" |
34 #include "intnum.h" | 33 #include "intnum.h" |
35 #include "expr.h" | 34 #include "expr.h" |
36 #include "value.h" | 35 #include "value.h" |
37 | 36 |
38 #include "bytecode.h" | 37 #include "bytecode.h" |
(...skipping 24 matching lines...) Expand all Loading... |
63 | 62 |
64 int item_size; | 63 int item_size; |
65 } bytecode_data; | 64 } bytecode_data; |
66 | 65 |
67 static void bc_data_destroy(void *contents); | 66 static void bc_data_destroy(void *contents); |
68 static void bc_data_print(const void *contents, FILE *f, int indent_level); | 67 static void bc_data_print(const void *contents, FILE *f, int indent_level); |
69 static void bc_data_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); | 68 static void bc_data_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); |
70 static int bc_data_item_size(yasm_bytecode *bc); | 69 static int bc_data_item_size(yasm_bytecode *bc); |
71 static int bc_data_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, | 70 static int bc_data_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, |
72 void *add_span_data); | 71 void *add_span_data); |
73 static int bc_data_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, | 72 static int bc_data_tobytes(yasm_bytecode *bc, unsigned char **bufp, |
| 73 unsigned char *bufstart, void *d, |
74 yasm_output_value_func output_value, | 74 yasm_output_value_func output_value, |
75 /*@null@*/ yasm_output_reloc_func output_reloc); | 75 /*@null@*/ yasm_output_reloc_func output_reloc); |
76 | 76 |
77 static const yasm_bytecode_callback bc_data_callback = { | 77 static const yasm_bytecode_callback bc_data_callback = { |
78 bc_data_destroy, | 78 bc_data_destroy, |
79 bc_data_print, | 79 bc_data_print, |
80 bc_data_finalize, | 80 bc_data_finalize, |
81 bc_data_item_size, | 81 bc_data_item_size, |
82 bc_data_calc_len, | 82 bc_data_calc_len, |
83 yasm_bc_expand_common, | 83 yasm_bc_expand_common, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 if (!yasm_dv_get_multiple(dv, &multiple)) | 196 if (!yasm_dv_get_multiple(dv, &multiple)) |
197 len *= multiple; | 197 len *= multiple; |
198 | 198 |
199 bc->len += len; | 199 bc->len += len; |
200 } | 200 } |
201 | 201 |
202 return 0; | 202 return 0; |
203 } | 203 } |
204 | 204 |
205 static int | 205 static int |
206 bc_data_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, | 206 bc_data_tobytes(yasm_bytecode *bc, unsigned char **bufp, |
| 207 unsigned char *bufstart, void *d, |
207 yasm_output_value_func output_value, | 208 yasm_output_value_func output_value, |
208 /*@unused@*/ yasm_output_reloc_func output_reloc) | 209 /*@unused@*/ yasm_output_reloc_func output_reloc) |
209 { | 210 { |
210 bytecode_data *bc_data = (bytecode_data *)bc->contents; | 211 bytecode_data *bc_data = (bytecode_data *)bc->contents; |
211 yasm_dataval *dv; | 212 yasm_dataval *dv; |
212 unsigned char *bufp_orig = *bufp; | |
213 yasm_intnum *intn; | 213 yasm_intnum *intn; |
214 unsigned int val_len; | 214 unsigned int val_len; |
215 unsigned long multiple, i; | 215 unsigned long multiple, i; |
216 | 216 |
217 STAILQ_FOREACH(dv, &bc_data->datahead, link) { | 217 STAILQ_FOREACH(dv, &bc_data->datahead, link) { |
218 if (yasm_dv_get_multiple(dv, &multiple) || multiple == 0) | 218 if (yasm_dv_get_multiple(dv, &multiple) || multiple == 0) |
219 continue; | 219 continue; |
220 switch (dv->type) { | 220 switch (dv->type) { |
221 case DV_EMPTY: | 221 case DV_EMPTY: |
222 break; | 222 break; |
223 case DV_VALUE: | 223 case DV_VALUE: |
224 val_len = dv->data.val.size/8; | 224 val_len = dv->data.val.size/8; |
225 for (i=0; i<multiple; i++) { | 225 for (i=0; i<multiple; i++) { |
226 if (output_value(&dv->data.val, *bufp, val_len, | 226 if (output_value(&dv->data.val, *bufp, val_len, |
227 (unsigned long)(*bufp-bufp_orig), bc, 1, | 227 (unsigned long)(*bufp-bufstart), bc, 1, |
228 d)) | 228 d)) |
229 return 1; | 229 return 1; |
230 *bufp += val_len; | 230 *bufp += val_len; |
231 } | 231 } |
232 break; | 232 break; |
233 case DV_RAW: | 233 case DV_RAW: |
234 for (i=0; i<multiple; i++) { | 234 for (i=0; i<multiple; i++) { |
235 memcpy(*bufp, dv->data.raw.contents, dv->data.raw.len); | 235 memcpy(*bufp, dv->data.raw.contents, dv->data.raw.len); |
236 *bufp += dv->data.raw.len; | 236 *bufp += dv->data.raw.len; |
237 } | 237 } |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 yasm_dv_create_reserve(void) | 473 yasm_dv_create_reserve(void) |
474 { | 474 { |
475 yasm_dataval *retval = yasm_xmalloc(sizeof(yasm_dataval)); | 475 yasm_dataval *retval = yasm_xmalloc(sizeof(yasm_dataval)); |
476 | 476 |
477 retval->type = DV_RESERVE; | 477 retval->type = DV_RESERVE; |
478 retval->multiple = NULL; | 478 retval->multiple = NULL; |
479 | 479 |
480 return retval; | 480 return retval; |
481 } | 481 } |
482 | 482 |
| 483 yasm_value * |
| 484 yasm_dv_get_value(yasm_dataval *dv) |
| 485 { |
| 486 if (dv->type != DV_VALUE) |
| 487 return NULL; |
| 488 return &dv->data.val; |
| 489 } |
| 490 |
483 void | 491 void |
484 yasm_dv_set_multiple(yasm_dataval *dv, yasm_expr *e) | 492 yasm_dv_set_multiple(yasm_dataval *dv, yasm_expr *e) |
485 { | 493 { |
486 if (dv->multiple) | 494 if (dv->multiple) |
487 dv->multiple = yasm_expr_create_tree( dv->multiple, YASM_EXPR_MUL, e, | 495 dv->multiple = yasm_expr_create_tree( dv->multiple, YASM_EXPR_MUL, e, |
488 e->line); | 496 e->line); |
489 else | 497 else |
490 dv->multiple = e; | 498 dv->multiple = e; |
491 } | 499 } |
492 | 500 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 case DV_SLEB128: | 591 case DV_SLEB128: |
584 fprintf(f, "%*sSLEB128 value:\n", indent_level, ""); | 592 fprintf(f, "%*sSLEB128 value:\n", indent_level, ""); |
585 yasm_value_print(&cur->data.val, f, indent_level+1); | 593 yasm_value_print(&cur->data.val, f, indent_level+1); |
586 break; | 594 break; |
587 case DV_RESERVE: | 595 case DV_RESERVE: |
588 fprintf(f, "%*sReserved\n", indent_level, ""); | 596 fprintf(f, "%*sReserved\n", indent_level, ""); |
589 break; | 597 break; |
590 } | 598 } |
591 } | 599 } |
592 } | 600 } |
OLD | NEW |