A problem about LLVM IR

Hello,
When I process a LLBM IR(hello.bc), how can I distinguish the “define” function from “declare” function in the IR likes blow:

define i32 @main() ssp {
entry:
  %retval = alloca i32
  %0 = alloca i32
  %"alloca point" = bitcast i32 0 to i32
  %1 = call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @.str, i64 0, i64 0))
  store i32 0, i32* %0, align 4
  %2 = load i32* %0, align 4
  store i32 %2, i32* %retval, align 4
  br label %return
return:
  %retval1 = load i32* %retval
  ret i32 %retval1
}

declare i32 @puts(i8*)

when i write a pass as blow, it print both “main” and “puts”, now I only want to get the “define” function(main) but not “declare” function(puts), what can I do to complish my work?

Module::iterator It = _Module->begin(), Ite = _Module->end();
for(; It != Ite; ++It)
{
   errs()<<It->getName()<<"\n";
}

Thx.

–WangLei (BUPT)

Hi Lei,

You want It->isDeclaration(). It will return true for “declare” and false for “define”.

Cheers,

James