blob: f723321639f31494cfd952de3cd59a362e47a386 [file] [log] [blame]
PulkoMandy17fc7592022-07-28 18:27:54 +02001/*
2 * Backend for the Fire16 iCE40 SoftCore
3 * (c) 2019 by Sylvain Munaut
4 */
5
6#include "dt.h"
7
8
9/* This struct can be used to implement machine-specific */
10/* addressing-modes. */
11struct AddressingMode {
12 int not_used_yet; // FIXME
13};
14
15/* The number of registers of the target machine. */
16 /* - 16 rN GPR + 8 pairs
17 * - 16 sN GPR + 8 pairs
18 * - A, X, Y, I
19 */
20#define MAXR 52
21
22/* Number of commandline-options the code-generator accepts. */
23#define MAXGF 20
24
25/* If this is set to zero vbcc will not generate ICs where the */
26/* target operand is the same as the 2nd source operand. */
27/* This can sometimes simplify the code-generator, but usually */
28/* the code is better if the code-generator allows it. */
29#define USEQ2ASZ 1
30
31/* This specifies the smallest integer type that can be added to a */
32/* pointer. */
33#define MINADDI2P CHAR
34
35/* This specifies the smallest integer type that can be added to a */
36/* pointer. */
37#define MAXADDI2P INT
38
39/* If the bytes of an integer are ordered most significant byte */
40/* byte first and then decreasing set BIGENDIAN to 1. */
41#define BIGENDIAN 0
42
43/* If the bytes of an integer are ordered lest significant byte */
44/* byte first and then increasing set LITTLEENDIAN to 1. */
45#define LITTLEENDIAN 1
46
47/* Note that BIGENDIAN and LITTLEENDIAN are mutually exclusive. */
48
49/* If switch-statements should be generated as a sequence of */
50/* SUB,TST,BEQ ICs rather than COMPARE,BEQ ICs set this to 1. */
51/* This can yield better code on some machines. */
52#define SWITCHSUBS 0
53
54/* In optimizing compilation certain library memcpy/strcpy-calls */
55/* with length known at compile-time will be inlined using an */
56/* ASSIGN-IC if the size is less or equal to INLINEMEMCPY. */
57/* The type used for the ASSIGN-IC will be UNSIGNED|CHAR. */
58#define INLINEMEMCPY 16
59
60/* Parameters are sometimes passed in registers without __reg. */
61#define HAVE_REGPARMS 1
62
63/* Structure for reg_parm(). */
64struct reg_handle{
65 unsigned long gpr;
66};
67
68/* We have register pairs. */
69#define HAVE_REGPAIRS 1
70
71/* We use unsigned int as size_t rather than unsigned long which */
72/* is the default setting. */
73#define HAVE_INT_SIZET 1
74
75/* We have asm_peephole to optimize assembly-output */
76#define HAVE_TARGET_PEEPHOLE 0 /* FIXME: not yet */
77
78/* We have some target-specific variable attributes. */
79#define HAVE_TARGET_ATTRIBUTES 1
80
81/* We do not have target-specific pragmas */
82#undef HAVE_TARGET_PRAGMAS
83
84/* We keep track of all registers modified by a function. */
85#define HAVE_REGS_MODIFIED 1
86
87/* We have a implement our own cost-functions to adapt
88 register-allocation */
89#if 0 /* FIXME */
90#define HAVE_TARGET_RALLOC 1
91#define cost_move_reg(x,y) XXX
92#define cost_load_reg(x,y) XXX
93#define cost_save_reg(x,y) XXX
94#define cost_pushpop_reg(x) XXX
95#endif
96
97/* we do not have a mark_eff_ics function, this is used to prevent
98 optimizations on code which can already be implemented by efficient
99 assembly */
100#undef HAVE_TARGET_EFF_IC
101
102/* we do not need extra elements in the IC */
103#undef HAVE_EXT_IC
104
105/* we need extended types (for pmem/dmem pointers) */
106#define HAVE_EXT_TYPES 1
107
108#undef CHAR
109#undef SHORT
110#undef INT
111#undef LONG
112#undef LLONG
113#undef FLOAT
114#undef DOUBLE
115#undef LDOUBLE
116#undef VOID
117#undef POINTER
118#undef ARRAY
119#undef STRUCT
120#undef UNION
121#undef ENUM
122#undef FUNKT
123#undef BOOL
124#undef MAXINT
125#undef MAX_TYPE
126
127#define CHAR 1
128#define SHORT 2
129#define INT 3
130#define LONG 4
131#define LLONG 5
132#define FLOAT 6
133#define DOUBLE 7
134#define LDOUBLE 8
135#define VOID 9
136#define DPOINTER 10
137#define PPOINTER 11
138#define ARRAY 12
139#define STRUCT 13
140#define UNION 14
141#define ENUM 15
142#define FUNKT 16
143#define BOOL 17
144#define MAXINT 18
145#define MAX_TYPE MAXINT
146
147#define POINTER_TYPE(x) pointer_type(x)
148extern int pointer_type();
149#define ISPOINTER(x) ((x&NQ)>=DPOINTER&&(x&NQ)<=PPOINTER)
150#define ISSCALAR(x) ((x&NQ)>=CHAR&&(x&NQ)<=PPOINTER)
151#define ISINT(x) ((x&NQ)>=CHAR&&(x&NQ)<=LLONG)
152#define PTRDIFF_T(x) (INT)
153
154typedef zllong zmax;
155typedef zullong zumax;
156
157union atyps{
158 zchar vchar;
159 zuchar vuchar;
160 zshort vshort;
161 zushort vushort;
162 zint vint;
163 zuint vuint;
164 zlong vlong;
165 zulong vulong;
166 zllong vllong;
167 zullong vullong;
168 zmax vmax;
169 zumax vumax;
170 zfloat vfloat;
171 zdouble vdouble;
172 zldouble vldouble;
173};
174
175
176/* we need our own printval */
177#define HAVE_TGT_PRINTVAL 1
178
179/* we want to replace some ICs with libcalls */
180#define HAVE_LIBCALLS 1
181
182/* we much prefer BNE */
183#define HAVE_WANTBNE 1
184
185/* size of buffer for asm-output */
186#define EMIT_BUF_LEN 1024 /* should be enough */
187
188/* number of asm-output lines buffered */
189#define EMIT_BUF_DEPTH 4