Skip to content

Commit

Permalink
Remove redundant namespace use
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt committed May 12, 2024
1 parent 2fc133d commit 506dc4b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/tests/tests/tests.assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace zasm::tests

x86::Assembler assembler(program);

zasm::Label label01;
Label label01;
ASSERT_EQ(label01.isValid(), false);
ASSERT_EQ(assembler.bind(label01), ErrorCode::InvalidLabel);
}
Expand Down
4 changes: 2 additions & 2 deletions src/tests/tests/tests.instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ namespace zasm::tests

x86::Assembler assembler(program);

assembler.mov(x86::eax, zasm::Imm(2));
assembler.mov(x86::eax, Imm(2));

auto* instrNode = assembler.getCursor();

// Make copy.
Instruction instr = assembler.getCursor()->get<Instruction>();

// Modify operand.
instr.setOperand(1, zasm::Imm(1));
instr.setOperand(1, Imm(1));

// Emit modified
ASSERT_EQ(assembler.emit(instr), ErrorCode::None);
Expand Down
96 changes: 48 additions & 48 deletions src/tests/tests/tests.program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace zasm::tests
{
ASSERT_NE(node, nullptr);

const auto& instr = node->get<zasm::Instruction>();
const auto& instr = node->get<Instruction>();

const auto& imm = instr.getOperand<1, Imm>();
ASSERT_EQ(imm.value<int>(), i);
Expand Down Expand Up @@ -104,7 +104,7 @@ namespace zasm::tests
{
ASSERT_NE(node, nullptr);

const auto& instr = node->get<zasm::Instruction>();
const auto& instr = node->get<Instruction>();

const auto& imm = instr.getOperand<1, Imm>();
ASSERT_EQ(imm.value<int>(), i);
Expand Down Expand Up @@ -170,7 +170,7 @@ namespace zasm::tests
{
ASSERT_NE(node, nullptr);

const auto& instr = node->get<zasm::Instruction>();
const auto& instr = node->get<Instruction>();

const auto& imm = instr.getOperand<1, Imm>();
ASSERT_EQ(imm.value<int>(), NumberOrder[i]);
Expand Down Expand Up @@ -206,7 +206,7 @@ namespace zasm::tests
{
ASSERT_NE(node, nullptr);

const auto& instr = node->get<zasm::Instruction>();
const auto& instr = node->get<Instruction>();

const auto& imm = instr.getOperand<1, Imm>();
ASSERT_EQ(imm.value<int>(), NumberOrder[i]);
Expand All @@ -223,22 +223,22 @@ namespace zasm::tests

x86::Assembler assembler(program);

ASSERT_EQ(assembler.mov(x86::eax, x86::ebx), zasm::ErrorCode::None);
ASSERT_EQ(assembler.xor_(x86::ebx, x86::edx), zasm::ErrorCode::None);
ASSERT_EQ(assembler.add(x86::eax, Imm(1)), zasm::ErrorCode::None);
ASSERT_EQ(assembler.not_(x86::eax), zasm::ErrorCode::None);
ASSERT_EQ(assembler.xor_(x86::eax, Imm(1)), zasm::ErrorCode::None);
ASSERT_EQ(assembler.mov(x86::eax, x86::ebx), ErrorCode::None);
ASSERT_EQ(assembler.xor_(x86::ebx, x86::edx), ErrorCode::None);
ASSERT_EQ(assembler.add(x86::eax, Imm(1)), ErrorCode::None);
ASSERT_EQ(assembler.not_(x86::eax), ErrorCode::None);
ASSERT_EQ(assembler.xor_(x86::eax, Imm(1)), ErrorCode::None);

auto labelFoo = assembler.createLabel("foo");
ASSERT_EQ(labelFoo.getId(), zasm::Label::Id{ 0 });
ASSERT_EQ(labelFoo.getId(), Label::Id{ 0 });
ASSERT_EQ(labelFoo.isValid(), true);
ASSERT_EQ(assembler.bind(labelFoo), zasm::ErrorCode::None);
ASSERT_EQ(assembler.mov(x86::dword_ptr(x86::rip, labelFoo), x86::eax), zasm::ErrorCode::None);
ASSERT_EQ(assembler.bind(labelFoo), ErrorCode::None);
ASSERT_EQ(assembler.mov(x86::dword_ptr(x86::rip, labelFoo), x86::eax), ErrorCode::None);

ASSERT_EQ(program.size(), 7);

Serializer serializer;
ASSERT_EQ(serializer.serialize(program, 0x400000), zasm::ErrorCode::None);
ASSERT_EQ(serializer.serialize(program, 0x400000), ErrorCode::None);

const std::array<uint8_t, 18> expected = {
0x89, 0xd8, 0x31, 0xd3, 0x83, 0xc0, 0x01, 0xf7, 0xd0, 0x83, 0xf0, 0x01, 0x89, 0x05, 0xfa, 0xff, 0xff, 0xff,
Expand Down Expand Up @@ -269,41 +269,41 @@ namespace zasm::tests
{
x86::Assembler assembler(program);

ASSERT_EQ(assembler.push(x86::rax), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::rcx), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::rdx), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::rbx), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::rbp), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::rsi), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::rdi), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r8), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r9), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r10), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r11), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r12), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r13), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r14), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r15), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pushfq(), zasm::ErrorCode::None);

