/* */
/* */
/* */
-/* (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 */
+CodeMark GetCodePos (void)
+/* Get a marker pointing to the current output position */
{
- AddCodeLine ("+%s", Hint);
-}
-
-
-
-void AddEmptyLine (void)
-/* Add an empty line for formatting purposes */
-{
- /* Use a somewhat weird construct to avoid that gcc complains about
- * an empty format string.
- */
- static const char EmptyLine[] = "";
- AddCodeLine (EmptyLine);
+ 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);
}
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;
}
}