aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/cc/cc.h
diff options
context:
space:
mode:
Diffstat (limited to 'sys/cmd/cc/cc.h')
-rw-r--r--sys/cmd/cc/cc.h143
1 files changed, 98 insertions, 45 deletions
diff --git a/sys/cmd/cc/cc.h b/sys/cmd/cc/cc.h
index 1412302..0d4c876 100644
--- a/sys/cmd/cc/cc.h
+++ b/sys/cmd/cc/cc.h
@@ -207,19 +207,22 @@ enum
extern byte *tokens[NUM_TOKENS];
/* TODO: store literals in a big val */
+union Val
+{
+ byte *s;
+ double f;
+ vlong i;
+ uvlong ui;
+ int32 c;
+ uint32 uc;
+ rune r;
+};
+
struct Token
{
- uint32 kind;
- Pos pos;
- union {
- byte *s;
- double f;
- vlong i;
- uvlong ui;
- int32 c;
- uint32 uc;
- rune r;
- } val;
+ uint32 kind;
+ Pos pos;
+ union Val val;
};
enum
@@ -321,10 +324,10 @@ enum
/* conditional */
Xternary,
/* unary prefix ops */
- Xref, Xstar, Xplus, Xminus, Xneg, Xnot, Xsizeof, Xalnof, Xpreinc, Xpredec,
+ Xref, Xstar, Xplus, Xminus, Xneg, Xnot, Xsizeof, Xalignof, Xpreinc, Xpredec,
Xcast,
/* unary postfix ops */
- Xpostinc, Xpostdec, Xindex, Xcall, Xsel, Xcmpndlit,
+ Xpostinc, Xpostdec, Xindex, Xcall, Xselp, Xself, Xcmpdlit,
/* binary ops */
Xoror, Xandand, Xor, Xxor, Xand, Xneq, Xeql, Xgt, Xlt, Xgteq, Xlteq, Xlsft, Xrsft,
Xadd, Xsub, Xmul, Xdiv, Xmod,
@@ -347,12 +350,36 @@ enum
};
/* expressions */
+struct Key
+{
+ /*
+ * NOTE: bitpacked
+ * lower 32 -> index into designator array
+ * upper 32 -> type
+ */
+ uint64 kind;
+ union {
+ Expr *x;
+ string s;
+ };
+};
+
struct Expr
{
- struct Node;
- uint64 type;
+ struct Node;
+ Type *type;
union {
struct {
+ uint64 kind;
+ union Val;
+ } val;
+ struct {
+ int n;
+ struct Key *key;
+ Expr *val;
+ } cmpd;
+ Expr *x;
+ struct {
Expr *l;
Expr *r;
} asn;
@@ -361,13 +388,25 @@ struct Expr
Expr *t;
Expr *e;
} cond;
+ struct {
+ Expr *x;
+ union {
+ Expr *i;
+ string f;
+ };
+ } idx;
+ struct {
+ Expr *fn;
+ int n;
+ Expr **arg;
+ } call;
union {
Expr *pre;
Expr *post;
} unary;
struct {
- uint64 to;
- Expr *x;
+ Type *to;
+ Expr *x;
} cast;
struct {
Expr *l;
@@ -417,33 +456,8 @@ struct Stmt
/* declarations */
-struct Ptr
-{
- uint64 kind;
- Ptr *link;
-};
-
-struct Name
-{
- struct Node;
- union {
- string ident;
- struct Dtor *paren;
- };
- union {
- Expr *i;
- Expr *p;
- };
-};
-
-struct Dtor
-{
- Ptr ptr;
- Name name;
-};
-
-// specifiers
/*
+ * specifiers
* the design is the following:
* type info is held w/in a 64 bit integer.
* the bottom 32 bits are associated to specializations
@@ -510,6 +524,31 @@ enum
Sbad = -1,
};
+struct Ptr
+{
+ uint64 kind;
+ Ptr *link;
+};
+
+struct Name
+{
+ struct Node;
+ union {
+ string ident;
+ struct Dtor *paren;
+ };
+ union {
+ Expr *i;
+ Expr *p;
+ };
+};
+
+struct Dtor
+{
+ Ptr ptr;
+ Name name;
+};
+
struct Decls
{
union {
@@ -538,24 +577,38 @@ struct Decl
};
};
+enum
+{
+ Tbad,
+ Tbase,
+ Tarray,
+ Tptr,
+};
+
/* types */
struct Type
{
Sym *sym;
string ident;
+ uint64 kind;
uintptr size;
uint16 align;
union {
+ Type *ptr;
+ struct {
+ int len;
+ Type *elt;
+ } arr;
struct {
int len;
Dtor *d;
Expr *x;
- } su;
+ } agr;
struct {
int len;
string *s;
Expr *x;
- } en;
+ } enm;
};
};