Skip to content

Commit

Permalink
Fix struct over header boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
drmortalwombat committed Sep 19, 2021
1 parent 3ce8796 commit 10bb751
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 36 deletions.
19 changes: 19 additions & 0 deletions include/crt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,25 @@ __asm inp_store_frame_32

#pragma bytecode(BC_STORE_FRAME_32, inp_store_frame_32)

__asm inp_lea_frame
{
lda (ip), y
tax
iny
clc
lda (ip), y
adc sp
sta $00, x
iny
lda (ip), y
adc sp + 1
sta $01, x
iny
jmp startup.exec
}

#pragma bytecode(BC_LEA_FRAME, inp_lea_frame)

__asm inp_op_negate_16
{
sec
Expand Down
2 changes: 2 additions & 0 deletions include/crt.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ enum ByteCode
BC_STORE_FRAME_16,
BC_STORE_FRAME_32,

BC_LEA_FRAME,

BC_LOAD_ADDR_8,
BC_LOAD_ADDR_U8,
BC_LOAD_ADDR_I8,
Expand Down
17 changes: 15 additions & 2 deletions oscar64/ByteCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bool ByteCodeInstruction::LoadsRegister(uint32 reg) const
return true;
if (mCode >= BC_CONST_8 && mCode <= BC_CONST_32)
return true;
if (mCode == BC_LEA_ABS || mCode == BC_LEA_LOCAL)
if (mCode == BC_LEA_ABS || mCode == BC_LEA_LOCAL || mCode == BC_LEA_FRAME)
return true;
}

Expand Down Expand Up @@ -136,7 +136,7 @@ bool ByteCodeInstruction::ChangesRegister(uint32 reg) const
return true;
if (mCode >= BC_CONST_8 && mCode <= BC_CONST_32)
return true;
if (mCode == BC_LEA_ABS || mCode == BC_LEA_LOCAL)
if (mCode == BC_LEA_ABS || mCode == BC_LEA_LOCAL || mCode == BC_LEA_FRAME)
return true;
if (mCode >= BC_BINOP_ADDI_16 && mCode <= BC_BINOP_MULI8_16)
return true;
Expand Down Expand Up @@ -302,6 +302,7 @@ void ByteCodeInstruction::Assemble(ByteCodeGenerator* generator, ByteCodeBasicBl
break;

case BC_LEA_LOCAL:
case BC_LEA_FRAME:
block->PutCode(generator, mCode);
block->PutByte(mRegister);
block->PutWord(uint16(mValue));
Expand Down Expand Up @@ -621,6 +622,13 @@ void ByteCodeBasicBlock::LoadConstant(InterCodeProcedure* proc, const InterInstr
bins.mValue = ins->mIntValue + ins->mVarIndex + proc->mLocalSize + 2;
mIns.Push(bins);
}
else if (ins->mMemory == IM_FRAME)
{
ByteCodeInstruction bins(BC_LEA_FRAME);
bins.mRegister = BC_REG_TMP + proc->mTempOffset[ins->mTTemp];
bins.mValue = ins->mVarIndex + ins->mSIntConst[1] + 2;
mIns.Push(bins);
}
else if (ins->mMemory == IM_PROCEDURE)
{
ByteCodeInstruction bins(BC_CONST_16);
Expand Down Expand Up @@ -3240,6 +3248,11 @@ void ByteCodeProcedure::Disassemble(FILE * file, ByteCodeGenerator * generator,
i += 3;
break;

case BC_LEA_FRAME:
fprintf(file, "LEA\t%s, %d(SP)", TempName(generator->mMemory[mProgStart + i + 0], tbuffer, proc), uint16(generator->mMemory[mProgStart + i + 1] + 256 * generator->mMemory[mProgStart + i + 2]));
i += 3;
break;

case BC_STORE_FRAME_8:
fprintf(file, "MOVB\t%d(SP), %s", generator->mMemory[mProgStart + i + 1], TempName(generator->mMemory[mProgStart + i + 0], tbuffer, proc));
i += 2;
Expand Down
2 changes: 2 additions & 0 deletions oscar64/ByteCodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ enum ByteCode
BC_STORE_FRAME_16,
BC_STORE_FRAME_32,

BC_LEA_FRAME,

BC_LOAD_ADDR_8,
BC_LOAD_ADDR_U8,
BC_LOAD_ADDR_I8,
Expand Down
11 changes: 10 additions & 1 deletion oscar64/Declaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,12 @@ bool Declaration::IsSame(const Declaration* dec) const
else if (mType == DT_TYPE_BOOL || mType == DT_TYPE_FLOAT || mType == DT_TYPE_VOID)
return true;
else if (mType == DT_TYPE_STRUCT || mType == DT_TYPE_ENUM)
return false;
{
if (mIdent == dec->mIdent)
return true;
else
return false;
}
else if (mType == DT_TYPE_POINTER || mType == DT_TYPE_ARRAY)
return mBase->IsSame(dec->mBase);
else if (mType == DT_TYPE_FUNCTION)
Expand Down Expand Up @@ -459,6 +464,10 @@ bool Declaration::CanAssign(const Declaration* fromType) const
{
return true;
}
else if (mBase->mType == DT_TYPE_VOID && fromType->mType == DT_TYPE_FUNCTION)
{
return true;
}
}

return false;
Expand Down
79 changes: 55 additions & 24 deletions oscar64/InterCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,37 +1435,66 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*

vr = TranslateExpression(procType, proc, block, texp, breakBlock, continueBlock);

if (vr.mType->mType != DT_TYPE_ARRAY)
vr = Dereference(proc, block, vr);

if (pdec)
if (vr.mType->mType == DT_TYPE_STRUCT || vr.mType->mType == DT_TYPE_UNION)
{
if (!pdec->mBase->CanAssign(vr.mType))
if (pdec && !pdec->mBase->CanAssign(vr.mType))
mErrors->Error(texp->mLocation, "Cannot assign incompatible types");
vr = CoerceType(proc, block, vr, pdec->mBase);

vr = Dereference(proc, block, vr, 1);

if (vr.mReference != 1)
mErrors->Error(exp->mLeft->mLocation, "Not an adressable expression");

InterInstruction* cins = new InterInstruction();
cins->mCode = IC_COPY;
cins->mMemory = IM_INDIRECT;
cins->mSType[0] = IT_POINTER;
cins->mSTemp[0] = vr.mTemp;
cins->mSType[1] = IT_POINTER;
cins->mSTemp[1] = ains->mTTemp;
cins->mOperandSize = vr.mType->mSize;
block->Append(cins);

atotal += cins->mOperandSize;
}
else if (vr.mType->IsIntegerType() && vr.mType->mSize < 2)
else
{
vr = CoerceType(proc, block, vr, TheSignedIntTypeDeclaration);
}
if (vr.mType->mType == DT_TYPE_ARRAY || vr.mType->mType == DT_TYPE_FUNCTION)
vr = Dereference(proc, block, vr, 1);
else
vr = Dereference(proc, block, vr);

InterInstruction * wins = new InterInstruction();
wins->mCode = IC_STORE;
wins->mMemory = IM_INDIRECT;
wins->mSType[0] = InterTypeOf(vr.mType);;
wins->mSTemp[0] = vr.mTemp;
wins->mSType[1] = IT_POINTER;
wins->mSTemp[1] = ains->mTTemp;
if (pdec)
wins->mOperandSize = pdec->mSize;
else if (vr.mType->mSize > 2 && vr.mType->mType != DT_TYPE_ARRAY)
wins->mOperandSize = vr.mType->mSize;
else
wins->mOperandSize = 2;
if (pdec)
{
if (!pdec->mBase->CanAssign(vr.mType))
mErrors->Error(texp->mLocation, "Cannot assign incompatible types");
vr = CoerceType(proc, block, vr, pdec->mBase);
}
else if (vr.mType->IsIntegerType() && vr.mType->mSize < 2)
{
vr = CoerceType(proc, block, vr, TheSignedIntTypeDeclaration);
}

block->Append(wins);

atotal += wins->mOperandSize;
InterInstruction* wins = new InterInstruction();
wins->mCode = IC_STORE;
wins->mMemory = IM_INDIRECT;
wins->mSType[0] = InterTypeOf(vr.mType);;
wins->mSTemp[0] = vr.mTemp;
wins->mSType[1] = IT_POINTER;
wins->mSTemp[1] = ains->mTTemp;
if (pdec)
wins->mOperandSize = pdec->mSize;
else if (vr.mType->mSize > 2 && vr.mType->mType != DT_TYPE_ARRAY)
wins->mOperandSize = vr.mType->mSize;
else
wins->mOperandSize = 2;

block->Append(wins);

atotal += wins->mOperandSize;
}

if (pdec)
pdec = pdec->mNext;
}
Expand Down Expand Up @@ -1541,6 +1570,8 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
if (cexp->mAsmInsType != ASMIT_BYTE)
{
int opcode = AsmInsOpcodes[cexp->mAsmInsType][cexp->mAsmInsMode];
if (opcode < 0)
mErrors->Error(cexp->mLocation, "Invalid opcode adressing mode");
d[offset++] = opcode;
}

