blob: 4593e2acc4b586d0688e8a750a34fb8869e74f3d [file] [log] [blame]
Reid Spencerf89143c2004-06-29 23:31:01 +00001//===-- Reader.h - Interface To Bytecode Reading ----------------*- C++ -*-===//
Misha Brukman8a96c532005-04-21 21:44:41 +00002//
Reid Spencerf89143c2004-06-29 23:31:01 +00003// The LLVM Compiler Infrastructure
4//
Misha Brukman8a96c532005-04-21 21:44:41 +00005// This file was developed by Reid Spencer and is distributed under the
Reid Spencerf89143c2004-06-29 23:31:01 +00006// University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukman8a96c532005-04-21 21:44:41 +00007//
Reid Spencerf89143c2004-06-29 23:31:01 +00008//===----------------------------------------------------------------------===//
9//
Misha Brukman8a96c532005-04-21 21:44:41 +000010// This header file defines the interface to the Bytecode Reader which is
Reid Spencerf89143c2004-06-29 23:31:01 +000011// responsible for correctly interpreting bytecode files (backwards compatible)
12// and materializing a module from the bytecode read.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef BYTECODE_PARSER_H
17#define BYTECODE_PARSER_H
18
19#include "llvm/Constants.h"
20#include "llvm/DerivedTypes.h"
21#include "llvm/GlobalValue.h"
22#include "llvm/Function.h"
23#include "llvm/ModuleProvider.h"
Reid Spencera86159c2004-07-04 11:04:56 +000024#include "llvm/Bytecode/Analyzer.h"
Chris Lattner63cf59e2007-02-07 05:08:39 +000025#include "llvm/ADT/SmallVector.h"
Reid Spencerf89143c2004-06-29 23:31:01 +000026#include <utility>
Reid Spencer233fe722006-08-22 16:09:19 +000027#include <setjmp.h>
Reid Spencerf89143c2004-06-29 23:31:01 +000028
29namespace llvm {
30
Reid Spenceref9b9a72007-02-05 20:47:22 +000031// Forward declarations
32class BytecodeHandler;
33class TypeSymbolTable;
34class ValueSymbolTable;
Reid Spencerf89143c2004-06-29 23:31:01 +000035
36/// This class defines the interface for parsing a buffer of bytecode. The
37/// parser itself takes no action except to call the various functions of
38/// the handler interface. The parser's sole responsibility is the correct
Misha Brukman8a96c532005-04-21 21:44:41 +000039/// interpretation of the bytecode buffer. The handler is responsible for
40/// instantiating and keeping track of all values. As a convenience, the parser
Reid Spencerf89143c2004-06-29 23:31:01 +000041/// is responsible for materializing types and will pass them through the
42/// handler interface as necessary.
43/// @see BytecodeHandler
44/// @brief Bytecode Reader interface
45class BytecodeReader : public ModuleProvider {
46
47/// @name Constructors
48/// @{
49public:
50 /// @brief Default constructor. By default, no handler is used.
Misha Brukman8a96c532005-04-21 21:44:41 +000051 BytecodeReader(BytecodeHandler* h = 0) {
Reid Spencerd3539b82004-11-14 22:00:09 +000052 decompressedBlock = 0;
Reid Spencer17f52c52004-11-06 23:17:23 +000053 Handler = h;
Reid Spencerf89143c2004-06-29 23:31:01 +000054 }
55
Misha Brukman8a96c532005-04-21 21:44:41 +000056 ~BytecodeReader() {
57 freeState();
Chris Lattner19925222004-11-15 21:55:06 +000058 if (decompressedBlock) {
Reid Spencerd3539b82004-11-14 22:00:09 +000059 ::free(decompressedBlock);
Chris Lattner19925222004-11-15 21:55:06 +000060 decompressedBlock = 0;
61 }
Reid Spencer17f52c52004-11-06 23:17:23 +000062 }
Reid Spencerf89143c2004-06-29 23:31:01 +000063
64/// @}
65/// @name Types
66/// @{
67public:
Reid Spencerad89bd62004-07-25 18:07:36 +000068
Reid Spencerf89143c2004-06-29 23:31:01 +000069 /// @brief A convenience type for the buffer pointer
70 typedef const unsigned char* BufPtr;
71
72 /// @brief The type used for a vector of potentially abstract types
73 typedef std::vector<PATypeHolder> TypeListTy;
74
75 /// This type provides a vector of Value* via the User class for
76 /// storage of Values that have been constructed when reading the
77 /// bytecode. Because of forward referencing, constant replacement
78 /// can occur so we ensure that our list of Value* is updated
79 /// properly through those transitions. This ensures that the
80 /// correct Value* is in our list when it comes time to associate
81 /// constants with global variables at the end of reading the
82 /// globals section.
83 /// @brief A list of values as a User of those Values.
Chris Lattnercad28bd2005-01-29 00:36:19 +000084 class ValueList : public User {
85 std::vector<Use> Uses;
86 public:
Chris Lattnerfea49302005-08-16 21:59:52 +000087 ValueList() : User(Type::VoidTy, Value::ArgumentVal, 0, 0) {}
Reid Spencerf89143c2004-06-29 23:31:01 +000088
89 // vector compatibility methods
90 unsigned size() const { return getNumOperands(); }
Chris Lattnercad28bd2005-01-29 00:36:19 +000091 void push_back(Value *V) {
92 Uses.push_back(Use(V, this));
93 OperandList = &Uses[0];
94 ++NumOperands;
95 }
96 Value *back() const { return Uses.back(); }
97 void pop_back() { Uses.pop_back(); --NumOperands; }
98 bool empty() const { return NumOperands == 0; }
Reid Spencerf89143c2004-06-29 23:31:01 +000099 virtual void print(std::ostream& os) const {
Chris Lattnercad28bd2005-01-29 00:36:19 +0000100 for (unsigned i = 0; i < size(); ++i) {
Reid Spencera86159c2004-07-04 11:04:56 +0000101 os << i << " ";
102 getOperand(i)->print(os);
103 os << "\n";
Reid Spencerf89143c2004-06-29 23:31:01 +0000104 }
105 }
106 };
107
108 /// @brief A 2 dimensional table of values
109 typedef std::vector<ValueList*> ValueTable;
110
Misha Brukman8a96c532005-04-21 21:44:41 +0000111 /// This map is needed so that forward references to constants can be looked
Reid Spencerf89143c2004-06-29 23:31:01 +0000112 /// up by Type and slot number when resolving those references.
113 /// @brief A mapping of a Type/slot pair to a Constant*.
Chris Lattner389bd042004-12-09 06:19:44 +0000114 typedef std::map<std::pair<unsigned,unsigned>, Constant*> ConstantRefsType;
Reid Spencerf89143c2004-06-29 23:31:01 +0000115
116 /// For lazy read-in of functions, we need to save the location in the
117 /// data stream where the function is located. This structure provides that
118 /// information. Lazy read-in is used mostly by the JIT which only wants to
Misha Brukman8a96c532005-04-21 21:44:41 +0000119 /// resolve functions as it needs them.
Reid Spencerf89143c2004-06-29 23:31:01 +0000120 /// @brief Keeps pointers to function contents for later use.
121 struct LazyFunctionInfo {
122 const unsigned char *Buf, *EndBuf;
123 LazyFunctionInfo(const unsigned char *B = 0, const unsigned char *EB = 0)
124 : Buf(B), EndBuf(EB) {}
125 };
126
127 /// @brief A mapping of functions to their LazyFunctionInfo for lazy reading.
128 typedef std::map<Function*, LazyFunctionInfo> LazyFunctionMap;
129
130 /// @brief A list of global variables and the slot number that initializes
131 /// them.
132 typedef std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInitsList;
133
134 /// This type maps a typeslot/valueslot pair to the corresponding Value*.
135 /// It is used for dealing with forward references as values are read in.
136 /// @brief A map for dealing with forward references of values.
137 typedef std::map<std::pair<unsigned,unsigned>,Value*> ForwardReferenceMap;
138
139/// @}
140/// @name Methods
141/// @{
142public:
Chris Lattner0d3382a2007-02-07 19:49:01 +0000143
144 typedef size_t Decompressor_t(const char *, size_t, char*&, std::string*);
145
Reid Spencer233fe722006-08-22 16:09:19 +0000146 /// @returns true if an error occurred
Reid Spencerf89143c2004-06-29 23:31:01 +0000147 /// @brief Main interface to parsing a bytecode buffer.
Reid Spencer233fe722006-08-22 16:09:19 +0000148 bool ParseBytecode(
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000149 volatile BufPtr Buf, ///< Beginning of the bytecode buffer
Reid Spencer5c15fe52004-07-05 00:57:50 +0000150 unsigned Length, ///< Length of the bytecode buffer
Reid Spencer233fe722006-08-22 16:09:19 +0000151 const std::string &ModuleID, ///< An identifier for the module constructed.
Chris Lattner0d3382a2007-02-07 19:49:01 +0000152 Decompressor_t *Decompressor = 0, ///< Optional decompressor.
Reid Spencer233fe722006-08-22 16:09:19 +0000153 std::string* ErrMsg = 0 ///< Optional place for error message
Reid Spencerf89143c2004-06-29 23:31:01 +0000154 );
155
Reid Spencerf89143c2004-06-29 23:31:01 +0000156 /// @brief Parse all function bodies
Reid Spencer99655e12006-08-25 19:54:53 +0000157 bool ParseAllFunctionBodies(std::string* ErrMsg);
Reid Spencerf89143c2004-06-29 23:31:01 +0000158
Reid Spencerf89143c2004-06-29 23:31:01 +0000159 /// @brief Parse the next function of specific type
Reid Spencer99655e12006-08-25 19:54:53 +0000160 bool ParseFunction(Function* Func, std::string* ErrMsg) ;
Reid Spencerf89143c2004-06-29 23:31:01 +0000161
162 /// This method is abstract in the parent ModuleProvider class. Its
163 /// implementation is identical to the ParseFunction method.
164 /// @see ParseFunction
165 /// @brief Make a specific function materialize.
Reid Spencer99655e12006-08-25 19:54:53 +0000166 virtual bool materializeFunction(Function *F, std::string *ErrMsg = 0) {
Reid Spencerf89143c2004-06-29 23:31:01 +0000167 LazyFunctionMap::iterator Fi = LazyFunctionLoadMap.find(F);
Reid Spencer99655e12006-08-25 19:54:53 +0000168 if (Fi == LazyFunctionLoadMap.end())
169 return false;
170 if (ParseFunction(F,ErrMsg))
Chris Lattner0300f3e2006-07-06 21:35:01 +0000171 return true;
Chris Lattner0300f3e2006-07-06 21:35:01 +0000172 return false;
Reid Spencerf89143c2004-06-29 23:31:01 +0000173 }
174
175 /// This method is abstract in the parent ModuleProvider class. Its
Misha Brukman8a96c532005-04-21 21:44:41 +0000176 /// implementation is identical to ParseAllFunctionBodies.
Reid Spencerf89143c2004-06-29 23:31:01 +0000177 /// @see ParseAllFunctionBodies
178 /// @brief Make the whole module materialize
Reid Spencer99655e12006-08-25 19:54:53 +0000179 virtual Module* materializeModule(std::string *ErrMsg = 0) {
180 if (ParseAllFunctionBodies(ErrMsg))
Chris Lattner0300f3e2006-07-06 21:35:01 +0000181 return 0;
Reid Spencerf89143c2004-06-29 23:31:01 +0000182 return TheModule;
183 }
184
185 /// This method is provided by the parent ModuleProvde class and overriden
186 /// here. It simply releases the module from its provided and frees up our
187 /// state.
188 /// @brief Release our hold on the generated module
Chris Lattner94aa7f32006-07-07 06:06:06 +0000189 Module* releaseModule(std::string *ErrInfo = 0) {
Reid Spencerf89143c2004-06-29 23:31:01 +0000190 // Since we're losing control of this Module, we must hand it back complete
Reid Spencer49521432006-11-11 11:54:25 +0000191 Module *M = ModuleProvider::releaseModule(ErrInfo);
Reid Spencerf89143c2004-06-29 23:31:01 +0000192 freeState();
193 return M;
194 }
195
196/// @}
197/// @name Parsing Units For Subclasses
198/// @{
199protected:
200 /// @brief Parse whole module scope
201 void ParseModule();
202
203 /// @brief Parse the version information block
204 void ParseVersionInfo();
205
206 /// @brief Parse the ModuleGlobalInfo block
207 void ParseModuleGlobalInfo();
208
Reid Spencer78d033e2007-01-06 07:24:44 +0000209 /// @brief Parse a value symbol table
210 void ParseTypeSymbolTable(TypeSymbolTable *ST);
211
212 /// @brief Parse a value symbol table
Reid Spenceref9b9a72007-02-05 20:47:22 +0000213 void ParseValueSymbolTable(Function* Func, ValueSymbolTable *ST);
Reid Spencerf89143c2004-06-29 23:31:01 +0000214
Reid Spencerf89143c2004-06-29 23:31:01 +0000215 /// @brief Parse functions lazily.
216 void ParseFunctionLazily();
217
218 /// @brief Parse a function body
219 void ParseFunctionBody(Function* Func);
220
Reid Spencerf89143c2004-06-29 23:31:01 +0000221 /// @brief Parse global types
222 void ParseGlobalTypes();
223
Reid Spencerf89143c2004-06-29 23:31:01 +0000224 /// @brief Parse a basic block (for LLVM 1.0 basic block blocks)
225 BasicBlock* ParseBasicBlock(unsigned BlockNo);
226
Reid Spencerf89143c2004-06-29 23:31:01 +0000227 /// @brief parse an instruction list (for post LLVM 1.0 instruction lists
228 /// with blocks differentiated by terminating instructions.
229 unsigned ParseInstructionList(
230 Function* F ///< The function into which BBs will be inserted
231 );
Misha Brukman8a96c532005-04-21 21:44:41 +0000232
Reid Spencerf89143c2004-06-29 23:31:01 +0000233 /// @brief Parse a single instruction.
234 void ParseInstruction(
Chris Lattner63cf59e2007-02-07 05:08:39 +0000235 SmallVector <unsigned, 8>& Args, ///< The arguments to be filled in
Reid Spencerf89143c2004-06-29 23:31:01 +0000236 BasicBlock* BB ///< The BB the instruction goes in
237 );
238
239 /// @brief Parse the whole constant pool
Misha Brukman8a96c532005-04-21 21:44:41 +0000240 void ParseConstantPool(ValueTable& Values, TypeListTy& Types,
Reid Spencera86159c2004-07-04 11:04:56 +0000241 bool isFunction);
Reid Spencerf89143c2004-06-29 23:31:01 +0000242
Chris Lattner3bc5a602006-01-25 23:08:15 +0000243 /// @brief Parse a single constant pool value
244 Value *ParseConstantPoolValue(unsigned TypeID);
Reid Spencerf89143c2004-06-29 23:31:01 +0000245
246 /// @brief Parse a block of types constants
Reid Spencer66906512004-07-11 17:24:05 +0000247 void ParseTypes(TypeListTy &Tab, unsigned NumEntries);
Reid Spencerf89143c2004-06-29 23:31:01 +0000248
249 /// @brief Parse a single type constant
Reid Spencer66906512004-07-11 17:24:05 +0000250 const Type *ParseType();
Reid Spencerf89143c2004-06-29 23:31:01 +0000251
252 /// @brief Parse a string constants block
253 void ParseStringConstants(unsigned NumEntries, ValueTable &Tab);
254
Chris Lattnerf0edc6c2006-10-12 18:32:30 +0000255 /// @brief Release our memory.
256 void freeState() {
257 freeTable(FunctionValues);
258 freeTable(ModuleValues);
259 }
260
Reid Spencerf89143c2004-06-29 23:31:01 +0000261/// @}
262/// @name Data
263/// @{
264private:
Reid Spencer233fe722006-08-22 16:09:19 +0000265 std::string ErrorMsg; ///< A place to hold an error message through longjmp
266 jmp_buf context; ///< Where to return to if an error occurs.
Misha Brukman8a96c532005-04-21 21:44:41 +0000267 char* decompressedBlock; ///< Result of decompression
Reid Spencerf89143c2004-06-29 23:31:01 +0000268 BufPtr MemStart; ///< Start of the memory buffer
269 BufPtr MemEnd; ///< End of the memory buffer
270 BufPtr BlockStart; ///< Start of current block being parsed
271 BufPtr BlockEnd; ///< End of current block being parsed
272 BufPtr At; ///< Where we're currently parsing at
273
Reid Spencera86159c2004-07-04 11:04:56 +0000274 /// Information about the module, extracted from the bytecode revision number.
Chris Lattner45b5dd22004-08-03 23:41:28 +0000275 ///
Reid Spencerf89143c2004-06-29 23:31:01 +0000276 unsigned char RevisionNum; // The rev # itself
277
Reid Spencerf89143c2004-06-29 23:31:01 +0000278 /// @brief This vector is used to deal with forward references to types in
279 /// a module.
280 TypeListTy ModuleTypes;
Chris Lattnereebac5f2005-10-03 21:26:53 +0000281
282 /// @brief This is an inverse mapping of ModuleTypes from the type to an
283 /// index. Because refining types causes the index of this map to be
284 /// invalidated, any time we refine a type, we clear this cache and recompute
285 /// it next time we need it. These entries are ordered by the pointer value.
286 std::vector<std::pair<const Type*, unsigned> > ModuleTypeIDCache;
Reid Spencerf89143c2004-06-29 23:31:01 +0000287
288 /// @brief This vector is used to deal with forward references to types in
289 /// a function.
290 TypeListTy FunctionTypes;
291
292 /// When the ModuleGlobalInfo section is read, we create a Function object
293 /// for each function in the module. When the function is loaded, after the
294 /// module global info is read, this Function is populated. Until then, the
295 /// functions in this vector just hold the function signature.
296 std::vector<Function*> FunctionSignatureList;
297
298 /// @brief This is the table of values belonging to the current function
299 ValueTable FunctionValues;
300
301 /// @brief This is the table of values belonging to the module (global)
302 ValueTable ModuleValues;
303
304 /// @brief This keeps track of function level forward references.
305 ForwardReferenceMap ForwardReferences;
306
307 /// @brief The basic blocks we've parsed, while parsing a function.
308 std::vector<BasicBlock*> ParsedBasicBlocks;
309
Chris Lattner1c765b02004-10-14 01:49:34 +0000310 /// This maintains a mapping between <Type, Slot #>'s and forward references
311 /// to constants. Such values may be referenced before they are defined, and
312 /// if so, the temporary object that they represent is held here. @brief
313 /// Temporary place for forward references to constants.
Reid Spencerf89143c2004-06-29 23:31:01 +0000314 ConstantRefsType ConstantFwdRefs;
315
316 /// Constant values are read in after global variables. Because of this, we
317 /// must defer setting the initializers on global variables until after module
Chris Lattner1c765b02004-10-14 01:49:34 +0000318 /// level constants have been read. In the mean time, this list keeps track
319 /// of what we must do.
Reid Spencerf89143c2004-06-29 23:31:01 +0000320 GlobalInitsList GlobalInits;
321
322 // For lazy reading-in of functions, we need to save away several pieces of
323 // information about each function: its begin and end pointer in the buffer
324 // and its FunctionSlot.
325 LazyFunctionMap LazyFunctionLoadMap;
326
Misha Brukman8a96c532005-04-21 21:44:41 +0000327 /// This stores the parser's handler which is used for handling tasks other
328 /// just than reading bytecode into the IR. If this is non-null, calls on
329 /// the (polymorphic) BytecodeHandler interface (see llvm/Bytecode/Handler.h)
330 /// will be made to report the logical structure of the bytecode file. What
331 /// the handler does with the events it receives is completely orthogonal to
Reid Spencerf89143c2004-06-29 23:31:01 +0000332 /// the business of parsing the bytecode and building the IR. This is used,
333 /// for example, by the llvm-abcd tool for analysis of byte code.
334 /// @brief Handler for parsing events.
335 BytecodeHandler* Handler;
336
Reid Spencer3e595462006-01-19 06:57:58 +0000337
Reid Spencerf89143c2004-06-29 23:31:01 +0000338/// @}
339/// @name Implementation Details
340/// @{
341private:
342 /// @brief Determines if this module has a function or not.
343 bool hasFunctions() { return ! FunctionSignatureList.empty(); }
344
345 /// @brief Determines if the type id has an implicit null value.
346 bool hasImplicitNull(unsigned TyID );
347
348 /// @brief Converts a type slot number to its Type*
349 const Type *getType(unsigned ID);
350
Reid Spencerd798a512006-11-14 04:47:22 +0000351 /// @brief Read in a type id and turn it into a Type*
352 inline const Type* readType();
Reid Spencera86159c2004-07-04 11:04:56 +0000353
Reid Spencerf89143c2004-06-29 23:31:01 +0000354 /// @brief Converts a Type* to its type slot number
355 unsigned getTypeSlot(const Type *Ty);
356
Reid Spencera86159c2004-07-04 11:04:56 +0000357 /// @brief Gets the global type corresponding to the TypeId
358 const Type *getGlobalTableType(unsigned TypeId);
Reid Spencerf89143c2004-06-29 23:31:01 +0000359
Reid Spencera86159c2004-07-04 11:04:56 +0000360 /// @brief Get a value from its typeid and slot number
Reid Spencerf89143c2004-06-29 23:31:01 +0000361 Value* getValue(unsigned TypeID, unsigned num, bool Create = true);
362
Reid Spencerf89143c2004-06-29 23:31:01 +0000363 /// @brief Get a basic block for current function
364 BasicBlock *getBasicBlock(unsigned ID);
365
Reid Spencera86159c2004-07-04 11:04:56 +0000366 /// @brief Get a constant value from its typeid and value slot.
Reid Spencerf89143c2004-06-29 23:31:01 +0000367 Constant* getConstantValue(unsigned typeSlot, unsigned valSlot);
368
369 /// @brief Convenience function for getting a constant value when
370 /// the Type has already been resolved.
371 Constant* getConstantValue(const Type *Ty, unsigned valSlot) {
372 return getConstantValue(getTypeSlot(Ty), valSlot);
373 }
374
Reid Spencerf89143c2004-06-29 23:31:01 +0000375 /// @brief Insert a newly created value
376 unsigned insertValue(Value *V, unsigned Type, ValueTable &Table);
377
378 /// @brief Insert the arguments of a function.
379 void insertArguments(Function* F );
380
Misha Brukman8a96c532005-04-21 21:44:41 +0000381 /// @brief Resolve all references to the placeholder (if any) for the
Reid Spencerf89143c2004-06-29 23:31:01 +0000382 /// given constant.
Chris Lattner389bd042004-12-09 06:19:44 +0000383 void ResolveReferencesToConstant(Constant *C, unsigned Typ, unsigned Slot);
Reid Spencerf89143c2004-06-29 23:31:01 +0000384
Reid Spencerf89143c2004-06-29 23:31:01 +0000385 /// @brief Free a table, making sure to free the ValueList in the table.
386 void freeTable(ValueTable &Tab) {
387 while (!Tab.empty()) {
388 delete Tab.back();
389 Tab.pop_back();
390 }
391 }
392
Reid Spencer233fe722006-08-22 16:09:19 +0000393 inline void error(const std::string& errmsg);
Reid Spencer24399722004-07-09 22:21:33 +0000394
Reid Spencerf89143c2004-06-29 23:31:01 +0000395 BytecodeReader(const BytecodeReader &); // DO NOT IMPLEMENT
396 void operator=(const BytecodeReader &); // DO NOT IMPLEMENT
397
Reid Spencera54b7cb2007-01-12 07:05:14 +0000398 // This enum provides the values of the well-known type slots that are always
399 // emitted as the first few types in the table by the BytecodeWriter class.
400 enum WellKnownTypeSlots {
401 VoidTypeSlot = 0, ///< TypeID == VoidTyID
402 FloatTySlot = 1, ///< TypeID == FloatTyID
403 DoubleTySlot = 2, ///< TypeID == DoubleTyID
404 LabelTySlot = 3, ///< TypeID == LabelTyID
405 BoolTySlot = 4, ///< TypeID == IntegerTyID, width = 1
406 Int8TySlot = 5, ///< TypeID == IntegerTyID, width = 8
407 Int16TySlot = 6, ///< TypeID == IntegerTyID, width = 16
408 Int32TySlot = 7, ///< TypeID == IntegerTyID, width = 32
409 Int64TySlot = 8 ///< TypeID == IntegerTyID, width = 64
410 };
411
Reid Spencerf89143c2004-06-29 23:31:01 +0000412/// @}
413/// @name Reader Primitives
414/// @{
415private:
416
417 /// @brief Is there more to parse in the current block?
418 inline bool moreInBlock();
419
420 /// @brief Have we read past the end of the block
421 inline void checkPastBlockEnd(const char * block_name);
422
423 /// @brief Align to 32 bits
424 inline void align32();
425
426 /// @brief Read an unsigned integer as 32-bits
427 inline unsigned read_uint();
428
429 /// @brief Read an unsigned integer with variable bit rate encoding
430 inline unsigned read_vbr_uint();
431
Reid Spencerad89bd62004-07-25 18:07:36 +0000432 /// @brief Read an unsigned integer of no more than 24-bits with variable
433 /// bit rate encoding.
434 inline unsigned read_vbr_uint24();
435
Reid Spencerf89143c2004-06-29 23:31:01 +0000436 /// @brief Read an unsigned 64-bit integer with variable bit rate encoding.
437 inline uint64_t read_vbr_uint64();
438
439 /// @brief Read a signed 64-bit integer with variable bit rate encoding.
440 inline int64_t read_vbr_int64();
441
442 /// @brief Read a string
443 inline std::string read_str();
444
Reid Spencer66906512004-07-11 17:24:05 +0000445 /// @brief Read a float value
446 inline void read_float(float& FloatVal);
447
448 /// @brief Read a double value
449 inline void read_double(double& DoubleVal);
450
Reid Spencerf89143c2004-06-29 23:31:01 +0000451 /// @brief Read an arbitrary data chunk of fixed length
452 inline void read_data(void *Ptr, void *End);
453
Reid Spencera86159c2004-07-04 11:04:56 +0000454 /// @brief Read a bytecode block header
Reid Spencerf89143c2004-06-29 23:31:01 +0000455 inline void read_block(unsigned &Type, unsigned &Size);
Reid Spencerf89143c2004-06-29 23:31:01 +0000456/// @}
457};
458
Reid Spencera86159c2004-07-04 11:04:56 +0000459/// @brief A function for creating a BytecodeAnalzer as a handler
460/// for the Bytecode reader.
Misha Brukman8a96c532005-04-21 21:44:41 +0000461BytecodeHandler* createBytecodeAnalyzerHandler(BytecodeAnalysis& bca,
Reid Spencer572c2562004-08-21 20:50:49 +0000462 std::ostream* output );
Reid Spencera86159c2004-07-04 11:04:56 +0000463
464
Reid Spencerf89143c2004-06-29 23:31:01 +0000465} // End llvm namespace
466
467// vim: sw=2
468#endif