Fix array of array of char init with strings

This commit is contained in:
drmortalwombat 2021-09-07 13:37:56 +02:00
parent 14f6af66af
commit 722347609d
5 changed files with 194 additions and 1 deletions

View File

@ -0,0 +1,113 @@
#include "NativeCodeGenerator.h"
NativeCodeInstruction::NativeCodeInstruction(AsmInsType type, AsmInsMode mode)
: mType(type), mMode(mode), mGlobal(false), mAddress(0), mVarIndex(-1)
{}
void NativeCodeInstruction::Assemble(ByteCodeGenerator* generator, NativeCodeBasicBlock* block)
{
switch (mMode)
{
block->PutByte(AsmInsOpcodes[mType][mMode]);
switch (mMode)
{
case ASMIM_IMPLIED:
break;
case ASMIM_IMMEDIATE:
case ASMIM_ZERO_PAGE:
case ASMIM_ZERO_PAGE_X:
case ASMIM_INDIRECT_X:
case ASMIM_INDIRECT_Y:
block->PutByte(uint8(mAddress));
break;
case ASMIM_ABSOLUTE:
case ASMIM_INDIRECT:
case ASMIM_ABSOLUTE_X:
case ASMIM_ABSOLUTE_Y:
if (mGlobal)
{
ByteCodeRelocation rl;
rl.mAddr = block->mCode.Size();
rl.mFunction = false;
rl.mLower = true;
rl.mUpper = true;
rl.mIndex = mVarIndex;
rl.mOffset = mAddress;
block->mRelocations.Push(rl);
block->PutWord(0);
}
else
{
block->PutWord(uint16(mAddress));
}
break;
case ASMIM_RELATIVE:
block->PutByte(uint8(mAddress - block->mCode.Size() - 1));
break;
}
}
}
void NativeCodeBasicBlock::PutByte(uint8 code)
{
this->mCode.Insert(code);
}
void NativeCodeBasicBlock::PutWord(uint16 code)
{
this->mCode.Insert((uint8)(code & 0xff));
this->mCode.Insert((uint8)(code >> 8));
}
#if 0
static AsmInsType InvertBranchCondition(AsmInsType code)
{
switch (code)
{
case BC_BRANCHS_EQ: return BC_BRANCHS_NE;
case BC_BRANCHS_NE: return BC_BRANCHS_EQ;
case BC_BRANCHS_GT: return BC_BRANCHS_LE;
case BC_BRANCHS_GE: return BC_BRANCHS_LT;
case BC_BRANCHS_LT: return BC_BRANCHS_GE;
case BC_BRANCHS_LE: return BC_BRANCHS_GT;
default:
return code;
}
}
static AsmInsType TransposeBranchCondition(AsmInsType code)
{
switch (code)
{
case BC_BRANCHS_EQ: return BC_BRANCHS_EQ;
case BC_BRANCHS_NE: return BC_BRANCHS_NE;
case BC_BRANCHS_GT: return BC_BRANCHS_LT;
case BC_BRANCHS_GE: return BC_BRANCHS_LE;
case BC_BRANCHS_LT: return BC_BRANCHS_GT;
case BC_BRANCHS_LE: return BC_BRANCHS_GE;
default:
return code;
}
}
int NativeCodeBasicBlock::PutBranch(ByteCodeGenerator* generator, AsmInsType code, int offset)
{
if (offset >= -126 && offset <= 129)
{
PutByte(AsmInsOpcodes[code][ASMIM_RELATIVE]);
PutByte(offset - 2);
return 2;
}
else
{
PutByte(AsmInsOpcodes[code][ASMIM_RELATIVE]);
PutCode(generator, ByteCode(code + (BC_JUMPF - BC_JUMPS)));
PutWord(offset - 3);
return 3;
}
}
#endif

View File

@ -0,0 +1,71 @@
#pragma once
#include "ByteCodeGenerator.h"
#include "Assembler.h"
class NativeCodeProcedure;
class NativeCodeBasicBlock;
class NativeCodeInstruction
{
public:
NativeCodeInstruction(AsmInsType type, AsmInsMode mode);
AsmInsType mType;
AsmInsMode mMode;
int mAddress, mVarIndex;
bool mGlobal;
void Assemble(ByteCodeGenerator* generator, NativeCodeBasicBlock* block);
};
class NativeCodeBasicBlock
{
public:
NativeCodeBasicBlock(void);
~NativeCodeBasicBlock(void);
DynamicArray<uint8> mCode;
int mIndex;
NativeCodeBasicBlock* mTrueJump, * mFalseJump;
AsmInsType mBranch;
GrowingArray<NativeCodeInstruction> mIns;
GrowingArray<ByteCodeRelocation> mRelocations;
int mOffset, mSize;
bool mPlaced, mCopied, mKnownShortBranch, mBypassed, mAssembled;
int PutBranch(ByteCodeGenerator* generator, AsmInsType code, int offset);
NativeCodeBasicBlock* BypassEmptyBlocks(void);
void CalculateOffset(int& total);
void CopyCode(ByteCodeGenerator* generator, uint8* target);
void Assemble(ByteCodeGenerator* generator);
void Compile(InterCodeProcedure* iproc, NativeCodeProcedure* proc, InterCodeBasicBlock* block);
void Close(NativeCodeBasicBlock* trueJump, NativeCodeBasicBlock* falseJump, AsmInsType branch);
void PutByte(uint8 code);
void PutWord(uint16 code);
};
class NativeCodeProcedure
{
public:
NativeCodeProcedure(void);
~NativeCodeProcedure(void);
NativeCodeBasicBlock* entryBlock, * exitBlock;
NativeCodeBasicBlock** tblocks;
int mProgStart, mProgSize;
void Compile(ByteCodeGenerator* generator, InterCodeProcedure* proc);
NativeCodeBasicBlock* CompileBlock(InterCodeProcedure* iproc, InterCodeBasicBlock* block);
};

View File

@ -469,7 +469,8 @@ Declaration * Parser::CopyConstantInitializer(int offset, Declaration* dtype, Ex
else
{
Declaration* ndec = new Declaration(dec->mLocation, DT_CONST_DATA);
ndec->mValue = exp;
ndec->mData = dec->mData;
ndec->mSize = dec->mSize;
ndec->mBase = dtype;
dec = ndec;
}

View File

@ -151,6 +151,7 @@
<ClCompile Include="Ident.cpp" />
<ClCompile Include="InterCode.cpp" />
<ClCompile Include="InterCodeGenerator.cpp" />
<ClCompile Include="NativeCodeGenerator.cpp" />
<ClCompile Include="NumberSet.cpp" />
<ClCompile Include="oscar64.cpp" />
<ClCompile Include="Parser.cpp" />
@ -171,6 +172,7 @@
<ClInclude Include="InterCode.h" />
<ClInclude Include="InterCodeGenerator.h" />
<ClInclude Include="MachineTypes.h" />
<ClInclude Include="NativeCodeGenerator.h" />
<ClInclude Include="NumberSet.h" />
<ClInclude Include="Parser.h" />
<ClInclude Include="Preprocessor.h" />

View File

@ -60,6 +60,9 @@
<ClCompile Include="Scanner.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NativeCodeGenerator.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Array.h">
@ -119,6 +122,9 @@
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="NativeCodeGenerator.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="oscar64.rc">