From 183e2354e9fdd107be420cbb185c1d239434aa48 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Tue, 4 Aug 2026 05:34:15 +0800 Subject: [MIR] Add machine instruction parser and printer Parse MachineFunction bodies in two passes and serialize the same MachineIR model in complete or readable form. Extend instruction attachments and memory operands required by the fixed LLVM MIR grammar, and cover deterministic parse-print round trips. --- backend/include/rcc/CodeGen/MachineInstr.h | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'backend/include/rcc/CodeGen/MachineInstr.h') diff --git a/backend/include/rcc/CodeGen/MachineInstr.h b/backend/include/rcc/CodeGen/MachineInstr.h index 69d7dd7..e7294b4 100644 --- a/backend/include/rcc/CodeGen/MachineInstr.h +++ b/backend/include/rcc/CodeGen/MachineInstr.h @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include @@ -154,6 +156,56 @@ public: DebugInstrNumber = 0; } + [[nodiscard]] std::optional preInstrSymbol() const noexcept; + [[nodiscard]] Expected setPreInstrSymbol(std::string Symbol); + void clearPreInstrSymbol() noexcept { + PreInstrSymbol.reset(); + } + + [[nodiscard]] std::optional postInstrSymbol() const noexcept; + [[nodiscard]] Expected setPostInstrSymbol(std::string Symbol); + void clearPostInstrSymbol() noexcept { + PostInstrSymbol.reset(); + } + + [[nodiscard]] const std::optional &heapAllocMarker() const noexcept { + return HeapAllocMarker; + } + [[nodiscard]] Expected setHeapAllocMarker(MachineMetadataReference Marker); + void clearHeapAllocMarker() noexcept { + HeapAllocMarker.reset(); + } + + [[nodiscard]] const std::optional &pcSections() const noexcept { + return PCSections; + } + [[nodiscard]] Expected setPCSections(MachineMetadataReference Sections); + void clearPCSections() noexcept { + PCSections.reset(); + } + + [[nodiscard]] const std::optional &mmra() const noexcept { + return MMRA; + } + [[nodiscard]] Expected setMMRA(MachineMetadataReference Metadata); + void clearMMRA() noexcept { + MMRA.reset(); + } + + [[nodiscard]] std::optional cfiType() const noexcept { + return CFIType; + } + [[nodiscard]] Expected setCFIType(std::uint64_t Type); + void clearCFIType() noexcept { + CFIType.reset(); + } + + [[nodiscard]] std::optional deactivationSymbol() const noexcept; + [[nodiscard]] Expected setDeactivationSymbol(std::string Symbol); + void clearDeactivationSymbol() noexcept { + DeactivationSymbol.reset(); + } + private: MachineInstr(MachineFunction &OwnerFunction, Opcode InstructionOpcode, MachineInstrStableID StableID); @@ -177,6 +229,13 @@ private: std::optional DebugLocation; std::optional Origin; std::uint32_t DebugInstrNumber = 0; + std::optional PreInstrSymbol; + std::optional PostInstrSymbol; + std::optional HeapAllocMarker; + std::optional PCSections; + std::optional MMRA; + std::optional CFIType; + std::optional DeactivationSymbol; friend class MachineArena; friend class MachineBasicBlock; -- cgit v1.2.3