#include <stdlib.h>
#include <string.h>
-static LLVMModuleRef load_module(void) {
+static LLVMModuleRef load_module(bool Lazy) {
LLVMMemoryBufferRef MB;
LLVMModuleRef M;
char *msg = NULL;
exit(1);
}
- if (LLVMParseBitcode(MB, &M, &msg)) {
+ LLVMBool Ret;
+ if (Lazy)
+ Ret = LLVMGetBitcodeModule(MB, &M, &msg);
+ else
+ Ret = LLVMParseBitcode(MB, &M, &msg);
+
+ if (Ret) {
fprintf(stderr, "Error parsing bitcode: %s\n", msg);
+ LLVMDisposeMemoryBuffer(MB);
exit(1);
}
+ if (!Lazy)
+ LLVMDisposeMemoryBuffer(MB);
+
return M;
}
-int module_dump(void) {
- LLVMModuleRef M = load_module();
+int module_dump(bool Lazy) {
+ LLVMModuleRef M = load_module(Lazy);
char *irstr = LLVMPrintModuleToString(M);
puts(irstr);
}
int module_list_functions(void) {
- LLVMModuleRef M = load_module();
+ LLVMModuleRef M = load_module(false);
LLVMValueRef f;
f = LLVMGetFirstFunction(M);
if (LLVMIsDeclaration(f)) {
printf("FunctionDeclaration: %s\n", LLVMGetValueName(f));
} else {
+ LLVMBasicBlockRef bb;
+ LLVMValueRef isn;
unsigned nisn = 0;
unsigned nbb = 0;
printf("FunctionDefinition: %s [#bb=%u]\n", LLVMGetValueName(f),
LLVMCountBasicBlocks(f));
- for (LLVMBasicBlockRef bb = LLVMGetFirstBasicBlock(f); bb;
+ for (bb = LLVMGetFirstBasicBlock(f); bb;
bb = LLVMGetNextBasicBlock(bb)) {
nbb++;
- for (LLVMValueRef isn = LLVMGetFirstInstruction(bb); isn;
+ for (isn = LLVMGetFirstInstruction(bb); isn;
isn = LLVMGetNextInstruction(isn)) {
nisn++;
if (LLVMIsACallInst(isn)) {
}
int module_list_globals(void) {
- LLVMModuleRef M = load_module();
+ LLVMModuleRef M = load_module(false);
LLVMValueRef g;
g = LLVMGetFirstGlobal(M);