blob: c852cce6babdc18873c73d462ff39887c7e45d44 [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"
Reid Spencerf89143c2004-06-29 23:31:01 +000021#include "llvm/ModuleProvider.h"
Reid Spencera86159c2004-07-04 11:04:56 +000022#include "llvm/Bytecode/Analyzer.h"
Chris Lattner63cf59e2007-02-07 05:08:39 +000023#include "llvm/ADT/SmallVector.h"
Reid Spencerf89143c2004-06-29 23:31:01 +000024#include <utility>
Reid Spencer233fe722006-08-22 16:09:19 +000025#include <setjmp.h>
Reid Spencerf89143c2004-06-29 23:31:01 +000026
27namespace llvm {
28
Reid Spenceref9b9a72007-02-05 20:47:22 +000029// Forward declarations
30class BytecodeHandler;
31class TypeSymbolTable;
32class ValueSymbolTable;
Reid Spencerf89143c2004-06-29 23:31:01 +000033
34/// This class defines the interface for parsing a buffer of bytecode. The
35/// parser itself takes no action except to call the various functions of
36/// the handler interface. The parser's sole responsibility is the correct
Misha Brukman8a96c532005-04-21 21:44:41 +000037/// interpretation of the bytecode buffer. The handler is responsible for
38/// instantiating and keeping track of all values. As a convenience, the parser
Reid Spencerf89143c2004-06-29 23:31:01 +000039/// is responsible for materializing types and will pass them through the
40/// handler interface as necessary.
41/// @see BytecodeHandler
42/// @brief Bytecode Reader interface
43class BytecodeReader : public ModuleProvider {
44
45/// @name Constructors
46/// @{
47public:
48 /// @brief Default constructor. By default, no handler is used.
Misha Brukman8a96c532005-04-21 21:44:41 +000049 BytecodeReader(BytecodeHandler* h = 0) {
Reid Spencerd3539b82004-11-14 22:00:09 +000050 decompressedBlock = 0;
Reid Spencer17f52c52004-11-06 23:17:23 +000051 Handler = h;
Reid Spencerf89143c2004-06-29 23:31:01 +000052 }
53
Misha Brukman8a96c532005-04-21 21:44:41 +000054 ~BytecodeReader() {
55 freeState();
Chris Lattner19925222004-11-15 21:55:06 +000056 if (decompressedBlock) {
Reid Spencerd3539b82004-11-14 22:00:09 +000057 ::free(decompressedBlock);
Chris Lattner19925222004-11-15 21:55:06 +000058 decompressedBlock = 0;
59 }
Reid Spencer17f52c52004-11-06 23:17:23 +000060 }
Reid Spencerf89143c2004-06-29 23:31:01 +000061
62/// @}
63/// @name Types
64/// @{
65public:
Reid Spencerad89bd62004-07-25 18:07:36 +000066
Reid Spencerf89143c2004-06-29 23:31:01 +000067 /// @brief A convenience type for the buffer pointer
68 typedef const unsigned char* BufPtr;
69
70 /// @brief The type used for a vector of potentially abstract types
71 typedef std::vector<PATypeHolder> TypeListTy;
72
73 /// This type provides a vector of Value* via the User class for
74 /// storage of Values that have been constructed when reading the
75 /// bytecode. Because of forward referencing, constant replacement
76 /// can occur so we ensure that our list of Value* is updated
77 /// properly through those transitions. This ensures that the
78 /// correct Value* is in our list when it comes time to associate
79 /// constants with global variables at the end of reading the
80 /// globals section.
81 /// @brief A list of values as a User of those Values.
Chris Lattnercad28bd2005-01-29 00:36:19 +000082 class ValueList : public User {
Chris Lattner18939522007-02-13 07:28:20 +000083 SmallVector<Use, 32> Uses;
Chris Lattnercad28bd2005-01-29 00:36:19 +000084 public:
Chris Lattnerfea49302005-08-16 21:59:52 +000085 ValueList() : User(Type::VoidTy, Value::ArgumentVal, 0, 0) {}
Reid Spencerf89143c2004-06-29 23:31:01 +000086
87 // vector compatibility methods
88 unsigned size() const { return getNumOperands(); }
Chris Lattnercad28bd2005-01-29 00:36:19 +000089 void push_back(Value *V) {
90 Uses.push_back(Use(V, this));
91 OperandList = &Uses[0];
92 ++NumOperands;
93 }
94 Value *back() const { return Uses.back(); }
95 void pop_back() { Uses.pop_back(); --NumOperands; }
96 bool empty() const { return NumOperands == 0; }
Reid Spencerf89143c2004-06-29 23:31:01 +000097 virtual void print(std::ostream& os) const {
Chris Lattnercad28bd2005-01-29 00:36:19 +000098 for (unsigned i = 0; i < size(); ++i) {
Reid Spencera86159c2004-07-04 11:04:56 +000099 os << i << " ";
100 getOperand(i)->print(os);
101 os << "\n";
Reid Spencerf89143c2004-06-29 23:31:01 +0000102 }
103 }
104 };
105
106 /// @brief A 2 dimensional table of values
107 typedef std::vector<ValueList*> ValueTable;
108
Misha Brukman8a96c532005-04-21 21:44:41 +0000109 /// This map is needed so that forward references to constants can be looked
Reid Spencerf89143c2004-06-29 23:31:01 +0000110 /// up by Type and slot number when resolving those references.
111 /// @brief A mapping of a Type/slot pair to a Constant*.
Chris Lattner389bd042004-12-09 06:19:44 +0000112 typedef std::map<std::pair<unsigned,unsigned>, Constant*> ConstantRefsType;
Reid Spencerf89143c2004-06-29 23:31:01 +0000113
114 /// For lazy read-in of functions, we need to save the location in the
115 /// data stream where the function is located. This structure provides that
116 /// information. Lazy read-in is used mostly by the JIT which only wants to
Misha Brukman8a96c532005-04-21 21:44:41 +0000117 /// resolve functions as it needs them.
Reid Spencerf89143c2004-06-29 23:31:01 +0000118 /// @brief Keeps pointers to function contents for later use.
119 struct LazyFunctionInfo {
120 const unsigned char *Buf, *EndBuf;
121 LazyFunctionInfo(const unsigned char *B = 0, const unsigned char *EB = 0)
122 : Buf(B), EndBuf(EB) {}
123 };
124
125 /// @brief A mapping of functions to their LazyFunctionInfo for lazy reading.
126 typedef std::map<Function*, LazyFunctionInfo> LazyFunctionMap;
127
128 /// @brief A list of global variables and the slot number that initializes
129 /// them.
130 typedef std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInitsList;
131
132 /// This type maps a typeslot/valueslot pair to the corresponding Value*.
133 /// It is used for dealing with forward references as values are read in.
134 /// @brief A map for dealing with forward references of values.
135 typedef std::map<std::pair<unsigned,unsigned>,Value*> ForwardReferenceMap;
136
137/// @}
138/// @name Methods
139/// @{
140public:
Chris Lattnerf2e292c2007-02-07 21:41:02 +0000141 typedef size_t BCDecompressor_t(const char *, size_t, char*&, std::string*);
142
Reid Spencer233fe722006-08-22 16:09:19 +0000143 /// @returns true if an error occurred
Reid Spencerf89143c2004-06-29 23:31:01 +0000144 /// @brief Main interface to parsing a bytecode buffer.
Reid Spencer233fe722006-08-22 16:09:19 +0000145 bool ParseBytecode(
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000146 volatile BufPtr Buf, ///< Beginning of the bytecode buffer
Reid Spencer5c15fe52004-07-05 00:57:50 +0000147 unsigned Length, ///< Length of the bytecode buffer
Reid Spencer233fe722006-08-22 16:09:19 +0000148 const std::string &ModuleID, ///< An identifier for the module constructed.
Chris Lattnerf2e292c2007-02-07 21:41:02 +0000149 BCDecompressor_t *Decompressor = 0, ///< Optional decompressor.
Reid Spencer233fe722006-08-22 16:09:19 +0000150 std::string* ErrMsg = 0 ///< Optional place for error message
Reid Spencerf89143c2004-06-29 23:31:01 +0000151 );
152
Reid Spencerf89143c2004-06-29 23:31:01 +0000153 /// @brief Parse all function bodies
Reid Spencer99655e12006-08-25 19:54:53 +0000154 bool ParseAllFunctionBodies(std::string* ErrMsg);
Reid Spencerf89143c2004-06-29 23:31:01 +0000155
Reid Spencerf89143c2004-06-29 23:31:01 +0000156 /// @brief Parse the next function of specific type
Chris Lattnerf735f7b2007-03-29 18:58:08 +0000157 bool ParseFunction(Function* Func, std::string* ErrMsg);
Reid Spencerf89143c2004-06-29 23:31:01 +0000158
159 /// This method is abstract in the parent ModuleProvider class. Its
160 /// implementation is identical to the ParseFunction method.
161 /// @see ParseFunction
162 /// @brief Make a specific function materialize.
Reid Spencer99655e12006-08-25 19:54:53 +0000163 virtual bool materializeFunction(Function *F, std::string *ErrMsg = 0) {
Chris Lattnerf735f7b2007-03-29 18:58:08 +0000164 // If it already is material, ignore the request.
165 if (!F->hasNotBeenReadFromBytecode()) return false;
166
167 assert(LazyFunctionLoadMap.count(F) &&
168 "not materialized but I don't know about it?");
Reid Spencer99655e12006-08-25 19:54:53 +0000169 if (ParseFunction(F,ErrMsg))
Chris Lattner0300f3e2006-07-06 21:35:01 +0000170 return true;
Chris Lattner0300f3e2006-07-06 21:35:01 +0000171 return false;
Reid Spencerf89143c2004-06-29 23:31:01 +0000172 }
Chris Lattnerf735f7b2007-03-29 18:58:08 +0000173
174 /// dematerializeFunction - If the given function is read in, and if the
175 /// module provider supports it, release the memory for the function, and set
176 /// it up to be materialized lazily. If the provider doesn't support this
177 /// capability, this method is a noop.
178 ///
179 virtual void dematerializeFunction(Function *F) {
180 // If the function is not materialized, or if it is a prototype, ignore.
181 if (F->hasNotBeenReadFromBytecode() ||
182 F->isDeclaration())
183 return;
184
185 // Just forget the function body, we can remat it later.
186 F->deleteBody();
187 F->setLinkage(GlobalValue::GhostLinkage);
188 }
Reid Spencerf89143c2004-06-29 23:31:01 +0000189
190 /// This method is abstract in the parent ModuleProvider class. Its
Misha Brukman8a96c532005-04-21 21:44:41 +0000191 /// implementation is identical to ParseAllFunctionBodies.
Reid Spencerf89143c2004-06-29 23:31:01 +0000192 /// @see ParseAllFunctionBodies
193 /// @brief Make the whole module materialize
Reid Spencer99655e12006-08-25 19:54:53 +0000194 virtual Module* materializeModule(std::string *ErrMsg = 0) {
195 if (ParseAllFunctionBodies(ErrMsg))
Chris Lattner0300f3e2006-07-06 21:35:01 +0000196 return 0;
Reid Spencerf89143c2004-06-29 23:31:01 +0000197 return TheModule;
198 }
199
200 /// This method is provided by the parent ModuleProvde class and overriden
201 /// here. It simply releases the module from its provided and frees up our
202 /// state.
203 /// @brief Release our hold on the generated module
Chris Lattner94aa7f32006-07-07 06:06:06 +0000204 Module* releaseModule(std::string *ErrInfo = 0) {
Reid Spencerf89143c2004-06-29 23:31:01 +0000205 // Since we're losing control of this Module, we must hand it back complete
Reid Spencer49521432006-11-11 11:54:25 +0000206 Module *M = ModuleProvider::releaseModule(ErrInfo);
Reid Spencerf89143c2004-06-29 23:31:01 +0000207 freeState();
208 return M;
209 }
210
211/// @}
212/// @name Parsing Units For Subclasses
213/// @{
214protected:
215 /// @brief Parse whole module scope
216 void ParseModule();
217
218 /// @brief Parse the version information block
219 void ParseVersionInfo();
220
221 /// @brief Parse the ModuleGlobalInfo block
222 void ParseModuleGlobalInfo();
223
Reid Spencer78d033e2007-01-06 07:24:44 +0000224 /// @brief Parse a value symbol table
225 void ParseTypeSymbolTable(TypeSymbolTable *ST);
226
227 /// @brief Parse a value symbol table
Reid Spenceref9b9a72007-02-05 20:47:22 +0000228 void ParseValueSymbolTable(Function* Func, ValueSymbolTable *ST);
Reid Spencerf89143c2004-06-29 23:31:01 +0000229
Reid Spencerf89143c2004-06-29 23:31:01 +0000230 /// @brief Parse functions lazily.
231 void ParseFunctionLazily();
232
233 /// @brief Parse a function body
234 void ParseFunctionBody(Function* Func);
235
Reid Spencerf89143c2004-06-29 23:31:01 +0000236 /// @brief Parse global types
237 void ParseGlobalTypes();
238
Reid Spencer91ac04a2007-04-09 06:14:31 +0000239
Reid Spencerf89143c2004-06-29 23:31:01 +0000240 /// @brief Parse a basic block (for LLVM 1.0 basic block blocks)
241 BasicBlock* ParseBasicBlock(unsigned BlockNo);
242
Reid Spencerf89143c2004-06-29 23:31:01 +0000243 /// @brief parse an instruction list (for post LLVM 1.0 instruction lists
244 /// with blocks differentiated by terminating instructions.
245 unsigned ParseInstructionList(
246 Function* F ///< The function into which BBs will be inserted
247 );
Misha Brukman8a96c532005-04-21 21:44:41 +0000248
Reid Spencerf89143c2004-06-29 23:31:01 +0000249 /// @brief Parse a single instruction.
250 void ParseInstruction(
Chris Lattner63cf59e2007-02-07 05:08:39 +0000251 SmallVector <unsigned, 8>& Args, ///< The arguments to be filled in
Reid Spencerf89143c2004-06-29 23:31:01 +0000252 BasicBlock* BB ///< The BB the instruction goes in
253 );
254
255 /// @brief Parse the whole constant pool
Misha Brukman8a96c532005-04-21 21:44:41 +0000256 void ParseConstantPool(ValueTable& Values, TypeListTy& Types,
Reid Spencera86159c2004-07-04 11:04:56 +0000257 bool isFunction);
Reid Spencerf89143c2004-06-29 23:31:01 +0000258
Chris Lattner3bc5a602006-01-25 23:08:15 +0000259 /// @brief Parse a single constant pool value
260 Value *ParseConstantPoolValue(unsigned TypeID);
Reid Spencerf89143c2004-06-29 23:31:01 +0000261
262 /// @brief Parse a block of types constants
Reid Spencer66906512004-07-11 17:24:05 +0000263 void ParseTypes(TypeListTy &Tab, unsigned NumEntries);
Reid Spencerf89143c2004-06-29 23:31:01 +0000264
265 /// @brief Parse a single type constant
Reid Spencer66906512004-07-11 17:24:05 +0000266 const Type *ParseType();
Reid Spencerf89143c2004-06-29 23:31:01 +0000267
Reid Spencer91ac04a2007-04-09 06:14:31 +0000268 /// @brief Parse a list of parameter attributes
269 ParamAttrsList *ParseParamAttrsList();
270
Reid Spencerf89143c2004-06-29 23:31:01 +0000271 /// @brief Parse a string constants block
272 void ParseStringConstants(unsigned NumEntries, ValueTable &Tab);
273
Chris Lattnerf0edc6c2006-10-12 18:32:30 +0000274 /// @brief Release our memory.
275 void freeState() {
276 freeTable(FunctionValues);
277 freeTable(ModuleValues);
278 }
279
Reid Spencerf89143c2004-06-29 23:31:01 +0000280/// @}
281/// @name Data
282/// @{
283private:
Reid Spencer233fe722006-08-22 16:09:19 +0000284 std::string ErrorMsg; ///< A place to hold an error message through longjmp
285 jmp_buf context; ///< Where to return to if an error occurs.
Misha Brukman8a96c532005-04-21 21:44:41 +0000286 char* decompressedBlock; ///< Result of decompression
Reid Spencerf89143c2004-06-29 23:31:01 +0000287 BufPtr MemStart; ///< Start of the memory buffer
288 BufPtr MemEnd; ///< End of the memory buffer
289 BufPtr BlockStart; ///< Start of current block being parsed
290 BufPtr BlockEnd; ///< End of current block being parsed
291 BufPtr At; ///< Where we're currently parsing at
292
Reid Spencera86159c2004-07-04 11:04:56 +0000293 /// Information about the module, extracted from the bytecode revision number.
Chris Lattner45b5dd22004-08-03 23:41:28 +0000294 ///
Reid Spencerf89143c2004-06-29 23:31:01 +0000295 unsigned char RevisionNum; // The rev # itself
296
Reid Spencerf89143c2004-06-29 23:31:01 +0000297 /// @brief This vector is used to deal with forward references to types in
298 /// a module.
299 TypeListTy ModuleTypes;
Chris Lattnereebac5f2005-10-03 21:26:53 +0000300
301 /// @brief This is an inverse mapping of ModuleTypes from the type to an
302 /// index. Because refining types causes the index of this map to be
303 /// invalidated, any time we refine a type, we clear this cache and recompute
304 /// it next time we need it. These entries are ordered by the pointer value.
305 std::vector<std::pair<const Type*, unsigned> > ModuleTypeIDCache;
Reid Spencerf89143c2004-06-29 23:31:01 +0000306
307 /// @brief This vector is used to deal with forward references to types in
308 /// a function.
309 TypeListTy FunctionTypes;
310
311 /// When the ModuleGlobalInfo section is read, we create a Function object
312 /// for each function in the module. When the function is loaded, after the
313 /// module global info is read, this Function is populated. Until then, the
314 /// functions in this vector just hold the function signature.
315 std::vector<Function*> FunctionSignatureList;
316
317 /// @brief This is the table of values belonging to the current function
318 ValueTable FunctionValues;
319
320 /// @brief This is the table of values belonging to the module (global)
321 ValueTable ModuleValues;
322
323 /// @brief This keeps track of function level forward references.
324 ForwardReferenceMap ForwardReferences;
325
326 /// @brief The basic blocks we've parsed, while parsing a function.
327 std::vector<BasicBlock*> ParsedBasicBlocks;
328
Chris Lattner1c765b02004-10-14 01:49:34 +0000329 /// This maintains a mapping between <Type, Slot #>'s and forward references
330 /// to constants. Such values may be referenced before they are defined, and
331 /// if so, the temporary object that they represent is held here. @brief
332 /// Temporary place for forward references to constants.
Reid Spencerf89143c2004-06-29 23:31:01 +0000333 ConstantRefsType ConstantFwdRefs;
334
335 /// Constant values are read in after global variables. Because of this, we
336 /// must defer setting the initializers on global variables until after module
Chris Lattner1c765b02004-10-14 01:49:34 +0000337 /// level constants have been read. In the mean time, this list keeps track
338 /// of what we must do.
Reid Spencerf89143c2004-06-29 23:31:01 +0000339 GlobalInitsList GlobalInits;
340
341 // For lazy reading-in of functions, we need to save away several pieces of
342 // information about each function: its begin and end pointer in the buffer
343 // and its FunctionSlot.
344 LazyFunctionMap LazyFunctionLoadMap;
345
Misha Brukman8a96c532005-04-21 21:44:41 +0000346 /// This stores the parser's handler which is used for handling tasks other
347 /// just than reading bytecode into the IR. If this is non-null, calls on
348 /// the (polymorphic) BytecodeHandler interface (see llvm/Bytecode/Handler.h)
349 /// will be made to report the logical structure of the bytecode file. What
350 /// the handler does with the events it receives is completely orthogonal to
Reid Spencerf89143c2004-06-29 23:31:01 +0000351 /// the business of parsing the bytecode and building the IR. This is used,
352 /// for example, by the llvm-abcd tool for analysis of byte code.
353 /// @brief Handler for parsing events.
354 BytecodeHandler* Handler;
355
Reid Spencer3e595462006-01-19 06:57:58 +0000356
Reid Spencerf89143c2004-06-29 23:31:01 +0000357/// @}
358/// @name Implementation Details
359/// @{
360private:
361 /// @brief Determines if this module has a function or not.
362 bool hasFunctions() { return ! FunctionSignatureList.empty(); }
363
364 /// @brief Determines if the type id has an implicit null value.
365 bool hasImplicitNull(unsigned TyID );
366
367 /// @brief Converts a type slot number to its Type*
368 const Type *getType(unsigned ID);
369
Reid Spencerd798a512006-11-14 04:47:22 +0000370 /// @brief Read in a type id and turn it into a Type*
371 inline const Type* readType();
Reid Spencera86159c2004-07-04 11:04:56 +0000372
Reid Spencerf89143c2004-06-29 23:31:01 +0000373 /// @brief Converts a Type* to its type slot number
374 unsigned getTypeSlot(const Type *Ty);
375
Reid Spencera86159c2004-07-04 11:04:56 +0000376 /// @brief Gets the global type corresponding to the TypeId
377 const Type *getGlobalTableType(unsigned TypeId);
Reid Spencerf89143c2004-06-29 23:31:01 +0000378
Reid Spencera86159c2004-07-04 11:04:56 +0000379 /// @brief Get a value from its typeid and slot number
Reid Spencerf89143c2004-06-29 23:31:01 +0000380 Value* getValue(unsigned TypeID, unsigned num, bool Create = true);
381
Reid Spencerf89143c2004-06-29 23:31:01 +0000382 /// @brief Get a basic block for current function
383 BasicBlock *getBasicBlock(unsigned ID);
384
Reid Spencera86159c2004-07-04 11:04:56 +0000385 /// @brief Get a constant value from its typeid and value slot.
Reid Spencerf89143c2004-06-29 23:31:01 +0000386 Constant* getConstantValue(unsigned typeSlot, unsigned valSlot);
387
388 /// @brief Convenience function for getting a constant value when
389 /// the Type has already been resolved.
390 Constant* getConstantValue(const Type *Ty, unsigned valSlot) {
391 return getConstantValue(getTypeSlot(Ty), valSlot);
392 }
393
Reid Spencerf89143c2004-06-29 23:31:01 +0000394 /// @brief Insert a newly created value
395 unsigned insertValue(Value *V, unsigned Type, ValueTable &Table);
396
397 /// @brief Insert the arguments of a function.
398 void insertArguments(Function* F );
399
Misha Brukman8a96c532005-04-21 21:44:41 +0000400 /// @brief Resolve all references to the placeholder (if any) for the
Reid Spencerf89143c2004-06-29 23:31:01 +0000401 /// given constant.
Chris Lattner389bd042004-12-09 06:19:44 +0000402 void ResolveReferencesToConstant(Constant *C, unsigned Typ, unsigned Slot);
Reid Spencerf89143c2004-06-29 23:31:01 +0000403
Reid Spencerf89143c2004-06-29 23:31:01 +0000404 /// @brief Free a table, making sure to free the ValueList in the table.
405 void freeTable(ValueTable &Tab) {
406 while (!Tab.empty()) {
407 delete Tab.back();
408 Tab.pop_back();
409 }
410 }
411
Reid Spencer233fe722006-08-22 16:09:19 +0000412 inline void error(const std::string& errmsg);
Reid Spencer24399722004-07-09 22:21:33 +0000413
Reid Spencerf89143c2004-06-29 23:31:01 +0000414 BytecodeReader(const BytecodeReader &); // DO NOT IMPLEMENT
415 void operator=(const BytecodeReader &); // DO NOT IMPLEMENT
416
Reid Spencera54b7cb2007-01-12 07:05:14 +0000417 // This enum provides the values of the well-known type slots that are always
418 // emitted as the first few types in the table by the BytecodeWriter class.
419 enum WellKnownTypeSlots {
420 VoidTypeSlot = 0, ///< TypeID == VoidTyID
421 FloatTySlot = 1, ///< TypeID == FloatTyID
422 DoubleTySlot = 2, ///< TypeID == DoubleTyID
423 LabelTySlot = 3, ///< TypeID == LabelTyID
424 BoolTySlot = 4, ///< TypeID == IntegerTyID, width = 1
425 Int8TySlot = 5, ///< TypeID == IntegerTyID, width = 8
426 Int16TySlot = 6, ///< TypeID == IntegerTyID, width = 16
427 Int32TySlot = 7, ///< TypeID == IntegerTyID, width = 32
428 Int64TySlot = 8 ///< TypeID == IntegerTyID, width = 64
429 };
430
Reid Spencerf89143c2004-06-29 23:31:01 +0000431/// @}
432/// @name Reader Primitives
433/// @{
434private:
435
436 /// @brief Is there more to parse in the current block?
437 inline bool moreInBlock();
438
439 /// @brief Have we read past the end of the block
440 inline void checkPastBlockEnd(const char * block_name);
441
442 /// @brief Align to 32 bits
443 inline void align32();
444
445 /// @brief Read an unsigned integer as 32-bits
446 inline unsigned read_uint();
447
448 /// @brief Read an unsigned integer with variable bit rate encoding
449 inline unsigned read_vbr_uint();
450
Reid Spencerad89bd62004-07-25 18:07:36 +0000451 /// @brief Read an unsigned integer of no more than 24-bits with variable
452 /// bit rate encoding.
453 inline unsigned read_vbr_uint24();
454
Reid Spencerf89143c2004-06-29 23:31:01 +0000455 /// @brief Read an unsigned 64-bit integer with variable bit rate encoding.
456 inline uint64_t read_vbr_uint64();
457
458 /// @brief Read a signed 64-bit integer with variable bit rate encoding.
459 inline int64_t read_vbr_int64();
460
461 /// @brief Read a string
462 inline std::string read_str();
Chris Lattnerdd8cec52007-02-12 18:53:43 +0000463 inline void read_str(SmallVectorImpl<char> &StrData);
Reid Spencerf89143c2004-06-29 23:31:01 +0000464
Reid Spencer66906512004-07-11 17:24:05 +0000465 /// @brief Read a float value
466 inline void read_float(float& FloatVal);
467
468 /// @brief Read a double value
469 inline void read_double(double& DoubleVal);
470
Reid Spencerf89143c2004-06-29 23:31:01 +0000471 /// @brief Read an arbitrary data chunk of fixed length
472 inline void read_data(void *Ptr, void *End);
473
Reid Spencera86159c2004-07-04 11:04:56 +0000474 /// @brief Read a bytecode block header
Reid Spencerf89143c2004-06-29 23:31:01 +0000475 inline void read_block(unsigned &Type, unsigned &Size);
Reid Spencerf89143c2004-06-29 23:31:01 +0000476/// @}
477};
478
Reid Spencerf89143c2004-06-29 23:31:01 +0000479} // End llvm namespace
480
481// vim: sw=2
482#endif