diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-12 19:45:09 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-12 19:45:09 +0800 |
| commit | 09e8ef3e0dae29be7aa21a6e22a118a3f545945f (patch) | |
| tree | cfc5a7148aca9e768df16743c2c637e8c00a9d44 /backend/include | |
| parent | 1775d50ba02dab033c639f5c8fedd46cb6613bef (diff) | |
| download | rcc-project-09e8ef3e0dae29be7aa21a6e22a118a3f545945f.tar.gz rcc-project-09e8ef3e0dae29be7aa21a6e22a118a3f545945f.tar.xz | |
[Tooling] Complete the LLVM MIR command-line contract
Diffstat (limited to 'backend/include')
| -rw-r--r-- | backend/include/rcc/CodeGen/CommandFlags.h | 72 | ||||
| -rw-r--r-- | backend/include/rcc/Tooling/BackendDriver.h | 1 | ||||
| -rw-r--r-- | backend/include/rcc/Tooling/BackendInvocation.h | 33 | ||||
| -rw-r--r-- | backend/include/rcc/Tooling/PipelineDriver.h | 2 |
4 files changed, 78 insertions, 30 deletions
diff --git a/backend/include/rcc/CodeGen/CommandFlags.h b/backend/include/rcc/CodeGen/CommandFlags.h new file mode 100644 index 0000000..0ee2f0d --- /dev/null +++ b/backend/include/rcc/CodeGen/CommandFlags.h @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef RCC_CODEGEN_COMMANDFLAGS_H +#define RCC_CODEGEN_COMMANDFLAGS_H + +#include "rcc/Support/Error.h" + +#include <cstddef> +#include <cstdint> +#include <optional> +#include <span> +#include <string> +#include <string_view> +#include <vector> + +namespace rcc { + +enum class RelocationModel : std::uint8_t { + Static, + PositionIndependent, +}; + +enum class CodeModel : std::uint8_t { + Small, + Medium, + Large, +}; + +enum class OptimizationLevel : std::uint8_t { + O0, + O1, + O2, + O3, + Os, + Oz, +}; + +enum class CodeGenFileType : std::uint8_t { + AssemblyFile, + ObjectFile, + Null, +}; + +struct CodeGenCommandFlags final { + std::optional<std::string> Triple; + std::optional<std::string> CPU; + std::optional<std::string> TuneCPU; + std::optional<std::string> ABI; + std::vector<std::string> FeatureOverrides; + std::optional<RelocationModel> Relocation; + std::optional<CodeModel> Code; + std::optional<OptimizationLevel> Optimization; + CodeGenFileType FileType = CodeGenFileType::AssemblyFile; + bool FileTypeWasSpecified = false; +}; + +[[nodiscard]] std::string_view spelling(RelocationModel Value) noexcept; +[[nodiscard]] std::string_view spelling(CodeModel Value) noexcept; +[[nodiscard]] std::string_view spelling(OptimizationLevel Value) noexcept; +[[nodiscard]] std::string_view spelling(CodeGenFileType Value) noexcept; + +[[nodiscard]] Expected<RelocationModel> parseRelocationModel(std::string_view Value); +[[nodiscard]] Expected<CodeModel> parseCodeModel(std::string_view Value); +[[nodiscard]] Expected<OptimizationLevel> parseOptimizationLevel(std::string_view Value); +[[nodiscard]] Expected<CodeGenFileType> parseCodeGenFileType(std::string_view Value); +[[nodiscard]] Expected<bool> parseCodeGenCommandFlag(std::span<const std::string_view> Arguments, + std::size_t &Index, + CodeGenCommandFlags &Flags); + +} // namespace rcc + +#endif // RCC_CODEGEN_COMMANDFLAGS_H diff --git a/backend/include/rcc/Tooling/BackendDriver.h b/backend/include/rcc/Tooling/BackendDriver.h index f762c1e..7b62b6d 100644 --- a/backend/include/rcc/Tooling/BackendDriver.h +++ b/backend/include/rcc/Tooling/BackendDriver.h @@ -46,7 +46,6 @@ runBackend(CanonicalMIR Input, const TargetDescription &Target, const BackendInv MachinePassInstrumentation *Instrumentation = nullptr); [[nodiscard]] std::string_view spelling(BackendOutputKind Output) noexcept; -[[nodiscard]] Expected<BackendOutputKind> parseBackendOutputKind(std::string_view Value); [[nodiscard]] ArtifactKind manifestArtifactKind(BackendOutputKind Output) noexcept; [[nodiscard]] Expected<ArtifactKind> cacheArtifactKind(BackendOutputKind Output); diff --git a/backend/include/rcc/Tooling/BackendInvocation.h b/backend/include/rcc/Tooling/BackendInvocation.h index db1c5d2..d61f038 100644 --- a/backend/include/rcc/Tooling/BackendInvocation.h +++ b/backend/include/rcc/Tooling/BackendInvocation.h @@ -3,6 +3,7 @@ #ifndef RCC_TOOLING_BACKENDINVOCATION_H #define RCC_TOOLING_BACKENDINVOCATION_H +#include "rcc/CodeGen/CommandFlags.h" #include "rcc/Support/Error.h" #include <cstdint> @@ -25,26 +26,6 @@ inline constexpr std::string_view GenericOpcodeReferenceVersion = "rcc-generic-o inline constexpr std::string_view RV64GCTargetABILoweringVersion = "rcc-rv64gc-lp64d-v1"; inline constexpr std::string_view CompilerBuildFingerprint = "rcc-backend-0.1.0-stage17"; -enum class RelocationModel : std::uint8_t { - Static, - PositionIndependent, -}; - -enum class CodeModel : std::uint8_t { - Small, - Medium, - Large, -}; - -enum class OptimizationLevel : std::uint8_t { - O0, - O1, - O2, - O3, - Os, - Oz, -}; - enum class LayoutOwnership : std::uint8_t { NativeObject, CompilerFinalLayout, @@ -74,14 +55,14 @@ struct BackendInvocation final { std::vector<std::string> Features; std::string ABI; std::string DataLayout; - RelocationModel Relocation = RelocationModel::PositionIndependent; - CodeModel Code = CodeModel::Small; + rcc::RelocationModel Relocation = rcc::RelocationModel::PositionIndependent; + rcc::CodeModel Code = rcc::CodeModel::Small; std::vector<BackendOption> TargetOptions; LayoutOwnership Layout = LayoutOwnership::NativeObject; std::string AssemblerFlavor; std::string AssemblerVersion; std::vector<BackendOption> AssemblerOptions; - OptimizationLevel Optimization = OptimizationLevel::O2; + rcc::OptimizationLevel Optimization = rcc::OptimizationLevel::O2; std::vector<std::string> PassPipeline{"default"}; DeterminismOptions Determinism; std::optional<std::uint64_t> ActionFuel; @@ -104,13 +85,7 @@ computeTargetDescriptionFingerprint(const TargetDescription &Target); const BackendInvocation &Invocation, std::string_view TargetFingerprint); -[[nodiscard]] std::string_view spelling(RelocationModel Value) noexcept; -[[nodiscard]] std::string_view spelling(CodeModel Value) noexcept; -[[nodiscard]] std::string_view spelling(OptimizationLevel Value) noexcept; [[nodiscard]] std::string_view spelling(LayoutOwnership Value) noexcept; -[[nodiscard]] Expected<RelocationModel> parseRelocationModel(std::string_view Value); -[[nodiscard]] Expected<CodeModel> parseCodeModel(std::string_view Value); -[[nodiscard]] Expected<OptimizationLevel> parseOptimizationLevel(std::string_view Value); [[nodiscard]] Expected<LayoutOwnership> parseLayoutOwnership(std::string_view Value); } // namespace tooling diff --git a/backend/include/rcc/Tooling/PipelineDriver.h b/backend/include/rcc/Tooling/PipelineDriver.h index d6c9f58..5d2dc45 100644 --- a/backend/include/rcc/Tooling/PipelineDriver.h +++ b/backend/include/rcc/Tooling/PipelineDriver.h @@ -36,6 +36,8 @@ enum class SnapshotPhase : std::uint8_t { }; struct PipelineControls final { + std::optional<std::string> StartBefore; + std::optional<std::string> StartAfter; std::optional<std::string> StopBefore; std::optional<std::string> StopAfter; std::vector<std::string> PrintBefore; |
