diff --git a/azm/BUILD b/azm/BUILD index 844bc944..93c1ecbd 100644 --- a/azm/BUILD +++ b/azm/BUILD @@ -3,13 +3,13 @@ load("//bzl:copts.bzl", "HASTUR_COPTS") cc_library( name = "azm", - hdrs = ["assembler.h"], + hdrs = glob(["**/*.h"]), copts = HASTUR_COPTS, visibility = ["//visibility:public"], ) [cc_test( - name = src[:-4], + name = src[:-4].replace("/", "_"), size = "small", srcs = [src], copts = HASTUR_COPTS, @@ -18,7 +18,7 @@ cc_library( "//etest", ], ) for src in glob( - include = ["*_test.cpp"], + include = ["**/*_test.cpp"], )] cc_binary( diff --git a/azm/assembler.h b/azm/amd64/assembler.h similarity index 92% rename from azm/assembler.h rename to azm/amd64/assembler.h index 9b1ad3e8..67a96de7 100644 --- a/azm/assembler.h +++ b/azm/amd64/assembler.h @@ -2,8 +2,8 @@ // // SPDX-License-Identifier: BSD-2-Clause -#ifndef AZM_ASSEMBLER_H_ -#define AZM_ASSEMBLER_H_ +#ifndef AZM_AMD64_ASSEMBLER_H_ +#define AZM_AMD64_ASSEMBLER_H_ #include #include @@ -11,7 +11,7 @@ #include #include -namespace azm { +namespace azm::amd64 { enum class Reg32 { Eax, @@ -39,7 +39,7 @@ constexpr std::optional register_index(Reg32 reg) { } // https://www.felixcloutier.com/x86/ -class Amd64Assembler { +class Assembler { public: [[nodiscard]] std::vector take_assembled() { return std::exchange(assembled_, {}); } @@ -78,6 +78,6 @@ class Amd64Assembler { std::vector assembled_; }; -} // namespace azm +} // namespace azm::amd64 #endif diff --git a/azm/assembler_test.cpp b/azm/amd64/assembler_test.cpp similarity index 89% rename from azm/assembler_test.cpp rename to azm/amd64/assembler_test.cpp index 1c149f75..f024292e 100644 --- a/azm/assembler_test.cpp +++ b/azm/amd64/assembler_test.cpp @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: BSD-2-Clause -#include "azm/assembler.h" +#include "azm/amd64/assembler.h" #include "etest/etest2.h" @@ -14,7 +14,7 @@ using CodeVec = std::vector; int main() { etest::Suite s{"assembler::amd64"}; - using namespace azm; + using namespace azm::amd64; s.add_test("Register index", [](etest::IActions &a) { a.expect_eq(register_index(Reg32::Eax), 0); @@ -25,14 +25,14 @@ int main() { }); s.add_test("ADD EAX, imm32", [](etest::IActions &a) { - Amd64Assembler assembler; + Assembler assembler; assembler.add(Reg32::Eax, Imm32{0x42}); a.expect_eq(assembler.take_assembled(), CodeVec{0x05, 0x42, 0, 0, 0}); }); s.add_test("ADD w/ unsupported dst is ud2", [](etest::IActions &a) { - Amd64Assembler assembler; + Assembler assembler; assembler.add(Reg32::Edx, Imm32{0x42}); auto unsupported_add_code = assembler.take_assembled(); @@ -42,7 +42,7 @@ int main() { }); s.add_test("MOV r32, imm32", [](etest::IActions &a) { - Amd64Assembler assembler; + Assembler assembler; assembler.mov(Reg32::Eax, Imm32{0xdeadbeef}); a.expect_eq(assembler.take_assembled(), CodeVec{0xb8, 0xef, 0xbe, 0xad, 0xde}); @@ -52,14 +52,14 @@ int main() { }); s.add_test("RET", [](etest::IActions &a) { - Amd64Assembler assembler; + Assembler assembler; assembler.ret(); a.expect_eq(assembler.take_assembled(), CodeVec{0xc3}); }); s.add_test("UD2", [](etest::IActions &a) { - Amd64Assembler assembler; + Assembler assembler; assembler.ud2(); a.expect_eq(assembler.take_assembled(), CodeVec{0x0f, 0x0b}); diff --git a/azm/azm_example.cpp b/azm/azm_example.cpp index 69d4eedf..5f55218e 100644 --- a/azm/azm_example.cpp +++ b/azm/azm_example.cpp @@ -2,15 +2,15 @@ // // SPDX-License-Identifier: BSD-2-Clause -#include "azm/assembler.h" +#include "azm/amd64/assembler.h" #include #include #include int main() { - using namespace azm; - Amd64Assembler assembler; + using namespace azm::amd64; + Assembler assembler; assembler.mov(Reg32::Eax, Imm32{3}); assembler.add(Reg32::Eax, Imm32{39}); assembler.mov(Reg32::Ecx, Imm32{0x4321});