From ce05175372a9ddca1a225db0765ace1127a39293 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Fri, 12 Nov 2021 09:22:01 -0800 Subject: chore: simplified organizational structure --- src/cmd/cc/bits.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/cmd/cc/bits.c (limited to 'src/cmd/cc/bits.c') diff --git a/src/cmd/cc/bits.c b/src/cmd/cc/bits.c new file mode 100644 index 0000000..4b405dc --- /dev/null +++ b/src/cmd/cc/bits.c @@ -0,0 +1,114 @@ +#include "cc.h" + +// ----------------------------------------------------------------------- +// Architecture + +enum +{ + archx64, + numarch, +}; + +// ----------------------------------------------------------------------- +// Types + +/* + * enumerated type specifers + * see https://en.wikipedia.org/wiki/C_data_types + */ +#define VOID X(Tvoid, 2) + +#define BOOL X(Tbool, 3) +#define CHAR X(Tchar, 4) +#define SCHAR X(Tsign|Tchar, 5) +#define UCHAR X(Tunsign|Tchar, 6) + +#define SHORT X(Tshort, 7), X(Tshort|Tint, 7) +#define SSHORT X(Tsign|Tshort, 8), X(Tsign|Tshort|Tint, 8) +#define USHORT X(Tunsign|Tshort, 9), X(Tunsign|Tshort|Tint, 9) + +#define INT X(0, 10), X(Tint, 10) +#define SINT X(Tsign, 11), X(Tsign|Tint, 11) +#define UINT X(Tunsign, 12), X(Tunsign|Tint, 12) + +#define LONG X(Tlong, 13), X(Tlong|Tint, 13) +#define SLONG X(Tsign|Tlong, 14), X(Tsign|Tlong|Tint, 14) +#define ULONG X(Tunsign|Tlong, 15), X(Tunsign|Tlong|Tint, 15) + +#define VLONG X(Tvlong, 16), X(Tvlong|Tint, 16) +#define SVLONG X(Tsign|Tvlong, 17), X(Tsign|Tvlong|Tint, 17) +#define UVLONG X(Tunsign|Tvlong, 18), X(Tunsign|Tvlong|Tint, 18) + +#define FLOAT X(Tfloat, 19) +#define DOUBLE X(Tdouble, 20) +#define LONGDB X(Tlong|Tdouble, 21) +#define COMPLEX X(Tcmplx, 22) +#define IMAGINARY X(Timag, 23) + +/* fixed width definitions */ +#define DEF(sz, aln, mx, sgn) {.size=sz, .align=aln, .max=mx, .sign=sgn } + +#define INT8 DEF(1, 1, 0x7fff, 0) +#define UINT8 DEF(1, 1, 0xffff, 1) + +#define INT16 DEF(2, 2, 0x7fff, 0) +#define UINT16 DEF(2, 2, 0xffff, 1) + +#define INT32 DEF(4, 4, 0x7fffffff, 0) +#define UINT32 DEF(4, 4, 0xffffffff, 1) + +#define INT64 DEF(8, 8, 0x7fffffffffffffff, 0) +#define UINT64 DEF(8, 8, 0xffffffffffffffff, 1) + +/* architecture specific definitions */ +// TODO: max value should be able to take floats +#define TYPES \ + TYPE(DEF(0, 0, 0, 0), VOID) \ + TYPE(INT8, BOOL) \ + TYPE(UINT8, CHAR) \ + TYPE(INT8, SCHAR) \ + TYPE(UINT8, UCHAR) \ + TYPE(INT16, SHORT) \ + TYPE(INT16, SSHORT) \ + TYPE(UINT16, USHORT) \ + TYPE(INT32, INT) \ + TYPE(INT32, SINT) \ + TYPE(UINT32, UINT) \ + TYPE(INT64, LONG) \ + TYPE(INT64, SLONG) \ + TYPE(UINT64, ULONG) \ + TYPE(INT64, VLONG) \ + TYPE(INT64, SVLONG) \ + TYPE(UINT64, UVLONG) \ + TYPE(DEF(4, 4, 0, 0), FLOAT) \ + TYPE(DEF(8, 8, 0, 0), DOUBLE) \ + TYPE(DEF(16, 16, 0, 0), LONGDB) \ + TYPE(DEF(8, 8, 0, 0), COMPLEX) \ + TYPE(DEF(4, 4, 0, 0), IMAGINARY) \ + +Type pointer = {.size=8, .align=8, .max=0xffffffffffffffff, .sign=0}; + +/* pack architecture specific definitions into exported arrays */ +#define TYPE(a, ...) a, +Type basetypes[] = { + { 0 }, /* sentinel value for bad types */ + { 0 }, /* sentinel value for variadic args */ + TYPES +}; +#undef TYPE + +#define TYPE(a, ...) __VA_ARGS__, +#define X(a, b) a +uint64 validtypespec[38] = { + TYPES + Tstruct, Tunion, Tenum, Tname, +}; +#undef X + +#define X(a, b) b +int indextypespec[38] = { + TYPES + -1, -1, -1, -1, +}; +#undef X +#undef TYPE -- cgit v1.2.1