From ac4cbd735e351d1aa78ba6160876d0bf6dd034d2 Mon Sep 17 00:00:00 2001 From: George Koehler Date: Sat, 11 Nov 2017 16:09:05 -0500 Subject: [PATCH] Use libc assert(); fix dependencies; unbreak isduo(). Switch from custom assert() to libc assert() in mach/proto/as. Continue to disable asserts if DEBUG == 0. This change found a problem in the build system; comm2.y was missing depedencies on comm0.h and comm1.h. Add the missing dependencies to the cppfile rule. Allow the dependencies by modifying cppfile in first/build.lua to act like cfile if t.dir is false. Now that comm2.y gets rebuilt, I must fix the wrong prototype of yyparse() in comm1.h. I got unlucky as induo() in comm5.c was reading beyond the end of the array. It found an operator "= " ('=' then space) in the garbage, so it returned a garbage token number, and "VAR = 123" became a syntax error. Unbreak induo() by terminating the array. --- first/build.lua | 4 +++- mach/proto/as/build.lua | 2 ++ mach/proto/as/comm0.h | 18 +++++++++--------- mach/proto/as/comm1.h | 2 +- mach/proto/as/comm5.c | 1 + mach/proto/as/comm6.c | 4 +--- mach/proto/as/comm7.c | 16 ---------------- 7 files changed, 17 insertions(+), 30 deletions(-) diff --git a/first/build.lua b/first/build.lua index 20eab73c8..b9fa0ab1f 100644 --- a/first/build.lua +++ b/first/build.lua @@ -92,7 +92,9 @@ definerule("cppfile", local hdrpaths = {} for _, t in pairs(e.deps) do - hdrpaths[#hdrpaths+1] = "-I"..t.dir + if t.dir then + hdrpaths[#hdrpaths+1] = "-I"..t.dir + end end hdrpaths = uniquify(hdrpaths) diff --git a/mach/proto/as/build.lua b/mach/proto/as/build.lua index 6d846682e..9782b4b4b 100644 --- a/mach/proto/as/build.lua +++ b/mach/proto/as/build.lua @@ -21,6 +21,8 @@ definerule("build_as", srcs = { "mach/proto/as/comm2.y" }, outleaf = "comm2.y", deps = { + "mach/proto/as/comm0.h", + "mach/proto/as/comm1.h", "h+emheaders", archlib, }, diff --git a/mach/proto/as/comm0.h b/mach/proto/as/comm0.h index 2d00c8e45..60fb172b4 100644 --- a/mach/proto/as/comm0.h +++ b/mach/proto/as/comm0.h @@ -105,16 +105,16 @@ _include "out.h" #include "out.h" #endif -#if DEBUG == 0 -#define assert(ex) /* nothing */ +/* + * Define assert(). Disable assertions if DEBUG == 0. + */ +#if DEBUG == 0 && !defined(NDEBUG) +#define NDEBUG #endif - -#if DEBUG == 1 -#define assert(ex) {if (!(ex)) assert1();} -#endif - -#if DEBUG == 2 -#define assert(ex) {if (!(ex)) assert2(__FILE__, __LINE__);} +#ifdef _include +_include +#else +#include #endif #define CTRL(x) ((x) & 037) diff --git a/mach/proto/as/comm1.h b/mach/proto/as/comm1.h index e23e6b045..7ea697015 100644 --- a/mach/proto/as/comm1.h +++ b/mach/proto/as/comm1.h @@ -105,7 +105,7 @@ extern int curr_token; /* forward function declarations */ /* comm2.y */ -void yyparse(void); +int yyparse(void); /* comm4.c */ void stop(void); void newmodule(const char *); diff --git a/mach/proto/as/comm5.c b/mach/proto/as/comm5.c index 447be2f91..e7d45c7fb 100644 --- a/mach/proto/as/comm5.c +++ b/mach/proto/as/comm5.c @@ -283,6 +283,7 @@ induo(int c) ('>'<<8) | '>', OP_RR, ('|'<<8) | '|', OP_OO, ('&'<<8) | '&', OP_AA, + 0 /* terminates array */ }; short *p; diff --git a/mach/proto/as/comm6.c b/mach/proto/as/comm6.c index 84cdbf72e..8aca81e8a 100644 --- a/mach/proto/as/comm6.c +++ b/mach/proto/as/comm6.c @@ -79,10 +79,8 @@ newident(item_t *ip, int typ) void newlabel(item_t *ip) { -#if DEBUG != 0 -#ifdef THREE_PASS +#if defined(THREE_PASS) && !defined(NDEBUG) ADDR_T oldval = ip->i_valu; -#endif #endif if (DOTSCT == NULL) diff --git a/mach/proto/as/comm7.c b/mach/proto/as/comm7.c index ace23620b..b75794d88 100644 --- a/mach/proto/as/comm7.c +++ b/mach/proto/as/comm7.c @@ -406,22 +406,6 @@ void fatal(const char* s, ...) va_end(ap); } -#if DEBUG == 2 -assert2(file, line) -char *file; -{ - fatal("assertion failed (%s, %d)", file, line); -} -#endif - -#if DEBUG == 1 -assert1() -{ - fatal("assertion failed"); - abort(); -} -#endif - /* VARARGS1 */ void serror(const char* s, ...) {