我需要使用clang的API轉儲源代碼塊的活性。我嘗試過打印塊的活性,但沒有成功。下面是我試過的代碼轉儲塊使用Clang的源代碼的活力
bool MyASTVisitor::VisitFunctionDecl(FunctionDecl *f) {
std::cout<<"Dump Liveness\n";
clang::AnalysisDeclContextManager adcm;
clang::AnalysisDeclContext *adc = adcm.getContext(llvm::cast<clang::Decl>(f));
//clang::LiveVariables *lv = clang::LiveVariables::create(*adc);
//clang::LiveVariables *lv = clang::LiveVariables::computeLiveness(*adc,false);
clang::LiveVariables *lv = adc->getAnalysis<LiveVariables>();
clang::LiveVariables::Observer *obs = new clang::LiveVariables::Observer();
lv->runOnAllBlocks(*obs);
lv->dumpBlockLiveness((f->getASTContext()).getSourceManager());
return true;
}
我已經覆蓋了訪問函數,並試圖打印函數的活性。我嘗試過使用create,computeLiveness和getAnalysis方法來獲得LiveVariables對象,但是所有的方法都失敗了。但是除活動組號外,不顯示活性信息。
當我使用clang的命令行參數來打印活性時,它會正確顯示輸出。
我使用以下源代碼作爲從Live Variable Analysis Wikipedia 取得的測試用例。
int main(int argc, char *argv[])
{
int a,b,c,d,x;
a = 3;
b = 5;
d = 4;
x = 100;
if(a>b){
c = a+b;
d = 2;
}
c = 4;
return b * d + c;
}
有人請指出我哪裏可能是錯的? 在此先感謝。
非常感謝@Quentin它的工作。 :) –
但是,這似乎不適用於鐺3.1。在叮噹時工作3.8。 –