Added an early implementation of Live-Variables analysis built on
source-level CFGs. This code may change significantly in the near
future as we explore different means to implement dataflow analyses.
Added a driver option, -dump-live-variables, to view the output of
live variable analysis. This output is very ALPHA; it will be improved shortly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41737 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/ASTStreamers.cpp b/Driver/ASTStreamers.cpp
index f77505b..a1494e4 100644
--- a/Driver/ASTStreamers.cpp
+++ b/Driver/ASTStreamers.cpp
@@ -14,6 +14,7 @@
#include "ASTStreamers.h"
#include "clang/AST/AST.h"
#include "clang/AST/CFG.h"
+#include "clang/Analysis/LiveVariables.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/ASTStreamer.h"
using namespace clang;
@@ -184,4 +185,28 @@
ASTStreamer_Terminate(Streamer);
}
+void clang::AnalyzeLiveVariables(Preprocessor &PP, unsigned MainFileID)
+{
+ ASTContext Context(PP.getTargetInfo(), PP.getIdentifierTable());
+ ASTStreamerTy *Streamer = ASTStreamer_Init(PP, Context, MainFileID);
+
+ while (Decl *D = ASTStreamer_ReadTopLevelDecl(Streamer)) {
+ if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+ if (FD->getBody()) {
+ PrintFunctionDeclStart(FD);
+ fprintf(stderr,"\n");
+ if (CFG* C = CFG::buildCFG(FD->getBody())) {
+ LiveVariables L;
+ L.runOnCFG(*C);
+ L.DumpBlockLiveness();
+ }
+ else
+ fprintf(stderr," Error processing CFG.\n");
+ }
+ }
+ }
+
+ ASTStreamer_Terminate(Streamer);
+}
+