is needed for the GAS .uleb128 and .sleb128 directives. * intnum.c (yasm_intnum_sign): New signedness discovery function. * intnum.h (yasm_intnum_sign): Prototype. * intnum.c (yasm_intnum_get_leb128, yasm_intnum_size_leb128): New. * intnum.h (yasm_intnum_get_leb128, yasm_intnum_size_leb128): Prototype. * leb128_test.c: New test for intnum-level LEB128 functions. * bytecode.c (bytecode_leb128): New bytecode and supporting functions. (yasm_bc_create_leb128): New creation function. * bytecode.h (yasm_bc_create_leb128): Prototype. * gas-token.re: Recognize .uleb128 and .sleb128. * gas-bison.y: Ditto. (gas_define_leb128): New. * leb128.asm: New test for GAS .uleb128 and .sleb128 directives. svn path=/trunk/yasm/; revision=12870.5.0rc2
parent
8ab7670690
commit
1ddc1272d2
12 changed files with 927 additions and 2 deletions
@ -0,0 +1,159 @@ |
||||
/* $Id$
|
||||
* |
||||
* Copyright (C) 2005 Peter Johnson |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* 1. Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE |
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||||
* POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
#ifdef HAVE_CONFIG_H |
||||
# include <config.h> |
||||
#endif |
||||
|
||||
#ifdef STDC_HEADERS |
||||
# include <stdlib.h> |
||||
# include <string.h> |
||||
#endif |
||||
|
||||
#include <stdio.h> |
||||
|
||||
#include "libyasm/intnum.c" |
||||
|
||||
typedef struct Test_Entry { |
||||
/* signedness (0=unsigned, 1=signed) */ |
||||
int sign; |
||||
|
||||
/* whether input value should be negated */ |
||||
int negate; |
||||
|
||||
/* input value (as hex string) */ |
||||
const char *input; |
||||
|
||||
/* correct size returned from both size_leb128 and get_leb128 */ |
||||
unsigned long outsize; |
||||
|
||||
/* correct return data from get_leb128 */ |
||||
const unsigned char *result; |
||||
} Test_Entry; |
||||
|
||||
static Test_Entry tests[] = { |
||||
/* Unsigned values */ |
||||
{0, 0, "0", 1, (const unsigned char *)"\x00"}, |
||||
{0, 0, "2", 1, (const unsigned char *)"\x02"}, |
||||
{0, 0, "7F", 1, (const unsigned char *)"\x7F"}, |
||||
{0, 0, "80", 2, (const unsigned char *)"\x80\x01"}, |
||||
{0, 0, "81", 2, (const unsigned char *)"\x81\x01"}, |
||||
{0, 0, "82", 2, (const unsigned char *)"\x82\x01"}, |
||||
{0, 0, "3239", 2, (const unsigned char *)"\xB9\x64"}, |
||||
/* Signed zero value */ |
||||
{1, 0, "0", 1, (const unsigned char *)"\x00"}, |
||||
/* Signed positive values */ |
||||
{1, 0, "2", 1, (const unsigned char *)"\x02"}, |
||||
{1, 0, "7F", 2, (const unsigned char *)"\xFF\x00"}, |
||||
{1, 0, "80", 2, (const unsigned char *)"\x80\x01"}, |
||||
{1, 0, "81", 2, (const unsigned char *)"\x81\x01"}, |
||||
/* Signed negative values */ |
||||
{1, 1, "2", 1, (const unsigned char *)"\x7E"}, |
||||
{1, 1, "7F", 2, (const unsigned char *)"\x81\x7F"}, |
||||
{1, 1, "80", 2, (const unsigned char *)"\x80\x7F"}, |
||||
{1, 1, "81", 2, (const unsigned char *)"\xFF\x7E"}, |
||||
}; |
||||
|
||||
static char failed[1000]; |
||||
static char failmsg[100]; |
||||
|
||||
static int |
||||
run_test(Test_Entry *test) |
||||
{ |
||||
char *valstr = yasm__xstrdup(test->input); |
||||
yasm_intnum *intn = yasm_intnum_create_hex(valstr, 0); |
||||
unsigned long size, i; |
||||
unsigned char out[100]; |
||||
int bad; |
||||
|
||||
yasm_xfree(valstr); |
||||
|
||||
if (test->negate) |
||||
yasm_intnum_calc(intn, YASM_EXPR_NEG, NULL, 0); |
||||
|
||||
size = yasm_intnum_size_leb128(intn, test->sign); |
||||
if (size != test->outsize) { |
||||
yasm_intnum_destroy(intn); |
||||
sprintf(failmsg, "%ssigned %s%s size() bad size: expected %lu, got %lu!", |
||||
test->sign?"":"un", test->negate?"-":"", test->input, |
||||
test->outsize, size); |
||||
return 1; |
||||
} |
||||
|
||||
for (i=0; i<sizeof(out); i++) |
||||
out[i] = 0xFF; |
||||
size = yasm_intnum_get_leb128(intn, out, test->sign); |
||||
if (size != test->outsize) { |
||||
yasm_intnum_destroy(intn); |
||||
sprintf(failmsg, "%ssigned %s%s get() bad size: expected %lu, got %lu!", |
||||
test->sign?"":"un", test->negate?"-":"", test->input, |
||||
test->outsize, size); |
||||
return 1; |
||||
} |
||||
|
||||
bad = 0; |
||||
for (i=0; i<test->outsize && !bad; i++) { |
||||
if (out[i] != test->result[i]) |
||||
bad = 1; |
||||
} |
||||
if (bad) { |
||||
yasm_intnum_destroy(intn); |
||||
sprintf(failmsg, "%ssigned %s%s get() bad output!", |
||||
test->sign?"":"un", test->negate?"-":"", test->input); |
||||
return 1; |
||||
} |
||||
|
||||
yasm_intnum_destroy(intn); |
||||
return 0; |
||||
} |
||||
|
||||
int |
||||
main(void) |
||||
{ |
||||
int nf = 0; |
||||
int numtests = sizeof(tests)/sizeof(Test_Entry); |
||||
int i; |
||||
|
||||
if (BitVector_Boot() != ErrCode_Ok) |
||||
return EXIT_FAILURE; |
||||
yasm_intnum_initialize(); |
||||
|
||||
failed[0] = '\0'; |
||||
printf("Test leb128_test: "); |
||||
for (i=0; i<numtests; i++) { |
||||
int fail = run_test(&tests[i]); |
||||
printf("%c", fail>0 ? 'F':'.'); |
||||
fflush(stdout); |
||||
if (fail) |
||||
sprintf(failed, "%s ** F: %s\n", failed, failmsg); |
||||
nf += fail; |
||||
} |
||||
|
||||
yasm_intnum_cleanup(); |
||||
|
||||
printf(" +%d-%d/%d %d%%\n%s", |
||||
numtests-nf, nf, numtests, 100*(numtests-nf)/numtests, failed); |
||||
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
||||
} |
@ -0,0 +1,18 @@ |
||||
.data |
||||
.uleb128 0 |
||||
.uleb128 2 |
||||
.uleb128 127 |
||||
.uleb128 128 |
||||
.uleb128 129 |
||||
.uleb128 130 |
||||
.uleb128 12857 |
||||
|
||||
.sleb128 0 |
||||
.sleb128 2 |
||||
.sleb128 -2 |
||||
.sleb128 127 |
||||
.sleb128 -127 |
||||
.sleb128 128 |
||||
.sleb128 -128 |
||||
.sleb128 129 |
||||
.sleb128 -129 |
@ -0,0 +1,448 @@ |
||||
7f |
||||
45 |
||||
4c |
||||
46 |
||||
01 |
||||
01 |
||||
01 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
01 |
||||
00 |
||||
03 |
||||
00 |
||||
01 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
d0 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
34 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
28 |
||||
00 |
||||
06 |
||||
00 |
||||
01 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
02 |
||||
7f |
||||
80 |
||||
01 |
||||
81 |
||||
01 |
||||
82 |
||||
01 |
||||
b9 |
||||
64 |
||||
00 |
||||
02 |
||||
7e |
||||
ff |
||||
00 |
||||
81 |
||||
7f |
||||
80 |
||||
01 |
||||
80 |
||||
7f |
||||
81 |
||||
01 |
||||
ff |
||||
7e |
||||
00 |
||||
00 |
||||
00 |
||||
2e |
||||
74 |
||||
65 |
||||
78 |
||||
74 |
||||
00 |
||||
2e |
||||
64 |
||||
61 |
||||
74 |
||||
61 |
||||
00 |
||||
2e |
||||
73 |
||||
74 |
||||
72 |
||||
74 |
||||
61 |
||||
62 |
||||
00 |
||||
2e |
||||
73 |
||||
79 |
||||
6d |
||||
74 |
||||
61 |
||||
62 |
||||
00 |
||||
2e |
||||
73 |
||||
68 |
||||
73 |
||||
74 |
||||
72 |
||||
74 |
||||
61 |
||||
62 |
||||
00 |
||||
00 |
||||
00 |
||||
2d |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
01 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
04 |
||||
00 |
||||
f1 |
||||
ff |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
03 |
||||
00 |
||||
05 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
03 |
||||
00 |
||||
04 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
1d |
||||
00 |
||||
00 |
||||
00 |
||||
03 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
5c |
||||
00 |
||||
00 |
||||
00 |
||||
27 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
0d |
||||
00 |
||||
00 |
||||
00 |
||||
03 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
84 |
||||
00 |
||||
00 |
||||
00 |
||||
03 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
15 |
||||
00 |
||||
00 |
||||
00 |
||||
02 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
88 |
||||
00 |
||||
00 |
||||
00 |
||||
40 |
||||
00 |
||||
00 |
||||
00 |
||||
02 |
||||
00 |
||||
00 |
||||
00 |
||||
04 |
||||
00 |
||||
00 |
||||
00 |
||||
04 |
||||
00 |
||||
00 |
||||
00 |
||||
10 |
||||
00 |
||||
00 |
||||
00 |
||||
01 |
||||
00 |
||||
00 |
||||
00 |
||||
01 |
||||
00 |
||||
00 |
||||
00 |
||||
06 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
40 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
10 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
07 |
||||
00 |
||||
00 |
||||
00 |
||||
01 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
40 |
||||
00 |
||||
00 |
||||
00 |
||||
1a |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
04 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
||||
00 |
Loading…
Reference in new issue