Add .assert actions that aren't evaluated at assembly time.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4321 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2009-10-04 12:40:19 +00:00
parent a3529cd048
commit 1efebb9024
10 changed files with 170 additions and 51 deletions

View File

@@ -34,7 +34,6 @@
/* common */
#include "assertdefs.h"
#include "coll.h"
#include "xmalloc.h"
@@ -57,10 +56,10 @@
/* An assertion entry */
typedef struct Assertion Assertion;
struct Assertion {
ExprNode* Expr; /* Expression to evaluate */
unsigned Action; /* Action to take */
unsigned Msg; /* Message to print (if any) */
FilePos Pos; /* File position of assertion */
ExprNode* Expr; /* Expression to evaluate */
AssertAction Action; /* Action to take */
unsigned Msg; /* Message to print (if any) */
FilePos Pos; /* File position of assertion */
};
/* Collection with all assertions for a module */
@@ -74,7 +73,7 @@ static Collection Assertions = STATIC_COLLECTION_INITIALIZER;
static Assertion* NewAssertion (ExprNode* Expr, unsigned Action, unsigned Msg)
static Assertion* NewAssertion (ExprNode* Expr, AssertAction Action, unsigned Msg)
/* Create a new Assertion struct and return it */
{
/* Allocate memory */
@@ -92,7 +91,7 @@ static Assertion* NewAssertion (ExprNode* Expr, unsigned Action, unsigned Msg)
void AddAssertion (ExprNode* Expr, unsigned Action, unsigned Msg)
void AddAssertion (ExprNode* Expr, AssertAction Action, unsigned Msg)
/* Add an assertion to the assertion table */
{
/* Add an assertion object to the table */
@@ -112,11 +111,17 @@ void CheckAssertions (void)
/* Check the assertions */
for (I = 0; I < Count; ++I) {
long Val;
/* Get the next assertion */
Assertion* A = CollAtUnchecked (&Assertions, I);
/* Ignore it, if it should only be evaluated by the linker */
if (!AssertAtAsmTime (A->Action)) {
continue;
}
/* Can we evaluate the expression? */
long Val;
if (IsConstExpr (A->Expr, &Val) && Val == 0) {
/* Apply the action */
const char* Msg = GetString (A->Msg);
@@ -162,7 +167,7 @@ void WriteAssertions (void)
/* Write it to the file */
WriteExpr (A->Expr);
ObjWriteVar (A->Action);
ObjWriteVar ((unsigned) A->Action);
ObjWriteVar (A->Msg);
ObjWritePos (&A->Pos);
}

View File

@@ -6,8 +6,8 @@
/* */
/* */
/* */
/* (C) 2003-2005, Ullrich von Bassewitz */
/* R<EFBFBD>merstrasse 52 */
/* (C) 2003-2009, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
@@ -38,6 +38,11 @@
/* common */
#include "assertion.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
@@ -55,7 +60,7 @@ struct ExprNode;
void AddAssertion (struct ExprNode* Expr, unsigned Action, unsigned Msg);
void AddAssertion (struct ExprNode* Expr, AssertAction Action, unsigned Msg);
/* Add an assertion to the assertion table */
void CheckAssertions (void);

View File

@@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1998-2008, Ullrich von Bassewitz */
/* (C) 1998-2009, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@@ -39,7 +39,6 @@
/* common */
#include "addrsize.h"
#include "assertdefs.h"
#include "attrib.h"
#include "bitops.h"
#include "check.h"
@@ -60,7 +59,7 @@
#include "studyexpr.h"
#include "symtab.h"
/*****************************************************************************/
/* Forwards */

View File

@@ -40,7 +40,7 @@
#include <errno.h>
/* common */
#include "assertdefs.h"
#include "assertion.h"
#include "bitops.h"
#include "cddefs.h"
#include "coll.h"
@@ -408,11 +408,13 @@ static void DoAssert (void)
{
static const char* ActionTab [] = {
"WARN", "WARNING",
"ERROR"
"ERROR",
"LDWARN", "LDWARNING",
"LDERROR",
};
int Action;
unsigned Msg;
AssertAction Action;
unsigned Msg;
/* First we have the expression that has to evaluated */
ExprNode* Expr = Expression ();
@@ -423,8 +425,7 @@ static void DoAssert (void)
ErrorSkip ("Identifier expected");
return;
}
Action = GetSubKey (ActionTab, sizeof (ActionTab) / sizeof (ActionTab[0]));
switch (Action) {
switch (GetSubKey (ActionTab, sizeof (ActionTab) / sizeof (ActionTab[0]))) {
case 0:
case 1:
@@ -437,8 +438,23 @@ static void DoAssert (void)
Action = ASSERT_ACT_ERROR;
break;
case 3:
case 4:
/* Linker warning */
Action = ASSERT_ACT_LDWARN;
break;
case 5:
/* Linker error */
Action = ASSERT_ACT_LDERROR;
break;
default:
Error ("Illegal assert action specifier");
/* Use lderror - there won't be an .o file anyway */
Action = ASSERT_ACT_LDERROR;
break;
}
NextTok ();
@@ -470,7 +486,7 @@ static void DoAssert (void)
}
/* Remember the assertion */
AddAssertion (Expr, Action, Msg);
AddAssertion (Expr, (AssertAction) Action, Msg);
}