shithub: scc

Download patch

ref: c3b7e1ffbcbbdcd7049c150319db145bcca6cf6f
parent: 9ec827fe1ceba3de3209e235fcb8a65382baf4bb
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Mar 28 13:15:01 EDT 2014

Unify headers

We were using too much headers, and in the end we where including
all of them, so it was a not good idea. This patch reduces allmost of
them only to cc.h.

--- a/cc.h
+++ b/cc.h
@@ -1,6 +1,10 @@
 #ifndef CC_H
 #define CC_H
 
+#ifndef __bool_true_and_false_defined
+#include <stdbool.h>
+#endif
+
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
 
 extern unsigned linenum;
@@ -26,4 +30,176 @@
 extern void *xcalloc(size_t nmemb, size_t size);
 extern char *xstrdup(const char *s);
 extern void *xrealloc(void *buff, register size_t size);
+
+#define CTX_OUTER 0
+#define CTX_FUNC  1
+
+enum {
+	NS_IDEN = 0,
+	NS_LABEL,
+	NS_TAG,
+	NR_NAMESPACES,
+	NS_KEYWORD,
+	NS_FREE
+};
+
+struct funpars;
+struct symbol;
+
+struct ctype {
+	uint8_t op;           /* type builder operator */
+	short size;           /* size of variables */
+	short nelem;          /* number of elements in arrays */
+	unsigned defined : 1; /* type defined (is not a forward reference) */
+	unsigned cplex : 1;   /* complex specifier */
+	unsigned imag : 1;
+	unsigned sign : 1;    /* sign type */
+	struct symbol *sym;   /* symbol of the tag identifier */
+	struct ctype *type;   /* base type */
+	struct ctype *next;   /* next element in the hash */
+	union {
+		struct funpar *pars;  /* function parameters */
+		struct field *fields; /* aggregate fields */
+	} u;
+};
+
+struct field {
+	struct symbol *sym;
+	struct field *next;
+};
+
+struct funpar {
+	struct ctype *type;
+	struct funpar *next;
+};
+
+union value {
+	char c;
+	int i;
+	struct symbol *sym;
+	uint8_t ns, token;
+	short offset;
+};
+
+struct symbol {
+	char *name;
+	struct ctype *type;
+	short id;
+	uint8_t ctx;
+	uint8_t token;
+	uint8_t ns;
+	struct {
+		bool isglobal : 1;
+		bool isstatic : 1;
+		bool isauto : 1;
+		bool isregister : 1;
+	} s;
+	union value u;
+	struct symbol *next;
+	struct symbol *hash;
+};
+
+extern void freesyms(uint8_t ns);
+
+extern struct ctype *qualifier(struct ctype *tp, uint8_t qlf),
+	*ctype(int8_t type, int8_t sign, int8_t size, int8_t cplex),
+	*mktype(struct ctype *tp,
+	        uint8_t op, struct symbol *tag, uint16_t nelem);
+
+extern struct symbol
+	*lookup(char *s, unsigned char ns),
+	*install(char *s, unsigned char ns);
+
+extern void context(void (*fun)(void));
+
+extern struct ctype *voidtype,
+	*uchartype,   *chartype,
+	*uinttype,    *inttype,
+	*ushortype,   *shortype,
+	*longtype,    *ulongtype,
+	*ullongtype,  *llongtype,
+	*floattype,   *cfloattype,  *ifloattype,
+	*doubletype,  *cdoubletype, *idoubletype,
+	*ldoubletype, *cldoubletype,*ildoubletype;
+
+#define ISQUAL(t)    (isqual((t)->op))
+#define UNQUAL(t)    (ISQUAL(t) ? (t)->type : (t))
+#define BTYPE(t)     (UNQUAL(t)->op)
+#define isfun(op)    ((op) == FTN)
+#define isptr(op)    ((op) == PTR)
+#define isary(op)    ((op) == ARY)
+#define isarith(op)  ((op) & ARITH)
+#define isaddr(op)   ((op) & POINTER)
+#define isrecord(op) ((op) & RECORD)
+#define isqual(op)   ((op) & TQUALIFIER)
+
+
+#define ARITH         8
+#define RECORD        16
+#define POINTER       32
+#define ATYPE(x)      (ARITH  | (x))
+#define RTYPE(x)      (RECORD | (x))
+#define PTYPE(x)      (POINTER| (x))
+
+#define FTN           1
+#define ENUM          2
+#define TYPENAME      3
+#define VOID          4
+
+#define FLOAT         ATYPE(1)
+#define INT           ATYPE(2)
+#define BOOL          ATYPE(3)
+
+#define STRUCT        RTYPE(1)
+#define UNION         RTYPE(2)
+
+#define PTR           PTYPE(1)
+#define ARY           PTYPE(2)
+
+#define CHAR          (ARY+1)
+#define DOUBLE        (ARY+2)
+#define SHORT         (ARY+3)
+#define LONG          (ARY+4)
+
+#define COMPLEX       (ARY+5)
+#define IMAGINARY     (ARY+6)
+#define UNSIGNED      (ARY+7)
+#define SIGNED        (ARY+8)
+
+#define CONST         (1<<0)
+#define VOLATILE      (1<<1)
+#define RESTRICT      (1<<2)
+
+#define TYPEDEF       1
+#define EXTERN        2
+#define STATIC        3
+#define AUTO          4
+#define REGISTER      5
+
+#define accept(t) ((bool) (yytoken == (t) ? next() : 0))
+#define ahead()   yyntoken
+
+enum tokens {
+	TQUALIFIER = 128, TYPE, IDEN, SCLASS,
+	CONSTANT, SIZEOF,
+	INDIR, INC, DEC, SHL, SHR,
+	LE, GE, EQ, NE, AND, OR,
+	MUL_EQ, DIV_EQ, MOD_EQ, ADD_EQ, SUB_EQ, AND_EQ,
+	XOR_EQ, OR_EQ, SHL_EQ, SHR_EQ,
+	ELLIPSIS,
+	CASE, DEFAULT, IF, ELSE, SWITCH, WHILE, DO, FOR, GOTO,
+	CONTINUE, BREAK, RETURN, EOFTOK, NOTOK
+};
+
+union yystype {
+	struct symbol *sym;
+	uint8_t token;
+};
+
+extern union yystype yylval;
+extern char yytext[];
+extern uint8_t yytoken, yyntoken;
+
+extern uint8_t next(void);
+extern void expect(uint8_t tok);
 #endif
