Fix unnamed parameters in function prototype

This commit is contained in:
drmortalwombat 2021-09-11 16:05:31 +02:00
parent 93b6aca8a3
commit 897de02adf
6 changed files with 183 additions and 30 deletions

View File

@ -16,7 +16,7 @@ __asm startup
sta sp sta sp
lda StackTop + 1 lda StackTop + 1
sta sp + 1 sta sp + 1
pexec:
ldy #0 ldy #0
exec: exec:
lda (ip), y lda (ip), y
@ -38,6 +38,36 @@ incip:
#pragma startup(startup) #pragma startup(startup)
__asm bcexec
{
lda ip
pha
lda ip + 1
pha
lda accu
sta ip
lda accu + 1
sta ip + 1
ldy #0
lda #<done
sta (sp), y
iny
lda #>done
sta (sp), y
jmp startup.pexec
done: nop
pla
pla
pla
sta ip + 1
pla
sta ip
rts
}
#pragma runtime(bcexec, bcexec)
__asm negaccu __asm negaccu
{ {
sec sec
@ -1772,8 +1802,7 @@ __asm inp_call
sta ip sta ip
lda addr + 1 lda addr + 1
sta ip + 1 sta ip + 1
ldy #0 jmp startup.pexec
jmp startup.exec
} }
#pragma bytecode(BC_CALL, inp_call) #pragma bytecode(BC_CALL, inp_call)

View File

@ -29,7 +29,9 @@ enum AsmInsMode
ASMIM_INDIRECT_Y, ASMIM_INDIRECT_Y,
ASMIM_RELATIVE, ASMIM_RELATIVE,
NUM_ASM_INS_MODES NUM_ASM_INS_MODES,
ASMIM_IMMEDIATE_ADDRESS
}; };
struct AsmInsData struct AsmInsData

View File

@ -53,6 +53,9 @@ static const uint32 DTF_CONST = 0x00000040;
static const uint32 DTF_VOLATILE = 0x00000080; static const uint32 DTF_VOLATILE = 0x00000080;
static const uint32 DTF_EXTERN = 0x00000100; static const uint32 DTF_EXTERN = 0x00000100;
static const uint32 DTF_NATIVE = 0x00000200; static const uint32 DTF_NATIVE = 0x00000200;
static const uint32 DTF_UPPER_BYTE = 0x00000400;
static const uint32 DTF_LOWER_BYTE = 0x00000800;
class Declaration; class Declaration;

View File

