]> git.sur5r.net Git - cc65/commitdiff
Move inline asm parsing into a separate module
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 9 Sep 2001 09:33:06 +0000 (09:33 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 9 Sep 2001 09:33:06 +0000 (09:33 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@880 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/asmstmt.c [new file with mode: 0644]
src/cc65/asmstmt.h [new file with mode: 0644]
src/cc65/compile.c
src/cc65/expr.c
src/cc65/make/gcc.mak
src/cc65/make/watcom.mak

diff --git a/src/cc65/asmstmt.c b/src/cc65/asmstmt.c
new file mode 100644 (file)
index 0000000..76f5596
--- /dev/null
@@ -0,0 +1,105 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                asmstmt.c                                 */
+/*                                                                           */
+/*           Inline assembler statements for the cc65 C compiler            */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2001             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>
+
+/* cc65 */         
+#include "codegen.h"
+#include "error.h"
+#include "litpool.h"
+#include "scanner.h"
+#include "asmstmt.h"
+
+
+
+/*****************************************************************************/
+/*                                  Code                                    */
+/*****************************************************************************/
+
+
+
+void AsmStatement (void)
+/* This function parses ASM statements. The syntax of the ASM directive
+ * looks like the one defined for C++ (C has no ASM directive), that is,
+ * a string literal in parenthesis.
+ */
+{
+    /* Skip the ASM */
+    NextToken ();
+
+    /* Need left parenthesis */
+    ConsumeLParen ();
+
+    /* String literal */
+    if (CurTok.Tok != TOK_SCONST) {
+       Error ("String literal expected");
+    } else {
+
+       /* The string literal may consist of more than one line of assembler
+        * code. Separate the single lines and output the code.
+        */
+       const char* S = GetLiteral (CurTok.IVal);
+       while (*S) {
+
+                   /* Separate the lines */
+           const char* E = strchr (S, '\n');
+           if (E) {
+               /* Found a newline */
+               g_asmcode (S, E-S);
+               S = E+1;
+           } else {
+               int Len = strlen (S);
+               g_asmcode (S, Len);
+               S += Len;
+           }
+       }
+
+       /* Reset the string pointer, effectivly clearing the string from the
+        * string table. Since we're working with one token lookahead, this
+        * will fail if the next token is also a string token, but that's a
+        * syntax error anyway, because we expect a right paren.
+        */
+       ResetLiteralPoolOffs (CurTok.IVal);
+    }
+
+    /* Skip the string token */
+    NextToken ();
+
+    /* Closing paren needed */
+    ConsumeRParen ();
+}
+
+
+
diff --git a/src/cc65/asmstmt.h b/src/cc65/asmstmt.h
new file mode 100644 (file)
index 0000000..9de91f4
--- /dev/null
@@ -0,0 +1,60 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                asmstmt.h                                 */
+/*                                                                           */
+/*           Inline assembler statements for the cc65 C compiler            */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2001             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 ASMSTMT_H
+#define ASMSTMT_H
+
+
+
+/*****************************************************************************/
+/*                                  Code                                    */
+/*****************************************************************************/
+
+
+
+void AsmStatement (void);
+/* This function parses ASM statements. The syntax of the ASM directive
+ * looks like the one defined for C++ (C has no ASM directive), that is,
+ * a string literal in parenthesis.
+ */
+
+
+
+/* End of asmstmt.h */
+
+#endif
+
+
+
index 19a5446e3d445efa8a8d507f2fcd03382d452dd2..de1144bb0f5c7c6e2c2e9bc02e64269ec926d6d0 100644 (file)
@@ -40,6 +40,7 @@
 
 /* cc65 */
 #include "asmlabel.h"
+#include "asmstmt.h"
 #include "codegen.h"
 #include "declare.h"
 #include "error.h"
@@ -87,7 +88,7 @@ static void Parse (void)
 
        /* Check for an ASM statement (which is allowed also on global level) */
        if (CurTok.Tok == TOK_ASM) {
-           doasm ();
+           AsmStatement ();
            ConsumeSemi ();
            continue;
        }
index 71b9788bacd162183374785a2af4bee3ec390864..46484528e925977bbad457ddd9b0bb2c586610f6 100644 (file)
@@ -17,6 +17,7 @@
 /* cc65 */
 #include "asmcode.h"
 #include "asmlabel.h"
+#include "asmstmt.h"
 #include "codegen.h"
 #include "datatype.h"
 #include "declare.h"
@@ -758,59 +759,6 @@ static void CallFunction (ExprDesc* lval)
 
 
 
-void doasm (void)
-/* This function parses ASM statements. The syntax of the ASM directive
- * looks like the one defined for C++ (C has no ASM directive), that is,
- * a string literal in parenthesis.
- */
-{
-    /* Skip the ASM */
-    NextToken ();
-
-    /* Need left parenthesis */
-    ConsumeLParen ();
-
-    /* String literal */
-    if (CurTok.Tok != TOK_SCONST) {
-       Error ("String literal expected");
-    } else {
-
-       /* The string literal may consist of more than one line of assembler
-        * code. Separate the single lines and output the code.
-        */
-       const char* S = GetLiteral (CurTok.IVal);
-       while (*S) {
-
-           /* Allow lines up to 256 bytes */
-           const char* E = strchr (S, '\n');
-           if (E) {
-               /* Found a newline */
-               g_asmcode (S, E-S);
-               S = E+1;
-           } else {
-               int Len = strlen (S);
-               g_asmcode (S, Len);
-               S += Len;
-           }
-       }
-
-       /* Reset the string pointer, effectivly clearing the string from the
-        * string table. Since we're working with one token lookahead, this
-        * will fail if the next token is also a string token, but that's a
-        * syntax error anyway, because we expect a right paren.
-        */
-       ResetLiteralPoolOffs (CurTok.IVal);
-    }
-
-    /* Skip the string token */
-    NextToken ();
-
-    /* Closing paren needed */
-    ConsumeRParen ();
-}
-
-
-
 static int primary (ExprDesc* lval)
 /* This is the lowest level of the expression parser. */
 {
@@ -977,7 +925,7 @@ static int primary (ExprDesc* lval)
 
     /* ASM statement? */
     if (CurTok.Tok == TOK_ASM) {
-       doasm ();
+       AsmStatement ();
        lval->Type  = type_void;
        lval->Flags = E_MEXPR;
        lval->ConstVal = 0;
index 38db8dffdca730b43dbb1587421af082d863726e..5facfeaaa686e8bd0c558413761bf6ab8c4cab4f 100644 (file)
@@ -25,6 +25,7 @@ LDFLAGS=
 OBJS = anonname.o      \
        asmcode.o       \
        asmlabel.o      \
+       asmstmt.o       \
        codeent.o       \
        codegen.o       \
        codelab.o       \
index 62a982120dbaad74916d2da4fd4410271eb444d9..ad6585172c8be426e9b9fca8270e801532f2f967 100644 (file)
@@ -70,6 +70,7 @@ CCCFG = $(CCCFG) -i=..\common
 OBJS = anonname.obj    \
        asmcode.obj     \
        asmlabel.obj    \
+       asmstmt.obj     \
        codeent.obj     \
        codegen.obj     \
        codelab.obj     \
@@ -138,6 +139,7 @@ NAME $<
 FILE anonname.obj
 FILE asmcode.obj
 FILE asmlabel.obj
+FILE asmstmt.obj
 FILE codeent.obj
 FILE codegen.obj
 FILE codelab.obj