Add -rpt option to generate error map and asm files if linker fails

This commit is contained in:
drmortalwombat 2024-09-26 20:32:20 +02:00
parent 5613a719c5
commit 1fb68c1bf3
7 changed files with 122 additions and 21 deletions

View File

@ -120,6 +120,7 @@ The compiler is command line driven, and creates an executable .prg file.
* -Os : optimize for size
* -Oi : enable auto inline of small functions (part of O2/O3)
* -Oa : optimize inline assembler (part of O2/O3)
* -Oa : optimize inline assembler (part of O2/O3)
* -Oz : enable auto placement of global variables in zero page (part of O3)
* -Op : optimize constant parameters
* -g : create source level debug info and add source line numbers to asm listing
@ -133,6 +134,7 @@ The compiler is command line driven, and creates an executable .prg file.
* -cid : cartridge type ID, used by vice emulator
* -pp : compile in C++ mode
* -psci : use PETSCII encoding for all strings without prefix
* -rpt : generate error files .error.map, .error.asm when linker fails
A list of source files can be provided.

View File

@ -223,8 +223,8 @@ void * memmove(void * dst, const void * src, int size)
int sz = size;
if (sz > 0)
{
char * d = dst;
const char * s = src;
char * d = (char *)dst;
const char * s = (const char *)src;
if (d < s)
{
do {
@ -245,7 +245,7 @@ void * memmove(void * dst, const void * src, int size)
int memcmp(const void * ptr1, const void * ptr2, int size)
{
const char * p = ptr1, * q = ptr2;
const char * p = (const char *)ptr1, * q = (const char *)ptr2;
char c, d;
while (size--)

View File

@ -1188,6 +1188,82 @@ bool Compiler::BuildLZO(const char* targetPath)
}
}
bool Compiler::RemoveErrorFile(const char* targetPath)
{
char prgPath[200], mapPath[200], asmPath[200], intPath[200];
char basePath[200];
strcpy_s(basePath, targetPath);
ptrdiff_t i = strlen(basePath);
while (i > 0 && basePath[i - 1] != '/' && basePath[i - 1] != '\\' && basePath[i - 1] != ':')
i--;
if (i > 0)
basePath[i] = 0;
strcpy_s(prgPath, targetPath);
i = strlen(prgPath);
while (i > 0 && prgPath[i - 1] != '.')
i--;
if (i > 0)
prgPath[i] = 0;
strcpy_s(mapPath, prgPath);
strcpy_s(asmPath, prgPath);
strcpy_s(intPath, prgPath);
strcat_s(mapPath, "error.map");
strcat_s(asmPath, "error.asm");
strcat_s(intPath, "error.int");
remove(mapPath);
remove(asmPath);
remove(intPath);
return true;
}
bool Compiler::WriteErrorFile(const char* targetPath)
{
char prgPath[200], mapPath[200], asmPath[200], intPath[200];
char basePath[200];
strcpy_s(basePath, targetPath);
ptrdiff_t i = strlen(basePath);
while (i > 0 && basePath[i - 1] != '/' && basePath[i - 1] != '\\' && basePath[i - 1] != ':')
i--;
if (i > 0)
basePath[i] = 0;
strcpy_s(prgPath, targetPath);
i = strlen(prgPath);
while (i > 0 && prgPath[i - 1] != '.')
i--;
if (i > 0)
prgPath[i] = 0;
strcpy_s(mapPath, prgPath);
strcpy_s(asmPath, prgPath);
strcpy_s(intPath, prgPath);
strcat_s(mapPath, "error.map");
strcat_s(asmPath, "error.asm");
strcat_s(intPath, "error.int");
if (mCompilerOptions & COPT_VERBOSE)
printf("Writing <%s>\n", mapPath);
mLinker->WriteMapFile(mapPath);
if (mCompilerOptions & COPT_VERBOSE)
printf("Writing <%s>\n", asmPath);
mLinker->WriteAsmFile(asmPath, mVersion);
if (mCompilerOptions & COPT_VERBOSE)
printf("Writing <%s>\n", intPath);
mInterCodeModule->Disassemble(intPath);
return true;
}
bool Compiler::WriteOutputFile(const char* targetPath, DiskImage * d64)
{
char prgPath[200], mapPath[200], asmPath[200], lblPath[200], intPath[200], bcsPath[200], dbjPath[200];

View File

@ -48,6 +48,8 @@ public:
bool ParseSource(void);
bool GenerateCode(void);
bool WriteOutputFile(const char* targetPath, DiskImage * d64);
bool WriteErrorFile(const char* targetPath);
bool RemoveErrorFile(const char* targetPath);
int ExecuteCode(bool profile, int trace);
void AddDefine(const Ident* ident, const char* value);

View File

@ -39,6 +39,7 @@ static const uint64 COPT_DEBUGINFO = 1ULL << 51;
static const uint64 COPT_CPLUSPLUS = 1ULL << 52;
static const uint64 COPT_PETSCII = 1ULL << 53;
static const uint64 COPT_ERROR_FILES = 1ULL << 54;

View File

@ -1676,15 +1676,18 @@ bool Linker::WriteMapFile(const char* filename)
if (obj->mFlags & LOBJF_REFERENCED)
{
if (banked)
if (obj->mRegion)
{
int k = 0;
while (k < 64 && !(obj->mRegion->mCartridgeBanks & (1ull << k)))
k++;
if (k < 64)
fprintf(file, "%02x:", k);
else
fprintf(file, "--:");
if (banked)
{
int k = 0;
while (k < 64 && !(obj->mRegion->mCartridgeBanks & (1ull << k)))
k++;
if (k < 64)
fprintf(file, "%02x:", k);
else
fprintf(file, "--:");
}
}
if (obj->mIdent)
@ -1728,15 +1731,18 @@ bool Linker::WriteMapFile(const char* filename)
{
const LinkerObject* obj = so[i];
if (banked)
if (obj->mRegion)
{
int k = 0;
while (k < 64 && !(obj->mRegion->mCartridgeBanks & (1ull << k)))
k++;
if (k < 64)
fprintf(file, "%02x:", k);
else
fprintf(file, "--:");
if (banked)
{
int k = 0;
while (k < 64 && !(obj->mRegion->mCartridgeBanks & (1ull << k)))
k++;
if (k < 64)
fprintf(file, "%02x:", k);
else
fprintf(file, "--:");
}
}
fprintf(file, "%04x (%04x) : %s, %s:%s\n", obj->mAddress, obj->mSize, obj->mIdent->mString, LinkerObjectTypeNames[obj->mType], obj->mSection->mIdent->mString);
@ -1926,7 +1932,9 @@ bool Linker::WriteAsmFile(const char* filename, const char* version)
mByteCodeDisassembler.Disassemble(file, mMemory, -1, obj->mAddress, obj->mSize, obj->mProc, obj->mIdent, this);
break;
case LOT_NATIVE_CODE:
if (obj->mRegion->mCartridgeBanks)
if (!obj->mRegion)
mNativeDisassembler.Disassemble(file, obj->mData, -1, 0, obj->mSize, obj->mProc, obj->mIdent, this, obj->mFullIdent);
else if (obj->mRegion->mCartridgeBanks)
{
int i = 0;
while (!(obj->mRegion->mCartridgeBanks & (1ULL << i)))
@ -1939,7 +1947,9 @@ bool Linker::WriteAsmFile(const char* filename, const char* version)
mNativeDisassembler.Disassemble(file, mMemory, -1, obj->mAddress, obj->mSize, obj->mProc, obj->mIdent, this, obj->mFullIdent);
break;
case LOT_DATA:
if (obj->mRegion->mCartridgeBanks)
if (!obj->mRegion)
mNativeDisassembler.DumpMemory(file, obj->mData, -1, 0, obj->mSize, obj->mProc, obj->mIdent, this, obj);
else if (obj->mRegion->mCartridgeBanks)
{
int i = 0;
while (!(obj->mRegion->mCartridgeBanks & (1ULL << i)))

View File

@ -312,6 +312,10 @@ int main2(int argc, const char** argv)
compiler->mCompilerOptions |= COPT_CPLUSPLUS;
compiler->AddDefine(Ident::Unique("__cplusplus"), "1");
}
else if (arg[1] == 'r' && arg[2] == 'm' && arg[3] == 'p')
{
compiler->mCompilerOptions |= COPT_ERROR_FILES;
}
else
compiler->mErrors->Error(loc, EERR_COMMAND_LINE, "Invalid command line argument", arg);
}
@ -524,6 +528,8 @@ int main2(int argc, const char** argv)
printf("Starting %s %s\n", strProductName, strProductVersion);
}
compiler->WriteErrorFile(targetPath);
{
char dstring[100], tstring[100];
time_t now = time(NULL);
@ -579,6 +585,10 @@ int main2(int argc, const char** argv)
if (emulate)
compiler->ExecuteCode(profile, trace);
}
else if (compiler->mCompilerOptions & COPT_ERROR_FILES)
{
compiler->WriteErrorFile(targetPath);
}
}
if (compiler->mErrors->mErrorCount != 0)