]> Shamusworld >> Repos - rmac/blobdiff - riscasm.c
Fixed subtle bug in expr().
[rmac] / riscasm.c
index fbc8f81cf605ff2a14178c7754b9c64bac94718b..89dfd3a881b831b3a6c9ac7e28d94b2c68c756fe 100644 (file)
--- a/riscasm.c
+++ b/riscasm.c
@@ -130,9 +130,11 @@ void strtoupper(char * s)
 // Function to return "malformed expression" error
 // This is done mainly to remove a bunch of GOTO statements in the parser
 //
-static inline int MalformedOpcode(void)
+static inline int MalformedOpcode(int signal)
 {
-       error("Malformed opcode");
+       char buf[16];
+       sprintf(buf, "%02X", signal);
+       errors("Malformed opcode [internal $%s]", buf);
        return ERROR;
 }
 
@@ -166,20 +168,13 @@ int GetRegister(WORD rattr)
 
        // Evaluate what's in the global "tok" buffer
        if (expr(r_expr, &eval, &eattr, &esym) != OK)
-               return MalformedOpcode();
+               // Hmm, the evaluator should report the error to us...
+//             return MalformedOpcode(0x00);
+               return ERROR;
 
        if ((challoc - ch_size) < 4)
                chcheck(4L);
 
-       // See if this symbol has been defined, then undefined:
-//does nothing
-//segfaults now (esym == NULL?)
-/*     if (esym->sattre & UNDEF_EQUR)
-       {
-               error("undefined register");
-               return ERROR;
-       }*/
-
        if (!(eattr & DEFINED))
        {
                fixup((WORD)(FU_WORD | rattr), sloc, r_expr);      
@@ -294,12 +289,12 @@ int GenerateRISCCode(int state)
                        attrflg |= FU_SUB32;
 
                if (*tok != '#')
-                       return MalformedOpcode();
+                       return MalformedOpcode(0x01);
 
                tok++;
 
                if (expr(r_expr, &eval, &eattr, &esym) != OK)
-                       return MalformedOpcode();
+                       return MalformedOpcode(0x02);
 
                if ((challoc - ch_size) < 4)
                        chcheck(4L);
@@ -334,12 +329,12 @@ int GenerateRISCCode(int state)
        // Move Immediate--n,Rn--n in Second Word
        case RI_MOVEI:
                if (*tok != '#')
-                       return MalformedOpcode();
+                       return MalformedOpcode(0x03);
 
                tok++;
 
                if (expr(r_expr, &eval, &eattr, &esym) != OK)
-                       return MalformedOpcode();
+                       return MalformedOpcode(0x04);
 
                if ((challoc - ch_size) < 4)
                        chcheck(4L);
@@ -392,7 +387,7 @@ int GenerateRISCCode(int state)
                parm = 41;
 
                if (*tok != '(')
-                       return MalformedOpcode();
+                       return MalformedOpcode(0x05);
 
                tok++;
 
@@ -461,7 +456,7 @@ int GenerateRISCCode(int state)
                                else
                                {
                                        if (expr(r_expr, &eval, &eattr, &esym) != OK)
-                                               return MalformedOpcode();
+                                               return MalformedOpcode(0x06);
 
                                        if ((challoc - ch_size) < 4)
                                                chcheck(4L);
@@ -502,7 +497,7 @@ int GenerateRISCCode(int state)
                }
 
                if (*tok != ')')
-                       return MalformedOpcode();
+                       return MalformedOpcode(0x07);
 
                tok++;
                CHECK_COMMA;
@@ -518,7 +513,7 @@ int GenerateRISCCode(int state)
                CHECK_COMMA;
 
                if (*tok != '(')
-                       return MalformedOpcode();
+                       return MalformedOpcode(0x08);
 
                tok++;
                indexed = 0;
@@ -588,7 +583,7 @@ int GenerateRISCCode(int state)
                                else
                                {
                                        if (expr(r_expr, &eval, &eattr, &esym) != OK)
-                                               return MalformedOpcode();
+                                               return MalformedOpcode(0x09);
 
                                        if ((challoc - ch_size) < 4)
                                                chcheck(4L);
@@ -631,7 +626,7 @@ int GenerateRISCCode(int state)
                }
 
                if (*tok != ')')
-                       return MalformedOpcode();
+                       return MalformedOpcode(0x0A);
 
                tok++;
                at_eol();
@@ -641,13 +636,13 @@ int GenerateRISCCode(int state)
        // LOADB/LOADP/LOADW (Rn),Rn
        case RI_LOADN:                    
                if (*tok != '(')
-                       return MalformedOpcode();
+                       return MalformedOpcode(0x0B);
 
                tok++;
                reg1 = GetRegister(FU_REGONE);
 
                if (*tok != ')')
-                       return MalformedOpcode();
+                       return MalformedOpcode(0x0C);
 
                tok++;
                CHECK_COMMA;
@@ -662,13 +657,13 @@ int GenerateRISCCode(int state)
                CHECK_COMMA;
 
                if (*tok != '(')
-                       return MalformedOpcode();
+                       return MalformedOpcode(0x0D);
 
                tok++;
                reg2 = GetRegister(FU_REGTWO);
 
                if (*tok != ')')
-                       return MalformedOpcode();
+                       return MalformedOpcode(0x0E);
 
                tok++;
                at_eol();
@@ -765,7 +760,7 @@ int GenerateRISCCode(int state)
                {
                        // JR cc,n
                        if (expr(r_expr, &eval, &eattr, &esym) != OK)
-                               return MalformedOpcode();
+                               return MalformedOpcode(0x0F);
 
                        if ((challoc - ch_size) < 4)
                                chcheck(4L);
@@ -789,13 +784,13 @@ int GenerateRISCCode(int state)
                {
                        // JUMP cc, (Rn)
                        if (*tok != '(')
-                               return MalformedOpcode();
+                               return MalformedOpcode(0x10);
 
                        tok++;
                        reg2 = GetRegister(FU_REGTWO);
 
                        if (*tok != ')')
-                               return MalformedOpcode();
+                               return MalformedOpcode(0x11);
 
                        tok++;
                        at_eol();