clang: lib/FrontendTool/ExecuteCompilerInvocation.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

16#include "clang/Config/config.h"

29#include "llvm/Option/OptTable.h"

30#include "llvm/Option/Option.h"

31#include "llvm/Support/BuryPointer.h"

32#include "llvm/Support/DynamicLibrary.h"

33#include "llvm/Support/ErrorHandling.h"

34

35#if CLANG_ENABLE_CIR

37#endif

38

39using namespace clang;

41

43

44static std::unique_ptr

47 StringRef Action("unknown");

48 (void)Action;

49

52 bool EmitsCIR = Act == EmitCIR;

53

54 if (!UseCIR && EmitsCIR)

55 llvm::report_fatal_error("-emit-cir and only valid when using -fclangir");

56

58 case ASTDeclList: return std::make_unique();

59 case ASTDump: return std::make_unique();

60 case ASTPrint: return std::make_unique();

61 case ASTView: return std::make_unique();

62 case DumpCompilerOptions:

63 return std::make_unique();

64 case DumpRawTokens: return std::make_unique();

65 case DumpTokens: return std::make_unique();

66 case EmitAssembly: return std::make_unique();

67 case EmitBC: return std::make_unique();

68 case EmitCIR:

69#if CLANG_ENABLE_CIR

70 return std::make_uniquecir::EmitCIRAction();

71#else

72 llvm_unreachable("CIR suppport not built into clang");

73#endif

74 case EmitHTML: return std::make_unique();

75 case EmitLLVM: return std::make_unique();

76 case EmitLLVMOnly: return std::make_unique();

77 case EmitCodeGenOnly: return std::make_unique();

78 case EmitObj: return std::make_unique();

79 case ExtractAPI:

80 return std::make_unique();

81 case FixIt: return std::make_unique();

82 case GenerateModule:

83 return std::make_unique();

84 case GenerateModuleInterface:

85 return std::make_unique();

86 case GenerateReducedModuleInterface:

87 return std::make_unique();

88 case GenerateHeaderUnit:

89 return std::make_unique();

90 case GeneratePCH: return std::make_unique();

91 case GenerateInterfaceStubs:

92 return std::make_unique();

93 case InitOnly: return std::make_unique();

94 case ParseSyntaxOnly: return std::make_unique();

95 case ModuleFileInfo: return std::make_unique();

96 case VerifyPCH: return std::make_unique();

97 case TemplightDump: return std::make_unique();

98

99 case PluginAction: {

100 for (const FrontendPluginRegistry::entry &Plugin :

101 FrontendPluginRegistry::entries()) {

103 std::unique_ptr P(Plugin.instantiate());

106 P->ParseArgs(

107 CI,

109 return nullptr;

110 return std::move(P);

111 }

112 }

113

116 return nullptr;

117 }

118

119 case PrintPreamble: return std::make_unique();

120 case PrintPreprocessedInput: {

123 return std::make_unique();

124 return std::make_unique();

125 }

126

127 case RewriteMacros: return std::make_unique();

128 case RewriteTest: return std::make_unique();

129#if CLANG_ENABLE_OBJC_REWRITER

130 case RewriteObjC: return std::make_unique();

131#else

132 case RewriteObjC: Action = "RewriteObjC"; break;

133#endif

134#if CLANG_ENABLE_ARCMT

135 case MigrateSource:

136 return std::make_uniquearcmt::MigrateSourceAction();

137#else

138 case MigrateSource: Action = "MigrateSource"; break;

139#endif

140#if CLANG_ENABLE_STATIC_ANALYZER

141 case RunAnalysis: return std::make_uniqueento::AnalysisAction();

142#else

143 case RunAnalysis: Action = "RunAnalysis"; break;

144#endif

145 case RunPreprocessorOnly: return std::make_unique();

146 case PrintDependencyDirectivesSourceMinimizerOutput:

147 return std::make_unique();

148 }

149

150#if !CLANG_ENABLE_ARCMT || !CLANG_ENABLE_STATIC_ANALYZER \

151 || !CLANG_ENABLE_OBJC_REWRITER

153 return 0;

154#else

155 llvm_unreachable("Invalid program action!");

156#endif

157}

158

159std::unique_ptr

161

163 if (!Act)

164 return nullptr;

165

167

169 Act = std::make_unique(std::move(Act));

170 }

171

172#if CLANG_ENABLE_ARCMT

175

178 break;

180 Act = std::make_uniquearcmt::CheckAction(std::move(Act));

181 break;

183 Act = std::make_uniquearcmt::ModifyAction(std::move(Act));

184 break;

186 Act = std::make_uniquearcmt::MigrateAction(std::move(Act),

190 break;

191 }

192

194 Act = std::make_uniquearcmt::ObjCMigrateAction(std::move(Act),

197 }

