cc1as.h raw

   1  // Source: https://github.com/llvm/llvm-project/blob/main/clang/tools/driver/cc1as_main.cpp
   2  // See cc1as.cpp for details.
   3  
   4  //===-- cc1as.h - Clang Assembler  ----------------------------------------===//
   5  //
   6  // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
   7  // See https://llvm.org/LICENSE.txt for license information.
   8  // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
   9  //
  10  //===----------------------------------------------------------------------===//
  11  //
  12  // This is the entry point to the clang -cc1as functionality, which implements
  13  // the direct interface to the LLVM MC based assembler.
  14  //
  15  //===----------------------------------------------------------------------===//
  16  
  17  #include <llvm/Config/llvm-config.h>
  18  
  19  /// Helper class for representing a single invocation of the assembler.
  20  struct AssemblerInvocation {
  21    /// @name Target Options
  22    /// @{
  23  
  24    /// The name of the target triple to assemble for.
  25    std::string Triple;
  26  
  27    /// If given, the name of the target CPU to determine which instructions
  28    /// are legal.
  29    std::string CPU;
  30  
  31    /// The list of target specific features to enable or disable -- this should
  32    /// be a list of strings starting with '+' or '-'.
  33    std::vector<std::string> Features;
  34  
  35    /// The list of symbol definitions.
  36    std::vector<std::string> SymbolDefs;
  37  
  38    /// @}
  39    /// @name Language Options
  40    /// @{
  41  
  42    std::vector<std::string> IncludePaths;
  43    LLVM_PREFERRED_TYPE(bool)
  44    unsigned NoInitialTextSection : 1;
  45    LLVM_PREFERRED_TYPE(bool)
  46    unsigned SaveTemporaryLabels : 1;
  47    LLVM_PREFERRED_TYPE(bool)
  48    unsigned GenDwarfForAssembly : 1;
  49    LLVM_PREFERRED_TYPE(bool)
  50    unsigned Dwarf64 : 1;
  51    unsigned DwarfVersion;
  52    std::string DwarfDebugFlags;
  53    std::string DwarfDebugProducer;
  54    std::string DebugCompilationDir;
  55    llvm::SmallVector<std::pair<std::string, std::string>, 0> DebugPrefixMap;
  56    llvm::DebugCompressionType CompressDebugSections =
  57        llvm::DebugCompressionType::None;
  58    std::string MainFileName;
  59    std::string SplitDwarfOutput;
  60  
  61    /// @}
  62    /// @name Frontend Options
  63    /// @{
  64  
  65    std::string InputFile;
  66    std::vector<std::string> LLVMArgs;
  67    std::string OutputPath;
  68    enum FileType {
  69      FT_Asm,  ///< Assembly (.s) output, transliterate mode.
  70      FT_Null, ///< No output, for timing purposes.
  71      FT_Obj   ///< Object file output.
  72    };
  73    FileType OutputType;
  74    LLVM_PREFERRED_TYPE(bool)
  75    unsigned ShowHelp : 1;
  76    LLVM_PREFERRED_TYPE(bool)
  77    unsigned ShowVersion : 1;
  78  
  79    /// @}
  80    /// @name Transliterate Options
  81    /// @{
  82  
  83    unsigned OutputAsmVariant;
  84    LLVM_PREFERRED_TYPE(bool)
  85    unsigned ShowEncoding : 1;
  86    LLVM_PREFERRED_TYPE(bool)
  87    unsigned ShowInst : 1;
  88  
  89    /// @}
  90    /// @name Assembler Options
  91    /// @{
  92  
  93    LLVM_PREFERRED_TYPE(bool)
  94    unsigned RelaxAll : 1;
  95    LLVM_PREFERRED_TYPE(bool)
  96    unsigned NoExecStack : 1;
  97    LLVM_PREFERRED_TYPE(bool)
  98    unsigned FatalWarnings : 1;
  99    LLVM_PREFERRED_TYPE(bool)
 100    unsigned NoWarn : 1;
 101    LLVM_PREFERRED_TYPE(bool)
 102    unsigned NoTypeCheck : 1;
 103    LLVM_PREFERRED_TYPE(bool)
 104    unsigned IncrementalLinkerCompatible : 1;
 105    LLVM_PREFERRED_TYPE(bool)
 106    unsigned EmbedBitcode : 1;
 107  
 108    /// Whether to emit DWARF unwind info.
 109    EmitDwarfUnwindType EmitDwarfUnwind;
 110  
 111    // Whether to emit compact-unwind for non-canonical entries.
 112    // Note: maybe overriden by other constraints.
 113    LLVM_PREFERRED_TYPE(bool)
 114    unsigned EmitCompactUnwindNonCanonical : 1;
 115  
 116    LLVM_PREFERRED_TYPE(bool)
 117    unsigned Crel : 1;
 118  #if LLVM_VERSION_MAJOR >= 20
 119    LLVM_PREFERRED_TYPE(bool)
 120    unsigned ImplicitMapsyms : 1;
 121  #endif
 122  
 123    LLVM_PREFERRED_TYPE(bool)
 124    unsigned X86RelaxRelocations : 1;
 125    LLVM_PREFERRED_TYPE(bool)
 126    unsigned X86Sse2Avx : 1;
 127  
 128    /// The name of the relocation model to use.
 129    std::string RelocationModel;
 130  
 131    /// The ABI targeted by the backend. Specified using -target-abi. Empty
 132    /// otherwise.
 133    std::string TargetABI;
 134  
 135    /// Darwin target variant triple, the variant of the deployment target
 136    /// for which the code is being compiled.
 137    std::optional<llvm::Triple> DarwinTargetVariantTriple;
 138  
 139    /// The version of the darwin target variant SDK which was used during the
 140    /// compilation
 141    llvm::VersionTuple DarwinTargetVariantSDKVersion;
 142  
 143    /// The name of a file to use with \c .secure_log_unique directives.
 144    std::string AsSecureLogFile;
 145    /// @}
 146  
 147  public:
 148    AssemblerInvocation() {
 149      Triple = "";
 150      NoInitialTextSection = 0;
 151      InputFile = "-";
 152      OutputPath = "-";
 153      OutputType = FT_Asm;
 154      OutputAsmVariant = 0;
 155      ShowInst = 0;
 156      ShowEncoding = 0;
 157      RelaxAll = 0;
 158      NoExecStack = 0;
 159      FatalWarnings = 0;
 160      NoWarn = 0;
 161      NoTypeCheck = 0;
 162      IncrementalLinkerCompatible = 0;
 163      Dwarf64 = 0;
 164      DwarfVersion = 0;
 165      EmbedBitcode = 0;
 166      EmitDwarfUnwind = EmitDwarfUnwindType::Default;
 167      EmitCompactUnwindNonCanonical = false;
 168      Crel = false;
 169  #if LLVM_VERSION_MAJOR >= 20
 170      ImplicitMapsyms = 0;
 171  #endif
 172      X86RelaxRelocations = 0;
 173      X86Sse2Avx = 0;
 174    }
 175  
 176    static bool CreateFromArgs(AssemblerInvocation &Res,
 177                               ArrayRef<const char *> Argv,
 178                               DiagnosticsEngine &Diags);
 179  };
 180  
 181  bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags);
 182