Added further output information to help debug

This commit is contained in:
DataHoarder 2021-01-05 12:21:11 +01:00
parent 22b72ede9f
commit 4b201a9a5e
2 changed files with 9 additions and 4 deletions

View file

@ -173,7 +173,7 @@ uint32_t Assembler::placeFunction(uint32_t base, const Function &function) {
auto instr = Instruction::Instruction::getCommandForDeclaration(d);
if (instr == nullptr) {
throw std::runtime_error("Unknown or invalid declaration");
throw std::runtime_error("Unknown or invalid declaration on function " + function.label);
}
instr->setAddress(offset);
@ -194,7 +194,7 @@ uint32_t Assembler::placeFunction(uint32_t base, const Function &function) {
if (labeledAddress.find(t.getTextValue()) != labeledAddress.end()) {
t.valueImmediate += labeledAddress.at(t.getTextValue());
} else {
throw std::runtime_error("Could not find local label " + t.getTextValue());
throw std::runtime_error("Could not find local label " + t.getTextValue() + " on function " + function.label);
}
} else if (entries.find(t.getTextValue()) != entries.end()) {
t.valueImmediate += entries.at(t.getTextValue()).first;
@ -208,7 +208,7 @@ uint32_t Assembler::placeFunction(uint32_t base, const Function &function) {
for (auto &d : declarations) {
auto instr = Instruction::Instruction::getCommandForDeclaration(d);
if (instr == nullptr) {
throw std::runtime_error("Unknown or invalid declaration");
throw std::runtime_error("Unknown or invalid declaration on function " + function.label);
}
if (!d.label.empty()) {
@ -222,7 +222,7 @@ uint32_t Assembler::placeFunction(uint32_t base, const Function &function) {
auto data = instr->toBytes();
if (offset + data.size() > bytes.size()) {
throw std::runtime_error("Instruction encoding exceeds image size");
throw std::runtime_error("Instruction encoding exceeds image size on function " + function.label);
}
std::copy(data.begin(), data.end(), bytes.begin() + offset);

View file

@ -43,6 +43,7 @@ int main(int argc, char *argv[]) {
for (int inputIndex = 1; inputIndex < (argc - 1); ++inputIndex) {
try {
std::cout << "Parsing file " << argv[inputIndex] << "\n";
std::ifstream image(argv[inputIndex]);
if (image.is_open()) {
std::vector<uint8_t> bytes;
@ -71,6 +72,8 @@ int main(int argc, char *argv[]) {
Assembler assembler(linker);
std::cout << "Assembly start\n";
Assembler::ImageConfig config;
config.header.baseAddress = linker.getIntegerConstant("rrcc_BASE_ADDRESS", 0x080000, false);
@ -86,6 +89,8 @@ int main(int argc, char *argv[]) {
assembler.assemble(entrypointName, config);
std::cout << "Assembly done\n";
std::ofstream patchedImage(argv[argc - 1]);
if (patchedImage.is_open()) {