Enhanced debuggability of assembly and parsing errors
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2021-01-04 06:09:39 +01:00
parent a51287bcee
commit 1566c33d58
2 changed files with 21 additions and 13 deletions

View file

@ -35,6 +35,7 @@ void Parser::parse() {
std::string currentValue;
uint8_t c;
currentValue.reserve(16);
uint32_t lineNumber = 1;
std::vector<std::vector<std::pair<Token::Type, size_t>>> states = {
/* 0 */ {{Token::Type::Label, 1}, {Token::Type::Directive, 4}},
@ -180,7 +181,7 @@ void Parser::parse() {
if (!foundToken) {
//TODO: ERROR
throw std::runtime_error("Could not find new Token state");
throw std::runtime_error("Could not find new Token state, unexpected value = " + currentValue);
}
}
@ -212,6 +213,8 @@ void Parser::parse() {
if (c == '\0') {
functions.emplace_back(std::move(currentFunction));
break;
}else{
lineNumber++;
}
}
if (c == ';') {
@ -221,7 +224,7 @@ void Parser::parse() {
currentValue += c;
}
}catch (const std::exception& e){
std::cerr << "Exception: " << e.what() << " on " << currentFunction.label << "\n";
std::cerr << "Exception: " << e.what() << " on " << currentFunction.label << " (line# " << std::dec << lineNumber << ")\n";
throw e;
}
}

View file

@ -40,18 +40,23 @@ int main(int argc, char *argv[]) {
}
for (int inputIndex = 1; inputIndex < (argc - 1); ++inputIndex) {
std::ifstream image(argv[inputIndex]);
if (image.is_open()) {
std::vector<uint8_t> bytes;
int c;
while (!image.eof() && (c = image.get()) != EOF) {
bytes.push_back(c);
try {
std::ifstream image(argv[inputIndex]);
if (image.is_open()) {
std::vector<uint8_t> bytes;
int c;
while (!image.eof() && (c = image.get()) != EOF) {
bytes.push_back(c);
}
Parser parser(bytes, linker.getVariables());
parser.parse();
linker.addFromParser(parser);
} else {
throw std::runtime_error("Could not open " + std::string(argv[inputIndex]));
}
Parser parser(bytes, linker.getVariables());
parser.parse();
linker.addFromParser(parser);
} else {
throw std::runtime_error("Could not open " + std::string(argv[inputIndex]));
}catch (const std::exception& e){
std::cerr << "Exception: " << e.what() << " on input file " << argv[inputIndex] << "\n";
return 1;
}
}