blob: 72a6040366403950cfe797eb47d10e3bd2e15a17 [file] [log] [blame]
Reid Spencerf4ec6382004-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 Spencere6c95492004-07-04 11:04:56 +000024#include "llvm/Bytecode/Analyzer.h"
Reid Spencerf4ec6382004-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.
47 BytecodeReader(
48 BytecodeHandler* h = 0
49 ) {
Reid Spencer2e492042004-11-06 23:17:23 +000050 Handler = h;
Reid Spencerf4ec6382004-06-29 23:31:01 +000051 }
52
Reid Spencer2e492042004-11-06 23:17:23 +000053 ~BytecodeReader() {
54 freeState();
55 if (bi.buff != 0)
56 ::free(bi.buff);
57 }
Reid Spencerf4ec6382004-06-29 23:31:01 +000058
59/// @}
60/// @name Types
61/// @{
62public:
Reid Spencerb2bdb942004-07-25 18:07:36 +000063
Reid Spencerf4ec6382004-06-29 23:31:01 +000064 /// @brief A convenience type for the buffer pointer
65 typedef const unsigned char* BufPtr;
66
67 /// @brief The type used for a vector of potentially abstract types
68 typedef std::vector<PATypeHolder> TypeListTy;
69
Reid Spencer899ad352004-11-07 18:19:00 +000070 /// This structure is only used when a bytecode file is compressed.
71 /// As bytecode is being decompressed, the memory buffer might need
72 /// to be reallocated. The buffer allocation is handled in a callback
73 /// and this structure is needed to retain information across calls
74 /// to the callback.
Reid Spencer2e492042004-11-06 23:17:23 +000075 /// @brief An internal buffer object used for handling decompression
76 struct BufferInfo {
77 char* buff;
78 unsigned size;
79 BufferInfo() { buff = 0; size = 0; }
80 };
81
Reid Spencerf4ec6382004-06-29 23:31:01 +000082 /// This type provides a vector of Value* via the User class for
83 /// storage of Values that have been constructed when reading the
84 /// bytecode. Because of forward referencing, constant replacement
85 /// can occur so we ensure that our list of Value* is updated
86 /// properly through those transitions. This ensures that the
87 /// correct Value* is in our list when it comes time to associate
88 /// constants with global variables at the end of reading the
89 /// globals section.
90 /// @brief A list of values as a User of those Values.
91 struct ValueList : public User {
Reid Spencer1d8d08f2004-07-18 00:13:12 +000092 ValueList() : User(Type::VoidTy, Value::ValueListVal) {}
Reid Spencerf4ec6382004-06-29 23:31:01 +000093
94 // vector compatibility methods
95 unsigned size() const { return getNumOperands(); }
96 void push_back(Value *V) { Operands.push_back(Use(V, this)); }
97 Value *back() const { return Operands.back(); }
98 void pop_back() { Operands.pop_back(); }
99 bool empty() const { return Operands.empty(); }
100 // must override this
101 virtual void print(std::ostream& os) const {
102 for ( unsigned i = 0; i < size(); i++ ) {
Reid Spencere6c95492004-07-04 11:04:56 +0000103 os << i << " ";
104 getOperand(i)->print(os);
105 os << "\n";
Reid Spencerf4ec6382004-06-29 23:31:01 +0000106 }
107 }
108 };
109
110 /// @brief A 2 dimensional table of values
111 typedef std::vector<ValueList*> ValueTable;
112
113 /// This map is needed so that forward references to constants can be looked
114 /// up by Type and slot number when resolving those references.
115 /// @brief A mapping of a Type/slot pair to a Constant*.
116 typedef std::map<std::pair<const Type*,unsigned>, Constant*> ConstantRefsType;
117
118 /// For lazy read-in of functions, we need to save the location in the
119 /// data stream where the function is located. This structure provides that
120 /// information. Lazy read-in is used mostly by the JIT which only wants to
121 /// resolve functions as it needs them.
122 /// @brief Keeps pointers to function contents for later use.
123 struct LazyFunctionInfo {
124 const unsigned char *Buf, *EndBuf;
125 LazyFunctionInfo(const unsigned char *B = 0, const unsigned char *EB = 0)
126 : Buf(B), EndBuf(EB) {}
127 };
128
129 /// @brief A mapping of functions to their LazyFunctionInfo for lazy reading.
130 typedef std::map<Function*, LazyFunctionInfo> LazyFunctionMap;
131
132 /// @brief A list of global variables and the slot number that initializes
133 /// them.
134 typedef std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInitsList;
135
136 /// This type maps a typeslot/valueslot pair to the corresponding Value*.
137 /// It is used for dealing with forward references as values are read in.
138 /// @brief A map for dealing with forward references of values.
139 typedef std::map<std::pair<unsigned,unsigned>,Value*> ForwardReferenceMap;
140
141/// @}
142/// @name Methods
143/// @{
144public:
Reid Spencerf4ec6382004-06-29 23:31:01 +0000145 /// @brief Main interface to parsing a bytecode buffer.
146 void ParseBytecode(
Reid Spencer02b67082004-07-05 00:57:50 +0000147 const unsigned char *Buf, ///< Beginning of the bytecode buffer
148 unsigned Length, ///< Length of the bytecode buffer
Reid Spencer8631bc32004-08-21 20:50:49 +0000149 const std::string &ModuleID ///< An identifier for the module constructed.
Reid Spencerf4ec6382004-06-29 23:31:01 +0000150 );
151
Reid Spencerf4ec6382004-06-29 23:31:01 +0000152 /// @brief Parse all function bodies
Reid Spencere6c95492004-07-04 11:04:56 +0000153 void ParseAllFunctionBodies();
Reid Spencerf4ec6382004-06-29 23:31:01 +0000154
Reid Spencerf4ec6382004-06-29 23:31:01 +0000155 /// @brief Parse the next function of specific type
Reid Spencere6c95492004-07-04 11:04:56 +0000156 void ParseFunction(Function* Func) ;
Reid Spencerf4ec6382004-06-29 23:31:01 +0000157
158 /// This method is abstract in the parent ModuleProvider class. Its
159 /// implementation is identical to the ParseFunction method.
160 /// @see ParseFunction
161 /// @brief Make a specific function materialize.
162 virtual void materializeFunction(Function *F) {
163 LazyFunctionMap::iterator Fi = LazyFunctionLoadMap.find(F);
164 if (Fi == LazyFunctionLoadMap.end()) return;
165 ParseFunction(F);
166 }
167
168 /// This method is abstract in the parent ModuleProvider class. Its
169 /// implementation is identical to ParseAllFunctionBodies.
170 /// @see ParseAllFunctionBodies
171 /// @brief Make the whole module materialize
172 virtual Module* materializeModule() {
173 ParseAllFunctionBodies();
174 return TheModule;
175 }
176
177 /// This method is provided by the parent ModuleProvde class and overriden
178 /// here. It simply releases the module from its provided and frees up our
179 /// state.
180 /// @brief Release our hold on the generated module
181 Module* releaseModule() {
182 // Since we're losing control of this Module, we must hand it back complete
183 Module *M = ModuleProvider::releaseModule();
184 freeState();
185 return M;
186 }
187
188/// @}
189/// @name Parsing Units For Subclasses
190/// @{
191protected:
192 /// @brief Parse whole module scope
193 void ParseModule();
194
195 /// @brief Parse the version information block
196 void ParseVersionInfo();
197
198 /// @brief Parse the ModuleGlobalInfo block
199 void ParseModuleGlobalInfo();
200
201 /// @brief Parse a symbol table
202 void ParseSymbolTable( Function* Func, SymbolTable *ST);
203
Reid Spencerf4ec6382004-06-29 23:31:01 +0000204 /// @brief Parse functions lazily.
205 void ParseFunctionLazily();
206
207 /// @brief Parse a function body
208 void ParseFunctionBody(Function* Func);
209
Reid Spencere6c95492004-07-04 11:04:56 +0000210 /// @brief Parse the type list portion of a compaction table
Chris Lattnercd843962004-08-03 23:41:28 +0000211 void ParseCompactionTypes(unsigned NumEntries);
Reid Spencere6c95492004-07-04 11:04:56 +0000212
Reid Spencerf4ec6382004-06-29 23:31:01 +0000213 /// @brief Parse a compaction table
214 void ParseCompactionTable();
215
216 /// @brief Parse global types
217 void ParseGlobalTypes();
218
Reid Spencerf4ec6382004-06-29 23:31:01 +0000219 /// @brief Parse a basic block (for LLVM 1.0 basic block blocks)
220 BasicBlock* ParseBasicBlock(unsigned BlockNo);
221
Reid Spencerf4ec6382004-06-29 23:31:01 +0000222 /// @brief parse an instruction list (for post LLVM 1.0 instruction lists
223 /// with blocks differentiated by terminating instructions.
224 unsigned ParseInstructionList(
225 Function* F ///< The function into which BBs will be inserted
226 );
227
Reid Spencerf4ec6382004-06-29 23:31:01 +0000228 /// @brief Parse a single instruction.
229 void ParseInstruction(
230 std::vector<unsigned>& Args, ///< The arguments to be filled in
231 BasicBlock* BB ///< The BB the instruction goes in
232 );
233
234 /// @brief Parse the whole constant pool
Reid Spencere6c95492004-07-04 11:04:56 +0000235 void ParseConstantPool(ValueTable& Values, TypeListTy& Types,
236 bool isFunction);
Reid Spencerf4ec6382004-06-29 23:31:01 +0000237
238 /// @brief Parse a single constant value
239 Constant* ParseConstantValue(unsigned TypeID);
240
241 /// @brief Parse a block of types constants
Reid Spencerdb3bf192004-07-11 17:24:05 +0000242 void ParseTypes(TypeListTy &Tab, unsigned NumEntries);
Reid Spencerf4ec6382004-06-29 23:31:01 +0000243
244 /// @brief Parse a single type constant
Reid Spencerdb3bf192004-07-11 17:24:05 +0000245 const Type *ParseType();
Reid Spencerf4ec6382004-06-29 23:31:01 +0000246
247 /// @brief Parse a string constants block
248 void ParseStringConstants(unsigned NumEntries, ValueTable &Tab);
249
250/// @}
251/// @name Data
252/// @{
253private:
Reid Spencer899ad352004-11-07 18:19:00 +0000254 BufferInfo bi; ///< Buffer info for decompression
Reid Spencerf4ec6382004-06-29 23:31:01 +0000255 BufPtr MemStart; ///< Start of the memory buffer
256 BufPtr MemEnd; ///< End of the memory buffer
257 BufPtr BlockStart; ///< Start of current block being parsed
258 BufPtr BlockEnd; ///< End of current block being parsed
259 BufPtr At; ///< Where we're currently parsing at
260
Reid Spencere6c95492004-07-04 11:04:56 +0000261 /// Information about the module, extracted from the bytecode revision number.
Chris Lattnercd843962004-08-03 23:41:28 +0000262 ///
Reid Spencerf4ec6382004-06-29 23:31:01 +0000263 unsigned char RevisionNum; // The rev # itself
264
Reid Spencere6c95492004-07-04 11:04:56 +0000265 /// Flags to distinguish LLVM 1.0 & 1.1 bytecode formats (revision #0)
Reid Spencerf4ec6382004-06-29 23:31:01 +0000266
Chris Lattnercd843962004-08-03 23:41:28 +0000267 /// Revision #0 had an explicit alignment of data only for the
268 /// ModuleGlobalInfo block. This was fixed to be like all other blocks in 1.2
Reid Spencerf4ec6382004-06-29 23:31:01 +0000269 bool hasInconsistentModuleGlobalInfo;
270
Reid Spencere6c95492004-07-04 11:04:56 +0000271 /// Revision #0 also explicitly encoded zero values for primitive types like
272 /// int/sbyte/etc.
Reid Spencerf4ec6382004-06-29 23:31:01 +0000273 bool hasExplicitPrimitiveZeros;
274
275 // Flags to control features specific the LLVM 1.2 and before (revision #1)
276
Reid Spencere6c95492004-07-04 11:04:56 +0000277 /// LLVM 1.2 and earlier required that getelementptr structure indices were
278 /// ubyte constants and that sequential type indices were longs.
Reid Spencerf4ec6382004-06-29 23:31:01 +0000279 bool hasRestrictedGEPTypes;
280
Reid Spencere6c95492004-07-04 11:04:56 +0000281 /// LLVM 1.2 and earlier had class Type deriving from Value and the Type
282 /// objects were located in the "Type Type" plane of various lists in read
283 /// by the bytecode reader. In LLVM 1.3 this is no longer the case. Types are
284 /// completely distinct from Values. Consequently, Types are written in fixed
285 /// locations in LLVM 1.3. This flag indicates that the older Type derived
286 /// from Value style of bytecode file is being read.
287 bool hasTypeDerivedFromValue;
288
Reid Spencerb2bdb942004-07-25 18:07:36 +0000289 /// LLVM 1.2 and earlier encoded block headers as two uint (8 bytes), one for
Chris Lattnercd843962004-08-03 23:41:28 +0000290 /// the size and one for the type. This is a bit wasteful, especially for
291 /// small files where the 8 bytes per block is a large fraction of the total
292 /// block size. In LLVM 1.3, the block type and length are encoded into a
293 /// single uint32 by restricting the number of block types (limit 31) and the
294 /// maximum size of a block (limit 2^27-1=134,217,727). Note that the module
295 /// block still uses the 8-byte format so the maximum size of a file can be
Reid Spencerb2bdb942004-07-25 18:07:36 +0000296 /// 2^32-1 bytes long.
297 bool hasLongBlockHeaders;
298
Reid Spencerb2bdb942004-07-25 18:07:36 +0000299 /// LLVM 1.2 and earlier wrote type slot numbers as vbr_uint32. In LLVM 1.3
300 /// this has been reduced to vbr_uint24. It shouldn't make much difference
301 /// since we haven't run into a module with > 24 million types, but for safety
302 /// the 24-bit restriction has been enforced in 1.3 to free some bits in
303 /// various places and to ensure consistency. In particular, global vars are
304 /// restricted to 24-bits.
305 bool has32BitTypes;
306
307 /// LLVM 1.2 and earlier did not provide a target triple nor a list of
308 /// libraries on which the bytecode is dependent. LLVM 1.3 provides these
309 /// features, for use in future versions of LLVM.
310 bool hasNoDependentLibraries;
311
Reid Spencerc3e43642004-08-17 07:45:14 +0000312 /// LLVM 1.3 and earlier caused blocks and other fields to start on 32-bit
313 /// aligned boundaries. This can lead to as much as 30% bytecode size overhead
314 /// in various corner cases (lots of long instructions). In LLVM 1.4,
315 /// alignment of bytecode fields was done away with completely.
316 bool hasAlignment;
Reid Spencerb2bdb942004-07-25 18:07:36 +0000317
Chris Lattner770709b2004-10-16 18:18:16 +0000318 // In version 4 and earlier, the bytecode format did not support the 'undef'
319 // constant.
320 bool hasNoUndefValue;
321
322 // In version 4 and earlier, the bytecode format did not save space for flags
323 // in the global info block for functions.
324 bool hasNoFlagsForFunctions;
325
326 // In version 4 and earlier, there was no opcode space reserved for the
327 // unreachable instruction.
328 bool hasNoUnreachableInst;
329
330 // In version 5, basic blocks have a minimum index of 0 whereas all the
Reid Spencer8631bc32004-08-21 20:50:49 +0000331 // other primitives have a minimum index of 1 (because 0 is the "null"
332 // value. In version 5, we made this consistent.
333 bool hasInconsistentBBSlotNums;
334
Chris Lattner770709b2004-10-16 18:18:16 +0000335 // In version 5, the types SByte and UByte were encoded as vbr_uint so that
Reid Spencer8631bc32004-08-21 20:50:49 +0000336 // signed values > 63 and unsigned values >127 would be encoded as two
337 // bytes. In version 5, they are encoded directly in a single byte.
338 bool hasVBRByteTypes;
339
Chris Lattner770709b2004-10-16 18:18:16 +0000340 // In version 5, modules begin with a "Module Block" which encodes a 4-byte
Reid Spencer8631bc32004-08-21 20:50:49 +0000341 // integer value 0x01 to identify the module block. This is unnecessary and
342 // removed in version 5.
343 bool hasUnnecessaryModuleBlockId;
344
Chris Lattnercd843962004-08-03 23:41:28 +0000345 /// CompactionTypes - If a compaction table is active in the current function,
346 /// this is the mapping that it contains. We keep track of what resolved type
347 /// it is as well as what global type entry it is.
348 std::vector<std::pair<const Type*, unsigned> > CompactionTypes;
Reid Spencerf4ec6382004-06-29 23:31:01 +0000349
350 /// @brief If a compaction table is active in the current function,
351 /// this is the mapping that it contains.
352 std::vector<std::vector<Value*> > CompactionValues;
353
354 /// @brief This vector is used to deal with forward references to types in
355 /// a module.
356 TypeListTy ModuleTypes;
357
358 /// @brief This vector is used to deal with forward references to types in
359 /// a function.
360 TypeListTy FunctionTypes;
361
362 /// When the ModuleGlobalInfo section is read, we create a Function object
363 /// for each function in the module. When the function is loaded, after the
364 /// module global info is read, this Function is populated. Until then, the
365 /// functions in this vector just hold the function signature.
366 std::vector<Function*> FunctionSignatureList;
367
368 /// @brief This is the table of values belonging to the current function
369 ValueTable FunctionValues;
370
371 /// @brief This is the table of values belonging to the module (global)
372 ValueTable ModuleValues;
373
374 /// @brief This keeps track of function level forward references.
375 ForwardReferenceMap ForwardReferences;
376
377 /// @brief The basic blocks we've parsed, while parsing a function.
378 std::vector<BasicBlock*> ParsedBasicBlocks;
379
Chris Lattner315157d2004-10-14 01:49:34 +0000380 /// This maintains a mapping between <Type, Slot #>'s and forward references
381 /// to constants. Such values may be referenced before they are defined, and
382 /// if so, the temporary object that they represent is held here. @brief
383 /// Temporary place for forward references to constants.
Reid Spencerf4ec6382004-06-29 23:31:01 +0000384 ConstantRefsType ConstantFwdRefs;
385
386 /// Constant values are read in after global variables. Because of this, we
387 /// must defer setting the initializers on global variables until after module
Chris Lattner315157d2004-10-14 01:49:34 +0000388 /// level constants have been read. In the mean time, this list keeps track
389 /// of what we must do.
Reid Spencerf4ec6382004-06-29 23:31:01 +0000390 GlobalInitsList GlobalInits;
391
392 // For lazy reading-in of functions, we need to save away several pieces of
393 // information about each function: its begin and end pointer in the buffer
394 // and its FunctionSlot.
395 LazyFunctionMap LazyFunctionLoadMap;
396
397 /// This stores the parser's handler which is used for handling tasks other
398 /// just than reading bytecode into the IR. If this is non-null, calls on
399 /// the (polymorphic) BytecodeHandler interface (see llvm/Bytecode/Handler.h)
400 /// will be made to report the logical structure of the bytecode file. What
401 /// the handler does with the events it receives is completely orthogonal to
402 /// the business of parsing the bytecode and building the IR. This is used,
403 /// for example, by the llvm-abcd tool for analysis of byte code.
404 /// @brief Handler for parsing events.
405 BytecodeHandler* Handler;
406
407/// @}
408/// @name Implementation Details
409/// @{
410private:
411 /// @brief Determines if this module has a function or not.
412 bool hasFunctions() { return ! FunctionSignatureList.empty(); }
413
414 /// @brief Determines if the type id has an implicit null value.
415 bool hasImplicitNull(unsigned TyID );
416
417 /// @brief Converts a type slot number to its Type*
418 const Type *getType(unsigned ID);
419
Reid Spencere6c95492004-07-04 11:04:56 +0000420 /// @brief Converts a pre-sanitized type slot number to its Type* and
421 /// sanitizes the type id.
422 inline const Type* getSanitizedType(unsigned& ID );
423
424 /// @brief Read in and get a sanitized type id
425 inline const Type* BytecodeReader::readSanitizedType();
426
Reid Spencerf4ec6382004-06-29 23:31:01 +0000427 /// @brief Converts a Type* to its type slot number
428 unsigned getTypeSlot(const Type *Ty);
429
430 /// @brief Converts a normal type slot number to a compacted type slot num.
431 unsigned getCompactionTypeSlot(unsigned type);
432
Reid Spencere6c95492004-07-04 11:04:56 +0000433 /// @brief Gets the global type corresponding to the TypeId
434 const Type *getGlobalTableType(unsigned TypeId);
Reid Spencerf4ec6382004-06-29 23:31:01 +0000435
436 /// This is just like getTypeSlot, but when a compaction table is in use,
437 /// it is ignored.
438 unsigned getGlobalTableTypeSlot(const Type *Ty);
439
Reid Spencere6c95492004-07-04 11:04:56 +0000440 /// @brief Get a value from its typeid and slot number
Reid Spencerf4ec6382004-06-29 23:31:01 +0000441 Value* getValue(unsigned TypeID, unsigned num, bool Create = true);
442
Chris Lattnerbba09b32004-08-04 00:19:23 +0000443 /// @brief Get a value from its type and slot number, ignoring compaction
444 /// tables.
445 Value *getGlobalTableValue(unsigned TyID, unsigned SlotNo);
Reid Spencerf4ec6382004-06-29 23:31:01 +0000446
Reid Spencerf4ec6382004-06-29 23:31:01 +0000447 /// @brief Get a basic block for current function
448 BasicBlock *getBasicBlock(unsigned ID);
449
Reid Spencere6c95492004-07-04 11:04:56 +0000450 /// @brief Get a constant value from its typeid and value slot.
Reid Spencerf4ec6382004-06-29 23:31:01 +0000451 Constant* getConstantValue(unsigned typeSlot, unsigned valSlot);
452
453 /// @brief Convenience function for getting a constant value when
454 /// the Type has already been resolved.
455 Constant* getConstantValue(const Type *Ty, unsigned valSlot) {
456 return getConstantValue(getTypeSlot(Ty), valSlot);
457 }
458
Reid Spencerf4ec6382004-06-29 23:31:01 +0000459 /// @brief Insert a newly created value
460 unsigned insertValue(Value *V, unsigned Type, ValueTable &Table);
461
462 /// @brief Insert the arguments of a function.
463 void insertArguments(Function* F );
464
465 /// @brief Resolve all references to the placeholder (if any) for the
466 /// given constant.
467 void ResolveReferencesToConstant(Constant *C, unsigned Slot);
468
469 /// @brief Release our memory.
470 void freeState() {
471 freeTable(FunctionValues);
472 freeTable(ModuleValues);
473 }
474
475 /// @brief Free a table, making sure to free the ValueList in the table.
476 void freeTable(ValueTable &Tab) {
477 while (!Tab.empty()) {
478 delete Tab.back();
479 Tab.pop_back();
480 }
481 }
482
Reid Spencerf3905c82004-07-09 22:21:33 +0000483 inline void error(std::string errmsg);
484
Reid Spencerf4ec6382004-06-29 23:31:01 +0000485 BytecodeReader(const BytecodeReader &); // DO NOT IMPLEMENT
486 void operator=(const BytecodeReader &); // DO NOT IMPLEMENT
487
488/// @}
489/// @name Reader Primitives
490/// @{
491private:
492
493 /// @brief Is there more to parse in the current block?
494 inline bool moreInBlock();
495
496 /// @brief Have we read past the end of the block
497 inline void checkPastBlockEnd(const char * block_name);
498
499 /// @brief Align to 32 bits
500 inline void align32();
501
502 /// @brief Read an unsigned integer as 32-bits
503 inline unsigned read_uint();
504
505 /// @brief Read an unsigned integer with variable bit rate encoding
506 inline unsigned read_vbr_uint();
507
Reid Spencerb2bdb942004-07-25 18:07:36 +0000508 /// @brief Read an unsigned integer of no more than 24-bits with variable
509 /// bit rate encoding.
510 inline unsigned read_vbr_uint24();
511
Reid Spencerf4ec6382004-06-29 23:31:01 +0000512 /// @brief Read an unsigned 64-bit integer with variable bit rate encoding.
513 inline uint64_t read_vbr_uint64();
514
515 /// @brief Read a signed 64-bit integer with variable bit rate encoding.
516 inline int64_t read_vbr_int64();
517
518 /// @brief Read a string
519 inline std::string read_str();
520
Reid Spencerdb3bf192004-07-11 17:24:05 +0000521 /// @brief Read a float value
522 inline void read_float(float& FloatVal);
523
524 /// @brief Read a double value
525 inline void read_double(double& DoubleVal);
526
Reid Spencerf4ec6382004-06-29 23:31:01 +0000527 /// @brief Read an arbitrary data chunk of fixed length
528 inline void read_data(void *Ptr, void *End);
529
Reid Spencere6c95492004-07-04 11:04:56 +0000530 /// @brief Read a bytecode block header
Reid Spencerf4ec6382004-06-29 23:31:01 +0000531 inline void read_block(unsigned &Type, unsigned &Size);
532
Reid Spencere6c95492004-07-04 11:04:56 +0000533 /// @brief Read a type identifier and sanitize it.
534 inline bool read_typeid(unsigned &TypeId);
535
536 /// @brief Recalculate type ID for pre 1.3 bytecode files.
537 inline bool sanitizeTypeId(unsigned &TypeId );
Reid Spencerf4ec6382004-06-29 23:31:01 +0000538/// @}
539};
540
Reid Spencere6c95492004-07-04 11:04:56 +0000541/// @brief A function for creating a BytecodeAnalzer as a handler
542/// for the Bytecode reader.
Reid Spencer8631bc32004-08-21 20:50:49 +0000543BytecodeHandler* createBytecodeAnalyzerHandler(BytecodeAnalysis& bca,
544 std::ostream* output );
Reid Spencere6c95492004-07-04 11:04:56 +0000545
546
Reid Spencerf4ec6382004-06-29 23:31:01 +0000547} // End llvm namespace
548
549// vim: sw=2
550#endif