aboutsummaryrefslogtreecommitdiff
path: root/backend/unittests/CodeGen/TargetFunctionStateTest.cpp
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-01 16:07:24 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-01 16:07:24 +0800
commit924dcd36ebed84f04729de05ec08b311a36a04c1 (patch)
tree300af742968d4d48915ef178855741f7087fc979 /backend/unittests/CodeGen/TargetFunctionStateTest.cpp
parentcfdbcc469f9691bd9dce3b0b86982a63d86ca6b7 (diff)
downloadrcc-project-924dcd36ebed84f04729de05ec08b311a36a04c1.tar.gz
rcc-project-924dcd36ebed84f04729de05ec08b311a36a04c1.tar.xz
[CodeGen] Add target register descriptions
Introduce an immutable register topology for units, subregisters, classes, banks, and preserved masks. Bind instruction descriptors to this topology through TargetDescription so builders, cloning, and verification share one target-aware contract. Add the test-only TestTarget model and positive and negative target fact coverage.
Diffstat (limited to 'backend/unittests/CodeGen/TargetFunctionStateTest.cpp')
-rw-r--r--backend/unittests/CodeGen/TargetFunctionStateTest.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/backend/unittests/CodeGen/TargetFunctionStateTest.cpp b/backend/unittests/CodeGen/TargetFunctionStateTest.cpp
index a306b8f..2286400 100644
--- a/backend/unittests/CodeGen/TargetFunctionStateTest.cpp
+++ b/backend/unittests/CodeGen/TargetFunctionStateTest.cpp
@@ -2,6 +2,7 @@
#include "rcc/CodeGen/TargetFunctionState.h"
+#include "Target/TestTarget.h"
#include "rcc/CodeGen/InstructionDescriptor.h"
#include "rcc/CodeGen/MachineFunction.h"
#include "rcc/CodeGen/MachineFunctionCloner.h"
@@ -146,14 +147,17 @@ struct CollidingFunctionInfo final {
const CollidingFunctionInfo &Right) = default;
};
-[[nodiscard]] rcc::Expected<rcc::InstructionSet> createInstructionSet() {
+[[nodiscard]] rcc::Expected<rcc::TargetDescription> createTarget() {
rcc::InstructionDescriptor Descriptor;
Descriptor.InstructionOpcode = rcc::Opcode::fromValue(1);
Descriptor.Name = "TEST_NOP";
Descriptor.Flags = {rcc::InstructionFlag::ProducesCode};
std::vector<rcc::InstructionDescriptor> Descriptors;
Descriptors.push_back(std::move(Descriptor));
- return rcc::InstructionSet::create(std::move(Descriptors));
+ auto Instructions = rcc::InstructionSet::create(std::move(Descriptors));
+ if (!Instructions)
+ return std::unexpected(Instructions.error());
+ return rcc::test::createTestTargetDescription(std::move(*Instructions));
}
void testTargetFunctionStateContract(TestContext &Context) {
@@ -212,10 +216,10 @@ void testTargetFunctionStateFailures(TestContext &Context) {
}
void testMachineFunctionOwnershipAndVerification(TestContext &Context) {
- auto InstructionSet = createInstructionSet();
+ auto Target = createTarget();
auto Function =
rcc::MachineFunction::create("target_state", rcc::MachineFunctionStableID::fromValue(1));
- if (!InstructionSet || !Function)
+ if (!Target || !Function)
return;
Context.expect(!(*Function)->setTargetState(rcc::TargetFunctionState{}),
@@ -225,7 +229,7 @@ void testMachineFunctionOwnershipAndVerification(TestContext &Context) {
"machine function must accept one verified target state");
Context.expect((*Function)->getTargetInfo<TestFunctionInfo>() != nullptr &&
(*Function)->getTargetInfo<CollidingFunctionInfo>() == nullptr &&
- rcc::MachineVerifier::verify(**Function, *InstructionSet).has_value(),
+ rcc::MachineVerifier::verify(**Function, *Target).has_value(),
"machine function must expose and verify its strong target state");
auto Replacement = rcc::TargetFunctionState::create(TestFunctionInfo{8192, true, "lp64d"});
@@ -236,7 +240,7 @@ void testMachineFunctionOwnershipAndVerification(TestContext &Context) {
if (Info == nullptr)
return;
Info->CallingConvention.clear();
- Context.expect(!rcc::MachineVerifier::verify(**Function, *InstructionSet),
+ Context.expect(!rcc::MachineVerifier::verify(**Function, *Target),
"machine verifier must reject invalid concrete target state");
}