github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/builder/cc1as.h (about) 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 /// Helper class for representing a single invocation of the assembler. 18 struct AssemblerInvocation { 19 /// @name Target Options 20 /// @{ 21 22 /// The name of the target triple to assemble for. 23 std::string Triple; 24 25 /// If given, the name of the target CPU to determine which instructions 26 /// are legal. 27 std::string CPU; 28 29 /// The list of target specific features to enable or disable -- this should 30 /// be a list of strings starting with '+' or '-'. 31 std::vector<std::string> Features; 32 33 /// The list of symbol definitions. 34 std::vector<std::string> SymbolDefs; 35 36 /// @} 37 /// @name Language Options 38 /// @{ 39 40 std::vector<std::string> IncludePaths; 41 unsigned NoInitialTextSection : 1; 42 unsigned SaveTemporaryLabels : 1; 43 unsigned GenDwarfForAssembly : 1; 44 unsigned RelaxELFRelocations : 1; 45 unsigned Dwarf64 : 1; 46 unsigned DwarfVersion; 47 std::string DwarfDebugFlags; 48 std::string DwarfDebugProducer; 49 std::string DebugCompilationDir; 50 llvm::SmallVector<std::pair<std::string, std::string>, 0> DebugPrefixMap; 51 llvm::DebugCompressionType CompressDebugSections = 52 llvm::DebugCompressionType::None; 53 std::string MainFileName; 54 std::string SplitDwarfOutput; 55 56 /// @} 57 /// @name Frontend Options 58 /// @{ 59 60 std::string InputFile; 61 std::vector<std::string> LLVMArgs; 62 std::string OutputPath; 63 enum FileType { 64 FT_Asm, ///< Assembly (.s) output, transliterate mode. 65 FT_Null, ///< No output, for timing purposes. 66 FT_Obj ///< Object file output. 67 }; 68 FileType OutputType; 69 unsigned ShowHelp : 1; 70 unsigned ShowVersion : 1; 71 72 /// @} 73 /// @name Transliterate Options 74 /// @{ 75 76 unsigned OutputAsmVariant; 77 unsigned ShowEncoding : 1; 78 unsigned ShowInst : 1; 79 80 /// @} 81 /// @name Assembler Options 82 /// @{ 83 84 unsigned RelaxAll : 1; 85 unsigned NoExecStack : 1; 86 unsigned FatalWarnings : 1; 87 unsigned NoWarn : 1; 88 unsigned NoTypeCheck : 1; 89 unsigned IncrementalLinkerCompatible : 1; 90 unsigned EmbedBitcode : 1; 91 92 /// Whether to emit DWARF unwind info. 93 EmitDwarfUnwindType EmitDwarfUnwind; 94 95 // Whether to emit compact-unwind for non-canonical entries. 96 // Note: maybe overriden by other constraints. 97 unsigned EmitCompactUnwindNonCanonical : 1; 98 99 /// The name of the relocation model to use. 100 std::string RelocationModel; 101 102 /// The ABI targeted by the backend. Specified using -target-abi. Empty 103 /// otherwise. 104 std::string TargetABI; 105 106 /// Darwin target variant triple, the variant of the deployment target 107 /// for which the code is being compiled. 108 std::optional<llvm::Triple> DarwinTargetVariantTriple; 109 110 /// The version of the darwin target variant SDK which was used during the 111 /// compilation 112 llvm::VersionTuple DarwinTargetVariantSDKVersion; 113 114 /// The name of a file to use with \c .secure_log_unique directives. 115 std::string AsSecureLogFile; 116 /// @} 117 118 public: 119 AssemblerInvocation() { 120 Triple = ""; 121 NoInitialTextSection = 0; 122 InputFile = "-"; 123 OutputPath = "-"; 124 OutputType = FT_Asm; 125 OutputAsmVariant = 0; 126 ShowInst = 0; 127 ShowEncoding = 0; 128 RelaxAll = 0; 129 NoExecStack = 0; 130 FatalWarnings = 0; 131 NoWarn = 0; 132 NoTypeCheck = 0; 133 IncrementalLinkerCompatible = 0; 134 Dwarf64 = 0; 135 DwarfVersion = 0; 136 EmbedBitcode = 0; 137 EmitDwarfUnwind = EmitDwarfUnwindType::Default; 138 EmitCompactUnwindNonCanonical = false; 139 } 140 141 static bool CreateFromArgs(AssemblerInvocation &Res, 142 ArrayRef<const char *> Argv, 143 DiagnosticsEngine &Diags); 144 }; 145 146 bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags);