[llvm-commits] CVS: llvm/lib/Bytecode/Archive/Archive.cpp ArchiveInternals.h

Chris Lattner sabre at nondot.org
Wed Feb 7 15:53:37 PST 2007



Changes in directory llvm/lib/Bytecode/Archive:

Archive.cpp updated: 1.16 -> 1.17
ArchiveInternals.h updated: 1.5 -> 1.6
---
Log message:

move archive-specific stuff out of bcreader into archive library.


---
Diffs of the changes:  (+80 -3)

 Archive.cpp        |   70 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 ArchiveInternals.h |   13 ++++++++-
 2 files changed, 80 insertions(+), 3 deletions(-)


Index: llvm/lib/Bytecode/Archive/Archive.cpp
diff -u llvm/lib/Bytecode/Archive/Archive.cpp:1.16 llvm/lib/Bytecode/Archive/Archive.cpp:1.17
--- llvm/lib/Bytecode/Archive/Archive.cpp:1.16	Wed Feb  7 15:41:01 2007
+++ llvm/lib/Bytecode/Archive/Archive.cpp	Wed Feb  7 17:53:17 2007
@@ -14,8 +14,9 @@
 
 #include "ArchiveInternals.h"
 #include "llvm/ModuleProvider.h"
+#include "llvm/Module.h"
+#include "llvm/Bytecode/Reader.h"
 #include "llvm/System/Process.h"
-
 using namespace llvm;
 
 // getMemberSize - compute the actual physical size of the file member as seen
@@ -190,3 +191,70 @@
   cleanUpMemory();
 }
 
+
+
+static void getSymbols(Module*M, std::vector<std::string>& symbols) {
+  // Loop over global variables
+  for (Module::global_iterator GI = M->global_begin(), GE=M->global_end(); GI != GE; ++GI)
+    if (!GI->isDeclaration() && !GI->hasInternalLinkage())
+      if (!GI->getName().empty())
+        symbols.push_back(GI->getName());
+  
+  // Loop over functions.
+  for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
+    if (!FI->isDeclaration() && !FI->hasInternalLinkage())
+      if (!FI->getName().empty())
+        symbols.push_back(FI->getName());
+}
+
+// Get just the externally visible defined symbols from the bytecode
+bool llvm::GetBytecodeSymbols(const sys::Path& fName,
+                              std::vector<std::string>& symbols,
+                              BCDecompressor_t *BCDC,
+                              std::string* ErrMsg) {
+  ModuleProvider *MP = getBytecodeModuleProvider(fName.toString(), BCDC,ErrMsg);
+  if (!MP)
+    return true;
+  
+  // Get the module from the provider
+  Module* M = MP->materializeModule();
+  if (M == 0) {
+    delete MP;
+    return true;
+  }
+  
+  // Get the symbols
+  getSymbols(M, symbols);
+  
+  // Done with the module.
+  delete MP;
+  return true;
+}
+
+ModuleProvider*
+llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
+                         const std::string& ModuleID,
+                         std::vector<std::string>& symbols,
+                         BCDecompressor_t *BCDC,
+                         std::string* ErrMsg) {
+  // Get the module provider
+  ModuleProvider* MP = 
+  getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, BCDC, ErrMsg, 0);
+  if (!MP)
+    return 0;
+  
+  // Get the module from the provider
+  Module* M = MP->materializeModule();
+  if (M == 0) {
+    delete MP;
+    return 0;
+  }
+  
+  // Get the symbols
+  getSymbols(M, symbols);
+  
+  // Done with the module. Note that ModuleProvider will delete the
+  // Module when it is deleted. Also note that its the caller's responsibility
+  // to delete the ModuleProvider.
+  return MP;
+}


Index: llvm/lib/Bytecode/Archive/ArchiveInternals.h
diff -u llvm/lib/Bytecode/Archive/ArchiveInternals.h:1.5 llvm/lib/Bytecode/Archive/ArchiveInternals.h:1.6
--- llvm/lib/Bytecode/Archive/ArchiveInternals.h:1.5	Thu Apr 21 16:13:18 2005
+++ llvm/lib/Bytecode/Archive/ArchiveInternals.h	Wed Feb  7 17:53:17 2007
@@ -65,9 +65,18 @@
     bool checkSignature() {
       return 0 == memcmp(fmag, ARFILE_MEMBER_MAGIC,2);
     }
-
   };
-
+  
+  // Get just the externally visible defined symbols from the bytecode
+  bool GetBytecodeSymbols(const sys::Path& fName,
+                          std::vector<std::string>& symbols,
+                          BCDecompressor_t *BCDC, std::string* ErrMsg);
+  
+  ModuleProvider* GetBytecodeSymbols(const unsigned char*Buffer,unsigned Length,
+                                     const std::string& ModuleID,
+                                     std::vector<std::string>& symbols,
+                                     BCDecompressor_t *BCDC,
+                                     std::string* ErrMsg);
 }
 
 #endif






More information about the llvm-commits mailing list