@ -185,6 +185,26 @@ void InterCodeGenerator::TranslateAssembler(InterCodeModule* mod, Expression * e
case ASMIM_IMPLIED: case ASMIM_IMPLIED:
break; break;
case ASMIM_IMMEDIATE: case ASMIM_IMMEDIATE:
if (aexp->mType == DT_CONST_INTEGER)
d[offset++] = cexp->mLeft->mDecValue->mInteger & 255;
else if (aexp->mType == DT_LABEL_REF)
{
if (aexp->mBase->mBase->mVarIndex < 0)
TranslateAssembler(mod, aexp->mBase->mBase->mValue);
InterVariable::Reference ref;
ref.mFunction = false;
ref.mUpper = aexp->mFlags & DTF_UPPER_BYTE;
ref.mLower = !(aexp->mFlags & DTF_UPPER_BYTE);
ref.mAddr = offset;
ref.mIndex = aexp->mBase->mBase->mVarIndex;
ref.mOffset = aexp->mOffset + aexp->mBase->mInteger;
references.Push(ref);
offset += 1;
}
break;
case ASMIM_ZERO_PAGE: case ASMIM_ZERO_PAGE:
case ASMIM_ZERO_PAGE_X: case ASMIM_ZERO_PAGE_X:
case ASMIM_INDIRECT_X: case ASMIM_INDIRECT_X:

View File

@ -960,6 +960,9 @@ void NativeCodeInstruction::Assemble(NativeCodeBasicBlock* block)
block->PutByte(mAddress); block->PutByte(mAddress);
else else
{ {
if (mMode == ASMIM_IMMEDIATE_ADDRESS)
block->PutByte(AsmInsOpcodes[mType][ASMIM_IMMEDIATE]);
else
block->PutByte(AsmInsOpcodes[mType][mMode]); block->PutByte(AsmInsOpcodes[mType][mMode]);
switch (mMode) switch (mMode)
@ -974,11 +977,12 @@ void NativeCodeInstruction::Assemble(NativeCodeBasicBlock* block)
block->PutByte(uint8(mAddress)); block->PutByte(uint8(mAddress));
break; break;
case ASMIM_IMMEDIATE: case ASMIM_IMMEDIATE:
case ASMIM_IMMEDIATE_ADDRESS:
if (mVarIndex != -1) if (mVarIndex != -1)
{ {
ByteCodeRelocation rl; ByteCodeRelocation rl;
rl.mAddr = block->mCode.Size(); rl.mAddr = block->mCode.Size();
rl.mFunction = false; rl.mFunction = mFunction;
rl.mLower = mLower; rl.mLower = mLower;
rl.mUpper = mUpper; rl.mUpper = mUpper;
rl.mIndex = mVarIndex; rl.mIndex = mVarIndex;
@ -1144,9 +1148,9 @@ void NativeCodeBasicBlock::LoadConstantToReg(InterCodeProcedure * proc, const In
{ {
if (ins.mMemory == IM_GLOBAL) if (ins.mMemory == IM_GLOBAL)
{ {
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, ins.mIntValue, ins.mVarIndex, true, false)); mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE_ADDRESS, ins.mIntValue, ins.mVarIndex, true, false));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, reg)); mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, reg));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, ins.mIntValue, ins.mVarIndex, false, true)); mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE_ADDRESS, ins.mIntValue, ins.mVarIndex, false, true));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, reg + 1)); mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, reg + 1));
} }
else if (ins.mMemory == IM_ABSOLUTE) else if (ins.mMemory == IM_ABSOLUTE)
@ -3191,44 +3195,49 @@ void NativeCodeBasicBlock::LoadEffectiveAddress(InterCodeProcedure* proc, const
void NativeCodeBasicBlock::CallFunction(InterCodeProcedure* proc, const InterInstruction& ins) void NativeCodeBasicBlock::CallFunction(InterCodeProcedure* proc, const InterInstruction& ins)
{ {
#if 0
if (ins.mSTemp[0] < 0) if (ins.mSTemp[0] < 0)
{ {
ByteCodeInstruction bins(BC_LEA_ABS); NativeCodeInstruction lins(ASMIT_LDA, ASMIM_IMMEDIATE_ADDRESS, ins.mSIntConst[0], ins.mVarIndex, true, false);
bins.mRelocate = true; lins.mFunction = ins.mMemory == IM_PROCEDURE;
bins.mFunction = true; NativeCodeInstruction hins(ASMIT_LDA, ASMIM_IMMEDIATE_ADDRESS, ins.mSIntConst[0], ins.mVarIndex, false, true);
bins.mVIndex = ins.mVarIndex; hins.mFunction = ins.mMemory == IM_PROCEDURE;
bins.mValue = 0;
bins.mRegister = BC_REG_ADDR; mIns.Push(lins);
mIns.Push(bins); mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_ACCU));
mIns.Push(hins);
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 1));
} }
else else
{ {
ByteCodeInstruction bins(BC_ADDR_REG); mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mSTemp[0]] + 0));
bins.mRegister = BC_REG_TMP + proc->mTempOffset[ins.mSTemp[0]]; mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_ACCU));
bins.mRegisterFinal = ins.mSFinal[0]; mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mSTemp[0]] + 1));
mIns.Push(bins); mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 1));
} }
ByteCodeInstruction cins(BC_CALL); mIns.Push(NativeCodeInstruction("bcexec"));
mIns.Push(cins);
if (ins.mTTemp >= 0) if (ins.mTTemp >= 0)
{ {
if (ins.mTType == IT_FLOAT) if (ins.mTType == IT_FLOAT)
{ {
ByteCodeInstruction bins(BC_STORE_REG_32); mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 0));
bins.mRegister = BC_REG_TMP + proc->mTempOffset[ins.mTTemp]; mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mTTemp] + 0));
mIns.Push(bins); mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 1));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mTTemp] + 1));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 2));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mTTemp] + 2));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 3));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mTTemp] + 3));
} }
else else
{ {
ByteCodeInstruction bins(BC_STORE_REG_16); mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 0));
bins.mRegister = BC_REG_TMP + proc->mTempOffset[ins.mTTemp]; mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mTTemp] + 0));
mIns.Push(bins); mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 1));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mTTemp] + 1));
} }
} }
#endif
} }
void NativeCodeBasicBlock::CallAssembler(InterCodeProcedure* proc, const InterInstruction& ins) void NativeCodeBasicBlock::CallAssembler(InterCodeProcedure* proc, const InterInstruction& ins)

