diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/c/bitvector.expect | 20 | ||||
| -rw-r--r-- | test/c/bv_literal.expect | 2 | ||||
| -rw-r--r-- | test/c/gvector.expect | 2 | ||||
| -rw-r--r-- | test/c/return_leak.expect | 0 | ||||
| -rw-r--r-- | test/c/return_leak.sail | 12 | ||||
| -rw-r--r-- | test/c/sail.h | 77 | ||||
| -rw-r--r-- | test/c/struct.expect | 6 |
7 files changed, 100 insertions, 19 deletions
diff --git a/test/c/bitvector.expect b/test/c/bitvector.expect index 9e11e149..e761021d 100644 --- a/test/c/bitvector.expect +++ b/test/c/bitvector.expect @@ -1,10 +1,10 @@ -x = 16'0xBEEF -y = 200'0x0 -z = 16'0xCAFE -zero_extend(z) = 32'0xCAFE -q = 72'0xABFEEDDEADBEEFCAFE -k = 8'0xFF -k + k = 8'0xFE -0xFF + 1 = 8'0x0 -0xFF + 2 = 8'0x1 -0xFF + 3 = 8'0x2 +x = 0xBEEF +y = 0x00000000000000000000000000000000000000000000000000 +z = 0xCAFE +zero_extend(z) = 0x0000CAFE +q = 0xABFEEDDEADBEEFCAFE +k = 0xFF +k + k = 0xFE +0xFF + 1 = 0x00 +0xFF + 2 = 0x01 +0xFF + 3 = 0x02 diff --git a/test/c/bv_literal.expect b/test/c/bv_literal.expect index 78d1026a..33123250 100644 --- a/test/c/bv_literal.expect +++ b/test/c/bv_literal.expect @@ -1 +1 @@ -y = 4'0xD +y = 0xD diff --git a/test/c/gvector.expect b/test/c/gvector.expect index ae7bf842..57176c53 100644 --- a/test/c/gvector.expect +++ b/test/c/gvector.expect @@ -1,3 +1,3 @@ T[1] = 5 y[1] = 5 -R[0] = 32'0xDEADBEEF +R[0] = 0xDEADBEEF diff --git a/test/c/return_leak.expect b/test/c/return_leak.expect new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/c/return_leak.expect diff --git a/test/c/return_leak.sail b/test/c/return_leak.sail new file mode 100644 index 00000000..2e7890f7 --- /dev/null +++ b/test/c/return_leak.sail @@ -0,0 +1,12 @@ +default Order dec + +$include <vector_dec.sail> + +val main : unit -> unit + +function main () = { + x : int = 3; + return (); + x = x; + () +}
\ No newline at end of file diff --git a/test/c/sail.h b/test/c/sail.h index 2363c27e..89aad9ba 100644 --- a/test/c/sail.h +++ b/test/c/sail.h @@ -33,8 +33,8 @@ unit sail_assert(bool b, sail_string msg) { } unit sail_exit(const unit u) { - fprintf(stderr, "Unexpected exit\n"); - exit(1); + fprintf(stderr, "exit\n"); + exit(0); } void elf_entry(mpz_t *rop, const unit u) { @@ -77,6 +77,13 @@ void init_sail_string(sail_string *str) { *str = istr; } +void reinit_sail_string(sail_string *str) { + free(*str); + char *istr = (char *) malloc(1 * sizeof(char)); + istr[0] = '\0'; + *str = istr; +} + void set_sail_string(sail_string *str1, const sail_string str2) { size_t len = strlen(str2); *str1 = realloc(*str1, len + 1); @@ -131,6 +138,10 @@ void init_mpz_t(mpz_t *op) { mpz_init(*op); } +void reinit_mpz_t(mpz_t *op) { + mpz_set_ui(*op, 0); +} + void clear_mpz_t(mpz_t *op) { mpz_clear(*op); } @@ -139,10 +150,18 @@ void init_mpz_t_of_int64_t(mpz_t *rop, int64_t op) { mpz_init_set_si(*rop, op); } +void reinit_mpz_t_of_int64_t(mpz_t *rop, int64_t op) { + mpz_set_si(*rop, op); +} + void init_mpz_t_of_sail_string(mpz_t *rop, sail_string str) { mpz_init_set_str(*rop, str, 10); } +void reinit_mpz_t_of_sail_string(mpz_t *rop, sail_string str) { + mpz_set_str(*rop, str, 10); +} + int64_t convert_int64_t_of_mpz_t(const mpz_t op) { return mpz_get_si(op); } @@ -240,9 +259,37 @@ void pow2(mpz_t *rop, mpz_t exp) { // ***** Sail bitvectors ***** -unit print_bits(const sail_string str, const bv_t op) { +unit print_bits(const sail_string str, const bv_t op) +{ fputs(str, stdout); - gmp_printf("%d'0x%ZX\n", op.len, op.bits); + + if (op.len % 4 == 0) { + fputs("0x", stdout); + mpz_t buf; + mpz_init_set(buf, *op.bits); + + char *hex = malloc((op.len / 4) * sizeof(char)); + + for (int i = 0; i < op.len / 4; ++i) { + char c = (char) ((0xF & mpz_get_ui(buf)) + 0x30); + hex[i] = (c < 0x3A) ? c : c + 0x7; + mpz_fdiv_q_2exp(buf, buf, 4); + } + + for (int i = op.len / 4; i > 0; --i) { + fputc(hex[i - 1], stdout); + } + + free(hex); + mpz_clear(buf); + } else { + fputs("0b", stdout); + for (int i = op.len; i > 0; --i) { + fputc(mpz_tstbit(*op.bits, i - 1) + 0x30, stdout); + } + } + + fputs("\n", stdout); } void length_bv_t(mpz_t *rop, const bv_t op) { @@ -255,12 +302,22 @@ void init_bv_t(bv_t *rop) { mpz_init(*rop->bits); } +void reinit_bv_t(bv_t *rop) { + rop->len = 0; + mpz_set_ui(*rop->bits, 0); +} + void init_bv_t_of_uint64_t(bv_t *rop, const uint64_t op, const uint64_t len, const bool direction) { rop->bits = malloc(sizeof(mpz_t)); rop->len = len; mpz_init_set_ui(*rop->bits, op); } +void reinit_bv_t_of_uint64_t(bv_t *rop, const uint64_t op, const uint64_t len, const bool direction) { + rop->len = len; + mpz_set_ui(*rop->bits, op); +} + void set_bv_t(bv_t *rop, const bv_t op) { rop->len = op.len; mpz_set(*rop->bits, *op.bits); @@ -288,6 +345,14 @@ void replicate_bits(bv_t *rop, const bv_t op1, const mpz_t op2) { } } +uint64_t fast_replicate_bits(const uint64_t shift, const uint64_t v, const int64_t times) { + uint64_t r = 0; + for (int i = 0; i < times; ++i) { + r |= v << shift; + } + return r; +} + void slice(bv_t *rop, const bv_t op, const mpz_t start_mpz, const mpz_t len_mpz) { uint64_t start = mpz_get_ui(start_mpz); @@ -559,6 +624,10 @@ void init_real(real *rop) { mpf_init(*rop); } +void reinit_real(real *rop) { + mpf_set_ui(*rop, 0); +} + void clear_real(real *rop) { mpf_clear(*rop); } diff --git a/test/c/struct.expect b/test/c/struct.expect index ecf6e2e1..a2120904 100644 --- a/test/c/struct.expect +++ b/test/c/struct.expect @@ -1,3 +1,3 @@ -x.A = 4'0x8 -x.A = 4'0xF -(struct {A = 0b1111, B = 0b11} : test).B = 2'0x3 +x.A = 0x8 +x.A = 0xF +(struct {A = 0b1111, B = 0b11} : test).B = 0b11 |
