Skip to content

Commit

Permalink
Add test for label node lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt committed Jul 2, 2024
1 parent 74bfe0a commit 0584df9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/src/tests/tests.program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,35 @@ namespace zasm::tests
}
}

TEST(ProgramTests, TestLabelNodeLookup)
{
Program program(MachineMode::AMD64);

x86::Assembler assembler(program);

auto label = assembler.createLabel();
ASSERT_EQ(assembler.mov(x86::eax, Imm(0)), ErrorCode::None);
ASSERT_EQ(assembler.mov(x86::eax, Imm(1)), ErrorCode::None);
ASSERT_EQ(assembler.mov(x86::eax, Imm(2)), ErrorCode::None);
ASSERT_EQ(assembler.bind(label), ErrorCode::None);
ASSERT_EQ(assembler.mov(x86::eax, Imm(3)), ErrorCode::None);

auto* labelNode = program.getNodeForLabel(label);
ASSERT_NE(labelNode, nullptr);

ASSERT_EQ(labelNode->holds<Label>(), true);
ASSERT_EQ(labelNode->get<Label>().getId(), label.getId());

auto* nextNode = labelNode->getNext();
ASSERT_NE(nextNode, nullptr);

ASSERT_EQ(nextNode->holds<Instruction>(), true);
const auto& instr = nextNode->get<Instruction>();

ASSERT_EQ(instr.isOperandType<Imm>(1), true);

const auto& imm = instr.getOperand<1, Imm>();
ASSERT_EQ(imm.value<int>(), 3);
}

} // namespace zasm::tests

0 comments on commit 0584df9

Please sign in to comment.