/* */
/* compile.c */
/* */
-/* Top level compiler subroutine */
+/* Top level compiler subroutine */
/* */
/* */
/* */
-/* (C) 2000-2008 Ullrich von Bassewitz */
-/* Roemerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 2000-2009, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
#include "input.h"
#include "litpool.h"
#include "macrotab.h"
+#include "output.h"
#include "pragma.h"
#include "preproc.h"
#include "standard.h"
while (CurTok.Tok != TOK_CEOF) {
DeclSpec Spec;
- Declaration Decl;
/* Check for empty statements */
if (CurTok.Tok == TOK_SEMI) {
comma = 0;
while (1) {
+ Declaration Decl;
+
/* Read the next declaration */
ParseDecl (&Spec, &Decl, DM_NEED_IDENT);
if (Decl.Ident[0] == '\0') {
* specified as static. This means that "extern int i" will not
* get storage allocated.
*/
- if ((Decl.StorageClass & SC_FUNC) == 0 &&
- (Decl.StorageClass & SC_TYPEDEF) == 0 &&
+ if ((Decl.StorageClass & SC_FUNC) != SC_FUNC &&
+ (Decl.StorageClass & SC_TYPEDEF) != SC_TYPEDEF &&
((Spec.Flags & DS_DEF_STORAGE) != 0 ||
(Decl.StorageClass & (SC_STATIC | SC_EXTERN)) == SC_STATIC)) {
/* Add an entry to the symbol table */
Entry = AddGlobalSym (Decl.Ident, Decl.Type, Decl.StorageClass);
+ /* Add declaration attributes */
+ SymUseAttr (Entry, &Decl);
+
/* Reserve storage for the variable if we need to */
if (Decl.StorageClass & SC_STORAGE) {
}
}
- /* Switch to the data or rodata segment */
- if (IsQualConst (Decl.Type)) {
- g_userodata ();
+ /* Switch to the data or rodata segment. For arrays, check
+ * the element qualifiers, since not the array but its
+ * elements are const.
+ */
+ if (IsQualConst (Decl.Type) ||
+ (IsTypeArray (Decl.Type) &&
+ IsQualConst (GetElementType (Decl.Type)))) {
+ g_userodata ();
} else {
g_usedata ();
}
};
/* Add macros that are always defined */
- DefineNumericMacro ("__CC65__", VERSION);
+ DefineNumericMacro ("__CC65__", GetVersionAsNumber ());
/* Language standard that is supported */
DefineNumericMacro ("__CC65_STD_C89__", STD_C89);
DefineTextMacro ("__DATE__", DateStr);
DefineTextMacro ("__TIME__", TimeStr);
+ /* Other standard macros */
+ /* DefineNumericMacro ("__STDC__", 1); <- not now */
+ DefineNumericMacro ("__STDC_HOSTED__", 1);
+
/* Initialize the literal pool */
InitLiteralPool ();
/* Are we supposed to compile or just preprocess the input? */
if (PreprocessOnly) {
+ /* Open the file */
+ OpenOutputFile ();
+
+ /* Preprocess each line and write it to the output file */
while (NextLine ()) {
Preprocess ();
- printf ("%.*s\n", SB_GetLen (Line), SB_GetConstBuf (Line));
+ WriteOutput ("%.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
}
+ /* Close the output file */
+ CloseOutputFile ();
+
if (Debug) {
PrintMacroStats (stdout);
}