From 8558f80b4077536d6aa46b97328d6df1210e261f Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Thu, 13 Aug 2026 13:18:05 +0800 Subject: [Support] Centralize error context handling --- backend/lib/CodeGen/PrologueEpilogueInsertion.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'backend/lib/CodeGen/PrologueEpilogueInsertion.cpp') diff --git a/backend/lib/CodeGen/PrologueEpilogueInsertion.cpp b/backend/lib/CodeGen/PrologueEpilogueInsertion.cpp index c935d6a..d51a93b 100644 --- a/backend/lib/CodeGen/PrologueEpilogueInsertion.cpp +++ b/backend/lib/CodeGen/PrologueEpilogueInsertion.cpp @@ -3,11 +3,11 @@ #include "rcc/CodeGen/PrologueEpilogueInsertion.h" #include "rcc/CodeGen/FrameIndexElimination.h" +#include "rcc/CodeGen/LiveVariables.h" #include "rcc/CodeGen/MachineBasicBlock.h" #include "rcc/CodeGen/MachineFunction.h" #include "rcc/CodeGen/MachineFunctionCloner.h" #include "rcc/CodeGen/MachineInstr.h" -#include "rcc/CodeGen/LiveVariables.h" #include "rcc/CodeGen/MachineMemOperand.h" #include "rcc/CodeGen/MachineOperand.h" #include "rcc/CodeGen/MachineVerifier.h" @@ -19,14 +19,7 @@ #include namespace rcc { -namespace { - -[[nodiscard]] Error prefixedError(const Error &Source, std::string Prefix) { - Prefix.append(Source.message()); - return Error(Source.code(), std::move(Prefix)); -} - -} // namespace +namespace {} // namespace const MachinePassContract &PrologueEpilogueInsertionPass::contract() const noexcept { static const MachinePassContract Contract = [] { @@ -63,15 +56,16 @@ Expected PrologueEpilogueInsertionPass::run(MachineFunction & Function, Target, MachineFunctionCloneOptions{.NewStableID = Function.stableID(), .NewName = std::nullopt}); if (!Trial) - return std::unexpected(prefixedError(Trial.error(), "frame transaction setup failed: ")); + return std::unexpected(withErrorContext(Trial.error(), "frame transaction setup failed: ")); auto TrialRun = runImplementation(*Trial->ClonedFunction, Target); if (!TrialRun) - return std::unexpected(prefixedError(TrialRun.error(), "frame transaction rejected input: ")); + return std::unexpected( + withErrorContext(TrialRun.error(), "frame transaction rejected input: ")); auto Transition = Trial->ClonedFunction->properties().applyTransition( contract().Requires, contract().Sets, contract().Clears); if (!Transition) { return std::unexpected( - prefixedError(Transition.error(), "frame transaction property update failed: ")); + withErrorContext(Transition.error(), "frame transaction property update failed: ")); } auto Verified = MachineVerifier::verify(*Trial->ClonedFunction, Target, @@ -80,12 +74,12 @@ Expected PrologueEpilogueInsertionPass::run(MachineFunction & .VerifyProperties = true}); if (!Verified) { return std::unexpected( - prefixedError(Verified.error(), "frame transaction postcondition failed: ")); + withErrorContext(Verified.error(), "frame transaction postcondition failed: ")); } auto Result = runImplementation(Function, Target); if (!Result) { - return std::unexpected(prefixedError( + return std::unexpected(withErrorContext( Result.error(), "frame lowering diverged after successful transaction preflight: ")); } return Result; -- cgit v1.2.3