aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/MIR
diff options
context:
space:
mode:
Diffstat (limited to 'backend/include/rcc/MIR')
-rw-r--r--backend/include/rcc/MIR/MIDebugSyntax.h26
-rw-r--r--backend/include/rcc/MIR/MILexer.h181
-rw-r--r--backend/include/rcc/MIR/MIParser.h107
-rw-r--r--backend/include/rcc/MIR/MIPrinter.h35
-rw-r--r--backend/include/rcc/MIR/MIRDocument.h141
5 files changed, 0 insertions, 490 deletions
diff --git a/backend/include/rcc/MIR/MIDebugSyntax.h b/backend/include/rcc/MIR/MIDebugSyntax.h
deleted file mode 100644
index 4952128..0000000
--- a/backend/include/rcc/MIR/MIDebugSyntax.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#ifndef RCC_MIR_MIDEBUGSYNTAX_H
-#define RCC_MIR_MIDEBUGSYNTAX_H
-
-#include <cstdint>
-#include <optional>
-#include <span>
-#include <string>
-#include <string_view>
-
-namespace rcc::mir {
-
-[[nodiscard]] std::optional<std::uint64_t>
-parseDIExpressionOpcodeName(std::string_view Name) noexcept;
-
-[[nodiscard]] std::optional<std::uint64_t>
-parseDIExpressionAttributeEncodingName(std::string_view Name) noexcept;
-
-[[nodiscard]] std::string invalidDIExpressionElementMessage(std::string_view Name);
-
-[[nodiscard]] std::string formatDIExpression(std::span<const std::uint64_t> Elements);
-
-} // namespace rcc::mir
-
-#endif // RCC_MIR_MIDEBUGSYNTAX_H
diff --git a/backend/include/rcc/MIR/MILexer.h b/backend/include/rcc/MIR/MILexer.h
deleted file mode 100644
index f54f255..0000000
--- a/backend/include/rcc/MIR/MILexer.h
+++ /dev/null
@@ -1,181 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#ifndef RCC_MIR_MILEXER_H
-#define RCC_MIR_MILEXER_H
-
-#include "rcc/Support/TextDiagnostic.h"
-
-#include <cstddef>
-#include <cstdint>
-#include <memory>
-#include <span>
-#include <string>
-#include <string_view>
-#include <utility>
-#include <variant>
-
-namespace rcc::mir {
-
-enum class MITokenKind : std::uint8_t {
- EndOfFile,
- Error,
- Newline,
-
- Comma,
- Equal,
- Underscore,
- Colon,
- DoubleColon,
- Dot,
- Exclaim,
- LeftParen,
- RightParen,
- LeftBrace,
- RightBrace,
- Plus,
- Minus,
- Less,
- Greater,
-
- Keyword,
- MetadataKeyword,
- Identifier,
- NamedRegister,
- NamedVirtualRegister,
- MachineBasicBlockLabel,
- MachineBasicBlock,
- StackObject,
- FixedStackObject,
- NamedGlobalValue,
- GlobalValue,
- ExternalSymbol,
- MCSymbol,
- IntegerLiteral,
- FloatingPointLiteral,
- HexLiteral,
- VirtualRegister,
- ConstantPoolItem,
- JumpTableIndex,
- NamedIRBlock,
- IRBlock,
- NamedIRValue,
- IRValue,
- QuotedIRValue,
- SubRegisterIndex,
- StringConstant,
-};
-
-[[nodiscard]] std::string_view getMITokenKindName(MITokenKind Kind) noexcept;
-[[nodiscard]] bool isMIKeyword(std::string_view Spelling) noexcept;
-[[nodiscard]] bool isMIMetadataKeyword(std::string_view Spelling) noexcept;
-
-class MIToken final {
-public:
- [[nodiscard]] MITokenKind kind() const noexcept {
- return Kind;
- }
-
- [[nodiscard]] const TextRange &range() const noexcept {
- return Range;
- }
-
- [[nodiscard]] std::string_view spelling() const noexcept {
- return Spelling;
- }
-
- [[nodiscard]] bool hasStringValue() const noexcept {
- return !std::holds_alternative<std::monostate>(StringValue);
- }
-
- [[nodiscard]] std::string_view stringValue() const noexcept;
-
- [[nodiscard]] bool hasIntegerValue() const noexcept {
- return !IntegerValue.empty();
- }
-
- [[nodiscard]] std::string_view integerValue() const noexcept {
- return IntegerValue;
- }
-
- [[nodiscard]] bool is(MITokenKind Expected) const noexcept {
- return Kind == Expected;
- }
-
- [[nodiscard]] bool isKeyword(std::string_view Expected) const noexcept {
- return Kind == MITokenKind::Keyword && stringValue() == Expected;
- }
-
- [[nodiscard]] bool isMetadataKeyword(std::string_view Expected) const noexcept {
- return Kind == MITokenKind::MetadataKeyword && stringValue() == Expected;
- }
-
- [[nodiscard]] bool isNewlineOrEnd() const noexcept {
- return Kind == MITokenKind::Newline || Kind == MITokenKind::EndOfFile;
- }
-
- [[nodiscard]] bool isErrorOrEnd() const noexcept {
- return Kind == MITokenKind::Error || Kind == MITokenKind::EndOfFile;
- }
-
- [[nodiscard]] bool isRegister() const noexcept;
- [[nodiscard]] bool isRegisterFlag() const noexcept;
- [[nodiscard]] bool isMemoryOperandFlag() const noexcept;
-
-private:
- using StringValueStorage = std::variant<std::monostate, std::string_view, std::string>;
-
- MIToken(MITokenKind Kind, TextRange Range, std::string_view Spelling,
- StringValueStorage StringValue = {}, std::string_view IntegerValue = {})
- : Kind(Kind), Range(Range), Spelling(Spelling), StringValue(std::move(StringValue)),
- IntegerValue(IntegerValue) {}
-
- MITokenKind Kind = MITokenKind::Error;
- TextRange Range;
- std::string_view Spelling;
- StringValueStorage StringValue;
- std::string_view IntegerValue;
-
- friend class MILexer;
-};
-
-struct MILexerOptions final {
- std::size_t MaximumTokenLength = std::size_t{1} << 24U;
- std::size_t MaximumTokens = std::size_t{1} << 24U;
-};
-
-class MILexer final {
-public:
- MILexer(std::string SourceName, std::string SourceText, MILexerOptions Options = {});
- MILexer(const MILexer &) = delete;
- MILexer &operator=(const MILexer &) = delete;
- MILexer(MILexer &&) noexcept;
- MILexer &operator=(MILexer &&) noexcept;
- ~MILexer();
-
- [[nodiscard]] MIToken next();
-
- [[nodiscard]] const TextSource &source() const noexcept;
- [[nodiscard]] std::span<const TextDiagnostic> diagnostics() const noexcept;
- [[nodiscard]] bool failed() const noexcept;
- [[nodiscard]] std::size_t tokenCount() const noexcept;
-
-private:
- [[nodiscard]] static MIToken makeToken(MITokenKind Kind, TextRange Range,
- std::string_view Spelling,
- std::string_view IntegerValue = {});
- [[nodiscard]] static MIToken makeStringToken(MITokenKind Kind, TextRange Range,
- std::string_view Spelling,
- std::string_view StringValue,
- std::string_view IntegerValue = {});
- [[nodiscard]] static MIToken makeOwnedStringToken(MITokenKind Kind, TextRange Range,
- std::string_view Spelling,
- std::string StringValue,
- std::string_view IntegerValue = {});
-
- class Impl;
- std::unique_ptr<Impl> Implementation;
-};
-
-} // namespace rcc::mir
-
-#endif // RCC_MIR_MILEXER_H
diff --git a/backend/include/rcc/MIR/MIParser.h b/backend/include/rcc/MIR/MIParser.h
deleted file mode 100644
index b660f47..0000000
--- a/backend/include/rcc/MIR/MIParser.h
+++ /dev/null
@@ -1,107 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#ifndef RCC_MIR_MIPARSER_H
-#define RCC_MIR_MIPARSER_H
-
-#include "rcc/CodeGen/MachineIRTypes.h"
-#include "rcc/CodeGen/MachineMetadata.h"
-#include "rcc/CodeGen/Register.h"
-#include "rcc/Support/Error.h"
-#include "rcc/Support/TextDiagnostic.h"
-
-#include <cstddef>
-#include <cstdint>
-#include <functional>
-#include <memory>
-#include <optional>
-#include <span>
-#include <string>
-#include <string_view>
-#include <vector>
-
-namespace rcc {
-
-class MachineFunction;
-class TargetDescription;
-
-namespace mir {
-
-struct MIVirtualRegisterSlot final {
- std::uint32_t TextID = 0;
- Register Reg;
-};
-
-struct MIFrameObjectSlot final {
- std::uint32_t TextID = 0;
- FrameIndex Index;
- std::optional<std::string> Name;
-};
-
-struct MIConstantPoolSlot final {
- std::uint32_t TextID = 0;
- ConstantPoolIndex Index;
-};
-
-struct MIJumpTableSlot final {
- std::uint32_t TextID = 0;
- JumpTableIndex Index;
-};
-
-struct MIMetadataSlot final {
- std::uint32_t TextID = 0;
- MachineMetadataReference Reference;
-};
-
-struct MISyncScopeSlot final {
- std::string Name;
- SyncScopeID ID;
-};
-
-struct MIParserContext final {
- std::vector<MIVirtualRegisterSlot> VirtualRegisters;
- std::vector<MIFrameObjectSlot> StackObjects;
- std::vector<MIFrameObjectSlot> FixedStackObjects;
- std::vector<MIConstantPoolSlot> ConstantPoolItems;
- std::vector<MIJumpTableSlot> JumpTables;
- std::vector<MIMetadataSlot> Metadata;
- std::vector<MISyncScopeSlot> SyncScopes;
- std::function<bool(std::string_view)> HasIRBlock;
- std::function<Expected<SyncScopeID>(std::string_view)> InternSyncScope;
- std::function<Expected<std::uint32_t>(std::uint32_t)> PointerSizeInBits;
-};
-
-struct MIParserOptions final {
- std::size_t MaximumTokens = std::size_t{1} << 24U;
- std::size_t MaximumTokenLength = std::size_t{1} << 24U;
- std::size_t MaximumBlocks = std::size_t{1} << 20U;
- std::size_t MaximumInstructions = std::size_t{1} << 24U;
- std::size_t MaximumOperandsPerInstruction = std::size_t{1} << 20U;
- std::size_t MaximumMemoryOperandsPerInstruction = std::size_t{1} << 20U;
- bool VerifyAfterParse = true;
-};
-
-class MIParser final {
-public:
- MIParser(MachineFunction &Function, const TargetDescription &Target, std::string SourceName,
- std::string SourceText, MIParserContext Context = {}, MIParserOptions Options = {});
- MIParser(const MIParser &) = delete;
- MIParser &operator=(const MIParser &) = delete;
- MIParser(MIParser &&) noexcept;
- MIParser &operator=(MIParser &&) noexcept;
- ~MIParser();
-
- [[nodiscard]] Expected<void> parse();
-
- [[nodiscard]] const TextSource &source() const noexcept;
- [[nodiscard]] std::span<const TextDiagnostic> diagnostics() const noexcept;
- [[nodiscard]] bool failed() const noexcept;
-
-private:
- class Impl;
- std::unique_ptr<Impl> Implementation;
-};
-
-} // namespace mir
-} // namespace rcc
-
-#endif // RCC_MIR_MIPARSER_H
diff --git a/backend/include/rcc/MIR/MIPrinter.h b/backend/include/rcc/MIR/MIPrinter.h
deleted file mode 100644
index 663859e..0000000
--- a/backend/include/rcc/MIR/MIPrinter.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#ifndef RCC_MIR_MIPRINTER_H
-#define RCC_MIR_MIPRINTER_H
-
-#include "rcc/MIR/MIParser.h"
-#include "rcc/Support/Error.h"
-
-#include <string>
-
-namespace rcc {
-
-class MachineFunction;
-class TargetDescription;
-
-namespace mir {
-
-enum class MIPrintMode : unsigned char {
- Complete,
- Readable,
-};
-
-struct MIPrinterOptions final {
- MIPrintMode Mode = MIPrintMode::Complete;
-};
-
-[[nodiscard]] Expected<std::string> printMachineFunctionBody(const MachineFunction &Function,
- const TargetDescription &Target,
- const MIParserContext &Context = {},
- MIPrinterOptions Options = {});
-
-} // namespace mir
-} // namespace rcc
-
-#endif // RCC_MIR_MIPRINTER_H
diff --git a/backend/include/rcc/MIR/MIRDocument.h b/backend/include/rcc/MIR/MIRDocument.h
deleted file mode 100644
index 6041657..0000000
--- a/backend/include/rcc/MIR/MIRDocument.h
+++ /dev/null
@@ -1,141 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#ifndef RCC_MIR_MIRDOCUMENT_H
-#define RCC_MIR_MIRDOCUMENT_H
-
-#include "rcc/CodeGen/CompilationUnit.h"
-#include "rcc/CodeGen/StableID.h"
-#include "rcc/MIR/EmbeddedIR.h"
-#include "rcc/MIR/MIParser.h"
-#include "rcc/MIR/MIPrinter.h"
-#include "rcc/Support/TextDiagnostic.h"
-#include "rcc/Support/YAML.h"
-
-#include <cstdint>
-#include <optional>
-#include <span>
-#include <string>
-#include <utility>
-#include <vector>
-
-namespace rcc {
-
-class TargetDescription;
-
-namespace mir {
-
-struct MIRFunctionDocumentInfo final {
- MachineFunctionStableID Function;
- std::optional<bool> NoPHIs;
- std::optional<bool> IsSSA;
- std::optional<bool> NoVRegs;
- std::optional<bool> HasFakeUses;
-
- friend bool operator==(const MIRFunctionDocumentInfo &Left,
- const MIRFunctionDocumentInfo &Right) = default;
-};
-
-class MIRDocument final {
-public:
- MIRDocument();
- explicit MIRDocument(CompilationUnit Unit);
- MIRDocument(const MIRDocument &) = delete;
- MIRDocument &operator=(const MIRDocument &) = delete;
- MIRDocument(MIRDocument &&) noexcept;
- MIRDocument &operator=(MIRDocument &&) noexcept;
- ~MIRDocument();
-
- [[nodiscard]] CompilationUnit &unit() noexcept {
- return Unit;
- }
-
- [[nodiscard]] const CompilationUnit &unit() const noexcept {
- return Unit;
- }
-
- [[nodiscard]] const EmbeddedIRReferenceIndex *embeddedIR() const noexcept {
- return EmbeddedIR ? &*EmbeddedIR : nullptr;
- }
-
- [[nodiscard]] std::span<const MIRFunctionDocumentInfo> functionDocumentInfo() const noexcept {
- return FunctionInfo;
- }
-
- [[nodiscard]] std::span<const MISyncScopeSlot> syncScopes() const noexcept {
- return SyncScopes;
- }
-
-private:
- CompilationUnit Unit;
- std::optional<EmbeddedIRReferenceIndex> EmbeddedIR;
- std::vector<MIRFunctionDocumentInfo> FunctionInfo;
- std::vector<MISyncScopeSlot> SyncScopes;
-
- friend class MIRDocumentParser;
-};
-
-struct MIRDocumentParserOptions final {
- yaml::ParseOptions YAML;
- MIParserOptions MachineInstructions;
- std::string DataLayout;
- bool VerifyMachineFunctions = true;
-};
-
-class MIRDocumentParseResult final {
-public:
- MIRDocumentParseResult(const MIRDocumentParseResult &) = delete;
- MIRDocumentParseResult &operator=(const MIRDocumentParseResult &) = delete;
- MIRDocumentParseResult(MIRDocumentParseResult &&) noexcept;
- MIRDocumentParseResult &operator=(MIRDocumentParseResult &&) noexcept;
- ~MIRDocumentParseResult();
-
- [[nodiscard]] bool succeeded() const noexcept {
- return Document.has_value() && Diagnostics.empty();
- }
-
- [[nodiscard]] MIRDocument *document() noexcept {
- return Document ? &*Document : nullptr;
- }
-
- [[nodiscard]] const MIRDocument *document() const noexcept {
- return Document ? &*Document : nullptr;
- }
-
- [[nodiscard]] const TextSource &source() const noexcept {
- return Source;
- }
-
- [[nodiscard]] std::span<const TextDiagnostic> diagnostics() const noexcept {
- return Diagnostics;
- }
-
-private:
- MIRDocumentParseResult(std::string SourceName, std::string SourceText)
- : Source(std::move(SourceName), std::move(SourceText)) {}
-
- TextSource Source;
- std::optional<MIRDocument> Document;
- std::vector<TextDiagnostic> Diagnostics;
-
- friend class MIRDocumentParser;
-};
-
-[[nodiscard]] MIRDocumentParseResult parseMIRDocument(const TargetDescription &Target,
- std::string SourceName,
- std::string SourceText,
- MIRDocumentParserOptions Options = {});
-
-struct MIRDocumentPrinterOptions final {
- MIPrintMode Mode = MIPrintMode::Complete;
- bool EmitEmbeddedIR = true;
- std::string DataLayout;
-};
-
-[[nodiscard]] Expected<std::string> printMIRDocument(const MIRDocument &Document,
- const TargetDescription &Target,
- MIRDocumentPrinterOptions Options = {});
-
-} // namespace mir
-} // namespace rcc
-
-#endif // RCC_MIR_MIRDOCUMENT_H