Expand Down
7 changes: 5 additions & 2 deletions oscar64/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ Declaration* Parser::ParseStructDeclaration(uint32 flags, DecType dt)
}
}

dec->mIdent = structName;
dec->mScope = new DeclarationScope(nullptr);
if (!dec->mIdent || !dec->mScope)
{
dec->mIdent = structName;
dec->mScope = new DeclarationScope(nullptr);
}

if (mScanner->mToken == TK_OPEN_BRACE)
{
Expand Down
8 changes: 4 additions & 4 deletions oscar64/oscar64.rc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,29,0
PRODUCTVERSION 1,0,29,0
FILEVERSION 1,0,30,0
PRODUCTVERSION 1,0,30,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -43,12 +43,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "oscar64"
VALUE "FileDescription", "oscar64 compiler"
VALUE "FileVersion", "1.0.29.0"
VALUE "FileVersion", "1.0.30.0"
VALUE "InternalName", "oscar64.exe"
VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "oscar64.exe"
VALUE "ProductName", "oscar64"
VALUE "ProductVersion", "1.0.29.0"
VALUE "ProductVersion", "1.0.30.0"
END
END
BLOCK "VarFileInfo"
Expand Down
6 changes: 3 additions & 3 deletions oscar64setup/oscar64setup.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:oscar64"
"ProductCode" = "8:{F445EC12-D294-4466-A17F-16892657646C}"
"PackageCode" = "8:{C263EE73-C81E-4C63-9EEA-4FD3EA106F58}"
"ProductCode" = "8:{3661BD30-0CEA-48FD-9F79-F3EE87E35F13}"
"PackageCode" = "8:{E524D01A-EAC6-47DD-A7F3-1E088056634C}"
"UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}"
"AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:1.0.29"
"ProductVersion" = "8:1.0.30"
"Manufacturer" = "8:oscar64"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
Expand Down

0 comments on commit 10bb751

Please sign in to comment.