]> git.sur5r.net Git - cc65/blobdiff - src/cc65/asmcode.c
Renamed ExprDesc.Val to ExprDesc.IVal. Added an FVal field for a floating
[cc65] / src / cc65 / asmcode.c
index b62d36dcdc6d207e825af8df07c11dd9288254c6..776e36f674e2b4efcf12693030eeac5bc5488f98 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 2000-2001 Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 
 
 
-#include "asmline.h"
+/* common */
 #include "check.h"
-#include "global.h"
+
+/* cc65 */
+#include "codeopt.h"
+#include "codeseg.h"
+#include "dataseg.h"
+#include "segments.h"
+#include "symtab.h"
 #include "asmcode.h"
 
 
 
 /*****************************************************************************/
-/*                                  Code                                    */
+/*                                  Code                                    */
 /*****************************************************************************/
 
 
 
-void AddCodeLine (const char* Format, ...)
-/* Add a new line of code to the output */
-{
-    va_list ap;
-    va_start (ap, Format);
-    NewCodeLine (Format, ap);
-    va_end (ap);
-}
-
-
-
-void AddCodeHint (const char* Hint)
-/* Add an optimizer hint */
-{
-    AddCodeLine ("+%s", Hint);
-}
-
-
-
-void AddEmptyLine (void)
-/* Add an empty line for formatting purposes */
+CodeMark GetCodePos (void)
+/* Get a marker pointing to the current output position */
 {
-    AddCodeLine ("");
+    return CS_GetEntryCount (CS->Code);
 }
 
 
 
-CodeMark GetCodePos (void)
-/* Get a marker pointing to the current output position */
+void RemoveCode (CodeMark M)
+/* Remove all code after the given code marker */
 {
-    /* This function should never be called without any code output */
-    CHECK (LastLine != 0);
-
-    return LastLine;
+    CS_DelCodeAfter (CS->Code, M);
 }
 
 
 
-void RemoveCode (CodeMark M)
-/* Remove all code after the given code marker */
+void MoveCode (CodeMark Start, CodeMark End, CodeMark Target)
+/* Move the code between Start (inclusive) and End (exclusive) to
+ * (before) Target.
+ */
 {
-    while (LastLine != M) {
-       FreeCodeLine (LastLine);
-    }
+    CS_MoveEntries (CS->Code, Start, End - Start, Target);
 }
 
 
@@ -97,17 +81,26 @@ void RemoveCode (CodeMark M)
 void WriteOutput (FILE* F)
 /* Write the final output to a file */
 {
-    Line* L = FirstLine;
-    while (L) {
-       /* Don't write optimizer hints if not requested to do so */
-       if (L->Line[0] == '+') {
-           if (Debug) {
-               fprintf (F, ";%s\n", L->Line);
-           }
-       } else {
-           fprintf (F, "%s\n", L->Line);
-       }
-       L = L->Next;
+    SymTable* SymTab;
+    SymEntry* Entry;
+
+    /* Output the global data segment */
+    CHECK (!HaveGlobalCode ());
+    OutputSegments (CS, F);
+
+    /* Output all global or referenced functions */
+    SymTab = GetGlobalSymTab ();
+    Entry  = SymTab->SymHead;
+    while (Entry) {
+               if (IsTypeFunc (Entry->Type)            &&
+                   SymIsDef (Entry)                    &&
+                   (Entry->Flags & (SC_REF | SC_EXTERN)) != 0) {
+                   /* Function which is defined and referenced or extern */
+                   CS_MergeLabels (Entry->V.F.Seg->Code);
+                   RunOpt (Entry->V.F.Seg->Code);
+                   OutputSegments (Entry->V.F.Seg, F);
+               }
+               Entry = Entry->NextSym;
     }
 }