--- a/code.c
+++ b/code.c
@@ -2,7 +2,7 @@
 #include <stdint.h>
 #include <stdio.h>
 
-#include "symbol.h"
+#include "cc.h"
 
 void
 emitsym(struct symbol *sym)
--- a/code.h
+++ /dev/null
@@ -1,10 +1,0 @@
-
-#ifndef CODE_H_
-#define CODE_H_
-
-struct symbol;
-
-extern void emitsym(struct symbol *sym),  emitfun(struct symbol *sym),
-	emitframe(struct symbol *sym), emitret(struct symbol *sym);
-
-#endif
--- a/decl.c
+++ b/decl.c
@@ -5,8 +5,6 @@
 
 #include "sizes.h"
 #include "cc.h"
-#include "tokens.h"
-#include "symbol.h"
 #include "machine.h"
 
 #define ID_EXPECTED     1
--- a/error.c
+++ b/error.c
@@ -1,6 +1,7 @@
 
 #include <stdarg.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <stdio.h>
 
 #include "cc.h"
--- a/expr.c
+++ b/expr.c
@@ -2,9 +2,6 @@
 #include <stdio.h>
 
 #include "cc.h"
-#include "code.h"
-#include "tokens.h"
-#include "symbol.h"
 
 void expr(void);
 
--- a/lex.c
+++ b/lex.c
@@ -6,8 +6,6 @@
 #include <ctype.h>
 
 #include "cc.h"
-#include "tokens.h"
-#include "symbol.h"
 #include "sizes.h"
 
 static FILE *yyin;
--- a/main.c
+++ b/main.c
@@ -3,7 +3,6 @@
 #include <stdint.h>
 
 #include "cc.h"
-#include "tokens.h"
 
 extern void extdecl(void), init_keywords(void), open_file(const char *file);
 
--- a/stmt.c
+++ b/stmt.c
@@ -1,9 +1,8 @@
 
+#include <stddef.h>
 #include <stdint.h>
 
-#include "symbol.h"
-#include "tokens.h"
-
+#include "cc.h"
 
 void
 compound(void)
--- a/symbol.c
+++ b/symbol.c
@@ -5,8 +5,6 @@
 #include <string.h>
 
 #include "cc.h"
-#include "symbol.h"
-#include "tokens.h"
 
 #define NR_SYM_HASH 32
 
