Add -rpt option to generate error map and asm files if linker fails
This commit is contained in:
parent
76975e93aa
commit
8eebad4d8a
|
@ -120,6 +120,7 @@ The compiler is command line driven, and creates an executable .prg file.
|
||||||
* -Os : optimize for size
|
* -Os : optimize for size
|
||||||
* -Oi : enable auto inline of small functions (part of O2/O3)
|
* -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)
|
||||||
|
* -Oa : optimize inline assembler (part of O2/O3)
|
||||||
* -Oz : enable auto placement of global variables in zero page (part of O3)
|
* -Oz : enable auto placement of global variables in zero page (part of O3)
|
||||||
* -Op : optimize constant parameters
|
* -Op : optimize constant parameters
|
||||||
* -g : create source level debug info and add source line numbers to asm listing
|
* -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
|
* -cid : cartridge type ID, used by vice emulator
|
||||||
* -pp : compile in C++ mode
|
* -pp : compile in C++ mode
|
||||||
* -psci : use PETSCII encoding for all strings without prefix
|
* -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.
|
A list of source files can be provided.
|
||||||
|
|
||||||
|
|
|
@ -223,8 +223,8 @@ void * memmove(void * dst, const void * src, int size)
|
||||||
int sz = size;
|
int sz = size;
|
||||||
if (sz > 0)
|
if (sz > 0)
|
||||||
{
|
{
|
||||||
char * d = dst;
|
char * d = (char *)dst;
|
||||||
const char * s = src;
|
const char * s = (const char *)src;
|
||||||
if (d < s)
|
if (d < s)
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
|
@ -245,7 +245,7 @@ void * memmove(void * dst, const void * src, int size)
|
||||||
|
|
||||||
int memcmp(const void * ptr1, const void * ptr2, 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;
|
char c, d;
|
||||||
|
|
||||||
while (size--)
|
while (size--)
|
||||||
|
|
|
@ -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)
|
bool Compiler::WriteOutputFile(const char* targetPath, DiskImage * d64)
|
||||||
{
|
{
|
||||||
char prgPath[200], mapPath[200], asmPath[200], lblPath[200], intPath[200], bcsPath[200], dbjPath[200];
|
char prgPath[200], mapPath[200], asmPath[200], lblPath[200], intPath[200], bcsPath[200], dbjPath[200];
|
||||||
|
|
|
@ -48,6 +48,8 @@ public:
|
||||||
bool ParseSource(void);
|
bool ParseSource(void);
|
||||||
bool GenerateCode(void);
|
bool GenerateCode(void);
|
||||||
bool WriteOutputFile(const char* targetPath, DiskImage * d64);
|
bool WriteOutputFile(const char* targetPath, DiskImage * d64);
|
||||||
|
bool WriteErrorFile(const char* targetPath);
|
||||||
|
bool RemoveErrorFile(const char* targetPath);
|
||||||
int ExecuteCode(bool profile, int trace);
|
int ExecuteCode(bool profile, int trace);
|
||||||
|
|
||||||
void AddDefine(const Ident* ident, const char* value);
|
void AddDefine(const Ident* ident, const char* value);
|
||||||
|
|
|
@ -39,6 +39,7 @@ static const uint64 COPT_DEBUGINFO = 1ULL << 51;
|
||||||
|
|
||||||
static const uint64 COPT_CPLUSPLUS = 1ULL << 52;
|
static const uint64 COPT_CPLUSPLUS = 1ULL << 52;
|
||||||
static const uint64 COPT_PETSCII = 1ULL << 53;
|
static const uint64 COPT_PETSCII = 1ULL << 53;
|
||||||
|
static const uint64 COPT_ERROR_FILES = 1ULL << 54;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1676,15 +1676,18 @@ bool Linker::WriteMapFile(const char* filename)
|
||||||
|
|
||||||
if (obj->mFlags & LOBJF_REFERENCED)
|
if (obj->mFlags & LOBJF_REFERENCED)
|
||||||
{
|
{
|
||||||
if (banked)
|
if (obj->mRegion)
|
||||||
{
|
{
|
||||||
int k = 0;
|
if (banked)
|
||||||
while (k < 64 && !(obj->mRegion->mCartridgeBanks & (1ull << k)))
|
{
|
||||||
k++;
|
int k = 0;
|
||||||
if (k < 64)
|
while (k < 64 && !(obj->mRegion->mCartridgeBanks & (1ull << k)))
|
||||||
fprintf(file, "%02x:", k);
|
k++;
|
||||||
else
|
if (k < 64)
|
||||||
fprintf(file, "--:");
|
fprintf(file, "%02x:", k);
|
||||||
|
else
|
||||||
|
fprintf(file, "--:");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj->mIdent)
|
if (obj->mIdent)
|
||||||
|
@ -1728,15 +1731,18 @@ bool Linker::WriteMapFile(const char* filename)
|
||||||
{
|
{
|
||||||
const LinkerObject* obj = so[i];
|
const LinkerObject* obj = so[i];
|
||||||
|
|
||||||
if (banked)
|
if (obj->mRegion)
|
||||||
{
|
{
|
||||||
int k = 0;
|
if (banked)
|
||||||
while (k < 64 && !(obj->mRegion->mCartridgeBanks & (1ull << k)))
|
{
|
||||||
k++;
|
int k = 0;
|
||||||
if (k < 64)
|
while (k < 64 && !(obj->mRegion->mCartridgeBanks & (1ull << k)))
|
||||||
fprintf(file, "%02x:", k);
|
k++;
|
||||||
else
|
if (k < 64)
|
||||||
fprintf(file, "--:");
|
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);
|
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);
|
mByteCodeDisassembler.Disassemble(file, mMemory, -1, obj->mAddress, obj->mSize, obj->mProc, obj->mIdent, this);
|
||||||
break;
|
break;
|
||||||
case LOT_NATIVE_CODE:
|
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;
|
int i = 0;
|
||||||
while (!(obj->mRegion->mCartridgeBanks & (1ULL << i)))
|
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);
|
mNativeDisassembler.Disassemble(file, mMemory, -1, obj->mAddress, obj->mSize, obj->mProc, obj->mIdent, this, obj->mFullIdent);
|
||||||
break;
|
break;
|
||||||
case LOT_DATA:
|
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;
|
int i = 0;
|
||||||
while (!(obj->mRegion->mCartridgeBanks & (1ULL << i)))
|
while (!(obj->mRegion->mCartridgeBanks & (1ULL << i)))
|
||||||
|
|
|
@ -312,6 +312,10 @@ int main2(int argc, const char** argv)
|
||||||
compiler->mCompilerOptions |= COPT_CPLUSPLUS;
|
compiler->mCompilerOptions |= COPT_CPLUSPLUS;
|
||||||
compiler->AddDefine(Ident::Unique("__cplusplus"), "1");
|
compiler->AddDefine(Ident::Unique("__cplusplus"), "1");
|
||||||
}
|
}
|
||||||
|
else if (arg[1] == 'r' && arg[2] == 'm' && arg[3] == 'p')
|
||||||
|
{
|
||||||
|
compiler->mCompilerOptions |= COPT_ERROR_FILES;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
compiler->mErrors->Error(loc, EERR_COMMAND_LINE, "Invalid command line argument", arg);
|
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);
|
printf("Starting %s %s\n", strProductName, strProductVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compiler->WriteErrorFile(targetPath);
|
||||||
|
|
||||||
{
|
{
|
||||||
char dstring[100], tstring[100];
|
char dstring[100], tstring[100];
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
@ -579,6 +585,10 @@ int main2(int argc, const char** argv)
|
||||||
if (emulate)
|
if (emulate)
|
||||||
compiler->ExecuteCode(profile, trace);
|
compiler->ExecuteCode(profile, trace);
|
||||||
}
|
}
|
||||||
|
else if (compiler->mCompilerOptions & COPT_ERROR_FILES)
|
||||||
|
{
|
||||||
|
compiler->WriteErrorFile(targetPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compiler->mErrors->mErrorCount != 0)
|
if (compiler->mErrors->mErrorCount != 0)
|
||||||
|
|
Loading…
Reference in New Issue