From: cuz Date: Tue, 19 Apr 2005 22:03:30 +0000 (+0000) Subject: Evaluate .asserts with known conditions in the assembler. X-Git-Tag: V2.12.0~370 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=05ab8714d255a0d7d34c433cf0ba2002eb50e615;p=cc65 Evaluate .asserts with known conditions in the assembler. git-svn-id: svn://svn.cc65.org/cc65/trunk@3471 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index 6ac295017..2522e54c8 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -384,8 +384,8 @@ static void DoAssert (void) "ERROR" }; - int Action; - + int Action; + long Val; /* First we have the expression that has to evaluated */ ExprNode* Expr = Expression (); @@ -419,10 +419,35 @@ static void DoAssert (void) /* Read the message */ if (Tok != TOK_STRCON) { ErrorSkip ("String constant expected"); + return; + } + + /* If we can evaluate the assertion now, there's no need to pass it to the + * linker. + */ + if (IsConstExpr (Expr, &Val)) { + /* We can evaluate the expression, so handle it in the assembler */ + switch (Action) { + + case ASSERT_ACT_WARN: + Warning (0, "%s", SVal); + break; + + case ASSERT_ACT_ERROR: + Error ("%s", SVal); + break; + + default: + Internal ("Illegal assert action specifier"); + break; + } } else { + /* Cannot evaluate, add it to the object file */ AddAssertion (Expr, Action, GetStringId (SVal)); - NextTok (); } + + /* Skip the message */ + NextTok (); }