OLD | NEW |
1 /* | 1 /* |
2 * Integer number functions. | 2 * Integer number 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: intnum.c 2133 2008-10-07 05:59:29Z peter $"); | 28 /*@unused@*/ RCSID("$Id: intnum.c 2253 2010-01-01 20:47:58Z peter $"); |
29 | 29 |
30 #include <ctype.h> | 30 #include <ctype.h> |
31 #include <limits.h> | 31 #include <limits.h> |
32 | 32 |
33 #include "coretype.h" | 33 #include "coretype.h" |
34 #include "bitvect.h" | 34 #include "bitvect.h" |
35 #include "file.h" | 35 #include "file.h" |
36 | 36 |
37 #include "errwarn.h" | 37 #include "errwarn.h" |
38 #include "intnum.h" | 38 #include "intnum.h" |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 BitVector_Empty(conv_bv); | 378 BitVector_Empty(conv_bv); |
379 if (bigendian) { | 379 if (bigendian) { |
380 /* TODO */ | 380 /* TODO */ |
381 yasm_internal_error(N_("big endian not implemented")); | 381 yasm_internal_error(N_("big endian not implemented")); |
382 } else { | 382 } else { |
383 for (i = 0; i < srcsize; i++) | 383 for (i = 0; i < srcsize; i++) |
384 BitVector_Chunk_Store(conv_bv, 8, i*8, ptr[i]); | 384 BitVector_Chunk_Store(conv_bv, 8, i*8, ptr[i]); |
385 } | 385 } |
386 | 386 |
387 /* Sign extend if needed */ | 387 /* Sign extend if needed */ |
388 if (srcsize*8 < BITVECT_NATIVE_SIZE && sign && (ptr[i] & 0x80) == 0x80) | 388 if (srcsize*8 < BITVECT_NATIVE_SIZE && sign && (ptr[i-1] & 0x80) == 0x80) |
389 BitVector_Interval_Fill(conv_bv, i*8, BITVECT_NATIVE_SIZE-1); | 389 BitVector_Interval_Fill(conv_bv, i*8, BITVECT_NATIVE_SIZE-1); |
390 | 390 |
391 intnum_frombv(intn, conv_bv); | 391 intnum_frombv(intn, conv_bv); |
392 return intn; | 392 return intn; |
393 } | 393 } |
394 | 394 |
395 yasm_intnum * | 395 yasm_intnum * |
396 yasm_intnum_copy(const yasm_intnum *intn) | 396 yasm_intnum_copy(const yasm_intnum *intn) |
397 { | 397 { |
398 yasm_intnum *n = yasm_xmalloc(sizeof(yasm_intnum)); | 398 yasm_intnum *n = yasm_xmalloc(sizeof(yasm_intnum)); |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 case INTNUM_L: | 1088 case INTNUM_L: |
1089 fprintf(f, "0x%lx", intn->val.l); | 1089 fprintf(f, "0x%lx", intn->val.l); |
1090 break; | 1090 break; |
1091 case INTNUM_BV: | 1091 case INTNUM_BV: |
1092 s = BitVector_to_Hex(intn->val.bv); | 1092 s = BitVector_to_Hex(intn->val.bv); |
1093 fprintf(f, "0x%s", (char *)s); | 1093 fprintf(f, "0x%s", (char *)s); |
1094 yasm_xfree(s); | 1094 yasm_xfree(s); |
1095 break; | 1095 break; |
1096 } | 1096 } |
1097 } | 1097 } |
OLD | NEW |