From 239cbdcb2b601871dfcb96757f0a2e3b78b48a79 Mon Sep 17 00:00:00 2001 From: cuz Date: Tue, 1 May 2001 16:57:43 +0000 Subject: [PATCH] Working on the backend git-svn-id: svn://svn.cc65.org/cc65/trunk@702 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/asmcode.c | 7 +------ src/cc65/codegen.c | 34 ++++++++++++++++++++-------------- src/cc65/codegen.h | 18 ++++++++++++++---- src/cc65/codeseg.c | 3 --- src/cc65/expr.c | 28 ++++++++++++++++++++-------- src/cc65/litpool.h | 8 ++++---- 6 files changed, 59 insertions(+), 39 deletions(-) diff --git a/src/cc65/asmcode.c b/src/cc65/asmcode.c index cf1979457..227adbe2b 100644 --- a/src/cc65/asmcode.c +++ b/src/cc65/asmcode.c @@ -64,12 +64,7 @@ void AddCodeHint (const char* Hint) CodeMark GetCodePos (void) /* Get a marker pointing to the current output position */ { - unsigned EntryCount = GetCodeSegEntries (CS); - - /* This function should never be called without any code output */ - CHECK (EntryCount > 0); - - return EntryCount; + return GetCodeSegEntries (CS); } diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index 8c1bd89f5..4573471d0 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -49,8 +49,6 @@ #include "cpu.h" #include "error.h" #include "global.h" -#include "litpool.h" -/* ### #include "optimize.h" */ #include "segname.h" #include "util.h" #include "codegen.h" @@ -191,18 +189,6 @@ void g_preamble (void) /* Define long branch macros */ AddCodeLine (".macpack\tlongbranch"); - - /* Tell the optimizer that this is the end of the preamble */ - AddCodeHint ("end_of_preamble"); -} - - - -void g_postamble (void) -/* Generate assembler code postamble */ -{ - /* Tell the optimizer that this is the start of the postamble */ - AddCodeHint ("start_of_postamble"); } @@ -3938,6 +3924,26 @@ void g_zerobytes (unsigned n) +/*****************************************************************************/ +/* User supplied assembler code */ +/*****************************************************************************/ + + + +void g_asmcode (const char* Line, int Len) +/* Output one line of assembler code. If Len is greater than zero, it is used + * as the maximum number of characters to use from Line. + */ +{ + if (Len >= 0) { + AddCodeSegLine (CS, "%.*s", Len, Line); + } else { + AddCodeSegLine (CS, "%s", Line); + } +} + + + /*****************************************************************************/ /* Inlined known functions */ /*****************************************************************************/ diff --git a/src/cc65/codegen.h b/src/cc65/codegen.h index 9eaf1b429..2b0274fe0 100644 --- a/src/cc65/codegen.h +++ b/src/cc65/codegen.h @@ -37,7 +37,7 @@ #define CODEGEN_H - + /* ##### */ #include "dataseg.h" #include "codeseg.h" @@ -101,9 +101,6 @@ extern CodeSeg* CS; void g_preamble (void); /* Generate the assembler code preamble */ -void g_postamble (void); -/* Generate assembler code postamble */ - /*****************************************************************************/ @@ -450,6 +447,19 @@ void g_zerobytes (unsigned n); +/*****************************************************************************/ +/* User supplied assembler code */ +/*****************************************************************************/ + + + +void g_asmcode (const char* Line, int Len); +/* Output one line of assembler code. If Len is greater than zero, it is used + * as the maximum number of characters to use from Line. + */ + + + /*****************************************************************************/ /* Inlined known functions */ /*****************************************************************************/ diff --git a/src/cc65/codeseg.c b/src/cc65/codeseg.c index c3993237c..959efbfe4 100644 --- a/src/cc65/codeseg.c +++ b/src/cc65/codeseg.c @@ -486,9 +486,6 @@ void DelCodeSegAfter (CodeSeg* S, unsigned Last) /* Get the number of entries in this segment */ unsigned Count = CollCount (&S->Entries); - /* Must not be called with count zero */ - CHECK (Count > 0 && Count >= Last); - /* Remove all entries after the given one */ while (Last < Count) { diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 321e5d243..f909fcbe9 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -744,11 +744,7 @@ void doasm (void) * looks like the one defined for C++ (C has no ASM directive), that is, * a string literal in parenthesis. */ -{ - /* ########## */ - Error ("Currently unavailable"); - -#if 0 +{ /* Skip the ASM */ NextToken (); @@ -759,8 +755,25 @@ void doasm (void) if (curtok != TOK_SCONST) { Error ("String literal expected"); } else { - /* Write the string directly into the output, followed by a newline */ - AddCodeLine (GetLiteral (curval)); + + /* 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 (curval); + 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 @@ -775,7 +788,6 @@ void doasm (void) /* Closing paren needed */ ConsumeRParen (); -#endif } diff --git a/src/cc65/litpool.h b/src/cc65/litpool.h index cd5cf9031..e9ad3c5cb 100644 --- a/src/cc65/litpool.h +++ b/src/cc65/litpool.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 1998-2001 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ -- 2.39.5