shithub: scc

Download patch

ref: 2ee4c38b7e9809aefb5c8cb1f874444928a0b188
parent: 3567fa6b6a3b3cc390eae405afc6c7368eb1b6a1
author: FRIGN <[email protected]>
date: Wed May 25 03:58:42 EDT 2016

[cc1] Unboolify

Bools artificially limit what you can do on a logical basis with normal
ints. So let's drop them.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -347,7 +347,7 @@
 extern void cpperror(char *fmt, ...);
 
 /* types.c */
-extern bool eqtype(Type *tp1, Type *tp2);
+extern int eqtype(Type *tp1, Type *tp2);
 extern Type *ctype(unsigned type, unsigned sign, unsigned size);
 extern Type *mktype(Type *tp, int op, TINT nelem, Type *data[]);
 extern Type *duptype(Type *base);
@@ -376,10 +376,10 @@
 /* lex.c */
 extern char ahead(void);
 extern unsigned next(void);
-extern bool moreinput(void);
+extern int moreinput(void);
 extern void expect(unsigned tok);
 extern void discard(void);
-extern bool addinput(char *fname);
+extern int addinput(char *fname);
 extern void setsafe(int type);
 extern void ilex(char *fname);
 #define accept(t) ((yytoken == (t)) ? next() : 0)
@@ -402,9 +402,9 @@
 extern Node *decay(Node *), *negate(Node *np), *assign(void);
 extern Node *convert(Node *np, Type *tp1, char iscast);
 extern Node *iconstexpr(void), *condexpr(void), *expr(void);
-extern bool isnodecmp(int op);
+extern int isnodecmp(int op);
 extern int negop(int op);
-extern bool cmpnode(Node *np, TUINT val);
+extern int cmpnode(Node *np, TUINT val);
 
 /* init.c */
 extern void initializer(Symbol *sym, Type *tp);
@@ -412,8 +412,8 @@
 
 /* cpp.c */
 extern void icpp(void);
-extern bool cpp(void);
-extern bool expand(char *begin, Symbol *sym);
+extern int cpp(void);
+extern int expand(char *begin, Symbol *sym);
 extern void incdir(char *dir);
 extern void outcpp(void);
 extern Symbol *defmacro(char *s);
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -226,7 +226,7 @@
 }
 
 #define BUFSIZE ((INPUTSIZ > FILENAME_MAX+2) ? INPUTSIZ : FILENAME_MAX+2)
-bool
+int
 expand(char *begin, Symbol *sym)
 {
 	size_t total, elen, rlen, llen, ilen;
@@ -324,7 +324,7 @@
 	return n;
 }
 
-static bool
+static int
 getdefs(Symbol *args[NR_MACROARG], int nargs, char *bp, size_t bufsiz)
 {
 	Symbol **argp;
@@ -425,7 +425,7 @@
 	dirinclude[ninclude-1] = dir;
 }
 
-static bool
+static int
 includefile(char *dir, char *file, size_t filelen)
 {
 	size_t dirlen;
@@ -684,7 +684,7 @@
 	next();
 }
 
