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/MIR/EmbeddedIR.h | 39 +++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'backend/include/rcc/MIR/EmbeddedIR.h') diff --git a/backend/include/rcc/MIR/EmbeddedIR.h b/backend/include/rcc/MIR/EmbeddedIR.h index 8e9e0f6..50567de 100644 --- a/backend/include/rcc/MIR/EmbeddedIR.h +++ b/backend/include/rcc/MIR/EmbeddedIR.h @@ -24,6 +24,20 @@ struct EmbeddedIRReference final { TextRange Range; }; +struct EmbeddedIRMetadataDefinition final { + std::string Name; + TextRange Range; + std::string DynamicType; +}; + +struct EmbeddedIRTypeDefinition final { + std::string Name; + TextRange Range; + std::string Definition; + TextRange DefinitionRange; + bool NumericName = false; +}; + class EmbeddedIRFunction final { public: [[nodiscard]] std::string_view name() const noexcept { @@ -46,8 +60,13 @@ public: return Allocas; } + [[nodiscard]] std::span values() const noexcept { + return Values; + } + [[nodiscard]] const EmbeddedIRReference *block(std::string_view QueryName) const noexcept; [[nodiscard]] const EmbeddedIRReference *alloca(std::string_view QueryName) const noexcept; + [[nodiscard]] const EmbeddedIRReference *value(std::string_view QueryName) const noexcept; private: struct StringHash final { @@ -63,8 +82,10 @@ private: bool IsDefinition = false; std::vector Blocks; std::vector Allocas; + std::vector Values; std::unordered_map> BlockNameToIndex; std::unordered_map> AllocaNameToIndex; + std::unordered_map> ValueNameToIndex; friend class EmbeddedIRIndexer; }; @@ -101,13 +122,19 @@ public: return GlobalObjects; } - [[nodiscard]] std::span metadataDefinitions() const noexcept { + [[nodiscard]] std::span + metadataDefinitions() const noexcept { return MetadataDefinitions; } + [[nodiscard]] std::span typeDefinitions() const noexcept { + return TypeDefinitions; + } + [[nodiscard]] const EmbeddedIRFunction *function(std::string_view Name) const noexcept; [[nodiscard]] const EmbeddedIRReference *globalObject(std::string_view Name) const noexcept; - [[nodiscard]] const EmbeddedIRReference *metadata(std::string_view Name) const noexcept; + [[nodiscard]] const EmbeddedIRMetadataDefinition *metadata(std::string_view Name) const noexcept; + [[nodiscard]] const EmbeddedIRTypeDefinition *typeDefinition(std::string_view Name) const noexcept; [[nodiscard]] bool hasGlobalValue(std::string_view Name) const noexcept { return function(Name) != nullptr || globalObject(Name) != nullptr; } @@ -131,10 +158,12 @@ private: std::optional DataLayoutRange; std::vector Functions; std::vector GlobalObjects; - std::vector MetadataDefinitions; + std::vector MetadataDefinitions; + std::vector TypeDefinitions; std::unordered_map> FunctionNameToIndex; std::unordered_map> GlobalNameToIndex; std::unordered_map> MetadataNameToIndex; + std::unordered_map> TypeNameToIndex; friend class EmbeddedIRIndexer; }; @@ -159,6 +188,10 @@ public: return Diagnostics; } + [[nodiscard]] std::optional takeIndex() && { + return std::move(Index); + } + private: EmbeddedIRIndexResult() = default; -- cgit v1.2.3