[llvm-commits] CVS: llvm/lib/Bytecode/Reader/ReaderWrappers.cpp

Reid Spencer reid at x10sys.com
Sun Nov 14 14:01:33 PST 2004



Changes in directory llvm/lib/Bytecode/Reader:

ReaderWrappers.cpp updated: 1.33 -> 1.34
---
Log message:

Add wrappers to get defined symbols from bytecode

---
Diffs of the changes:  (+48 -19)

Index: llvm/lib/Bytecode/Reader/ReaderWrappers.cpp
diff -u llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.33 llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.34
--- llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.33	Sat Nov  6 02:56:40 2004
+++ llvm/lib/Bytecode/Reader/ReaderWrappers.cpp	Sun Nov 14 16:00:48 2004
@@ -346,6 +346,30 @@
   }
 }
 
+namespace {
+void getSymbols(Module*M, std::vector<std::string>& symbols) {
+  // Loop over global variables
+  for (Module::giterator GI = M->gbegin(), GE=M->gend(); GI != GE; ++GI) {
+    if (GI->hasInitializer()) {
+      std::string name ( GI->getName() );
+      if (!name.empty()) {
+        symbols.push_back(name);
+      }
+    }
+  }
+
+  //Loop over functions
+  for (Module::iterator FI = M->begin(), FE=M->end(); FI != FE; ++FI) {
+    if (!FI->isExternal()) {
+      std::string name ( FI->getName() );
+      if (!name.empty()) {
+        symbols.push_back(name);
+      }
+    }
+  }
+}
+}
+
 // Get just the externally visible defined symbols from the bytecode
 bool llvm::GetBytecodeSymbols(const sys::Path& fName,
                               std::vector<std::string>& symbols) {
@@ -355,25 +379,8 @@
     // Get the module from the provider
     Module* M = AMP->releaseModule();
 
-    // Loop over global variables
-    for (Module::giterator GI = M->gbegin(), GE=M->gend(); GI != GE; ++GI) {
-      if (GI->hasInitializer()) {
-        std::string name ( GI->getName() );
-        if (!name.empty()) {
-          symbols.push_back(name);
-        }
-      }
-    }
-
-    //Loop over functions
-    for (Module::iterator FI = M->begin(), FE=M->end(); FI != FE; ++FI) {
-      if (!FI->isExternal()) {
-        std::string name ( FI->getName() );
-        if (!name.empty()) {
-          symbols.push_back(name);
-        }
-      }
-    }
+    // Get the symbols
+    getSymbols(M, symbols);
 
     // Done with the module
     delete M;
@@ -384,4 +391,26 @@
   }
 }
 
+bool llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
+                              const std::string& ModuleID,
+                              std::vector<std::string>& symbols) {
+
+  try {
+    std::auto_ptr<ModuleProvider>
+      AMP(getBytecodeBufferModuleProvider(Buffer, Length, ModuleID));
+
+    // Get the module from the provider
+    Module* M = AMP->releaseModule();
+
+    // Get the symbols
+    getSymbols(M, symbols);
+
+    // Done with the module
+    delete M;
+    return true;
+
+  } catch (...) {
+    return false;
+  }
+}
 // vim: sw=2 ai






More information about the llvm-commits mailing list