1 //===-- llvm/Bytecode/Reader.h - Reader for VM bytecode files ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This functionality is implemented by the lib/Bytecode/Reader library.
11 // This library is used to read VM bytecode files from an iostream.
13 // Note that performance of this library is _crucial_ for performance of the
14 // JIT type applications, so we have designed the bytecode format to support
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_BYTECODE_READER_H
20 #define LLVM_BYTECODE_READER_H
22 #include "llvm/System/Path.h"
23 #include "llvm/ModuleProvider.h"
24 #include "llvm/Module.h"
29 // Forward declare the handler class
30 class BytecodeHandler;
32 /// getBytecodeModuleProvider - lazy function-at-a-time loading from a file
34 ModuleProvider *getBytecodeModuleProvider(
35 const std::string &Filename, ///< Name of file to be read
36 BytecodeHandler* H = 0 ///< Optional handler for reader events
39 /// getBytecodeBufferModuleProvider - lazy function-at-a-time loading from a
42 ModuleProvider *getBytecodeBufferModuleProvider(const unsigned char *Buffer,
44 const std::string &ModuleID="",
45 BytecodeHandler* H = 0);
47 /// @brief Parse the given bytecode file
48 Module* ParseBytecodeFile(const std::string &Filename,
49 std::string *ErrorStr = 0);
51 /// @brief Parse a given bytecode buffer
52 Module* ParseBytecodeBuffer(const unsigned char *Buffer,
54 const std::string &ModuleID = "",
55 std::string *ErrorStr = 0);
57 /// This function will read only the necessary parts of a bytecode file in order
58 /// to determine the list of dependent libraries encoded within it. The \p
59 /// deplibs parameter will contain a vector of strings of the bytecode module's
60 /// dependent libraries.
61 /// @returns true on success, false otherwise
62 /// @brief Get the list of dependent libraries from a bytecode file.
63 bool GetBytecodeDependentLibraries(const std::string &fileName,
64 Module::LibraryListType& deplibs);
66 /// This function will read only the necessary parts of a bytecode file in order
67 /// to obtain a list of externally visible global symbols that the bytecode
68 /// module defines. This is used for archiving and linking when only the list
69 /// of symbols the module defines is needed.
70 /// @returns true on success, false otherwise
71 /// @brief Get a bytecode file's externally visibile defined global symbols.
72 bool GetBytecodeSymbols(const sys::Path& fileName,
73 std::vector<std::string>& syms);
75 /// This function will read only the necessary parts of a bytecode buffer in
76 /// order to obtain a list of externally visible global symbols that the
77 /// bytecode module defines. This is used for archiving and linking when only
78 /// the list of symbols the module defines is needed and the bytecode is
79 /// already in memory.
80 /// @returns the ModuleProvider on success, 0 if the bytecode can't be parsed
81 /// @brief Get a bytecode file's externally visibile defined global symbols.
82 ModuleProvider* GetBytecodeSymbols(
83 const unsigned char*Buffer, ///< The buffer to be parsed
84 unsigned Length, ///< The length of \p Buffer
85 const std::string& ModuleID, ///< An identifier for the module
86 std::vector<std::string>& symbols ///< The symbols defined in the module
89 } // End llvm namespace