View File

@ -677,6 +677,21 @@ Declaration* Parser::ParseDeclaration(bool variable)
{ {
if (!ndec->mBase->IsSame(pdec->mBase)) if (!ndec->mBase->IsSame(pdec->mBase))
mErrors->Error(ndec->mLocation, "Function declaration differs"); mErrors->Error(ndec->mLocation, "Function declaration differs");
else
{
//
// Take parameter names from new declaration
//
Declaration* npdec = ndec->mBase->mParams, *ppdec = pdec->mBase->mParams;
while (npdec && ppdec)
{
if (npdec->mIdent)
ppdec->mIdent = npdec->mIdent;
npdec = npdec->mNext;
ppdec = ppdec->mNext;
}
}
ndec = pdec; ndec = pdec;
} }
else else
@ -1818,6 +1833,81 @@ Expression* Parser::ParseAssemblerAddOperand(void)
Expression* Parser::ParseAssemblerOperand(void) Expression* Parser::ParseAssemblerOperand(void)
{ {
if (mScanner->mToken == TK_LESS_THAN)
{
mScanner->NextToken();
Expression* exp = ParseAssemblerOperand();
if (exp->mType == EX_CONSTANT)
{
if (exp->mDecValue->mType == DT_CONST_INTEGER)
{
Declaration* dec = new Declaration(mScanner->mLocation, DT_CONST_INTEGER);
dec->mInteger = exp->mDecValue->mInteger & 0xff;
dec->mBase = TheUnsignedIntTypeDeclaration;
exp->mDecValue = dec;
}
else if (exp->mDecValue->mType == DT_LABEL)
{
Declaration* ndec = new Declaration(mScanner->mLocation, DT_LABEL_REF);
ndec->mBase = exp->mDecValue;
ndec->mOffset = 0;
ndec->mFlags |= DTF_LOWER_BYTE;
exp->mDecValue = ndec;
}
else if (exp->mDecValue->mType == DT_LABEL_REF)
{
Declaration* ndec = new Declaration(mScanner->mLocation, DT_LABEL_REF);
ndec->mBase = exp->mDecValue->mBase;
ndec->mOffset = exp->mDecValue->mOffset;
ndec->mFlags |= DTF_LOWER_BYTE;
exp->mDecValue = ndec;
}
else
mErrors->Error(mScanner->mLocation, "Label or integer value for lower byte operator expected");
}
else
mErrors->Error(mScanner->mLocation, "Constant for lower byte operator expected");
return exp;
}
else if (mScanner->mToken == TK_GREATER_THAN)
{
mScanner->NextToken();
Expression* exp = ParseAssemblerOperand();
if (exp->mType == EX_CONSTANT)
{
if (exp->mDecValue->mType == DT_CONST_INTEGER)
{
Declaration* dec = new Declaration(mScanner->mLocation, DT_CONST_INTEGER);
dec->mInteger = (exp->mDecValue->mInteger >> 8) & 0xff;
dec->mBase = TheUnsignedIntTypeDeclaration;
exp->mDecValue = dec;
}
else if (exp->mDecValue->mType == DT_LABEL)
{
Declaration* ndec = new Declaration(mScanner->mLocation, DT_LABEL_REF);
ndec->mBase = exp->mDecValue;
ndec->mOffset = 0;
ndec->mFlags |= DTF_UPPER_BYTE;
exp->mDecValue = ndec;
}
else if (exp->mDecValue->mType == DT_LABEL_REF)
{
Declaration* ndec = new Declaration(mScanner->mLocation, DT_LABEL_REF);
ndec->mBase = exp->mDecValue->mBase;
ndec->mOffset = exp->mDecValue->mOffset;
ndec->mFlags |= DTF_UPPER_BYTE;
exp->mDecValue = ndec;
}
else
mErrors->Error(mScanner->mLocation, "Label or integer value for lower byte operator expected");
}
else
mErrors->Error(mScanner->mLocation, "Constant for upper byte operator expected");
}
else
return ParseAssemblerAddOperand(); return ParseAssemblerAddOperand();
} }