[llvm] r255985 - Add a test for LLVMGetBitcodeModule.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 17 19:57:26 PST 2015


Author: rafael
Date: Thu Dec 17 21:57:26 2015
New Revision: 255985

URL: http://llvm.org/viewvc/llvm-project?rev=255985&view=rev
Log:
Add a test for LLVMGetBitcodeModule.

Modified:
    llvm/trunk/test/Bindings/llvm-c/functions.ll
    llvm/trunk/tools/llvm-c-test/llvm-c-test.h
    llvm/trunk/tools/llvm-c-test/main.c
    llvm/trunk/tools/llvm-c-test/module.c

Modified: llvm/trunk/test/Bindings/llvm-c/functions.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/llvm-c/functions.ll?rev=255985&r1=255984&r2=255985&view=diff
==============================================================================
--- llvm/trunk/test/Bindings/llvm-c/functions.ll (original)
+++ llvm/trunk/test/Bindings/llvm-c/functions.ll Thu Dec 17 21:57:26 2015
@@ -1,4 +1,13 @@
-; RUN: llvm-as < %s | llvm-c-test --module-list-functions | FileCheck %s
+; RUN: llvm-as %s -o %t.bc
+; RUN: llvm-c-test --module-list-functions < %t.bc| FileCheck %s
+; RUN: llvm-c-test --module-dump < %t.bc| FileCheck --check-prefix=MOD %s
+; RUN: llvm-c-test --lazy-module-dump < %t.bc| FileCheck --check-prefix=LMOD %s
+
+; MOD:      define i32 @X() {
+; MOD-NEXT:   entry:
+
+; LMOD:      ; Materializable
+; LMOD-NEXT: define i32 @X() {}
 
 define i32 @X() {
 entry:

Modified: llvm/trunk/tools/llvm-c-test/llvm-c-test.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-c-test/llvm-c-test.h?rev=255985&r1=255984&r2=255985&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-c-test/llvm-c-test.h (original)
+++ llvm/trunk/tools/llvm-c-test/llvm-c-test.h Thu Dec 17 21:57:26 2015
@@ -13,11 +13,13 @@
 #ifndef LLVM_C_TEST_H
 #define LLVM_C_TEST_H
 
+#include <stdbool.h>
+
 // helpers.c
 void tokenize_stdin(void (*cb)(char **tokens, int ntokens));
 
 // module.c
-int module_dump(void);
+int module_dump(bool Lazy);
 int module_list_functions(void);
 int module_list_globals(void);
 

Modified: llvm/trunk/tools/llvm-c-test/main.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-c-test/main.c?rev=255985&r1=255984&r2=255985&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-c-test/main.c (original)
+++ llvm/trunk/tools/llvm-c-test/main.c Thu Dec 17 21:57:26 2015
@@ -23,6 +23,9 @@ static void print_usage(void) {
   fprintf(stderr, " Commands:\n");
   fprintf(stderr, "  * --module-dump\n");
   fprintf(stderr, "    Read bytecode from stdin - print disassembly\n\n");
+  fprintf(stderr, "  * --lazy-module-dump\n");
+  fprintf(stderr,
+          "    Lazily read bytecode from stdin - print disassembly\n\n");
   fprintf(stderr, "  * --module-list-functions\n");
   fprintf(stderr,
           "    Read bytecode from stdin - list summary of functions\n\n");
@@ -49,8 +52,10 @@ int main(int argc, char **argv) {
 
   LLVMInitializeCore(pr);
 
-  if (argc == 2 && !strcmp(argv[1], "--module-dump")) {
-    return module_dump();
+  if (argc == 2 && !strcmp(argv[1], "--lazy-module-dump")) {
+    return module_dump(true);
+  } else if (argc == 2 && !strcmp(argv[1], "--module-dump")) {
+    return module_dump(false);
   } else if (argc == 2 && !strcmp(argv[1], "--module-list-functions")) {
     return module_list_functions();
   } else if (argc == 2 && !strcmp(argv[1], "--module-list-globals")) {

Modified: llvm/trunk/tools/llvm-c-test/module.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-c-test/module.c?rev=255985&r1=255984&r2=255985&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-c-test/module.c (original)
+++ llvm/trunk/tools/llvm-c-test/module.c Thu Dec 17 21:57:26 2015
@@ -19,7 +19,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-static LLVMModuleRef load_module(void) {
+static LLVMModuleRef load_module(bool Lazy) {
   LLVMMemoryBufferRef MB;
   LLVMModuleRef M;
   char *msg = NULL;
@@ -29,18 +29,26 @@ static LLVMModuleRef load_module(void) {
     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);
   }
 
-  LLVMDisposeMemoryBuffer(MB);
+  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);
@@ -52,7 +60,7 @@ int module_dump(void) {
 }
 
 int module_list_functions(void) {
-  LLVMModuleRef M = load_module();
+  LLVMModuleRef M = load_module(false);
   LLVMValueRef f;
 
   f = LLVMGetFirstFunction(M);
@@ -93,7 +101,7 @@ int module_list_functions(void) {
 }
 
 int module_list_globals(void) {
-  LLVMModuleRef M = load_module();
+  LLVMModuleRef M = load_module(false);
   LLVMValueRef g;
 
   g = LLVMGetFirstGlobal(M);




More information about the llvm-commits mailing list