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/ModuleProvider.h"
23 #include "llvm/Module.h"
24 #include "llvm/Support/Compressor.h"
25 #include "llvm/System/Path.h"
29 // Forward declare the handler class
30 class BytecodeHandler;
32 typedef size_t BCDecompressor_t(const char *, size_t, char*&, std::string*);
34 /// This function returns a ModuleProvider that can be used to do lazy
35 /// function-at-a-time loading from a bytecode file.
36 /// @returns NULL on error
37 /// @returns ModuleProvider* if successful
38 /// @brief Get a ModuleProvide for a bytecode file.
39 ModuleProvider *getBytecodeModuleProvider(
40 const std::string &Filename, ///< Name of file to be read
41 BCDecompressor_t *BCDC = Compressor::decompressToNewBuffer,
42 std::string* ErrMsg = 0, ///< Optional error message holder
43 BytecodeHandler* H = 0 ///< Optional handler for reader events
46 /// This function returns a ModuleProvider that can be used to do lazy
47 /// function function-at-a-time loading from a bytecode buffer.
48 /// @returns NULL on error
49 /// @returns ModuleProvider* if successful
50 /// @brief Get a ModuleProvider for a bytecode buffer.
51 ModuleProvider *getBytecodeBufferModuleProvider(
52 const unsigned char *Buffer, ///< Start of buffer to parse
53 unsigned BufferSize, ///< Size of the buffer
54 const std::string &ModuleID, ///< Name to give the module
55 BCDecompressor_t *BCDC = Compressor::decompressToNewBuffer,
56 std::string* ErrMsg = 0, ///< Optional place to return an error message
57 BytecodeHandler* H = 0 ///< Optional handler for reader events
60 /// This is the main interface to bytecode parsing. It opens the file specified
61 /// by \p Filename and parses the entire file, returing the corresponding Module
62 /// object if successful.
63 /// @returns NULL on error
64 /// @returns the module corresponding to the bytecode file, if successful
65 /// @brief Parse the given bytecode file
66 Module* ParseBytecodeFile(
67 const std::string &Filename, ///< Name of file to parse
68 BCDecompressor_t *BCDC = Compressor::decompressToNewBuffer,
69 std::string *ErrMsg = 0 ///< Optional place to return an error message
72 /// Parses a bytecode buffer specified by \p Buffer and \p BufferSize.
73 /// @returns NULL on error
74 /// @returns the module corresponding to the bytecode buffer, if successful
75 /// @brief Parse a given bytecode buffer
76 Module* ParseBytecodeBuffer(
77 const unsigned char *Buffer, ///< Start of buffer to parse
78 unsigned BufferSize, ///< Size of the buffer
79 const std::string &ModuleID="", ///< Name to give the module
80 BCDecompressor_t *BCDC = Compressor::decompressToNewBuffer,
81 std::string *ErrMsg = 0 ///< Optional place to return an error message
84 } // End llvm namespace