Fix error in recursive macro expansion

This commit is contained in:
drmortalwombat 2022-12-13 08:18:25 +01:00
parent 0055911491
commit de3c7415b3
3 changed files with 25 additions and 11 deletions

View File

@ -14815,6 +14815,9 @@ NativeCodeBasicBlock * NativeCodeBasicBlock::SplitMatchingTails(NativeCodeProced
nblock->mEntryBlocks.Push(bi);
nblock->mNumEntries++;
nblock->mEntryRequiredRegs = mEntryRequiredRegs;
nblock->mExitRequiredRegs = mEntryRequiredRegs;
bi->mTrueJump = nblock;
mEntryBlocks[i] = nullptr;
mNumEntries--;
@ -14863,6 +14866,9 @@ NativeCodeBasicBlock* NativeCodeBasicBlock::AddDominatorBlock(NativeCodeProcedur
mEntryBlocks[mEntryBlocks.IndexOf(pblock)] = tblock;
tblock->mEntryRequiredRegs = mEntryRequiredRegs;
tblock->mExitRequiredRegs = mEntryRequiredRegs;
if (pblock->mTrueJump == this)
pblock->mTrueJump = tblock;
if (pblock->mFalseJump == this)
@ -26936,8 +26942,10 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
mIns[i + 1].mType == ASMIT_DEC && mIns[i + 1].mMode == ASMIM_ZERO_PAGE && mIns[i + 1].mAddress == mIns[i + 0].mAddress &&
!(mIns[i + 2].mLive & LIVE_CPU_REG_C))
{
mIns[i + 0].mType = ASMIT_SEC; mIns[i + 0].mMode = ASMIM_IMPLIED; mIns[i + 0].mLive |= LIVE_CPU_REG_C;
mIns[i + 1].mType = ASMIT_SBC; mIns[i + 1].mMode = ASMIM_IMMEDIATE; mIns[i + 1].mAddress = 1;
mIns[i + 0].mType = ASMIT_SEC; mIns[i + 0].mMode = ASMIM_IMPLIED; mIns[i + 0].mLive |= LIVE_CPU_REG_C | LIVE_CPU_REG_A;
mIns[i + 1].mType = ASMIT_SBC; mIns[i + 1].mMode = ASMIM_IMMEDIATE; mIns[i + 1].mAddress = 1; mIns[i + 1].mLive |= LIVE_CPU_REG_A;
if (mIns[i + 2].mLive & LIVE_CPU_REG_Z)
mIns[i + 1].mLive |= LIVE_CPU_REG_Z;
mIns[i + 2].mType = ASMIT_STA;
progress = true;
}

View File

@ -149,8 +149,8 @@ const char* TokenNames[] =
};
Macro::Macro(const Ident* ident)
: mIdent(ident), mString(nullptr), mNumArguments(-1)
Macro::Macro(const Ident* ident, MacroDict * scope)
: mIdent(ident), mString(nullptr), mNumArguments(-1), mScope(scope)
{
}
@ -389,7 +389,7 @@ static inline int HexValue(char ch)
void Scanner::AddMacro(const Ident* ident, const char* value)
{
Macro* macro = new Macro(ident);
Macro* macro = new Macro(ident, nullptr);
macro->SetString(value);
mDefines->Insert(macro);
}
@ -501,7 +501,7 @@ void Scanner::NextToken(void)
{
if (mToken != TK_IDENT)
mTokenIdent = Ident::Unique(TokenNames[mToken]);
Macro* macro = new Macro(mTokenIdent);
Macro* macro = new Macro(mTokenIdent, nullptr);
if (mTokenChar == '(')
{
@ -614,7 +614,7 @@ void Scanner::NextToken(void)
Macro* macro = mDefines->Lookup(ident);
if (!macro)
{
macro = new Macro(ident);
macro = new Macro(ident, nullptr);
mDefines->Insert(macro);
}
char buffer[20];
@ -739,6 +739,8 @@ void Scanner::NextToken(void)
}
else if (def->mNumArguments > 0)
{
MacroDict* scope = mDefineArguments;
mDefineArguments = new MacroDict();
NextRawToken();
if (mToken == TK_OPEN_PARENTHESIS)
@ -765,7 +767,7 @@ void Scanner::NextToken(void)
}
offset++;
}
Macro* arg = new Macro(def->mArguments[i]);
Macro* arg = new Macro(def->mArguments[i], scope);
arg->SetString(mLine + mOffset, offset - mOffset);
mDefineArguments->Insert(arg);
mOffset = offset;
@ -790,7 +792,7 @@ void Scanner::NextToken(void)
NextChar();
}
else
mDefineArguments = nullptr;
mDefineArguments = def->mScope;
ex->mLine = mLine;
ex->mOffset = mOffset;
@ -1628,7 +1630,7 @@ bool Scanner::NextChar(void)
if (mMacroExpansion)
{
MacroExpansion* mac = mMacroExpansion->mLink;
delete mDefineArguments;
// delete mDefineArguments;
mLine = mMacroExpansion->mLine;
mOffset = mMacroExpansion->mOffset;

View File

@ -150,10 +150,12 @@ enum Token
extern const char* TokenNames[];
class MacroDict;
class Macro
{
public:
Macro(const Ident* ident);
Macro(const Ident* ident, MacroDict* scope);
~Macro(void);
void SetString(const char* str);
@ -164,6 +166,7 @@ public:
const char* mString;
int mNumArguments;
const Ident * mArguments[32];
MacroDict* mScope;
};
typedef Macro* MacroPtr;
@ -181,6 +184,7 @@ public:
protected:
MacroPtr * mHash;
int mHashSize, mHashFill;
MacroDict * mParent;
};
class Scanner