OLD | NEW |
1 /* | 1 /* |
2 * Align bytecode | 2 * Align bytecode |
3 * | 3 * |
4 * Copyright (C) 2005-2007 Peter Johnson | 4 * Copyright (C) 2005-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-align.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 | 35 |
37 #include "bytecode.h" | 36 #include "bytecode.h" |
38 | 37 |
(...skipping 12 matching lines...) Expand all Loading... |
51 } bytecode_align; | 50 } bytecode_align; |
52 | 51 |
53 static void bc_align_destroy(void *contents); | 52 static void bc_align_destroy(void *contents); |
54 static void bc_align_print(const void *contents, FILE *f, int indent_level); | 53 static void bc_align_print(const void *contents, FILE *f, int indent_level); |
55 static void bc_align_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); | 54 static void bc_align_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); |
56 static int bc_align_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, | 55 static int bc_align_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, |
57 void *add_span_data); | 56 void *add_span_data); |
58 static int bc_align_expand(yasm_bytecode *bc, int span, long old_val, | 57 static int bc_align_expand(yasm_bytecode *bc, int span, long old_val, |
59 long new_val, /*@out@*/ long *neg_thres, | 58 long new_val, /*@out@*/ long *neg_thres, |
60 /*@out@*/ long *pos_thres); | 59 /*@out@*/ long *pos_thres); |
61 static int bc_align_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, | 60 static int bc_align_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_align_callback = { | 65 static const yasm_bytecode_callback bc_align_callback = { |
66 bc_align_destroy, | 66 bc_align_destroy, |
67 bc_align_print, | 67 bc_align_print, |
68 bc_align_finalize, | 68 bc_align_finalize, |
69 NULL, | 69 NULL, |
70 bc_align_calc_len, | 70 bc_align_calc_len, |
71 bc_align_expand, | 71 bc_align_expand, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 yasm_intnum_get_uint(yasm_expr_get_intnum(&align->maxskip, 0)); | 157 yasm_intnum_get_uint(yasm_expr_get_intnum(&align->maxskip, 0)); |
158 if (bc->len > maxskip) { | 158 if (bc->len > maxskip) { |
159 *pos_thres = (long)end-maxskip-1; | 159 *pos_thres = (long)end-maxskip-1; |
160 bc->len = 0; | 160 bc->len = 0; |
161 } | 161 } |
162 } | 162 } |
163 return 1; | 163 return 1; |
164 } | 164 } |
165 | 165 |
166 static int | 166 static int |
167 bc_align_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, | 167 bc_align_tobytes(yasm_bytecode *bc, unsigned char **bufp, |
| 168 unsigned char *bufstart, void *d, |
168 yasm_output_value_func output_value, | 169 yasm_output_value_func output_value, |
169 /*@unused@*/ yasm_output_reloc_func output_reloc) | 170 /*@unused@*/ yasm_output_reloc_func output_reloc) |
170 { | 171 { |
171 bytecode_align *align = (bytecode_align *)bc->contents; | 172 bytecode_align *align = (bytecode_align *)bc->contents; |
172 unsigned long len; | 173 unsigned long len; |
173 unsigned long boundary = | 174 unsigned long boundary = |
174 yasm_intnum_get_uint(yasm_expr_get_intnum(&align->boundary, 0)); | 175 yasm_intnum_get_uint(yasm_expr_get_intnum(&align->boundary, 0)); |
175 | 176 |
176 if (boundary == 0) | 177 if (boundary == 0) |
177 return 0; | 178 return 0; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 { | 236 { |
236 bytecode_align *align = yasm_xmalloc(sizeof(bytecode_align)); | 237 bytecode_align *align = yasm_xmalloc(sizeof(bytecode_align)); |
237 | 238 |
238 align->boundary = boundary; | 239 align->boundary = boundary; |
239 align->fill = fill; | 240 align->fill = fill; |
240 align->maxskip = maxskip; | 241 align->maxskip = maxskip; |
241 align->code_fill = code_fill; | 242 align->code_fill = code_fill; |
242 | 243 |
243 return yasm_bc_create_common(&bc_align_callback, align, line); | 244 return yasm_bc_create_common(&bc_align_callback, align, line); |
244 } | 245 } |
OLD | NEW |