xa51, work in progress
[fw/sdcc] / as / xa51 / xa_asm.y
index 339b750915da8e6fccad8292a3c589f03ab64532..4b87ea3f109abf8f7bb1419e8cc2a2a37f540fa1 100644 (file)
@@ -5,7 +5,7 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; version 2.
  *
- * Foobar is distributed in the hope that it will be useful,
+ * Paul's XA51 Assembler is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
@@ -40,7 +40,6 @@ extern void yyrestart(FILE *new_file);
 extern char * disasm(int byte, int memory_location);
 extern void hexout(int byte, int memory_location, int end);
 void error(char *s);
-void fatal_error(char *s);
 
 static int bitmask[]={1, 2, 4, 8, 16, 32, 64, 128};
 
@@ -54,7 +53,7 @@ static int bitmask[]={1, 2, 4, 8, 16, 32, 64, 128};
 %token SETB SEXT SUB SUBB TRAP XCH XOR
 %token REG DPTR PC A C USP
 %token WORD BIT NUMBER CHAR STRING EOL LOCAL_LABEL
-%token ORG EQU DB DW BITDEF REGDEF LOW HIGH
+%token ORG EQU SFR DB DW BITDEF REGDEF LOW HIGH
 %token RSHIFT LSHIFT
 %token AREA AREA_NAME AREA_DESC DS
 %token MODULE GLOBL 
@@ -85,7 +84,7 @@ line:          linesymbol ':' linenosym {
                }
 
 linenosym:     directive EOL {
-                       if (p3) out(op, $1);
+                       if (p3) out(op, $1);
                        $$ = $1;
                }
              | instruction EOL {
@@ -112,9 +111,14 @@ directive:     '.' ORG expr {
                        if (p1 || p2) assign_value(symbol_name, $5);
                        $$ = 0;
                }
-            | symbol EQU expr {
+             | normal_or_bit_symbol '=' expr {
+                       if (p1) build_sym_list(symbol_name);
+                       if (p1 || p2) assign_value(symbol_name, $3);
+               }
+            | symbol SFR expr {
                        if (p1) build_sym_list(symbol_name);
                        if (p1 || p2) assign_value(symbol_name, $3);
+                       if (p1 || p2) mk_sfr(symbol_name);
                        $$ = 0;
                }
             | '.' BITDEF bitsymbol ',' bit {
@@ -133,6 +137,14 @@ directive:     '.' ORG expr {
                         if (p1 || p2) assign_value(symbol_name, $3);
                         $$ = 0;
                 }
+            | bitsymbol BITDEF expr {
+                       if (p1) {
+                                build_sym_list(symbol_name);
+                                mk_bit(symbol_name);
+                        }
+                        if (p1 || p2) assign_value(symbol_name, $3);
+                        $$ = 0;
+                }
             | '.' REGDEF regsymbol ',' REG {
                        if (p1) {
                                build_sym_list(symbol_name);
@@ -166,14 +178,16 @@ directive:     '.' ORG expr {
                }
             | '.' MODULE WORD {
                        /* ignore module definition */
-                       build_sym_list(lex_sym_name);
-                       assign_value(lex_sym_name, 0);
                        $$ = 0;
                }
             | '.' GLOBL WORD {
                        /* ignore global symbol declaration */
                        $$ = 0;
                }
+            | '.' GLOBL bit {
+                       /* ignore bit symbol declaration */
+                       $$ = 0;
+               }
             | '.' DS expr {
                        /* todo: if CSEG, emit some filler bytes */
                        $$ = $3;
@@ -182,7 +196,7 @@ directive:     '.' ORG expr {
 db_directive:  DB {db_count = 0;}
 
 
-linesymbol:    WORD  { 
+linesymbol:    normal_or_bit_symbol  { 
                        strcpy(symbol_name, lex_sym_name);
                        if (!strchr(lex_sym_name, ':')) {
                                /* non-local label, remember base name */
@@ -191,6 +205,9 @@ linesymbol:    WORD  {
                        if (is_target(symbol_name)) pad_with_nop();
                }
 
+normal_or_bit_symbol: WORD {$$ = $1;}
+               | BIT {$$ = $1;}
+
 bytes:           byte_element
                | bytes ',' byte_element
 
@@ -1124,7 +1141,7 @@ int reg(int reg_spec)
 int reg_indirect(int reg_spec)
 {
        if (reg_spec & BYTE_REG)
-               error("Imdirect addressing may not use byte registers");
+               error("Indirect addressing may not use byte registers");
        if ((reg_spec & 15) > 7)
                error("Only R0 through R7 may be used for indirect addr");
        return reg_spec & 7;
@@ -1302,11 +1319,6 @@ int yyerror(char *s)
 }
 
 void error(char *s)
-{
-       yyerror(s);
-}
-
-void fatal_error(char *s)
 {
        yyerror(s);
        exit(1);