2006-06-18 13:43:12 +08:00
|
|
|
//===--- clang.cpp - C-Language Front-end ---------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-06-18 13:43:12 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This utility may be invoked in the following manner:
|
2006-11-21 13:52:55 +08:00
|
|
|
// clang --help - Output help info.
|
|
|
|
// clang [options] - Read from stdin.
|
|
|
|
// clang [options] file - Read from "file".
|
|
|
|
// clang [options] file1 file2 - Read these files.
|
2006-06-18 13:43:12 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// TODO: Options to support:
|
|
|
|
//
|
|
|
|
// -ffatal-errors
|
|
|
|
// -ftabstop=width
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-07-05 03:04:05 +08:00
|
|
|
#include "clang.h"
|
2007-10-07 14:04:32 +08:00
|
|
|
#include "ASTConsumers.h"
|
2008-10-23 13:50:47 +08:00
|
|
|
#include "clang/Driver/CompileOptions.h"
|
2008-11-04 06:31:48 +08:00
|
|
|
#include "clang/Driver/PathDiagnosticClients.h"
|
2008-08-22 17:25:22 +08:00
|
|
|
#include "clang/Driver/InitHeaderSearch.h"
|
2008-08-06 07:33:20 +08:00
|
|
|
#include "clang/Driver/TextDiagnosticBuffer.h"
|
|
|
|
#include "clang/Driver/TextDiagnosticPrinter.h"
|
2008-03-27 14:17:42 +08:00
|
|
|
#include "clang/Analysis/PathDiagnostic.h"
|
2008-08-11 12:54:23 +08:00
|
|
|
#include "clang/AST/Decl.h"
|
2007-12-19 05:34:28 +08:00
|
|
|
#include "clang/AST/TranslationUnit.h"
|
2008-02-06 10:01:47 +08:00
|
|
|
#include "clang/CodeGen/ModuleBuilder.h"
|
2008-02-06 08:23:21 +08:00
|
|
|
#include "clang/Sema/ParseAST.h"
|
2007-09-16 06:56:56 +08:00
|
|
|
#include "clang/AST/ASTConsumer.h"
|
2006-07-31 09:59:18 +08:00
|
|
|
#include "clang/Parse/Parser.h"
|
2006-10-22 15:28:56 +08:00
|
|
|
#include "clang/Lex/HeaderSearch.h"
|
2006-06-18 13:43:12 +08:00
|
|
|
#include "clang/Basic/FileManager.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
2006-10-15 03:54:37 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2008-10-01 04:16:56 +08:00
|
|
|
#include "llvm/ADT/OwningPtr.h"
|
2007-12-16 07:20:07 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2008-10-01 04:16:56 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/Config/config.h"
|
2006-06-18 13:43:12 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2008-10-28 08:38:08 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2007-04-29 15:12:06 +08:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2008-10-02 09:21:33 +08:00
|
|
|
#include "llvm/System/Host.h"
|
2008-03-03 11:16:03 +08:00
|
|
|
#include "llvm/System/Path.h"
|
2008-10-01 04:16:56 +08:00
|
|
|
#include "llvm/System/Signals.h"
|
2006-06-18 13:43:12 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Global options.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-10-17 00:54:18 +08:00
|
|
|
static bool HadErrors = false;
|
2008-10-05 07:42:49 +08:00
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
Verbose("v", llvm::cl::desc("Enable verbose output"));
|
|
|
|
static llvm::cl::opt<bool>
|
2007-12-30 09:38:50 +08:00
|
|
|
Stats("print-stats",
|
|
|
|
llvm::cl::desc("Print performance metrics and statistics"));
|
2008-10-17 00:54:18 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
DisableFree("disable-free",
|
|
|
|
llvm::cl::desc("Disable freeing of memory on exit"),
|
|
|
|
llvm::cl::init(false));
|
2006-06-18 13:43:12 +08:00
|
|
|
|
|
|
|
enum ProgActions {
|
2008-04-15 06:03:09 +08:00
|
|
|
RewriteObjC, // ObjC->C Rewriter.
|
2008-09-18 22:10:13 +08:00
|
|
|
RewriteBlocks, // ObjC->C Rewriter for Blocks.
|
2008-05-08 14:52:13 +08:00
|
|
|
RewriteMacros, // Expand macros but not #includes.
|
2008-10-12 13:29:20 +08:00
|
|
|
RewriteTest, // Rewriter playground
|
2008-03-19 15:53:42 +08:00
|
|
|
HTMLTest, // HTML displayer testing stuff.
|
2008-10-22 07:49:24 +08:00
|
|
|
EmitAssembly, // Emit a .s file.
|
2007-05-24 14:29:05 +08:00
|
|
|
EmitLLVM, // Emit a .ll file.
|
2007-12-24 09:52:34 +08:00
|
|
|
EmitBC, // Emit a .bc file.
|
2007-12-13 08:37:31 +08:00
|
|
|
SerializeAST, // Emit a .ast file.
|
2008-03-19 05:19:49 +08:00
|
|
|
EmitHTML, // Translate input source into HTML.
|
2007-10-11 08:18:28 +08:00
|
|
|
ASTPrint, // Parse ASTs and print them.
|
|
|
|
ASTDump, // Parse ASTs and dump them.
|
|
|
|
ASTView, // Parse ASTs and view them in Graphviz.
|
2007-10-17 07:37:27 +08:00
|
|
|
TestSerialization, // Run experimental serialization code.
|
2006-07-31 09:59:18 +08:00
|
|
|
ParsePrintCallbacks, // Parse and print each callback.
|
2006-11-06 02:00:10 +08:00
|
|
|
ParseSyntaxOnly, // Parse and perform semantic analysis.
|
2006-07-31 09:59:18 +08:00
|
|
|
ParseNoop, // Parse with noop callbacks.
|
2006-06-18 13:43:12 +08:00
|
|
|
RunPreprocessorOnly, // Just lex, no output.
|
|
|
|
PrintPreprocessedInput, // -E mode.
|
2008-10-12 13:03:36 +08:00
|
|
|
DumpTokens, // Dump out preprocessed tokens.
|
|
|
|
DumpRawTokens, // Dump out raw tokens.
|
2008-10-21 08:54:44 +08:00
|
|
|
RunAnalysis, // Run one or more source code analyses.
|
2008-10-24 07:36:29 +08:00
|
|
|
GeneratePCH, // Generate precompiled header.
|
|
|
|
InheritanceView // View C++ inheritance for a specified class.
|
2006-06-18 13:43:12 +08:00
|
|
|
};
|
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::opt<ProgActions>
|
|
|
|
ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
|
|
|
|
llvm::cl::init(ParseSyntaxOnly),
|
|
|
|
llvm::cl::values(
|
2006-06-18 13:43:12 +08:00
|
|
|
clEnumValN(RunPreprocessorOnly, "Eonly",
|
|
|
|
"Just run preprocessor, no output (for timings)"),
|
|
|
|
clEnumValN(PrintPreprocessedInput, "E",
|
|
|
|
"Run preprocessor, emit preprocessed file"),
|
2008-10-12 13:03:36 +08:00
|
|
|
clEnumValN(DumpRawTokens, "dump-raw-tokens",
|
|
|
|
"Lex file in raw mode and dump raw tokens"),
|
|
|
|
clEnumValN(DumpTokens, "dump-tokens",
|
2006-06-18 13:43:12 +08:00
|
|
|
"Run preprocessor, dump internal rep of tokens"),
|
2006-07-31 09:59:18 +08:00
|
|
|
clEnumValN(ParseNoop, "parse-noop",
|
|
|
|
"Run parser with noop callbacks (for timings)"),
|
2006-08-17 13:51:27 +08:00
|
|
|
clEnumValN(ParseSyntaxOnly, "fsyntax-only",
|
|
|
|
"Run parser and perform semantic analysis"),
|
2006-11-06 02:00:10 +08:00
|
|
|
clEnumValN(ParsePrintCallbacks, "parse-print-callbacks",
|
|
|
|
"Run parser and print each callback invoked"),
|
2008-03-19 05:19:49 +08:00
|
|
|
clEnumValN(EmitHTML, "emit-html",
|
|
|
|
"Output input source as HTML"),
|
2007-10-11 08:18:28 +08:00
|
|
|
clEnumValN(ASTPrint, "ast-print",
|
|
|
|
"Build ASTs and then pretty-print them"),
|
|
|
|
clEnumValN(ASTDump, "ast-dump",
|
|
|
|
"Build ASTs and then debug dump them"),
|
2007-10-11 08:37:43 +08:00
|
|
|
clEnumValN(ASTView, "ast-view",
|
2008-05-08 16:28:14 +08:00
|
|
|
"Build ASTs and view them with GraphViz"),
|
2007-10-17 07:37:27 +08:00
|
|
|
clEnumValN(TestSerialization, "test-pickling",
|
2008-05-08 16:28:14 +08:00
|
|
|
"Run prototype serialization code"),
|
2008-10-22 07:49:24 +08:00
|
|
|
clEnumValN(EmitAssembly, "S",
|
|
|
|
"Emit native assembly code"),
|
2007-05-24 14:29:05 +08:00
|
|
|
clEnumValN(EmitLLVM, "emit-llvm",
|
2007-09-07 05:26:58 +08:00
|
|
|
"Build ASTs then convert to LLVM, emit .ll file"),
|
2007-12-24 09:52:34 +08:00
|
|
|
clEnumValN(EmitBC, "emit-llvm-bc",
|
|
|
|
"Build ASTs then convert to LLVM, emit .bc file"),
|
2007-12-20 03:47:59 +08:00
|
|
|
clEnumValN(SerializeAST, "serialize",
|
2007-12-13 08:37:31 +08:00
|
|
|
"Build ASTs and emit .ast file"),
|
2008-10-12 13:29:20 +08:00
|
|
|
clEnumValN(RewriteTest, "rewrite-test",
|
|
|
|
"Rewriter playground"),
|
2008-04-15 06:03:09 +08:00
|
|
|
clEnumValN(RewriteObjC, "rewrite-objc",
|
2008-05-08 14:52:13 +08:00
|
|
|
"Rewrite ObjC into C (code rewriter example)"),
|
|
|
|
clEnumValN(RewriteMacros, "rewrite-macros",
|
|
|
|
"Expand macros without full preprocessing"),
|
2008-09-18 22:10:13 +08:00
|
|
|
clEnumValN(RewriteBlocks, "rewrite-blocks",
|
|
|
|
"Rewrite Blocks to C"),
|
2006-06-18 13:43:12 +08:00
|
|
|
clEnumValEnd));
|
|
|
|
|
2007-12-20 03:47:59 +08:00
|
|
|
|
|
|
|
static llvm::cl::opt<std::string>
|
|
|
|
OutputFile("o",
|
2007-12-20 03:50:41 +08:00
|
|
|
llvm::cl::value_desc("path"),
|
2007-12-20 03:47:59 +08:00
|
|
|
llvm::cl::desc("Specify output file (for --serialize, this is a directory)"));
|
2008-04-15 02:40:58 +08:00
|
|
|
|
2008-05-08 16:54:20 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Code Generator Options
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
GenerateDebugInfo("g",
|
|
|
|
llvm::cl::desc("Generate source level debug information"));
|
|
|
|
|
2008-04-15 02:40:58 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Diagnostic Options
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-09-27 03:42:19 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
VerifyDiagnostics("verify",
|
2008-05-08 16:28:14 +08:00
|
|
|
llvm::cl::desc("Verify emitted diagnostics and warnings"));
|
2007-09-27 03:42:19 +08:00
|
|
|
|
2008-03-27 14:17:42 +08:00
|
|
|
static llvm::cl::opt<std::string>
|
|
|
|
HTMLDiag("html-diags",
|
|
|
|
llvm::cl::desc("Generate HTML to report diagnostics"),
|
|
|
|
llvm::cl::value_desc("HTML directory"));
|
|
|
|
|
2008-08-06 07:33:20 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
NoShowColumn("fno-show-column",
|
|
|
|
llvm::cl::desc("Do not include column number on diagnostics"));
|
|
|
|
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
NoCaretDiagnostics("fno-caret-diagnostics",
|
|
|
|
llvm::cl::desc("Do not include source line and caret with"
|
|
|
|
" diagnostics"));
|
|
|
|
|
|
|
|
|
2008-04-15 02:40:58 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-10-24 07:36:29 +08:00
|
|
|
// C++ Visualization.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static llvm::cl::opt<std::string>
|
|
|
|
InheritanceViewCls("cxx-inheritance-view",
|
|
|
|
llvm::cl::value_desc("class name"),
|
|
|
|
llvm::cl::desc("View C++ inhertance for a specified class"));
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Analyzer Options.
|
2008-04-15 02:40:58 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static llvm::cl::opt<bool>
|
2008-08-28 06:31:43 +08:00
|
|
|
VisualizeEGDot("analyzer-viz-egraph-graphviz",
|
|
|
|
llvm::cl::desc("Display exploded graph using GraphViz"));
|
2008-04-15 02:40:58 +08:00
|
|
|
|
|
|
|
static llvm::cl::opt<bool>
|
2008-08-28 06:31:43 +08:00
|
|
|
VisualizeEGUbi("analyzer-viz-egraph-ubigraph",
|
|
|
|
llvm::cl::desc("Display exploded graph using Ubigraph"));
|
|
|
|
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
AnalyzeAll("analyzer-opt-analyze-headers",
|
2008-04-15 02:40:58 +08:00
|
|
|
llvm::cl::desc("Force the static analyzer to analyze "
|
2008-05-08 16:28:14 +08:00
|
|
|
"functions defined in header files"));
|
2008-04-15 02:40:58 +08:00
|
|
|
|
2008-07-02 08:03:09 +08:00
|
|
|
static llvm::cl::list<Analyses>
|
2008-10-24 09:04:59 +08:00
|
|
|
AnalysisList(llvm::cl::desc("SCA Checks/Analyses:"),
|
2008-07-02 08:03:09 +08:00
|
|
|
llvm::cl::values(
|
2008-07-15 08:46:02 +08:00
|
|
|
#define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE)\
|
2008-07-15 07:41:13 +08:00
|
|
|
clEnumValN(NAME, CMDFLAG, DESC),
|
|
|
|
#include "Analyses.def"
|
|
|
|
clEnumValEnd));
|
2008-07-02 08:03:09 +08:00
|
|
|
|
2008-10-24 09:04:59 +08:00
|
|
|
static llvm::cl::opt<AnalysisStores>
|
|
|
|
AnalysisStoreOpt(llvm::cl::desc("SCA Low-Level Options (Store):"),
|
|
|
|
llvm::cl::init(BasicStoreModel),
|
|
|
|
llvm::cl::values(
|
|
|
|
#define ANALYSIS_STORE(NAME, CMDFLAG, DESC)\
|
|
|
|
clEnumValN(NAME##Model, "analyzer-store-" CMDFLAG, DESC),
|
|
|
|
#include "Analyses.def"
|
|
|
|
clEnumValEnd));
|
|
|
|
|
2008-11-04 07:18:07 +08:00
|
|
|
static llvm::cl::opt<AnalysisDiagClients>
|
|
|
|
AnalysisDiagOpt(llvm::cl::desc("SCA Output Options:"),
|
|
|
|
llvm::cl::init(PD_HTML),
|
|
|
|
llvm::cl::values(
|
|
|
|
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN)\
|
|
|
|
clEnumValN(PD_##NAME, "analyzer-output-" CMDFLAG, DESC),
|
|
|
|
#include "Analyses.def"
|
|
|
|
clEnumValEnd));
|
|
|
|
|
2006-10-17 13:16:26 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Language Options
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
enum LangKind {
|
|
|
|
langkind_unspecified,
|
|
|
|
langkind_c,
|
|
|
|
langkind_c_cpp,
|
2008-10-23 01:29:21 +08:00
|
|
|
langkind_asm_cpp,
|
2008-10-21 08:54:44 +08:00
|
|
|
langkind_c_pch,
|
2006-10-17 13:16:26 +08:00
|
|
|
langkind_cxx,
|
|
|
|
langkind_cxx_cpp,
|
|
|
|
langkind_objc,
|
|
|
|
langkind_objc_cpp,
|
2008-10-21 08:54:44 +08:00
|
|
|
langkind_objc_pch,
|
2006-10-17 13:16:26 +08:00
|
|
|
langkind_objcxx,
|
|
|
|
langkind_objcxx_cpp
|
|
|
|
};
|
|
|
|
|
|
|
|
/* TODO: GCC also accepts:
|
|
|
|
c-header c++-header objective-c-header objective-c++-header
|
2008-10-23 01:29:21 +08:00
|
|
|
assembler
|
2006-10-17 13:16:26 +08:00
|
|
|
ada, f77*, ratfor (!), f95, java, treelang
|
|
|
|
*/
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::opt<LangKind>
|
|
|
|
BaseLang("x", llvm::cl::desc("Base language to compile"),
|
|
|
|
llvm::cl::init(langkind_unspecified),
|
|
|
|
llvm::cl::values(clEnumValN(langkind_c, "c", "C"),
|
2006-10-17 13:16:26 +08:00
|
|
|
clEnumValN(langkind_cxx, "c++", "C++"),
|
|
|
|
clEnumValN(langkind_objc, "objective-c", "Objective C"),
|
|
|
|
clEnumValN(langkind_objcxx,"objective-c++","Objective C++"),
|
|
|
|
clEnumValN(langkind_c_cpp, "c-cpp-output",
|
|
|
|
"Preprocessed C"),
|
2008-10-23 01:29:21 +08:00
|
|
|
clEnumValN(langkind_asm_cpp, "assembler-with-cpp",
|
|
|
|
"Preprocessed asm"),
|
2006-10-17 13:16:26 +08:00
|
|
|
clEnumValN(langkind_cxx_cpp, "c++-cpp-output",
|
2008-10-21 08:54:44 +08:00
|
|
|
"Preprocessed C++"),
|
2006-10-17 13:16:26 +08:00
|
|
|
clEnumValN(langkind_objc_cpp, "objective-c-cpp-output",
|
|
|
|
"Preprocessed Objective C"),
|
|
|
|
clEnumValN(langkind_objcxx_cpp,"objective-c++-cpp-output",
|
|
|
|
"Preprocessed Objective C++"),
|
2008-10-21 08:54:44 +08:00
|
|
|
clEnumValN(langkind_c_pch,"c-header",
|
|
|
|
"Precompiled C header"),
|
|
|
|
clEnumValN(langkind_objc_pch, "objective-c-header",
|
|
|
|
"Precompiled Objective C header"),
|
2006-10-17 13:16:26 +08:00
|
|
|
clEnumValEnd));
|
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
LangObjC("ObjC", llvm::cl::desc("Set base language to Objective-C"),
|
|
|
|
llvm::cl::Hidden);
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
LangObjCXX("ObjC++", llvm::cl::desc("Set base language to Objective-C++"),
|
|
|
|
llvm::cl::Hidden);
|
2006-10-17 13:16:26 +08:00
|
|
|
|
2007-12-06 07:49:08 +08:00
|
|
|
/// InitializeBaseLanguage - Handle the -x foo options.
|
|
|
|
static void InitializeBaseLanguage() {
|
|
|
|
if (LangObjC)
|
|
|
|
BaseLang = langkind_objc;
|
|
|
|
else if (LangObjCXX)
|
|
|
|
BaseLang = langkind_objcxx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LangKind GetLanguage(const std::string &Filename) {
|
|
|
|
if (BaseLang != langkind_unspecified)
|
|
|
|
return BaseLang;
|
|
|
|
|
|
|
|
std::string::size_type DotPos = Filename.rfind('.');
|
|
|
|
|
|
|
|
if (DotPos == std::string::npos) {
|
|
|
|
BaseLang = langkind_c; // Default to C if no extension.
|
2008-01-05 03:12:28 +08:00
|
|
|
return langkind_c;
|
2006-10-17 13:16:26 +08:00
|
|
|
}
|
|
|
|
|
2007-12-06 07:49:08 +08:00
|
|
|
std::string Ext = std::string(Filename.begin()+DotPos+1, Filename.end());
|
|
|
|
// C header: .h
|
|
|
|
// C++ header: .hh or .H;
|
|
|
|
// assembler no preprocessing: .s
|
|
|
|
// assembler: .S
|
|
|
|
if (Ext == "c")
|
|
|
|
return langkind_c;
|
2008-10-29 04:33:42 +08:00
|
|
|
else if (Ext == "S")
|
2008-10-23 01:29:21 +08:00
|
|
|
return langkind_asm_cpp;
|
2007-12-06 07:49:08 +08:00
|
|
|
else if (Ext == "i")
|
|
|
|
return langkind_c_cpp;
|
|
|
|
else if (Ext == "ii")
|
|
|
|
return langkind_cxx_cpp;
|
|
|
|
else if (Ext == "m")
|
|
|
|
return langkind_objc;
|
|
|
|
else if (Ext == "mi")
|
|
|
|
return langkind_objc_cpp;
|
|
|
|
else if (Ext == "mm" || Ext == "M")
|
|
|
|
return langkind_objcxx;
|
|
|
|
else if (Ext == "mii")
|
|
|
|
return langkind_objcxx_cpp;
|
|
|
|
else if (Ext == "C" || Ext == "cc" || Ext == "cpp" || Ext == "CPP" ||
|
|
|
|
Ext == "c++" || Ext == "cp" || Ext == "cxx")
|
|
|
|
return langkind_cxx;
|
|
|
|
else
|
|
|
|
return langkind_c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-21 08:54:44 +08:00
|
|
|
static void InitializeCOptions(LangOptions &Options) {
|
|
|
|
// Do nothing.
|
|
|
|
}
|
|
|
|
|
|
|
|
static void InitializeObjCOptions(LangOptions &Options) {
|
|
|
|
Options.ObjC1 = Options.ObjC2 = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool InitializeLangOptions(LangOptions &Options, LangKind LK){
|
2006-10-17 13:16:26 +08:00
|
|
|
// FIXME: implement -fpreprocessed mode.
|
|
|
|
bool NoPreprocess = false;
|
2008-10-21 08:54:44 +08:00
|
|
|
bool PCH = false;
|
2006-10-17 13:16:26 +08:00
|
|
|
|
2007-12-06 07:49:08 +08:00
|
|
|
switch (LK) {
|
2006-10-17 13:16:26 +08:00
|
|
|
default: assert(0 && "Unknown language kind!");
|
2008-10-21 08:54:44 +08:00
|
|
|
case langkind_c_pch:
|
|
|
|
InitializeCOptions(Options);
|
|
|
|
PCH = true;
|
|
|
|
break;
|
2008-10-23 01:29:21 +08:00
|
|
|
case langkind_asm_cpp:
|
|
|
|
// FALLTHROUGH
|
2006-10-17 13:16:26 +08:00
|
|
|
case langkind_c_cpp:
|
|
|
|
NoPreprocess = true;
|
|
|
|
// FALLTHROUGH
|
|
|
|
case langkind_c:
|
2008-10-21 08:54:44 +08:00
|
|
|
InitializeCOptions(Options);
|
2006-10-17 13:16:26 +08:00
|
|
|
break;
|
|
|
|
case langkind_cxx_cpp:
|
|
|
|
NoPreprocess = true;
|
|
|
|
// FALLTHROUGH
|
|
|
|
case langkind_cxx:
|
|
|
|
Options.CPlusPlus = 1;
|
|
|
|
break;
|
2008-10-21 08:54:44 +08:00
|
|
|
case langkind_objc_pch:
|
|
|
|
InitializeObjCOptions(Options);
|
|
|
|
PCH = true;
|
|
|
|
break;
|
2006-10-17 13:16:26 +08:00
|
|
|
case langkind_objc_cpp:
|
|
|
|
NoPreprocess = true;
|
|
|
|
// FALLTHROUGH
|
|
|
|
case langkind_objc:
|
2008-10-21 08:54:44 +08:00
|
|
|
InitializeObjCOptions(Options);
|
2006-10-17 13:16:26 +08:00
|
|
|
break;
|
|
|
|
case langkind_objcxx_cpp:
|
|
|
|
NoPreprocess = true;
|
|
|
|
// FALLTHROUGH
|
|
|
|
case langkind_objcxx:
|
|
|
|
Options.ObjC1 = Options.ObjC2 = 1;
|
|
|
|
Options.CPlusPlus = 1;
|
|
|
|
break;
|
|
|
|
}
|
2008-10-21 08:54:44 +08:00
|
|
|
|
|
|
|
return PCH;
|
2006-10-17 13:16:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// LangStds - Language standards we support.
|
|
|
|
enum LangStds {
|
|
|
|
lang_unspecified,
|
|
|
|
lang_c89, lang_c94, lang_c99,
|
2008-09-04 05:22:16 +08:00
|
|
|
lang_gnu_START,
|
|
|
|
lang_gnu89 = lang_gnu_START, lang_gnu99,
|
2007-07-16 12:18:29 +08:00
|
|
|
lang_cxx98, lang_gnucxx98,
|
|
|
|
lang_cxx0x, lang_gnucxx0x
|
2006-10-17 13:16:26 +08:00
|
|
|
};
|
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::opt<LangStds>
|
|
|
|
LangStd("std", llvm::cl::desc("Language standard to compile for"),
|
|
|
|
llvm::cl::init(lang_unspecified),
|
|
|
|
llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
|
2006-11-21 09:21:07 +08:00
|
|
|
clEnumValN(lang_c89, "c90", "ISO C 1990"),
|
2006-10-17 13:16:26 +08:00
|
|
|
clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
|
|
|
|
clEnumValN(lang_c94, "iso9899:199409",
|
|
|
|
"ISO C 1990 with amendment 1"),
|
|
|
|
clEnumValN(lang_c99, "c99", "ISO C 1999"),
|
|
|
|
// clEnumValN(lang_c99, "c9x", "ISO C 1999"),
|
|
|
|
clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
|
|
|
|
// clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
|
|
|
|
clEnumValN(lang_gnu89, "gnu89",
|
|
|
|
"ISO C 1990 with GNU extensions (default for C)"),
|
|
|
|
clEnumValN(lang_gnu99, "gnu99",
|
|
|
|
"ISO C 1999 with GNU extensions"),
|
|
|
|
clEnumValN(lang_gnu99, "gnu9x",
|
|
|
|
"ISO C 1999 with GNU extensions"),
|
|
|
|
clEnumValN(lang_cxx98, "c++98",
|
|
|
|
"ISO C++ 1998 with amendments"),
|
|
|
|
clEnumValN(lang_gnucxx98, "gnu++98",
|
|
|
|
"ISO C++ 1998 with amendments and GNU "
|
|
|
|
"extensions (default for C++)"),
|
2007-07-16 12:18:29 +08:00
|
|
|
clEnumValN(lang_cxx0x, "c++0x",
|
|
|
|
"Upcoming ISO C++ 200x with amendments"),
|
|
|
|
clEnumValN(lang_gnucxx0x, "gnu++0x",
|
|
|
|
"Upcoming ISO C++ 200x with amendments and GNU "
|
|
|
|
"extensions (default for C++)"),
|
2006-10-17 13:16:26 +08:00
|
|
|
clEnumValEnd));
|
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::opt<bool>
|
2006-12-04 15:48:37 +08:00
|
|
|
NoOperatorNames("fno-operator-names",
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::cl::desc("Do not treat C++ operator name keywords as "
|
|
|
|
"synonyms for operators"));
|
2006-12-04 15:48:37 +08:00
|
|
|
|
2007-10-15 10:50:23 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
PascalStrings("fpascal-strings",
|
|
|
|
llvm::cl::desc("Recognize and construct Pascal-style "
|
|
|
|
"string literals"));
|
2008-02-07 11:50:06 +08:00
|
|
|
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
MSExtensions("fms-extensions",
|
|
|
|
llvm::cl::desc("Accept some non-standard constructs used in "
|
2008-05-08 16:28:14 +08:00
|
|
|
"Microsoft header files "));
|
2007-11-28 13:34:05 +08:00
|
|
|
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
WritableStrings("fwritable-strings",
|
2008-05-08 16:28:14 +08:00
|
|
|
llvm::cl::desc("Store string literals as writable data"));
|
2007-11-30 12:21:22 +08:00
|
|
|
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
LaxVectorConversions("flax-vector-conversions",
|
|
|
|
llvm::cl::desc("Allow implicit conversions between vectors"
|
|
|
|
" with a different number of elements or "
|
2008-05-08 16:28:14 +08:00
|
|
|
"different element types"));
|
2008-04-29 12:37:03 +08:00
|
|
|
|
2008-08-12 01:36:14 +08:00
|
|
|
// FIXME: This (and all GCC -f options) really come in -f... and
|
|
|
|
// -fno-... forms, and additionally support automagic behavior when
|
|
|
|
// they are not defined. For example, -fexceptions defaults to on or
|
|
|
|
// off depending on the language. We should support this behavior in
|
|
|
|
// some form (perhaps just add a facility for distinguishing when an
|
|
|
|
// has its default value from when it has been set to its default
|
|
|
|
// value).
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
Exceptions("fexceptions",
|
|
|
|
llvm::cl::desc("Enable support for exception handling."));
|
|
|
|
|
2008-08-12 05:35:06 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
GNURuntime("fgnu-runtime",
|
2008-10-21 08:54:44 +08:00
|
|
|
llvm::cl::desc("Generate output compatible with the standard GNU "
|
|
|
|
"Objective-C runtime."));
|
2008-08-12 05:35:06 +08:00
|
|
|
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
NeXTRuntime("fnext-runtime",
|
2008-10-21 08:54:44 +08:00
|
|
|
llvm::cl::desc("Generate output compatible with the NeXT "
|
|
|
|
"runtime."));
|
2008-08-12 05:35:06 +08:00
|
|
|
|
2008-09-04 05:22:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences."));
|
|
|
|
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
Ansi("ansi", llvm::cl::desc("Equivalent to specifying -std=c89."));
|
|
|
|
|
2006-10-17 13:16:26 +08:00
|
|
|
// FIXME: add:
|
|
|
|
// -fdollars-in-identifiers
|
2007-10-15 10:50:23 +08:00
|
|
|
// -fpascal-strings
|
2008-08-23 16:43:39 +08:00
|
|
|
static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
|
|
|
|
TargetInfo *Target) {
|
2008-09-04 05:22:16 +08:00
|
|
|
|
|
|
|
if (Ansi) // "The -ansi option is equivalent to -std=c89."
|
|
|
|
LangStd = lang_c89;
|
|
|
|
|
2006-10-17 13:16:26 +08:00
|
|
|
if (LangStd == lang_unspecified) {
|
|
|
|
// Based on the base language, pick one.
|
2007-12-06 07:49:08 +08:00
|
|
|
switch (LK) {
|
2006-10-17 13:16:26 +08:00
|
|
|
default: assert(0 && "Unknown base language");
|
|
|
|
case langkind_c:
|
2008-10-23 01:29:21 +08:00
|
|
|
case langkind_asm_cpp:
|
2006-10-17 13:16:26 +08:00
|
|
|
case langkind_c_cpp:
|
2008-10-21 08:54:44 +08:00
|
|
|
case langkind_c_pch:
|
2006-10-17 13:16:26 +08:00
|
|
|
case langkind_objc:
|
|
|
|
case langkind_objc_cpp:
|
2008-10-21 08:54:44 +08:00
|
|
|
case langkind_objc_pch:
|
2007-05-04 05:03:48 +08:00
|
|
|
LangStd = lang_gnu99;
|
2006-10-17 13:16:26 +08:00
|
|
|
break;
|
|
|
|
case langkind_cxx:
|
|
|
|
case langkind_cxx_cpp:
|
|
|
|
case langkind_objcxx:
|
|
|
|
case langkind_objcxx_cpp:
|
|
|
|
LangStd = lang_gnucxx98;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (LangStd) {
|
|
|
|
default: assert(0 && "Unknown language standard!");
|
|
|
|
|
|
|
|
// Fall through from newer standards to older ones. This isn't really right.
|
|
|
|
// FIXME: Enable specifically the right features based on the language stds.
|
2007-07-16 12:18:29 +08:00
|
|
|
case lang_gnucxx0x:
|
|
|
|
case lang_cxx0x:
|
|
|
|
Options.CPlusPlus0x = 1;
|
|
|
|
// FALL THROUGH
|
2006-10-17 13:16:26 +08:00
|
|
|
case lang_gnucxx98:
|
|
|
|
case lang_cxx98:
|
|
|
|
Options.CPlusPlus = 1;
|
2006-12-04 15:48:37 +08:00
|
|
|
Options.CXXOperatorNames = !NoOperatorNames;
|
2007-11-15 15:30:50 +08:00
|
|
|
Options.Boolean = 1;
|
2006-10-17 13:16:26 +08:00
|
|
|
// FALL THROUGH.
|
|
|
|
case lang_gnu99:
|
|
|
|
case lang_c99:
|
|
|
|
Options.C99 = 1;
|
|
|
|
Options.HexFloats = 1;
|
|
|
|
// FALL THROUGH.
|
|
|
|
case lang_gnu89:
|
|
|
|
Options.BCPLComment = 1; // Only for C99/C++.
|
|
|
|
// FALL THROUGH.
|
|
|
|
case lang_c94:
|
2008-02-25 12:01:39 +08:00
|
|
|
Options.Digraphs = 1; // C94, C99, C++.
|
|
|
|
// FALL THROUGH.
|
2006-10-17 13:16:26 +08:00
|
|
|
case lang_c89:
|
|
|
|
break;
|
|
|
|
}
|
2008-09-11 12:21:06 +08:00
|
|
|
|
|
|
|
if (Options.CPlusPlus) {
|
|
|
|
Options.C99 = 0;
|
|
|
|
Options.HexFloats = (LangStd == lang_gnucxx98 || LangStd==lang_gnucxx0x);
|
|
|
|
}
|
2006-10-17 13:16:26 +08:00
|
|
|
|
2008-04-05 14:32:51 +08:00
|
|
|
if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
|
|
|
|
Options.ImplicitInt = 1;
|
|
|
|
else
|
|
|
|
Options.ImplicitInt = 0;
|
2008-09-04 05:22:16 +08:00
|
|
|
|
|
|
|
// Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs or -ansi
|
|
|
|
// is specified, or -std is set to a conforming mode.
|
|
|
|
Options.Trigraphs = LangStd < lang_gnu_START || Trigraphs ? 1 : 0;
|
|
|
|
|
2006-10-17 13:16:26 +08:00
|
|
|
Options.DollarIdents = 1; // FIXME: Really a target property.
|
2007-10-15 10:50:23 +08:00
|
|
|
Options.PascalStrings = PascalStrings;
|
2008-02-07 11:50:06 +08:00
|
|
|
Options.Microsoft = MSExtensions;
|
2007-11-28 13:34:05 +08:00
|
|
|
Options.WritableStrings = WritableStrings;
|
2007-11-30 12:21:22 +08:00
|
|
|
Options.LaxVectorConversions = LaxVectorConversions;
|
2008-08-12 01:36:14 +08:00
|
|
|
Options.Exceptions = Exceptions;
|
2008-08-12 05:35:06 +08:00
|
|
|
|
|
|
|
if (NeXTRuntime) {
|
|
|
|
Options.NeXTRuntime = 1;
|
|
|
|
} else if (GNURuntime) {
|
|
|
|
Options.NeXTRuntime = 0;
|
|
|
|
} else {
|
2008-08-23 16:43:39 +08:00
|
|
|
Options.NeXTRuntime = Target->useNeXTRuntimeAsDefault();
|
2008-08-12 05:35:06 +08:00
|
|
|
}
|
2008-11-22 09:04:48 +08:00
|
|
|
|
|
|
|
if (Options.CPlusPlus)
|
|
|
|
Options.Blocks = 0;
|
2006-10-17 13:16:26 +08:00
|
|
|
}
|
2006-06-18 13:43:12 +08:00
|
|
|
|
2008-04-29 12:37:03 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
ObjCExclusiveGC("fobjc-gc-only",
|
|
|
|
llvm::cl::desc("Use GC exclusively for Objective-C related "
|
2008-05-08 16:28:14 +08:00
|
|
|
"memory management"));
|
2008-04-29 12:37:03 +08:00
|
|
|
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
ObjCEnableGC("fobjc-gc",
|
2008-08-06 07:33:20 +08:00
|
|
|
llvm::cl::desc("Enable Objective-C garbage collection"));
|
2008-04-29 12:37:03 +08:00
|
|
|
|
|
|
|
void InitializeGCMode(LangOptions &Options) {
|
|
|
|
if (ObjCExclusiveGC)
|
|
|
|
Options.setGCMode(LangOptions::GCOnly);
|
|
|
|
else if (ObjCEnableGC)
|
|
|
|
Options.setGCMode(LangOptions::HybridGC);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Our DiagnosticClient implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// FIXME: Werror should take a list of things, -Werror=foo,bar
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
WarningsAsErrors("Werror", llvm::cl::desc("Treat all warnings as errors"));
|
2006-06-18 13:43:12 +08:00
|
|
|
|
2008-05-29 23:36:45 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
SilenceWarnings("w", llvm::cl::desc("Do not emit any warnings"));
|
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::opt<bool>
|
2007-07-07 07:09:18 +08:00
|
|
|
WarnOnExtensions("pedantic", llvm::cl::init(false),
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::cl::desc("Issue a warning on uses of GCC extensions"));
|
2006-06-18 13:43:12 +08:00
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::opt<bool>
|
2006-06-18 13:43:12 +08:00
|
|
|
ErrorOnExtensions("pedantic-errors",
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::cl::desc("Issue an error on uses of GCC extensions"));
|
2006-06-18 13:43:12 +08:00
|
|
|
|
2008-09-13 02:10:20 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
SuppressSystemWarnings("suppress-system-warnings",
|
2008-10-01 04:49:53 +08:00
|
|
|
llvm::cl::desc("Suppress warnings issued in system headers"),
|
2008-09-13 02:10:20 +08:00
|
|
|
llvm::cl::init(true));
|
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::opt<bool>
|
2006-07-05 08:55:08 +08:00
|
|
|
WarnUnusedMacros("Wunused_macros",
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::cl::desc("Warn for unused macros in the main translation unit"));
|
2006-07-05 08:55:08 +08:00
|
|
|
|
2007-11-14 02:37:02 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
WarnFloatEqual("Wfloat-equal",
|
2008-05-08 16:28:14 +08:00
|
|
|
llvm::cl::desc("Warn about equality comparisons of floating point values"));
|
2007-11-14 02:37:02 +08:00
|
|
|
|
2007-12-18 01:50:07 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
WarnNoFormatNonLiteral("Wno-format-nonliteral",
|
2008-05-08 16:28:14 +08:00
|
|
|
llvm::cl::desc("Do not warn about non-literal format strings"));
|
2007-12-18 01:50:07 +08:00
|
|
|
|
2008-01-24 01:19:46 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
WarnUndefMacros("Wundef",
|
|
|
|
llvm::cl::desc("Warn on use of undefined macros in #if's"));
|
|
|
|
|
2008-05-06 05:18:06 +08:00
|
|
|
static llvm::cl::opt<bool>
|
2008-05-31 00:42:02 +08:00
|
|
|
WarnImplicitFunctionDeclaration("Wimplicit-function-declaration",
|
|
|
|
llvm::cl::desc("Warn about uses of implicitly defined functions"));
|
2008-01-24 01:19:46 +08:00
|
|
|
|
2008-10-21 18:37:50 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
WarnNoStrictSelectorMatch("Wno-strict-selector-match",
|
|
|
|
llvm::cl::desc("Do not warn about duplicate methods that have the same size and alignment"),
|
|
|
|
llvm::cl::init(true));
|
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
/// InitializeDiagnostics - Initialize the diagnostic object, based on the
|
|
|
|
/// current command line option settings.
|
|
|
|
static void InitializeDiagnostics(Diagnostic &Diags) {
|
2008-05-29 23:36:45 +08:00
|
|
|
Diags.setIgnoreAllWarnings(SilenceWarnings);
|
2006-06-18 13:43:12 +08:00
|
|
|
Diags.setWarningsAsErrors(WarningsAsErrors);
|
|
|
|
Diags.setWarnOnExtensions(WarnOnExtensions);
|
|
|
|
Diags.setErrorOnExtensions(ErrorOnExtensions);
|
2006-07-05 08:55:08 +08:00
|
|
|
|
2008-09-13 02:10:20 +08:00
|
|
|
// Suppress warnings in system headers unless requested not to.
|
|
|
|
Diags.setSuppressSystemWarnings(SuppressSystemWarnings);
|
|
|
|
|
2006-07-05 08:55:08 +08:00
|
|
|
// Silence the "macro is not used" warning unless requested.
|
|
|
|
if (!WarnUnusedMacros)
|
|
|
|
Diags.setDiagnosticMapping(diag::pp_macro_not_used, diag::MAP_IGNORE);
|
2007-11-14 02:37:02 +08:00
|
|
|
|
|
|
|
// Silence "floating point comparison" warnings unless requested.
|
|
|
|
if (!WarnFloatEqual)
|
|
|
|
Diags.setDiagnosticMapping(diag::warn_floatingpoint_eq, diag::MAP_IGNORE);
|
2007-12-18 01:50:07 +08:00
|
|
|
|
|
|
|
// Silence "format string is not a string literal" warnings if requested
|
|
|
|
if (WarnNoFormatNonLiteral)
|
2007-12-18 01:50:39 +08:00
|
|
|
Diags.setDiagnosticMapping(diag::warn_printf_not_string_constant,
|
|
|
|
diag::MAP_IGNORE);
|
2008-01-24 01:19:46 +08:00
|
|
|
if (!WarnUndefMacros)
|
|
|
|
Diags.setDiagnosticMapping(diag::warn_pp_undef_identifier,diag::MAP_IGNORE);
|
2008-02-12 06:40:08 +08:00
|
|
|
|
2008-05-06 05:18:06 +08:00
|
|
|
if (!WarnImplicitFunctionDeclaration)
|
|
|
|
Diags.setDiagnosticMapping(diag::warn_implicit_function_decl,
|
|
|
|
diag::MAP_IGNORE);
|
|
|
|
|
2008-02-12 06:40:08 +08:00
|
|
|
if (MSExtensions) // MS allows unnamed struct/union fields.
|
|
|
|
Diags.setDiagnosticMapping(diag::w_no_declarators, diag::MAP_IGNORE);
|
2008-05-05 07:52:02 +08:00
|
|
|
|
|
|
|
// If -pedantic-errors is set, turn extensions that warn by default into
|
|
|
|
// errors.
|
|
|
|
if (ErrorOnExtensions) {
|
|
|
|
Diags.setDiagnosticMapping(diag::warn_hex_escape_too_large,
|
|
|
|
diag::MAP_ERROR);
|
|
|
|
Diags.setDiagnosticMapping(diag::warn_octal_escape_too_large,
|
|
|
|
diag::MAP_ERROR);
|
|
|
|
}
|
2006-06-18 13:43:12 +08:00
|
|
|
}
|
|
|
|
|
2008-02-19 05:21:23 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Analysis-specific options.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static llvm::cl::opt<std::string>
|
|
|
|
AnalyzeSpecificFunction("analyze-function",
|
2008-05-08 16:28:14 +08:00
|
|
|
llvm::cl::desc("Run analysis on specific function"));
|
2008-02-19 05:21:23 +08:00
|
|
|
|
2008-03-08 06:58:01 +08:00
|
|
|
static llvm::cl::opt<bool>
|
2008-04-11 06:16:52 +08:00
|
|
|
TrimGraph("trim-egraph",
|
2008-05-08 16:28:14 +08:00
|
|
|
llvm::cl::desc("Only show error-related paths in the analysis graph"));
|
2008-03-08 06:58:01 +08:00
|
|
|
|
2007-12-04 06:06:55 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Target Triple Processing.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static llvm::cl::opt<std::string>
|
|
|
|
TargetTriple("triple",
|
2008-05-08 16:28:14 +08:00
|
|
|
llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)"));
|
2007-12-04 06:06:55 +08:00
|
|
|
|
2008-03-05 09:18:20 +08:00
|
|
|
static llvm::cl::opt<std::string>
|
2008-05-08 16:28:14 +08:00
|
|
|
Arch("arch", llvm::cl::desc("Specify target architecture (e.g. i686)"));
|
2007-12-04 06:06:55 +08:00
|
|
|
|
2008-09-30 09:13:12 +08:00
|
|
|
static llvm::cl::opt<std::string>
|
|
|
|
MacOSVersionMin("mmacosx-version-min",
|
|
|
|
llvm::cl::desc("Specify target Mac OS/X version (e.g. 10.5)"));
|
|
|
|
|
2008-10-01 04:16:56 +08:00
|
|
|
// If -mmacosx-version-min=10.3.9 is specified, change the triple from being
|
|
|
|
// something like powerpc-apple-darwin9 to powerpc-apple-darwin7
|
|
|
|
static void HandleMacOSVersionMin(std::string &Triple) {
|
|
|
|
std::string::size_type DarwinDashIdx = Triple.find("-darwin");
|
|
|
|
if (DarwinDashIdx == std::string::npos) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"-mmacosx-version-min only valid for darwin (Mac OS/X) targets\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
unsigned DarwinNumIdx = DarwinDashIdx + strlen("-darwin");
|
|
|
|
|
|
|
|
// Remove the number.
|
|
|
|
Triple.resize(DarwinNumIdx);
|
|
|
|
|
|
|
|
// Validate that MacOSVersionMin is a 'version number', starting with 10.[3-9]
|
|
|
|
bool MacOSVersionMinIsInvalid = false;
|
|
|
|
int VersionNum = 0;
|
|
|
|
if (MacOSVersionMin.size() < 4 ||
|
|
|
|
MacOSVersionMin.substr(0, 3) != "10." ||
|
|
|
|
!isdigit(MacOSVersionMin[3])) {
|
|
|
|
MacOSVersionMinIsInvalid = true;
|
|
|
|
} else {
|
|
|
|
const char *Start = MacOSVersionMin.c_str()+3;
|
|
|
|
char *End = 0;
|
|
|
|
VersionNum = (int)strtol(Start, &End, 10);
|
|
|
|
|
2008-10-01 04:30:12 +08:00
|
|
|
// The version number must be in the range 0-9.
|
|
|
|
MacOSVersionMinIsInvalid = (unsigned)VersionNum > 9;
|
|
|
|
|
2008-10-01 04:16:56 +08:00
|
|
|
// Turn MacOSVersionMin into a darwin number: e.g. 10.3.9 is 3 -> 7.
|
|
|
|
Triple += llvm::itostr(VersionNum+4);
|
|
|
|
|
2008-10-01 04:30:12 +08:00
|
|
|
if (End[0] == '.' && isdigit(End[1]) && End[2] == '\0') { // 10.4.7 is ok.
|
|
|
|
// Add the period piece (.7) to the end of the triple. This gives us
|
|
|
|
// something like ...-darwin8.7
|
2008-10-01 04:16:56 +08:00
|
|
|
Triple += End;
|
|
|
|
} else if (End[0] != '\0') { // "10.4" is ok. 10.4x is not.
|
|
|
|
MacOSVersionMinIsInvalid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MacOSVersionMinIsInvalid) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"-mmacosx-version-min=%s is invalid, expected something like '10.4'.\n",
|
|
|
|
MacOSVersionMin.c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CreateTargetTriple - Process the various options that affect the target
|
|
|
|
/// triple and build a final aggregate triple that we are compiling for.
|
2008-03-09 09:35:13 +08:00
|
|
|
static std::string CreateTargetTriple() {
|
2007-12-04 06:06:55 +08:00
|
|
|
// Initialize base triple. If a -triple option has been specified, use
|
|
|
|
// that triple. Otherwise, default to the host triple.
|
2007-12-12 13:01:48 +08:00
|
|
|
std::string Triple = TargetTriple;
|
2008-10-02 09:21:33 +08:00
|
|
|
if (Triple.empty()) {
|
|
|
|
Triple = LLVM_HOSTTRIPLE;
|
|
|
|
|
|
|
|
// On darwin, we want to update the version to match that of the
|
|
|
|
// host.
|
|
|
|
std::string::size_type DarwinDashIdx = Triple.find("-darwin");
|
|
|
|
if (DarwinDashIdx != std::string::npos) {
|
|
|
|
Triple.resize(DarwinDashIdx + strlen("-darwin"));
|
|
|
|
|
|
|
|
Triple += llvm::sys::osVersion();
|
|
|
|
}
|
|
|
|
}
|
2007-12-04 06:06:55 +08:00
|
|
|
|
2008-03-09 09:35:13 +08:00
|
|
|
// If -arch foo was specified, remove the architecture from the triple we have
|
|
|
|
// so far and replace it with the specified one.
|
2008-09-30 09:13:12 +08:00
|
|
|
if (!Arch.empty()) {
|
|
|
|
// Decompose the base triple into "arch" and suffix.
|
|
|
|
std::string::size_type FirstDashIdx = Triple.find('-');
|
2008-03-09 09:35:13 +08:00
|
|
|
|
2008-09-30 09:13:12 +08:00
|
|
|
if (FirstDashIdx == std::string::npos) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Malformed target triple: \"%s\" ('-' could not be found).\n",
|
|
|
|
Triple.c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
2007-12-04 06:06:55 +08:00
|
|
|
|
2008-09-30 09:13:12 +08:00
|
|
|
Triple = Arch + std::string(Triple.begin()+FirstDashIdx, Triple.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
// If -mmacosx-version-min=10.3.9 is specified, change the triple from being
|
|
|
|
// something like powerpc-apple-darwin9 to powerpc-apple-darwin7
|
2008-10-01 04:16:56 +08:00
|
|
|
if (!MacOSVersionMin.empty())
|
|
|
|
HandleMacOSVersionMin(Triple);
|
2007-12-04 06:06:55 +08:00
|
|
|
|
2008-09-30 09:13:12 +08:00
|
|
|
return Triple;
|
2007-12-04 06:06:55 +08:00
|
|
|
}
|
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Preprocessor Initialization
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// FIXME: Preprocessor builtins to support.
|
|
|
|
// -A... - Play with #assertions
|
|
|
|
// -undef - Undefine all predefined macros
|
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::list<std::string>
|
|
|
|
D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
|
|
|
|
llvm::cl::desc("Predefine the specified macro"));
|
|
|
|
static llvm::cl::list<std::string>
|
|
|
|
U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
|
|
|
|
llvm::cl::desc("Undefine the specified macro"));
|
2006-06-18 13:43:12 +08:00
|
|
|
|
2008-01-10 09:53:41 +08:00
|
|
|
static llvm::cl::list<std::string>
|
|
|
|
ImplicitIncludes("include", llvm::cl::value_desc("file"),
|
|
|
|
llvm::cl::desc("Include file before parsing"));
|
|
|
|
|
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
// Append a #define line to Buf for Macro. Macro should be of the form XXX,
|
|
|
|
// in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
|
|
|
|
// "#define XXX Y z W". To get a #define with no value, use "XXX=".
|
|
|
|
static void DefineBuiltinMacro(std::vector<char> &Buf, const char *Macro,
|
|
|
|
const char *Command = "#define ") {
|
|
|
|
Buf.insert(Buf.end(), Command, Command+strlen(Command));
|
|
|
|
if (const char *Equal = strchr(Macro, '=')) {
|
|
|
|
// Turn the = into ' '.
|
|
|
|
Buf.insert(Buf.end(), Macro, Equal);
|
|
|
|
Buf.push_back(' ');
|
|
|
|
Buf.insert(Buf.end(), Equal+1, Equal+strlen(Equal));
|
|
|
|
} else {
|
|
|
|
// Push "macroname 1".
|
|
|
|
Buf.insert(Buf.end(), Macro, Macro+strlen(Macro));
|
|
|
|
Buf.push_back(' ');
|
|
|
|
Buf.push_back('1');
|
|
|
|
}
|
|
|
|
Buf.push_back('\n');
|
|
|
|
}
|
|
|
|
|
2008-01-10 09:53:41 +08:00
|
|
|
/// AddImplicitInclude - Add an implicit #include of the specified file to the
|
|
|
|
/// predefines buffer.
|
|
|
|
static void AddImplicitInclude(std::vector<char> &Buf, const std::string &File){
|
|
|
|
const char *Inc = "#include \"";
|
|
|
|
Buf.insert(Buf.end(), Inc, Inc+strlen(Inc));
|
|
|
|
Buf.insert(Buf.end(), File.begin(), File.end());
|
|
|
|
Buf.push_back('"');
|
|
|
|
Buf.push_back('\n');
|
|
|
|
}
|
|
|
|
|
2007-10-10 06:10:18 +08:00
|
|
|
|
|
|
|
/// InitializePreprocessor - Initialize the preprocessor getting it and the
|
2008-04-20 07:25:44 +08:00
|
|
|
/// environment ready to process a single file. This returns true on error.
|
2007-10-10 06:10:18 +08:00
|
|
|
///
|
2008-04-20 07:25:44 +08:00
|
|
|
static bool InitializePreprocessor(Preprocessor &PP,
|
|
|
|
bool InitializeSourceMgr,
|
|
|
|
const std::string &InFile) {
|
2007-12-16 04:48:40 +08:00
|
|
|
FileManager &FileMgr = PP.getFileManager();
|
2007-10-10 06:10:18 +08:00
|
|
|
|
|
|
|
// Figure out where to get and map in the main file.
|
2007-12-16 04:48:40 +08:00
|
|
|
SourceManager &SourceMgr = PP.getSourceManager();
|
2008-04-18 06:31:54 +08:00
|
|
|
|
|
|
|
if (InitializeSourceMgr) {
|
|
|
|
if (InFile != "-") {
|
|
|
|
const FileEntry *File = FileMgr.getFile(InFile);
|
|
|
|
if (File) SourceMgr.createMainFileID(File, SourceLocation());
|
|
|
|
if (SourceMgr.getMainFileID() == 0) {
|
|
|
|
fprintf(stderr, "Error reading '%s'!\n",InFile.c_str());
|
2008-04-20 07:25:44 +08:00
|
|
|
return true;
|
2008-04-18 06:31:54 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
|
|
|
|
if (SB) SourceMgr.createMainFileIDForMemBuffer(SB);
|
|
|
|
if (SourceMgr.getMainFileID() == 0) {
|
|
|
|
fprintf(stderr, "Error reading standard input! Empty?\n");
|
2008-04-20 07:25:44 +08:00
|
|
|
return true;
|
2008-04-18 06:31:54 +08:00
|
|
|
}
|
2007-10-10 06:10:18 +08:00
|
|
|
}
|
2006-06-18 13:43:12 +08:00
|
|
|
}
|
2008-04-14 22:41:57 +08:00
|
|
|
|
2008-04-20 07:09:31 +08:00
|
|
|
std::vector<char> PredefineBuffer;
|
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
// Add macros from the command line.
|
2008-04-14 22:41:57 +08:00
|
|
|
unsigned d = 0, D = D_macros.size();
|
|
|
|
unsigned u = 0, U = U_macros.size();
|
|
|
|
while (d < D || u < U) {
|
|
|
|
if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
|
|
|
|
DefineBuiltinMacro(PredefineBuffer, D_macros[d++].c_str());
|
|
|
|
else
|
|
|
|
DefineBuiltinMacro(PredefineBuffer, U_macros[u++].c_str(), "#undef ");
|
|
|
|
}
|
|
|
|
|
2008-01-10 09:53:41 +08:00
|
|
|
// FIXME: Read any files specified by -imacros.
|
|
|
|
|
|
|
|
// Add implicit #includes from -include.
|
|
|
|
for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
|
|
|
|
AddImplicitInclude(PredefineBuffer, ImplicitIncludes[i]);
|
2007-10-10 06:10:18 +08:00
|
|
|
|
2008-04-20 07:09:31 +08:00
|
|
|
// Null terminate PredefinedBuffer and add it.
|
2007-10-10 06:10:18 +08:00
|
|
|
PredefineBuffer.push_back(0);
|
2008-04-20 07:09:31 +08:00
|
|
|
PP.setPredefines(&PredefineBuffer[0]);
|
2007-10-10 06:10:18 +08:00
|
|
|
|
|
|
|
// Once we've read this, we're done.
|
2008-04-20 07:25:44 +08:00
|
|
|
return false;
|
2006-06-18 13:43:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Preprocessor include path information.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// This tool exports a large number of command line options to control how the
|
|
|
|
// preprocessor searches for header files. At root, however, the Preprocessor
|
|
|
|
// object takes a very simple interface: a list of directories to search for
|
|
|
|
//
|
|
|
|
// FIXME: -nostdinc,-nostdinc++
|
2007-08-27 01:47:35 +08:00
|
|
|
// FIXME: -imultilib
|
2006-06-18 13:43:12 +08:00
|
|
|
//
|
2008-01-10 09:53:41 +08:00
|
|
|
// FIXME: -imacros
|
2006-06-18 13:43:12 +08:00
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories"));
|
2006-06-18 13:43:12 +08:00
|
|
|
|
|
|
|
// Various command line options. These four add directories to each chain.
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::list<std::string>
|
|
|
|
F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
|
|
|
|
llvm::cl::desc("Add directory to framework include search path"));
|
|
|
|
static llvm::cl::list<std::string>
|
|
|
|
I_dirs("I", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
|
|
|
|
llvm::cl::desc("Add directory to include search path"));
|
|
|
|
static llvm::cl::list<std::string>
|
|
|
|
idirafter_dirs("idirafter", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
|
|
|
|
llvm::cl::desc("Add directory to AFTER include search path"));
|
|
|
|
static llvm::cl::list<std::string>
|
|
|
|
iquote_dirs("iquote", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
|
|
|
|
llvm::cl::desc("Add directory to QUOTE include search path"));
|
|
|
|
static llvm::cl::list<std::string>
|
|
|
|
isystem_dirs("isystem", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
|
|
|
|
llvm::cl::desc("Add directory to SYSTEM include search path"));
|
2006-06-18 13:43:12 +08:00
|
|
|
|
|
|
|
// These handle -iprefix/-iwithprefix/-iwithprefixbefore.
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::list<std::string>
|
|
|
|
iprefix_vals("iprefix", llvm::cl::value_desc("prefix"), llvm::cl::Prefix,
|
|
|
|
llvm::cl::desc("Set the -iwithprefix/-iwithprefixbefore prefix"));
|
|
|
|
static llvm::cl::list<std::string>
|
|
|
|
iwithprefix_vals("iwithprefix", llvm::cl::value_desc("dir"), llvm::cl::Prefix,
|
|
|
|
llvm::cl::desc("Set directory to SYSTEM include search path with prefix"));
|
|
|
|
static llvm::cl::list<std::string>
|
|
|
|
iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"),
|
|
|
|
llvm::cl::Prefix,
|
|
|
|
llvm::cl::desc("Set directory to include search path with prefix"));
|
2006-06-18 13:43:12 +08:00
|
|
|
|
2007-08-27 01:47:35 +08:00
|
|
|
static llvm::cl::opt<std::string>
|
|
|
|
isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"),
|
|
|
|
llvm::cl::desc("Set the system root directory (usually /)"));
|
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
// Finally, implement the code that groks the options above.
|
2008-03-01 16:07:28 +08:00
|
|
|
|
2006-10-18 13:34:33 +08:00
|
|
|
/// InitializeIncludePaths - Process the -I options and set them in the
|
|
|
|
/// HeaderSearch object.
|
2008-08-22 17:25:22 +08:00
|
|
|
void InitializeIncludePaths(const char *Argv0, HeaderSearch &Headers,
|
|
|
|
FileManager &FM, const LangOptions &Lang) {
|
|
|
|
InitHeaderSearch Init(Headers, Verbose, isysroot);
|
|
|
|
|
2008-05-31 08:27:00 +08:00
|
|
|
// Handle -I... and -F... options, walking the lists in parallel.
|
|
|
|
unsigned Iidx = 0, Fidx = 0;
|
|
|
|
while (Iidx < I_dirs.size() && Fidx < F_dirs.size()) {
|
|
|
|
if (I_dirs.getPosition(Iidx) < F_dirs.getPosition(Fidx)) {
|
2008-08-22 17:25:22 +08:00
|
|
|
Init.AddPath(I_dirs[Iidx], InitHeaderSearch::Angled, false, true, false);
|
2008-05-31 08:27:00 +08:00
|
|
|
++Iidx;
|
|
|
|
} else {
|
2008-08-22 17:25:22 +08:00
|
|
|
Init.AddPath(F_dirs[Fidx], InitHeaderSearch::Angled, false, true, true);
|
2008-05-31 08:27:00 +08:00
|
|
|
++Fidx;
|
|
|
|
}
|
|
|
|
}
|
2006-10-22 15:34:56 +08:00
|
|
|
|
2008-05-31 08:27:00 +08:00
|
|
|
// Consume what's left from whatever list was longer.
|
|
|
|
for (; Iidx != I_dirs.size(); ++Iidx)
|
2008-08-22 17:25:22 +08:00
|
|
|
Init.AddPath(I_dirs[Iidx], InitHeaderSearch::Angled, false, true, false);
|
2008-05-31 08:27:00 +08:00
|
|
|
for (; Fidx != F_dirs.size(); ++Fidx)
|
2008-08-22 17:25:22 +08:00
|
|
|
Init.AddPath(F_dirs[Fidx], InitHeaderSearch::Angled, false, true, true);
|
2006-06-18 13:43:12 +08:00
|
|
|
|
|
|
|
// Handle -idirafter... options.
|
|
|
|
for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i)
|
2008-08-22 17:25:22 +08:00
|
|
|
Init.AddPath(idirafter_dirs[i], InitHeaderSearch::After,
|
|
|
|
false, true, false);
|
2006-06-18 13:43:12 +08:00
|
|
|
|
|
|
|
// Handle -iquote... options.
|
|
|
|
for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i)
|
2008-08-22 17:25:22 +08:00
|
|
|
Init.AddPath(iquote_dirs[i], InitHeaderSearch::Quoted, false, true, false);
|
2006-06-18 13:43:12 +08:00
|
|
|
|
|
|
|
// Handle -isystem... options.
|
|
|
|
for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i)
|
2008-08-22 17:25:22 +08:00
|
|
|
Init.AddPath(isystem_dirs[i], InitHeaderSearch::System, false, true, false);
|
2006-06-18 13:43:12 +08:00
|
|
|
|
|
|
|
// Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in
|
|
|
|
// parallel, processing the values in order of occurance to get the right
|
|
|
|
// prefixes.
|
|
|
|
{
|
|
|
|
std::string Prefix = ""; // FIXME: this isn't the correct default prefix.
|
|
|
|
unsigned iprefix_idx = 0;
|
|
|
|
unsigned iwithprefix_idx = 0;
|
|
|
|
unsigned iwithprefixbefore_idx = 0;
|
|
|
|
bool iprefix_done = iprefix_vals.empty();
|
|
|
|
bool iwithprefix_done = iwithprefix_vals.empty();
|
|
|
|
bool iwithprefixbefore_done = iwithprefixbefore_vals.empty();
|
|
|
|
while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) {
|
|
|
|
if (!iprefix_done &&
|
|
|
|
(iwithprefix_done ||
|
|
|
|
iprefix_vals.getPosition(iprefix_idx) <
|
|
|
|
iwithprefix_vals.getPosition(iwithprefix_idx)) &&
|
|
|
|
(iwithprefixbefore_done ||
|
|
|
|
iprefix_vals.getPosition(iprefix_idx) <
|
|
|
|
iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
|
|
|
|
Prefix = iprefix_vals[iprefix_idx];
|
|
|
|
++iprefix_idx;
|
|
|
|
iprefix_done = iprefix_idx == iprefix_vals.size();
|
|
|
|
} else if (!iwithprefix_done &&
|
|
|
|
(iwithprefixbefore_done ||
|
|
|
|
iwithprefix_vals.getPosition(iwithprefix_idx) <
|
|
|
|
iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
|
2008-08-22 17:25:22 +08:00
|
|
|
Init.AddPath(Prefix+iwithprefix_vals[iwithprefix_idx],
|
|
|
|
InitHeaderSearch::System, false, false, false);
|
2006-06-18 13:43:12 +08:00
|
|
|
++iwithprefix_idx;
|
|
|
|
iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size();
|
|
|
|
} else {
|
2008-08-22 17:25:22 +08:00
|
|
|
Init.AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx],
|
|
|
|
InitHeaderSearch::Angled, false, false, false);
|
2006-06-18 13:43:12 +08:00
|
|
|
++iwithprefixbefore_idx;
|
|
|
|
iwithprefixbefore_done =
|
|
|
|
iwithprefixbefore_idx == iwithprefixbefore_vals.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-01 16:07:28 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
Init.AddDefaultEnvVarPaths(Lang);
|
2008-03-01 16:07:28 +08:00
|
|
|
|
2008-03-03 11:16:03 +08:00
|
|
|
// Add the clang headers, which are relative to the clang driver.
|
|
|
|
llvm::sys::Path MainExecutablePath =
|
2008-03-03 13:57:43 +08:00
|
|
|
llvm::sys::Path::GetMainExecutable(Argv0,
|
|
|
|
(void*)(intptr_t)InitializeIncludePaths);
|
2008-03-03 11:16:03 +08:00
|
|
|
if (!MainExecutablePath.isEmpty()) {
|
|
|
|
MainExecutablePath.eraseComponent(); // Remove /clang from foo/bin/clang
|
|
|
|
MainExecutablePath.eraseComponent(); // Remove /bin from foo/bin
|
|
|
|
MainExecutablePath.appendComponent("Headers"); // Get foo/Headers
|
2008-08-22 17:25:22 +08:00
|
|
|
Init.AddPath(MainExecutablePath.c_str(), InitHeaderSearch::System,
|
|
|
|
false, false, false);
|
2008-03-03 11:16:03 +08:00
|
|
|
}
|
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
if (!nostdinc)
|
|
|
|
Init.AddDefaultSystemIncludePaths(Lang);
|
2006-06-18 13:43:12 +08:00
|
|
|
|
|
|
|
// Now that we have collected all of the include paths, merge them all
|
|
|
|
// together and tell the preprocessor about them.
|
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
Init.Realize();
|
2006-06-18 13:43:12 +08:00
|
|
|
}
|
|
|
|
|
2008-04-18 05:38:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Driver PreprocessorFactory - For lazily generating preprocessors ...
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class VISIBILITY_HIDDEN DriverPreprocessorFactory : public PreprocessorFactory {
|
2008-04-18 06:31:54 +08:00
|
|
|
const std::string &InFile;
|
2008-04-18 05:38:34 +08:00
|
|
|
Diagnostic &Diags;
|
|
|
|
const LangOptions &LangInfo;
|
|
|
|
TargetInfo &Target;
|
|
|
|
SourceManager &SourceMgr;
|
|
|
|
HeaderSearch &HeaderInfo;
|
2008-04-18 06:31:54 +08:00
|
|
|
bool InitializeSourceMgr;
|
|
|
|
|
2008-04-18 05:38:34 +08:00
|
|
|
public:
|
2008-04-18 06:31:54 +08:00
|
|
|
DriverPreprocessorFactory(const std::string &infile,
|
|
|
|
Diagnostic &diags, const LangOptions &opts,
|
2008-04-18 05:38:34 +08:00
|
|
|
TargetInfo &target, SourceManager &SM,
|
|
|
|
HeaderSearch &Headers)
|
2008-04-18 06:31:54 +08:00
|
|
|
: InFile(infile), Diags(diags), LangInfo(opts), Target(target),
|
|
|
|
SourceMgr(SM), HeaderInfo(Headers), InitializeSourceMgr(true) {}
|
|
|
|
|
2008-04-18 05:38:34 +08:00
|
|
|
|
|
|
|
virtual ~DriverPreprocessorFactory() {}
|
|
|
|
|
|
|
|
virtual Preprocessor* CreatePreprocessor() {
|
2008-04-18 06:31:54 +08:00
|
|
|
Preprocessor* PP = new Preprocessor(Diags, LangInfo, Target,
|
|
|
|
SourceMgr, HeaderInfo);
|
|
|
|
|
2008-04-20 07:25:44 +08:00
|
|
|
if (InitializePreprocessor(*PP, InitializeSourceMgr, InFile)) {
|
2008-04-18 06:31:54 +08:00
|
|
|
delete PP;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-10-25 06:12:41 +08:00
|
|
|
/// FIXME: PP can only handle one callback
|
|
|
|
if (ProgAction != PrintPreprocessedInput) {
|
|
|
|
const char* ErrStr;
|
|
|
|
bool DFG = CreateDependencyFileGen(PP, OutputFile, InFile, ErrStr);
|
|
|
|
if (!DFG && ErrStr) {
|
2008-10-26 04:19:34 +08:00
|
|
|
fprintf(stderr, "%s", ErrStr);
|
2008-10-25 06:12:41 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-18 06:31:54 +08:00
|
|
|
InitializeSourceMgr = false;
|
|
|
|
return PP;
|
2008-04-18 05:38:34 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2006-06-18 13:43:12 +08:00
|
|
|
|
2006-07-31 09:59:18 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-08-17 14:28:25 +08:00
|
|
|
// Basic Parser driver
|
2006-07-31 09:59:18 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-04-20 07:25:44 +08:00
|
|
|
static void ParseFile(Preprocessor &PP, MinimalAction *PA) {
|
2006-07-31 09:59:18 +08:00
|
|
|
Parser P(PP, *PA);
|
2007-12-20 06:51:13 +08:00
|
|
|
PP.EnterMainSourceFile();
|
2006-07-31 09:59:18 +08:00
|
|
|
|
2006-08-17 14:28:25 +08:00
|
|
|
// Parsing the specified input file.
|
2006-07-31 09:59:18 +08:00
|
|
|
P.ParseTranslationUnit();
|
2006-08-17 14:28:25 +08:00
|
|
|
delete PA;
|
|
|
|
}
|
2006-07-31 09:59:18 +08:00
|
|
|
|
2008-10-23 13:50:47 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Code generation options
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
OptSize("Os",
|
|
|
|
llvm::cl::desc("Optimize for size"));
|
|
|
|
|
|
|
|
// It might be nice to add bounds to the CommandLine library directly.
|
|
|
|
struct OptLevelParser : public llvm::cl::parser<unsigned> {
|
|
|
|
bool parse(llvm::cl::Option &O, const char *ArgName,
|
|
|
|
const std::string &Arg, unsigned &Val) {
|
|
|
|
if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val))
|
|
|
|
return true;
|
|
|
|
// FIXME: Support -O4.
|
|
|
|
if (Val > 3)
|
|
|
|
return O.error(": '" + Arg + "' invalid optimization level!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static llvm::cl::opt<unsigned, false, OptLevelParser>
|
|
|
|
OptLevel("O", llvm::cl::Prefix,
|
|
|
|
llvm::cl::desc("Optimization level"),
|
|
|
|
llvm::cl::init(0));
|
|
|
|
|
|
|
|
static void InitializeCompileOptions(CompileOptions &Opts) {
|
|
|
|
Opts.OptimizeSize = OptSize;
|
2008-10-29 15:56:11 +08:00
|
|
|
if (OptSize) {
|
|
|
|
// -Os implies -O2
|
|
|
|
// FIXME: Diagnose conflicting options.
|
|
|
|
Opts.OptimizationLevel = 2;
|
|
|
|
} else {
|
|
|
|
Opts.OptimizationLevel = OptLevel;
|
|
|
|
}
|
2008-10-29 11:42:18 +08:00
|
|
|
|
|
|
|
// FIXME: There are llvm-gcc options to control these selectively.
|
|
|
|
Opts.InlineFunctions = (Opts.OptimizationLevel > 1);
|
|
|
|
Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
|
|
|
|
Opts.SimplifyLibCalls = 1;
|
2008-10-31 17:34:21 +08:00
|
|
|
|
|
|
|
#ifdef NDEBUG
|
|
|
|
Opts.VerifyModule = 0;
|
|
|
|
#endif
|
2008-10-23 13:50:47 +08:00
|
|
|
}
|
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Main driver
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-12-06 02:27:04 +08:00
|
|
|
/// CreateASTConsumer - Create the ASTConsumer for the corresponding program
|
|
|
|
/// action. These consumers can operate on both ASTs that are freshly
|
|
|
|
/// parsed from source files as well as those deserialized from Bitcode.
|
2007-12-20 06:24:34 +08:00
|
|
|
static ASTConsumer* CreateASTConsumer(const std::string& InFile,
|
2007-12-13 08:37:31 +08:00
|
|
|
Diagnostic& Diag, FileManager& FileMgr,
|
2008-02-06 09:42:25 +08:00
|
|
|
const LangOptions& LangOpts,
|
2008-04-16 14:11:58 +08:00
|
|
|
Preprocessor *PP,
|
2008-08-06 02:50:11 +08:00
|
|
|
PreprocessorFactory *PPF) {
|
2007-12-06 02:27:04 +08:00
|
|
|
switch (ProgAction) {
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case ASTPrint:
|
|
|
|
return CreateASTPrinter();
|
|
|
|
|
|
|
|
case ASTDump:
|
|
|
|
return CreateASTDumper();
|
|
|
|
|
|
|
|
case ASTView:
|
2008-03-19 05:19:49 +08:00
|
|
|
return CreateASTViewer();
|
|
|
|
|
|
|
|
case EmitHTML:
|
2008-04-18 06:31:54 +08:00
|
|
|
return CreateHTMLPrinter(OutputFile, Diag, PP, PPF);
|
2008-07-03 02:23:21 +08:00
|
|
|
|
2008-10-24 07:36:29 +08:00
|
|
|
case InheritanceView:
|
|
|
|
return CreateInheritanceViewer(InheritanceViewCls);
|
|
|
|
|
2007-12-06 02:27:04 +08:00
|
|
|
case TestSerialization:
|
2008-06-04 23:55:15 +08:00
|
|
|
return CreateSerializationTest(Diag, FileMgr);
|
2007-12-06 02:27:04 +08:00
|
|
|
|
2008-10-22 07:49:24 +08:00
|
|
|
case EmitAssembly:
|
2007-12-06 02:27:04 +08:00
|
|
|
case EmitLLVM:
|
2008-10-23 13:50:47 +08:00
|
|
|
case EmitBC: {
|
|
|
|
BackendAction Act;
|
|
|
|
if (ProgAction == EmitAssembly) {
|
|
|
|
Act = Backend_EmitAssembly;
|
|
|
|
} else if (ProgAction == EmitLLVM) {
|
|
|
|
Act = Backend_EmitLL;
|
|
|
|
} else {
|
|
|
|
Act = Backend_EmitBC;
|
|
|
|
}
|
|
|
|
CompileOptions Opts;
|
|
|
|
InitializeCompileOptions(Opts);
|
|
|
|
return CreateBackendConsumer(Act, Diag, LangOpts, Opts,
|
2008-10-22 07:49:24 +08:00
|
|
|
InFile, OutputFile, GenerateDebugInfo);
|
2008-10-23 13:50:47 +08:00
|
|
|
}
|
2007-12-24 09:52:34 +08:00
|
|
|
|
2007-12-20 01:25:59 +08:00
|
|
|
case SerializeAST:
|
2007-12-13 08:37:31 +08:00
|
|
|
// FIXME: Allow user to tailor where the file is written.
|
2008-06-04 23:55:15 +08:00
|
|
|
return CreateASTSerializer(InFile, OutputFile, Diag);
|
2007-12-13 08:37:31 +08:00
|
|
|
|
2008-04-15 06:03:09 +08:00
|
|
|
case RewriteObjC:
|
2008-03-22 08:08:40 +08:00
|
|
|
return CreateCodeRewriterTest(InFile, OutputFile, Diag, LangOpts);
|
2008-09-18 22:10:13 +08:00
|
|
|
|
|
|
|
case RewriteBlocks:
|
|
|
|
return CreateBlockRewriter(InFile, OutputFile, Diag, LangOpts);
|
2008-07-02 08:03:09 +08:00
|
|
|
|
|
|
|
case RunAnalysis:
|
|
|
|
assert (!AnalysisList.empty());
|
|
|
|
return CreateAnalysisConsumer(&AnalysisList[0],
|
|
|
|
&AnalysisList[0]+AnalysisList.size(),
|
2008-11-04 07:18:07 +08:00
|
|
|
AnalysisStoreOpt, AnalysisDiagOpt,
|
2008-07-02 08:03:09 +08:00
|
|
|
Diag, PP, PPF, LangOpts,
|
|
|
|
AnalyzeSpecificFunction,
|
2008-08-28 06:31:43 +08:00
|
|
|
OutputFile, VisualizeEGDot, VisualizeEGUbi,
|
|
|
|
TrimGraph, AnalyzeAll);
|
2007-12-06 02:27:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-16 05:20:00 +08:00
|
|
|
/// ProcessInputFile - Process a single input file with the specified state.
|
|
|
|
///
|
2008-04-18 06:31:54 +08:00
|
|
|
static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
|
2008-10-21 08:54:44 +08:00
|
|
|
const std::string &InFile, ProgActions PA) {
|
2008-08-08 10:46:37 +08:00
|
|
|
llvm::OwningPtr<ASTConsumer> Consumer;
|
2007-07-22 14:05:44 +08:00
|
|
|
bool ClearSourceMgr = false;
|
2007-09-27 02:39:29 +08:00
|
|
|
|
2008-10-21 08:54:44 +08:00
|
|
|
switch (PA) {
|
2007-06-27 11:19:45 +08:00
|
|
|
default:
|
2008-08-08 10:46:37 +08:00
|
|
|
Consumer.reset(CreateASTConsumer(InFile, PP.getDiagnostics(),
|
|
|
|
PP.getFileManager(), PP.getLangOptions(),
|
|
|
|
&PP, &PPF));
|
2007-12-06 02:27:04 +08:00
|
|
|
|
|
|
|
if (!Consumer) {
|
|
|
|
fprintf(stderr, "Unexpected program action!\n");
|
2008-10-05 07:42:49 +08:00
|
|
|
HadErrors = true;
|
2007-12-06 02:27:04 +08:00
|
|
|
return;
|
|
|
|
}
|
2007-12-20 06:24:34 +08:00
|
|
|
|
2007-12-06 02:27:04 +08:00
|
|
|
break;
|
|
|
|
|
2008-10-12 13:03:36 +08:00
|
|
|
case DumpRawTokens: {
|
|
|
|
SourceManager &SM = PP.getSourceManager();
|
|
|
|
std::pair<const char*,const char*> File =
|
|
|
|
SM.getBufferData(SM.getMainFileID());
|
|
|
|
// Start lexing the specified input file.
|
|
|
|
Lexer RawLex(SourceLocation::getFileLoc(SM.getMainFileID(), 0),
|
|
|
|
PP.getLangOptions(), File.first, File.second);
|
|
|
|
RawLex.SetKeepWhitespaceMode(true);
|
|
|
|
|
|
|
|
Token RawTok;
|
|
|
|
|
|
|
|
RawLex.LexFromRawLexer(RawTok);
|
|
|
|
while (RawTok.isNot(tok::eof)) {
|
|
|
|
PP.DumpToken(RawTok, true);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
RawLex.LexFromRawLexer(RawTok);
|
|
|
|
}
|
|
|
|
ClearSourceMgr = true;
|
|
|
|
break;
|
|
|
|
}
|
2006-07-31 09:59:18 +08:00
|
|
|
case DumpTokens: { // Token dump mode.
|
2007-07-21 00:59:19 +08:00
|
|
|
Token Tok;
|
2008-10-12 13:03:36 +08:00
|
|
|
// Start preprocessing the specified input file.
|
2007-12-20 06:51:13 +08:00
|
|
|
PP.EnterMainSourceFile();
|
2006-06-18 13:43:12 +08:00
|
|
|
do {
|
2006-06-18 14:48:37 +08:00
|
|
|
PP.Lex(Tok);
|
2006-07-31 09:59:18 +08:00
|
|
|
PP.DumpToken(Tok, true);
|
2007-06-23 06:43:15 +08:00
|
|
|
fprintf(stderr, "\n");
|
2007-10-10 02:03:42 +08:00
|
|
|
} while (Tok.isNot(tok::eof));
|
2007-07-22 14:05:44 +08:00
|
|
|
ClearSourceMgr = true;
|
2006-06-18 13:43:12 +08:00
|
|
|
break;
|
|
|
|
}
|
2006-07-31 09:59:18 +08:00
|
|
|
case RunPreprocessorOnly: { // Just lex as fast as we can, no output.
|
2007-07-21 00:59:19 +08:00
|
|
|
Token Tok;
|
2006-07-29 14:35:08 +08:00
|
|
|
// Start parsing the specified input file.
|
2007-12-20 06:51:13 +08:00
|
|
|
PP.EnterMainSourceFile();
|
2006-06-18 13:43:12 +08:00
|
|
|
do {
|
2006-06-18 14:48:37 +08:00
|
|
|
PP.Lex(Tok);
|
2007-10-10 02:03:42 +08:00
|
|
|
} while (Tok.isNot(tok::eof));
|
2007-07-22 14:05:44 +08:00
|
|
|
ClearSourceMgr = true;
|
2006-06-18 13:43:12 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-10-21 08:54:44 +08:00
|
|
|
|
|
|
|
case GeneratePCH: {
|
|
|
|
CacheTokens(PP, OutputFile);
|
|
|
|
ClearSourceMgr = true;
|
|
|
|
break;
|
|
|
|
}
|
2006-07-31 09:59:18 +08:00
|
|
|
|
|
|
|
case PrintPreprocessedInput: // -E mode.
|
2008-01-28 07:55:11 +08:00
|
|
|
DoPrintPreprocessedInput(PP, OutputFile);
|
2007-07-22 14:05:44 +08:00
|
|
|
ClearSourceMgr = true;
|
2006-07-31 09:59:18 +08:00
|
|
|
break;
|
2008-05-08 14:52:13 +08:00
|
|
|
|
2006-07-31 09:59:18 +08:00
|
|
|
case ParseNoop: // -parse-noop
|
2008-10-31 16:56:51 +08:00
|
|
|
ParseFile(PP, new MinimalAction(PP));
|
2007-07-22 14:05:44 +08:00
|
|
|
ClearSourceMgr = true;
|
2006-08-17 13:51:27 +08:00
|
|
|
break;
|
2006-11-06 02:00:10 +08:00
|
|
|
|
2006-07-31 09:59:18 +08:00
|
|
|
case ParsePrintCallbacks:
|
2008-10-31 16:56:51 +08:00
|
|
|
ParseFile(PP, CreatePrintParserActionsAction(PP));
|
2007-07-22 14:05:44 +08:00
|
|
|
ClearSourceMgr = true;
|
2006-08-17 13:51:27 +08:00
|
|
|
break;
|
2007-09-27 02:39:29 +08:00
|
|
|
|
2006-11-21 12:07:21 +08:00
|
|
|
case ParseSyntaxOnly: // -fsyntax-only
|
2008-08-08 10:46:37 +08:00
|
|
|
Consumer.reset(new ASTConsumer());
|
2006-08-07 02:29:56 +08:00
|
|
|
break;
|
2008-05-08 14:52:13 +08:00
|
|
|
|
|
|
|
case RewriteMacros:
|
2008-05-10 06:43:24 +08:00
|
|
|
RewriteMacrosInInput(PP, InFile, OutputFile);
|
2008-05-08 14:52:13 +08:00
|
|
|
ClearSourceMgr = true;
|
|
|
|
break;
|
2008-10-12 13:29:20 +08:00
|
|
|
|
|
|
|
case RewriteTest:
|
|
|
|
DoRewriteTest(PP, InFile, OutputFile);
|
|
|
|
ClearSourceMgr = true;
|
|
|
|
break;
|
2007-09-17 03:46:59 +08:00
|
|
|
}
|
2007-09-27 02:39:29 +08:00
|
|
|
|
2008-10-28 06:03:52 +08:00
|
|
|
if (Consumer)
|
2008-10-17 00:54:18 +08:00
|
|
|
ParseAST(PP, Consumer.get(), Stats, !DisableFree);
|
2008-10-28 06:03:52 +08:00
|
|
|
|
|
|
|
if (VerifyDiagnostics)
|
2008-10-28 06:10:13 +08:00
|
|
|
if (CheckDiagnostics(PP))
|
|
|
|
exit(1);
|
2008-02-06 09:42:25 +08:00
|
|
|
|
2006-11-21 13:52:55 +08:00
|
|
|
if (Stats) {
|
2007-12-20 06:24:34 +08:00
|
|
|
fprintf(stderr, "\nSTATISTICS FOR '%s':\n", InFile.c_str());
|
2006-11-21 13:52:55 +08:00
|
|
|
PP.PrintStats();
|
2006-11-21 14:08:20 +08:00
|
|
|
PP.getIdentifierTable().PrintStats();
|
2007-12-16 04:48:40 +08:00
|
|
|
PP.getHeaderSearchInfo().PrintStats();
|
2007-07-22 14:05:44 +08:00
|
|
|
if (ClearSourceMgr)
|
2007-12-16 04:48:40 +08:00
|
|
|
PP.getSourceManager().PrintStats();
|
2007-06-23 06:43:15 +08:00
|
|
|
fprintf(stderr, "\n");
|
2006-11-21 13:52:55 +08:00
|
|
|
}
|
2007-07-22 14:05:44 +08:00
|
|
|
|
|
|
|
// For a multi-file compilation, some things are ok with nuking the source
|
|
|
|
// manager tables, other require stable fileid/macroid's across multiple
|
|
|
|
// files.
|
2007-12-16 04:48:40 +08:00
|
|
|
if (ClearSourceMgr)
|
|
|
|
PP.getSourceManager().clearIDTables();
|
2008-11-11 14:35:39 +08:00
|
|
|
|
|
|
|
if (DisableFree)
|
|
|
|
Consumer.take();
|
2006-11-21 13:52:55 +08:00
|
|
|
}
|
|
|
|
|
2007-12-13 07:41:08 +08:00
|
|
|
static void ProcessSerializedFile(const std::string& InFile, Diagnostic& Diag,
|
|
|
|
FileManager& FileMgr) {
|
|
|
|
|
|
|
|
if (VerifyDiagnostics) {
|
|
|
|
fprintf(stderr, "-verify does not yet work with serialized ASTs.\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::sys::Path Filename(InFile);
|
|
|
|
|
|
|
|
if (!Filename.isValid()) {
|
|
|
|
fprintf(stderr, "serialized file '%s' not available.\n",InFile.c_str());
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2008-04-24 00:25:39 +08:00
|
|
|
llvm::OwningPtr<TranslationUnit> TU(ReadASTBitcodeFile(Filename, FileMgr));
|
2007-12-14 02:11:11 +08:00
|
|
|
|
|
|
|
if (!TU) {
|
|
|
|
fprintf(stderr, "error: file '%s' could not be deserialized\n",
|
|
|
|
InFile.c_str());
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2007-12-20 03:27:38 +08:00
|
|
|
// Observe that we use the source file name stored in the deserialized
|
|
|
|
// translation unit, rather than InFile.
|
2007-12-21 03:47:16 +08:00
|
|
|
llvm::OwningPtr<ASTConsumer>
|
2008-06-04 23:55:15 +08:00
|
|
|
Consumer(CreateASTConsumer(InFile, Diag, FileMgr, TU->getLangOptions(),
|
2008-08-06 02:50:11 +08:00
|
|
|
0, 0));
|
2008-08-11 03:59:06 +08:00
|
|
|
|
2007-12-13 07:41:08 +08:00
|
|
|
if (!Consumer) {
|
|
|
|
fprintf(stderr, "Unsupported program action with serialized ASTs!\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
2008-08-11 03:59:06 +08:00
|
|
|
|
2008-04-24 00:25:39 +08:00
|
|
|
Consumer->Initialize(TU->getContext());
|
2008-08-11 03:59:06 +08:00
|
|
|
|
2008-02-06 09:42:25 +08:00
|
|
|
// FIXME: We need to inform Consumer about completed TagDecls as well.
|
2007-12-13 07:41:08 +08:00
|
|
|
for (TranslationUnit::iterator I=TU->begin(), E=TU->end(); I!=E; ++I)
|
|
|
|
Consumer->HandleTopLevelDecl(*I);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
static llvm::cl::list<std::string>
|
|
|
|
InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>"));
|
2006-11-21 13:52:55 +08:00
|
|
|
|
2007-12-13 07:41:08 +08:00
|
|
|
static bool isSerializedFile(const std::string& InFile) {
|
|
|
|
if (InFile.size() < 4)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const char* s = InFile.c_str()+InFile.size()-4;
|
|
|
|
|
|
|
|
return s[0] == '.' &&
|
|
|
|
s[1] == 'a' &&
|
|
|
|
s[2] == 's' &&
|
|
|
|
s[3] == 't';
|
|
|
|
}
|
|
|
|
|
2007-06-28 12:54:17 +08:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2008-03-03 11:16:03 +08:00
|
|
|
llvm::cl::ParseCommandLineOptions(argc, argv, " llvm clang cfe\n");
|
2007-06-28 12:54:17 +08:00
|
|
|
llvm::sys::PrintStackTraceOnErrorSignal();
|
2006-11-21 13:52:55 +08:00
|
|
|
|
2007-06-28 12:54:17 +08:00
|
|
|
// If no input was specified, read from stdin.
|
|
|
|
if (InputFilenames.empty())
|
|
|
|
InputFilenames.push_back("-");
|
2007-12-12 07:28:38 +08:00
|
|
|
|
2007-06-28 12:54:17 +08:00
|
|
|
// Create a file manager object to provide access to and cache the filesystem.
|
|
|
|
FileManager FileMgr;
|
2006-11-21 13:52:55 +08:00
|
|
|
|
2007-12-12 07:28:38 +08:00
|
|
|
// Create the diagnostic client for reporting errors or for
|
|
|
|
// implementing -verify.
|
2008-08-11 03:59:06 +08:00
|
|
|
DiagnosticClient* TextDiagClient = 0;
|
2008-03-27 14:17:42 +08:00
|
|
|
|
2008-08-08 01:49:57 +08:00
|
|
|
if (!VerifyDiagnostics) {
|
|
|
|
// Print diagnostics to stderr by default.
|
2008-11-19 14:56:25 +08:00
|
|
|
TextDiagClient = new TextDiagnosticPrinter(llvm::errs(),
|
|
|
|
!NoShowColumn,
|
2008-08-08 01:49:57 +08:00
|
|
|
!NoCaretDiagnostics);
|
|
|
|
} else {
|
|
|
|
// When checking diagnostics, just buffer them up.
|
|
|
|
TextDiagClient = new TextDiagnosticBuffer();
|
|
|
|
|
|
|
|
if (InputFilenames.size() != 1) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"-verify only works on single input files for now.\n");
|
|
|
|
return 1;
|
2007-06-28 12:54:17 +08:00
|
|
|
}
|
2007-06-16 05:20:00 +08:00
|
|
|
}
|
2008-08-08 01:49:57 +08:00
|
|
|
|
2007-06-27 11:19:45 +08:00
|
|
|
// Configure our handling of diagnostics.
|
2008-08-08 01:49:57 +08:00
|
|
|
llvm::OwningPtr<DiagnosticClient> DiagClient(TextDiagClient);
|
|
|
|
Diagnostic Diags(DiagClient.get());
|
2007-12-12 07:28:38 +08:00
|
|
|
InitializeDiagnostics(Diags);
|
|
|
|
|
2007-12-06 07:24:17 +08:00
|
|
|
// -I- is a deprecated GCC feature, scan for it and reject it.
|
|
|
|
for (unsigned i = 0, e = I_dirs.size(); i != e; ++i) {
|
|
|
|
if (I_dirs[i] == "-") {
|
2008-11-18 13:05:28 +08:00
|
|
|
Diags.Report(FullSourceLoc(), diag::err_pp_I_dash_not_supported);
|
2007-12-06 07:24:17 +08:00
|
|
|
I_dirs.erase(I_dirs.begin()+i);
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
2008-03-14 14:12:05 +08:00
|
|
|
|
|
|
|
// Get information about the target being compiled for.
|
|
|
|
std::string Triple = CreateTargetTriple();
|
2008-08-08 02:13:12 +08:00
|
|
|
llvm::OwningPtr<TargetInfo> Target(TargetInfo::CreateTargetInfo(Triple));
|
|
|
|
|
2008-03-14 14:12:05 +08:00
|
|
|
if (Target == 0) {
|
|
|
|
fprintf(stderr, "Sorry, I don't know what target this is: %s\n",
|
|
|
|
Triple.c_str());
|
|
|
|
fprintf(stderr, "Please use -triple or -arch.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2007-12-06 07:24:17 +08:00
|
|
|
|
2008-07-02 08:03:09 +08:00
|
|
|
// Are we invoking one or more source analyses?
|
|
|
|
if (!AnalysisList.empty() && ProgAction == ParseSyntaxOnly)
|
|
|
|
ProgAction = RunAnalysis;
|
2008-10-24 07:36:29 +08:00
|
|
|
else if (!InheritanceViewCls.empty()) // C++ visualization?
|
|
|
|
ProgAction = InheritanceView;
|
2008-08-08 01:49:57 +08:00
|
|
|
|
2008-06-07 06:42:39 +08:00
|
|
|
llvm::OwningPtr<SourceManager> SourceMgr;
|
|
|
|
|
2007-06-27 11:19:45 +08:00
|
|
|
for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
|
2007-12-12 07:28:38 +08:00
|
|
|
const std::string &InFile = InputFilenames[i];
|
|
|
|
|
2008-08-08 01:49:57 +08:00
|
|
|
if (isSerializedFile(InFile)) {
|
|
|
|
Diags.setClient(TextDiagClient);
|
2007-12-13 07:41:08 +08:00
|
|
|
ProcessSerializedFile(InFile,Diags,FileMgr);
|
2008-08-08 01:49:57 +08:00
|
|
|
}
|
2007-12-13 07:41:08 +08:00
|
|
|
else {
|
|
|
|
/// Create a SourceManager object. This tracks and owns all the file
|
|
|
|
/// buffers allocated to a translation unit.
|
2008-06-07 06:42:39 +08:00
|
|
|
if (!SourceMgr)
|
|
|
|
SourceMgr.reset(new SourceManager());
|
|
|
|
else
|
|
|
|
SourceMgr->clearIDTables();
|
2007-12-12 07:28:38 +08:00
|
|
|
|
2007-12-13 07:41:08 +08:00
|
|
|
// Initialize language options, inferring file types from input filenames.
|
|
|
|
LangOptions LangInfo;
|
|
|
|
InitializeBaseLanguage();
|
|
|
|
LangKind LK = GetLanguage(InFile);
|
2008-10-21 08:54:44 +08:00
|
|
|
bool PCH = InitializeLangOptions(LangInfo, LK);
|
2008-08-23 16:43:39 +08:00
|
|
|
InitializeLanguageStandard(LangInfo, LK, Target.get());
|
2008-04-29 12:37:03 +08:00
|
|
|
InitializeGCMode(LangInfo);
|
2008-10-21 08:54:44 +08:00
|
|
|
|
2007-12-13 07:41:08 +08:00
|
|
|
// Process the -I options and set them in the HeaderInfo.
|
|
|
|
HeaderSearch HeaderInfo(FileMgr);
|
2008-06-06 09:47:30 +08:00
|
|
|
|
2008-03-03 11:16:03 +08:00
|
|
|
InitializeIncludePaths(argv[0], HeaderInfo, FileMgr, LangInfo);
|
2007-12-13 07:41:08 +08:00
|
|
|
|
|
|
|
// Set up the preprocessor with these options.
|
2008-04-18 06:31:54 +08:00
|
|
|
DriverPreprocessorFactory PPFactory(InFile, Diags, LangInfo, *Target,
|
2008-06-07 06:42:39 +08:00
|
|
|
*SourceMgr.get(), HeaderInfo);
|
2007-12-13 07:41:08 +08:00
|
|
|
|
2008-04-18 05:38:34 +08:00
|
|
|
llvm::OwningPtr<Preprocessor> PP(PPFactory.CreatePreprocessor());
|
|
|
|
|
2008-04-18 06:31:54 +08:00
|
|
|
if (!PP)
|
2007-12-20 06:29:55 +08:00
|
|
|
continue;
|
2008-08-08 01:49:57 +08:00
|
|
|
|
|
|
|
// Create the HTMLDiagnosticsClient if we are using one. Otherwise,
|
|
|
|
// always reset to using TextDiagClient.
|
|
|
|
llvm::OwningPtr<DiagnosticClient> TmpClient;
|
2007-12-20 06:29:55 +08:00
|
|
|
|
2008-08-08 01:49:57 +08:00
|
|
|
if (!HTMLDiag.empty()) {
|
|
|
|
TmpClient.reset(CreateHTMLDiagnosticClient(HTMLDiag, PP.get(),
|
|
|
|
&PPFactory));
|
|
|
|
Diags.setClient(TmpClient.get());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Diags.setClient(TextDiagClient);
|
|
|
|
|
|
|
|
// Process the source file.
|
2008-10-21 08:54:44 +08:00
|
|
|
ProcessInputFile(*PP, PPFactory, InFile, PCH ? GeneratePCH : ProgAction);
|
|
|
|
|
2008-06-07 06:42:39 +08:00
|
|
|
HeaderInfo.ClearFileInfo();
|
2007-12-13 07:41:08 +08:00
|
|
|
|
|
|
|
if (Stats)
|
2008-06-07 06:42:39 +08:00
|
|
|
SourceMgr->PrintStats();
|
2007-12-13 07:41:08 +08:00
|
|
|
}
|
2007-06-27 11:19:45 +08:00
|
|
|
}
|
2008-03-14 14:12:05 +08:00
|
|
|
|
2008-08-08 02:13:12 +08:00
|
|
|
if (unsigned NumDiagnostics = Diags.getNumDiagnostics())
|
2007-06-28 12:54:17 +08:00
|
|
|
fprintf(stderr, "%d diagnostic%s generated.\n", NumDiagnostics,
|
|
|
|
(NumDiagnostics == 1 ? "" : "s"));
|
2006-08-14 06:25:42 +08:00
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
if (Stats) {
|
2006-11-21 14:08:20 +08:00
|
|
|
FileMgr.PrintStats();
|
2007-06-23 06:43:15 +08:00
|
|
|
fprintf(stderr, "\n");
|
2006-06-18 13:43:12 +08:00
|
|
|
}
|
2006-10-25 11:15:08 +08:00
|
|
|
|
2008-10-28 06:10:13 +08:00
|
|
|
// If verifying diagnostics and we reached here, all is well.
|
|
|
|
if (VerifyDiagnostics)
|
|
|
|
return 0;
|
|
|
|
|
2008-10-28 08:38:08 +08:00
|
|
|
// Managed static deconstruction. Useful for making things like
|
|
|
|
// -time-passes usable.
|
|
|
|
llvm::llvm_shutdown();
|
|
|
|
|
2008-10-05 07:42:49 +08:00
|
|
|
return HadErrors || (Diags.getNumErrors() != 0);
|
2006-06-18 13:43:12 +08:00
|
|
|
}
|