ASSERT_EQ(assembler.popfq(), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r15), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r14), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r13), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r12), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r11), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r10), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r9), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r8), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::rdi), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::rsi), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::rbp), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::rbx), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::rdx), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::rcx), zasm::ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::rax), zasm::ErrorCode::None);

ASSERT_EQ(serializer.serialize(program, address), zasm::ErrorCode::None);
ASSERT_EQ(assembler.push(x86::rax), ErrorCode::None);
ASSERT_EQ(assembler.push(x86::rcx), ErrorCode::None);
ASSERT_EQ(assembler.push(x86::rdx), ErrorCode::None);
ASSERT_EQ(assembler.push(x86::rbx), ErrorCode::None);
ASSERT_EQ(assembler.push(x86::rbp), ErrorCode::None);
ASSERT_EQ(assembler.push(x86::rsi), ErrorCode::None);
ASSERT_EQ(assembler.push(x86::rdi), ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r8), ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r9), ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r10), ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r11), ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r12), ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r13), ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r14), ErrorCode::None);
ASSERT_EQ(assembler.push(x86::r15), ErrorCode::None);
ASSERT_EQ(assembler.pushfq(), ErrorCode::None);

ASSERT_EQ(assembler.popfq(), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r15), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r14), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r13), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r12), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r11), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r10), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r9), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::r8), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::rdi), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::rsi), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::rbp), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::rbx), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::rdx), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::rcx), ErrorCode::None);
ASSERT_EQ(assembler.pop(x86::rax), ErrorCode::None);

ASSERT_EQ(serializer.serialize(program, address), ErrorCode::None);
address += 0x10;

ASSERT_NE(serializer.getCodeSize(), 0);
Expand Down
18 changes: 9 additions & 9 deletions src/tests/tests/tests.serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,12 +1040,12 @@ namespace zasm::tests

TEST(SerializationTests, SerializeDecodedSwapNodes)
{
zasm::Program program(zasm::MachineMode::I386);
std::vector<zasm::Node*> tails = {};
Program program(MachineMode::I386);
std::vector<Node*> tails = {};

{
zasm::x86::Assembler a(program);
zasm::Decoder decoder(zasm::MachineMode::I386);
x86::Assembler a(program);
Decoder decoder(MachineMode::I386);

const std::array<uint8_t, 12> raw_data = {
0xB8, 0x00, 0x10, 0x40, 0x00, // mov eax, [blabla]
Expand All @@ -1071,15 +1071,15 @@ namespace zasm::tests
auto bind_node = program.bindLabel(label);
program.moveBefore(tails[4], *bind_node);

tails[3]->getIf<zasm::Instruction>()->setOperand(0, label);
tails[3]->getIf<Instruction>()->setOperand(0, label);

zasm::x86::Assembler a(program);
x86::Assembler a(program);
a.setCursor(tails[4]);
a.xor_(zasm::x86::eax, zasm::x86::eax);
a.xor_(x86::eax, x86::eax);

zasm::Serializer serializer{};
Serializer serializer{};
auto r = serializer.serialize(program, 0x406000);
ASSERT_EQ(r, zasm::ErrorCode::None);
ASSERT_EQ(r, ErrorCode::None);

const std::array<std::uint8_t, 14> expected = { 0xB8, 0x00, 0x10, 0x40, 0x00, 0x83, 0xF8,
0x00, 0x90, 0xEB, 0x00, 0xC3, 0x31, 0xC0 };
Expand Down

0 comments on commit 506dc4b

Please sign in to comment.