blob: 3733523975d7feb04139deb5a1fe90749885ec9d [file] [log] [blame]
Reid Spencerf89143c2004-06-29 23:31:01 +00001//===-- Reader.h - Interface To Bytecode Reading ----------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Reid Spencer and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This header file defines the interface to the Bytecode Reader which is
11// 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"
Reid Spencerf89143c2004-06-29 23:31:01 +000025#include <utility>
26#include <map>
27
28namespace llvm {
29
30class BytecodeHandler; ///< Forward declare the handler interface
31
32/// This class defines the interface for parsing a buffer of bytecode. The
33/// parser itself takes no action except to call the various functions of
34/// the handler interface. The parser's sole responsibility is the correct
35/// interpretation of the bytecode buffer. The handler is responsible for
36/// instantiating and keeping track of all values. As a convenience, the parser
37/// is responsible for materializing types and will pass them through the
38/// handler interface as necessary.
39/// @see BytecodeHandler
40/// @brief Bytecode Reader interface
41class BytecodeReader : public ModuleProvider {
42
43/// @name Constructors
44/// @{
45public:
46 /// @brief Default constructor. By default, no handler is used.
Chris Lattner19925222004-11-15 21:55:06 +000047 BytecodeReader(BytecodeHandler* h = 0) {
Reid Spencerd3539b82004-11-14 22:00:09 +000048 decompressedBlock = 0;
Reid Spencer17f52c52004-11-06 23:17:23 +000049 Handler = h;
Reid Spencerf89143c2004-06-29 23:31:01 +000050 }
51
Reid Spencer17f52c52004-11-06 23:17:23 +000052 ~BytecodeReader() {
53 freeState();
Chris Lattner19925222004-11-15 21:55:06 +000054 if (decompressedBlock) {
Reid Spencerd3539b82004-11-14 22:00:09 +000055 ::free(decompressedBlock);
Chris Lattner19925222004-11-15 21:55:06 +000056 decompressedBlock = 0;
57 }
Reid Spencer17f52c52004-11-06 23:17:23 +000058 }
Reid Spencerf89143c2004-06-29 23:31:01 +000059
60/// @}
61/// @name Types
62/// @{
63public:
Reid Spencerad89bd62004-07-25 18:07:36 +000064
Reid Spencerf89143c2004-06-29 23:31:01 +000065 /// @brief A convenience type for the buffer pointer
66 typedef const unsigned char* BufPtr;
67
68 /// @brief The type used for a vector of potentially abstract types
69 typedef std::vector<PATypeHolder> TypeListTy;
70
71 /// This type provides a vector of Value* via the User class for
72 /// storage of Values that have been constructed when reading the
73 /// bytecode. Because of forward referencing, constant replacement
74 /// can occur so we ensure that our list of Value* is updated
75 /// properly through those transitions. This ensures that the
76 /// correct Value* is in our list when it comes time to associate
77 /// constants with global variables at the end of reading the
78 /// globals section.
79 /// @brief A list of values as a User of those Values.
80 struct ValueList : public User {
Reid Spencer89fc0e32004-07-18 00:13:12 +000081 ValueList() : User(Type::VoidTy, Value::ValueListVal) {}
Reid Spencerf89143c2004-06-29 23:31:01 +000082
83 // vector compatibility methods
84 unsigned size() const { return getNumOperands(); }
85 void push_back(Value *V) { Operands.push_back(Use(V, this)); }
86 Value *back() const { return Operands.back(); }
87 void pop_back() { Operands.pop_back(); }
88 bool empty() const { return Operands.empty(); }
89 // must override this
90 virtual void print(std::ostream& os) const {
91 for ( unsigned i = 0; i < size(); i++ ) {
Reid Spencera86159c2004-07-04 11:04:56 +000092 os << i << " ";
93 getOperand(i)->print(os);
94 os << "\n";
Reid Spencerf89143c2004-06-29 23:31:01 +000095 }
96 }
97 };
98
99 /// @brief A 2 dimensional table of values
100 typedef std::vector<ValueList*> ValueTable;
101
102 /// This map is needed so that forward references to constants can be looked
103 /// up by Type and slot number when resolving those references.
104 /// @brief A mapping of a Type/slot pair to a Constant*.
105 typedef std::map<std::pair<const Type*,unsigned>, Constant*> ConstantRefsType;
106
107 /// For lazy read-in of functions, we need to save the location in the
108 /// data stream where the function is located. This structure provides that
109 /// information. Lazy read-in is used mostly by the JIT which only wants to
110 /// resolve functions as it needs them.
111 /// @brief Keeps pointers to function contents for later use.
112 struct LazyFunctionInfo {
113 const unsigned char *Buf, *EndBuf;
114 LazyFunctionInfo(const unsigned char *B = 0, const unsigned char *EB = 0)
115 : Buf(B), EndBuf(EB) {}
116 };
117
118 /// @brief A mapping of functions to their LazyFunctionInfo for lazy reading.
119 typedef std::map<Function*, LazyFunctionInfo> LazyFunctionMap;
120
121 /// @brief A list of global variables and the slot number that initializes
122 /// them.
123 typedef std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInitsList;
124
125 /// This type maps a typeslot/valueslot pair to the corresponding Value*.
126 /// It is used for dealing with forward references as values are read in.
127 /// @brief A map for dealing with forward references of values.
128 typedef std::map<std::pair<unsigned,unsigned>,Value*> ForwardReferenceMap;
129
130/// @}
131/// @name Methods
132/// @{
133public:
Reid Spencerf89143c2004-06-29 23:31:01 +0000134 /// @brief Main interface to parsing a bytecode buffer.
135 void ParseBytecode(
Reid Spencer5c15fe52004-07-05 00:57:50 +0000136 const unsigned char *Buf, ///< Beginning of the bytecode buffer
137 unsigned Length, ///< Length of the bytecode buffer
Reid Spencer572c2562004-08-21 20:50:49 +0000138 const std::string &ModuleID ///< An identifier for the module constructed.
Reid Spencerf89143c2004-06-29 23:31:01 +0000139 );
140
Reid Spencerf89143c2004-06-29 23:31:01 +0000141 /// @brief Parse all function bodies
Reid Spencera86159c2004-07-04 11:04:56 +0000142 void ParseAllFunctionBodies();
Reid Spencerf89143c2004-06-29 23:31:01 +0000143
Reid Spencerf89143c2004-06-29 23:31:01 +0000144 /// @brief Parse the next function of specific type
Reid Spencera86159c2004-07-04 11:04:56 +0000145 void ParseFunction(Function* Func) ;
Reid Spencerf89143c2004-06-29 23:31:01 +0000146
147 /// This method is abstract in the parent ModuleProvider class. Its
148 /// implementation is identical to the ParseFunction method.
149 /// @see ParseFunction
150 /// @brief Make a specific function materialize.
151 virtual void materializeFunction(Function *F) {
152 LazyFunctionMap::iterator Fi = LazyFunctionLoadMap.find(F);
153 if (Fi == LazyFunctionLoadMap.end()) return;
154 ParseFunction(F);
155 }
156
157 /// This method is abstract in the parent ModuleProvider class. Its
158 /// implementation is identical to ParseAllFunctionBodies.
159 /// @see ParseAllFunctionBodies
160 /// @brief Make the whole module materialize
161 virtual Module* materializeModule() {
162 ParseAllFunctionBodies();
163 return TheModule;
164 }
165
166 /// This method is provided by the parent ModuleProvde class and overriden
167 /// here. It simply releases the module from its provided and frees up our
168 /// state.
169 /// @brief Release our hold on the generated module
170 Module* releaseModule() {
171 // Since we're losing control of this Module, we must hand it back complete
172 Module *M = ModuleProvider::releaseModule();
173 freeState();
174 return M;
175 }
176
177/// @}
178/// @name Parsing Units For Subclasses
179/// @{
180protected:
181 /// @brief Parse whole module scope
182 void ParseModule();
183
184 /// @brief Parse the version information block
185 void ParseVersionInfo();
186
187 /// @brief Parse the ModuleGlobalInfo block
188 void ParseModuleGlobalInfo();
189
190 /// @brief Parse a symbol table
191 void ParseSymbolTable( Function* Func, SymbolTable *ST);
192
Reid Spencerf89143c2004-06-29 23:31:01 +0000193 /// @brief Parse functions lazily.
194 void ParseFunctionLazily();
195
196 /// @brief Parse a function body
197 void ParseFunctionBody(Function* Func);
198
Reid Spencera86159c2004-07-04 11:04:56 +0000199 /// @brief Parse the type list portion of a compaction table
Chris Lattner45b5dd22004-08-03 23:41:28 +0000200 void ParseCompactionTypes(unsigned NumEntries);
Reid Spencera86159c2004-07-04 11:04:56 +0000201
Reid Spencerf89143c2004-06-29 23:31:01 +0000202 /// @brief Parse a compaction table
203 void ParseCompactionTable();
204
205 /// @brief Parse global types
206 void ParseGlobalTypes();
207
Reid Spencerf89143c2004-06-29 23:31:01 +0000208 /// @brief Parse a basic block (for LLVM 1.0 basic block blocks)
209 BasicBlock* ParseBasicBlock(unsigned BlockNo);
210
Reid Spencerf89143c2004-06-29 23:31:01 +0000211 /// @brief parse an instruction list (for post LLVM 1.0 instruction lists
212 /// with blocks differentiated by terminating instructions.
213 unsigned ParseInstructionList(
214 Function* F ///< The function into which BBs will be inserted
215 );
216
Reid Spencerf89143c2004-06-29 23:31:01 +0000217 /// @brief Parse a single instruction.
218 void ParseInstruction(
219 std::vector<unsigned>& Args, ///< The arguments to be filled in
220 BasicBlock* BB ///< The BB the instruction goes in
221 );
222
223 /// @brief Parse the whole constant pool
Reid Spencera86159c2004-07-04 11:04:56 +0000224 void ParseConstantPool(ValueTable& Values, TypeListTy& Types,
225 bool isFunction);
Reid Spencerf89143c2004-06-29 23:31:01 +0000226
227 /// @brief Parse a single constant value
228 Constant* ParseConstantValue(unsigned TypeID);
229
230 /// @brief Parse a block of types constants
Reid Spencer66906512004-07-11 17:24:05 +0000231 void ParseTypes(TypeListTy &Tab, unsigned NumEntries);
Reid Spencerf89143c2004-06-29 23:31:01 +0000232
233 /// @brief Parse a single type constant
Reid Spencer66906512004-07-11 17:24:05 +0000234 const Type *ParseType();
Reid Spencerf89143c2004-06-29 23:31:01 +0000235
236 /// @brief Parse a string constants block
237 void ParseStringConstants(unsigned NumEntries, ValueTable &Tab);
238
239/// @}
240/// @name Data
241/// @{
242private:
Reid Spencerd3539b82004-11-14 22:00:09 +0000243 char* decompressedBlock; ///< Result of decompression
Reid Spencerf89143c2004-06-29 23:31:01 +0000244 BufPtr MemStart; ///< Start of the memory buffer
245 BufPtr MemEnd; ///< End of the memory buffer
246 BufPtr BlockStart; ///< Start of current block being parsed
247 BufPtr BlockEnd; ///< End of current block being parsed
248 BufPtr At; ///< Where we're currently parsing at
249
Reid Spencera86159c2004-07-04 11:04:56 +0000250 /// Information about the module, extracted from the bytecode revision number.
Chris Lattner45b5dd22004-08-03 23:41:28 +0000251 ///
Reid Spencerf89143c2004-06-29 23:31:01 +0000252 unsigned char RevisionNum; // The rev # itself
253
Reid Spencera86159c2004-07-04 11:04:56 +0000254 /// Flags to distinguish LLVM 1.0 & 1.1 bytecode formats (revision #0)
Reid Spencerf89143c2004-06-29 23:31:01 +0000255
Chris Lattner45b5dd22004-08-03 23:41:28 +0000256 /// Revision #0 had an explicit alignment of data only for the
257 /// ModuleGlobalInfo block. This was fixed to be like all other blocks in 1.2
Reid Spencerf89143c2004-06-29 23:31:01 +0000258 bool hasInconsistentModuleGlobalInfo;
259
Reid Spencera86159c2004-07-04 11:04:56 +0000260 /// Revision #0 also explicitly encoded zero values for primitive types like
261 /// int/sbyte/etc.
Reid Spencerf89143c2004-06-29 23:31:01 +0000262 bool hasExplicitPrimitiveZeros;
263
264 // Flags to control features specific the LLVM 1.2 and before (revision #1)
265
Reid Spencera86159c2004-07-04 11:04:56 +0000266 /// LLVM 1.2 and earlier required that getelementptr structure indices were
267 /// ubyte constants and that sequential type indices were longs.
Reid Spencerf89143c2004-06-29 23:31:01 +0000268 bool hasRestrictedGEPTypes;
269
Reid Spencera86159c2004-07-04 11:04:56 +0000270 /// LLVM 1.2 and earlier had class Type deriving from Value and the Type
271 /// objects were located in the "Type Type" plane of various lists in read
272 /// by the bytecode reader. In LLVM 1.3 this is no longer the case. Types are
273 /// completely distinct from Values. Consequently, Types are written in fixed
274 /// locations in LLVM 1.3. This flag indicates that the older Type derived
275 /// from Value style of bytecode file is being read.
276 bool hasTypeDerivedFromValue;
277
Reid Spencerad89bd62004-07-25 18:07:36 +0000278 /// LLVM 1.2 and earlier encoded block headers as two uint (8 bytes), one for
Chris Lattner45b5dd22004-08-03 23:41:28 +0000279 /// the size and one for the type. This is a bit wasteful, especially for
280 /// small files where the 8 bytes per block is a large fraction of the total
281 /// block size. In LLVM 1.3, the block type and length are encoded into a
282 /// single uint32 by restricting the number of block types (limit 31) and the
283 /// maximum size of a block (limit 2^27-1=134,217,727). Note that the module
284 /// block still uses the 8-byte format so the maximum size of a file can be
Reid Spencerad89bd62004-07-25 18:07:36 +0000285 /// 2^32-1 bytes long.
286 bool hasLongBlockHeaders;
287
Reid Spencerad89bd62004-07-25 18:07:36 +0000288 /// LLVM 1.2 and earlier wrote type slot numbers as vbr_uint32. In LLVM 1.3
289 /// this has been reduced to vbr_uint24. It shouldn't make much difference
290 /// since we haven't run into a module with > 24 million types, but for safety
291 /// the 24-bit restriction has been enforced in 1.3 to free some bits in
292 /// various places and to ensure consistency. In particular, global vars are
293 /// restricted to 24-bits.
294 bool has32BitTypes;
295
296 /// LLVM 1.2 and earlier did not provide a target triple nor a list of
297 /// libraries on which the bytecode is dependent. LLVM 1.3 provides these
298 /// features, for use in future versions of LLVM.
299 bool hasNoDependentLibraries;
300
Reid Spencer38d54be2004-08-17 07:45:14 +0000301 /// LLVM 1.3 and earlier caused blocks and other fields to start on 32-bit
302 /// aligned boundaries. This can lead to as much as 30% bytecode size overhead
303 /// in various corner cases (lots of long instructions). In LLVM 1.4,
304 /// alignment of bytecode fields was done away with completely.
305 bool hasAlignment;
Reid Spencerad89bd62004-07-25 18:07:36 +0000306
Chris Lattnera79e7cc2004-10-16 18:18:16 +0000307 // In version 4 and earlier, the bytecode format did not support the 'undef'
308 // constant.
309 bool hasNoUndefValue;
310
311 // In version 4 and earlier, the bytecode format did not save space for flags
312 // in the global info block for functions.
313 bool hasNoFlagsForFunctions;
314
315 // In version 4 and earlier, there was no opcode space reserved for the
316 // unreachable instruction.
317 bool hasNoUnreachableInst;
318
319 // In version 5, basic blocks have a minimum index of 0 whereas all the
Reid Spencer572c2562004-08-21 20:50:49 +0000320 // other primitives have a minimum index of 1 (because 0 is the "null"
321 // value. In version 5, we made this consistent.
322 bool hasInconsistentBBSlotNums;
323
Chris Lattnera79e7cc2004-10-16 18:18:16 +0000324 // In version 5, the types SByte and UByte were encoded as vbr_uint so that
Reid Spencer572c2562004-08-21 20:50:49 +0000325 // signed values > 63 and unsigned values >127 would be encoded as two
326 // bytes. In version 5, they are encoded directly in a single byte.
327 bool hasVBRByteTypes;
328
Chris Lattnera79e7cc2004-10-16 18:18:16 +0000329 // In version 5, modules begin with a "Module Block" which encodes a 4-byte
Reid Spencer572c2562004-08-21 20:50:49 +0000330 // integer value 0x01 to identify the module block. This is unnecessary and
331 // removed in version 5.
332 bool hasUnnecessaryModuleBlockId;
333
Chris Lattner45b5dd22004-08-03 23:41:28 +0000334 /// CompactionTypes - If a compaction table is active in the current function,
335 /// this is the mapping that it contains. We keep track of what resolved type
336 /// it is as well as what global type entry it is.
337 std::vector<std::pair<const Type*, unsigned> > CompactionTypes;
Reid Spencerf89143c2004-06-29 23:31:01 +0000338
339 /// @brief If a compaction table is active in the current function,
340 /// this is the mapping that it contains.
341 std::vector<std::vector<Value*> > CompactionValues;
342
343 /// @brief This vector is used to deal with forward references to types in
344 /// a module.
345 TypeListTy ModuleTypes;
346
347 /// @brief This vector is used to deal with forward references to types in
348 /// a function.
349 TypeListTy FunctionTypes;
350
351 /// When the ModuleGlobalInfo section is read, we create a Function object
352 /// for each function in the module. When the function is loaded, after the
353 /// module global info is read, this Function is populated. Until then, the
354 /// functions in this vector just hold the function signature.
355 std::vector<Function*> FunctionSignatureList;
356
357 /// @brief This is the table of values belonging to the current function
358 ValueTable FunctionValues;
359
360 /// @brief This is the table of values belonging to the module (global)
361 ValueTable ModuleValues;
362
363 /// @brief This keeps track of function level forward references.
364 ForwardReferenceMap ForwardReferences;
365
366 /// @brief The basic blocks we've parsed, while parsing a function.
367 std::vector<BasicBlock*> ParsedBasicBlocks;
368
Chris Lattner1c765b02004-10-14 01:49:34 +0000369 /// This maintains a mapping between <Type, Slot #>'s and forward references
370 /// to constants. Such values may be referenced before they are defined, and
371 /// if so, the temporary object that they represent is held here. @brief
372 /// Temporary place for forward references to constants.
Reid Spencerf89143c2004-06-29 23:31:01 +0000373 ConstantRefsType ConstantFwdRefs;
374
375 /// Constant values are read in after global variables. Because of this, we
376 /// must defer setting the initializers on global variables until after module
Chris Lattner1c765b02004-10-14 01:49:34 +0000377 /// level constants have been read. In the mean time, this list keeps track
378 /// of what we must do.
Reid Spencerf89143c2004-06-29 23:31:01 +0000379 GlobalInitsList GlobalInits;
380
381 // For lazy reading-in of functions, we need to save away several pieces of
382 // information about each function: its begin and end pointer in the buffer
383 // and its FunctionSlot.
384 LazyFunctionMap LazyFunctionLoadMap;
385
386 /// This stores the parser's handler which is used for handling tasks other
387 /// just than reading bytecode into the IR. If this is non-null, calls on
388 /// the (polymorphic) BytecodeHandler interface (see llvm/Bytecode/Handler.h)
389 /// will be made to report the logical structure of the bytecode file. What
390 /// the handler does with the events it receives is completely orthogonal to
391 /// the business of parsing the bytecode and building the IR. This is used,
392 /// for example, by the llvm-abcd tool for analysis of byte code.
393 /// @brief Handler for parsing events.
394 BytecodeHandler* Handler;
395
396/// @}
397/// @name Implementation Details
398/// @{
399private:
400 /// @brief Determines if this module has a function or not.
401 bool hasFunctions() { return ! FunctionSignatureList.empty(); }
402
403 /// @brief Determines if the type id has an implicit null value.
404 bool hasImplicitNull(unsigned TyID );
405
406 /// @brief Converts a type slot number to its Type*
407 const Type *getType(unsigned ID);
408
Reid Spencera86159c2004-07-04 11:04:56 +0000409 /// @brief Converts a pre-sanitized type slot number to its Type* and
410 /// sanitizes the type id.
411 inline const Type* getSanitizedType(unsigned& ID );
412
413 /// @brief Read in and get a sanitized type id
Chris Lattner19925222004-11-15 21:55:06 +0000414 inline const Type* readSanitizedType();
Reid Spencera86159c2004-07-04 11:04:56 +0000415
Reid Spencerf89143c2004-06-29 23:31:01 +0000416 /// @brief Converts a Type* to its type slot number
417 unsigned getTypeSlot(const Type *Ty);
418
419 /// @brief Converts a normal type slot number to a compacted type slot num.
420 unsigned getCompactionTypeSlot(unsigned type);
421
Reid Spencera86159c2004-07-04 11:04:56 +0000422 /// @brief Gets the global type corresponding to the TypeId
423 const Type *getGlobalTableType(unsigned TypeId);
Reid Spencerf89143c2004-06-29 23:31:01 +0000424
425 /// This is just like getTypeSlot, but when a compaction table is in use,
426 /// it is ignored.
427 unsigned getGlobalTableTypeSlot(const Type *Ty);
428
Reid Spencera86159c2004-07-04 11:04:56 +0000429 /// @brief Get a value from its typeid and slot number
Reid Spencerf89143c2004-06-29 23:31:01 +0000430 Value* getValue(unsigned TypeID, unsigned num, bool Create = true);
431
Chris Lattner2c6c14d2004-08-04 00:19:23 +0000432 /// @brief Get a value from its type and slot number, ignoring compaction
433 /// tables.
434 Value *getGlobalTableValue(unsigned TyID, unsigned SlotNo);
Reid Spencerf89143c2004-06-29 23:31:01 +0000435
Reid Spencerf89143c2004-06-29 23:31:01 +0000436 /// @brief Get a basic block for current function
437 BasicBlock *getBasicBlock(unsigned ID);
438
Reid Spencera86159c2004-07-04 11:04:56 +0000439 /// @brief Get a constant value from its typeid and value slot.
Reid Spencerf89143c2004-06-29 23:31:01 +0000440 Constant* getConstantValue(unsigned typeSlot, unsigned valSlot);
441
442 /// @brief Convenience function for getting a constant value when
443 /// the Type has already been resolved.
444 Constant* getConstantValue(const Type *Ty, unsigned valSlot) {
445 return getConstantValue(getTypeSlot(Ty), valSlot);
446 }
447
Reid Spencerf89143c2004-06-29 23:31:01 +0000448 /// @brief Insert a newly created value
449 unsigned insertValue(Value *V, unsigned Type, ValueTable &Table);
450
451 /// @brief Insert the arguments of a function.
452 void insertArguments(Function* F );
453
454 /// @brief Resolve all references to the placeholder (if any) for the
455 /// given constant.
456 void ResolveReferencesToConstant(Constant *C, unsigned Slot);
457
458 /// @brief Release our memory.
459 void freeState() {
460 freeTable(FunctionValues);
461 freeTable(ModuleValues);
462 }
463
464 /// @brief Free a table, making sure to free the ValueList in the table.
465 void freeTable(ValueTable &Tab) {
466 while (!Tab.empty()) {
467 delete Tab.back();
468 Tab.pop_back();
469 }
470 }
471
Reid Spencer24399722004-07-09 22:21:33 +0000472 inline void error(std::string errmsg);
473
Reid Spencerf89143c2004-06-29 23:31:01 +0000474 BytecodeReader(const BytecodeReader &); // DO NOT IMPLEMENT
475 void operator=(const BytecodeReader &); // DO NOT IMPLEMENT
476
477/// @}
478/// @name Reader Primitives
479/// @{
480private:
481
482 /// @brief Is there more to parse in the current block?
483 inline bool moreInBlock();
484
485 /// @brief Have we read past the end of the block
486 inline void checkPastBlockEnd(const char * block_name);
487
488 /// @brief Align to 32 bits
489 inline void align32();
490
491 /// @brief Read an unsigned integer as 32-bits
492 inline unsigned read_uint();
493
494 /// @brief Read an unsigned integer with variable bit rate encoding
495 inline unsigned read_vbr_uint();
496
Reid Spencerad89bd62004-07-25 18:07:36 +0000497 /// @brief Read an unsigned integer of no more than 24-bits with variable
498 /// bit rate encoding.
499 inline unsigned read_vbr_uint24();
500
Reid Spencerf89143c2004-06-29 23:31:01 +0000501 /// @brief Read an unsigned 64-bit integer with variable bit rate encoding.
502 inline uint64_t read_vbr_uint64();
503
504 /// @brief Read a signed 64-bit integer with variable bit rate encoding.
505 inline int64_t read_vbr_int64();
506
507 /// @brief Read a string
508 inline std::string read_str();
509
Reid Spencer66906512004-07-11 17:24:05 +0000510 /// @brief Read a float value
511 inline void read_float(float& FloatVal);
512
513 /// @brief Read a double value
514 inline void read_double(double& DoubleVal);
515
Reid Spencerf89143c2004-06-29 23:31:01 +0000516 /// @brief Read an arbitrary data chunk of fixed length
517 inline void read_data(void *Ptr, void *End);
518
Reid Spencera86159c2004-07-04 11:04:56 +0000519 /// @brief Read a bytecode block header
Reid Spencerf89143c2004-06-29 23:31:01 +0000520 inline void read_block(unsigned &Type, unsigned &Size);
521
Reid Spencera86159c2004-07-04 11:04:56 +0000522 /// @brief Read a type identifier and sanitize it.
523 inline bool read_typeid(unsigned &TypeId);
524
525 /// @brief Recalculate type ID for pre 1.3 bytecode files.
526 inline bool sanitizeTypeId(unsigned &TypeId );
Reid Spencerf89143c2004-06-29 23:31:01 +0000527/// @}
528};
529
Reid Spencera86159c2004-07-04 11:04:56 +0000530/// @brief A function for creating a BytecodeAnalzer as a handler
531/// for the Bytecode reader.
Reid Spencer572c2562004-08-21 20:50:49 +0000532BytecodeHandler* createBytecodeAnalyzerHandler(BytecodeAnalysis& bca,
533 std::ostream* output );
Reid Spencera86159c2004-07-04 11:04:56 +0000534
535
Reid Spencerf89143c2004-06-29 23:31:01 +0000536} // End llvm namespace
537
538// vim: sw=2
539#endif