--- a/symbol.h
+++ /dev/null
@@ -1,112 +1,0 @@
-
-#ifndef SYMBOL_H
-#define SYMBOL_H
-
-#if ! __bool_true_and_false_are_defined
-#include <stdbool.h>
-#endif
-
-#define CTX_OUTER 0
-#define CTX_FUNC  1
-
-enum {
-	NS_IDEN = 0,
-	NS_LABEL,
-	NS_TAG,
-	NR_NAMESPACES,
-	NS_KEYWORD,
-	NS_FREE
-};
-
-struct funpars;
-struct symbol;
-
-struct ctype {
-	uint8_t op;           /* type builder operator */
-	short size;           /* size of variables */
-	short nelem;          /* number of elements in arrays */
-	unsigned defined : 1; /* type defined (is not a forward reference) */
-	unsigned cplex : 1;   /* complex specifier */
-	unsigned imag : 1;
-	unsigned sign : 1;    /* sign type */
-	struct symbol *sym;   /* symbol of the tag identifier */
-	struct ctype *type;   /* base type */
-	struct ctype *next;   /* next element in the hash */
-	union {
-		struct funpar *pars;  /* function parameters */
-		struct field *fields; /* aggregate fields */
-	} u;
-};
-
-struct field {
-	struct symbol *sym;
-	struct field *next;
-};
-
-struct funpar {
-	struct ctype *type;
-	struct funpar *next;
-};
-
-union value {
-	char c;
-	int i;
-	struct symbol *sym;
-	uint8_t ns, token;
-	short offset;
-};
-
-struct symbol {
-	char *name;
-	struct ctype *type;
-	short id;
-	uint8_t ctx;
-	uint8_t token;
-	uint8_t ns;
-	struct {
-		bool isglobal : 1;
-		bool isstatic : 1;
-		bool isauto : 1;
-		bool isregister : 1;
-	} s;
-	union value u;
-	struct symbol *next;
-	struct symbol *hash;
-};
-
-extern void freesyms(uint8_t ns);
-
-extern struct ctype *qualifier(struct ctype *tp, uint8_t qlf),
-	*ctype(int8_t type, int8_t sign, int8_t size, int8_t cplex),
-	*mktype(struct ctype *tp,
-	        uint8_t op, struct symbol *tag, uint16_t nelem);
-
-extern struct symbol
-	*lookup(char *s, unsigned char ns),
-	*install(char *s, unsigned char ns);
-
-extern void context(void (*fun)(void));
-
-extern struct ctype *voidtype,
-	*uchartype,   *chartype,
-	*uinttype,    *inttype,
-	*ushortype,   *shortype,
-	*longtype,    *ulongtype,
-	*ullongtype,  *llongtype,
-	*floattype,   *cfloattype,  *ifloattype,
-	*doubletype,  *cdoubletype, *idoubletype,
-	*ldoubletype, *cldoubletype,*ildoubletype;
-
-#define ISQUAL(t)    (isqual((t)->op))
-#define UNQUAL(t)    (ISQUAL(t) ? (t)->type : (t))
-#define BTYPE(t)     (UNQUAL(t)->op)
-#define isfun(op)    ((op) == FTN)
-#define isptr(op)    ((op) == PTR)
-#define isary(op)    ((op) == ARY)
-#define isarith(op)  ((op) & ARITH)
-#define isaddr(op)   ((op) & POINTER)
-#define isrecord(op) ((op) & RECORD)
-#define isqual(op)   ((op) & TQUALIFIER)
-
-
-#endif
--- a/tokens.h
+++ /dev/null
@@ -1,79 +1,0 @@
-#ifndef TOKENS_H
-#define TOKENS_H
-
-#if ! __bool_true_false_are_defined
-# include <stdbool.h>
-#endif
-
-#define ARITH         8
-#define RECORD        16
-#define POINTER       32
-#define ATYPE(x)      (ARITH  | (x))
-#define RTYPE(x)      (RECORD | (x))
-#define PTYPE(x)      (POINTER| (x))
-
-#define FTN           1
-#define ENUM          2
-#define TYPENAME      3
-#define VOID          4
-
-#define FLOAT         ATYPE(1)
-#define INT           ATYPE(2)
-#define BOOL          ATYPE(3)
-
-#define STRUCT        RTYPE(1)
-#define UNION         RTYPE(2)
-
-#define PTR           PTYPE(1)
-#define ARY           PTYPE(2)
-
-#define CHAR          (ARY+1)
-#define DOUBLE        (ARY+2)
-#define SHORT         (ARY+3)
-#define LONG          (ARY+4)
-
-#define COMPLEX       (ARY+5)
-#define IMAGINARY     (ARY+6)
-#define UNSIGNED      (ARY+7)
-#define SIGNED        (ARY+8)
-
-#define CONST         (1<<0)
-#define VOLATILE      (1<<1)
-#define RESTRICT      (1<<2)
-
-#define TYPEDEF       1
-#define EXTERN        2
-#define STATIC        3
-#define AUTO          4
-#define REGISTER      5
-
-#define accept(t) ((bool) (yytoken == (t) ? next() : 0))
-#define ahead()   yyntoken
-
-enum tokens {
-	TQUALIFIER = 128, TYPE, IDEN, SCLASS,
-	CONSTANT, SIZEOF,
-	INDIR, INC, DEC, SHL, SHR,
-	LE, GE, EQ, NE, AND, OR,
-	MUL_EQ, DIV_EQ, MOD_EQ, ADD_EQ, SUB_EQ, AND_EQ,
-	XOR_EQ, OR_EQ, SHL_EQ, SHR_EQ,
-	ELLIPSIS,
-	CASE, DEFAULT, IF, ELSE, SWITCH, WHILE, DO, FOR, GOTO,
-	CONTINUE, BREAK, RETURN, EOFTOK, NOTOK
-};
-
-struct symbol;
-union yystype {
-	struct symbol *sym;
-	uint8_t token;
-};
-
-extern union yystype yylval;
-extern char yytext[];
-extern uint8_t yytoken, yyntoken;
-
-
-extern uint8_t next(void);
-extern void expect(uint8_t tok);
-
-#endif
--- a/types.c
+++ b/types.c
@@ -5,8 +5,6 @@
 
 #include "sizes.h"
 #include "cc.h"
-#include "tokens.h"
-#include "symbol.h"
 #include "machine.h"
 
 #define NR_TYPE_HASH 16
--- a/wrapper.c
+++ b/wrapper.c
@@ -2,6 +2,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <stdint.h>
+
 #include "cc.h"