-bool
+int
 cpp(void)
 {
 	static struct {
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -65,7 +65,7 @@
 	va_end(va);
 }
 
-static bool
+static int
 pop(struct declarators *dp, struct decl *dcl)
 {
 	struct declarator *p;
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -12,7 +12,7 @@
 
 Node *expr(void);
 
-bool
+int
 cmpnode(Node *np, TUINT val)
 {
 	Symbol *sym;
@@ -36,7 +36,7 @@
 	return 0;
 }
 
-bool
+int
 isnodecmp(int op)
 {
 	switch (op) {
--- a/cc1/fold.c
+++ b/cc1/fold.c
@@ -17,7 +17,7 @@
 	return v;
 }
 
-static bool
+static int
 addi(TINT l, TINT r, Type *tp)
 {
 	struct limits *lim = getlimits(tp);
@@ -35,7 +35,7 @@
 	return 0;
 }
 
-static bool
+static int
 addf(TFLOAT l, TFLOAT r, Type *tp)
 {
 	struct limits *lim = getlimits(tp);
@@ -53,19 +53,19 @@
 	return 0;
 }
 
-static bool
+static int
 subi(TINT l, TINT r, Type *tp)
 {
 	return addi(l, -r, tp);
 }
 
-static bool
+static int
 subf(TFLOAT l, TFLOAT r, Type *tp)
 {
 	return addf(l, -r, tp);
 }
 
-static bool
+static int
 muli(TINT l, TINT r, Type *tp)
 {
 	struct limits *lim = getlimits(tp);
@@ -83,7 +83,7 @@
 	return 0;
 }
 
-static bool
+static int
 mulf(TFLOAT l, TFLOAT r, Type *tp)
 {
 	struct limits *lim = getlimits(tp);
@@ -101,7 +101,7 @@
 	return 0;
 }
 
-static bool
+static int
 divi(TINT l, TINT r,  Type *tp)
 {
 	struct limits *lim = getlimits(tp);
@@ -113,7 +113,7 @@
 	return 1;
 }
 
-static bool
+static int
 divf(TFLOAT l, TFLOAT r,  Type *tp)
 {
 	struct limits *lim = getlimits(tp);
@@ -128,7 +128,7 @@
 	return 1;
 }
 
-static bool
+static int
 lshi(TINT l, TINT r, Type *tp)
 {
 	if (r < 0 || r >= tp->size * 8) {
@@ -138,7 +138,7 @@
 	return muli(l, 1 << r, tp);
 }
 
-static bool
+static int
 rshi(TINT l, TINT r, Type *tp)
 {
 	if (r < 0 || r >= tp->size * 8) {
@@ -148,12 +148,12 @@
 	return 1;
 }
 
-static bool
+static int
 foldint(int op, Symbol *res, TINT l, TINT r)
 {
 	TINT i;
 	Type *tp = res->type;
-	bool (*validate)(TINT, TINT, Type *tp);
+	int (*validate)(TINT, TINT, Type *tp);
 
 	switch (op) {
 	case OADD: validate = addi; break;
@@ -196,7 +196,7 @@
 	return 1;
 }
 
-static bool
+static int
 folduint(int op, Symbol *res, TUINT l, TUINT r)
 {
 	TINT i;
@@ -234,12 +234,12 @@
 	return 1;
 }
 
-static bool
+static int
 foldfloat(int op, Symbol *res, TFLOAT l, TFLOAT r)
 {
 	TFLOAT f;
 	TINT i;
-	bool (*validate)(TFLOAT, TFLOAT, Type *tp);
+	int (*validate)(TFLOAT, TFLOAT, Type *tp);
 
 	switch (op) {
 	case OADD: validate = addf; break;
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -93,7 +93,7 @@
 	keywords(keys, NS_KEYWORD);
 }
 
-bool
+int
 addinput(char *fname)
 {
 	FILE *fp;
@@ -174,7 +174,7 @@
 		error("unterminated comment");
 }
 
-static bool
+static int
 readline(void)
 {
 	char *bp, *lim;
@@ -212,7 +212,7 @@
 	return 1;
 }
 
-bool
+int
 moreinput(void)
 {
 	static char file[FILENAME_MAX];
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -308,7 +308,7 @@
 	return *tbl = bp;
 }
 
-bool
+int
 eqtype(Type *tp1, Type *tp2)
 {
 	TINT n;
--- a/inc/cc.h
+++ b/inc/cc.h
@@ -1,12 +1,4 @@
 /* See LICENSE file for copyright and license details. */
-#ifndef __bool_true_and_false_defined
-#ifdef NBOOL
-typedef unsigned bool;
-#else
-#include <stdbool.h>
-#endif
-#endif
-
 #ifndef NDEBUG
 extern int debug;
 #define DBG(fmt, ...) dbg(fmt, __VA_ARGS__)