198 }

199#endif

200

201

202

203

208 }

210 Act = std::make_unique(std::move(Act));

211 }

212

213

214

216 Act = std::make_unique(std::move(Act),

218

219 return Act;

220}

221

223

226 llvm::outs(), "clang -cc1 [options] file...",

227 "LLVM 'Clang' Compiler: http://clang.llvm.org",

228 false, false,

230 return true;

231 }

232

233

234

235

237 llvm:🆑:PrintVersionMessage();

238 return true;

239 }

240

242

243

244

245

246

249 auto Args = std::make_unique<const char*[]>(NumArgs + 2);

250 Args[0] = "clang (LLVM option parsing)";

251 for (unsigned i = 0; i != NumArgs; ++i)

253 Args[NumArgs + 1] = nullptr;

254 llvm:🆑:ParseCommandLineOptions(NumArgs + 1, Args.get());

255 }

256

257#if CLANG_ENABLE_STATIC_ANALYZER

258

259

261

262

266 return true;

267 }

268

269

273 return true;

274 }

275

276

279 return true;

280 }

281

282

285 return true;

286 }

287#endif

288

289

291 return false;

292

294 if (!Act)

295 return false;

298 llvm::BuryPointer(std::move(Act));

300}

301

302}

Stores options for the analyzer from the command line.

unsigned ShowCheckerOptionDeveloperList

unsigned ShowEnabledCheckerList

unsigned ShowCheckerHelpAlpha

unsigned ShowConfigOptionsList

unsigned ShowCheckerHelpDeveloper

unsigned ShowCheckerOptionList

unsigned ShowCheckerOptionAlphaList

CompilerInstance - Helper class for managing a single instance of the Clang compiler.

AnalyzerOptions & getAnalyzerOpts()

DiagnosticsEngine & getDiagnostics() const

Get the current diagnostics engine.

PreprocessorOutputOptions & getPreprocessorOutputOpts()

void LoadRequestedPlugins()

Load the list of plugins requested in the FrontendOptions.

FrontendOptions & getFrontendOpts()

bool ExecuteAction(FrontendAction &Act)

ExecuteAction - Execute the provided action against the compiler's CompilerInvocation object.

CodeGenOptions & getCodeGenOpts()

DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)

Issue the message to the client.

bool hasErrorOccurred() const

FrontendOptions - Options for controlling the behavior of the frontend.

enum clang::FrontendOptions::@202 ARCMTAction

unsigned EmitSymbolGraph

Whether to emit symbol graph files as a side effect of compilation.

std::map< std::string, std::vector< std::string > > PluginArgs

Args to pass to the plugins.

std::vector< std::string > LLVMArgs

A list of arguments to forward to LLVM's option processing; this should only be used for debugging an...

unsigned ShowHelp

Show the -help text.

unsigned FixAndRecompile

Apply fixes and recompile.

unsigned UseClangIRPipeline

Use Clang IR pipeline to emit code.

std::string ActionName

The name of the action to run when using a plugin action.

std::string ARCMTMigrateReportOut

unsigned ShowVersion

Show the -version text.

unsigned ARCMTMigrateEmitARCErrors

Emit ARC errors even if the migrator can fix them.

std::string SymbolGraphOutputDir

std::vector< std::string > ASTMergeFiles

The list of AST files to merge.

unsigned DisableFree

Disable memory freeing on exit.

frontend::ActionKind ProgramAction

The frontend action to perform.

@ ReplaceAction

Replace the main action.

@ CmdlineAfterMainAction

Execute the action after the main action if on the command line.

unsigned RewriteIncludes

Preprocess include directives only.

unsigned RewriteImports

Include contents of transitively-imported modules.

const llvm::opt::OptTable & getDriverOptTable()

void printEnabledCheckerList(llvm::raw_ostream &OS, CompilerInstance &CI)

void printCheckerHelp(llvm::raw_ostream &OS, CompilerInstance &CI)

void printAnalyzerConfigList(llvm::raw_ostream &OS)

void printCheckerConfigList(llvm::raw_ostream &OS, CompilerInstance &CI)

@ MigrateSource

Run migrator.

@ GeneratePCH

Generate pre-compiled header.

The JSON file list parser is used to communicate input to InstallAPI.

static std::unique_ptr< FrontendAction > CreateFrontendBaseAction(CompilerInstance &CI)

bool ExecuteCompilerInvocation(CompilerInstance *Clang)

ExecuteCompilerInvocation - Execute the given actions described by the compiler invocation object in ...

std::unique_ptr< FrontendAction > CreateFrontendAction(CompilerInstance &CI)

Construct the FrontendAction of a compiler invocation based on the options specified for the compiler...

@ Success

Template argument deduction was successful.