aboutsummaryrefslogtreecommitdiffhomepage
path: root/targ.c
blob: 7772537575193b028703622c0ae7a68810bc36df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "common.h"

extern const struct mctarg t_amd64_sysv;
static const struct targ {
   const char *name;
   struct { uchar longsize, vlongsize, ptrsize, valistsize; };
   struct { uchar longalign, vlongalign, doublealign, ptralign; };
   bool charsigned;
   uchar sizetype, ptrdifftype;
   const struct mctarg *mctarg;
} targs[] = {
   { "amd64-sysv", {8, 8, 8, 24}, {8, 8, 8, 8}, 1, TYULONG, TYLONG, &t_amd64_sysv },
   { "i686-sysv",  {4, 8, 4,  8}, {4, 4, 4, 4}, 1, TYUINT, TYINT }
};

uchar targ_primsizes[TYPTR+1];
uchar targ_primalign[TYPTR+1];
enum typetag targ_sizetype, targ_ptrdifftype;
bool targ_charsigned, targ_bigendian, targ_64bit;
const struct mctarg *mctarg;

void
targ_init(const char *starg)
{
   const struct targ *t = &targs[0];
   uchar *sizes = targ_primsizes, *align = targ_primalign;

   sizes[TYBOOL] = sizes[TYCHAR] = sizes[TYSCHAR] = sizes[TYUCHAR] = 1;
   sizes[TYSHORT] = sizes[TYUSHORT] = 2;
   sizes[TYUINT] = sizes[TYINT] = 4;
   sizes[TYFLOAT] = 4;
   sizes[TYDOUBLE] = 8;
   memcpy(align, sizes, sizeof targ_primalign);
   sizes[TYULONG] = sizes[TYLONG] = t->longsize;
   sizes[TYUVLONG] = sizes[TYVLONG] = t->vlongsize;
   sizes[TYPTR] = t->ptrsize;
   sizes[TYVALIST] = t->valistsize;
   align[TYULONG] = align[TYLONG] = t->longalign;
   align[TYUVLONG] = align[TYVLONG] = t->vlongalign;
   align[TYDOUBLE] = t->doublealign;
   align[TYVALIST] = align[TYPTR] = t->ptralign;
   targ_sizetype = t->sizetype;
   targ_ptrdifftype = t->ptrdifftype;
   targ_charsigned = t->charsigned;
   targ_bigendian = 0;
   targ_64bit = t->ptrsize == 8;
   mctarg = t->mctarg;
}