MEGAPATCH checkin.
[oota-llvm.git] / lib / Bytecode / Reader / Reader.cpp
1 //===- Reader.cpp - Code to read bytecode files ---------------------------===//
2 //
3 // This library implements the functionality defined in llvm/Bytecode/Reader.h
4 //
5 // Note that this library should be as fast as possible, reentrant, and 
6 // threadsafe!!
7 //
8 // TODO: Make error message outputs be configurable depending on an option?
9 // TODO: Allow passing in an option to ignore the symbol table
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "ReaderInternals.h"
14 #include "llvm/Bytecode/Reader.h"
15 #include "llvm/Bytecode/Format.h"
16 #include "llvm/GlobalVariable.h"
17 #include "llvm/Module.h"
18 #include "llvm/Constants.h"
19 #include "llvm/iPHINode.h"
20 #include "llvm/iOther.h"
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <sys/mman.h>
24 #include <fcntl.h>
25 #include <unistd.h>
26 #include <algorithm>
27 #include <iostream>
28 using std::cerr;
29 using std::make_pair;
30
31 bool BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) {
32   if (Ty->isPrimitiveType()) {
33     Slot = Ty->getPrimitiveID();
34   } else {
35     // Check the method level types first...
36     TypeValuesListTy::iterator I = find(MethodTypeValues.begin(),
37                                         MethodTypeValues.end(), Ty);
38     if (I != MethodTypeValues.end()) {
39       Slot = FirstDerivedTyID+ModuleTypeValues.size()+
40              (&*I - &MethodTypeValues[0]);
41     } else {
42       I = find(ModuleTypeValues.begin(), ModuleTypeValues.end(), Ty);
43       if (I == ModuleTypeValues.end()) return true;   // Didn't find type!
44       Slot = FirstDerivedTyID + (&*I - &ModuleTypeValues[0]);
45     }
46   }
47   //cerr << "getTypeSlot '" << Ty->getName() << "' = " << Slot << "\n";
48   return false;
49 }
50
51 const Type *BytecodeParser::getType(unsigned ID) {
52   const Type *T = Type::getPrimitiveType((Type::PrimitiveID)ID);
53   if (T) return T;
54   
55   //cerr << "Looking up Type ID: " << ID << "\n";
56
57   const Value *D = getValue(Type::TypeTy, ID, false);
58   if (D == 0) return failure<const Type*>(0);
59
60   return cast<Type>(D);
61 }
62
63 int BytecodeParser::insertValue(Value *Val, std::vector<ValueList> &ValueTab) {
64   unsigned type;
65   if (getTypeSlot(Val->getType(), type)) return failure<int>(-1);
66   assert(type != Type::TypeTyID && "Types should never be insertValue'd!");
67  
68   if (ValueTab.size() <= type)
69     ValueTab.resize(type+1, ValueList());
70
71   //cerr << "insertValue Values[" << type << "][" << ValueTab[type].size() 
72   //     << "] = " << Val << "\n";
73   ValueTab[type].push_back(Val);
74
75   return ValueTab[type].size()-1;
76 }
77
78 Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) {
79   unsigned Num = oNum;
80   unsigned type;   // The type plane it lives in...
81
82   if (getTypeSlot(Ty, type)) return failure<Value*>(0); // TODO: true
83
84   if (type == Type::TypeTyID) {  // The 'type' plane has implicit values
85     assert(Create == false);
86     const Type *T = Type::getPrimitiveType((Type::PrimitiveID)Num);
87     if (T) return (Value*)T;   // Asked for a primitive type...
88
89     // Otherwise, derived types need offset...
90     Num -= FirstDerivedTyID;
91
92     // Is it a module level type?
93     if (Num < ModuleTypeValues.size())
94       return (Value*)ModuleTypeValues[Num].get();
95
96     // Nope, is it a method level type?
97     Num -= ModuleTypeValues.size();
98     if (Num < MethodTypeValues.size())
99       return (Value*)MethodTypeValues[Num].get();
100
101     return 0;
102   }
103
104   if (type < ModuleValues.size()) {
105     if (Num < ModuleValues[type].size())
106       return ModuleValues[type][Num];
107     Num -= ModuleValues[type].size();
108   }
109
110   if (Values.size() > type && Values[type].size() > Num)
111     return Values[type][Num];
112
113   if (!Create) return failure<Value*>(0);  // Do not create a placeholder?
114
115   Value *d = 0;
116   switch (Ty->getPrimitiveID()) {
117   case Type::LabelTyID: d = new    BBPHolder(Ty, oNum); break;
118   case Type::FunctionTyID:
119     cerr << "Creating method pholder! : " << type << ":" << oNum << " " 
120          << Ty->getName() << "\n";
121     d = new MethPHolder(Ty, oNum);
122     if (insertValue(d, LateResolveModuleValues) ==-1) return failure<Value*>(0);
123     return d;
124   default:                   d = new   DefPHolder(Ty, oNum); break;
125   }
126
127   assert(d != 0 && "How did we not make something?");
128   if (insertValue(d, LateResolveValues) == -1) return failure<Value*>(0);
129   return d;
130 }
131
132 bool BytecodeParser::postResolveValues(ValueTable &ValTab) {
133   bool Error = false;
134   for (unsigned ty = 0; ty < ValTab.size(); ++ty) {
135     ValueList &DL = ValTab[ty];
136     unsigned Size;
137     while ((Size = DL.size())) {
138       unsigned IDNumber = getValueIDNumberFromPlaceHolder(DL[Size-1]);
139
140       Value *D = DL[Size-1];
141       DL.pop_back();
142
143       Value *NewDef = getValue(D->getType(), IDNumber, false);
144       if (NewDef == 0) {
145         Error = true;  // Unresolved thinger
146         cerr << "Unresolvable reference found: <"
147               << D->getType()->getDescription() << ">:" << IDNumber << "!\n";
148       } else {
149         // Fixup all of the uses of this placeholder def...
150         D->replaceAllUsesWith(NewDef);
151
152         // Now that all the uses are gone, delete the placeholder...
153         // If we couldn't find a def (error case), then leak a little
154         delete D;  // memory, 'cause otherwise we can't remove all uses!
155       }
156     }
157   }
158
159   return Error;
160 }
161
162 bool BytecodeParser::ParseBasicBlock(const uchar *&Buf, const uchar *EndBuf, 
163                                      BasicBlock *&BB) {
164   BB = new BasicBlock();
165
166   while (Buf < EndBuf) {
167     Instruction *Inst;
168     if (ParseInstruction(Buf, EndBuf, Inst)) {
169       delete BB;
170       return failure(true);
171     }
172
173     if (Inst == 0) { delete BB; return failure(true); }
174     if (insertValue(Inst, Values) == -1) { delete BB; return failure(true); }
175
176     BB->getInstList().push_back(Inst);
177
178     BCR_TRACE(4, Inst);
179   }
180
181   return false;
182 }
183
184 bool BytecodeParser::ParseSymbolTable(const uchar *&Buf, const uchar *EndBuf,
185                                       SymbolTable *ST) {
186   while (Buf < EndBuf) {
187     // Symtab block header: [num entries][type id number]
188     unsigned NumEntries, Typ;
189     if (read_vbr(Buf, EndBuf, NumEntries) ||
190         read_vbr(Buf, EndBuf, Typ)) return failure(true);
191     const Type *Ty = getType(Typ);
192     if (Ty == 0) return failure(true);
193
194     BCR_TRACE(3, "Plane Type: '" << Ty << "' with " << NumEntries <<
195               " entries\n");
196
197     for (unsigned i = 0; i < NumEntries; ++i) {
198       // Symtab entry: [def slot #][name]
199       unsigned slot;
200       if (read_vbr(Buf, EndBuf, slot)) return failure(true);
201       std::string Name;
202       if (read(Buf, EndBuf, Name, false))  // Not aligned...
203         return failure(true);
204
205       Value *D = getValue(Ty, slot, false); // Find mapping...
206       if (D == 0) {
207         BCR_TRACE(3, "FAILED LOOKUP: Slot #" << slot << "\n");
208         return failure(true);
209       }
210       BCR_TRACE(4, "Map: '" << Name << "' to #" << slot << ":" << D;
211                 if (!isa<Instruction>(D)) cerr << "\n");
212
213       D->setName(Name, ST);
214     }
215   }
216
217   if (Buf > EndBuf) return failure(true);
218   return false;
219 }
220
221 // DeclareNewGlobalValue - Patch up forward references to global values in the
222 // form of ConstantPointerRef.
223 //
224 void BytecodeParser::DeclareNewGlobalValue(GlobalValue *GV, unsigned Slot) {
225   // Check to see if there is a forward reference to this global variable...
226   // if there is, eliminate it and patch the reference to use the new def'n.
227   GlobalRefsType::iterator I = GlobalRefs.find(make_pair(GV->getType(), Slot));
228
229   if (I != GlobalRefs.end()) {
230     GlobalVariable *OldGV = I->second;   // Get the placeholder...
231     BCR_TRACE(3, "Mutating CPPR Forward Ref!\n");
232       
233     // Loop over all of the uses of the GlobalValue.  The only thing they are
234     // allowed to be at this point is ConstantPointerRef's.
235     assert(OldGV->use_size() == 1 && "Only one reference should exist!");
236     while (!OldGV->use_empty()) {
237       User *U = OldGV->use_back();  // Must be a ConstantPointerRef...
238       ConstantPointerRef *CPPR = cast<ConstantPointerRef>(U);
239       assert(CPPR->getValue() == OldGV && "Something isn't happy");
240       
241       BCR_TRACE(4, "Mutating Forward Ref!\n");
242       
243       // Change the const pool reference to point to the real global variable
244       // now.  This should drop a use from the OldGV.
245       CPPR->mutateReference(GV);
246     }
247     
248     // Remove GV from the module...
249     GV->getParent()->getGlobalList().remove(OldGV);
250     delete OldGV;                        // Delete the old placeholder
251     
252     // Remove the map entry for the global now that it has been created...
253     GlobalRefs.erase(I);
254   }
255 }
256
257 bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf, 
258                                  Module *C) {
259   // Clear out the local values table...
260   Values.clear();
261   if (MethodSignatureList.empty()) {
262     Error = "Function found, but FunctionSignatureList empty!";
263     return failure(true);  // Unexpected method!
264   }
265
266   const PointerType *PMTy = MethodSignatureList.front().first; // PtrMeth
267   const FunctionType *MTy  = dyn_cast<FunctionType>(PMTy->getElementType());
268   if (MTy == 0) return failure(true);  // Not ptr to method!
269
270   unsigned isInternal;
271   if (read_vbr(Buf, EndBuf, isInternal)) return failure(true);
272
273   unsigned MethSlot = MethodSignatureList.front().second;
274   MethodSignatureList.pop_front();
275   Function *M = new Function(MTy, isInternal != 0);
276
277   BCR_TRACE(2, "METHOD TYPE: " << MTy << "\n");
278
279   const FunctionType::ParamTypes &Params = MTy->getParamTypes();
280   for (FunctionType::ParamTypes::const_iterator It = Params.begin();
281        It != Params.end(); ++It) {
282     Argument *FA = new Argument(*It);
283     if (insertValue(FA, Values) == -1) {
284       Error = "Error reading method arguments!\n";
285       delete M; return failure(true); 
286     }
287     M->getArgumentList().push_back(FA);
288   }
289
290   while (Buf < EndBuf) {
291     unsigned Type, Size;
292     const uchar *OldBuf = Buf;
293     if (readBlock(Buf, EndBuf, Type, Size)) {
294       Error = "Error reading Function level block!";
295       delete M; return failure(true); 
296     }
297
298     switch (Type) {
299     case BytecodeFormat::ConstantPool:
300       BCR_TRACE(2, "BLOCK BytecodeFormat::ConstantPool: {\n");
301       if (ParseConstantPool(Buf, Buf+Size, Values, MethodTypeValues)) {
302         delete M; return failure(true);
303       }
304       break;
305
306     case BytecodeFormat::BasicBlock: {
307       BCR_TRACE(2, "BLOCK BytecodeFormat::BasicBlock: {\n");
308       BasicBlock *BB;
309       if (ParseBasicBlock(Buf, Buf+Size, BB) ||
310           insertValue(BB, Values) == -1) {
311         delete M; return failure(true);                // Parse error... :(
312       }
313
314       M->getBasicBlockList().push_back(BB);
315       break;
316     }
317
318     case BytecodeFormat::SymbolTable:
319       BCR_TRACE(2, "BLOCK BytecodeFormat::SymbolTable: {\n");
320       if (ParseSymbolTable(Buf, Buf+Size, M->getSymbolTableSure())) {
321         delete M; return failure(true);
322       }
323       break;
324
325     default:
326       BCR_TRACE(2, "BLOCK <unknown>:ignored! {\n");
327       Buf += Size;
328       if (OldBuf > Buf) return failure(true); // Wrap around!
329       break;
330     }
331     BCR_TRACE(2, "} end block\n");
332
333     if (align32(Buf, EndBuf)) {
334       Error = "Error aligning Function level block!";
335       delete M;    // Malformed bc file, read past end of block.
336       return failure(true);
337     }
338   }
339
340   if (postResolveValues(LateResolveValues) ||
341       postResolveValues(LateResolveModuleValues)) {
342     Error = "Error resolving method values!";
343     delete M; return failure(true);     // Unresolvable references!
344   }
345
346   Value *MethPHolder = getValue(PMTy, MethSlot, false);
347   assert(MethPHolder && "Something is broken no placeholder found!");
348   assert(isa<Function>(MethPHolder) && "Not a function?");
349
350   unsigned type;  // Type slot
351   assert(!getTypeSlot(MTy, type) && "How can meth type not exist?");
352   getTypeSlot(PMTy, type);
353
354   C->getFunctionList().push_back(M);
355
356   // Replace placeholder with the real method pointer...
357   ModuleValues[type][MethSlot] = M;
358
359   // Clear out method level types...
360   MethodTypeValues.clear();
361
362   // If anyone is using the placeholder make them use the real method instead
363   MethPHolder->replaceAllUsesWith(M);
364
365   // We don't need the placeholder anymore!
366   delete MethPHolder;
367
368   // If the method is empty, we don't need the method argument entries...
369   if (M->isExternal())
370     M->getArgumentList().clear();
371
372   DeclareNewGlobalValue(M, MethSlot);
373
374   return false;
375 }
376
377 bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End,
378                                            Module *Mod) {
379   if (!MethodSignatureList.empty()) {
380     Error = "Two ModuleGlobalInfo packets found!";
381     return failure(true);  // Two ModuleGlobal blocks?
382   }
383
384   // Read global variables...
385   unsigned VarType;
386   if (read_vbr(Buf, End, VarType)) return failure(true);
387   while (VarType != Type::VoidTyID) { // List is terminated by Void
388     // VarType Fields: bit0 = isConstant, bit1 = hasInitializer,
389     // bit2 = isInternal, bit3+ = slot#
390     const Type *Ty = getType(VarType >> 3);
391     if (!Ty || !isa<PointerType>(Ty)) { 
392       Error = "Global not pointer type!  Ty = " + Ty->getDescription();
393       return failure(true); 
394     }
395
396     const PointerType *PTy = cast<const PointerType>(Ty);
397     const Type *ElTy = PTy->getElementType();
398
399     Constant *Initializer = 0;
400     if (VarType & 2) { // Does it have an initalizer?
401       // Do not improvise... values must have been stored in the constant pool,
402       // which should have been read before now.
403       //
404       unsigned InitSlot;
405       if (read_vbr(Buf, End, InitSlot)) return failure(true);
406       
407       Value *V = getValue(ElTy, InitSlot, false);
408       if (V == 0) return failure(true);
409       Initializer = cast<Constant>(V);
410     }
411
412     // Create the global variable...
413     GlobalVariable *GV = new GlobalVariable(ElTy, VarType & 1, VarType & 4,
414                                             Initializer);
415     int DestSlot = insertValue(GV, ModuleValues);
416     if (DestSlot == -1) return failure(true);
417
418     Mod->getGlobalList().push_back(GV);
419
420     DeclareNewGlobalValue(GV, unsigned(DestSlot));
421
422     BCR_TRACE(2, "Global Variable of type: " << PTy->getDescription() 
423               << " into slot #" << DestSlot << "\n");
424
425     if (read_vbr(Buf, End, VarType)) return failure(true);
426   }
427
428   // Read the method signatures for all of the methods that are coming, and 
429   // create fillers in the Value tables.
430   unsigned MethSignature;
431   if (read_vbr(Buf, End, MethSignature)) return failure(true);
432   while (MethSignature != Type::VoidTyID) { // List is terminated by Void
433     const Type *Ty = getType(MethSignature);
434     if (!Ty || !isa<PointerType>(Ty) ||
435         !isa<FunctionType>(cast<PointerType>(Ty)->getElementType())) { 
436       Error = "Function not ptr to func type!  Ty = " + Ty->getDescription();
437       return failure(true); 
438     }
439     
440     // We create methods by passing the underlying FunctionType to create...
441     Ty = cast<PointerType>(Ty)->getElementType();
442
443     // When the ModuleGlobalInfo section is read, we load the type of each 
444     // method and the 'ModuleValues' slot that it lands in.  We then load a 
445     // placeholder into its slot to reserve it.  When the method is loaded, this
446     // placeholder is replaced.
447
448     // Insert the placeholder...
449     Value *Val = new MethPHolder(Ty, 0);
450     if (insertValue(Val, ModuleValues) == -1) return failure(true);
451
452     // Figure out which entry of its typeslot it went into...
453     unsigned TypeSlot;
454     if (getTypeSlot(Val->getType(), TypeSlot)) return failure(true);
455
456     unsigned SlotNo = ModuleValues[TypeSlot].size()-1;
457     
458     // Keep track of this information in a linked list that is emptied as 
459     // methods are loaded...
460     //
461     MethodSignatureList.push_back(
462            make_pair(cast<const PointerType>(Val->getType()), SlotNo));
463     if (read_vbr(Buf, End, MethSignature)) return failure(true);
464     BCR_TRACE(2, "Function of type: " << Ty << "\n");
465   }
466
467   if (align32(Buf, End)) return failure(true);
468
469   // This is for future proofing... in the future extra fields may be added that
470   // we don't understand, so we transparently ignore them.
471   //
472   Buf = End;
473   return false;
474 }
475
476 bool BytecodeParser::ParseModule(const uchar *Buf, const uchar *EndBuf, 
477                                 Module *&C) {
478
479   unsigned Type, Size;
480   if (readBlock(Buf, EndBuf, Type, Size)) return failure(true);
481   if (Type != BytecodeFormat::Module || Buf+Size != EndBuf) {
482     Error = "Expected Module packet!";
483     return failure(true);                      // Hrm, not a class?
484   }
485
486   BCR_TRACE(0, "BLOCK BytecodeFormat::Module: {\n");
487   MethodSignatureList.clear();                 // Just in case...
488
489   // Read into instance variables...
490   if (read_vbr(Buf, EndBuf, FirstDerivedTyID)) return failure(true);
491   if (align32(Buf, EndBuf)) return failure(true);
492   BCR_TRACE(1, "FirstDerivedTyID = " << FirstDerivedTyID << "\n");
493
494   TheModule = C = new Module();
495   while (Buf < EndBuf) {
496     const uchar *OldBuf = Buf;
497     if (readBlock(Buf, EndBuf, Type, Size)) { delete C; return failure(true); }
498     switch (Type) {
499     case BytecodeFormat::ConstantPool:
500       BCR_TRACE(1, "BLOCK BytecodeFormat::ConstantPool: {\n");
501       if (ParseConstantPool(Buf, Buf+Size, ModuleValues, ModuleTypeValues)) {
502         delete C; return failure(true);
503       }
504       break;
505
506     case BytecodeFormat::ModuleGlobalInfo:
507       BCR_TRACE(1, "BLOCK BytecodeFormat::ModuleGlobalInfo: {\n");
508
509       if (ParseModuleGlobalInfo(Buf, Buf+Size, C)) {
510         delete C; return failure(true);
511       }
512       break;
513
514     case BytecodeFormat::Function: {
515       BCR_TRACE(1, "BLOCK BytecodeFormat::Function: {\n");
516       if (ParseMethod(Buf, Buf+Size, C)) {
517         delete C; return failure(true);               // Error parsing method
518       }
519       break;
520     }
521
522     case BytecodeFormat::SymbolTable:
523       BCR_TRACE(1, "BLOCK BytecodeFormat::SymbolTable: {\n");
524       if (ParseSymbolTable(Buf, Buf+Size, C->getSymbolTableSure())) {
525         delete C; return failure(true);
526       }
527       break;
528
529     default:
530       Error = "Expected Module Block!";
531       Buf += Size;
532       if (OldBuf > Buf) return failure(true); // Wrap around!
533       break;
534     }
535     BCR_TRACE(1, "} end block\n");
536     if (align32(Buf, EndBuf)) { delete C; return failure(true); }
537   }
538
539   if (!MethodSignatureList.empty()) {     // Expected more methods!
540     Error = "Function expected, but bytecode stream at end!";
541     return failure(true);
542   }
543
544   BCR_TRACE(0, "} end block\n\n");
545   return false;
546 }
547
548 Module *BytecodeParser::ParseBytecode(const uchar *Buf, const uchar *EndBuf) {
549   LateResolveValues.clear();
550   unsigned Sig;
551   // Read and check signature...
552   if (read(Buf, EndBuf, Sig) ||
553       Sig != ('l' | ('l' << 8) | ('v' << 16) | 'm' << 24)) {
554     Error = "Invalid bytecode signature!";
555     return failure<Module*>(0);                          // Invalid signature!
556   }
557
558   Module *Result;
559   if (ParseModule(Buf, EndBuf, Result)) return 0;
560   return Result;
561 }
562
563
564 Module *ParseBytecodeBuffer(const uchar *Buffer, unsigned Length) {
565   BytecodeParser Parser;
566   return Parser.ParseBytecode(Buffer, Buffer+Length);
567 }
568
569 // Parse and return a class file...
570 //
571 Module *ParseBytecodeFile(const std::string &Filename, std::string *ErrorStr) {
572   struct stat StatBuf;
573   Module *Result = 0;
574
575   if (Filename != std::string("-")) {        // Read from a file...
576     int FD = open(Filename.c_str(), O_RDONLY);
577     if (FD == -1) {
578       if (ErrorStr) *ErrorStr = "Error opening file!";
579       return failure<Module*>(0);
580     }
581
582     if (fstat(FD, &StatBuf) == -1) { close(FD); return failure<Module*>(0); }
583
584     int Length = StatBuf.st_size;
585     if (Length == 0) { 
586       if (ErrorStr) *ErrorStr = "Error stat'ing file!";
587       close(FD); return failure<Module*>(0); 
588     }
589     uchar *Buffer = (uchar*)mmap(0, Length, PROT_READ, 
590                                 MAP_PRIVATE, FD, 0);
591     if (Buffer == (uchar*)-1) {
592       if (ErrorStr) *ErrorStr = "Error mmapping file!";
593       close(FD); return failure<Module*>(0);
594     }
595
596     BytecodeParser Parser;
597     Result  = Parser.ParseBytecode(Buffer, Buffer+Length);
598
599     munmap((char*)Buffer, Length);
600     close(FD);
601     if (ErrorStr) *ErrorStr = Parser.getError();
602   } else {                              // Read from stdin
603     size_t FileSize = 0;
604     int BlockSize;
605     uchar Buffer[4096], *FileData = 0;
606     while ((BlockSize = read(0, Buffer, 4))) {
607       if (BlockSize == -1) { free(FileData); return failure<Module*>(0); }
608
609       FileData = (uchar*)realloc(FileData, FileSize+BlockSize);
610       memcpy(FileData+FileSize, Buffer, BlockSize);
611       FileSize += BlockSize;
612     }
613
614     if (FileSize == 0) {
615       if (ErrorStr) *ErrorStr = "Standard Input empty!";
616       free(FileData); return failure<Module*>(0);
617     }
618
619 #define ALIGN_PTRS 1
620 #if ALIGN_PTRS
621     uchar *Buf = (uchar*)mmap(0, FileSize, PROT_READ|PROT_WRITE, 
622                               MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
623     assert((Buf != (uchar*)-1) && "mmap returned error!");
624     memcpy(Buf, FileData, FileSize);
625     free(FileData);
626 #else
627     uchar *Buf = FileData;
628 #endif
629
630     BytecodeParser Parser;
631     Result = Parser.ParseBytecode(Buf, Buf+FileSize);
632
633 #if ALIGN_PTRS
634     munmap((char*)Buf, FileSize);   // Free mmap'd data area
635 #else
636     free(FileData);          // Free realloc'd block of memory
637 #endif
638
639     if (ErrorStr) *ErrorStr = Parser.getError();
640   }
641
642   return Result;
643 }