summaryrefslogtreecommitdiffhomepage
path: root/CompilerDriver
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-05 09:21:23 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-05 09:30:47 +0100
commit45ba4c0aa0ec33e4aeafacf932c2498783e57591 (patch)
tree5f210110f5f671f0d851dd69a1d010dfd979bb60 /CompilerDriver
parent6b74d623cb97ef9e95def486d7e06fa0eb00ee81 (diff)
\isa: revision 1: remove jr and jal.
\masm: bug fix: add filter to prevent jlr, jrl, scall and sbreak from thowing an error. \masm: bug fix: jb with missing labels were valid, now it's not. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'CompilerDriver')
-rw-r--r--CompilerDriver/masm.cc30
1 files changed, 22 insertions, 8 deletions
diff --git a/CompilerDriver/masm.cc b/CompilerDriver/masm.cc
index f60c716..2d227e0 100644
--- a/CompilerDriver/masm.cc
+++ b/CompilerDriver/masm.cc
@@ -561,13 +561,17 @@ static std::string masm_check_line(std::string& line, const std::string& file)
}
}
- std::vector<std::string> opcodes_list = { "jb", "psh", "stw", "ldw", "lda", "sta" };
+ // these do take an argument.
+ std::vector<std::string> operands_inst = { "jb", "psh", "stw", "ldw", "lda", "sta" };
+
+ // these don't.
+ std::vector<std::string> filter_inst = { "jlr", "jrl", "scall", "sbreak" };
for (auto& opcode64x0 : kOpcodes64x0)
{
if (line.find(opcode64x0.fName) != std::string::npos)
{
- for (auto& op : opcodes_list)
+ for (auto& op : operands_inst)
{
// if only instruction found.
if (line == op)
@@ -580,12 +584,16 @@ static std::string masm_check_line(std::string& line, const std::string& file)
}
// if it is like that -> addr1, 0x0
- if (!isspace(line[line.find(opcode64x0.fName) + strlen(opcode64x0.fName)]))
+ if (auto it = std::find(filter_inst.begin(), filter_inst.end(), opcode64x0.fName);
+ it == filter_inst.cend())
{
- err_str += "\nmissing space between ";
- err_str += opcode64x0.fName;
- err_str += " and operands.\nhere -> ";
- err_str += line;
+ if (!isspace(line[line.find(opcode64x0.fName) + strlen(opcode64x0.fName)]))
+ {
+ err_str += "\nmissing space between ";
+ err_str += opcode64x0.fName;
+ err_str += " and operands.\nhere -> ";
+ err_str += line;
+ }
}
return err_str;
@@ -617,7 +625,7 @@ namespace detail
};
}
-static bool masm_write_number(std::size_t pos, std::string& jump_label)
+static bool masm_write_number(const std::size_t& pos, std::string& jump_label)
{
if (!isdigit(jump_label[pos]))
return false;
@@ -944,6 +952,12 @@ masm_write_label:
cpy_jump_label.erase(cpy_jump_label.find(' '), 1);
}
+ if (cpy_jump_label.size() < 1)
+ {
+ detail::print_error("label is empty, can't jump on it.", file);
+ throw std::runtime_error("label_empty");
+ }
+
auto mld_reloc_str = std::to_string(cpy_jump_label.size());
mld_reloc_str += kRelocSymbol;
mld_reloc_str += cpy_jump_label;