OLD | NEW |
1 /* | 1 /* |
2 * Incbin bytecode | 2 * Incbin 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-incbin.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 "linemap.h" | 32 #include "linemap.h" |
34 | 33 |
35 #include "errwarn.h" | 34 #include "errwarn.h" |
36 #include "intnum.h" | 35 #include "intnum.h" |
37 #include "expr.h" | 36 #include "expr.h" |
38 #include "value.h" | 37 #include "value.h" |
(...skipping 12 matching lines...) Expand all Loading... |
51 | 50 |
52 /* maximum number of bytes to read (NULL=no limit) */ | 51 /* maximum number of bytes to read (NULL=no limit) */ |
53 /*@only@*/ /*@null@*/ yasm_expr *maxlen; | 52 /*@only@*/ /*@null@*/ yasm_expr *maxlen; |
54 } bytecode_incbin; | 53 } bytecode_incbin; |
55 | 54 |
56 static void bc_incbin_destroy(void *contents); | 55 static void bc_incbin_destroy(void *contents); |
57 static void bc_incbin_print(const void *contents, FILE *f, int indent_level); | 56 static void bc_incbin_print(const void *contents, FILE *f, int indent_level); |
58 static void bc_incbin_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); | 57 static void bc_incbin_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); |
59 static int bc_incbin_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, | 58 static int bc_incbin_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, |
60 void *add_span_data); | 59 void *add_span_data); |
61 static int bc_incbin_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, | 60 static int bc_incbin_tobytes(yasm_bytecode *bc, unsigned char **bufp, |
| 61 unsigned char *bufstart, void *d, |
62 yasm_output_value_func output_value, | 62 yasm_output_value_func output_value, |
63 /*@null@*/ yasm_output_reloc_func output_reloc); | 63 /*@null@*/ yasm_output_reloc_func output_reloc); |
64 | 64 |
65 static const yasm_bytecode_callback bc_incbin_callback = { | 65 static const yasm_bytecode_callback bc_incbin_callback = { |
66 bc_incbin_destroy, | 66 bc_incbin_destroy, |
67 bc_incbin_print, | 67 bc_incbin_print, |
68 bc_incbin_finalize, | 68 bc_incbin_finalize, |
69 NULL, | 69 NULL, |
70 bc_incbin_calc_len, | 70 bc_incbin_calc_len, |
71 yasm_bc_expand_common, | 71 yasm_bc_expand_common, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 } | 188 } |
189 flen -= start; | 189 flen -= start; |
190 if (incbin->maxlen) | 190 if (incbin->maxlen) |
191 if (maxlen < flen) | 191 if (maxlen < flen) |
192 flen = maxlen; | 192 flen = maxlen; |
193 bc->len += flen; | 193 bc->len += flen; |
194 return 0; | 194 return 0; |
195 } | 195 } |
196 | 196 |
197 static int | 197 static int |
198 bc_incbin_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, | 198 bc_incbin_tobytes(yasm_bytecode *bc, unsigned char **bufp, |
| 199 unsigned char *bufstart, void *d, |
199 yasm_output_value_func output_value, | 200 yasm_output_value_func output_value, |
200 /*@unused@*/ yasm_output_reloc_func output_reloc) | 201 /*@unused@*/ yasm_output_reloc_func output_reloc) |
201 { | 202 { |
202 bytecode_incbin *incbin = (bytecode_incbin *)bc->contents; | 203 bytecode_incbin *incbin = (bytecode_incbin *)bc->contents; |
203 FILE *f; | 204 FILE *f; |
204 /*@dependent@*/ /*@null@*/ const yasm_intnum *num; | 205 /*@dependent@*/ /*@null@*/ const yasm_intnum *num; |
205 unsigned long start = 0; | 206 unsigned long start = 0; |
206 | 207 |
207 /* Convert start to integer value */ | 208 /* Convert start to integer value */ |
208 if (incbin->start) { | 209 if (incbin->start) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 yasm_linemap_lookup(linemap, line, &incbin->from, &xline); | 256 yasm_linemap_lookup(linemap, line, &incbin->from, &xline); |
256 | 257 |
257 /*@-mustfree@*/ | 258 /*@-mustfree@*/ |
258 incbin->filename = filename; | 259 incbin->filename = filename; |
259 incbin->start = start; | 260 incbin->start = start; |
260 incbin->maxlen = maxlen; | 261 incbin->maxlen = maxlen; |
261 /*@=mustfree@*/ | 262 /*@=mustfree@*/ |
262 | 263 |
263 return yasm_bc_create_common(&bc_incbin_callback, incbin, line); | 264 return yasm_bc_create_common(&bc_incbin_callback, incbin, line); |
264 } | 265 } |
OLD | NEW |