]> git.sur5r.net Git - cc65/commitdiff
Separated the emulation features in a module.
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 2 Sep 2000 11:35:22 +0000 (11:35 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 2 Sep 2000 11:35:22 +0000 (11:35 +0000)
Add a new command line option --feature that allows to set emulation
features from the command line.

git-svn-id: svn://svn.cc65.org/cc65/trunk@311 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/ca65/feature.c [new file with mode: 0644]
src/ca65/feature.h [new file with mode: 0644]
src/ca65/main.c
src/ca65/make/gcc.mak
src/ca65/make/watcom.mak
src/ca65/pseudo.c
src/ca65/scanner.c
src/ca65/scanner.h

diff --git a/src/ca65/feature.c b/src/ca65/feature.c
new file mode 100644 (file)
index 0000000..71f5f05
--- /dev/null
@@ -0,0 +1,114 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                feature.c                                 */
+/*                                                                           */
+/*                 Subroutines for the emulation features                   */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2000     Ullrich von Bassewitz                                        */
+/*              Wacholderweg 14                                              */
+/*              D-70597 Stuttgart                                            */
+/* EMail:       uz@musoftware.de                                             */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#include <string.h>
+
+/* ca65 */
+#include "global.h"
+#include "feature.h"
+
+
+
+/*****************************************************************************/
+/*                                          Data                                    */
+/*****************************************************************************/
+
+
+
+/* Names of the features */
+static const char* FeatureKeys[FEAT_COUNT] = {
+    "dollar_is_pc",
+    "labels_without_colons",
+    "loose_string_term",
+    "at_in_identifiers",
+    "dollar_in_identifiers",
+    "pc_assignment",
+};
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+feature_t FindFeature (const char* Key)
+/* Find the feature in a table and return the corresponding enum value. If the
+ * feature is invalid, return FEAT_UNKNOWN.
+ */
+{
+    feature_t F;
+
+    /* This is not time critical, so do a linear search */
+    for (F = (feature_t) 0; F < FEAT_COUNT; ++F) {
+       if (strcmp (Key, FeatureKeys[F]) == 0) {
+           /* Found, index is enum value */
+           return F;
+       }
+    }
+
+    /* Not found */
+    return FEAT_UNKNOWN;
+}
+
+
+
+feature_t SetFeature (const char* Key)
+/* Find the feature and set the corresponding flag if the feature is known.
+ * In any case, return the feature found. An invalid Key will return
+ * FEAT_UNKNOWN.
+ */
+{
+    /* Map the string to an enum value */
+    feature_t Feature = FindFeature (Key);
+
+    /* Set the flags */
+    switch (Feature) {
+       case FEAT_DOLLAR_IS_PC:          DollarIsPC     = 1;    break;
+       case FEAT_LABELS_WITHOUT_COLONS: NoColonLabels  = 1;    break;
+       case FEAT_LOOSE_STRING_TERM:     LooseStringTerm= 1;    break;
+       case FEAT_AT_IN_IDENTIFIERS:     AtInIdents     = 1;    break;
+       case FEAT_DOLLAR_IN_IDENTIFIERS: DollarInIdents = 1;    break;
+       case FEAT_PC_ASSIGNMENT:         PCAssignment   = 1;    break;
+               default:                         /* Keep gcc silent */  break;
+    }
+
+    /* Return the value found */
+    return Feature;
+}
+
+
+
diff --git a/src/ca65/feature.h b/src/ca65/feature.h
new file mode 100644 (file)
index 0000000..c366cd9
--- /dev/null
@@ -0,0 +1,86 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                feature.h                                 */
+/*                                                                           */
+/*                 Subroutines for the emulation features                   */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2000     Ullrich von Bassewitz                                        */
+/*              Wacholderweg 14                                              */
+/*              D-70597 Stuttgart                                            */
+/* EMail:       uz@musoftware.de                                             */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#ifndef FEATURE_H
+#define        FEATURE_H
+
+
+
+/*****************************************************************************/
+/*                                          Data                                    */
+/*****************************************************************************/
+
+
+
+typedef enum {
+    FEAT_UNKNOWN               = -1,
+    FEAT_DOLLAR_IS_PC,
+    FEAT_LABELS_WITHOUT_COLONS,
+    FEAT_LOOSE_STRING_TERM,
+    FEAT_AT_IN_IDENTIFIERS,
+    FEAT_DOLLAR_IN_IDENTIFIERS,
+    FEAT_PC_ASSIGNMENT,
+    
+    /* Special value: Number of features available */
+    FEAT_COUNT
+} feature_t;
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+feature_t FindFeature (const char* Key);
+/* Find the feature in a table and return the corresponding enum value. If the
+ * feature is invalid, return FEAT_UNKNOWN.
+ */
+
+feature_t SetFeature (const char* Key);
+/* Find the feature and set the corresponding flag if the feature is known.
+ * In any case, return the feature found. An invalid Key will return
+ * FEAT_UNKNOWN.
+ */
+
+
+
+/* End of feature.h */
+
+#endif
+
+
+
index 5c96f5048dbfd0cdd13a6e870035cf94d77cae0c..ecbb58ec973ea9eb62b1e00d7b41392585ed42c6 100644 (file)
@@ -48,6 +48,7 @@
 #include "abend.h"
 #include "error.h"
 #include "expr.h"
+#include "feature.h"
 #include "filetab.h"
 #include "global.h"
 #include "incpath.h"
@@ -96,6 +97,7 @@ static void Usage (void)
                     "  --auto-import\t\tMark unresolved symbols as import\n"
                     "  --cpu type\t\tSet cpu type\n"
                     "  --debug-info\t\tAdd debug info to object file\n"
+            "  --feature name\tSet an emulation feature\n"
             "  --help\t\tHelp (this text)\n"
             "  --ignore-case\t\tIgnore case of symbols\n"
                     "  --include-dir dir\tSet an include directory search path\n"
@@ -220,6 +222,17 @@ static void OptDebugInfo (const char* Opt, const char* Arg)
 
 
 
+static void OptFeature (const char* Opt, const char* Arg)
+/* Set an emulation feature */
+{
+    /* Set the feature, check for errors */
+    if (SetFeature (Arg) == FEAT_UNKNOWN) {
+       AbEnd ("Illegal emulation feature: `%s'", Arg);
+    }
+}
+
+
+
 static void OptHelp (const char* Opt, const char* Arg)
 /* Print usage information and exit */
 {
@@ -479,15 +492,16 @@ int main (int argc, char* argv [])
         { "--auto-import",             0,      OptAutoImport           },
         { "--cpu",                     1,      OptCPU                  },
        { "--debug-info",       0,      OptDebugInfo            },
-       { "--help",             0,      OptHelp                 },
+       { "--feature",          1,      OptFeature              },
+       { "--help",             0,      OptHelp                 },
        { "--ignore-case",      0,      OptIgnoreCase           },
        { "--include-dir",      1,      OptIncludeDir           },
-       { "--listing",          0,      OptListing              },
+       { "--listing",          0,      OptListing              },
        { "--pagelength",       1,      OptPageLength           },
-       { "--smart",            0,      OptSmart                },
-       { "--target",           1,      OptTarget               },
-       { "--verbose",          0,      OptVerbose              },
-       { "--version",          0,      OptVersion              },
+       { "--smart",            0,      OptSmart                },
+       { "--target",           1,      OptTarget               },
+       { "--verbose",          0,      OptVerbose              },
+       { "--version",          0,      OptVersion              },
     };
 
     int I;
index 6407780dc7b580ee7d3cf5041d3b02389a25a15a..66366a8e11ebf00610c48e79918e026b8c67d5ef 100644 (file)
@@ -14,6 +14,7 @@ OBJS =  condasm.o     \
        ea.o            \
         error.o                \
         expr.o         \
+       feature.o       \
        filetab.o       \
        fragment.o      \
         global.o               \
index 28817ef76c759bf49ed7bdfba1d677f184401f17..a09f90c1457031a918b9d40bfc9efcb6bf94e937 100644 (file)
@@ -72,6 +72,7 @@ OBJS =        condasm.obj     \
        ea.obj          \
        error.obj       \
        expr.obj        \
+       feature.obj     \
        filetab.obj     \
        fragment.obj    \
        global.obj      \
@@ -118,6 +119,7 @@ FILE dbginfo.obj
 FILE ea.obj
 FILE error.obj
 FILE expr.obj
+FILE feature.obj
 FILE filetab.obj
 FILE fragment.obj
 FILE global.obj
index 58a778034b2e5796b44999e89384d2fbec154fe9..7deb39c1bdcc660b01d9bb80fdfd78071d83f731 100644 (file)
@@ -49,6 +49,7 @@
 #include "dbginfo.h"
 #include "error.h"
 #include "expr.h"
+#include "feature.h"
 #include "global.h"
 #include "instr.h"
 #include "listing.h"
@@ -511,17 +512,6 @@ static void DoFarAddr (void)
 static void DoFeature (void)
 /* Switch the Feature option */
 {
-    int Feature;
-
-    static const char* Keys[] = {
-               "DOLLAR_IS_PC",
-       "LABELS_WITHOUT_COLONS",
-       "LOOSE_STRING_TERM",
-       "AT_IN_IDENTIFIERS",
-       "DOLLAR_IN_IDENTIFIERS",
-       "PC_ASSIGNMENT",
-    };
-
     /* Allow a list of comma separated keywords */
     while (1) {
 
@@ -531,27 +521,18 @@ static void DoFeature (void)
            return;
        }
 
-       /* Map the keyword to a number */
-       Feature = GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]));
-       if (Feature < 0) {
+       /* Make the string attribute lower case */
+       LocaseSVal ();
+
+       /* Set the feature and check for errors */
+       if (SetFeature (SVal) == FEAT_UNKNOWN) {
            /* Not found */
            ErrorSkip (ERR_ILLEGAL_FEATURE);
            return;
-       }
-
-       /* Skip the keyword */
-       NextTok ();
-
-       /* Switch the feature on */
-       switch (Feature) {
-           case 0:     DollarIsPC      = 1;    break;
-           case 1:     NoColonLabels   = 1;    break;
-           case 2:     LooseStringTerm = 1;    break;
-           case 3:     AtInIdents      = 1;    break;
-           case 4:     DollarInIdents  = 1;    break;
-           case 5:     PCAssignment    = 1;    break;
-           default:    Internal ("Invalid feature: %d", Feature);
-       }
+       } else {
+           /* Skip the keyword */
+           NextTok ();
+       }
 
        /* Allow more than one keyword */
        if (Tok == TOK_COMMA) {
index 850bf03093e12e4877d8788a9ccc17d3fa785fa6..69733a3cd0ae900f17de6ad95e5702312c5d8d7a 100644 (file)
@@ -493,6 +493,18 @@ static void NextChar (void)
 
 
 
+void LocaseSVal (void)
+/* Make SVal lower case */
+{
+    unsigned I = 0;
+    while (SVal [I]) {
+       SVal [I] = tolower (SVal [I]);
+       ++I;
+    }
+}
+
+
+
 void UpcaseSVal (void)
 /* Make SVal upper case */
 {
index b2707d5111fc693a0d476c5a17ce0b124766b026..91ca49a2751386b1728eb22bc10debd74e22df15 100644 (file)
@@ -236,6 +236,9 @@ void DoneInputFile (void);
 void NewInputData (const char* Data, int Malloced);
 /* Add a chunk of input data to the input stream */
 
+void LocaseSVal (void);
+/* Make SVal lower case */
+
 void UpcaseSVal (void);
 /* Make SVal upper case */