X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvm-c-test%2Fmodule.c;h=a6c47bf5fa1687c9b76e43cbab98321dcc16a9c0;hb=HEAD;hp=50e6e9c6de109e2f9c1b825908e36654bf9d6177;hpb=2bef1a6b25d938210547cd0f5ba4a08abdad2583;p=oota-llvm.git diff --git a/tools/llvm-c-test/module.c b/tools/llvm-c-test/module.c index 50e6e9c6de1..a6c47bf5fa1 100644 --- a/tools/llvm-c-test/module.c +++ b/tools/llvm-c-test/module.c @@ -19,7 +19,14 @@ #include #include -static LLVMModuleRef load_module(void) { +static void diagnosticHandler(LLVMDiagnosticInfoRef DI, void *C) { + char *CErr = LLVMGetDiagInfoDescription(DI); + fprintf(stderr, "Error with new bitcode parser: %s\n", CErr); + LLVMDisposeMessage(CErr); + exit(1); +} + +static LLVMModuleRef load_module(bool Lazy, bool New) { LLVMMemoryBufferRef MB; LLVMModuleRef M; char *msg = NULL; @@ -29,16 +36,35 @@ static LLVMModuleRef load_module(void) { exit(1); } - if (LLVMParseBitcode(MB, &M, &msg)) { + LLVMBool Ret; + if (New) { + LLVMContextRef C = LLVMGetGlobalContext(); + LLVMContextSetDiagnosticHandler(C, diagnosticHandler, NULL); + if (Lazy) + Ret = LLVMGetBitcodeModule2(MB, &M); + else + Ret = LLVMParseBitcode2(MB, &M); + } else { + 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, bool New) { + LLVMModuleRef M = load_module(Lazy, New); char *irstr = LLVMPrintModuleToString(M); puts(irstr); @@ -50,7 +76,7 @@ int module_dump(void) { } int module_list_functions(void) { - LLVMModuleRef M = load_module(); + LLVMModuleRef M = load_module(false, false); LLVMValueRef f; f = LLVMGetFirstFunction(M); @@ -58,16 +84,18 @@ int module_list_functions(void) { 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)) { @@ -89,7 +117,7 @@ int module_list_functions(void) { } int module_list_globals(void) { - LLVMModuleRef M = load_module(); + LLVMModuleRef M = load_module(false, false); LLVMValueRef g; g = LLVMGetFirstGlobal(M);