diff options
| author | Michael Forney <mforney@mforney.org> | 2019-04-04 12:05:06 -0700 | 
|---|---|---|
| committer | Michael Forney <mforney@mforney.org> | 2019-04-04 12:27:43 -0700 | 
| commit | 54303c25f3d61ab8696e233bfe5d1d154617a600 (patch) | |
| tree | e48069fd506dd906f0220633488b7f1aa3e55539 | |
| parent | 2d036a019aa2879b092a17b740de3009d7352f74 (diff) | |
| download | cproc-54303c25f3d61ab8696e233bfe5d1d154617a600.tar.xz | |
Merge headers into cc.h
| -rw-r--r-- | backend.h | 41 | ||||
| -rw-r--r-- | cc.h | 512 | ||||
| -rw-r--r-- | decl.c | 10 | ||||
| -rw-r--r-- | decl.h | 53 | ||||
| -rw-r--r-- | deps.mk | 28 | ||||
| -rw-r--r-- | eval.c | 7 | ||||
| -rw-r--r-- | eval.h | 1 | ||||
| -rw-r--r-- | expr.c | 9 | ||||
| -rw-r--r-- | expr.h | 94 | ||||
| -rw-r--r-- | init.c | 7 | ||||
| -rw-r--r-- | init.h | 11 | ||||
| -rw-r--r-- | main.c | 5 | ||||
| -rw-r--r-- | pp.c | 5 | ||||
| -rw-r--r-- | pp.h | 8 | ||||
| -rw-r--r-- | qbe.c | 9 | ||||
| -rw-r--r-- | scan.c | 4 | ||||
| -rw-r--r-- | scan.h | 4 | ||||
| -rw-r--r-- | scope.c | 4 | ||||
| -rw-r--r-- | scope.h | 22 | ||||
| -rw-r--r-- | stmt.c | 9 | ||||
| -rw-r--r-- | stmt.h | 4 | ||||
| -rw-r--r-- | token.c | 3 | ||||
| -rw-r--r-- | token.h | 124 | ||||
| -rw-r--r-- | type.c | 3 | ||||
| -rw-r--r-- | type.h | 125 | 
25 files changed, 539 insertions, 563 deletions
| diff --git a/backend.h b/backend.h deleted file mode 100644 index 2ef3e9a..0000000 --- a/backend.h +++ /dev/null @@ -1,41 +0,0 @@ -struct gotolabel { -	struct value *label; -	_Bool defined; -}; - -struct switchcases { -	void *root; -	struct value *defaultlabel; -}; - -struct repr; -struct decl; -struct expr; -struct init; -struct scope; -struct type; - -struct switchcases *mkswitch(void); -void switchcase(struct switchcases *, uint64_t, struct value *); - -struct value *mkblock(char *); -struct value *mkglobal(char *, _Bool); -struct value *mkintconst(struct repr *, uint64_t); - -uint64_t intconstvalue(struct value *); - -struct func *mkfunc(char *, struct type *, struct scope *); -struct type *functype(struct func *); -void funclabel(struct func *, struct value *); -struct value *funcexpr(struct func *, struct expr *); -void funcjmp(struct func *, struct value *); -void funcjnz(struct func *, struct value *, struct value *, struct value *); -void funcret(struct func *, struct value *); -struct gotolabel *funcgoto(struct func *, char *); -void funcswitch(struct func *, struct value *, struct switchcases *, struct value *); -void funcinit(struct func *, struct decl *, struct init *); - -void emitfunc(struct func *, _Bool); -void emitdata(struct decl *,  struct init *); - -extern struct repr i8, i16, i32, i64, f32, f64; @@ -0,0 +1,512 @@ +/* token */ + +enum tokenkind { +	TNONE, + +	TEOF, +	TNEWLINE, + +	TIDENT, +	TNUMBER, +	TCHARCONST, +	TSTRINGLIT, + +	/* keyword */ +	TAUTO, +	TBREAK, +	TCASE, +	TCHAR, +	TCONST, +	TCONTINUE, +	TDEFAULT, +	TDO, +	TDOUBLE, +	TELSE, +	TENUM, +	TEXTERN, +	TFLOAT, +	TFOR, +	TGOTO, +	TIF, +	TINLINE, +	TINT, +	TLONG, +	TREGISTER, +	TRESTRICT, +	TRETURN, +	TSHORT, +	TSIGNED, +	TSIZEOF, +	TSTATIC, +	TSTRUCT, +	TSWITCH, +	TTYPEDEF, +	TUNION, +	TUNSIGNED, +	TVOID, +	TVOLATILE, +	TWHILE, +	T_ALIGNAS, +	T_ALIGNOF, +	T_ATOMIC, +	T_BOOL, +	T_COMPLEX, +	T_GENERIC, +	T_IMAGINARY, +	T_NORETURN, +	T_STATIC_ASSERT, +	T_THREAD_LOCAL, +	T__TYPEOF__, + +	/* punctuator */ +	TLBRACK, +	TRBRACK, +	TLPAREN, +	TRPAREN, +	TLBRACE, +	TRBRACE, +	TPERIOD, +	TARROW, +	TINC, +	TDEC, +	TBAND, +	TMUL, +	TADD, +	TSUB, +	TBNOT, +	TLNOT, +	TDIV, +	TMOD, +	TSHL, +	TSHR, +	TLESS, +	TGREATER, +	TLEQ, +	TGEQ, +	TEQL, +	TNEQ, +	TXOR, +	TBOR, +	TLAND, +	TLOR, +	TQUESTION, +	TCOLON, +	TSEMICOLON, +	TELLIPSIS, +	TASSIGN, +	TMULASSIGN, +	TDIVASSIGN, +	TMODASSIGN, +	TADDASSIGN, +	TSUBASSIGN, +	TSHLASSIGN, +	TSHRASSIGN, +	TBANDASSIGN, +	TXORASSIGN, +	TBORASSIGN, +	TCOMMA, +	THASH, +	THASHHASH, +}; + +struct location { +	const char *file; +	size_t line, col; +}; + +struct token { +	enum tokenkind kind; +	struct location loc; +	char *lit; +}; + +extern struct token tok; + +void tokprint(const struct token *); +_Noreturn void error(const struct location *, const char *, ...); +struct token; + +/* scan */ + +int scanfrom(const char *file); +void scan(struct token *); +struct location; + +void ppinit(const char *); + +void next(void); +_Bool peek(int); +char *expect(int, const char *); +_Bool consume(int); + +/* type */ + +enum typequal { +	QUALNONE, + +	QUALCONST    = 1<<1, +	QUALRESTRICT = 1<<2, +	QUALVOLATILE = 1<<3, +	QUALATOMIC   = 1<<4, +}; + +enum typekind { +	TYPENONE, + +	TYPEQUALIFIED, +	TYPEVOID, +	TYPEBASIC, +	TYPEPOINTER, +	TYPEARRAY, +	TYPEFUNC, +	TYPESTRUCT, +	TYPEUNION, +}; + +enum typeprop { +	PROPNONE, + +	PROPOBJECT  = 1<<0, +	PROPCHAR    = 1<<1, +	PROPINT     = 1<<2, +	PROPREAL    = 1<<3, +	PROPARITH   = 1<<4, +	PROPSCALAR  = 1<<5, +	PROPAGGR    = 1<<6, +	PROPDERIVED = 1<<7, +	PROPFLOAT   = 1<<8, +}; + +struct param { +	char *name; +	struct type *type; +	struct value *value; +	struct param *next; +}; + +struct bitfield { +	short before;  /* number of bits in the storage unit before the bit-field */ +	short after;   /* number of bits in the storage unit after the bit-field */ +}; + +struct member { +	char *name; +	struct type *type; +	uint64_t offset; +	struct bitfield bits; +	struct member *next; +}; + +struct type { +	enum typekind kind; +	int align; +	uint64_t size; +	struct repr *repr; +	union { +		struct type *base; +		struct list link;  /* used only during construction of type */ +	}; +	_Bool incomplete; +	union { +		struct { +			enum typequal kind; +		} qualified; +		struct { +			enum { +				BASICBOOL, +				BASICCHAR, +				BASICSHORT, +				BASICINT, +				BASICENUM, +				BASICLONG, +				BASICLONGLONG, +				BASICFLOAT, +				BASICDOUBLE, +				BASICLONGDOUBLE, +			} kind; +			_Bool issigned, iscomplex; +		} basic; +		struct { +			uint64_t length; +		} array; +		struct { +			_Bool isprototype, isvararg, isnoreturn, paraminfo; +			struct param *params; +		} func; +		struct { +			char *tag; +			struct member *members; +		} structunion; +	}; +}; + +struct type *mktype(enum typekind); +struct type *mkqualifiedtype(struct type *, enum typequal); +struct type *mkpointertype(struct type *); +struct type *mkarraytype(struct type *, uint64_t); + +_Bool typecompatible(struct type *, struct type *); +_Bool typesame(struct type *, struct type *); +struct type *typecomposite(struct type *, struct type *); +struct type *typeunqual(struct type *, enum typequal *); +struct type *typecommonreal(struct type *, struct type *); +struct type *typeargpromote(struct type *); +struct type *typeintpromote(struct type *); +enum typeprop typeprop(struct type *); +struct member *typemember(struct type *, const char *, uint64_t *); + +struct param *mkparam(char *, struct type *); + +extern struct type typevoid; +extern struct type typebool; +extern struct type typechar, typeschar, typeuchar; +extern struct type typeshort, typeushort; +extern struct type typeint, typeuint; +extern struct type typelong, typeulong; +extern struct type typellong, typeullong; +extern struct type typefloat, typedouble, typelongdouble; +extern struct type typevalist, typevalistptr; + +/* decl */ + +enum declkind { +	DECLTYPE, +	DECLOBJECT, +	DECLFUNC, +	DECLCONST, +	DECLBUILTIN, +}; + +enum linkage { +	LINKNONE, +	LINKINTERN, +	LINKEXTERN, +}; + +enum builtinkind { +	BUILTINALLOCA, +	BUILTINCONSTANTP, +	BUILTININFF, +	BUILTINNANF, +	BUILTINOFFSETOF, +	BUILTINVAARG, +	BUILTINVACOPY, +	BUILTINVAEND, +	BUILTINVALIST, +	BUILTINVASTART, +}; + +struct decl { +	enum declkind kind; +	enum linkage linkage; +	struct type *type; +	struct value *value; + +	/* objects and functions */ +	struct list link; +	int align;  /* may be more strict than type requires */ +	_Bool tentative, defined; + +	/* built-ins */ +	enum builtinkind builtin; +}; + +struct scope; +struct func; + +struct decl *mkdecl(enum declkind, struct type *, enum linkage); +_Bool decl(struct scope *, struct func *); +struct type *typename(struct scope *); + +struct expr; +struct decl *stringdecl(struct expr *); + +void emittentativedefns(void); + +/* scope */ + +struct scope { +	struct hashtable *tags; +	struct hashtable *decls; +	struct value *breaklabel; +	struct value *continuelabel; +	struct switchcases *switchcases; +	struct scope *parent; +}; + +void scopeinit(void); +struct scope *mkscope(struct scope *); +struct scope *delscope(struct scope *); + +struct decl; +void scopeputdecl(struct scope *, const char *, struct decl *); +struct decl *scopegetdecl(struct scope *, const char *, _Bool); + +struct type; +void scopeputtag(struct scope *, const char *, struct type *); +struct type *scopegettag(struct scope *, const char *, _Bool); + +extern struct scope filescope; + +/* expr */ + +enum exprkind { +	/* primary expression */ +	EXPRIDENT, +	EXPRCONST, +	EXPRSTRING, + +	/* postfix expression */ +	EXPRCALL, +	/* member E.M gets transformed to *(typeof(E.M) *)((char *)E + offsetof(typeof(E), M)) */ +	EXPRINCDEC, +	EXPRCOMPOUND, +	/* subscript E1[E2] gets transformed to *((E1)+(E2)) */ + +	EXPRUNARY, +	EXPRCAST, +	EXPRBINARY, +	EXPRCOND, +	EXPRASSIGN, +	EXPRCOMMA, + +	EXPRBUILTIN, +	EXPRTEMP, +}; + +enum exprflags { +	EXPRFLAG_LVAL    = 1<<0, +	EXPRFLAG_DECAYED = 1<<1, +}; + +struct expr { +	enum exprkind kind; +	enum exprflags flags; +	struct type *type; +	struct expr *next; +	union { +		struct { +			struct decl *decl; +		} ident; +		union { +			uint64_t i; +			double f; +		} constant; +		struct { +			char *data; +			size_t size; +		} string; +		struct { +			struct expr *func, *args; +			size_t nargs; +		} call; +		struct { +			struct init *init; +		} compound; +		struct { +			int op; +			_Bool post; +			struct expr *base; +		} incdec; +		struct { +			int op; +			struct expr *base; +		} unary; +		struct { +			struct expr *e; +		} cast; +		struct { +			int op; +			struct expr *l, *r; +		} binary; +		struct { +			struct expr *e, *t, *f; +		} cond; +		struct { +			struct expr *l, *r; +		} assign; +		struct { +			struct expr *exprs; +		} comma; +		struct { +			int kind; +			struct expr *arg; +		} builtin; +		struct value *temp; +	}; +}; + +struct scope; + +struct expr *expr(struct scope *); +struct expr *assignexpr(struct scope *); +uint64_t intconstexpr(struct scope *, _Bool); +void delexpr(struct expr *); + +struct expr *exprconvert(struct expr *, struct type *); + +/* eval */ + +struct expr *eval(struct expr *); + +/* init */ + +struct init { +	uint64_t start, end; +	struct expr *expr; +	struct init *next; +}; + +struct scope; +struct type; + +struct init *mkinit(uint64_t, uint64_t, struct expr *); +struct init *parseinit(struct scope *, struct type *); +struct func; +struct scope; + +void stmt(struct func *, struct scope *); + +/* backend */ + +struct gotolabel { +	struct value *label; +	_Bool defined; +}; + +struct switchcases { +	void *root; +	struct value *defaultlabel; +}; + +struct repr; +struct decl; +struct expr; +struct init; +struct scope; +struct type; + +struct switchcases *mkswitch(void); +void switchcase(struct switchcases *, uint64_t, struct value *); + +struct value *mkblock(char *); +struct value *mkglobal(char *, _Bool); +struct value *mkintconst(struct repr *, uint64_t); + +uint64_t intconstvalue(struct value *); + +struct func *mkfunc(char *, struct type *, struct scope *); +struct type *functype(struct func *); +void funclabel(struct func *, struct value *); +struct value *funcexpr(struct func *, struct expr *); +void funcjmp(struct func *, struct value *); +void funcjnz(struct func *, struct value *, struct value *, struct value *); +void funcret(struct func *, struct value *); +struct gotolabel *funcgoto(struct func *, char *); +void funcswitch(struct func *, struct value *, struct switchcases *, struct value *); +void funcinit(struct func *, struct decl *, struct init *); + +void emitfunc(struct func *, _Bool); +void emitdata(struct decl *,  struct init *); + +extern struct repr i8, i16, i32, i64, f32, f64; @@ -7,16 +7,8 @@  #include <stdlib.h>  #include <string.h>  #include "util.h" -#include "backend.h" -#include "decl.h" -#include "expr.h" +#include "cc.h"  #include "htab.h" -#include "init.h" -#include "pp.h" -#include "scope.h" -#include "stmt.h" -#include "token.h" -#include "type.h"  static struct list tentativedefns = {&tentativedefns, &tentativedefns}; @@ -1,53 +0,0 @@ -enum declkind { -	DECLTYPE, -	DECLOBJECT, -	DECLFUNC, -	DECLCONST, -	DECLBUILTIN, -}; - -enum linkage { -	LINKNONE, -	LINKINTERN, -	LINKEXTERN, -}; - -enum builtinkind { -	BUILTINALLOCA, -	BUILTINCONSTANTP, -	BUILTININFF, -	BUILTINNANF, -	BUILTINOFFSETOF, -	BUILTINVAARG, -	BUILTINVACOPY, -	BUILTINVAEND, -	BUILTINVALIST, -	BUILTINVASTART, -}; - -struct decl { -	enum declkind kind; -	enum linkage linkage; -	struct type *type; -	struct value *value; - -	/* objects and functions */ -	struct list link; -	int align;  /* may be more strict than type requires */ -	_Bool tentative, defined; - -	/* built-ins */ -	enum builtinkind builtin; -}; - -struct scope; -struct func; - -struct decl *mkdecl(enum declkind, struct type *, enum linkage); -_Bool decl(struct scope *, struct func *); -struct type *typename(struct scope *); - -struct expr; -struct decl *stringdecl(struct expr *); - -void emittentativedefns(void); @@ -1,22 +1,18 @@  driver.o: driver.c util.h config.h  util.o: util.c util.h -decl.o: decl.c util.h backend.h decl.h expr.h htab.h init.h pp.h scope.h \ - stmt.h token.h type.h -eval.o: eval.c util.h backend.h decl.h eval.h expr.h token.h type.h -expr.o: expr.c util.h decl.h eval.h expr.h init.h pp.h scope.h token.h \ - type.h +decl.o: decl.c util.h cc.h htab.h +eval.o: eval.c util.h cc.h +expr.o: expr.c util.h cc.h  htab.o: htab.c util.h htab.h -init.o: init.c util.h decl.h expr.h init.h pp.h token.h type.h -main.o: main.c util.h arg.h decl.h pp.h scope.h token.h -pp.o: pp.c util.h pp.h scan.h token.h -scan.o: scan.c util.h scan.h token.h -scope.o: scope.c util.h decl.h htab.h scope.h type.h +init.o: init.c util.h cc.h +main.o: main.c util.h arg.h cc.h +pp.o: pp.c util.h cc.h +scan.o: scan.c util.h cc.h +scope.o: scope.c util.h cc.h htab.h  siphash.o: siphash.c -stmt.o: stmt.c util.h backend.h decl.h expr.h pp.h scope.h stmt.h token.h \ - type.h +stmt.o: stmt.c util.h cc.h  tree.o: tree.c util.h tree.h -token.o: token.c util.h token.h -type.o: type.c util.h backend.h type.h +token.o: token.c util.h cc.h +type.o: type.c util.h cc.h  util.o: util.c util.h -qbe.o: qbe.c util.h backend.h decl.h eval.h expr.h htab.h init.h scope.h \ - token.h tree.h type.h ops.h +qbe.o: qbe.c util.h cc.h htab.h tree.h ops.h @@ -2,12 +2,7 @@  #include <stddef.h>  #include <stdint.h>  #include "util.h" -#include "backend.h" -#include "decl.h" -#include "eval.h" -#include "expr.h" -#include "token.h" -#include "type.h" +#include "cc.h"  static void  binary(struct expr *expr, enum tokenkind op, struct expr *l, struct expr *r) @@ -1 +0,0 @@ -struct expr *eval(struct expr *); @@ -8,14 +8,7 @@  #include <string.h>  #include <strings.h>  #include "util.h" -#include "decl.h" -#include "eval.h" -#include "expr.h" -#include "init.h" -#include "pp.h" -#include "scope.h" -#include "token.h" -#include "type.h" +#include "cc.h"  static struct expr *  mkexpr(enum exprkind k, struct type *t, enum exprflags flags) @@ -1,94 +0,0 @@ -enum exprkind { -	/* primary expression */ -	EXPRIDENT, -	EXPRCONST, -	EXPRSTRING, - -	/* postfix expression */ -	EXPRCALL, -	/* member E.M gets transformed to *(typeof(E.M) *)((char *)E + offsetof(typeof(E), M)) */ -	EXPRINCDEC, -	EXPRCOMPOUND, -	/* subscript E1[E2] gets transformed to *((E1)+(E2)) */ - -	EXPRUNARY, -	EXPRCAST, -	EXPRBINARY, -	EXPRCOND, -	EXPRASSIGN, -	EXPRCOMMA, - -	EXPRBUILTIN, -	EXPRTEMP, -}; - -enum exprflags { -	EXPRFLAG_LVAL    = 1<<0, -	EXPRFLAG_DECAYED = 1<<1, -}; - -struct expr { -	enum exprkind kind; -	enum exprflags flags; -	struct type *type; -	struct expr *next; -	union { -		struct { -			struct decl *decl; -		} ident; -		union { -			uint64_t i; -			double f; -		} constant; -		struct { -			char *data; -			size_t size; -		} string; -		struct { -			struct expr *func, *args; -			size_t nargs; -		} call; -		struct { -			struct init *init; -		} compound; -		struct { -			int op; -			_Bool post; -			struct expr *base; -		} incdec; -		struct { -			int op; -			struct expr *base; -		} unary; -		struct { -			struct expr *e; -		} cast; -		struct { -			int op; -			struct expr *l, *r; -		} binary; -		struct { -			struct expr *e, *t, *f; -		} cond; -		struct { -			struct expr *l, *r; -		} assign; -		struct { -			struct expr *exprs; -		} comma; -		struct { -			int kind; -			struct expr *arg; -		} builtin; -		struct value *temp; -	}; -}; - -struct scope; - -struct expr *expr(struct scope *); -struct expr *assignexpr(struct scope *); -uint64_t intconstexpr(struct scope *, _Bool); -void delexpr(struct expr *); - -struct expr *exprconvert(struct expr *, struct type *); @@ -6,12 +6,7 @@  #include <stdlib.h>  #include <string.h>  #include "util.h" -#include "decl.h" -#include "expr.h" -#include "init.h" -#include "pp.h" -#include "token.h" -#include "type.h" +#include "cc.h"  struct object {  	uint64_t offset; @@ -1,11 +0,0 @@ -struct init { -	uint64_t start, end; -	struct expr *expr; -	struct init *next; -}; - -struct scope; -struct type; - -struct init *mkinit(uint64_t, uint64_t, struct expr *); -struct init *parseinit(struct scope *, struct type *); @@ -5,10 +5,7 @@  #include <stdnoreturn.h>  #include "util.h"  #include "arg.h" -#include "decl.h" -#include "pp.h" -#include "scope.h" -#include "token.h" +#include "cc.h"  static noreturn void  usage(void) @@ -1,12 +1,11 @@  #include <stdarg.h>  #include <stdbool.h> +#include <stdint.h>  #include <stdio.h>  #include <stdlib.h>  #include <string.h>  #include "util.h" -#include "pp.h" -#include "scan.h" -#include "token.h" +#include "cc.h"  static struct token pending; @@ -1,8 +0,0 @@ -struct location; - -void ppinit(const char *); - -void next(void); -_Bool peek(int); -char *expect(int, const char *); -_Bool consume(int); @@ -6,16 +6,9 @@  #include <string.h>  #include <inttypes.h>  #include "util.h" -#include "backend.h" -#include "decl.h" -#include "eval.h" -#include "expr.h" +#include "cc.h"  #include "htab.h" -#include "init.h" -#include "scope.h" -#include "token.h"  #include "tree.h" -#include "type.h"  struct name {  	char *str; @@ -1,12 +1,12 @@  #include <ctype.h>  #include <stdarg.h>  #include <stdbool.h> +#include <stdint.h>  #include <stdio.h>  #include <stdlib.h>  #include <string.h>  #include "util.h" -#include "scan.h" -#include "token.h" +#include "cc.h"  struct buffer {  	char *str; @@ -1,4 +0,0 @@ -struct token; - -int scanfrom(const char *file); -void scan(struct token *); @@ -3,10 +3,8 @@  #include <stdint.h>  #include <string.h>  #include "util.h" -#include "decl.h" +#include "cc.h"  #include "htab.h" -#include "scope.h" -#include "type.h"  struct scope filescope; diff --git a/scope.h b/scope.h deleted file mode 100644 index feb2e8b..0000000 --- a/scope.h +++ /dev/null @@ -1,22 +0,0 @@ -struct scope { -	struct hashtable *tags; -	struct hashtable *decls; -	struct value *breaklabel; -	struct value *continuelabel; -	struct switchcases *switchcases; -	struct scope *parent; -}; - -void scopeinit(void); -struct scope *mkscope(struct scope *); -struct scope *delscope(struct scope *); - -struct decl; -void scopeputdecl(struct scope *, const char *, struct decl *); -struct decl *scopegetdecl(struct scope *, const char *, _Bool); - -struct type; -void scopeputtag(struct scope *, const char *, struct type *); -struct type *scopegettag(struct scope *, const char *, _Bool); - -extern struct scope filescope; @@ -5,14 +5,7 @@  #include <stdlib.h>  #include <string.h>  #include "util.h" -#include "backend.h" -#include "decl.h" -#include "expr.h" -#include "pp.h" -#include "scope.h" -#include "stmt.h" -#include "token.h" -#include "type.h" +#include "cc.h"  static bool  gotolabel(struct func *f) @@ -1,4 +0,0 @@ -struct func; -struct scope; - -void stmt(struct func *, struct scope *); @@ -1,8 +1,9 @@  #include <stdarg.h> +#include <stdint.h>  #include <stdio.h>  #include <stdlib.h>  #include "util.h" -#include "token.h" +#include "cc.h"  struct token tok; diff --git a/token.h b/token.h deleted file mode 100644 index ad19311..0000000 --- a/token.h +++ /dev/null @@ -1,124 +0,0 @@ -enum tokenkind { -	TNONE, - -	TEOF, -	TNEWLINE, - -	TIDENT, -	TNUMBER, -	TCHARCONST, -	TSTRINGLIT, - -	/* keyword */ -	TAUTO, -	TBREAK, -	TCASE, -	TCHAR, -	TCONST, -	TCONTINUE, -	TDEFAULT, -	TDO, -	TDOUBLE, -	TELSE, -	TENUM, -	TEXTERN, -	TFLOAT, -	TFOR, -	TGOTO, -	TIF, -	TINLINE, -	TINT, -	TLONG, -	TREGISTER, -	TRESTRICT, -	TRETURN, -	TSHORT, -	TSIGNED, -	TSIZEOF, -	TSTATIC, -	TSTRUCT, -	TSWITCH, -	TTYPEDEF, -	TUNION, -	TUNSIGNED, -	TVOID, -	TVOLATILE, -	TWHILE, -	T_ALIGNAS, -	T_ALIGNOF, -	T_ATOMIC, -	T_BOOL, -	T_COMPLEX, -	T_GENERIC, -	T_IMAGINARY, -	T_NORETURN, -	T_STATIC_ASSERT, -	T_THREAD_LOCAL, -	T__TYPEOF__, - -	/* punctuator */ -	TLBRACK, -	TRBRACK, -	TLPAREN, -	TRPAREN, -	TLBRACE, -	TRBRACE, -	TPERIOD, -	TARROW, -	TINC, -	TDEC, -	TBAND, -	TMUL, -	TADD, -	TSUB, -	TBNOT, -	TLNOT, -	TDIV, -	TMOD, -	TSHL, -	TSHR, -	TLESS, -	TGREATER, -	TLEQ, -	TGEQ, -	TEQL, -	TNEQ, -	TXOR, -	TBOR, -	TLAND, -	TLOR, -	TQUESTION, -	TCOLON, -	TSEMICOLON, -	TELLIPSIS, -	TASSIGN, -	TMULASSIGN, -	TDIVASSIGN, -	TMODASSIGN, -	TADDASSIGN, -	TSUBASSIGN, -	TSHLASSIGN, -	TSHRASSIGN, -	TBANDASSIGN, -	TXORASSIGN, -	TBORASSIGN, -	TCOMMA, -	THASH, -	THASHHASH, -}; - -struct location { -	const char *file; -	size_t line, col; -}; - -struct token { -	enum tokenkind kind; -	struct location loc; -	char *lit; -}; - -extern struct token tok; - -void tokprint(const struct token *); -_Noreturn void error(const struct location *, const char *, ...); @@ -4,8 +4,7 @@  #include <stdint.h>  #include <string.h>  #include "util.h" -#include "backend.h" -#include "type.h" +#include "cc.h"  struct type typevoid       = {.kind = TYPEVOID, .incomplete = true}; @@ -1,125 +0,0 @@ -enum typequal { -	QUALNONE, - -	QUALCONST    = 1<<1, -	QUALRESTRICT = 1<<2, -	QUALVOLATILE = 1<<3, -	QUALATOMIC   = 1<<4, -}; - -enum typekind { -	TYPENONE, - -	TYPEQUALIFIED, -	TYPEVOID, -	TYPEBASIC, -	TYPEPOINTER, -	TYPEARRAY, -	TYPEFUNC, -	TYPESTRUCT, -	TYPEUNION, -}; - -enum typeprop { -	PROPNONE, - -	PROPOBJECT  = 1<<0, -	PROPCHAR    = 1<<1, -	PROPINT     = 1<<2, -	PROPREAL    = 1<<3, -	PROPARITH   = 1<<4, -	PROPSCALAR  = 1<<5, -	PROPAGGR    = 1<<6, -	PROPDERIVED = 1<<7, -	PROPFLOAT   = 1<<8, -}; - -struct param { -	char *name; -	struct type *type; -	struct value *value; -	struct param *next; -}; - -struct bitfield { -	short before;  /* number of bits in the storage unit before the bit-field */ -	short after;   /* number of bits in the storage unit after the bit-field */ -}; - -struct member { -	char *name; -	struct type *type; -	uint64_t offset; -	struct bitfield bits; -	struct member *next; -}; - -struct type { -	enum typekind kind; -	int align; -	uint64_t size; -	struct repr *repr; -	union { -		struct type *base; -		struct list link;  /* used only during construction of type */ -	}; -	_Bool incomplete; -	union { -		struct { -			enum typequal kind; -		} qualified; -		struct { -			enum { -				BASICBOOL, -				BASICCHAR, -				BASICSHORT, -				BASICINT, -				BASICENUM, -				BASICLONG, -				BASICLONGLONG, -				BASICFLOAT, -				BASICDOUBLE, -				BASICLONGDOUBLE, -			} kind; -			_Bool issigned, iscomplex; -		} basic; -		struct { -			uint64_t length; -		} array; -		struct { -			_Bool isprototype, isvararg, isnoreturn, paraminfo; -			struct param *params; -		} func; -		struct { -			char *tag; -			struct member *members; -		} structunion; -	}; -}; - -struct type *mktype(enum typekind); -struct type *mkqualifiedtype(struct type *, enum typequal); -struct type *mkpointertype(struct type *); -struct type *mkarraytype(struct type *, uint64_t); - -_Bool typecompatible(struct type *, struct type *); -_Bool typesame(struct type *, struct type *); -struct type *typecomposite(struct type *, struct type *); -struct type *typeunqual(struct type *, enum typequal *); -struct type *typecommonreal(struct type *, struct type *); -struct type *typeargpromote(struct type *); -struct type *typeintpromote(struct type *); -enum typeprop typeprop(struct type *); -struct member *typemember(struct type *, const char *, uint64_t *); - -struct param *mkparam(char *, struct type *); - -extern struct type typevoid; -extern struct type typebool; -extern struct type typechar, typeschar, typeuchar; -extern struct type typeshort, typeushort; -extern struct type typeint, typeuint; -extern struct type typelong, typeulong; -extern struct type typellong, typeullong; -extern struct type typefloat, typedouble, typelongdouble; -extern struct type typevalist, typevalistptr; | 
