Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// | 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file implements the PNaCl bitcode file to Ice, to machine code | 10 // This file implements the PNaCl bitcode file to Ice, to machine code |
| 11 // translator. | 11 // translator. |
| 12 // | 12 // |
| 13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
| 14 | 14 |
| 15 #include "llvm/ADT/SmallString.h" | 15 #include "llvm/ADT/SmallString.h" |
| 16 #include "llvm/Bitcode/NaCl/NaClBitcodeDecoders.h" | 16 #include "llvm/Bitcode/NaCl/NaClBitcodeDecoders.h" |
| 17 #include "llvm/Bitcode/NaCl/NaClBitcodeDefs.h" | |
| 17 #include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h" | 18 #include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h" |
| 18 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" | 19 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" |
| 19 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" | 20 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" |
| 20 #include "llvm/Support/Format.h" | 21 #include "llvm/Support/Format.h" |
| 21 #include "llvm/Support/MemoryBuffer.h" | 22 #include "llvm/Support/MemoryBuffer.h" |
| 22 #include "llvm/Support/raw_ostream.h" | 23 #include "llvm/Support/raw_ostream.h" |
| 23 | 24 |
| 24 #include "IceAPInt.h" | 25 #include "IceAPInt.h" |
| 25 #include "IceAPFloat.h" | 26 #include "IceAPFloat.h" |
| 26 #include "IceCfg.h" | 27 #include "IceCfg.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 const std::string &Message) final; | 184 const std::string &Message) final; |
| 184 | 185 |
| 185 /// Generates error message with respect to the current block parser. | 186 /// Generates error message with respect to the current block parser. |
| 186 bool BlockError(const std::string &Message); | 187 bool BlockError(const std::string &Message); |
| 187 | 188 |
| 188 /// Returns the number of errors found while parsing the bitcode | 189 /// Returns the number of errors found while parsing the bitcode |
| 189 /// file. | 190 /// file. |
| 190 unsigned getNumErrors() const { return NumErrors; } | 191 unsigned getNumErrors() const { return NumErrors; } |
| 191 | 192 |
| 192 /// Changes the size of the type list to the given size. | 193 /// Changes the size of the type list to the given size. |
| 193 void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); } | 194 void resizeTypeIDValues(size_t NewSize) { TypeIDValues.resize(NewSize); } |
| 195 | |
| 196 size_t getNumTypeIDValues() const { return TypeIDValues.size(); } | |
| 194 | 197 |
| 195 /// Returns true if generation of Subzero IR is disabled. | 198 /// Returns true if generation of Subzero IR is disabled. |
| 196 bool isIRGenerationDisabled() const { | 199 bool isIRGenerationDisabled() const { |
| 197 return Translator.getFlags().getDisableIRGeneration(); | 200 return Translator.getFlags().getDisableIRGeneration(); |
| 198 } | 201 } |
| 199 | 202 |
| 200 /// Returns the undefined type associated with type ID. | 203 /// Returns the undefined type associated with type ID. |
| 201 /// Note: Returns extended type ready to be defined. | 204 /// Note: Returns extended type ready to be defined. |
| 202 ExtendedType *getTypeByIDForDefining(unsigned ID) { | 205 ExtendedType *getTypeByIDForDefining(NaClBcIndexSize_t ID) { |
| 203 // Get corresponding element, verifying the value is still undefined | 206 // Get corresponding element, verifying the value is still undefined |
| 204 // (and hence allowed to be defined). | 207 // (and hence allowed to be defined). |
| 205 ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Undefined); | 208 ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Undefined); |
| 206 if (Ty) | 209 if (Ty) |
| 207 return Ty; | 210 return Ty; |
| 208 if (ID >= TypeIDValues.size()) | 211 if (ID >= TypeIDValues.size()) { |
| 212 if (ID >= NaClBcIndexSize_t_Max) { | |
| 213 std::string Buffer; | |
| 214 raw_string_ostream StrBuf(Buffer); | |
| 215 StrBuf << "Can't define more than " << NaClBcIndexSize_t_Max | |
| 216 << " types\n"; | |
| 217 BlockError(StrBuf.str()); | |
| 218 // Recover by using existing type slot. | |
| 219 return &TypeIDValues[0]; | |
| 220 } | |
| 209 TypeIDValues.resize(ID + 1); | 221 TypeIDValues.resize(ID + 1); |
| 222 } | |
| 210 return &TypeIDValues[ID]; | 223 return &TypeIDValues[ID]; |
| 211 } | 224 } |
| 212 | 225 |
| 213 /// Returns the type associated with the given index. | 226 /// Returns the type associated with the given index. |
| 214 Ice::Type getSimpleTypeByID(unsigned ID) { | 227 Ice::Type getSimpleTypeByID(NaClBcIndexSize_t ID) { |
| 215 const ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Simple); | 228 const ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Simple); |
| 216 if (Ty == nullptr) | 229 if (Ty == nullptr) |
| 217 // Return error recovery value. | 230 // Return error recovery value. |
| 218 return Ice::IceType_void; | 231 return Ice::IceType_void; |
| 219 return cast<SimpleExtendedType>(Ty)->getType(); | 232 return cast<SimpleExtendedType>(Ty)->getType(); |
| 220 } | 233 } |
| 221 | 234 |
| 222 /// Returns the type signature associated with the given index. | 235 /// Returns the type signature associated with the given index. |
| 223 const Ice::FuncSigType &getFuncSigTypeByID(unsigned ID) { | 236 const Ice::FuncSigType &getFuncSigTypeByID(NaClBcIndexSize_t ID) { |
| 224 const ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::FuncSig); | 237 const ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::FuncSig); |
| 225 if (Ty == nullptr) | 238 if (Ty == nullptr) |
| 226 // Return error recovery value. | 239 // Return error recovery value. |
| 227 return UndefinedFuncSigType; | 240 return UndefinedFuncSigType; |
| 228 return cast<FuncSigExtendedType>(Ty)->getSignature(); | 241 return cast<FuncSigExtendedType>(Ty)->getSignature(); |
| 229 } | 242 } |
| 230 | 243 |
| 231 /// Sets the next function ID to the given LLVM function. | 244 /// Sets the next function ID to the given LLVM function. |
| 232 void setNextFunctionID(Ice::FunctionDeclaration *Fcn) { | 245 void setNextFunctionID(Ice::FunctionDeclaration *Fcn) { |
| 233 FunctionDeclarationList.push_back(Fcn); | 246 FunctionDeclarationList.push_back(Fcn); |
| 234 } | 247 } |
| 235 | 248 |
| 236 /// Returns the value id that should be associated with the the | 249 /// Returns the value id that should be associated with the the |
| 237 /// current function block. Increments internal counters during call | 250 /// current function block. Increments internal counters during call |
| 238 /// so that it will be in correct position for next function block. | 251 /// so that it will be in correct position for next function block. |
| 239 size_t getNextFunctionBlockValueID() { | 252 NaClBcIndexSize_t getNextFunctionBlockValueID() { |
| 240 size_t NumDeclaredFunctions = FunctionDeclarationList.size(); | 253 size_t NumDeclaredFunctions = FunctionDeclarationList.size(); |
| 241 while (NextDefiningFunctionID < NumDeclaredFunctions && | 254 while (NextDefiningFunctionID < NumDeclaredFunctions && |
| 242 FunctionDeclarationList[NextDefiningFunctionID]->isProto()) | 255 FunctionDeclarationList[NextDefiningFunctionID]->isProto()) |
| 243 ++NextDefiningFunctionID; | 256 ++NextDefiningFunctionID; |
| 244 if (NextDefiningFunctionID >= NumDeclaredFunctions) | 257 if (NextDefiningFunctionID >= NumDeclaredFunctions) |
| 245 Fatal("More function blocks than defined function addresses"); | 258 Fatal("More function blocks than defined function addresses"); |
| 246 return NextDefiningFunctionID++; | 259 return NextDefiningFunctionID++; |
| 247 } | 260 } |
| 248 | 261 |
| 249 /// Returns the function associated with ID. | 262 /// Returns the function associated with ID. |
| 250 Ice::FunctionDeclaration *getFunctionByID(unsigned ID) { | 263 Ice::FunctionDeclaration *getFunctionByID(NaClBcIndexSize_t ID) { |
| 251 if (ID < FunctionDeclarationList.size()) | 264 if (ID < FunctionDeclarationList.size()) |
| 252 return FunctionDeclarationList[ID]; | 265 return FunctionDeclarationList[ID]; |
| 253 return reportGetFunctionByIDError(ID); | 266 return reportGetFunctionByIDError(ID); |
| 254 } | 267 } |
| 255 | 268 |
| 256 /// Returns the constant associated with the given global value ID. | 269 /// Returns the constant associated with the given global value ID. |
| 257 Ice::Constant *getGlobalConstantByID(unsigned ID) { | 270 Ice::Constant *getGlobalConstantByID(NaClBcIndexSize_t ID) { |
| 258 assert(ID < ValueIDConstants.size()); | 271 assert(ID < ValueIDConstants.size()); |
| 259 return ValueIDConstants[ID]; | 272 return ValueIDConstants[ID]; |
| 260 } | 273 } |
| 261 | 274 |
| 262 /// Install names for all global values without names. Called after | 275 /// Install names for all global values without names. Called after |
| 263 /// the global value symbol table is processed, but before any | 276 /// the global value symbol table is processed, but before any |
| 264 /// function blocks are processed. | 277 /// function blocks are processed. |
| 265 void installGlobalNames() { | 278 void installGlobalNames() { |
| 266 assert(VariableDeclarations); | 279 assert(VariableDeclarations); |
| 267 installGlobalVarNames(); | 280 installGlobalVarNames(); |
| 268 installFunctionNames(); | 281 installFunctionNames(); |
| 269 } | 282 } |
| 270 | 283 |
| 271 void createValueIDs() { | 284 void createValueIDs() { |
| 272 assert(VariableDeclarations); | 285 assert(VariableDeclarations); |
| 273 ValueIDConstants.reserve(VariableDeclarations->size() + | 286 ValueIDConstants.reserve(VariableDeclarations->size() + |
| 274 FunctionDeclarationList.size()); | 287 FunctionDeclarationList.size()); |
| 275 createValueIDsForFunctions(); | 288 createValueIDsForFunctions(); |
| 276 createValueIDsForGlobalVars(); | 289 createValueIDsForGlobalVars(); |
| 277 } | 290 } |
| 278 | 291 |
| 279 /// Returns the number of function declarations in the bitcode file. | 292 /// Returns the number of function declarations in the bitcode file. |
| 280 unsigned getNumFunctionIDs() const { return FunctionDeclarationList.size(); } | 293 size_t getNumFunctionIDs() const { return FunctionDeclarationList.size(); } |
| 281 | 294 |
| 282 /// Returns the number of global declarations (i.e. IDs) defined in | 295 /// Returns the number of global declarations (i.e. IDs) defined in |
| 283 /// the bitcode file. | 296 /// the bitcode file. |
| 284 unsigned getNumGlobalIDs() const { | 297 size_t getNumGlobalIDs() const { |
| 285 if (VariableDeclarations) { | 298 if (VariableDeclarations) { |
| 286 return FunctionDeclarationList.size() + VariableDeclarations->size(); | 299 return FunctionDeclarationList.size() + VariableDeclarations->size(); |
| 287 } else { | 300 } else { |
| 288 return ValueIDConstants.size(); | 301 return ValueIDConstants.size(); |
| 289 } | 302 } |
| 290 } | 303 } |
| 291 | 304 |
| 292 /// Creates Count global variable declarations. | 305 /// Creates Count global variable declarations. |
| 293 void CreateGlobalVariables(size_t Count) { | 306 void createGlobalVariables(NaClBcIndexSize_t Count) { |
| 294 assert(VariableDeclarations); | 307 assert(VariableDeclarations); |
| 295 assert(VariableDeclarations->empty()); | 308 assert(VariableDeclarations->empty()); |
| 296 for (size_t i = 0; i < Count; ++i) { | 309 for (size_t i = 0; i < Count; ++i) { |
| 297 VariableDeclarations->push_back(Ice::VariableDeclaration::create()); | 310 VariableDeclarations->push_back(Ice::VariableDeclaration::create()); |
| 298 } | 311 } |
| 299 } | 312 } |
| 300 | 313 |
| 301 /// Returns the number of global variable declarations in the | 314 /// Returns the number of global variable declarations in the |
| 302 /// bitcode file. | 315 /// bitcode file. |
| 303 Ice::SizeT getNumGlobalVariables() const { | 316 size_t getNumGlobalVariables() const { |
| 304 if (VariableDeclarations) { | 317 if (VariableDeclarations) { |
| 305 return VariableDeclarations->size(); | 318 return VariableDeclarations->size(); |
| 306 } else { | 319 } else { |
| 307 return ValueIDConstants.size() - FunctionDeclarationList.size(); | 320 return ValueIDConstants.size() - FunctionDeclarationList.size(); |
| 308 } | 321 } |
| 309 } | 322 } |
| 310 | 323 |
| 311 /// Returns the global variable declaration with the given index. | 324 /// Returns the global variable declaration with the given index. |
| 312 Ice::VariableDeclaration *getGlobalVariableByID(unsigned Index) { | 325 Ice::VariableDeclaration *getGlobalVariableByID(NaClBcIndexSize_t Index) { |
| 313 assert(VariableDeclarations); | 326 assert(VariableDeclarations); |
| 314 if (Index < VariableDeclarations->size()) | 327 if (Index < VariableDeclarations->size()) |
| 315 return VariableDeclarations->at(Index); | 328 return VariableDeclarations->at(Index); |
| 316 return reportGetGlobalVariableByIDError(Index); | 329 return reportGetGlobalVariableByIDError(Index); |
| 317 } | 330 } |
| 318 | 331 |
| 319 /// Returns the global declaration (variable or function) with the | 332 /// Returns the global declaration (variable or function) with the |
| 320 /// given Index. | 333 /// given Index. |
| 321 Ice::GlobalDeclaration *getGlobalDeclarationByID(size_t Index) { | 334 Ice::GlobalDeclaration *getGlobalDeclarationByID(NaClBcIndexSize_t Index) { |
| 322 size_t NumFunctionIds = FunctionDeclarationList.size(); | 335 size_t NumFunctionIds = FunctionDeclarationList.size(); |
| 323 if (Index < NumFunctionIds) | 336 if (Index < NumFunctionIds) |
| 324 return getFunctionByID(Index); | 337 return getFunctionByID(Index); |
| 325 else | 338 else |
| 326 return getGlobalVariableByID(Index - NumFunctionIds); | 339 return getGlobalVariableByID(Index - NumFunctionIds); |
| 327 } | 340 } |
| 328 | 341 |
| 329 /// Returns the list of parsed global variable | 342 /// Returns the list of parsed global variable |
| 330 /// declarations. Releases ownership of the current list of global | 343 /// declarations. Releases ownership of the current list of global |
| 331 /// variables. Note: only returns non-null pointer on first | 344 /// variables. Note: only returns non-null pointer on first |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 348 // The types associated with each type ID. | 361 // The types associated with each type ID. |
| 349 std::vector<ExtendedType> TypeIDValues; | 362 std::vector<ExtendedType> TypeIDValues; |
| 350 // The set of functions (prototype and defined). | 363 // The set of functions (prototype and defined). |
| 351 FunctionDeclarationListType FunctionDeclarationList; | 364 FunctionDeclarationListType FunctionDeclarationList; |
| 352 // The ID of the next possible defined function ID in | 365 // The ID of the next possible defined function ID in |
| 353 // FunctionDeclarationList. FunctionDeclarationList is filled | 366 // FunctionDeclarationList. FunctionDeclarationList is filled |
| 354 // first. It's the set of functions (either defined or isproto). Then | 367 // first. It's the set of functions (either defined or isproto). Then |
| 355 // function definitions are encountered/parsed and | 368 // function definitions are encountered/parsed and |
| 356 // NextDefiningFunctionID is incremented to track the next | 369 // NextDefiningFunctionID is incremented to track the next |
| 357 // actually-defined function. | 370 // actually-defined function. |
| 358 size_t NextDefiningFunctionID; | 371 NaClBcIndexSize_t NextDefiningFunctionID; |
| 359 // The set of global variables. | 372 // The set of global variables. |
| 360 std::unique_ptr<Ice::VariableDeclarationList> VariableDeclarations; | 373 std::unique_ptr<Ice::VariableDeclarationList> VariableDeclarations; |
| 361 // Relocatable constants associated with global declarations. | 374 // Relocatable constants associated with global declarations. |
| 362 std::vector<Ice::Constant *> ValueIDConstants; | 375 std::vector<Ice::Constant *> ValueIDConstants; |
| 363 // Error recovery value to use when getFuncSigTypeByID fails. | 376 // Error recovery value to use when getFuncSigTypeByID fails. |
| 364 Ice::FuncSigType UndefinedFuncSigType; | 377 Ice::FuncSigType UndefinedFuncSigType; |
| 365 // The block parser currently being applied. Used for error | 378 // The block parser currently being applied. Used for error |
| 366 // reporting. | 379 // reporting. |
| 367 BlockParserBaseClass *BlockParser; | 380 BlockParserBaseClass *BlockParser; |
| 368 | 381 |
| 369 bool ParseBlock(unsigned BlockID) override; | 382 bool ParseBlock(unsigned BlockID) override; |
| 370 | 383 |
| 371 // Gets extended type associated with the given index, assuming the | 384 // Gets extended type associated with the given index, assuming the |
| 372 // extended type is of the WantedKind. Generates error message if | 385 // extended type is of the WantedKind. Generates error message if |
| 373 // corresponding extended type of WantedKind can't be found, and | 386 // corresponding extended type of WantedKind can't be found, and |
| 374 // returns nullptr. | 387 // returns nullptr. |
| 375 ExtendedType *getTypeByIDAsKind(unsigned ID, | 388 ExtendedType *getTypeByIDAsKind(NaClBcIndexSize_t ID, |
| 376 ExtendedType::TypeKind WantedKind) { | 389 ExtendedType::TypeKind WantedKind) { |
| 377 ExtendedType *Ty = nullptr; | 390 ExtendedType *Ty = nullptr; |
| 378 if (ID < TypeIDValues.size()) { | 391 if (ID < TypeIDValues.size()) { |
| 379 Ty = &TypeIDValues[ID]; | 392 Ty = &TypeIDValues[ID]; |
| 380 if (Ty->getKind() == WantedKind) | 393 if (Ty->getKind() == WantedKind) |
| 381 return Ty; | 394 return Ty; |
| 382 } | 395 } |
| 383 // Generate an error message and set ErrorStatus. | 396 // Generate an error message and set ErrorStatus. |
| 384 this->reportBadTypeIDAs(ID, Ty, WantedKind); | 397 this->reportBadTypeIDAs(ID, Ty, WantedKind); |
| 385 return nullptr; | 398 return nullptr; |
| 386 } | 399 } |
| 387 | 400 |
| 388 // Gives Decl a name if it doesn't already have one. Prefix and | 401 // Gives Decl a name if it doesn't already have one. Prefix and |
| 389 // NameIndex are used to generate the name. NameIndex is | 402 // NameIndex are used to generate the name. NameIndex is |
| 390 // automatically incremented if a new name is created. DeclType is | 403 // automatically incremented if a new name is created. DeclType is |
| 391 // literal text describing the type of name being created. Also | 404 // literal text describing the type of name being created. Also |
| 392 // generates warning if created names may conflict with named | 405 // generates warning if created names may conflict with named |
| 393 // declarations. | 406 // declarations. |
| 394 void installDeclarationName(Ice::GlobalDeclaration *Decl, | 407 void installDeclarationName(Ice::GlobalDeclaration *Decl, |
| 395 const Ice::IceString &Prefix, | 408 const Ice::IceString &Prefix, |
| 396 const char *DeclType, uint32_t &NameIndex) { | 409 const char *DeclType, |
| 410 NaClBcIndexSize_t &NameIndex) { | |
| 397 if (Decl->hasName()) { | 411 if (Decl->hasName()) { |
| 398 Translator.checkIfUnnamedNameSafe(Decl->getName(), DeclType, Prefix); | 412 Translator.checkIfUnnamedNameSafe(Decl->getName(), DeclType, Prefix); |
| 399 } else { | 413 } else { |
| 400 Decl->setName(Translator.createUnnamedName(Prefix, NameIndex)); | 414 Decl->setName(Translator.createUnnamedName(Prefix, NameIndex)); |
| 401 ++NameIndex; | 415 ++NameIndex; |
| 402 } | 416 } |
| 403 } | 417 } |
| 404 | 418 |
| 405 // Installs names for global variables without names. | 419 // Installs names for global variables without names. |
| 406 void installGlobalVarNames() { | 420 void installGlobalVarNames() { |
| 407 assert(VariableDeclarations); | 421 assert(VariableDeclarations); |
| 408 const Ice::IceString &GlobalPrefix = | 422 const Ice::IceString &GlobalPrefix = |
| 409 getTranslator().getFlags().getDefaultGlobalPrefix(); | 423 getTranslator().getFlags().getDefaultGlobalPrefix(); |
| 410 if (!GlobalPrefix.empty()) { | 424 if (!GlobalPrefix.empty()) { |
| 411 uint32_t NameIndex = 0; | 425 NaClBcIndexSize_t NameIndex = 0; |
| 412 for (Ice::VariableDeclaration *Var : *VariableDeclarations) { | 426 for (Ice::VariableDeclaration *Var : *VariableDeclarations) { |
| 413 installDeclarationName(Var, GlobalPrefix, "global", NameIndex); | 427 installDeclarationName(Var, GlobalPrefix, "global", NameIndex); |
| 414 } | 428 } |
| 415 } | 429 } |
| 416 } | 430 } |
| 417 | 431 |
| 418 // Installs names for functions without names. | 432 // Installs names for functions without names. |
| 419 void installFunctionNames() { | 433 void installFunctionNames() { |
| 420 const Ice::IceString &FunctionPrefix = | 434 const Ice::IceString &FunctionPrefix = |
| 421 getTranslator().getFlags().getDefaultFunctionPrefix(); | 435 getTranslator().getFlags().getDefaultFunctionPrefix(); |
| 422 if (!FunctionPrefix.empty()) { | 436 if (!FunctionPrefix.empty()) { |
| 423 uint32_t NameIndex = 0; | 437 NaClBcIndexSize_t NameIndex = 0; |
| 424 for (Ice::FunctionDeclaration *Func : FunctionDeclarationList) { | 438 for (Ice::FunctionDeclaration *Func : FunctionDeclarationList) { |
| 425 installDeclarationName(Func, FunctionPrefix, "function", NameIndex); | 439 installDeclarationName(Func, FunctionPrefix, "function", NameIndex); |
| 426 } | 440 } |
| 427 } | 441 } |
| 428 } | 442 } |
| 429 | 443 |
| 430 // Builds a constant symbol named Name, suppressing name mangling if | 444 // Builds a constant symbol named Name, suppressing name mangling if |
| 431 // SuppressMangling. IsExternal is true iff the symbol is external. | 445 // SuppressMangling. IsExternal is true iff the symbol is external. |
| 432 Ice::Constant *getConstantSym(const Ice::IceString &Name, | 446 Ice::Constant *getConstantSym(const Ice::IceString &Name, |
| 433 bool SuppressMangling, bool IsExternal) const { | 447 bool SuppressMangling, bool IsExternal) const { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 458 Ice::Constant *C = nullptr; | 472 Ice::Constant *C = nullptr; |
| 459 if (!isIRGenerationDisabled()) { | 473 if (!isIRGenerationDisabled()) { |
| 460 C = getConstantSym(Decl->getName(), Decl->getSuppressMangling(), | 474 C = getConstantSym(Decl->getName(), Decl->getSuppressMangling(), |
| 461 !Decl->hasInitializer()); | 475 !Decl->hasInitializer()); |
| 462 } | 476 } |
| 463 ValueIDConstants.push_back(C); | 477 ValueIDConstants.push_back(C); |
| 464 } | 478 } |
| 465 } | 479 } |
| 466 | 480 |
| 467 // Reports that type ID is undefined, or not of the WantedType. | 481 // Reports that type ID is undefined, or not of the WantedType. |
| 468 void reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, | 482 void reportBadTypeIDAs(NaClBcIndexSize_t ID, const ExtendedType *Ty, |
| 469 ExtendedType::TypeKind WantedType); | 483 ExtendedType::TypeKind WantedType); |
| 470 | 484 |
| 471 // Reports that there is no function declaration for ID. Returns an | 485 // Reports that there is no function declaration for ID. Returns an |
| 472 // error recovery value to use. | 486 // error recovery value to use. |
| 473 Ice::FunctionDeclaration *reportGetFunctionByIDError(unsigned ID); | 487 Ice::FunctionDeclaration *reportGetFunctionByIDError(NaClBcIndexSize_t ID); |
| 474 | 488 |
| 475 // Reports that there is not global variable declaration for | 489 // Reports that there is not global variable declaration for |
| 476 // ID. Returns an error recovery value to use. | 490 // ID. Returns an error recovery value to use. |
| 477 Ice::VariableDeclaration *reportGetGlobalVariableByIDError(unsigned Index); | 491 Ice::VariableDeclaration * |
| 492 reportGetGlobalVariableByIDError(NaClBcIndexSize_t Index); | |
| 478 | 493 |
| 479 // Reports that there is no corresponding ICE type for LLVMTy, and | 494 // Reports that there is no corresponding ICE type for LLVMTy, and |
| 480 // returns ICE::IceType_void. | 495 // returns ICE::IceType_void. |
|
Jim Stichnoth
2015/06/21 00:33:42
Ice::IceType_void
Karl
2015/06/22 22:10:04
Done.
| |
| 481 Ice::Type convertToIceTypeError(Type *LLVMTy); | 496 Ice::Type convertToIceTypeError(Type *LLVMTy); |
| 482 }; | 497 }; |
| 483 | 498 |
| 484 bool TopLevelParser::ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit, | 499 bool TopLevelParser::ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit, |
| 485 const std::string &Message) { | 500 const std::string &Message) { |
| 486 ErrorStatus.assign(Ice::EC_Bitcode); | 501 ErrorStatus.assign(Ice::EC_Bitcode); |
| 487 ++NumErrors; | 502 ++NumErrors; |
| 488 Ice::GlobalContext *Context = Translator.getContext(); | 503 Ice::GlobalContext *Context = Translator.getContext(); |
| 489 { // Lock while printing out error message. | 504 { // Lock while printing out error message. |
| 490 Ice::OstreamLocker L(Context); | 505 Ice::OstreamLocker L(Context); |
| 491 raw_ostream &OldErrStream = setErrStream(Context->getStrError()); | 506 raw_ostream &OldErrStream = setErrStream(Context->getStrError()); |
| 492 NaClBitcodeParser::ErrorAt(Level, Bit, Message); | 507 NaClBitcodeParser::ErrorAt(Level, Bit, Message); |
| 493 setErrStream(OldErrStream); | 508 setErrStream(OldErrStream); |
| 494 } | 509 } |
| 495 if (Level >= naclbitc::Error && | 510 if (Level >= naclbitc::Error && |
| 496 !Translator.getFlags().getAllowErrorRecovery()) | 511 !Translator.getFlags().getAllowErrorRecovery()) |
| 497 Fatal(); | 512 Fatal(); |
| 498 return true; | 513 return true; |
| 499 } | 514 } |
| 500 | 515 |
| 501 void TopLevelParser::reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, | 516 void TopLevelParser::reportBadTypeIDAs(NaClBcIndexSize_t ID, |
| 517 const ExtendedType *Ty, | |
| 502 ExtendedType::TypeKind WantedType) { | 518 ExtendedType::TypeKind WantedType) { |
| 503 std::string Buffer; | 519 std::string Buffer; |
| 504 raw_string_ostream StrBuf(Buffer); | 520 raw_string_ostream StrBuf(Buffer); |
| 505 if (Ty == nullptr) { | 521 if (Ty == nullptr) { |
| 506 StrBuf << "Can't find extended type for type id: " << ID; | 522 StrBuf << "Can't find extended type for type id: " << ID; |
| 507 } else { | 523 } else { |
| 508 StrBuf << "Type id " << ID << " not " << WantedType << ". Found: " << *Ty; | 524 StrBuf << "Type id " << ID << " not " << WantedType << ". Found: " << *Ty; |
| 509 } | 525 } |
| 510 BlockError(StrBuf.str()); | 526 BlockError(StrBuf.str()); |
| 511 } | 527 } |
| 512 | 528 |
| 513 Ice::FunctionDeclaration * | 529 Ice::FunctionDeclaration * |
| 514 TopLevelParser::reportGetFunctionByIDError(unsigned ID) { | 530 TopLevelParser::reportGetFunctionByIDError(NaClBcIndexSize_t ID) { |
| 515 std::string Buffer; | 531 std::string Buffer; |
| 516 raw_string_ostream StrBuf(Buffer); | 532 raw_string_ostream StrBuf(Buffer); |
| 517 StrBuf << "Function index " << ID | 533 StrBuf << "Function index " << ID |
| 518 << " not allowed. Out of range. Must be less than " | 534 << " not allowed. Out of range. Must be less than " |
| 519 << FunctionDeclarationList.size(); | 535 << FunctionDeclarationList.size(); |
| 520 BlockError(StrBuf.str()); | 536 BlockError(StrBuf.str()); |
| 521 // TODO(kschimpf) Remove error recovery once implementation complete. | 537 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 522 if (!FunctionDeclarationList.empty()) | 538 if (!FunctionDeclarationList.empty()) |
| 523 return FunctionDeclarationList[0]; | 539 return FunctionDeclarationList[0]; |
| 524 Fatal(); | 540 Fatal(); |
| 525 } | 541 } |
| 526 | 542 |
| 527 Ice::VariableDeclaration * | 543 Ice::VariableDeclaration * |
| 528 TopLevelParser::reportGetGlobalVariableByIDError(unsigned Index) { | 544 TopLevelParser::reportGetGlobalVariableByIDError(NaClBcIndexSize_t Index) { |
| 529 std::string Buffer; | 545 std::string Buffer; |
| 530 raw_string_ostream StrBuf(Buffer); | 546 raw_string_ostream StrBuf(Buffer); |
| 531 StrBuf << "Global index " << Index | 547 StrBuf << "Global index " << Index |
| 532 << " not allowed. Out of range. Must be less than " | 548 << " not allowed. Out of range. Must be less than " |
| 533 << VariableDeclarations->size(); | 549 << VariableDeclarations->size(); |
| 534 BlockError(StrBuf.str()); | 550 BlockError(StrBuf.str()); |
| 535 // TODO(kschimpf) Remove error recovery once implementation complete. | 551 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 536 if (!VariableDeclarations->empty()) | 552 if (!VariableDeclarations->empty()) |
| 537 return VariableDeclarations->at(0); | 553 return VariableDeclarations->at(0); |
| 538 Fatal(); | 554 Fatal(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 // Default implementation. Reports that block is unknown and skips | 611 // Default implementation. Reports that block is unknown and skips |
| 596 // its contents. | 612 // its contents. |
| 597 bool ParseBlock(unsigned BlockID) override; | 613 bool ParseBlock(unsigned BlockID) override; |
| 598 | 614 |
| 599 // Default implementation. Reports that the record is not | 615 // Default implementation. Reports that the record is not |
| 600 // understood. | 616 // understood. |
| 601 void ProcessRecord() override; | 617 void ProcessRecord() override; |
| 602 | 618 |
| 603 // Checks if the size of the record is Size. Return true if valid. | 619 // Checks if the size of the record is Size. Return true if valid. |
| 604 // Otherwise generates an error and returns false. | 620 // Otherwise generates an error and returns false. |
| 605 bool isValidRecordSize(unsigned Size, const char *RecordName) { | 621 bool isValidRecordSize(size_t Size, const char *RecordName) { |
| 606 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 622 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 607 if (Values.size() == Size) | 623 if (Values.size() == Size) |
| 608 return true; | 624 return true; |
| 609 ReportRecordSizeError(Size, RecordName, nullptr); | 625 ReportRecordSizeError(Size, RecordName, nullptr); |
| 610 return false; | 626 return false; |
| 611 } | 627 } |
| 612 | 628 |
| 613 // Checks if the size of the record is at least as large as the | 629 // Checks if the size of the record is at least as large as the |
| 614 // LowerLimit. Returns true if valid. Otherwise generates an error | 630 // LowerLimit. Returns true if valid. Otherwise generates an error |
| 615 // and returns false. | 631 // and returns false. |
| 616 bool isValidRecordSizeAtLeast(unsigned LowerLimit, const char *RecordName) { | 632 bool isValidRecordSizeAtLeast(size_t LowerLimit, const char *RecordName) { |
| 617 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 633 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 618 if (Values.size() >= LowerLimit) | 634 if (Values.size() >= LowerLimit) |
| 619 return true; | 635 return true; |
| 620 ReportRecordSizeError(LowerLimit, RecordName, "at least"); | 636 ReportRecordSizeError(LowerLimit, RecordName, "at least"); |
| 621 return false; | 637 return false; |
| 622 } | 638 } |
| 623 | 639 |
| 624 // Checks if the size of the record is no larger than the | 640 // Checks if the size of the record is no larger than the |
| 625 // UpperLimit. Returns true if valid. Otherwise generates an error | 641 // UpperLimit. Returns true if valid. Otherwise generates an error |
| 626 // and returns false. | 642 // and returns false. |
| 627 bool isValidRecordSizeAtMost(unsigned UpperLimit, const char *RecordName) { | 643 bool isValidRecordSizeAtMost(size_t UpperLimit, const char *RecordName) { |
| 628 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 644 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 629 if (Values.size() <= UpperLimit) | 645 if (Values.size() <= UpperLimit) |
| 630 return true; | 646 return true; |
| 631 ReportRecordSizeError(UpperLimit, RecordName, "no more than"); | 647 ReportRecordSizeError(UpperLimit, RecordName, "no more than"); |
| 632 return false; | 648 return false; |
| 633 } | 649 } |
| 634 | 650 |
| 635 // Checks if the size of the record is at least as large as the | 651 // Checks if the size of the record is at least as large as the |
| 636 // LowerLimit, and no larger than the UpperLimit. Returns true if | 652 // LowerLimit, and no larger than the UpperLimit. Returns true if |
| 637 // valid. Otherwise generates an error and returns false. | 653 // valid. Otherwise generates an error and returns false. |
| 638 bool isValidRecordSizeInRange(unsigned LowerLimit, unsigned UpperLimit, | 654 bool isValidRecordSizeInRange(size_t LowerLimit, size_t UpperLimit, |
| 639 const char *RecordName) { | 655 const char *RecordName) { |
| 640 return isValidRecordSizeAtLeast(LowerLimit, RecordName) || | 656 return isValidRecordSizeAtLeast(LowerLimit, RecordName) || |
| 641 isValidRecordSizeAtMost(UpperLimit, RecordName); | 657 isValidRecordSizeAtMost(UpperLimit, RecordName); |
| 642 } | 658 } |
| 643 | 659 |
| 644 private: | 660 private: |
| 645 /// Generates a record size error. ExpectedSize is the number | 661 /// Generates a record size error. ExpectedSize is the number |
| 646 /// of elements expected. RecordName is the name of the kind of | 662 /// of elements expected. RecordName is the name of the kind of |
| 647 /// record that has incorrect size. ContextMessage (if not nullptr) | 663 /// record that has incorrect size. ContextMessage (if not nullptr) |
| 648 /// is appended to "record expects" to describe how ExpectedSize | 664 /// is appended to "record expects" to describe how ExpectedSize |
| 649 /// should be interpreted. | 665 /// should be interpreted. |
| 650 void ReportRecordSizeError(unsigned ExpectedSize, const char *RecordName, | 666 void ReportRecordSizeError(size_t ExpectedSize, const char *RecordName, |
| 651 const char *ContextMessage); | 667 const char *ContextMessage); |
| 652 }; | 668 }; |
| 653 | 669 |
| 654 bool TopLevelParser::BlockError(const std::string &Message) { | 670 bool TopLevelParser::BlockError(const std::string &Message) { |
| 655 if (BlockParser) | 671 if (BlockParser) |
| 656 return BlockParser->Error(Message); | 672 return BlockParser->Error(Message); |
| 657 else | 673 else |
| 658 return Error(Message); | 674 return Error(Message); |
| 659 } | 675 } |
| 660 | 676 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 671 for (const uint64_t Val : Record.GetValues()) { | 687 for (const uint64_t Val : Record.GetValues()) { |
| 672 StrBuf << " " << Val; | 688 StrBuf << " " << Val; |
| 673 } | 689 } |
| 674 StrBuf << ">"; | 690 StrBuf << ">"; |
| 675 } else { | 691 } else { |
| 676 StrBuf << Message; | 692 StrBuf << Message; |
| 677 } | 693 } |
| 678 return Context->ErrorAt(Level, Bit, StrBuf.str()); | 694 return Context->ErrorAt(Level, Bit, StrBuf.str()); |
| 679 } | 695 } |
| 680 | 696 |
| 681 void BlockParserBaseClass::ReportRecordSizeError(unsigned ExpectedSize, | 697 void BlockParserBaseClass::ReportRecordSizeError(size_t ExpectedSize, |
| 682 const char *RecordName, | 698 const char *RecordName, |
| 683 const char *ContextMessage) { | 699 const char *ContextMessage) { |
| 684 std::string Buffer; | 700 std::string Buffer; |
| 685 raw_string_ostream StrBuf(Buffer); | 701 raw_string_ostream StrBuf(Buffer); |
| 686 const char *BlockName = getBlockName(); | 702 const char *BlockName = getBlockName(); |
| 687 const char FirstChar = toupper(*BlockName); | 703 const char FirstChar = toupper(*BlockName); |
| 688 StrBuf << FirstChar << (BlockName + 1) << " " << RecordName | 704 StrBuf << FirstChar << (BlockName + 1) << " " << RecordName |
| 689 << " record expects"; | 705 << " record expects"; |
| 690 if (ContextMessage) | 706 if (ContextMessage) |
| 691 StrBuf << " " << ContextMessage; | 707 StrBuf << " " << ContextMessage; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 719 | 735 |
| 720 // Class to parse a types block. | 736 // Class to parse a types block. |
| 721 class TypesParser : public BlockParserBaseClass { | 737 class TypesParser : public BlockParserBaseClass { |
| 722 TypesParser() = delete; | 738 TypesParser() = delete; |
| 723 TypesParser(const TypesParser &) = delete; | 739 TypesParser(const TypesParser &) = delete; |
| 724 TypesParser &operator=(const TypesParser &) = delete; | 740 TypesParser &operator=(const TypesParser &) = delete; |
| 725 | 741 |
| 726 public: | 742 public: |
| 727 TypesParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 743 TypesParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
| 728 : BlockParserBaseClass(BlockID, EnclosingParser), | 744 : BlockParserBaseClass(BlockID, EnclosingParser), |
| 729 Timer(Ice::TimerStack::TT_parseTypes, getTranslator().getContext()), | 745 Timer(Ice::TimerStack::TT_parseTypes, getTranslator().getContext()) {} |
| 730 NextTypeId(0) {} | |
| 731 | 746 |
| 732 ~TypesParser() override {} | 747 ~TypesParser() override { |
| 748 if (ExpectedNumTypes != Context->getNumTypeIDValues()) { | |
| 749 std::string Buffer; | |
| 750 raw_string_ostream StrBuf(Buffer); | |
| 751 StrBuf << "Types block expected " << ExpectedNumTypes | |
| 752 << " types but found: " << NextTypeId; | |
| 753 Error(StrBuf.str()); | |
| 754 } | |
| 755 } | |
| 733 | 756 |
| 734 private: | 757 private: |
| 735 Ice::TimerMarker Timer; | 758 Ice::TimerMarker Timer; |
| 736 // The type ID that will be associated with the next type defining | 759 // The type ID that will be associated with the next type defining |
| 737 // record in the types block. | 760 // record in the types block. |
| 738 unsigned NextTypeId; | 761 NaClBcIndexSize_t NextTypeId = 0; |
|
Jim Stichnoth
2015/06/21 00:33:42
Cool, I didn't know this was possible!
Karl
2015/06/22 22:10:03
Acknowledged.
| |
| 762 | |
| 763 // The expected number of types, based on record TYPE_CODE_NUMENTRY. | |
| 764 NaClBcIndexSize_t ExpectedNumTypes = 0; | |
| 739 | 765 |
| 740 void ProcessRecord() override; | 766 void ProcessRecord() override; |
| 741 | 767 |
| 742 const char *getBlockName() const override { return "type"; } | 768 const char *getBlockName() const override { return "type"; } |
| 743 | 769 |
| 744 void setNextTypeIDAsSimpleType(Ice::Type Ty) { | 770 void setNextTypeIDAsSimpleType(Ice::Type Ty) { |
| 745 Context->getTypeByIDForDefining(NextTypeId++)->setAsSimpleType(Ty); | 771 Context->getTypeByIDForDefining(NextTypeId++)->setAsSimpleType(Ty); |
| 746 } | 772 } |
| 747 }; | 773 }; |
| 748 | 774 |
| 749 void TypesParser::ProcessRecord() { | 775 void TypesParser::ProcessRecord() { |
| 750 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 776 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 751 switch (Record.GetCode()) { | 777 switch (Record.GetCode()) { |
| 752 case naclbitc::TYPE_CODE_NUMENTRY: | 778 case naclbitc::TYPE_CODE_NUMENTRY: { |
| 753 // NUMENTRY: [numentries] | 779 // NUMENTRY: [numentries] |
| 754 if (!isValidRecordSize(1, "count")) | 780 if (!isValidRecordSize(1, "count")) |
| 755 return; | 781 return; |
| 756 Context->resizeTypeIDValues(Values[0]); | 782 uint64_t Size = Values[0]; |
| 783 if (Size > NaClBcIndexSize_t_Max) { | |
| 784 std::string Buffer; | |
| 785 raw_string_ostream StrBuf(Buffer); | |
| 786 StrBuf << "Size to big for count record: " << Size; | |
| 787 Error(StrBuf.str()); | |
| 788 ExpectedNumTypes = NaClBcIndexSize_t_Max; | |
| 789 } | |
| 790 // The code double checks that Expected size and the actual size | |
| 791 // at the end of the block. To reduce allocations we preallocate | |
| 792 // the space. | |
| 793 // | |
| 794 // However, if the number is large, we suspect that the number | |
| 795 // is (possibly) incorrect. In that case, we preallocate a | |
| 796 // smaller space. | |
| 797 Context->resizeTypeIDValues(std::min(Size, (uint64_t)1000000)); | |
|
Jim Stichnoth
2015/06/21 00:33:42
do this without icky magic constants
Karl
2015/06/22 22:10:03
Done.
| |
| 798 ExpectedNumTypes = Size; | |
| 757 return; | 799 return; |
| 800 } | |
| 758 case naclbitc::TYPE_CODE_VOID: | 801 case naclbitc::TYPE_CODE_VOID: |
| 759 // VOID | 802 // VOID |
| 760 if (!isValidRecordSize(0, "void")) | 803 if (!isValidRecordSize(0, "void")) |
| 761 return; | 804 return; |
| 762 setNextTypeIDAsSimpleType(Ice::IceType_void); | 805 setNextTypeIDAsSimpleType(Ice::IceType_void); |
| 763 return; | 806 return; |
| 764 case naclbitc::TYPE_CODE_FLOAT: | 807 case naclbitc::TYPE_CODE_FLOAT: |
| 765 // FLOAT | 808 // FLOAT |
| 766 if (!isValidRecordSize(0, "float")) | 809 if (!isValidRecordSize(0, "float")) |
| 767 return; | 810 return; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 864 case naclbitc::TYPE_CODE_FUNCTION: { | 907 case naclbitc::TYPE_CODE_FUNCTION: { |
| 865 // FUNCTION: [vararg, retty, paramty x N] | 908 // FUNCTION: [vararg, retty, paramty x N] |
| 866 if (!isValidRecordSizeAtLeast(2, "signature")) | 909 if (!isValidRecordSizeAtLeast(2, "signature")) |
| 867 return; | 910 return; |
| 868 if (Values[0]) | 911 if (Values[0]) |
| 869 Error("Function type can't define varargs"); | 912 Error("Function type can't define varargs"); |
| 870 ExtendedType *Ty = Context->getTypeByIDForDefining(NextTypeId++); | 913 ExtendedType *Ty = Context->getTypeByIDForDefining(NextTypeId++); |
| 871 Ty->setAsFunctionType(); | 914 Ty->setAsFunctionType(); |
| 872 FuncSigExtendedType *FuncTy = cast<FuncSigExtendedType>(Ty); | 915 FuncSigExtendedType *FuncTy = cast<FuncSigExtendedType>(Ty); |
| 873 FuncTy->setReturnType(Context->getSimpleTypeByID(Values[1])); | 916 FuncTy->setReturnType(Context->getSimpleTypeByID(Values[1])); |
| 874 for (unsigned i = 2, e = Values.size(); i != e; ++i) { | 917 for (size_t i = 2, e = Values.size(); i != e; ++i) { |
| 875 // Check that type void not used as argument type. | 918 // Check that type void not used as argument type. |
| 876 // Note: PNaCl restrictions can't be checked until we | 919 // Note: PNaCl restrictions can't be checked until we |
| 877 // know the name, because we have to check for intrinsic signatures. | 920 // know the name, because we have to check for intrinsic signatures. |
| 878 Ice::Type ArgTy = Context->getSimpleTypeByID(Values[i]); | 921 Ice::Type ArgTy = Context->getSimpleTypeByID(Values[i]); |
| 879 if (ArgTy == Ice::IceType_void) { | 922 if (ArgTy == Ice::IceType_void) { |
| 880 std::string Buffer; | 923 std::string Buffer; |
| 881 raw_string_ostream StrBuf(Buffer); | 924 raw_string_ostream StrBuf(Buffer); |
| 882 StrBuf << "Type for parameter " << (i - 1) | 925 StrBuf << "Type for parameter " << (i - 1) |
| 883 << " not valid. Found: " << ArgTy; | 926 << " not valid. Found: " << ArgTy; |
| 884 // TODO(kschimpf) Remove error recovery once implementation complete. | 927 // TODO(kschimpf) Remove error recovery once implementation complete. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 911 CurGlobalVar(DummyGlobalVar) {} | 954 CurGlobalVar(DummyGlobalVar) {} |
| 912 | 955 |
| 913 ~GlobalsParser() final {} | 956 ~GlobalsParser() final {} |
| 914 | 957 |
| 915 const char *getBlockName() const override { return "globals"; } | 958 const char *getBlockName() const override { return "globals"; } |
| 916 | 959 |
| 917 private: | 960 private: |
| 918 Ice::TimerMarker Timer; | 961 Ice::TimerMarker Timer; |
| 919 // Keeps track of how many initializers are expected for the global variable | 962 // Keeps track of how many initializers are expected for the global variable |
| 920 // declaration being built. | 963 // declaration being built. |
| 921 unsigned InitializersNeeded; | 964 NaClBcIndexSize_t InitializersNeeded; |
| 922 | 965 |
| 923 // The index of the next global variable declaration. | 966 // The index of the next global variable declaration. |
| 924 unsigned NextGlobalID; | 967 NaClBcIndexSize_t NextGlobalID; |
| 925 | 968 |
| 926 // Dummy global variable declaration to guarantee CurGlobalVar is | 969 // Dummy global variable declaration to guarantee CurGlobalVar is |
| 927 // always defined (allowing code to not need to check if | 970 // always defined (allowing code to not need to check if |
| 928 // CurGlobalVar is nullptr). | 971 // CurGlobalVar is nullptr). |
| 929 Ice::VariableDeclaration *DummyGlobalVar; | 972 Ice::VariableDeclaration *DummyGlobalVar; |
| 930 | 973 |
| 931 // Holds the current global variable declaration being built. | 974 // Holds the current global variable declaration being built. |
| 932 Ice::VariableDeclaration *CurGlobalVar; | 975 Ice::VariableDeclaration *CurGlobalVar; |
| 933 | 976 |
| 934 void ExitBlock() override { | 977 void ExitBlock() override { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 970 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 1013 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 971 switch (Record.GetCode()) { | 1014 switch (Record.GetCode()) { |
| 972 case naclbitc::GLOBALVAR_COUNT: | 1015 case naclbitc::GLOBALVAR_COUNT: |
| 973 // COUNT: [n] | 1016 // COUNT: [n] |
| 974 if (!isValidRecordSize(1, "count")) | 1017 if (!isValidRecordSize(1, "count")) |
| 975 return; | 1018 return; |
| 976 if (NextGlobalID != Context->getNumGlobalVariables()) { | 1019 if (NextGlobalID != Context->getNumGlobalVariables()) { |
| 977 Error("Globals count record not first in block."); | 1020 Error("Globals count record not first in block."); |
| 978 return; | 1021 return; |
| 979 } | 1022 } |
| 980 Context->CreateGlobalVariables(Values[0]); | 1023 Context->createGlobalVariables(Values[0]); |
| 981 return; | 1024 return; |
| 982 case naclbitc::GLOBALVAR_VAR: { | 1025 case naclbitc::GLOBALVAR_VAR: { |
| 983 // VAR: [align, isconst] | 1026 // VAR: [align, isconst] |
| 984 if (!isValidRecordSize(2, "variable")) | 1027 if (!isValidRecordSize(2, "variable")) |
| 985 return; | 1028 return; |
| 986 verifyNoMissingInitializers(); | 1029 verifyNoMissingInitializers(); |
| 987 if (!isIRGenerationDisabled()) { | 1030 if (!isIRGenerationDisabled()) { |
| 988 InitializersNeeded = 1; | 1031 InitializersNeeded = 1; |
| 989 CurGlobalVar = Context->getGlobalVariableByID(NextGlobalID); | 1032 CurGlobalVar = Context->getGlobalVariableByID(NextGlobalID); |
| 990 CurGlobalVar->setAlignment((1 << Values[0]) >> 1); | 1033 CurGlobalVar->setAlignment((1 << Values[0]) >> 1); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1033 new Ice::VariableDeclaration::DataInitializer(Values)); | 1076 new Ice::VariableDeclaration::DataInitializer(Values)); |
| 1034 return; | 1077 return; |
| 1035 } | 1078 } |
| 1036 case naclbitc::GLOBALVAR_RELOC: { | 1079 case naclbitc::GLOBALVAR_RELOC: { |
| 1037 // RELOC: [val, [addend]] | 1080 // RELOC: [val, [addend]] |
| 1038 if (!isValidRecordSizeInRange(1, 2, "reloc")) | 1081 if (!isValidRecordSizeInRange(1, 2, "reloc")) |
| 1039 return; | 1082 return; |
| 1040 if (isIRGenerationDisabled()) | 1083 if (isIRGenerationDisabled()) |
| 1041 return; | 1084 return; |
| 1042 unsigned Index = Values[0]; | 1085 unsigned Index = Values[0]; |
| 1043 Ice::SizeT Offset = 0; | 1086 uint64_t Offset = 0; |
| 1044 if (Values.size() == 2) | 1087 if (Values.size() == 2) { |
| 1045 Offset = Values[1]; | 1088 Offset = Values[1]; |
| 1089 if (Offset > std::numeric_limits<uint32_t>::max()) { | |
| 1090 std::string Buffer; | |
| 1091 raw_string_ostream StrBuf(Buffer); | |
| 1092 StrBuf << "Added of global reloc record too big: " << Offset; | |
| 1093 Error(StrBuf.str()); | |
| 1094 } | |
| 1095 } | |
| 1046 CurGlobalVar->addInitializer(new Ice::VariableDeclaration::RelocInitializer( | 1096 CurGlobalVar->addInitializer(new Ice::VariableDeclaration::RelocInitializer( |
| 1047 Context->getGlobalDeclarationByID(Index), Offset)); | 1097 Context->getGlobalDeclarationByID(Index), Offset)); |
| 1048 return; | 1098 return; |
| 1049 } | 1099 } |
| 1050 default: | 1100 default: |
| 1051 BlockParserBaseClass::ProcessRecord(); | 1101 BlockParserBaseClass::ProcessRecord(); |
| 1052 return; | 1102 return; |
| 1053 } | 1103 } |
| 1054 } | 1104 } |
| 1055 | 1105 |
| 1056 /// Base class for parsing a valuesymtab block in the bitcode file. | 1106 /// Base class for parsing a valuesymtab block in the bitcode file. |
| 1057 class ValuesymtabParser : public BlockParserBaseClass { | 1107 class ValuesymtabParser : public BlockParserBaseClass { |
| 1058 ValuesymtabParser() = delete; | 1108 ValuesymtabParser() = delete; |
| 1059 ValuesymtabParser(const ValuesymtabParser &) = delete; | 1109 ValuesymtabParser(const ValuesymtabParser &) = delete; |
| 1060 void operator=(const ValuesymtabParser &) = delete; | 1110 void operator=(const ValuesymtabParser &) = delete; |
| 1061 | 1111 |
| 1062 public: | 1112 public: |
| 1063 ValuesymtabParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 1113 ValuesymtabParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
| 1064 : BlockParserBaseClass(BlockID, EnclosingParser) {} | 1114 : BlockParserBaseClass(BlockID, EnclosingParser) {} |
| 1065 | 1115 |
| 1066 ~ValuesymtabParser() override {} | 1116 ~ValuesymtabParser() override {} |
| 1067 | 1117 |
| 1068 const char *getBlockName() const override { return "valuesymtab"; } | 1118 const char *getBlockName() const override { return "valuesymtab"; } |
| 1069 | 1119 |
| 1070 protected: | 1120 protected: |
| 1071 typedef SmallString<128> StringType; | 1121 typedef SmallString<128> StringType; |
| 1072 | 1122 |
| 1073 // Associates Name with the value defined by the given Index. | 1123 // Associates Name with the value defined by the given Index. |
| 1074 virtual void setValueName(uint64_t Index, StringType &Name) = 0; | 1124 virtual void setValueName(NaClBcIndexSize_t Index, StringType &Name) = 0; |
| 1075 | 1125 |
| 1076 // Associates Name with the value defined by the given Index; | 1126 // Associates Name with the value defined by the given Index; |
| 1077 virtual void setBbName(uint64_t Index, StringType &Name) = 0; | 1127 virtual void setBbName(NaClBcIndexSize_t Index, StringType &Name) = 0; |
| 1078 | 1128 |
| 1079 private: | 1129 private: |
| 1080 void ProcessRecord() override; | 1130 void ProcessRecord() override; |
| 1081 | 1131 |
| 1082 void ConvertToString(StringType &ConvertedName) { | 1132 void ConvertToString(StringType &ConvertedName) { |
| 1083 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 1133 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 1084 for (size_t i = 1, e = Values.size(); i != e; ++i) { | 1134 for (size_t i = 1, e = Values.size(); i != e; ++i) { |
| 1085 ConvertedName += static_cast<char>(Values[i]); | 1135 ConvertedName += static_cast<char>(Values[i]); |
| 1086 } | 1136 } |
| 1087 } | 1137 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1188 | 1238 |
| 1189 return ParserResult; | 1239 return ParserResult; |
| 1190 } | 1240 } |
| 1191 | 1241 |
| 1192 ~FunctionParser() final {} | 1242 ~FunctionParser() final {} |
| 1193 | 1243 |
| 1194 const char *getBlockName() const override { return "function"; } | 1244 const char *getBlockName() const override { return "function"; } |
| 1195 | 1245 |
| 1196 Ice::Cfg *getFunc() const { return Func.get(); } | 1246 Ice::Cfg *getFunc() const { return Func.get(); } |
| 1197 | 1247 |
| 1198 uint32_t getNumGlobalIDs() const { return CachedNumGlobalValueIDs; } | 1248 size_t getNumGlobalIDs() const { return CachedNumGlobalValueIDs; } |
| 1199 | 1249 |
| 1200 void setNextLocalInstIndex(Ice::Operand *Op) { | 1250 void setNextLocalInstIndex(Ice::Operand *Op) { |
| 1201 setOperand(NextLocalInstIndex++, Op); | 1251 setOperand(NextLocalInstIndex++, Op); |
| 1202 } | 1252 } |
| 1203 | 1253 |
| 1204 // Set the next constant ID to the given constant C. | 1254 // Set the next constant ID to the given constant C. |
| 1205 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } | 1255 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } |
| 1206 | 1256 |
| 1207 // Returns the value referenced by the given value Index. | 1257 // Returns the value referenced by the given value Index. |
| 1208 Ice::Operand *getOperand(uint32_t Index) { | 1258 Ice::Operand *getOperand(NaClBcIndexSize_t Index) { |
| 1209 if (Index < CachedNumGlobalValueIDs) { | 1259 if (Index < CachedNumGlobalValueIDs) { |
| 1210 return Context->getGlobalConstantByID(Index); | 1260 return Context->getGlobalConstantByID(Index); |
| 1211 } | 1261 } |
| 1212 uint32_t LocalIndex = Index - CachedNumGlobalValueIDs; | 1262 NaClBcIndexSize_t LocalIndex = Index - CachedNumGlobalValueIDs; |
| 1213 if (LocalIndex >= LocalOperands.size()) { | 1263 if (LocalIndex >= LocalOperands.size()) { |
| 1214 std::string Buffer; | 1264 std::string Buffer; |
| 1215 raw_string_ostream StrBuf(Buffer); | 1265 raw_string_ostream StrBuf(Buffer); |
| 1216 StrBuf << "Value index " << Index << " not defined!"; | 1266 StrBuf << "Value index " << Index << " not defined!"; |
| 1217 Fatal(StrBuf.str()); | 1267 Fatal(StrBuf.str()); |
| 1218 } | 1268 } |
| 1219 Ice::Operand *Op = LocalOperands[LocalIndex]; | 1269 Ice::Operand *Op = LocalOperands[LocalIndex]; |
| 1220 if (Op == nullptr) { | 1270 if (Op == nullptr) { |
| 1221 if (isIRGenerationDisabled()) | 1271 if (isIRGenerationDisabled()) |
| 1222 return nullptr; | 1272 return nullptr; |
| 1223 std::string Buffer; | 1273 std::string Buffer; |
| 1224 raw_string_ostream StrBuf(Buffer); | 1274 raw_string_ostream StrBuf(Buffer); |
| 1225 StrBuf << "Value index " << Index << " not defined!"; | 1275 StrBuf << "Value index " << Index << " not defined!"; |
| 1226 Fatal(StrBuf.str()); | 1276 Fatal(StrBuf.str()); |
| 1227 } | 1277 } |
| 1228 return Op; | 1278 return Op; |
| 1229 } | 1279 } |
| 1230 | 1280 |
| 1231 private: | 1281 private: |
| 1232 Ice::TimerMarker Timer; | 1282 Ice::TimerMarker Timer; |
| 1233 // The corresponding ICE function defined by the function block. | 1283 // The corresponding ICE function defined by the function block. |
| 1234 std::unique_ptr<Ice::Cfg> Func; | 1284 std::unique_ptr<Ice::Cfg> Func; |
| 1235 // The index to the current basic block being built. | 1285 // The index to the current basic block being built. |
| 1236 uint32_t CurrentBbIndex; | 1286 NaClBcIndexSize_t CurrentBbIndex; |
| 1237 // The basic block being built. | 1287 // The basic block being built. |
| 1238 Ice::CfgNode *CurrentNode; | 1288 Ice::CfgNode *CurrentNode; |
| 1239 // The ID for the function. | 1289 // The ID for the function. |
| 1240 unsigned FcnId; | 1290 NaClBcIndexSize_t FcnId; |
| 1241 // The corresponding function declaration. | 1291 // The corresponding function declaration. |
| 1242 Ice::FunctionDeclaration *FuncDecl; | 1292 Ice::FunctionDeclaration *FuncDecl; |
| 1243 // Holds the dividing point between local and global absolute value indices. | 1293 // Holds the dividing point between local and global absolute value indices. |
| 1244 uint32_t CachedNumGlobalValueIDs; | 1294 size_t CachedNumGlobalValueIDs; |
| 1245 // Holds operands local to the function block, based on indices | 1295 // Holds operands local to the function block, based on indices |
| 1246 // defined in the bitcode file. | 1296 // defined in the bitcode file. |
| 1247 std::vector<Ice::Operand *> LocalOperands; | 1297 std::vector<Ice::Operand *> LocalOperands; |
| 1248 // Holds the index within LocalOperands corresponding to the next | 1298 // Holds the index within LocalOperands corresponding to the next |
| 1249 // instruction that generates a value. | 1299 // instruction that generates a value. |
| 1250 uint32_t NextLocalInstIndex; | 1300 NaClBcIndexSize_t NextLocalInstIndex; |
| 1251 // True if the last processed instruction was a terminating | 1301 // True if the last processed instruction was a terminating |
| 1252 // instruction. | 1302 // instruction. |
| 1253 bool InstIsTerminating; | 1303 bool InstIsTerminating; |
| 1254 // Upper limit of alignment power allowed by LLVM | 1304 // Upper limit of alignment power allowed by LLVM |
| 1255 static const uint32_t AlignPowerLimit = 29; | 1305 static const uint32_t AlignPowerLimit = 29; |
| 1256 | 1306 |
| 1257 // Extracts the corresponding Alignment to use, given the AlignPower | 1307 // Extracts the corresponding Alignment to use, given the AlignPower |
| 1258 // (i.e. 2**(AlignPower-1), or 0 if AlignPower == 0). InstName is the | 1308 // (i.e. 2**(AlignPower-1), or 0 if AlignPower == 0). InstName is the |
| 1259 // name of the instruction the alignment appears in. | 1309 // name of the instruction the alignment appears in. |
| 1260 void extractAlignment(const char *InstName, uint32_t AlignPower, | 1310 void extractAlignment(const char *InstName, uint32_t AlignPower, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1278 | 1328 |
| 1279 void ExitBlock() override; | 1329 void ExitBlock() override; |
| 1280 | 1330 |
| 1281 // Creates and appends a new basic block to the list of basic blocks. | 1331 // Creates and appends a new basic block to the list of basic blocks. |
| 1282 Ice::CfgNode *InstallNextBasicBlock() { | 1332 Ice::CfgNode *InstallNextBasicBlock() { |
| 1283 assert(!isIRGenerationDisabled()); | 1333 assert(!isIRGenerationDisabled()); |
| 1284 return Func->makeNode(); | 1334 return Func->makeNode(); |
| 1285 } | 1335 } |
| 1286 | 1336 |
| 1287 // Returns the Index-th basic block in the list of basic blocks. | 1337 // Returns the Index-th basic block in the list of basic blocks. |
| 1288 Ice::CfgNode *getBasicBlock(uint32_t Index) { | 1338 Ice::CfgNode *getBasicBlock(NaClBcIndexSize_t Index) { |
| 1289 assert(!isIRGenerationDisabled()); | 1339 assert(!isIRGenerationDisabled()); |
| 1290 const Ice::NodeList &Nodes = Func->getNodes(); | 1340 const Ice::NodeList &Nodes = Func->getNodes(); |
| 1291 if (Index >= Nodes.size()) { | 1341 if (Index >= Nodes.size()) { |
| 1292 std::string Buffer; | 1342 std::string Buffer; |
| 1293 raw_string_ostream StrBuf(Buffer); | 1343 raw_string_ostream StrBuf(Buffer); |
| 1294 StrBuf << "Reference to basic block " << Index | 1344 StrBuf << "Reference to basic block " << Index |
| 1295 << " not found. Must be less than " << Nodes.size(); | 1345 << " not found. Must be less than " << Nodes.size(); |
| 1296 Error(StrBuf.str()); | 1346 Error(StrBuf.str()); |
| 1297 // TODO(kschimpf) Remove error recovery once implementation complete. | 1347 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 1298 Index = 0; | 1348 Index = 0; |
| 1299 } | 1349 } |
| 1300 return Nodes[Index]; | 1350 return Nodes[Index]; |
| 1301 } | 1351 } |
| 1302 | 1352 |
| 1303 // Returns the Index-th basic block in the list of basic blocks. | 1353 // Returns the Index-th basic block in the list of basic blocks. |
| 1304 // Assumes Index corresponds to a branch instruction. Hence, if | 1354 // Assumes Index corresponds to a branch instruction. Hence, if |
| 1305 // the branch references the entry block, it also generates a | 1355 // the branch references the entry block, it also generates a |
| 1306 // corresponding error. | 1356 // corresponding error. |
| 1307 Ice::CfgNode *getBranchBasicBlock(uint32_t Index) { | 1357 Ice::CfgNode *getBranchBasicBlock(NaClBcIndexSize_t Index) { |
| 1308 assert(!isIRGenerationDisabled()); | 1358 assert(!isIRGenerationDisabled()); |
| 1309 if (Index == 0) { | 1359 if (Index == 0) { |
| 1310 Error("Branch to entry block not allowed"); | 1360 Error("Branch to entry block not allowed"); |
| 1311 // TODO(kschimpf) Remove error recovery once implementation complete. | 1361 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 1312 } | 1362 } |
| 1313 return getBasicBlock(Index); | 1363 return getBasicBlock(Index); |
| 1314 } | 1364 } |
| 1315 | 1365 |
| 1316 // Generate an instruction variable with type Ty. | 1366 // Generate an instruction variable with type Ty. |
| 1317 Ice::Variable *createInstVar(Ice::Type Ty) { | 1367 Ice::Variable *createInstVar(Ice::Type Ty) { |
| 1318 assert(!isIRGenerationDisabled()); | 1368 assert(!isIRGenerationDisabled()); |
| 1319 if (Ty == Ice::IceType_void) { | 1369 if (Ty == Ice::IceType_void) { |
| 1320 Error("Can't define instruction value using type void"); | 1370 Error("Can't define instruction value using type void"); |
| 1321 // Recover since we can't throw an exception. | 1371 // Recover since we can't throw an exception. |
| 1322 Ty = Ice::IceType_i32; | 1372 Ty = Ice::IceType_i32; |
| 1323 } | 1373 } |
| 1324 return Func->makeVariable(Ty); | 1374 return Func->makeVariable(Ty); |
| 1325 } | 1375 } |
| 1326 | 1376 |
| 1327 // Generates the next available local variable using the given type. | 1377 // Generates the next available local variable using the given type. |
| 1328 Ice::Variable *getNextInstVar(Ice::Type Ty) { | 1378 Ice::Variable *getNextInstVar(Ice::Type Ty) { |
| 1329 assert(!isIRGenerationDisabled()); | 1379 assert(!isIRGenerationDisabled()); |
| 1330 assert(NextLocalInstIndex >= CachedNumGlobalValueIDs); | 1380 assert(NextLocalInstIndex >= CachedNumGlobalValueIDs); |
| 1331 // Before creating one, see if a forwardtyperef has already defined it. | 1381 // Before creating one, see if a forwardtyperef has already defined it. |
| 1332 uint32_t LocalIndex = NextLocalInstIndex - CachedNumGlobalValueIDs; | 1382 NaClBcIndexSize_t LocalIndex = NextLocalInstIndex - CachedNumGlobalValueIDs; |
| 1333 if (LocalIndex < LocalOperands.size()) { | 1383 if (LocalIndex < LocalOperands.size()) { |
| 1334 Ice::Operand *Op = LocalOperands[LocalIndex]; | 1384 Ice::Operand *Op = LocalOperands[LocalIndex]; |
| 1335 if (Op != nullptr) { | 1385 if (Op != nullptr) { |
| 1336 if (Ice::Variable *Var = dyn_cast<Ice::Variable>(Op)) { | 1386 if (Ice::Variable *Var = dyn_cast<Ice::Variable>(Op)) { |
| 1337 if (Var->getType() == Ty) { | 1387 if (Var->getType() == Ty) { |
| 1338 ++NextLocalInstIndex; | 1388 ++NextLocalInstIndex; |
| 1339 return Var; | 1389 return Var; |
| 1340 } | 1390 } |
| 1341 } | 1391 } |
| 1342 std::string Buffer; | 1392 std::string Buffer; |
| 1343 raw_string_ostream StrBuf(Buffer); | 1393 raw_string_ostream StrBuf(Buffer); |
| 1344 StrBuf << "Illegal forward referenced instruction (" | 1394 StrBuf << "Illegal forward referenced instruction (" |
| 1345 << NextLocalInstIndex << "): " << *Op; | 1395 << NextLocalInstIndex << "): " << *Op; |
| 1346 Error(StrBuf.str()); | 1396 Error(StrBuf.str()); |
| 1347 // TODO(kschimpf) Remove error recovery once implementation complete. | 1397 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 1348 ++NextLocalInstIndex; | 1398 ++NextLocalInstIndex; |
| 1349 return createInstVar(Ty); | 1399 return createInstVar(Ty); |
| 1350 } | 1400 } |
| 1351 } | 1401 } |
| 1352 Ice::Variable *Var = createInstVar(Ty); | 1402 Ice::Variable *Var = createInstVar(Ty); |
| 1353 setOperand(NextLocalInstIndex++, Var); | 1403 setOperand(NextLocalInstIndex++, Var); |
| 1354 return Var; | 1404 return Var; |
| 1355 } | 1405 } |
| 1356 | 1406 |
| 1357 // Converts a relative index (wrt to BaseIndex) to an absolute value | 1407 // Converts a relative index (wrt to BaseIndex) to an absolute value |
| 1358 // index. | 1408 // index. |
| 1359 uint32_t convertRelativeToAbsIndex(int32_t Id, int32_t BaseIndex) { | 1409 NaClBcIndexSize_t convertRelativeToAbsIndex(NaClRelBcIndexSize_t Id, |
| 1410 NaClRelBcIndexSize_t BaseIndex) { | |
| 1360 if (BaseIndex < Id) { | 1411 if (BaseIndex < Id) { |
| 1361 std::string Buffer; | 1412 std::string Buffer; |
| 1362 raw_string_ostream StrBuf(Buffer); | 1413 raw_string_ostream StrBuf(Buffer); |
| 1363 StrBuf << "Invalid relative value id: " << Id | 1414 StrBuf << "Invalid relative value id: " << Id |
| 1364 << " (must be <= " << BaseIndex << ")"; | 1415 << " (must be <= " << BaseIndex << ")"; |
| 1365 Error(StrBuf.str()); | 1416 Error(StrBuf.str()); |
| 1366 // TODO(kschimpf) Remove error recovery once implementation complete. | 1417 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 1367 return 0; | 1418 return 0; |
| 1368 } | 1419 } |
| 1369 return BaseIndex - Id; | 1420 return BaseIndex - Id; |
| 1370 } | 1421 } |
| 1371 | 1422 |
| 1372 // Sets element Index (in the local operands list) to Op. | 1423 // Sets element Index (in the local operands list) to Op. |
| 1373 void setOperand(uint32_t Index, Ice::Operand *Op) { | 1424 void setOperand(NaClBcIndexSize_t Index, Ice::Operand *Op) { |
| 1374 assert(Op || isIRGenerationDisabled()); | 1425 assert(Op || isIRGenerationDisabled()); |
| 1375 // Check if simple push works. | 1426 // Check if simple push works. |
| 1376 uint32_t LocalIndex = Index - CachedNumGlobalValueIDs; | 1427 NaClBcIndexSize_t LocalIndex = Index - CachedNumGlobalValueIDs; |
| 1377 if (LocalIndex == LocalOperands.size()) { | 1428 if (LocalIndex == LocalOperands.size()) { |
| 1378 LocalOperands.push_back(Op); | 1429 LocalOperands.push_back(Op); |
| 1379 return; | 1430 return; |
| 1380 } | 1431 } |
| 1381 | 1432 |
| 1382 // Must be forward reference, expand vector to accommodate. | 1433 // Must be forward reference, expand vector to accommodate. |
| 1383 if (LocalIndex >= LocalOperands.size()) | 1434 if (LocalIndex >= LocalOperands.size()) |
| 1384 LocalOperands.resize(LocalIndex + 1); | 1435 LocalOperands.resize(LocalIndex + 1); |
| 1385 | 1436 |
| 1386 // If element not defined, set it. | 1437 // If element not defined, set it. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1399 raw_string_ostream StrBuf(Buffer); | 1450 raw_string_ostream StrBuf(Buffer); |
| 1400 StrBuf << "Multiple definitions for index " << Index << ": " << *Op | 1451 StrBuf << "Multiple definitions for index " << Index << ": " << *Op |
| 1401 << " and " << *OldOp; | 1452 << " and " << *OldOp; |
| 1402 Error(StrBuf.str()); | 1453 Error(StrBuf.str()); |
| 1403 // TODO(kschimpf) Remove error recovery once implementation complete. | 1454 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 1404 LocalOperands[LocalIndex] = Op; | 1455 LocalOperands[LocalIndex] = Op; |
| 1405 } | 1456 } |
| 1406 | 1457 |
| 1407 // Returns the relative operand (wrt to BaseIndex) referenced by | 1458 // Returns the relative operand (wrt to BaseIndex) referenced by |
| 1408 // the given value Index. | 1459 // the given value Index. |
| 1409 Ice::Operand *getRelativeOperand(int32_t Index, int32_t BaseIndex) { | 1460 Ice::Operand *getRelativeOperand(NaClBcIndexSize_t Index, |
| 1461 NaClBcIndexSize_t BaseIndex) { | |
| 1410 return getOperand(convertRelativeToAbsIndex(Index, BaseIndex)); | 1462 return getOperand(convertRelativeToAbsIndex(Index, BaseIndex)); |
| 1411 } | 1463 } |
| 1412 | 1464 |
| 1413 // Returns the absolute index of the next value generating instruction. | 1465 // Returns the absolute index of the next value generating instruction. |
| 1414 uint32_t getNextInstIndex() const { return NextLocalInstIndex; } | 1466 NaClBcIndexSize_t getNextInstIndex() const { return NextLocalInstIndex; } |
| 1415 | 1467 |
| 1416 // Generates type error message for binary operator Op | 1468 // Generates type error message for binary operator Op |
| 1417 // operating on Type OpTy. | 1469 // operating on Type OpTy. |
| 1418 void ReportInvalidBinaryOp(Ice::InstArithmetic::OpKind Op, Ice::Type OpTy); | 1470 void ReportInvalidBinaryOp(Ice::InstArithmetic::OpKind Op, Ice::Type OpTy); |
|
Jim Stichnoth
2015/06/21 00:33:42
reportInvalidBinaryOp
?
Karl
2015/06/22 22:10:04
Done.
| |
| 1419 | 1471 |
| 1420 // Validates if integer logical Op, for type OpTy, is valid. | 1472 // Validates if integer logical Op, for type OpTy, is valid. |
| 1421 // Returns true if valid. Otherwise generates error message and | 1473 // Returns true if valid. Otherwise generates error message and |
| 1422 // returns false. | 1474 // returns false. |
| 1423 bool isValidIntegerLogicalOp(Ice::InstArithmetic::OpKind Op, Ice::Type OpTy) { | 1475 bool isValidIntegerLogicalOp(Ice::InstArithmetic::OpKind Op, Ice::Type OpTy) { |
| 1424 if (Ice::isIntegerType(OpTy)) | 1476 if (Ice::isIntegerType(OpTy)) |
| 1425 return true; | 1477 return true; |
| 1426 ReportInvalidBinaryOp(Op, OpTy); | 1478 ReportInvalidBinaryOp(Op, OpTy); |
| 1427 return false; | 1479 return false; |
| 1428 } | 1480 } |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1903 CurrentNode->appendInst(Ice::InstAssign::create(Func.get(), Var, Var)); | 1955 CurrentNode->appendInst(Ice::InstAssign::create(Func.get(), Var, Var)); |
| 1904 } | 1956 } |
| 1905 }; | 1957 }; |
| 1906 | 1958 |
| 1907 void FunctionParser::ExitBlock() { | 1959 void FunctionParser::ExitBlock() { |
| 1908 if (isIRGenerationDisabled()) { | 1960 if (isIRGenerationDisabled()) { |
| 1909 return; | 1961 return; |
| 1910 } | 1962 } |
| 1911 // Before translating, check for blocks without instructions, and | 1963 // Before translating, check for blocks without instructions, and |
| 1912 // insert unreachable. This shouldn't happen, but be safe. | 1964 // insert unreachable. This shouldn't happen, but be safe. |
| 1913 unsigned Index = 0; | 1965 size_t Index = 0; |
| 1914 for (Ice::CfgNode *Node : Func->getNodes()) { | 1966 for (Ice::CfgNode *Node : Func->getNodes()) { |
| 1915 if (Node->getInsts().empty()) { | 1967 if (Node->getInsts().empty()) { |
| 1916 std::string Buffer; | 1968 std::string Buffer; |
| 1917 raw_string_ostream StrBuf(Buffer); | 1969 raw_string_ostream StrBuf(Buffer); |
| 1918 StrBuf << "Basic block " << Index << " contains no instructions"; | 1970 StrBuf << "Basic block " << Index << " contains no instructions"; |
| 1919 Error(StrBuf.str()); | 1971 Error(StrBuf.str()); |
| 1920 // TODO(kschimpf) Remove error recovery once implementation complete. | 1972 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 1921 Node->appendInst(Ice::InstUnreachable::create(Func.get())); | 1973 Node->appendInst(Ice::InstUnreachable::create(Func.get())); |
| 1922 } | 1974 } |
| 1923 ++Index; | 1975 ++Index; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1939 // is disabled we do the following: | 1991 // is disabled we do the following: |
| 1940 // 1) Delay exiting until after we extract operands. | 1992 // 1) Delay exiting until after we extract operands. |
| 1941 // 2) return before we access operands, since all operands will be a nullptr. | 1993 // 2) return before we access operands, since all operands will be a nullptr. |
| 1942 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 1994 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 1943 if (InstIsTerminating) { | 1995 if (InstIsTerminating) { |
| 1944 InstIsTerminating = false; | 1996 InstIsTerminating = false; |
| 1945 if (!isIRGenerationDisabled()) | 1997 if (!isIRGenerationDisabled()) |
| 1946 CurrentNode = getBasicBlock(++CurrentBbIndex); | 1998 CurrentNode = getBasicBlock(++CurrentBbIndex); |
| 1947 } | 1999 } |
| 1948 // The base index for relative indexing. | 2000 // The base index for relative indexing. |
| 1949 int32_t BaseIndex = getNextInstIndex(); | 2001 NaClBcIndexSize_t BaseIndex = getNextInstIndex(); |
| 1950 switch (Record.GetCode()) { | 2002 switch (Record.GetCode()) { |
| 1951 case naclbitc::FUNC_CODE_DECLAREBLOCKS: { | 2003 case naclbitc::FUNC_CODE_DECLAREBLOCKS: { |
| 1952 // DECLAREBLOCKS: [n] | 2004 // DECLAREBLOCKS: [n] |
| 1953 if (!isValidRecordSize(1, "count")) | 2005 if (!isValidRecordSize(1, "count")) |
| 1954 return; | 2006 return; |
| 1955 uint32_t NumBbs = Values[0]; | 2007 uint64_t NumBbsRaw = Values[0]; |
| 1956 if (NumBbs == 0) { | 2008 if (NumBbsRaw == 0) { |
| 1957 Error("Functions must contain at least one basic block."); | 2009 Error("Functions must contain at least one basic block."); |
| 1958 // TODO(kschimpf) Remove error recovery once implementation complete. | 2010 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 1959 NumBbs = 1; | 2011 NumBbsRaw = 1; |
| 2012 } else if (NumBbsRaw > NaClBcIndexSize_t_Max) { | |
| 2013 std::string Buffer; | |
| 2014 raw_string_ostream StrBuf(Buffer); | |
| 2015 StrBuf << "To many basic blocks specified: " << NumBbsRaw; | |
| 2016 Error(StrBuf.str()); | |
| 2017 NumBbsRaw = NaClBcIndexSize_t_Max; | |
| 1960 } | 2018 } |
| 1961 if (isIRGenerationDisabled()) | 2019 if (isIRGenerationDisabled()) |
| 1962 return; | 2020 return; |
| 1963 if (Func->getNodes().size() != 1) { | 2021 if (Func->getNodes().size() != 1) { |
| 1964 Error("Duplicate function block count record"); | 2022 Error("Duplicate function block count record"); |
| 1965 return; | 2023 return; |
| 1966 } | 2024 } |
| 1967 // Install the basic blocks, skipping bb0 which was created in the | 2025 // Install the basic blocks, skipping bb0 which was created in the |
| 1968 // constructor. | 2026 // constructor. |
| 1969 for (size_t i = 1; i < NumBbs; ++i) | 2027 for (size_t i = 1, NumBbs = NumBbsRaw; i < NumBbs; ++i) |
| 1970 InstallNextBasicBlock(); | 2028 InstallNextBasicBlock(); |
| 1971 return; | 2029 return; |
| 1972 } | 2030 } |
| 1973 case naclbitc::FUNC_CODE_INST_BINOP: { | 2031 case naclbitc::FUNC_CODE_INST_BINOP: { |
| 1974 // BINOP: [opval, opval, opcode] | 2032 // BINOP: [opval, opval, opcode] |
| 1975 if (!isValidRecordSize(3, "binop")) | 2033 if (!isValidRecordSize(3, "binop")) |
| 1976 return; | 2034 return; |
| 1977 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); | 2035 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); |
| 1978 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); | 2036 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); |
| 1979 if (isIRGenerationDisabled()) { | 2037 if (isIRGenerationDisabled()) { |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2276 } else if (CondTy != Cond->getType()) { | 2334 } else if (CondTy != Cond->getType()) { |
| 2277 std::string Buffer; | 2335 std::string Buffer; |
| 2278 raw_string_ostream StrBuf(Buffer); | 2336 raw_string_ostream StrBuf(Buffer); |
| 2279 StrBuf << "Case condition expects type " << CondTy | 2337 StrBuf << "Case condition expects type " << CondTy |
| 2280 << ". Found: " << Cond->getType(); | 2338 << ". Found: " << Cond->getType(); |
| 2281 Error(StrBuf.str()); | 2339 Error(StrBuf.str()); |
| 2282 return; | 2340 return; |
| 2283 } | 2341 } |
| 2284 Ice::CfgNode *DefaultLabel = | 2342 Ice::CfgNode *DefaultLabel = |
| 2285 isIRGenDisabled ? nullptr : getBranchBasicBlock(Values[2]); | 2343 isIRGenDisabled ? nullptr : getBranchBasicBlock(Values[2]); |
| 2286 unsigned NumCases = Values[3]; | 2344 uint64_t NumCasesRaw = Values[3]; |
| 2345 if (NumCasesRaw > std::numeric_limits<uint32_t>::max()) { | |
| 2346 std::string Buffer; | |
| 2347 raw_string_ostream StrBuf(Buffer); | |
| 2348 StrBuf << "Too many cases specified in switch: " << NumCasesRaw; | |
| 2349 Error(StrBuf.str()); | |
| 2350 NumCasesRaw = std::numeric_limits<uint32_t>::max(); | |
| 2351 } | |
| 2352 uint32_t NumCases = NumCasesRaw; | |
| 2287 | 2353 |
| 2288 // Now recognize each of the cases. | 2354 // Now recognize each of the cases. |
| 2289 if (!isValidRecordSize(4 + NumCases * 4, "switch")) | 2355 if (!isValidRecordSize(4 + NumCases * 4, "switch")) |
| 2290 return; | 2356 return; |
| 2291 Ice::InstSwitch *Switch = | 2357 Ice::InstSwitch *Switch = |
| 2292 isIRGenDisabled | 2358 isIRGenDisabled |
| 2293 ? nullptr | 2359 ? nullptr |
| 2294 : Ice::InstSwitch::create(Func.get(), NumCases, Cond, DefaultLabel); | 2360 : Ice::InstSwitch::create(Func.get(), NumCases, Cond, DefaultLabel); |
| 2295 unsigned ValCaseIndex = 4; // index to beginning of case entry. | 2361 unsigned ValCaseIndex = 4; // index to beginning of case entry. |
| 2296 for (unsigned CaseIndex = 0; CaseIndex < NumCases; | 2362 for (uint32_t CaseIndex = 0; CaseIndex < NumCases; |
| 2297 ++CaseIndex, ValCaseIndex += 4) { | 2363 ++CaseIndex, ValCaseIndex += 4) { |
| 2298 if (Values[ValCaseIndex] != 1 || Values[ValCaseIndex + 1] != 1) { | 2364 if (Values[ValCaseIndex] != 1 || Values[ValCaseIndex + 1] != 1) { |
| 2299 std::string Buffer; | 2365 std::string Buffer; |
| 2300 raw_string_ostream StrBuf(Buffer); | 2366 raw_string_ostream StrBuf(Buffer); |
| 2301 StrBuf << "Sequence [1, 1, value, label] expected for case entry " | 2367 StrBuf << "Sequence [1, 1, value, label] expected for case entry " |
| 2302 << "in switch record. (at index" << ValCaseIndex << ")"; | 2368 << "in switch record. (at index" << ValCaseIndex << ")"; |
| 2303 Error(StrBuf.str()); | 2369 Error(StrBuf.str()); |
| 2304 return; | 2370 return; |
| 2305 } | 2371 } |
| 2306 Ice::APInt Value(BitWidth, | 2372 Ice::APInt Value(BitWidth, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2349 for (unsigned i = 1; i < Values.size(); i += 2) { | 2415 for (unsigned i = 1; i < Values.size(); i += 2) { |
| 2350 assert(getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), | 2416 assert(getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), |
| 2351 BaseIndex) == nullptr); | 2417 BaseIndex) == nullptr); |
| 2352 } | 2418 } |
| 2353 setNextLocalInstIndex(nullptr); | 2419 setNextLocalInstIndex(nullptr); |
| 2354 return; | 2420 return; |
| 2355 } | 2421 } |
| 2356 Ice::Variable *Dest = getNextInstVar(Ty); | 2422 Ice::Variable *Dest = getNextInstVar(Ty); |
| 2357 Ice::InstPhi *Phi = | 2423 Ice::InstPhi *Phi = |
| 2358 Ice::InstPhi::create(Func.get(), Values.size() >> 1, Dest); | 2424 Ice::InstPhi::create(Func.get(), Values.size() >> 1, Dest); |
| 2359 for (unsigned i = 1; i < Values.size(); i += 2) { | 2425 for (size_t i = 1; i < Values.size(); i += 2) { |
| 2360 Ice::Operand *Op = | 2426 Ice::Operand *Op = |
| 2361 getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), BaseIndex); | 2427 getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), BaseIndex); |
| 2362 if (Op->getType() != Ty) { | 2428 if (Op->getType() != Ty) { |
| 2363 std::string Buffer; | 2429 std::string Buffer; |
| 2364 raw_string_ostream StrBuf(Buffer); | 2430 raw_string_ostream StrBuf(Buffer); |
| 2365 StrBuf << "Value " << *Op << " not type " << Ty | 2431 StrBuf << "Value " << *Op << " not type " << Ty |
| 2366 << " in phi instruction. Found: " << Op->getType(); | 2432 << " in phi instruction. Found: " << Op->getType(); |
| 2367 Error(StrBuf.str()); | 2433 Error(StrBuf.str()); |
| 2368 appendErrorInstruction(Ty); | 2434 appendErrorInstruction(Ty); |
| 2369 return; | 2435 return; |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2737 Timer(Ice::TimerStack::TT_parseFunctionValuesymtabs, | 2803 Timer(Ice::TimerStack::TT_parseFunctionValuesymtabs, |
| 2738 getTranslator().getContext()) {} | 2804 getTranslator().getContext()) {} |
| 2739 | 2805 |
| 2740 private: | 2806 private: |
| 2741 Ice::TimerMarker Timer; | 2807 Ice::TimerMarker Timer; |
| 2742 // Returns the enclosing function parser. | 2808 // Returns the enclosing function parser. |
| 2743 FunctionParser *getFunctionParser() const { | 2809 FunctionParser *getFunctionParser() const { |
| 2744 return reinterpret_cast<FunctionParser *>(GetEnclosingParser()); | 2810 return reinterpret_cast<FunctionParser *>(GetEnclosingParser()); |
| 2745 } | 2811 } |
| 2746 | 2812 |
| 2747 void setValueName(uint64_t Index, StringType &Name) override; | 2813 void setValueName(NaClBcIndexSize_t Index, StringType &Name) override; |
| 2748 void setBbName(uint64_t Index, StringType &Name) override; | 2814 void setBbName(NaClBcIndexSize_t Index, StringType &Name) override; |
| 2749 | 2815 |
| 2750 // Reports that the assignment of Name to the value associated with | 2816 // Reports that the assignment of Name to the value associated with |
| 2751 // index is not possible, for the given Context. | 2817 // index is not possible, for the given Context. |
| 2752 void reportUnableToAssign(const char *Context, uint64_t Index, | 2818 void reportUnableToAssign(const char *Context, NaClBcIndexSize_t Index, |
| 2753 StringType &Name) { | 2819 StringType &Name) { |
| 2754 std::string Buffer; | 2820 std::string Buffer; |
| 2755 raw_string_ostream StrBuf(Buffer); | 2821 raw_string_ostream StrBuf(Buffer); |
| 2756 StrBuf << "Function-local " << Context << " name '" << Name | 2822 StrBuf << "Function-local " << Context << " name '" << Name |
| 2757 << "' can't be associated with index " << Index; | 2823 << "' can't be associated with index " << Index; |
| 2758 Error(StrBuf.str()); | 2824 Error(StrBuf.str()); |
| 2759 } | 2825 } |
| 2760 }; | 2826 }; |
| 2761 | 2827 |
| 2762 void FunctionValuesymtabParser::setValueName(uint64_t Index, StringType &Name) { | 2828 void FunctionValuesymtabParser::setValueName(NaClBcIndexSize_t Index, |
| 2829 StringType &Name) { | |
| 2763 // Note: We check when Index is too small, so that we can error recover | 2830 // Note: We check when Index is too small, so that we can error recover |
| 2764 // (FP->getOperand will create fatal error). | 2831 // (FP->getOperand will create fatal error). |
| 2765 if (Index < getFunctionParser()->getNumGlobalIDs()) { | 2832 if (Index < getFunctionParser()->getNumGlobalIDs()) { |
| 2766 reportUnableToAssign("instruction", Index, Name); | 2833 reportUnableToAssign("instruction", Index, Name); |
| 2767 // TODO(kschimpf) Remove error recovery once implementation complete. | 2834 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 2768 return; | 2835 return; |
| 2769 } | 2836 } |
| 2770 if (isIRGenerationDisabled()) | 2837 if (isIRGenerationDisabled()) |
| 2771 return; | 2838 return; |
| 2772 Ice::Operand *Op = getFunctionParser()->getOperand(Index); | 2839 Ice::Operand *Op = getFunctionParser()->getOperand(Index); |
| 2773 if (Ice::Variable *V = dyn_cast<Ice::Variable>(Op)) { | 2840 if (Ice::Variable *V = dyn_cast<Ice::Variable>(Op)) { |
| 2774 if (ALLOW_DUMP) { | 2841 if (ALLOW_DUMP) { |
| 2775 std::string Nm(Name.data(), Name.size()); | 2842 std::string Nm(Name.data(), Name.size()); |
| 2776 V->setName(getFunctionParser()->getFunc(), Nm); | 2843 V->setName(getFunctionParser()->getFunc(), Nm); |
| 2777 } | 2844 } |
| 2778 } else { | 2845 } else { |
| 2779 reportUnableToAssign("variable", Index, Name); | 2846 reportUnableToAssign("variable", Index, Name); |
| 2780 } | 2847 } |
| 2781 } | 2848 } |
| 2782 | 2849 |
| 2783 void FunctionValuesymtabParser::setBbName(uint64_t Index, StringType &Name) { | 2850 void FunctionValuesymtabParser::setBbName(NaClBcIndexSize_t Index, |
| 2851 StringType &Name) { | |
| 2784 if (isIRGenerationDisabled()) | 2852 if (isIRGenerationDisabled()) |
| 2785 return; | 2853 return; |
| 2786 if (Index >= getFunctionParser()->getFunc()->getNumNodes()) { | 2854 if (Index >= getFunctionParser()->getFunc()->getNumNodes()) { |
| 2787 reportUnableToAssign("block", Index, Name); | 2855 reportUnableToAssign("block", Index, Name); |
| 2788 return; | 2856 return; |
| 2789 } | 2857 } |
| 2790 std::string Nm(Name.data(), Name.size()); | 2858 std::string Nm(Name.data(), Name.size()); |
| 2791 if (ALLOW_DUMP) | 2859 if (ALLOW_DUMP) |
| 2792 getFunctionParser()->getFunc()->getNodes()[Index]->setName(Nm); | 2860 getFunctionParser()->getFunc()->getNodes()[Index]->setName(Nm); |
| 2793 } | 2861 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2831 private: | 2899 private: |
| 2832 Ice::TimerMarker Timer; | 2900 Ice::TimerMarker Timer; |
| 2833 // True if we have already installed names for unnamed global declarations, | 2901 // True if we have already installed names for unnamed global declarations, |
| 2834 // and have generated global constant initializers. | 2902 // and have generated global constant initializers. |
| 2835 bool GlobalDeclarationNamesAndInitializersInstalled; | 2903 bool GlobalDeclarationNamesAndInitializersInstalled; |
| 2836 | 2904 |
| 2837 // Generates names for unnamed global addresses (i.e. functions and | 2905 // Generates names for unnamed global addresses (i.e. functions and |
| 2838 // global variables). Then lowers global variable declaration | 2906 // global variables). Then lowers global variable declaration |
| 2839 // initializers to the target. May be called multiple times. Only | 2907 // initializers to the target. May be called multiple times. Only |
| 2840 // the first call will do the installation. | 2908 // the first call will do the installation. |
| 2841 void InstallGlobalNamesAndGlobalVarInitializers() { | 2909 void InstallGlobalNamesAndGlobalVarInitializers() { |
|
Jim Stichnoth
2015/06/21 00:33:42
installGlobalNamesAndGlobalVarInitializers
?
Karl
2015/06/22 22:10:03
Done, all all other capitalization cases I could f
| |
| 2842 if (!GlobalDeclarationNamesAndInitializersInstalled) { | 2910 if (!GlobalDeclarationNamesAndInitializersInstalled) { |
| 2843 Context->installGlobalNames(); | 2911 Context->installGlobalNames(); |
| 2844 Context->createValueIDs(); | 2912 Context->createValueIDs(); |
| 2845 getTranslator().lowerGlobals(Context->getGlobalVariables()); | 2913 getTranslator().lowerGlobals(Context->getGlobalVariables()); |
| 2846 GlobalDeclarationNamesAndInitializersInstalled = true; | 2914 GlobalDeclarationNamesAndInitializersInstalled = true; |
| 2847 } | 2915 } |
| 2848 } | 2916 } |
| 2849 bool ParseBlock(unsigned BlockID) override; | 2917 bool ParseBlock(unsigned BlockID) override; |
| 2850 | 2918 |
| 2851 void ExitBlock() override { InstallGlobalNamesAndGlobalVarInitializers(); } | 2919 void ExitBlock() override { InstallGlobalNamesAndGlobalVarInitializers(); } |
| 2852 | 2920 |
| 2853 void ProcessRecord() override; | 2921 void ProcessRecord() override; |
| 2854 }; | 2922 }; |
| 2855 | 2923 |
| 2856 class ModuleValuesymtabParser : public ValuesymtabParser { | 2924 class ModuleValuesymtabParser : public ValuesymtabParser { |
| 2857 ModuleValuesymtabParser() = delete; | 2925 ModuleValuesymtabParser() = delete; |
| 2858 ModuleValuesymtabParser(const ModuleValuesymtabParser &) = delete; | 2926 ModuleValuesymtabParser(const ModuleValuesymtabParser &) = delete; |
| 2859 void operator=(const ModuleValuesymtabParser &) = delete; | 2927 void operator=(const ModuleValuesymtabParser &) = delete; |
| 2860 | 2928 |
| 2861 public: | 2929 public: |
| 2862 ModuleValuesymtabParser(unsigned BlockID, ModuleParser *MP) | 2930 ModuleValuesymtabParser(unsigned BlockID, ModuleParser *MP) |
| 2863 : ValuesymtabParser(BlockID, MP), | 2931 : ValuesymtabParser(BlockID, MP), |
| 2864 Timer(Ice::TimerStack::TT_parseModuleValuesymtabs, | 2932 Timer(Ice::TimerStack::TT_parseModuleValuesymtabs, |
| 2865 getTranslator().getContext()) {} | 2933 getTranslator().getContext()) {} |
| 2866 | 2934 |
| 2867 ~ModuleValuesymtabParser() override {} | 2935 ~ModuleValuesymtabParser() override {} |
| 2868 | 2936 |
| 2869 private: | 2937 private: |
| 2870 Ice::TimerMarker Timer; | 2938 Ice::TimerMarker Timer; |
| 2871 void setValueName(uint64_t Index, StringType &Name) override; | 2939 void setValueName(NaClBcIndexSize_t Index, StringType &Name) override; |
| 2872 void setBbName(uint64_t Index, StringType &Name) override; | 2940 void setBbName(NaClBcIndexSize_t Index, StringType &Name) override; |
| 2873 }; | 2941 }; |
| 2874 | 2942 |
| 2875 void ModuleValuesymtabParser::setValueName(uint64_t Index, StringType &Name) { | 2943 void ModuleValuesymtabParser::setValueName(NaClBcIndexSize_t Index, |
| 2944 StringType &Name) { | |
| 2876 Context->getGlobalDeclarationByID(Index) | 2945 Context->getGlobalDeclarationByID(Index) |
| 2877 ->setName(StringRef(Name.data(), Name.size())); | 2946 ->setName(StringRef(Name.data(), Name.size())); |
| 2878 } | 2947 } |
| 2879 | 2948 |
| 2880 void ModuleValuesymtabParser::setBbName(uint64_t Index, StringType &Name) { | 2949 void ModuleValuesymtabParser::setBbName(NaClBcIndexSize_t Index, |
| 2950 StringType &Name) { | |
| 2881 std::string Buffer; | 2951 std::string Buffer; |
| 2882 raw_string_ostream StrBuf(Buffer); | 2952 raw_string_ostream StrBuf(Buffer); |
| 2883 StrBuf << "Can't define basic block name at global level: '" << Name | 2953 StrBuf << "Can't define basic block name at global level: '" << Name |
| 2884 << "' -> " << Index; | 2954 << "' -> " << Index; |
| 2885 Error(StrBuf.str()); | 2955 Error(StrBuf.str()); |
| 2886 } | 2956 } |
| 2887 | 2957 |
| 2888 bool ModuleParser::ParseBlock(unsigned BlockID) { | 2958 bool ModuleParser::ParseBlock(unsigned BlockID) { |
| 2889 switch (BlockID) { | 2959 switch (BlockID) { |
| 2890 case naclbitc::BLOCKINFO_BLOCK_ID: | 2960 case naclbitc::BLOCKINFO_BLOCK_ID: |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2911 } | 2981 } |
| 2912 } | 2982 } |
| 2913 | 2983 |
| 2914 void ModuleParser::ProcessRecord() { | 2984 void ModuleParser::ProcessRecord() { |
| 2915 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 2985 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 2916 switch (Record.GetCode()) { | 2986 switch (Record.GetCode()) { |
| 2917 case naclbitc::MODULE_CODE_VERSION: { | 2987 case naclbitc::MODULE_CODE_VERSION: { |
| 2918 // VERSION: [version#] | 2988 // VERSION: [version#] |
| 2919 if (!isValidRecordSize(1, "version")) | 2989 if (!isValidRecordSize(1, "version")) |
| 2920 return; | 2990 return; |
| 2921 unsigned Version = Values[0]; | 2991 uint64_t Version = Values[0]; |
| 2922 if (Version != 1) { | 2992 if (Version != 1) { |
| 2923 std::string Buffer; | 2993 std::string Buffer; |
| 2924 raw_string_ostream StrBuf(Buffer); | 2994 raw_string_ostream StrBuf(Buffer); |
| 2925 StrBuf << "Unknown bitstream version: " << Version; | 2995 StrBuf << "Unknown bitstream version: " << Version; |
| 2926 Error(StrBuf.str()); | 2996 Error(StrBuf.str()); |
| 2927 } | 2997 } |
| 2928 return; | 2998 return; |
| 2929 } | 2999 } |
| 2930 case naclbitc::MODULE_CODE_FUNCTION: { | 3000 case naclbitc::MODULE_CODE_FUNCTION: { |
| 2931 // FUNCTION: [type, callingconv, isproto, linkage] | 3001 // FUNCTION: [type, callingconv, isproto, linkage] |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3026 } | 3096 } |
| 3027 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { | 3097 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { |
| 3028 ErrStream | 3098 ErrStream |
| 3029 << IRFilename | 3099 << IRFilename |
| 3030 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; | 3100 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; |
| 3031 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); | 3101 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); |
| 3032 } | 3102 } |
| 3033 } | 3103 } |
| 3034 | 3104 |
| 3035 } // end of namespace Ice | 3105 } // end of namespace Ice |
| OLD | NEW |