]> git.sur5r.net Git - cc65/blobdiff - src/ca65/main.c
Renamed some stuff. Write out the segment size as var, not 32 bit.
[cc65] / src / ca65 / main.c
index ceadced2ed13dd3e6d47bf55391920771ba9d6c3..7364891bc7208c54fac12eed9fbde5f7bd8c7678 100644 (file)
@@ -44,6 +44,7 @@
 #include "cmdline.h"
 #include "mmodel.h"
 #include "print.h"
+#include "scopedefs.h"
 #include "strbuf.h"
 #include "target.h"
 #include "tgttrans.h"
@@ -97,7 +98,7 @@ static void Usage (void)
             "  -g\t\t\t\tAdd debug info to object file\n"
             "  -h\t\t\t\tHelp (this text)\n"
             "  -i\t\t\t\tIgnore case of symbols\n"
-            "  -l\t\t\t\tCreate a listing if assembly was ok\n"
+            "  -l name\t\t\tCreate a listing file if assembly was ok\n"
             "  -mm model\t\t\tSet the memory model\n"
             "  -o name\t\t\tName the output file\n"
             "  -s\t\t\t\tEnable smart mode\n"
@@ -116,7 +117,7 @@ static void Usage (void)
             "  --help\t\t\tHelp (this text)\n"
             "  --ignore-case\t\t\tIgnore case of symbols\n"
             "  --include-dir dir\t\tSet an include directory search path\n"
-            "  --listing\t\t\tCreate a listing if assembly was ok\n"
+            "  --listing name\t\tCreate a listing file if assembly was ok\n"
             "  --list-bytes n\t\tMaximum number of bytes per listing line\n"
             "  --macpack-dir dir\t\tSet a macro package directory\n"
             "  --memory-model model\t\tSet the memory model\n"
@@ -388,7 +389,7 @@ static void OptCreateDep (const char* Opt, const char* Arg)
 
 
 static void OptCreateFullDep (const char* Opt attribute ((unused)),
-                             const char* Arg)
+                             const char* Arg)
 /* Handle the --create-full-dep option */
 {
     FileNameOption (Opt, Arg, &FullDepName);
@@ -477,11 +478,19 @@ static void OptListBytes (const char* Opt, const char* Arg)
 
 
 
-static void OptListing (const char* Opt attribute ((unused)),
-                       const char* Arg attribute ((unused)))
+static void OptListing (const char* Opt, const char* Arg)
 /* Create a listing file */
 {
-    Listing = 1;
+    /* Since the meaning of -l and --listing has changed, print an error if
+     * the filename is empty or begins with the option char.
+     */
+    if (Arg == 0 || *Arg == '\0' || *Arg == '-') {
+        Fatal ("The meaning of `%s' has changed. It does now "
+               "expect a file name as argument.", Opt);
+    }
+
+    /* Get the file name */
+    FileNameOption (Opt, Arg, &ListingName);
 }
 
 
@@ -588,7 +597,7 @@ static void OneLine (void)
     Segment*      Seg   = 0;
     unsigned long PC    = 0;
     SymEntry*     Sym   = 0;
-    int           Macro = 0;
+    Macro*        Mac   = 0;
     int           Instr = -1;
 
     /* Initialize the new listing line if we are actually reading from file
@@ -598,8 +607,8 @@ static void OneLine (void)
                InitListingLine ();
     }
 
+    /* Single colon means unnamed label */
     if (CurTok.Tok == TOK_COLON) {
-               /* An unnamed label */
                ULabDef ();
                NextTok ();
     }
@@ -612,11 +621,11 @@ static void OneLine (void)
             /* Macros and symbols cannot use instruction names */
             Instr = FindInstruction (&CurTok.SVal);
             if (Instr < 0) {
-                Macro = IsMacro (&CurTok.SVal);
+                Mac = FindMacro (&CurTok.SVal);
             }
         } else {
             /* Macros and symbols may use the names of instructions */
-            Macro = IsMacro (&CurTok.SVal);
+            Mac = FindMacro (&CurTok.SVal);
         }
     }
 
@@ -626,7 +635,7 @@ static void OneLine (void)
      */
     if (CurTok.Tok == TOK_LOCAL_IDENT ||
         CurTok.Tok == TOK_NAMESPACE   ||
-        (CurTok.Tok == TOK_IDENT && Instr < 0 && !Macro)) {
+        (CurTok.Tok == TOK_IDENT && Instr < 0 && Mac == 0)) {
 
         /* Did we have whitespace before the ident? */
         int HadWS = CurTok.WS;
@@ -707,11 +716,11 @@ static void OneLine (void)
                     /* Macros and symbols cannot use instruction names */
                     Instr = FindInstruction (&CurTok.SVal);
                     if (Instr < 0) {
-                        Macro = IsMacro (&CurTok.SVal);
+                        Mac = FindMacro (&CurTok.SVal);
                     }
                 } else {
                     /* Macros and symbols may use the names of instructions */
-                    Macro = IsMacro (&CurTok.SVal);
+                    Mac = FindMacro (&CurTok.SVal);
                 }
             }
         }
