tarval_is_long.c 1.81 KB
Newer Older
Andreas Zwinkau's avatar
Andreas Zwinkau committed
1
2
3
#include <limits.h>
#include <assert.h>

4
#include "firm.h"
Matthias Braun's avatar
Matthias Braun committed
5
#include "panic.h"
Andreas Zwinkau's avatar
Andreas Zwinkau committed
6
7
8
#include "irmode.h"
#include "tv.h"

9
10
11
int main(void)
{
	ir_init();
Andreas Zwinkau's avatar
Andreas Zwinkau committed
12

13
14
15
16
17
	ir_mode *big_s = new_int_mode("big signed", irma_twos_complement,
	                              66, 1, 0);
	ir_mode *big_u = new_int_mode("big signed", irma_twos_complement,
	                              66, 0, 0);

18
19
20
21
22
23
24
25
26
27
28
29
	ir_mode *long_u;
	ir_mode *long_s;
	if (sizeof(long) == 4) {
		long_u = mode_Iu;
		long_s = mode_Is;
	} else if (sizeof(long) == 8) {
		long_u = mode_Lu;
		long_s = mode_Ls;
	} else {
		panic("unexpected long size");
	}
	ir_tarval *ulongmax = get_mode_max(long_u);
30
	assert(tarval_is_long(ulongmax));
31
	ir_tarval *ulongmax_s = tarval_convert_to(ulongmax, long_s);
32
	assert(tarval_is_long(ulongmax_s));
33
	ir_tarval *ulongmax_se = tarval_convert_to(ulongmax_s, big_s);
34
	assert(tarval_is_long(ulongmax_se));
35
	ir_tarval *ulongmax_z = tarval_convert_to(ulongmax_s, big_u);
36
37
	assert(!tarval_is_long(ulongmax_z));

38
39
	ir_tarval *longmax = new_tarval_from_long(LONG_MAX, big_s);
	ir_tarval *longmin = new_tarval_from_long(LONG_MIN, big_s);
40
41
42
	assert(tarval_is_long(longmin));
	assert(tarval_is_long(longmax));

43
	ir_tarval *one      = new_tarval_from_long(1, big_s);
44
45
	ir_tarval *longmaxp = tarval_add(longmax, one);
	assert(!tarval_is_long(longmaxp));
46
	ir_tarval *longmax3 = tarval_sub(longmaxp, one);
47
48
49
50
51
52
53
54
55
56
57
58
	assert(tarval_is_long(longmax3));

	ir_tarval *longmax2 = sizeof(long) == 8 ? get_mode_max(mode_Ls)
	                    : sizeof(long) == 4 ? get_mode_max(mode_Is)
	                    : (panic("unexpected long size"), NULL);
	assert(tarval_is_long(longmax2));
	ir_tarval *longmin2 = sizeof(long) == 8 ? get_mode_min(mode_Ls)
	                    : sizeof(long) == 4 ? get_mode_min(mode_Is)
	                    : (panic("unexpected long size"), NULL);
	assert(tarval_is_long(longmin2));

	return 0;
Andreas Zwinkau's avatar
Andreas Zwinkau committed
59
}