OLD | NEW |
1 /* | 1 /* |
2 * Value handling | 2 * Value handling |
3 * | 3 * |
4 * Copyright (C) 2006-2007 Peter Johnson | 4 * Copyright (C) 2006-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: value.c 2064 2008-04-14 01:48:02Z peter $"); | 28 /*@unused@*/ RCSID("$Id: value.c 2220 2009-07-24 19:01:35Z peter $"); |
29 | 29 |
30 #include "libyasm-stdint.h" | 30 #include "libyasm-stdint.h" |
31 #include "coretype.h" | 31 #include "coretype.h" |
32 #include "bitvect.h" | 32 #include "bitvect.h" |
33 | 33 |
34 #include "errwarn.h" | 34 #include "errwarn.h" |
35 #include "intnum.h" | 35 #include "intnum.h" |
36 #include "floatnum.h" | 36 #include "floatnum.h" |
37 #include "expr.h" | 37 #include "expr.h" |
38 #include "value.h" | 38 #include "value.h" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 329 } |
330 } | 330 } |
331 break; | 331 break; |
332 case YASM_EXPR_SHR: | 332 case YASM_EXPR_SHR: |
333 /* Okay for single symrec in LHS and constant on RHS. | 333 /* Okay for single symrec in LHS and constant on RHS. |
334 * Single symrecs are not okay on RHS. | 334 * Single symrecs are not okay on RHS. |
335 * If RHS is non-constant, don't allow single symrec on LHS. | 335 * If RHS is non-constant, don't allow single symrec on LHS. |
336 * XXX: should rshift be an expr instead?? | 336 * XXX: should rshift be an expr instead?? |
337 */ | 337 */ |
338 | 338 |
339 /* Check for not allowed cases on RHS */ | 339 /* Check for single sym on LHS */ |
340 switch (e->terms[1].type) { | 340 if (e->terms[0].type != YASM_EXPR_SYM) |
341 case YASM_EXPR_REG: | 341 break; |
342 case YASM_EXPR_FLOAT: | |
343 return 1; /* not legal */ | |
344 case YASM_EXPR_SYM: | |
345 return 1; | |
346 case YASM_EXPR_EXPR: | |
347 if (value_finalize_scan(value, e->terms[1].data.expn, | |
348 expr_precbc, 1)) | |
349 return 1; | |
350 break; | |
351 default: | |
352 break; | |
353 } | |
354 | 342 |
355 /* Check for single sym and allowed cases on LHS */ | 343 /* If we already have a sym, we can't take another one */ |
356 switch (e->terms[0].type) { | 344 if (value->rel || ssym_not_ok) |
357 /*case YASM_EXPR_REG: ????? should this be illegal ????? */ | 345 return 1; |
358 case YASM_EXPR_FLOAT: | |
359 return 1; /* not legal */ | |
360 case YASM_EXPR_SYM: | |
361 if (value->rel || ssym_not_ok) | |
362 return 1; | |
363 value->rel = e->terms[0].data.sym; | |
364 /* and replace with 0 */ | |
365 e->terms[0].type = YASM_EXPR_INT; | |
366 e->terms[0].data.intn = yasm_intnum_create_uint(0); | |
367 break; | |
368 case YASM_EXPR_EXPR: | |
369 /* recurse */ | |
370 if (value_finalize_scan(value, e->terms[0].data.expn, | |
371 expr_precbc, ssym_not_ok)) | |
372 return 1; | |
373 break; | |
374 default: | |
375 break; /* ignore */ | |
376 } | |
377 | 346 |
378 /* Handle RHS */ | 347 /* RHS must be a positive integer */ |
379 if (!value->rel) | |
380 break; /* no handling needed */ | |
381 if (e->terms[1].type != YASM_EXPR_INT) | 348 if (e->terms[1].type != YASM_EXPR_INT) |
382 return 1; /* can't shift sym by non-constant integer */ | 349 return 1; /* can't shift sym by non-constant integer */ |
383 shamt = yasm_intnum_get_uint(e->terms[1].data.intn); | 350 shamt = yasm_intnum_get_uint(e->terms[1].data.intn); |
384 if ((shamt + value->rshift) > YASM_VALUE_RSHIFT_MAX) | 351 if ((shamt + value->rshift) > YASM_VALUE_RSHIFT_MAX) |
385 return 1; /* total shift would be too large */ | 352 return 1; /* total shift would be too large */ |
| 353 |
| 354 /* Update value */ |
386 value->rshift += shamt; | 355 value->rshift += shamt; |
| 356 value->rel = e->terms[0].data.sym; |
| 357 |
| 358 /* Replace symbol with 0 */ |
| 359 e->terms[0].type = YASM_EXPR_INT; |
| 360 e->terms[0].data.intn = yasm_intnum_create_uint(0); |
387 | 361 |
388 /* Just leave SHR in place */ | 362 /* Just leave SHR in place */ |
389 break; | 363 break; |
390 case YASM_EXPR_SEG: | 364 case YASM_EXPR_SEG: |
391 /* Okay for single symrec (can only be done once). | 365 /* Okay for single symrec (can only be done once). |
392 * Not okay for anything BUT a single symrec as an immediate | 366 * Not okay for anything BUT a single symrec as an immediate |
393 * child. | 367 * child. |
394 */ | 368 */ |
395 if (e->terms[0].type != YASM_EXPR_SYM) | 369 if (e->terms[0].type != YASM_EXPR_SYM) |
396 return 1; | 370 return 1; |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 if (value->ip_rel) | 763 if (value->ip_rel) |
790 fprintf(f, "%*s(IP-relative)\n", indent_level, ""); | 764 fprintf(f, "%*s(IP-relative)\n", indent_level, ""); |
791 if (value->jump_target) | 765 if (value->jump_target) |
792 fprintf(f, "%*s(Jump target)\n", indent_level, ""); | 766 fprintf(f, "%*s(Jump target)\n", indent_level, ""); |
793 if (value->section_rel) | 767 if (value->section_rel) |
794 fprintf(f, "%*s(Section-relative)\n", indent_level, ""); | 768 fprintf(f, "%*s(Section-relative)\n", indent_level, ""); |
795 if (value->no_warn) | 769 if (value->no_warn) |
796 fprintf(f, "%*s(Overflow warnings disabled)\n", indent_level, ""); | 770 fprintf(f, "%*s(Overflow warnings disabled)\n", indent_level, ""); |
797 } | 771 } |
798 } | 772 } |
OLD | NEW |