Actually I tried ModulePass. It works exactly as what I expect.But I found another problem. In ModulePass, it not only collects the functions I create, it also treat some system function such as 'printf' as a function. I do not if I does something wrong. The codes I use is as follows:
virtual bool runOnModule(Module &M) {
for (Module::iterator b = M.begin(), be = M.end(); b != be; ++b) {
Function *ff = dyn_cast<Function>(b);
errs() <<"testff0: "<<funcname_index<<'\n';
funcname[funcname_index++] = ff->getName();
}
return false;
}
My test source file:
void A(){}
void B(){printf("dada");}
void main(){A(); B();}
The ModulePass output is:
A
B
printf
main
Thanks.
Robert
LLVM modules contain declarations of external functions, which are still “functions”.
You can filter these out by checking ff->isDeclaration().
Cheers,
Scott