1
0
mirror of https://github.com/pfusik/xasm.git synced 2024-06-07 11:29:32 +00:00

If cannot open the file to be included, report error in the ICL line.

This commit is contained in:
Piotr Fusik 2014-02-21 23:06:03 +01:00
parent 059b631aab
commit 520145268a

64
xasm.d
View File

@ -49,21 +49,12 @@ bool optionHeaders; // opt h
bool optionListing; // opt l bool optionListing; // opt l
bool optionObject; // opt o bool optionObject; // opt o
string currentFilename;
int lineNo;
int includeLevel = 0;
string line; string line;
int column; int column;
class Location {
string filename;
int lineNo = 0;
this(string filename) {
this.filename = filename;
}
}
Location[] locations;
Location currentLocation;
bool foundEnd; bool foundEnd;
class AssemblyError : Exception { class AssemblyError : Exception {
@ -183,7 +174,7 @@ void warning(string msg, bool error = false) {
} }
if (line !is null) if (line !is null)
stderr.writeln(line); stderr.writeln(line);
stderr.writefln("%s (%d) %s: %s", currentLocation.filename, currentLocation.lineNo, error ? "ERROR" : "WARNING", msg); stderr.writefln("%s (%d) %s: %s", currentFilename, lineNo, error ? "ERROR" : "WARNING", msg);
exitCode = 1; exitCode = 1;
} }
@ -1117,15 +1108,15 @@ void listLine() {
assert(pass2); assert(pass2);
if (inFalseCondition() && !getOption('c')) if (inFalseCondition() && !getOption('c'))
return; return;
if (getOption('i') && locations.length > 0) if (getOption('i') && includeLevel > 0)
return; return;
ensureListingFileOpen('l', "Writing listing file...\n"); ensureListingFileOpen('l', "Writing listing file...\n");
if (currentLocation.filename != lastListedFilename) { if (currentFilename != lastListedFilename) {
listingStream.writeln("Source: ", currentLocation.filename); listingStream.writeln("Source: ", currentFilename);
lastListedFilename = currentLocation.filename; lastListedFilename = currentFilename;
} }
int i = 4; int i = 4;
int x = currentLocation.lineNo; int x = lineNo;
while (x > 0 && i >= 0) { while (x > 0 && i >= 0) {
listingLine[i--] = '0' + x % 10; listingLine[i--] = '0' + x % 10;
x /= 10; x /= 10;
@ -2260,7 +2251,9 @@ void assemblyIcl() {
string filename = readFilename(); string filename = readFilename();
checkNoExtraCharacters(); checkNoExtraCharacters();
listLine(); listLine();
includeLevel++;
assemblyFile(filename); assemblyFile(filename);
includeLevel--;
line = null; line = null;
} }
@ -2671,7 +2664,7 @@ void assemblyLine() {
debug { debug {
writeln(line); writeln(line);
} }
currentLocation.lineNo++; lineNo++;
totalLines++; totalLines++;
column = 0; column = 0;
listingColumn = 6; listingColumn = 6;
@ -2782,14 +2775,15 @@ void assemblyLine() {
void assemblyFile(string filename) { void assemblyFile(string filename) {
filename = filename.defaultExtension("asx"); filename = filename.defaultExtension("asx");
if (currentLocation !is null)
locations ~= currentLocation;
if (getOption('p')) if (getOption('p'))
filename = absolutePath(filename); filename = absolutePath(filename);
currentLocation = new Location(filename);
foundEnd = false;
File stream = openInputFile(filename); File stream = openInputFile(filename);
scope (exit) stream.close(); scope (exit) stream.close();
string oldFilename = currentFilename;
int oldLineNo = lineNo;
currentFilename = filename;
lineNo = 0;
foundEnd = false;
line = ""; line = "";
readChar: while (!foundEnd) { readChar: while (!foundEnd) {
ubyte[1] buffer; ubyte[1] buffer;
@ -2817,10 +2811,8 @@ void assemblyFile(string filename) {
if (!foundEnd) if (!foundEnd)
assemblyLine(); assemblyLine();
foundEnd = false; foundEnd = false;
if (locations.length > 0) { currentFilename = oldFilename;
currentLocation = locations[$ - 1]; lineNo = oldLineNo;
locations.length--;
}
} }
void assemblyPass() { void assemblyPass() {
@ -2837,17 +2829,15 @@ void assemblyPass() {
skipping = false; skipping = false;
repeatOffset = 0; repeatOffset = 0;
wereManyInstructions = false; wereManyInstructions = false;
if (commandLineDefinitions.length > 0) { currentFilename = "command line";
currentLocation = new Location("command line"); lineNo = 0;
foreach (definition; commandLineDefinitions) { foreach (definition; commandLineDefinitions) {
immutable i = indexOf(definition, '='); immutable i = indexOf(definition, '=');
assert(i >= 0); assert(i >= 0);
line = definition[0 .. i] ~ " equ " ~ definition[i + 1 .. $]; line = definition[0 .. i] ~ " equ " ~ definition[i + 1 .. $];
assemblyLine(); assemblyLine();
}
line = null;
} }
currentLocation = null; line = null;
totalLines = 0; totalLines = 0;
assemblyFile(sourceFilename); assemblyFile(sourceFilename);
if (ifContexts.length != 0) if (ifContexts.length != 0)