mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-28 01:49:33 -06:00
Add numeric label support to assembler
This commit is contained in:
@ -2029,7 +2029,7 @@ TEST(Assembler, RangeTest)
|
||||
EXPECT_TRUE(!IsFailure(Assemble(uimm_range_3, 0)));
|
||||
}
|
||||
|
||||
TEST(Assembly, MalformedExpressions)
|
||||
TEST(Assembler, MalformedExpressions)
|
||||
{
|
||||
constexpr char missing_arg[] = "add 0, 1";
|
||||
constexpr char missing_paren_0[] = ".4byte (1 + 2), ((3 * 6) + 7";
|
||||
@ -2065,7 +2065,7 @@ TEST(Assembly, MalformedExpressions)
|
||||
|
||||
// Modified listing of a subroutine, listing generated by IDA
|
||||
// Expect bytes are based on disc contents
|
||||
TEST(Assembly, RealAssembly)
|
||||
TEST(Assembler, RealAssembly)
|
||||
{
|
||||
constexpr char real_assembly[] = ".locate 0x8046A690\n"
|
||||
".defvar back_chain, -0x30\n"
|
||||
@ -2223,3 +2223,44 @@ TEST(Assembly, RealAssembly)
|
||||
EXPECT_EQ(code_blocks[0].instructions[i], real_expect[i]) << " -> i=" << i;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Assembler, NumericLabels)
|
||||
{
|
||||
constexpr char assembly[] = "0:b 0b\nb 0f\n0:.4byte 0\n0:\n1:.4byte 1b";
|
||||
constexpr u8 expect[] = {0x48, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x04,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c};
|
||||
|
||||
auto res = Assemble(assembly, 0);
|
||||
ASSERT_TRUE(!IsFailure(res));
|
||||
auto&& code_blocks = GetT(res);
|
||||
ASSERT_EQ(code_blocks.size(), 1);
|
||||
|
||||
ASSERT_EQ(code_blocks[0].instructions.size(), sizeof(expect));
|
||||
for (size_t i = 0; i < code_blocks[0].instructions.size(); i++)
|
||||
{
|
||||
EXPECT_EQ(code_blocks[0].instructions[i], expect[i]) << " -> i=" << i;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Assembler, InvalidNumericLabels)
|
||||
{
|
||||
constexpr char missing_forward[] = "0:b 0f";
|
||||
constexpr char missing_backward[] = "b 0b\n0:";
|
||||
constexpr char forward_directive[] = ".4byte 0f\n0:";
|
||||
constexpr char missing_backward_directive[] = ".4byte 0b\n0:";
|
||||
|
||||
auto res = Assemble(missing_forward, 0);
|
||||
EXPECT_TRUE(IsFailure(res) && GetFailure(res).message == "No numeric label '0' found below here")
|
||||
<< GetFailure(res).message;
|
||||
res = Assemble(missing_backward, 0);
|
||||
EXPECT_TRUE(IsFailure(res) && GetFailure(res).message == "No numeric label '0' found above here")
|
||||
<< GetFailure(res).message;
|
||||
res = Assemble(forward_directive, 0);
|
||||
EXPECT_TRUE(IsFailure(res) &&
|
||||
GetFailure(res).message ==
|
||||
"Forward label references not supported in fully resolved expressons")
|
||||
<< GetFailure(res).message;
|
||||
res = Assemble(missing_backward_directive, 0);
|
||||
EXPECT_TRUE(IsFailure(res) && GetFailure(res).message == "No numeric label '0' found above here")
|
||||
<< GetFailure(res).message;
|
||||
}
|
||||
|
Reference in New Issue
Block a user