OLD | NEW |
1 /* | 1 /* |
2 * Bytecode utility functions | 2 * Bytecode utility functions |
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-reserve.c 2130 2008-10-07 05:38:11Z 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" |
39 | 38 |
40 | 39 |
41 typedef struct bytecode_reserve { | 40 typedef struct bytecode_reserve { |
42 /*@only@*/ /*@null@*/ yasm_expr *numitems; /* number of items to reserve */ | 41 /*@only@*/ /*@null@*/ yasm_expr *numitems; /* number of items to reserve */ |
43 unsigned int itemsize; /* size of each item (in bytes) */ | 42 unsigned int itemsize; /* size of each item (in bytes) */ |
44 } bytecode_reserve; | 43 } bytecode_reserve; |
45 | 44 |
46 static void bc_reserve_destroy(void *contents); | 45 static void bc_reserve_destroy(void *contents); |
47 static void bc_reserve_print(const void *contents, FILE *f, int indent_level); | 46 static void bc_reserve_print(const void *contents, FILE *f, int indent_level); |
48 static void bc_reserve_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); | 47 static void bc_reserve_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); |
49 static int bc_reserve_elem_size(yasm_bytecode *bc); | 48 static int bc_reserve_elem_size(yasm_bytecode *bc); |
50 static int bc_reserve_calc_len(yasm_bytecode *bc, | 49 static int bc_reserve_calc_len(yasm_bytecode *bc, |
51 yasm_bc_add_span_func add_span, | 50 yasm_bc_add_span_func add_span, |
52 void *add_span_data); | 51 void *add_span_data); |
53 static int bc_reserve_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, | 52 static int bc_reserve_tobytes(yasm_bytecode *bc, unsigned char **bufp, |
| 53 unsigned char *bufstart, void *d, |
54 yasm_output_value_func output_value, | 54 yasm_output_value_func output_value, |
55 /*@null@*/ yasm_output_reloc_func output_reloc); | 55 /*@null@*/ yasm_output_reloc_func output_reloc); |
56 | 56 |
57 static const yasm_bytecode_callback bc_reserve_callback = { | 57 static const yasm_bytecode_callback bc_reserve_callback = { |
58 bc_reserve_destroy, | 58 bc_reserve_destroy, |
59 bc_reserve_print, | 59 bc_reserve_print, |
60 bc_reserve_finalize, | 60 bc_reserve_finalize, |
61 bc_reserve_elem_size, | 61 bc_reserve_elem_size, |
62 bc_reserve_calc_len, | 62 bc_reserve_calc_len, |
63 yasm_bc_expand_common, | 63 yasm_bc_expand_common, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 static int | 107 static int |
108 bc_reserve_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, | 108 bc_reserve_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, |
109 void *add_span_data) | 109 void *add_span_data) |
110 { | 110 { |
111 bytecode_reserve *reserve = (bytecode_reserve *)bc->contents; | 111 bytecode_reserve *reserve = (bytecode_reserve *)bc->contents; |
112 bc->len += reserve->itemsize; | 112 bc->len += reserve->itemsize; |
113 return 0; | 113 return 0; |
114 } | 114 } |
115 | 115 |
116 static int | 116 static int |
117 bc_reserve_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, | 117 bc_reserve_tobytes(yasm_bytecode *bc, unsigned char **bufp, |
| 118 unsigned char *bufstart, void *d, |
118 yasm_output_value_func output_value, | 119 yasm_output_value_func output_value, |
119 /*@unused@*/ yasm_output_reloc_func output_reloc) | 120 /*@unused@*/ yasm_output_reloc_func output_reloc) |
120 { | 121 { |
121 yasm_internal_error(N_("bc_reserve_tobytes called")); | 122 yasm_internal_error(N_("bc_reserve_tobytes called")); |
122 /*@notreached@*/ | 123 /*@notreached@*/ |
123 return 1; | 124 return 1; |
124 } | 125 } |
125 | 126 |
126 yasm_bytecode * | 127 yasm_bytecode * |
127 yasm_bc_create_reserve(yasm_expr *numitems, unsigned int itemsize, | 128 yasm_bc_create_reserve(yasm_expr *numitems, unsigned int itemsize, |
(...skipping 14 matching lines...) Expand all Loading... |
142 { | 143 { |
143 bytecode_reserve *reserve; | 144 bytecode_reserve *reserve; |
144 | 145 |
145 if (bc->callback != &bc_reserve_callback) | 146 if (bc->callback != &bc_reserve_callback) |
146 return NULL; | 147 return NULL; |
147 | 148 |
148 reserve = (bytecode_reserve *)bc->contents; | 149 reserve = (bytecode_reserve *)bc->contents; |
149 *itemsize = reserve->itemsize; | 150 *itemsize = reserve->itemsize; |
150 return reserve->numitems; | 151 return reserve->numitems; |
151 } | 152 } |
OLD | NEW |