X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fcompile.c;h=de1144bb0f5c7c6e2c2e9bc02e64269ec926d6d0;hb=1366b6cbea1b374fa7502354cf2cb8a971f71c5f;hp=4d62aefe55f34a59b8c757bb6dd720b51c2e1711;hpb=aa8737733fe51d2941f434c10ca028ac5ab2986c;p=cc65 diff --git a/src/cc65/compile.c b/src/cc65/compile.c index 4d62aefe5..de1144bb0 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 2000-2001 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -35,9 +35,12 @@ #include -#include "../common/version.h" +/* common */ +#include "version.h" +/* cc65 */ #include "asmlabel.h" +#include "asmstmt.h" #include "codegen.h" #include "declare.h" #include "error.h" @@ -45,7 +48,7 @@ #include "function.h" #include "global.h" #include "incpath.h" -#include "io.h" +#include "input.h" #include "litpool.h" #include "macrotab.h" #include "pragma.h" @@ -55,7 +58,7 @@ /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ @@ -66,30 +69,32 @@ static void Parse (void) int comma; SymEntry* Entry; - kill (); - NextToken (); /* "prime" the pump */ + /* Go... */ NextToken (); - while (curtok != TOK_CEOF) { + NextToken (); + + /* Parse until end of input */ + while (CurTok.Tok != TOK_CEOF) { DeclSpec Spec; Declaration Decl; int NeedStorage; /* Check for empty statements */ - if (curtok == TOK_SEMI) { + if (CurTok.Tok == TOK_SEMI) { NextToken (); continue; } /* Check for an ASM statement (which is allowed also on global level) */ - if (curtok == TOK_ASM) { - doasm (); + if (CurTok.Tok == TOK_ASM) { + AsmStatement (); ConsumeSemi (); continue; } /* Check for a #pragma */ - if (curtok == TOK_PRAGMA) { + if (CurTok.Tok == TOK_PRAGMA) { DoPragma (); continue; } @@ -99,12 +104,12 @@ static void Parse (void) /* Don't accept illegal storage classes */ if (Spec.StorageClass == SC_AUTO || Spec.StorageClass == SC_REGISTER) { - Error (ERR_ILLEGAL_STORAGE_CLASS); + Error ("Illegal storage class"); Spec.StorageClass = SC_EXTERN | SC_STATIC; } /* Check if this is only a type declaration */ - if (curtok == TOK_SEMI) { + if (CurTok.Tok == TOK_SEMI) { CheckEmptyDecl (&Spec); NextToken (); continue; @@ -136,7 +141,7 @@ static void Parse (void) /* Get the symbol flags */ SymFlags = Spec.StorageClass; - if (IsFunc (Decl.Type)) { + if (IsTypeFunc (Decl.Type)) { SymFlags |= SC_FUNC; } else { if (NeedStorage) { @@ -155,25 +160,29 @@ static void Parse (void) unsigned Size = SizeOf (Decl.Type); /* Allow initialization */ - if (curtok == TOK_ASSIGN) { + if (CurTok.Tok == TOK_ASSIGN) { /* We cannot initialize types of unknown size, or * void types in non ANSI mode. */ if (Size == 0) { - if (!IsVoid (Decl.Type)) { - if (!IsArray (Decl.Type)) { - /* Size is unknown and not an array */ - Error (ERR_UNKNOWN_SIZE); - } - } else if (ANSI) { - /* We cannot declare variables of type void */ - Error (ERR_ILLEGAL_TYPE); - } + if (!IsTypeVoid (Decl.Type)) { + if (!IsTypeArray (Decl.Type)) { + /* Size is unknown and not an array */ + Error ("Variable `%s' has unknown size", Decl.Ident); + } + } else if (ANSI) { + /* We cannot declare variables of type void */ + Error ("Illegal type for variable `%s'", Decl.Ident); + } } - /* Switch to the data segment */ - g_usedata (); + /* Switch to the data or rodata segment */ + if (IsQualConst (Decl.Type)) { + g_userodata (); + } else { + g_usedata (); + } /* Define a label */ g_defgloblabel (Entry->Name); @@ -185,12 +194,12 @@ static void Parse (void) ParseInit (Entry->Type); } else { - if (IsVoid (Decl.Type)) { + if (IsTypeVoid (Decl.Type)) { /* We cannot declare variables of type void */ - Error (ERR_ILLEGAL_TYPE); + Error ("Illegal type for variable `%s'", Decl.Ident); } else if (Size == 0) { /* Size is unknown */ - Error (ERR_UNKNOWN_SIZE); + Error ("Variable `%s' has unknown size", Decl.Ident); } /* Switch to the BSS segment */ @@ -206,7 +215,7 @@ static void Parse (void) } /* Check for end of declaration list */ - if (curtok == TOK_COMMA) { + if (CurTok.Tok == TOK_COMMA) { NextToken (); comma = 1; } else { @@ -215,12 +224,12 @@ static void Parse (void) } /* Function declaration? */ - if (IsFunc (Decl.Type)) { + if (Entry && IsTypeFunc (Entry->Type)) { /* Function */ if (!comma) { - if (curtok == TOK_SEMI) { + if (CurTok.Tok == TOK_SEMI) { /* Prototype only */ NextToken (); @@ -243,15 +252,12 @@ static void Parse (void) -void Compile (void) +void Compile (const char* FileName) /* Top level compile routine. Will setup things and call the parser. */ { char* Path; - /* Setup variables */ - LiteralLabel = GetLabel (); - /* Add some standard paths to the include search path */ AddIncludePath ("", INC_USER); /* Current directory */ AddIncludePath ("include", INC_SYS); @@ -266,44 +272,50 @@ void Compile (void) } /* Add macros that are always defined */ - AddNumericMacro ("__CC65__", (VER_MAJOR * 0x100) + (VER_MINOR * 0x10) + VER_PATCH); + DefineNumericMacro ("__CC65__", (VER_MAJOR * 0x100) + (VER_MINOR * 0x10) + VER_PATCH); /* Strict ANSI macro */ if (ANSI) { - AddNumericMacro ("__STRICT_ANSI__", 1); + DefineNumericMacro ("__STRICT_ANSI__", 1); } /* Optimization macros */ if (Optimize) { - AddNumericMacro ("__OPT__", 1); + DefineNumericMacro ("__OPT__", 1); if (FavourSize == 0) { - AddNumericMacro ("__OPT_i__", 1); + DefineNumericMacro ("__OPT_i__", 1); } if (EnableRegVars) { - AddNumericMacro ("__OPT_r__", 1); + DefineNumericMacro ("__OPT_r__", 1); } if (InlineStdFuncs) { - AddNumericMacro ("__OPT_s__", 1); + DefineNumericMacro ("__OPT_s__", 1); } } + /* Initialize the literal pool */ + InitLiteralPool (); + /* Create the base lexical level */ EnterGlobalLevel (); /* Generate the code generator preamble */ g_preamble (); + /* Open the input file */ + OpenMainFile (FileName); + /* Ok, start the ball rolling... */ Parse (); - /* Dump literal pool. */ + /* Dump the literal pool. */ DumpLiteralPool (); /* Write imported/exported symbols */ EmitExternals (); if (Debug) { - PrintLiteralStats (stdout); + PrintLiteralPoolStats (stdout); PrintMacroStats (stdout); }