targ.c (1741B)
1 #include <stdbool.h> 2 #include <string.h> 3 #include "util.h" 4 #include "cc.h" 5 6 const struct target *targ; 7 8 static const struct target alltargs[] = { 9 { 10 .name = "x86_64-sysv", 11 .typewchar = &typeint, 12 .typevalist = 13 &(struct type){ 14 .kind = TYPEARRAY, 15 .align = 8, 16 .size = 24, 17 .base = 18 &(struct type){ 19 .kind = TYPESTRUCT, 20 .align = 8, 21 .size = 24, 22 }, 23 }, 24 .signedchar = 1, 25 }, 26 { 27 .name = "aarch64", 28 .typevalist = 29 &(struct type){ 30 .kind = TYPESTRUCT, 31 .align = 8, 32 .size = 32, 33 .u.structunion.tag = "va_list", 34 }, 35 .typewchar = &typeuint, 36 }, 37 { 38 .name = "riscv64", 39 .typevalist = 40 &(struct type){ 41 .kind = TYPEPOINTER, 42 .prop = PROPSCALAR, 43 .align = 8, 44 .size = 8, 45 .base = &typevoid, 46 }, 47 .typewchar = &typeint, 48 }, 49 }; 50 51 void 52 targinit(const char *name) 53 { 54 size_t i; 55 enum typequal qual; 56 57 if (!name) { 58 /* TODO: provide a way to set this default */ 59 targ = &alltargs[0]; 60 } 61 for (i = 0; i < countof(alltargs) && !targ; ++i) { 62 if (strcmp(alltargs[i].name, name) == 0) 63 targ = &alltargs[i]; 64 } 65 if (!targ) 66 fatal("unknown target '%s'", name); 67 typechar.u.arith.issigned = targ->signedchar; 68 qual = QUALNONE; 69 typeadjvalist = typeadjust(targ->typevalist, &qual); 70 }