Added assertions

git-svn-id: svn://svn.cc65.org/cc65/trunk@2202 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2003-06-06 12:45:19 +00:00
parent 0aa75f12d6
commit bb24d025f6
29 changed files with 405 additions and 183 deletions

View File

@@ -162,6 +162,7 @@ void ErrorMsg (const FilePos* Pos, unsigned ErrNum, va_list ap)
"Illegal macro package name",
"Illegal emulation feature",
"Illegal scope specifier",
"Illegal assert action",
"Syntax error",
"Symbol `%s' is already defined",
"Undefined symbol `%s'",

View File

@@ -103,6 +103,7 @@ enum Errors {
ERR_ILLEGAL_MACPACK,
ERR_ILLEGAL_FEATURE,
ERR_ILLEGAL_SCOPE,
ERR_ILLEGAL_ASSERT_ACTION,
ERR_SYNTAX,
ERR_SYM_ALREADY_DEFINED,
ERR_SYM_UNDEFINED,

View File

@@ -56,6 +56,7 @@
#include "incpath.h"
#include "instr.h"
#include "istack.h"
#include "ldassert.h"
#include "lineinfo.h"
#include "listing.h"
#include "macro.h"
@@ -484,6 +485,9 @@ static void CreateObjFile (void)
/* Write the string pool */
WriteStrPool ();
/* Write the assertions */
WriteAssertions ();
/* Write an updated header and close the file */
ObjClose ();
}

View File

@@ -22,6 +22,7 @@ OBJS = condasm.o \
incpath.o \
instr.o \
istack.o \
ldassert.o \
lineinfo.o \
listing.o \
macpack.o \

View File

@@ -55,6 +55,7 @@ OBJS = condasm.obj \
incpath.obj \
instr.obj \
istack.obj \
ldassert.obj \
lineinfo.obj \
listing.obj \
macpack.obj \

View File

@@ -81,7 +81,9 @@ static ObjHeader Header = {
0, /* 32: Offset to list of line infos */
0, /* 32: Size of line infos */
0, /* 32: Offset to string pool */
0 /* 32: Size of string pool */
0, /* 32: Size of string pool */
0, /* 32: Offset to assertion table */
0 /* 32: Size of assertion table */
};
@@ -134,6 +136,8 @@ static void ObjWriteHeader (void)
ObjWrite32 (Header.LineInfoSize);
ObjWrite32 (Header.StrPoolOffs);
ObjWrite32 (Header.StrPoolSize);
ObjWrite32 (Header.AssertOffs);
ObjWrite32 (Header.AssertSize);
}
@@ -442,3 +446,19 @@ void ObjEndStrPool (void)
void ObjStartAssertions (void)
/* Mark the start of the assertion table */
{
Header.AssertOffs = ftell (F);
}
void ObjEndAssertions (void)
/* Mark the end of the assertion table */
{
Header.AssertSize = ftell (F) - Header.AssertOffs;
}

View File

@@ -133,6 +133,12 @@ void ObjStartStrPool (void);
void ObjEndStrPool (void);
/* Mark the end of the string pool section */
void ObjStartAssertions (void);
/* Mark the start of the assertion table */
void ObjEndAssertions (void);
/* Mark the end of the assertion table */
/* End of objfile.h */

View File

@@ -56,15 +56,17 @@
#include "global.h"
#include "incpath.h"
#include "instr.h"
#include "ldassert.h"
#include "listing.h"
#include "macpack.h"
#include "macro.h"
#include "nexttok.h"
#include "objcode.h"
#include "options.h"
#include "repeat.h"
#include "symtab.h"
#include "pseudo.h"
#include "repeat.h"
#include "spool.h"
#include "symtab.h"
@@ -326,6 +328,55 @@ static void DoASCIIZ (void)
static void DoAssert (void)
/* Add an assertion */
{
static const char* ActionTab [] = {
"WARN", "WARNING",
"ERROR"
};
int Action;
/* First we have the expression that has to evaluated */
ExprNode* Expr = Expression ();
ConsumeComma ();
/* Action follows */
if (Tok != TOK_IDENT) {
ErrorSkip (ERR_IDENT_EXPECTED);
return;
}
Action = GetSubKey (ActionTab, sizeof (ActionTab) / sizeof (ActionTab[0]));
switch (Action) {
case 0:
case 1:
/* Warning */
break;
case 2:
/* Error */
break;
default:
Error (ERR_ILLEGAL_SEG_ATTR);
}
NextTok ();
ConsumeComma ();
/* Read the message */
if (Tok != TOK_STRCON) {
ErrorSkip (ERR_STRCON_EXPECTED);
} else {
AddAssertion (Expr, Action, GetStringId (SVal));
NextTok ();
}
}
static void DoAutoImport (void)
/* Mark unresolved symbols as imported */
{
@@ -1078,7 +1129,7 @@ static void DoMacPack (void)
/* Insert the package */
InsertMacPack (Package);
}
}
@@ -1403,11 +1454,11 @@ enum {
};
/* Control command table */
struct CtrlDesc_ {
typedef struct CtrlDesc CtrlDesc;
struct CtrlDesc {
unsigned Flags; /* Flags for this directive */
void (*Handler) (void); /* Command handler */
};
typedef struct CtrlDesc_ CtrlDesc;
#define PSEUDO_COUNT (sizeof (CtrlCmdTab) / sizeof (CtrlCmdTab [0]))
static CtrlDesc CtrlCmdTab [] = {
@@ -1416,6 +1467,7 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoAddr }, /* .ADDR */
{ ccNone, DoAlign },
{ ccNone, DoASCIIZ },
{ ccNone, DoAssert },
{ ccNone, DoAutoImport },
{ ccNone, DoUnexpected }, /* .BLANK */
{ ccNone, DoBss },

View File

@@ -123,6 +123,7 @@ struct DotKeyword {
{ ".ALIGN", TOK_ALIGN },
{ ".AND", TOK_BAND },
{ ".ASCIIZ", TOK_ASCIIZ },
{ ".ASSERT", TOK_ASSERT },
{ ".AUTOIMPORT", TOK_AUTOIMPORT },
{ ".BITAND", TOK_AND },
{ ".BITNOT", TOK_NOT },

View File

@@ -115,6 +115,7 @@ enum Token {
TOK_ADDR,
TOK_ALIGN,
TOK_ASCIIZ,
TOK_ASSERT,
TOK_AUTOIMPORT,
TOK_BLANK,
TOK_BSS,
@@ -235,7 +236,7 @@ extern int ForcedEnd; /* Force end of assembly */
/*****************************************************************************/
void NewInputFile (const char* Name);
/* Open a new input file */