shithub: scc

Download patch

ref: 9f0c6b1818a3dac48845572bb64c250673c41c88
parent: e0b2f47525a1dc50a5089d2f472f1b51fbb0b483
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Apr 25 07:22:05 EDT 2014

Move common declarations to a unique file in a include
directory

--- a/cc1/Makefile
+++ b/cc1/Makefile
@@ -2,7 +2,7 @@
 OBJS = types.o decl.o lex.o error.o symbol.o main.o expr.o \
 	wrapper.o code.o stmt.o
 
-CFLAGS += -fno-diagnostics-show-caret -g
+CFLAGS += -I../include
 
 all: cc1
 
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -1,11 +1,7 @@
-#ifndef CC_H
-#define CC_H
+#ifndef CC1_H
+#define CC1_H
 
-#ifndef __bool_true_and_false_defined
-#include <stdbool.h>
-#endif
 
-
 struct user_opt {
 	unsigned char implicit;
 	unsigned char mixdcls;
@@ -16,14 +12,8 @@
 };
 
 extern  struct user_opt options;
-
 extern void error(const char *fmt, ...);
-extern void die(const char *fmt, ...);
 extern void warn(signed char flag, const char *fmt, ...);
-extern void *xmalloc(size_t size);
-extern void *xcalloc(size_t nmemb, size_t size);
-extern char *xstrdup(const char *s);
-extern void *xrealloc(void *buff, register size_t size);
 
 /* definitions of types */
 
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -2,6 +2,7 @@
 #include <stdint.h>
 #include <stdio.h>
 
