From fe2cd767b2f3206c3c97f20b1d238aa9e78344a0 Mon Sep 17 00:00:00 2001 From: cuz Date: Mon, 4 Jun 2001 12:27:16 +0000 Subject: [PATCH] Working on the backend git-svn-id: svn://svn.cc65.org/cc65/trunk@771 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/codegen.c | 4 ++-- src/cc65/codegen.h | 14 -------------- src/cc65/codeinfo.c | 4 ++-- src/cc65/codeseg.c | 4 ++-- src/cc65/codeseg.h | 2 +- src/cc65/opcodes.c | 37 ++++++++++++++++++++++--------------- src/cc65/opcodes.h | 1 + src/cc65/segments.c | 5 +++-- src/cc65/segments.h | 7 +++++-- 9 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index 004147b32..bdfe1b028 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -944,7 +944,7 @@ void g_putlocal (unsigned Flags, int Offs, long Val) { Offs -= oursp; CheckLocalOffs (Offs); - + if (Flags & CF_CONST) { g_getimmed (Flags, Val, Offs); } @@ -960,7 +960,7 @@ void g_putlocal (unsigned Flags, int Offs, long Val) break; case CF_LONG: - AddCode (OPC_STAEAX, AM_STACK, WordToStr (Offs), 0); + AddCode (OPC_STEAX, AM_STACK, WordToStr (Offs), 0); break; default: diff --git a/src/cc65/codegen.h b/src/cc65/codegen.h index 6bd016a23..9d1420fca 100644 --- a/src/cc65/codegen.h +++ b/src/cc65/codegen.h @@ -294,20 +294,6 @@ void g_addstatic (unsigned flags, unsigned long label, unsigned offs); -/*****************************************************************************/ -/* Compares of ax with a variable with fixed address */ -/*****************************************************************************/ - - - -void g_cmplocal (unsigned flags, int offs); -/* Compare a local variable to ax */ - -void g_cmpstatic (unsigned flags, unsigned label, unsigned offs); -/* Compare a static variable to ax */ - - - /*****************************************************************************/ /* Special op= functions */ /*****************************************************************************/ diff --git a/src/cc65/codeinfo.c b/src/cc65/codeinfo.c index 9c5a1b408..1885306de 100644 --- a/src/cc65/codeinfo.c +++ b/src/cc65/codeinfo.c @@ -296,7 +296,7 @@ static unsigned char GetRegInfo2 (CodeSeg* S, } /* If the instruction is an RTS or RTI, we're done */ - if (E->OPC == OP65_RTS || E->OPC == OP65_RTI) { + if ((E->Info & OF_RET) != 0) { break; } @@ -336,7 +336,7 @@ static unsigned char GetRegInfo2 (CodeSeg* S, } if (Index < 0) { Index = CS_GetEntryIndex (S, E); - } + } if ((E = CS_GetEntry (S, ++Index)) == 0) { Internal ("GetRegInfo2: No next entry!"); } diff --git a/src/cc65/codeseg.c b/src/cc65/codeseg.c index 44601c591..17457768f 100644 --- a/src/cc65/codeseg.c +++ b/src/cc65/codeseg.c @@ -402,7 +402,7 @@ CodeSeg* NewCodeSeg (const char* SegName, SymEntry* Func) -void CS_AddEntry (CodeSeg* S, struct CodeEntry* E, LineInfo* LI) +void CS_AddEntry (CodeSeg* S, struct CodeEntry* E) /* Add an entry to the given code segment */ { /* Transfer the labels if we have any */ @@ -465,7 +465,7 @@ void CS_AddLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap) /* If we have a code entry, transfer the labels and insert it */ if (E) { - CS_AddEntry (S, E, LI); + CS_AddEntry (S, E); } } diff --git a/src/cc65/codeseg.h b/src/cc65/codeseg.h index b98bf3e06..a157a79d4 100644 --- a/src/cc65/codeseg.h +++ b/src/cc65/codeseg.h @@ -94,7 +94,7 @@ struct CodeSeg { CodeSeg* NewCodeSeg (const char* SegName, SymEntry* Func); /* Create a new code segment, initialize and return it */ -void CS_AddEntry (CodeSeg* S, struct CodeEntry* E, LineInfo* LI); +void CS_AddEntry (CodeSeg* S, struct CodeEntry* E); /* Add an entry to the given code segment */ void CS_AddLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap) attribute ((format(printf,3,0))); diff --git a/src/cc65/opcodes.c b/src/cc65/opcodes.c index 8afeb9648..2c88ff394 100644 --- a/src/cc65/opcodes.c +++ b/src/cc65/opcodes.c @@ -60,105 +60,112 @@ const OPCDesc OPCTable[OPCODE_COUNT] = { /* Opcodes for the virtual stack machine */ { OPC_CALL, /* opcode */ "call", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_NONE, /* use */ REG_NONE, /* chg */ OF_CPU_VM | OF_CALL /* flags */ }, { OPC_ENTER, /* opcode */ "enter", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_Y, /* use */ REG_AXY, /* chg */ OF_CPU_VM /* flags */ }, { OPC_JMP, /* opcode */ "jump", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_NONE, /* use */ REG_NONE, /* chg */ OF_CPU_VM | OF_UBRA /* flags */ }, { OPC_LDA, /* opcode */ "lda", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_NONE, /* use */ REG_A, /* chg */ OF_CPU_VM | OF_LOAD /* flags */ }, { OPC_LDAX, /* opcode */ "ldax", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_NONE, /* use */ REG_AX, /* chg */ OF_CPU_VM | OF_LOAD /* flags */ }, { OPC_LDEAX, /* opcode */ "ldeax", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_NONE, /* use */ REG_EAX, /* chg */ OF_CPU_VM | OF_LOAD /* flags */ }, { OPC_LEA, /* opcode */ "lea", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_NONE, /* use */ REG_AX, /* chg */ OF_CPU_VM /* flags */ }, { OPC_LEAVE, /* opcode */ "leave", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_NONE, /* use */ REG_NONE, /* chg */ OF_CPU_VM /* flags */ }, { OPC_PHA, /* opcode */ "pha", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_A, /* use */ REG_NONE, /* chg */ OF_CPU_VM /* flags */ }, { OPC_PHAX, /* opcode */ "phax", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_AX, /* use */ REG_NONE, /* chg */ OF_CPU_VM /* flags */ }, { OPC_PHEAX, /* opcode */ "pheax", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_EAX, /* use */ REG_NONE, /* chg */ OF_CPU_VM /* flags */ }, + { OPC_RET, /* opcode */ + "ret", /* mnemonic */ + 1, /* size */ + REG_NONE, /* use */ + REG_NONE, /* chg */ + OF_CPU_VM | OF_RET /* flags */ + }, { OPC_SPACE, /* opcode */ "space", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_NONE, /* use */ REG_NONE, /* chg */ OF_CPU_VM /* flags */ }, { OPC_STA, /* opcode */ "sta", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_A, /* use */ REG_NONE, /* chg */ OF_CPU_VM /* flags */ }, { OPC_STAX, /* opcode */ "stax", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_AX, /* use */ REG_NONE, /* chg */ OF_CPU_VM /* flags */ }, { OPC_STEAX, /* opcode */ "steax", /* mnemonic */ - 0, /* size */ + 1, /* size */ REG_EAX, /* use */ REG_NONE, /* chg */ OF_CPU_VM /* flags */ diff --git a/src/cc65/opcodes.h b/src/cc65/opcodes.h index e5bbbb7ee..c81c978f5 100644 --- a/src/cc65/opcodes.h +++ b/src/cc65/opcodes.h @@ -64,6 +64,7 @@ typedef enum { OPC_PHA, OPC_PHAX, OPC_PHEAX, + OPC_RET, OPC_SPACE, OPC_STA, OPC_STAX, diff --git a/src/cc65/segments.c b/src/cc65/segments.c index b5ba646c4..232f9abd8 100644 --- a/src/cc65/segments.c +++ b/src/cc65/segments.c @@ -44,6 +44,7 @@ #include "xmalloc.h" /* cc65 */ +#include "codeent.h" #include "codeseg.h" #include "dataseg.h" #include "textseg.h" @@ -219,11 +220,11 @@ void AddCodeLine (const char* Format, ...) -void AddCode (struct CodeEntry* E) +void AddCode (opc_t OPC, am_t AM, const char* Arg, struct CodeLabel* JumpTo) /* Add a code entry to the current code segment */ { CHECK (CS != 0); - CS_AddEntry (CS->Code, E, CurTok.LI); + CS_AddEntry (CS->Code, NewCodeEntry (OPC, AM, Arg, JumpTo, CurTok.LI)); } diff --git a/src/cc65/segments.h b/src/cc65/segments.h index cd3a67309..1c9b5fd9a 100644 --- a/src/cc65/segments.h +++ b/src/cc65/segments.h @@ -43,6 +43,8 @@ /* common */ #include "attrib.h" +/* cc65 */ +#include "opcodes.h" /*****************************************************************************/ @@ -50,8 +52,9 @@ /*****************************************************************************/ - + struct CodeEntry; +struct CodeLabel; struct CodeSeg; struct DataSeg; struct TextSeg; @@ -123,7 +126,7 @@ void AddTextLine (const char* Format, ...) attribute ((format (printf, 1, 2))); void AddCodeLine (const char* Format, ...) attribute ((format (printf, 1, 2))); /* Add a line of code to the current code segment */ -void AddCode (struct CodeEntry* E); +void AddCode (opc_t OPC, am_t AM, const char* Arg, struct CodeLabel* JumpTo); /* Add a code entry to the current code segment */ void AddDataLine (const char* Format, ...) attribute ((format (printf, 1, 2))); -- 2.39.2