aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt1
-rw-r--r--examples/Makefile2
-rw-r--r--examples/PrintFunctionNames/Makefile11
-rw-r--r--examples/PrintFunctionNames/PrintFunctionNames.cpp22
-rw-r--r--examples/PrintFunctionNames/PrintFunctionNames.exports1
-rw-r--r--examples/clang-interpreter/CMakeLists.txt2
-rw-r--r--examples/clang-interpreter/Makefile6
-rw-r--r--examples/clang-interpreter/main.cpp8
-rw-r--r--examples/wpa/CMakeLists.txt1
-rw-r--r--examples/wpa/Makefile4
-rw-r--r--examples/wpa/clang-wpa.cpp13
11 files changed, 48 insertions, 23 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index d2738c69035e..9a32ee406523 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,4 +1,3 @@
add_subdirectory(clang-interpreter)
add_subdirectory(PrintFunctionNames)
-add_subdirectory(wpa)
diff --git a/examples/Makefile b/examples/Makefile
index c4af25263398..8cb431d73916 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -9,6 +9,6 @@
CLANG_LEVEL := ..
-PARALLEL_DIRS := clang-interpreter PrintFunctionNames wpa
+PARALLEL_DIRS := clang-interpreter PrintFunctionNames
include $(CLANG_LEVEL)/Makefile
diff --git a/examples/PrintFunctionNames/Makefile b/examples/PrintFunctionNames/Makefile
index 0ff5189437c7..125ac4854ffc 100644
--- a/examples/PrintFunctionNames/Makefile
+++ b/examples/PrintFunctionNames/Makefile
@@ -10,10 +10,15 @@
CLANG_LEVEL := ../..
LIBRARYNAME = PrintFunctionNames
+# If we don't need RTTI or EH, there's no reason to export anything
+# from the plugin.
+ifneq ($(REQUIRES_RTTI), 1)
+ifneq ($(REQUIRES_EH), 1)
+EXPORTED_SYMBOL_FILE = $(PROJ_SRC_DIR)/PrintFunctionNames.exports
+endif
+endif
+
LINK_LIBS_IN_SHARED = 1
SHARED_LIBRARY = 1
-USEDLIBS = clangIndex.a clangFrontend.a clangDriver.a clangSema.a \
- clangAnalysis.a clangAST.a clangParse.a clangLex.a clangBasic.a
-
include $(CLANG_LEVEL)/Makefile
diff --git a/examples/PrintFunctionNames/PrintFunctionNames.cpp b/examples/PrintFunctionNames/PrintFunctionNames.cpp
index 397cf843fa7f..cc138f56dbba 100644
--- a/examples/PrintFunctionNames/PrintFunctionNames.cpp
+++ b/examples/PrintFunctionNames/PrintFunctionNames.cpp
@@ -15,6 +15,7 @@
#include "clang/Frontend/FrontendPluginRegistry.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/AST.h"
+#include "clang/Frontend/CompilerInstance.h"
#include "llvm/Support/raw_ostream.h"
using namespace clang;
@@ -29,7 +30,7 @@ public:
llvm::errs() << "top-level-decl: \"" << ND->getNameAsString() << "\"\n";
}
}
-};
+};
class PrintFunctionNamesAction : public PluginASTAction {
protected:
@@ -37,15 +38,26 @@ protected:
return new PrintFunctionsConsumer();
}
- bool ParseArgs(const std::vector<std::string>& args) {
- for (unsigned i=0; i<args.size(); ++i)
+ bool ParseArgs(const CompilerInstance &CI,
+ const std::vector<std::string>& args) {
+ for (unsigned i = 0, e = args.size(); i != e; ++i) {
llvm::errs() << "PrintFunctionNames arg = " << args[i] << "\n";
+
+ // Example error handling.
+ if (args[i] == "-an-error") {
+ Diagnostic &D = CI.getDiagnostics();
+ unsigned DiagID = D.getCustomDiagID(
+ Diagnostic::Error, "invalid argument '" + args[i] + "'");
+ D.Report(DiagID);
+ return false;
+ }
+ }
if (args.size() && args[0] == "help")
PrintHelp(llvm::errs());
return true;
}
- void PrintHelp(llvm::raw_ostream& ros) {
+ void PrintHelp(llvm::raw_ostream& ros) {
ros << "Help for PrintFunctionNames plugin goes here\n";
}
@@ -53,5 +65,5 @@ protected:
}
-FrontendPluginRegistry::Add<PrintFunctionNamesAction>
+static FrontendPluginRegistry::Add<PrintFunctionNamesAction>
X("print-fns", "print function names");
diff --git a/examples/PrintFunctionNames/PrintFunctionNames.exports b/examples/PrintFunctionNames/PrintFunctionNames.exports
new file mode 100644
index 000000000000..0ff590d30d7b
--- /dev/null
+++ b/examples/PrintFunctionNames/PrintFunctionNames.exports
@@ -0,0 +1 @@
+_ZN4llvm8Registry*
diff --git a/examples/clang-interpreter/CMakeLists.txt b/examples/clang-interpreter/CMakeLists.txt
index 1aa9b2b59224..73f28bb7a2e7 100644
--- a/examples/clang-interpreter/CMakeLists.txt
+++ b/examples/clang-interpreter/CMakeLists.txt
@@ -2,10 +2,12 @@ set(LLVM_NO_RTTI 1)
set(LLVM_USED_LIBS
clangFrontend
+ clangSerialization
clangDriver
clangCodeGen
clangSema
clangChecker
+ clangIndex
clangAnalysis
clangRewrite
clangAST
diff --git a/examples/clang-interpreter/Makefile b/examples/clang-interpreter/Makefile
index 6fa58d22cbd9..2f5e017af803 100644
--- a/examples/clang-interpreter/Makefile
+++ b/examples/clang-interpreter/Makefile
@@ -17,8 +17,8 @@ TOOL_NO_EXPORTS = 1
LINK_COMPONENTS := jit interpreter nativecodegen bitreader bitwriter ipo \
selectiondag asmparser
-USEDLIBS = clangFrontend.a clangDriver.a clangCodeGen.a clangSema.a \
- clangChecker.a clangAnalysis.a clangRewrite.a clangAST.a \
- clangParse.a clangLex.a clangBasic.a
+USEDLIBS = clangFrontend.a clangSerialization.a clangDriver.a clangCodeGen.a \
+ clangSema.a clangChecker.a clangAnalysis.a clangRewrite.a \
+ clangAST.a clangParse.a clangLex.a clangBasic.a
include $(CLANG_LEVEL)/Makefile
diff --git a/examples/clang-interpreter/main.cpp b/examples/clang-interpreter/main.cpp
index ec4e8619829f..2ccba8b24a85 100644
--- a/examples/clang-interpreter/main.cpp
+++ b/examples/clang-interpreter/main.cpp
@@ -66,11 +66,11 @@ int Execute(llvm::Module *Mod, char * const *envp) {
int main(int argc, const char **argv, char * const *envp) {
void *MainAddr = (void*) (intptr_t) GetExecutablePath;
llvm::sys::Path Path = GetExecutablePath(argv[0]);
- TextDiagnosticPrinter DiagClient(llvm::errs(), DiagnosticOptions());
+ TextDiagnosticPrinter *DiagClient =
+ new TextDiagnosticPrinter(llvm::errs(), DiagnosticOptions());
- Diagnostic Diags(&DiagClient);
- Driver TheDriver(Path.getBasename(), Path.getDirname(),
- llvm::sys::getHostTriple(),
+ Diagnostic Diags(DiagClient);
+ Driver TheDriver(Path.str(), llvm::sys::getHostTriple(),
"a.out", /*IsProduction=*/false, /*CXXIsProduction=*/false,
Diags);
TheDriver.setTitle("clang interpreter");
diff --git a/examples/wpa/CMakeLists.txt b/examples/wpa/CMakeLists.txt
index c2b2ce63a934..13e4298c1f2e 100644
--- a/examples/wpa/CMakeLists.txt
+++ b/examples/wpa/CMakeLists.txt
@@ -6,6 +6,7 @@ set(LLVM_USED_LIBS
clangDriver
clangSema
clangAnalysis
+ clangSerialization
clangChecker
clangRewrite
clangAST
diff --git a/examples/wpa/Makefile b/examples/wpa/Makefile
index bd6ebfdc9bfe..0a70ea6359c8 100644
--- a/examples/wpa/Makefile
+++ b/examples/wpa/Makefile
@@ -17,7 +17,7 @@ TOOL_NO_EXPORTS = 1
LINK_COMPONENTS := asmparser bitreader mc core
USEDLIBS = clangChecker.a clangIndex.a clangFrontend.a clangDriver.a \
- clangSema.a clangAnalysis.a clangAST.a clangParse.a clangLex.a \
- clangBasic.a
+ clangSema.a clangAnalysis.a clangSerialization.a \
+ clangAST.a clangParse.a clangLex.a clangBasic.a
include $(CLANG_LEVEL)/Makefile
diff --git a/examples/wpa/clang-wpa.cpp b/examples/wpa/clang-wpa.cpp
index 74ec368cfbe7..41dca0dc451e 100644
--- a/examples/wpa/clang-wpa.cpp
+++ b/examples/wpa/clang-wpa.cpp
@@ -62,6 +62,10 @@ public:
return AST->getPreprocessor();
}
+ virtual Diagnostic &getDiagnostic() {
+ return AST->getDiagnostics();
+ }
+
virtual DeclReferenceMap &getDeclReferenceMap() {
return DeclRefMap;
}
@@ -87,7 +91,7 @@ int main(int argc, char **argv) {
= CompilerInstance::createDiagnostics(DiagOpts, argc, argv);
for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
const std::string &InFile = InputFilenames[i];
- llvm::OwningPtr<ASTUnit> AST(ASTUnit::LoadFromPCHFile(InFile, Diags));
+ llvm::OwningPtr<ASTUnit> AST(ASTUnit::LoadFromASTFile(InFile, Diags));
if (!AST)
return 1;
@@ -129,17 +133,18 @@ int main(int argc, char **argv) {
AnalysisManager AMgr(TU->getASTContext(), PP.getDiagnostics(),
PP.getLangOptions(), /* PathDiagnostic */ 0,
CreateRegionStoreManager,
- CreateRangeConstraintManager,
+ CreateRangeConstraintManager, &Idxer,
/* MaxNodes */ 300000, /* MaxLoop */ 3,
/* VisualizeEG */ false, /* VisualizeEGUbi */ false,
/* PurgeDead */ true, /* EagerlyAssume */ false,
- /* TrimGraph */ false, /* InlineCall */ true);
+ /* TrimGraph */ false, /* InlineCall */ true,
+ /* UseUnoptimizedCFG */ false);
GRTransferFuncs* TF = MakeCFRefCountTF(AMgr.getASTContext(), /*GC*/false,
AMgr.getLangOptions());
GRExprEngine Eng(AMgr, TF);
- Eng.ExecuteWorkList(AMgr.getStackFrame(FD), AMgr.getMaxNodes());
+ Eng.ExecuteWorkList(AMgr.getStackFrame(FD, TU), AMgr.getMaxNodes());
return 0;
}