mirror of
https://github.com/cc65/cc65.git
synced 2025-04-02 09:29:35 +00:00
Move inline asm parsing into a separate module
git-svn-id: svn://svn.cc65.org/cc65/trunk@880 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
bdf212b311
commit
56b8ead112
105
src/cc65/asmstmt.c
Normal file
105
src/cc65/asmstmt.c
Normal file
@ -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 ();
|
||||
}
|
||||
|
||||
|
||||
|
60
src/cc65/asmstmt.h
Normal file
60
src/cc65/asmstmt.h
Normal file
@ -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
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -25,6 +25,7 @@ LDFLAGS=
|
||||
OBJS = anonname.o \
|
||||
asmcode.o \
|
||||
asmlabel.o \
|
||||
asmstmt.o \
|
||||
codeent.o \
|
||||
codegen.o \
|
||||
codelab.o \
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user