/* */
/* */
/* */
-/* (C) 1998-2000 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 1998-2004 Ullrich von Bassewitz */
+/* Römerstraße 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
static void IntWarning (const char* Filename, unsigned Line, const char* Msg, va_list ap)
/* Print warning message - internal function. */
{
- if (!NoWarn) {
+ if (!IS_Get (&WarnDisable)) {
fprintf (stderr, "%s(%u): Warning: ", Filename, Line);
vfprintf (stderr, Msg, ap);
fprintf (stderr, "\n");
/* Use abort to create a core dump */
abort ();
-}
+}
/*****************************************************************************/
-
+
extern unsigned char AddSource; /* Add source lines as comments */
extern unsigned char DebugInfo; /* Add debug info to the obj */
extern unsigned char CreateDep; /* Create a dependency file */
extern unsigned char ANSI; /* Strict ANSI flag */
-extern unsigned char NoWarn; /* Suppress warnings */
extern unsigned long OptDisable; /* Optimizer passes to disable */
extern unsigned RegisterSpace; /* Space available for register vars */
/* Stackable options */
+extern IntStack WarnDisable; /* Suppress warnings */
extern IntStack WritableStrings; /* Literal strings are r/w */
extern IntStack InlineStdFuncs; /* Inline some known functions */
extern IntStack EnableRegVars; /* Enable register variables */
PR_CHARMAP,
PR_CHECKSTACK,
PR_CODESEG,
+ PR_CODESIZE,
PR_DATASEG,
+ PR_OPTIMIZE,
PR_REGVARADDR,
PR_REGVARS,
PR_RODATASEG,
PR_SIGNEDCHARS,
PR_STATICLOCALS,
+ PR_WARN,
PR_ZPSYM,
PR_COUNT
} pragma_t;
{ "charmap", PR_CHARMAP },
{ "checkstack", PR_CHECKSTACK },
{ "codeseg", PR_CODESEG },
+ { "codesize", PR_CODESIZE },
{ "dataseg", PR_DATASEG },
+ { "optimize", PR_OPTIMIZE },
{ "regvaraddr", PR_REGVARADDR },
{ "regvars", PR_REGVARS },
{ "rodataseg", PR_RODATASEG },
{ "signedchars", PR_SIGNEDCHARS },
{ "staticlocals", PR_STATICLOCALS },
+ { "warn", PR_WARN },
{ "zpsym", PR_ZPSYM },
};
} else {
SetSegName (Seg, Name);
}
- g_segname (Seg);
+ g_segname (Seg);
/* Call the string buf destructor */
DoneStrBuf (&S);
+static void IntPragma (StrBuf* B, IntStack* Stack, long Low, long High)
+/* Handle a pragma that expects an int paramater */
+{
+ ident Ident;
+ long Val;
+ int Push;
+
+ /* Try to read an identifier */
+ int IsIdent = SB_GetSym (B, Ident);
+
+ /* Check if we have a first argument named "pop" */
+ if (IsIdent && strcmp (Ident, "pop") == 0) {
+ if (IS_GetCount (Stack) < 2) {
+ Error ("Cannot pop, stack is empty");
+ } else {
+ IS_Drop (Stack);
+ }
+ /* No other arguments allowed */
+ return;
+ }
+
+ /* Check if we have a first argument named "push" */
+ if (IsIdent && strcmp (Ident, "push") == 0) {
+ Push = 1;
+ SB_SkipWhite (B);
+ if (SB_Get (B) != ',') {
+ Error ("Comma expected");
+ return;
+ }
+ SB_SkipWhite (B);
+ IsIdent = 0;
+ } else {
+ Push = 0;
+ }
+
+ /* Integer argument follows */
+ if (IsIdent || !SB_GetNumber (B, &Val)) {
+ Error ("Pragma argument must be numeric");
+ return;
+ }
+
+ /* Check the argument */
+ if (Val < Low || Val > High) {
+ Error ("Pragma argument out of bounds (%ld-%ld)", Low, High);
+ return;
+ }
+
+ /* Set/push the new value */
+ if (Push) {
+ if (IS_IsFull (Stack)) {
+ Error ("Cannot push: stack overflow");
+ } else {
+ IS_Push (Stack, Val);
+ }
+ } else {
+ IS_Set (Stack, Val);
+ }
+}
+
+
+
static void ParsePragma (void)
/* Parse the contents of the _Pragma statement */
{
SegNamePragma (&B, SEG_CODE);
break;
+ case PR_CODESIZE:
+ IntPragma (&B, &CodeSizeFactor, 10, 1000);
+ break;
+
case PR_DATASEG:
SegNamePragma (&B, SEG_DATA);
break;
+ case PR_OPTIMIZE:
+ FlagPragma (&B, &Optimize);
+ break;
+
case PR_REGVARADDR:
FlagPragma (&B, &AllowRegVarAddr);
break;
FlagPragma (&B, &StaticLocals);
break;
- case PR_ZPSYM:
+ case PR_WARN:
+ FlagPragma (&B, &WarnDisable);
+ break;
+
+ case PR_ZPSYM:
StringPragma (&B, MakeZPSym);
break;