@@ -721,9 +730,9 @@ static void OneLine (void)
     if (CurTok.Tok >= TOK_FIRSTPSEUDO && CurTok.Tok <= TOK_LASTPSEUDO) {
         /* A control command */
         HandlePseudo ();
-    } else if (Macro) {
+    } else if (Mac != 0) {
         /* A macro expansion */
-        MacExpandStart ();
+        MacExpandStart (Mac);
     } else if (Instr >= 0 ||
                (UbiquitousIdents && ((Instr = FindInstruction (&CurTok.SVal)) >= 0))) {
         /* A mnemonic - assemble one instruction */
@@ -798,12 +807,12 @@ static void CreateObjFile (void)
     /* Write the export list */
     WriteExports ();
 
-    /* Write the scopes if requested */
-    WriteScopes ();
-
     /* Write debug symbols if requested */
     WriteDbgSyms ();
 
+    /* Write the scopes if requested */
+    WriteScopes ();
+
     /* Write line infos if requested */
     WriteLineInfos ();
 
@@ -836,7 +845,7 @@ int main (int argc, char* argv [])
        { "--ignore-case",      0,      OptIgnoreCase           },
        { "--include-dir",      1,      OptIncludeDir           },
         { "--list-bytes",       1,      OptListBytes            },
-       { "--listing",          0,      OptListing              },
+       { "--listing",          1,      OptListing              },
         { "--macpack-dir",      1,      OptMacPackDir           },
         { "--memory-model",     1,      OptMemoryModel          },
        { "--pagelength",       1,      OptPageLength           },
@@ -857,12 +866,15 @@ int main (int argc, char* argv [])
     /* Initialize the include search paths */
     InitIncludePaths ();
 
+    /* Create the predefined segments */
+    SegInit ();
+
     /* Enter the base lexical level. We must do that here, since we may
      * define symbols using -D.
      */
-    SymEnterLevel (&GlobalNameSpace, ST_GLOBAL, ADDR_SIZE_DEFAULT);
+    SymEnterLevel (&GlobalNameSpace, SCOPE_FILE, ADDR_SIZE_DEFAULT, 0);
 
-    /* Initialize the line infos. Must be done here, since we need line infos 
+    /* Initialize the line infos. Must be done here, since we need line infos
      * for symbol definitions.
      */
     InitLineInfo ();
@@ -895,7 +907,7 @@ int main (int argc, char* argv [])
                            break;
 
                        case 'l':
-                   OptListing (Arg, 0);
+                   OptListing (Arg, GetArg (&I, 2));
                            break;
 
                 case 'm':
@@ -982,8 +994,8 @@ int main (int argc, char* argv [])
         SetMemoryModel (MMODEL_NEAR);
     }
 
-    /* Initialize the segments */
-    InitSegments ();
+    /* Set the default segment sizes according to the memory model */
+    SetSegmentSizes ();
 
     /* Initialize the scanner, open the input file */
     InitScanner (InFile);
@@ -999,9 +1011,9 @@ int main (int argc, char* argv [])
         CheckPseudo ();
     }
 
-    /* If we didn't have any errors, check the unnamed labels */
+    /* If we didn't have any errors, check and cleanup the unnamed labels */
     if (ErrorCount == 0) {
-        ULabCheck ();
+        ULabDone ();
     }
 
     /* If we didn't have any errors, check the symbol table */
@@ -1009,31 +1021,36 @@ int main (int argc, char* argv [])
         SymCheck ();
     }
 
+    /* If we didn't have any errors, close the file scope lexical level */
+    if (ErrorCount == 0) {
+        SymLeaveLevel ();
+    }
+
     /* If we didn't have any errors, check and resolve the segment data */
     if (ErrorCount == 0) {
-        SegCheck ();
+        SegDone ();
     }
 
-    /* If we didn't have any errors, check the assertions */
+    /* If we didn't have any errors, check       the assertions */
     if (ErrorCount == 0) {
         CheckAssertions ();
     }
 
-    /* If we didn't have an errors, index the line infos */
-    MakeLineInfoIndex ();
-
     /* Dump the data */
     if (Verbosity >= 2) {
         SymDump (stdout);
         SegDump ();
     }
 
+    /* If we didn't have an errors, finish off the line infos */
+    DoneLineInfo ();
+
     /* If we didn't have any errors, create the object, listing and
      * dependency files
      */
     if (ErrorCount == 0) {
        CreateObjFile ();
-       if (Listing) {
+       if (SB_GetLen (&ListingName) > 0) {
            CreateListing ();
        }
        CreateDependencies ();