diff --git a/autotest/autotest.bat b/autotest/autotest.bat index c7f8e74..9c615cf 100644 --- a/autotest/autotest.bat +++ b/autotest/autotest.bat @@ -1,99 +1,99 @@ @echo off -..\release\oscar64 -i=../include -rt=../include/crt.c -e stdlibtest.c +..\release\oscar64 -e stdlibtest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n stdlibtest.c +..\release\oscar64 -e -n stdlibtest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e testint16.c +..\release\oscar64 -e testint16.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n testint16.c +..\release\oscar64 -e -n testint16.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e recursiontest.c +..\release\oscar64 -e recursiontest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n recursiontest.c +..\release\oscar64 -e -n recursiontest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e strcmptest.c +..\release\oscar64 -e strcmptest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n strcmptest.c +..\release\oscar64 -e -n strcmptest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e arraytest.c +..\release\oscar64 -e arraytest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n arraytest.c +..\release\oscar64 -e -n arraytest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e arraytestfloat.c +..\release\oscar64 -e arraytestfloat.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n arraytestfloat.c +..\release\oscar64 -e -n arraytestfloat.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e optiontest.c +..\release\oscar64 -e optiontest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n optiontest.c +..\release\oscar64 -e -n optiontest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e floatcmptest.c +..\release\oscar64 -e floatcmptest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n floatcmptest.c +..\release\oscar64 -e -n floatcmptest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e floatmultest.c +..\release\oscar64 -e floatmultest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n floatmultest.c +..\release\oscar64 -e -n floatmultest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e staticconsttest.c +..\release\oscar64 -e staticconsttest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n staticconsttest.c +..\release\oscar64 -e -n staticconsttest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e arrayinittest.c +..\release\oscar64 -e arrayinittest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n arrayinittest.c +..\release\oscar64 -e -n arrayinittest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e array2stringinittest.c +..\release\oscar64 -e array2stringinittest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n array2stringinittest.c +..\release\oscar64 -e -n array2stringinittest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e testint16cmp.c +..\release\oscar64 -e testint16cmp.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n testint16cmp.c +..\release\oscar64 -e -n testint16cmp.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e floatstringtest.c +..\release\oscar64 -e floatstringtest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n floatstringtest.c +..\release\oscar64 -e -n floatstringtest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e qsorttest.c +..\release\oscar64 -e qsorttest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n qsorttest.c +..\release\oscar64 -e -n qsorttest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e loopdomtest.c +..\release\oscar64 -e loopdomtest.c if %errorlevel% neq 0 goto :error -..\release\oscar64 -i=../include -rt=../include/crt.c -e -n loopdomtest.c +..\release\oscar64 -e -n loopdomtest.c if %errorlevel% neq 0 goto :error exit /b 0 diff --git a/include/crt.c b/include/crt.c index d6aa3ae..19d1730 100644 --- a/include/crt.c +++ b/include/crt.c @@ -1,7 +1,9 @@ // crt.c #include -unsigned int StackTop = 0xa000 - 2; +void StackStart, StackEnd; + +#pragma section(stack, 0x0000, StackStart, StackEnd) int main(void); @@ -25,9 +27,9 @@ __asm startup lda #>bcode sta ip + 1 - lda StackTop + 0 + lda #StackEnd - 2 sta sp + 1 pexec: ldy #0 diff --git a/include/stdlib.c b/include/stdlib.c index 0370209..0a6a23f 100644 --- a/include/stdlib.c +++ b/include/stdlib.c @@ -270,14 +270,19 @@ struct Heap { bool freeHeapInit = false; +void HeapStart, HeapEnd; + +#pragma section(heap, 0x0000, HeapStart, HeapEnd) + + void * malloc(unsigned int size) { size = (size + 7) & ~3; if (!freeHeapInit) { - freeHeap = (Heap *)*(int *)0x2d; + freeHeap = (Heap *)&HeapStart; freeHeap->next = nullptr; - freeHeap->size = 0xa000 - 4096 - (int)freeHeap; + freeHeap->size = (unsigned int)&HeapEnd - (unsigned int)&HeapStart; freeHeapInit = true; } diff --git a/make/makefile b/make/makefile index 9d1a1b9..533d3e1 100644 --- a/make/makefile +++ b/make/makefile @@ -4,7 +4,7 @@ sources = $(wildcard ../oscar64/*.cpp) objects = $(patsubst ../oscar64/%.cpp,%.o,$(sources)) CXX = g++ -CPPFLAGS = -g -O -march=athlon64 -mfpmath=sse +CPPFLAGS = -g -O2 ifdef WINDIR @@ -29,8 +29,8 @@ endif sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$ -oscar64 : $(objects) - g++ $(CPPFLAGS) $(linklibs) $(objects) -o oscar64 +../bin/oscar64 : $(objects) + g++ $(CPPFLAGS) $(linklibs) $(objects) -o ../bin/oscar64 .PHONY : clean clean : diff --git a/oscar64/CompilationUnits.h b/oscar64/CompilationUnits.h index 3df1276..6eef704 100644 --- a/oscar64/CompilationUnits.h +++ b/oscar64/CompilationUnits.h @@ -28,6 +28,7 @@ public: DeclarationScope* mRuntimeScope; LinkerSection* mSectionCode, * mSectionData, * mSectionBSS, * mSectionHeap, * mSectionStack; + Linker* mLinker; bool AddUnit(Location & location, const char* name, const char * from); CompilationUnit* PendingUnit(void); diff --git a/oscar64/Compiler.cpp b/oscar64/Compiler.cpp index 9bcbbc1..960295a 100644 --- a/oscar64/Compiler.cpp +++ b/oscar64/Compiler.cpp @@ -20,11 +20,14 @@ Compiler::Compiler(void) mNativeCodeGenerator = new NativeCodeGenerator(mErrors, mLinker); mInterCodeModule = new InterCodeModule(); - mCompilationUnits->mSectionCode = mLinker->AddSection(Ident::Unique("code"), 0); - mCompilationUnits->mSectionData = mLinker->AddSection(Ident::Unique("data"), 0); - mCompilationUnits->mSectionBSS = mLinker->AddSection(Ident::Unique("bss"), 0); - mCompilationUnits->mSectionHeap = mLinker->AddSection(Ident::Unique("heap"), 0); - mCompilationUnits->mSectionStack = mLinker->AddSection(Ident::Unique("stack"), 0); + mCompilationUnits->mLinker = mLinker; + + mCompilationUnits->mSectionCode = mLinker->AddSection(Ident::Unique("code"), LST_DATA); + mCompilationUnits->mSectionData = mLinker->AddSection(Ident::Unique("data"), LST_DATA); + mCompilationUnits->mSectionBSS = mLinker->AddSection(Ident::Unique("bss"), LST_BSS); + mCompilationUnits->mSectionHeap = mLinker->AddSection(Ident::Unique("heap"), LST_HEAP); + mCompilationUnits->mSectionStack = mLinker->AddSection(Ident::Unique("stack"), LST_STACK); + mCompilationUnits->mSectionStack->mSize = 4096; } Compiler::~Compiler(void) @@ -51,7 +54,7 @@ bool Compiler::ParseSource(void) CompilationUnit* cunit; while (mErrors->mErrorCount == 0 && (cunit = mCompilationUnits->PendingUnit())) { - if (mPreprocessor->OpenSource(cunit->mFileName, true)) + if (mPreprocessor->OpenSource("Compiling", cunit->mFileName, true)) { Scanner* scanner = new Scanner(mErrors, mPreprocessor); @@ -123,20 +126,33 @@ bool Compiler::GenerateCode(void) const Ident* identMain = Ident::Unique("main"); const Ident* identCode = Ident::Unique("code"); - LinkerRegion * regionStartup = mLinker->AddRegion(identStartup, 0x0801, 0x0900); - LinkerRegion * regionBytecode = mLinker->AddRegion(identBytecode, 0x0900, 0x0a00); - LinkerRegion * regionMain = mLinker->AddRegion(identMain, 0x0a00, 0xa000); + LinkerRegion* regionStartup = mLinker->FindRegion(identStartup); + if (!regionStartup) + regionStartup = mLinker->AddRegion(identStartup, 0x0801, 0x0900); + + LinkerRegion* regionBytecode = mLinker->FindRegion(identBytecode); + if (!regionBytecode) + regionBytecode = mLinker->AddRegion(identBytecode, 0x0900, 0x0a00); - LinkerSection * sectionStartup = mLinker->AddSection(identStartup, 0); - LinkerSection * sectionBytecode = mLinker->AddSection(identBytecode, 0); + LinkerRegion* regionMain = mLinker->FindRegion(identMain); + + LinkerSection * sectionStartup = mLinker->AddSection(identStartup, LST_DATA); + LinkerSection * sectionBytecode = mLinker->AddSection(identBytecode, LST_DATA); regionStartup->mSections.Push(sectionStartup); regionBytecode->mSections.Push(sectionBytecode); - regionMain->mSections.Push(mCompilationUnits->mSectionCode); - regionMain->mSections.Push(mCompilationUnits->mSectionData); - regionMain->mSections.Push(mCompilationUnits->mSectionBSS); - regionMain->mSections.Push(mCompilationUnits->mSectionHeap); - regionMain->mSections.Push(mCompilationUnits->mSectionStack); + + if (!mLinker->IsSectionPlaced(mCompilationUnits->mSectionCode)) + { + if (!regionMain) + regionMain = mLinker->AddRegion(identMain, 0x0a00, 0xa000); + + regionMain->mSections.Push(mCompilationUnits->mSectionCode); + regionMain->mSections.Push(mCompilationUnits->mSectionData); + regionMain->mSections.Push(mCompilationUnits->mSectionBSS); + regionMain->mSections.Push(mCompilationUnits->mSectionHeap); + regionMain->mSections.Push(mCompilationUnits->mSectionStack); + } dcrtstart->mSection = sectionStartup; diff --git a/oscar64/Declaration.h b/oscar64/Declaration.h index 87c17a9..ff1b966 100644 --- a/oscar64/Declaration.h +++ b/oscar64/Declaration.h @@ -47,19 +47,20 @@ enum DecType // TypeFlags -static const uint32 DTF_SIGNED = 0x00000001; -static const uint32 DTF_DEFINED = 0x00000002; -static const uint32 DTF_GLOBAL = 0x00000004; -static const uint32 DTF_VARIADIC = 0x00000008; -static const uint32 DTF_INTRINSIC = 0x00000010; -static const uint32 DTF_STATIC = 0x00000020; -static const uint32 DTF_CONST = 0x00000040; -static const uint32 DTF_VOLATILE = 0x00000080; -static const uint32 DTF_EXTERN = 0x00000100; -static const uint32 DTF_NATIVE = 0x00000200; -static const uint32 DTF_UPPER_BYTE = 0x00000400; -static const uint32 DTF_LOWER_BYTE = 0x00000800; - +static const uint32 DTF_SIGNED = 0x00000001; +static const uint32 DTF_DEFINED = 0x00000002; +static const uint32 DTF_GLOBAL = 0x00000004; +static const uint32 DTF_VARIADIC = 0x00000008; +static const uint32 DTF_INTRINSIC = 0x00000010; +static const uint32 DTF_STATIC = 0x00000020; +static const uint32 DTF_CONST = 0x00000040; +static const uint32 DTF_VOLATILE = 0x00000080; +static const uint32 DTF_EXTERN = 0x00000100; +static const uint32 DTF_NATIVE = 0x00000200; +static const uint32 DTF_UPPER_BYTE = 0x00000400; +static const uint32 DTF_LOWER_BYTE = 0x00000800; +static const uint32 DTF_SECTION_START = 0x00001000; +static const uint32 DTF_SECTION_END = 0x00002000; class Declaration; diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 15824b5..25b066b 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -3220,8 +3220,10 @@ void InterCodeBasicBlock::SingleBlockLoopOptimisation(void) mInstructions[j++] = ins; } } +#ifdef _DEBUG if (j != mInstructions.Size()) printf("Moved %d %d\n", mIndex, mInstructions.Size() - j); +#endif mInstructions.SetSize(j); #endif } diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index 399361d..329df01 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -195,6 +195,11 @@ void InterCodeGenerator::InitGlobalVariable(InterCodeModule * mod, Declaration* dec->mVarIndex = var->mIndex; dec->mLinkerObject = var->mLinkerObject; + if (dec->mFlags & DTF_SECTION_START) + dec->mLinkerObject->mType = LOT_SECTION_START; + else if (dec->mFlags & DTF_SECTION_END) + dec->mLinkerObject->mType = LOT_SECTION_END; + uint8* d = var->mLinkerObject->AddSpace(var->mSize); if (dec->mValue) { @@ -260,6 +265,26 @@ void InterCodeGenerator::TranslateAssembler(InterCodeModule* mod, Expression * e offset += 1; } + else if (aexp->mType == DT_VARIABLE_REF) + { + if (aexp->mBase->mFlags & DTF_GLOBAL) + { + InitGlobalVariable(mod, aexp->mBase); + + LinkerReference ref; + ref.mObject = dec->mLinkerObject; + ref.mOffset = offset; + ref.mHighByte = aexp->mFlags & DTF_UPPER_BYTE; + ref.mLowByte = !(aexp->mFlags & DTF_UPPER_BYTE); + ref.mRefObject = aexp->mBase->mLinkerObject; + ref.mRefOffset = aexp->mOffset; + mLinker->AddReference(ref); + + offset += 1; + } + else + mErrors->Error(aexp->mLocation, EERR_ASM_INVALD_OPERAND, "Invalid immediate operand"); + } else if (aexp->mType == DT_FUNCTION_REF) { if (!aexp->mBase->mLinkerObject) @@ -279,6 +304,8 @@ void InterCodeGenerator::TranslateAssembler(InterCodeModule* mod, Expression * e offset += 1; } + else + mErrors->Error(aexp->mLocation, EERR_ASM_INVALD_OPERAND, "Invalid immediate operand"); break; case ASMIM_ZERO_PAGE: case ASMIM_ZERO_PAGE_X: diff --git a/oscar64/Linker.cpp b/oscar64/Linker.cpp index 8c3cfc7..97ab60d 100644 --- a/oscar64/Linker.cpp +++ b/oscar64/Linker.cpp @@ -49,10 +49,22 @@ LinkerRegion* Linker::AddRegion(const Ident* region, int start, int end) return lrgn; } -LinkerSection* Linker::AddSection(const Ident* section, uint32 flags) +LinkerRegion* Linker::FindRegion(const Ident* region) +{ + for (int i = 0; i < mRegions.Size(); i++) + { + if (mRegions[i]->mIdent == region) + return mRegions[i]; + } + + return nullptr; +} + +LinkerSection* Linker::AddSection(const Ident* section, LinkerSectionType type) { LinkerSection* lsec = new LinkerSection; lsec->mIdent = section; + lsec->mType = type; mSections.Push(lsec); return lsec; @@ -69,6 +81,19 @@ LinkerSection* Linker::FindSection(const Ident* section) return nullptr; } +bool Linker::IsSectionPlaced(LinkerSection* section) +{ + for (int i = 0; i < mRegions.Size(); i++) + { + LinkerRegion* rgn = mRegions[i]; + for (int j = 0; j < rgn->mSections.Size(); j++) + if (section == rgn->mSections[j]) + return true; + } + + return false; +} + LinkerObject * Linker::AddObject(const Location& location, const Ident* ident, LinkerSection * section, LinkerObjectType type) { LinkerObject* obj = new LinkerObject; @@ -112,6 +137,13 @@ void Linker::Link(void) if (mErrors->mErrorCount == 0) { + for (int i = 0; i < mSections.Size(); i++) + { + LinkerSection* lsec = mSections[i]; + lsec->mStart = 0x10000; + lsec->mEnd = 0x0000; + } + // Move objects into regions for (int i = 0; i < mRegions.Size(); i++) @@ -128,6 +160,11 @@ void Linker::Link(void) lobj->mPlaced = true; lobj->mAddress = lrgn->mStart + lrgn->mUsed; lrgn->mUsed += lobj->mSize; + + if (lobj->mAddress < lsec->mStart) + lsec->mStart = lobj->mAddress; + if (lobj->mAddress + lobj->mSize > lsec->mEnd) + lsec->mEnd = lobj->mAddress + lobj->mSize; } } } @@ -147,10 +184,49 @@ void Linker::Link(void) mProgramEnd = address; } + // Place stack segment + + for (int i = 0; i < mRegions.Size(); i++) + { + LinkerRegion* lrgn = mRegions[i]; + for (int j = 0; j < lrgn->mSections.Size(); j++) + { + LinkerSection* lsec = lrgn->mSections[j]; + + if (lsec->mType == LST_STACK) + { + lsec->mStart = lrgn->mEnd - lsec->mSize; + lsec->mEnd = lrgn->mEnd; + lrgn->mEnd = lsec->mStart; + } + } + } + + // Now expand the heap section to cover the reaminder of the region + + for (int i = 0; i < mRegions.Size(); i++) + { + LinkerRegion* lrgn = mRegions[i]; + for (int j = 0; j < lrgn->mSections.Size(); j++) + { + LinkerSection* lsec = lrgn->mSections[j]; + + if (lsec->mType == LST_HEAP) + { + lsec->mStart = lrgn->mStart + lrgn->mUsed; + lsec->mEnd = lrgn->mEnd; + } + } + } + for (int i = 0; i < mObjects.Size(); i++) { LinkerObject* obj = mObjects[i]; - if (obj->mReferenced) + if (obj->mType == LOT_SECTION_START) + obj->mAddress = obj->mSection->mStart; + else if (obj->mType == LOT_SECTION_END) + obj->mAddress = obj->mSection->mEnd; + else if (obj->mReferenced) { memcpy(mMemory + obj->mAddress, obj->mData, obj->mSize); } @@ -186,7 +262,10 @@ static const char * LinkerObjectTypeNames[] = "RUNTIME", "DATA", "BSS", - "STACK" + "HEAP", + "STACK", + "START", + "END" }; bool Linker::WritePrgFile(const char* filename) diff --git a/oscar64/Linker.h b/oscar64/Linker.h index ba67ddf..fa52441 100644 --- a/oscar64/Linker.h +++ b/oscar64/Linker.h @@ -18,7 +18,19 @@ enum LinkerObjectType LOT_RUNTIME, LOT_DATA, LOT_BSS, - LOT_STACK + LOT_HEAP, + LOT_STACK, + LOT_SECTION_START, + LOT_SECTION_END +}; + +enum LinkerSectionType +{ + LST_NONE, + LST_DATA, + LST_BSS, + LST_HEAP, + LST_STACK }; class LinkerObject; @@ -51,6 +63,10 @@ public: GrowingArray mObjects; + + int mStart, mEnd, mSize; + LinkerSectionType mType; + LinkerSection(void); }; @@ -79,9 +95,13 @@ public: ~Linker(void); LinkerRegion * AddRegion(const Ident* region, int start, int end); - LinkerSection * AddSection(const Ident* section, uint32 flags); + LinkerRegion* FindRegion(const Ident* region); + + LinkerSection * AddSection(const Ident* section, LinkerSectionType type); LinkerSection* FindSection(const Ident* section); + bool IsSectionPlaced(LinkerSection* section); + LinkerObject * AddObject(const Location & location, const Ident* ident, LinkerSection * section, LinkerObjectType type); void AddReference(const LinkerReference& ref); diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 4e57137..1253a78 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -2572,6 +2572,129 @@ void Parser::ParsePragma(void) ConsumeToken(TK_CLOSE_PARENTHESIS); } + else if (!strcmp(mScanner->mTokenIdent->mString, "region")) + { + mScanner->NextToken(); + ConsumeToken(TK_OPEN_PARENTHESIS); + + if (mScanner->mToken == TK_IDENT) + { + const Ident* regionIdent = mScanner->mTokenIdent; + mScanner->NextToken(); + + Expression* exp; + int start = 0, end = 0, flags = 0; + + ConsumeToken(TK_COMMA); + + exp = ParseRExpression(); + if (exp->mType == EX_CONSTANT && exp->mDecValue->mType == DT_CONST_INTEGER) + start = exp->mDecValue->mInteger; + else + mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Integer number for start expected"); + + ConsumeToken(TK_COMMA); + + exp = ParseRExpression(); + if (exp->mType == EX_CONSTANT && exp->mDecValue->mType == DT_CONST_INTEGER) + end = exp->mDecValue->mInteger; + else + mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Integer number for end expected"); + + ConsumeToken(TK_COMMA); + + exp = ParseRExpression(); + if (exp->mType == EX_CONSTANT && exp->mDecValue->mType == DT_CONST_INTEGER) + flags = exp->mDecValue->mInteger; + else + mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Integer number for flags expected"); + + LinkerRegion* rgn = mCompilationUnits->mLinker->FindRegion(regionIdent); + if (!rgn) + rgn = mCompilationUnits->mLinker->AddRegion(regionIdent, start, end); + else if (rgn->mStart != start || rgn->mEnd != end) + mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Conflicting linker region definition"); + + ConsumeToken(TK_COMMA); + ConsumeToken(TK_OPEN_BRACE); + if (!ConsumeTokenIf(TK_CLOSE_BRACE)) + { + do { + if (mScanner->mToken == TK_IDENT) + { + LinkerSection* lsec = mCompilationUnits->mLinker->FindSection(mScanner->mTokenIdent); + if (lsec) + { + rgn->mSections.Push(lsec); + } + else + mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Section name not defined"); + mScanner->NextToken(); + } + else + mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Section name expected"); + } while (ConsumeTokenIf(TK_COMMA)); + ConsumeToken(TK_CLOSE_BRACE); + } + } + else + mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Region name expected"); + + ConsumeToken(TK_CLOSE_PARENTHESIS); + } + else if (!strcmp(mScanner->mTokenIdent->mString, "section")) + { + mScanner->NextToken(); + ConsumeToken(TK_OPEN_PARENTHESIS); + + if (mScanner->mToken == TK_IDENT) + { + const Ident* sectionIdent = mScanner->mTokenIdent; + mScanner->NextToken(); + + int flags = 0; + Expression* exp; + Declaration* dstart = nullptr, * dend = nullptr; + + ConsumeToken(TK_COMMA); + + exp = ParseRExpression(); + if (exp->mType == EX_CONSTANT && exp->mDecValue->mType == DT_CONST_INTEGER) + flags = exp->mDecValue->mInteger; + else + mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Integer number for flags expected"); + + if (ConsumeTokenIf(TK_COMMA)) + { + exp = ParseExpression(); + if (exp->mDecValue && exp->mDecValue->mType == DT_VARIABLE) + dstart = exp->mDecValue; + + if (ConsumeTokenIf(TK_COMMA)) + { + exp = ParseExpression(); + if (exp->mDecValue && exp->mDecValue->mType == DT_VARIABLE) + dend = exp->mDecValue; + } + } + + LinkerSection* lsec = mCompilationUnits->mLinker->FindSection(sectionIdent); + if (dstart) + { + dstart->mSection = lsec; + dstart->mFlags |= DTF_SECTION_START; + } + if (dend) + { + dend->mSection = lsec; + dend->mFlags |= DTF_SECTION_END; + } + } + else + mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Section name expected"); + + ConsumeToken(TK_CLOSE_PARENTHESIS); + } else { mScanner->NextToken(); diff --git a/oscar64/Preprocessor.cpp b/oscar64/Preprocessor.cpp index 291fb6a..1e8fad8 100644 --- a/oscar64/Preprocessor.cpp +++ b/oscar64/Preprocessor.cpp @@ -65,8 +65,6 @@ bool SourceFile::Open(const char* name, const char* path) if (!fopen_s(&mFile, fname, "r")) { - printf("<%s>\n", fname); - _fullpath(mFileName, fname, sizeof(mFileName)); char* p = mFileName; while (*p) @@ -108,7 +106,7 @@ bool Preprocessor::NextLine(void) return false; } -bool Preprocessor::OpenSource(const char* name, bool local) +bool Preprocessor::OpenSource(const char * reason, const char* name, bool local) { if (mSource) mSource->mLocation = mLocation; @@ -144,7 +142,7 @@ bool Preprocessor::OpenSource(const char* name, bool local) if (ok) { - printf("Reading %s\n", source->mFileName); + printf("%s \"%s\"\n", reason, source->mFileName); source->mUp = mSource; mSource = source; mLocation.mFileName = mSource->mFileName; diff --git a/oscar64/Preprocessor.h b/oscar64/Preprocessor.h index 6f9e876..8c8e2df 100644 --- a/oscar64/Preprocessor.h +++ b/oscar64/Preprocessor.h @@ -48,7 +48,7 @@ public: void AddPath(const char* path); bool NextLine(void); - bool OpenSource(const char* name, bool local); + bool OpenSource(const char* reason, const char* name, bool local); bool CloseSource(void); Preprocessor(Errors * errors); diff --git a/oscar64/Scanner.cpp b/oscar64/Scanner.cpp index bbb065a..dfab64d 100644 --- a/oscar64/Scanner.cpp +++ b/oscar64/Scanner.cpp @@ -442,14 +442,14 @@ void Scanner::NextToken(void) NextRawToken(); if (mToken == TK_STRING) { - if (!mPreprocessor->OpenSource(mTokenString, true)) + if (!mPreprocessor->OpenSource("Including", mTokenString, true)) mErrors->Error(mLocation, EERR_FILE_NOT_FOUND, "Could not open source file", mTokenString); } else if (mToken == TK_LESS_THAN) { mOffset--; StringToken('>'); - if (!mPreprocessor->OpenSource(mTokenString, false)) + if (!mPreprocessor->OpenSource("Including", mTokenString, false)) mErrors->Error(mLocation, EERR_FILE_NOT_FOUND, "Could not open source file", mTokenString); } } diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index ea22004..22f7523 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -75,14 +75,12 @@ int main(int argc, const char** argv) while (length > 0 && basePath[length - 1] != '/' && basePath[length - 1] != '\\') length--; -#ifdef _DEBUG if (length > 0) { length--; while (length > 0 && basePath[length - 1] != '/' && basePath[length - 1] != '\\') length--; } -#endif basePath[length] = 0; diff --git a/oscar64/oscar64.rc b/oscar64/oscar64.rc index aa9217a..a5827b5 100644 --- a/oscar64/oscar64.rc +++ b/oscar64/oscar64.rc @@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,34,0 - PRODUCTVERSION 1,0,34,0 + FILEVERSION 1,0,35,0 + PRODUCTVERSION 1,0,35,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -43,12 +43,12 @@ BEGIN BEGIN VALUE "CompanyName", "oscar64" VALUE "FileDescription", "oscar64 compiler" - VALUE "FileVersion", "1.0.34.0" + VALUE "FileVersion", "1.0.35.0" VALUE "InternalName", "oscar64.exe" VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "OriginalFilename", "oscar64.exe" VALUE "ProductName", "oscar64" - VALUE "ProductVersion", "1.0.34.0" + VALUE "ProductVersion", "1.0.35.0" END END BLOCK "VarFileInfo" diff --git a/oscar64setup/oscar64setup.vdproj b/oscar64setup/oscar64setup.vdproj index ae1eeee..b60789a 100644 --- a/oscar64setup/oscar64setup.vdproj +++ b/oscar64setup/oscar64setup.vdproj @@ -14,12 +14,6 @@ "BackwardsCompatibleGUIDGeneration" = "8:TRUE" "Hierarchy" { - "Entry" - { - "MsmKey" = "8:_09883BBCC7921C34FAE8DEC8640E892E" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } "Entry" { "MsmKey" = "8:_0D8B657E4A954DBFAF14055CDFFB384C" @@ -34,24 +28,12 @@ } "Entry" { - "MsmKey" = "8:_284672F9297967D1B24B7BBC58FB364F" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_317711E6E48744A18655469B4C53767E" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" } "Entry" { - "MsmKey" = "8:_3EC91DF03E72BEDD522BC24213A5E7D9" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_3FFD08277B804985BDF072C0C1877287" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" @@ -70,30 +52,6 @@ } "Entry" { - "MsmKey" = "8:_5960F060020C6A2B0BAEF413344FB56B" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { - "MsmKey" = "8:_6FEB568DE0D18DD5F402D4B3832D2415" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { - "MsmKey" = "8:_88A92C320AD90969C1D5827C4A456293" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { - "MsmKey" = "8:_974C26D2A91F54190ED0067887191F4C" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_9D0D7A63D6C848CD85489D6E7C43AFAD" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" @@ -112,18 +70,6 @@ } "Entry" { - "MsmKey" = "8:_B0DB1EC3D085346B8C6502F8FE5A7495" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { - "MsmKey" = "8:_CB8C214BFD5557975BCF6DC7114EAE05" - "OwnerKey" = "8:_FB2E467BC172457785F4279BB0BFE8B6" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_D0E45B48D76B4407B0BDE4378C1DB2C7" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" @@ -257,26 +203,6 @@ } "File" { - "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_09883BBCC7921C34FAE8DEC8640E892E" - { - "SourcePath" = "8:api-ms-win-crt-stdio-l1-1-0.dll" - "TargetName" = "8:api-ms-win-crt-stdio-l1-1-0.dll" - "Tag" = "8:" - "Folder" = "8:_C95D3F098F884652A04D707B55B980EE" - "Condition" = "8:" - "Transitive" = "11:FALSE" - "Vital" = "11:TRUE" - "ReadOnly" = "11:FALSE" - "Hidden" = "11:FALSE" - "System" = "11:FALSE" - "Permanent" = "11:FALSE" - "SharedLegacy" = "11:FALSE" - "PackageAs" = "3:1" - "Register" = "3:1" - "Exclude" = "11:FALSE" - "IsDependency" = "11:TRUE" - "IsolateTo" = "8:" - } "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_0D8B657E4A954DBFAF14055CDFFB384C" { "SourcePath" = "8:..\\include\\crt.c" @@ -317,26 +243,6 @@ "IsDependency" = "11:FALSE" "IsolateTo" = "8:" } - "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_284672F9297967D1B24B7BBC58FB364F" - { - "SourcePath" = "8:VERSION.dll" - "TargetName" = "8:VERSION.dll" - "Tag" = "8:" - "Folder" = "8:_C95D3F098F884652A04D707B55B980EE" - "Condition" = "8:" - "Transitive" = "11:FALSE" - "Vital" = "11:TRUE" - "ReadOnly" = "11:FALSE" - "Hidden" = "11:FALSE" - "System" = "11:FALSE" - "Permanent" = "11:FALSE" - "SharedLegacy" = "11:FALSE" - "PackageAs" = "3:1" - "Register" = "3:1" - "Exclude" = "11:FALSE" - "IsDependency" = "11:TRUE" - "IsolateTo" = "8:" - } "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_317711E6E48744A18655469B4C53767E" { "SourcePath" = "8:..\\include\\math.c" @@ -357,26 +263,6 @@ "IsDependency" = "11:FALSE" "IsolateTo" = "8:" } - "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_3EC91DF03E72BEDD522BC24213A5E7D9" - { - "SourcePath" = "8:api-ms-win-crt-runtime-l1-1-0.dll" - "TargetName" = "8:api-ms-win-crt-runtime-l1-1-0.dll" - "Tag" = "8:" - "Folder" = "8:_C95D3F098F884652A04D707B55B980EE" - "Condition" = "8:" - "Transitive" = "11:FALSE" - "Vital" = "11:TRUE" - "ReadOnly" = "11:FALSE" - "Hidden" = "11:FALSE" - "System" = "11:FALSE" - "Permanent" = "11:FALSE" - "SharedLegacy" = "11:FALSE" - "PackageAs" = "3:1" - "Register" = "3:1" - "Exclude" = "11:FALSE" - "IsDependency" = "11:TRUE" - "IsolateTo" = "8:" - } "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_3FFD08277B804985BDF072C0C1877287" { "SourcePath" = "8:..\\include\\assert.c" @@ -437,86 +323,6 @@ "IsDependency" = "11:FALSE" "IsolateTo" = "8:" } - "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_5960F060020C6A2B0BAEF413344FB56B" - { - "SourcePath" = "8:api-ms-win-crt-math-l1-1-0.dll" - "TargetName" = "8:api-ms-win-crt-math-l1-1-0.dll" - "Tag" = "8:" - "Folder" = "8:_C95D3F098F884652A04D707B55B980EE" - "Condition" = "8:" - "Transitive" = "11:FALSE" - "Vital" = "11:TRUE" - "ReadOnly" = "11:FALSE" - "Hidden" = "11:FALSE" - "System" = "11:FALSE" - "Permanent" = "11:FALSE" - "SharedLegacy" = "11:FALSE" - "PackageAs" = "3:1" - "Register" = "3:1" - "Exclude" = "11:FALSE" - "IsDependency" = "11:TRUE" - "IsolateTo" = "8:" - } - "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_6FEB568DE0D18DD5F402D4B3832D2415" - { - "SourcePath" = "8:api-ms-win-crt-heap-l1-1-0.dll" - "TargetName" = "8:api-ms-win-crt-heap-l1-1-0.dll" - "Tag" = "8:" - "Folder" = "8:_C95D3F098F884652A04D707B55B980EE" - "Condition" = "8:" - "Transitive" = "11:FALSE" - "Vital" = "11:TRUE" - "ReadOnly" = "11:FALSE" - "Hidden" = "11:FALSE" - "System" = "11:FALSE" - "Permanent" = "11:FALSE" - "SharedLegacy" = "11:FALSE" - "PackageAs" = "3:1" - "Register" = "3:1" - "Exclude" = "11:FALSE" - "IsDependency" = "11:TRUE" - "IsolateTo" = "8:" - } - "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_88A92C320AD90969C1D5827C4A456293" - { - "SourcePath" = "8:api-ms-win-crt-string-l1-1-0.dll" - "TargetName" = "8:api-ms-win-crt-string-l1-1-0.dll" - "Tag" = "8:" - "Folder" = "8:_C95D3F098F884652A04D707B55B980EE" - "Condition" = "8:" - "Transitive" = "11:FALSE" - "Vital" = "11:TRUE" - "ReadOnly" = "11:FALSE" - "Hidden" = "11:FALSE" - "System" = "11:FALSE" - "Permanent" = "11:FALSE" - "SharedLegacy" = "11:FALSE" - "PackageAs" = "3:1" - "Register" = "3:1" - "Exclude" = "11:FALSE" - "IsDependency" = "11:TRUE" - "IsolateTo" = "8:" - } - "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_974C26D2A91F54190ED0067887191F4C" - { - "SourcePath" = "8:api-ms-win-crt-filesystem-l1-1-0.dll" - "TargetName" = "8:api-ms-win-crt-filesystem-l1-1-0.dll" - "Tag" = "8:" - "Folder" = "8:_C95D3F098F884652A04D707B55B980EE" - "Condition" = "8:" - "Transitive" = "11:FALSE" - "Vital" = "11:TRUE" - "ReadOnly" = "11:FALSE" - "Hidden" = "11:FALSE" - "System" = "11:FALSE" - "Permanent" = "11:FALSE" - "SharedLegacy" = "11:FALSE" - "PackageAs" = "3:1" - "Register" = "3:1" - "Exclude" = "11:FALSE" - "IsDependency" = "11:TRUE" - "IsolateTo" = "8:" - } "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_9D0D7A63D6C848CD85489D6E7C43AFAD" { "SourcePath" = "8:..\\include\\stdio.h" @@ -577,46 +383,6 @@ "IsDependency" = "11:FALSE" "IsolateTo" = "8:" } - "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_B0DB1EC3D085346B8C6502F8FE5A7495" - { - "SourcePath" = "8:VCRUNTIME140.dll" - "TargetName" = "8:VCRUNTIME140.dll" - "Tag" = "8:" - "Folder" = "8:_C95D3F098F884652A04D707B55B980EE" - "Condition" = "8:" - "Transitive" = "11:FALSE" - "Vital" = "11:TRUE" - "ReadOnly" = "11:FALSE" - "Hidden" = "11:FALSE" - "System" = "11:FALSE" - "Permanent" = "11:FALSE" - "SharedLegacy" = "11:FALSE" - "PackageAs" = "3:1" - "Register" = "3:1" - "Exclude" = "11:FALSE" - "IsDependency" = "11:TRUE" - "IsolateTo" = "8:" - } - "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_CB8C214BFD5557975BCF6DC7114EAE05" - { - "SourcePath" = "8:api-ms-win-crt-locale-l1-1-0.dll" - "TargetName" = "8:api-ms-win-crt-locale-l1-1-0.dll" - "Tag" = "8:" - "Folder" = "8:_C95D3F098F884652A04D707B55B980EE" - "Condition" = "8:" - "Transitive" = "11:FALSE" - "Vital" = "11:TRUE" - "ReadOnly" = "11:FALSE" - "Hidden" = "11:FALSE" - "System" = "11:FALSE" - "Permanent" = "11:FALSE" - "SharedLegacy" = "11:FALSE" - "PackageAs" = "3:1" - "Register" = "3:1" - "Exclude" = "11:FALSE" - "IsDependency" = "11:TRUE" - "IsolateTo" = "8:" - } "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_D0E45B48D76B4407B0BDE4378C1DB2C7" { "SourcePath" = "8:..\\include\\stdlib.h" @@ -795,6 +561,17 @@ "Property" = "8:TARGETDIR" "Folders" { + "{9EF0B969-E518-4E46-987F-47570745A589}:_607E75AF0E2A4CB9908C4C39DF8FE6E4" + { + "Name" = "8:bin" + "AlwaysCreate" = "11:FALSE" + "Condition" = "8:" + "Transitive" = "11:FALSE" + "Property" = "8:_210EBA1A0EC145268D1720AECA0F9358" + "Folders" + { + } + } "{9EF0B969-E518-4E46-987F-47570745A589}:_7C0D28C244F14A21B5F72213BBE59B6F" { "Name" = "8:include" @@ -824,15 +601,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:oscar64" - "ProductCode" = "8:{1B1262B2-CFAF-4346-9733-79DB9E224B6D}" - "PackageCode" = "8:{61594A55-5A4E-4179-BC77-8F48EEAB26C8}" + "ProductCode" = "8:{CE53A040-8B58-4F00-A6C5-E5150824541F}" + "PackageCode" = "8:{DE875F54-AF8A-4BDA-9BAD-C41F51A13B49}" "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.34" + "ProductVersion" = "8:1.0.35" "Manufacturer" = "8:oscar64" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:" @@ -1349,7 +1126,7 @@ "SourcePath" = "8:..\\Release\\oscar64.exe" "TargetName" = "8:" "Tag" = "8:" - "Folder" = "8:_C95D3F098F884652A04D707B55B980EE" + "Folder" = "8:_607E75AF0E2A4CB9908C4C39DF8FE6E4" "Condition" = "8:" "Transitive" = "11:FALSE" "Vital" = "11:TRUE"