+#include <cc.h>
 #include "cc1.h"
 
 char *opcodes[] = {
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -3,7 +3,8 @@
 #include <stdint.h>
 #include <string.h>
 
-#include "sizes.h"
+#include <sizes.h>
+#include <cc.h>
 #include "cc1.h"
 
 #define ID_EXPECTED     1
--- a/cc1/error.c
+++ b/cc1/error.c
@@ -4,6 +4,7 @@
 #include <stdint.h>
 #include <stdio.h>
 
+#include <cc.h>
 #include "cc1.h"
 
 extern unsigned linenum;
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -1,6 +1,7 @@
 #include <stdint.h>
 #include <stdio.h>
 
+#include <cc.h>
 #include "cc1.h"
 
 static Symbol *zero, *one;
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -5,8 +5,9 @@
 #include <string.h>
 #include <ctype.h>
 
+#include <sizes.h>
+#include <cc.h>
 #include "cc1.h"
-#include "sizes.h"
 
 static FILE *yyin;
 const char *filename;
--- a/cc1/main.c
+++ b/cc1/main.c
@@ -1,4 +1,5 @@
 
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <stdio.h>
--- a/cc1/sizes.h
+++ /dev/null
@@ -1,88 +1,0 @@
-#ifndef SIZES_H
-#define SIZES_H
-
-/*
- * 15 nesting levels of compound statements, iteration control
- * structures, and selection control structures
- */
-#define NR_BLOCK       15
-/*
- * 8 nesting levels of conditional inclusion
- */
-#define NR_COND   8
-/*
- * number of defined structs/unions in one translation unit
- */
-#define NR_MAXSTRUCTS 127
-/*
- * 12 pointer, array, and function declarators (in any combinations)
- *  modifying an arithmetic, a structure, a union, or an incomplete type
- *  in a declaration
- */
-#define NR_DECLARATORS  12
-/*
- * 31 declarators nested by parentheses within a full declarator.
- */
-#define NR_SUBTYPE     31
-/*
- * 32 expressions nested by parentheses within a full expression
- */
-#define NR_SUBEXPR     32
-/*
- * 31 significant initial characters in an internal identifier or a
- * macro name
- */
-#define IDENTSIZ       31
-/*
- * 511 external identifiers in one translation unit
- */
-#define NR_EXT_IDENT   511
-/*
- * 127 identifiers with block scope declared in one block
- */
-#define NR_INT_IDENT   127
-/*
- * 31 parameters in one function definition * 6 significant initial
- * characters in an external identifier.
- */
-#define NR_FUNPARAM    31
-/*
- * 31 parameters in one macro definition
- */
-#define NR_MACROARG    31
-/*
- * 509 characters in a logical source line.
- */
-#define LINESIZ     509
-/*
- * 509 characters in a character string literal or wide string literal
- * (after concatenation)
- */
-#define STRINGSIZ   509
-/*
- * 8 nesting levels for #include'd files
- */
-#define NR_INCLUDE   9
-/*
- * 257 case labels for a switch statement (excluding those for any
- * nested switch statements)
- */
-#define NR_SWITCH  257
-/*
- * 127 members in a single structure or union
- */
-#define NR_FIELDS  127
-/*
- * 127 enumeration constants in a single enumeration
- */
-#define NR_ENUM_CTES 127
-/*
- * 15 levels of nested structure or union definitions in a single
- *  struct-declaration-list
- */
-#define NR_STRUCT_LEVEL 15
-/*
- * 32767 bytes in an object (in a hosted environment only)
- */
-#define OBJECTSIZ  32767
-#endif
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -3,6 +3,7 @@
 #include <stdint.h>
 #include <stdio.h>
 
+#include <cc.h>
 #include "cc1.h"
 
 struct scase {
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <cc.h>
 #include "cc1.h"
 
 #define NR_SYM_HASH 32
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -3,7 +3,8 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "sizes.h"
+#include <sizes.h>
+#include <cc.h>
 #include "cc1.h"
 
 #define NR_TYPE_HASH 16
--- a/cc1/wrapper.c
+++ b/cc1/wrapper.c
@@ -1,11 +1,9 @@
 
 #include <stdlib.h>
 #include <string.h>
-
 #include <stdint.h>
 
-#include "cc1.h"
-
+#include <cc.h>
 
 static void
 out_of_memory(void)
--- /dev/null
+++ b/include/cc.h
@@ -1,0 +1,15 @@
+
+#ifndef CC_H_
+#define CC_H_
+
+#ifndef __bool_true_and_false_defined
+#include <stdbool.h>
+#endif
+
+extern void die(const char *fmt, ...);
+extern void *xmalloc(size_t size);
+extern void *xcalloc(size_t nmemb, size_t size);
+extern char *xstrdup(const char *s);
+extern void *xrealloc(void *buff, register size_t size);
+
+#endif
\ No newline at end of file
--- /dev/null
+++ b/include/sizes.h
@@ -1,0 +1,88 @@
+#ifndef SIZES_H
+#define SIZES_H
+
+/*
+ * 15 nesting levels of compound statements, iteration control
+ * structures, and selection control structures
+ */
+#define NR_BLOCK       15
+/*
+ * 8 nesting levels of conditional inclusion
+ */
+#define NR_COND   8
+/*
+ * number of defined structs/unions in one translation unit
+ */
+#define NR_MAXSTRUCTS 127
+/*
+ * 12 pointer, array, and function declarators (in any combinations)
+ *  modifying an arithmetic, a structure, a union, or an incomplete type
+ *  in a declaration
+ */
+#define NR_DECLARATORS  12
+/*
+ * 31 declarators nested by parentheses within a full declarator.
+ */
+#define NR_SUBTYPE     31
+/*
+ * 32 expressions nested by parentheses within a full expression
+ */
+#define NR_SUBEXPR     32
+/*
+ * 31 significant initial characters in an internal identifier or a
+ * macro name
+ */
+#define IDENTSIZ       31
+/*
+ * 511 external identifiers in one translation unit
+ */
+#define NR_EXT_IDENT   511
+/*
+ * 127 identifiers with block scope declared in one block
+ */
+#define NR_INT_IDENT   127
+/*
+ * 31 parameters in one function definition * 6 significant initial
+ * characters in an external identifier.
+ */
+#define NR_FUNPARAM    31
+/*
+ * 31 parameters in one macro definition
+ */
+#define NR_MACROARG    31
+/*
+ * 509 characters in a logical source line.
+ */
+#define LINESIZ     509
+/*
+ * 509 characters in a character string literal or wide string literal
+ * (after concatenation)
+ */
+#define STRINGSIZ   509
+/*
+ * 8 nesting levels for #include'd files
+ */
+#define NR_INCLUDE   9
+/*
+ * 257 case labels for a switch statement (excluding those for any
+ * nested switch statements)
+ */
+#define NR_SWITCH  257
+/*
+ * 127 members in a single structure or union
+ */
+#define NR_FIELDS  127
+/*
+ * 127 enumeration constants in a single enumeration
+ */
+#define NR_ENUM_CTES 127
+/*
+ * 15 levels of nested structure or union definitions in a single
+ *  struct-declaration-list
+ */
+#define NR_STRUCT_LEVEL 15
+/*
+ * 32767 bytes in an object (in a hosted environment only)
+ */
+#define OBJECTSIZ  32767
+#endif
--