From 09e8ef3e0dae29be7aa21a6e22a118a3f545945f Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Wed, 12 Aug 2026 19:45:09 +0800 Subject: [Tooling] Complete the LLVM MIR command-line contract --- backend/include/rcc/CodeGen/CommandFlags.h | 72 ++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 backend/include/rcc/CodeGen/CommandFlags.h (limited to 'backend/include/rcc/CodeGen') 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 +#include +#include +#include +#include +#include +#include + +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 Triple; + std::optional CPU; + std::optional TuneCPU; + std::optional ABI; + std::vector FeatureOverrides; + std::optional Relocation; + std::optional Code; + std::optional 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 parseRelocationModel(std::string_view Value); +[[nodiscard]] Expected parseCodeModel(std::string_view Value); +[[nodiscard]] Expected parseOptimizationLevel(std::string_view Value); +[[nodiscard]] Expected parseCodeGenFileType(std::string_view Value); +[[nodiscard]] Expected parseCodeGenCommandFlag(std::span Arguments, + std::size_t &Index, + CodeGenCommandFlags &Flags); + +} // namespace rcc + +#endif // RCC_CODEGEN_COMMANDFLAGS_H -- cgit v1.2.3