From 76d89700953ddd81cf31ab8f260eddf67e93aa85 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Fri, 7 Aug 2026 01:27:41 +0800 Subject: [MIR] Complete document parsing and printing Implement the single LLVM-compatible MIR document path with structured\nembedded-IR references, YAML mappings, constants, and deterministic printing.\n\nKeep pointer LLT widths DataLayout-derived, reject layout-dependent output\nwhen embedded IR is omitted, and record the fixed-baseline compatibility\ncontract and regression coverage. --- backend/include/rcc/CodeGen/TargetMIRTextInfo.h | 63 +++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'backend/include/rcc/CodeGen/TargetMIRTextInfo.h') diff --git a/backend/include/rcc/CodeGen/TargetMIRTextInfo.h b/backend/include/rcc/CodeGen/TargetMIRTextInfo.h index 4fdbb3a..b8eb4ee 100644 --- a/backend/include/rcc/CodeGen/TargetMIRTextInfo.h +++ b/backend/include/rcc/CodeGen/TargetMIRTextInfo.h @@ -7,6 +7,8 @@ #include "rcc/CodeGen/MachineIRTypes.h" #include "rcc/CodeGen/Register.h" #include "rcc/CodeGen/RegisterMask.h" +#include "rcc/CodeGen/TargetConstant.h" +#include "rcc/CodeGen/TargetFunctionState.h" #include "rcc/Support/Error.h" #include @@ -24,6 +26,55 @@ namespace rcc { class TargetRegisterInfo; +enum class MIRTargetNodeKind : std::uint8_t { + Null, + Scalar, + Sequence, + Mapping, + Count, +}; + +struct MIRTargetMappingEntry; + +struct MIRTargetNode final { + MIRTargetNode(); + MIRTargetNode(const MIRTargetNode &); + MIRTargetNode &operator=(const MIRTargetNode &); + MIRTargetNode(MIRTargetNode &&) noexcept; + MIRTargetNode &operator=(MIRTargetNode &&) noexcept; + ~MIRTargetNode(); + + MIRTargetNodeKind Kind = MIRTargetNodeKind::Null; + std::string Scalar; + std::vector Sequence; + std::vector Mapping; + + [[nodiscard]] static MIRTargetNode null(); + [[nodiscard]] static MIRTargetNode scalar(std::string Value); + [[nodiscard]] static MIRTargetNode sequence(std::vector Values); + [[nodiscard]] static MIRTargetNode mapping(std::vector Entries); + + [[nodiscard]] const MIRTargetNode *mappingValue(std::string_view Key) const noexcept; + [[nodiscard]] Expected verify() const; + + friend bool operator==(const MIRTargetNode &Left, const MIRTargetNode &Right); +}; + +struct MIRTargetMappingEntry final { + std::string Key; + MIRTargetNode Value; + + friend bool operator==(const MIRTargetMappingEntry &Left, + const MIRTargetMappingEntry &Right) = default; +}; + +using MIRTargetFunctionStateParser = + Expected (*)(const MIRTargetNode &Node); +using MIRTargetFunctionStatePrinter = + Expected (*)(const TargetFunctionState &State); +using MIRTargetConstantParser = Expected (*)(std::string_view Text); +using MIRTargetConstantPrinter = Expected (*)(const TargetConstant &Constant); + struct MIRRegisterMaskDesc final { std::string Name; std::shared_ptr Mask; @@ -75,6 +126,10 @@ struct TargetMIRTextInfoDesc final { StackID::noAllocStack(), }; std::optional FunctionStateType; + MIRTargetFunctionStateParser ParseFunctionState = nullptr; + MIRTargetFunctionStatePrinter PrintFunctionState = nullptr; + MIRTargetConstantParser ParseTargetConstant = nullptr; + MIRTargetConstantPrinter PrintTargetConstant = nullptr; }; class TargetMIRTextInfo final { @@ -180,6 +235,14 @@ public: return Description.FunctionStateType; } + [[nodiscard]] Expected + parseFunctionState(const MIRTargetNode &Node) const; + [[nodiscard]] Expected + printFunctionState(const TargetFunctionState &State) const; + [[nodiscard]] Expected parseTargetConstant(std::string_view Text) const; + [[nodiscard]] Expected + printTargetConstant(const TargetConstant &Constant) const; + private: explicit TargetMIRTextInfo(TargetMIRTextInfoDesc Description) : Description(std::move(Description)) {} -- cgit v1.2.3