[llvm-commits] CVS: llvm/lib/Bytecode/Analyzer/Parser.cpp Parser.h
LLVM
llvm at cs.uiuc.edu
Thu Jun 10 17:05:03 PDT 2004
Changes in directory llvm/lib/Bytecode/Analyzer:
Parser.cpp updated: 1.4 -> 1.5
Parser.h updated: 1.3 -> 1.4
---
Log message:
Make the parser deal with functions instead of just function types.
---
Diffs of the changes: (+42 -38)
Index: llvm/lib/Bytecode/Analyzer/Parser.cpp
diff -u llvm/lib/Bytecode/Analyzer/Parser.cpp:1.4 llvm/lib/Bytecode/Analyzer/Parser.cpp:1.5
--- llvm/lib/Bytecode/Analyzer/Parser.cpp:1.4 Thu Jun 10 03:09:13 2004
+++ llvm/lib/Bytecode/Analyzer/Parser.cpp Thu Jun 10 16:59:20 2004
@@ -312,37 +312,51 @@
if (FunctionSignatureList.empty())
throw std::string("FunctionSignatureList empty!");
- const Type *FType = FunctionSignatureList.back();
+ Function *Func = FunctionSignatureList.back();
FunctionSignatureList.pop_back();
// Save the information for future reading of the function
- LazyFunctionLoadMap[FType] = LazyFunctionInfo(BlockStart, BlockEnd);
+ LazyFunctionLoadMap[Func] = LazyFunctionInfo(BlockStart, BlockEnd);
// Pretend we've `parsed' this function
At = BlockEnd;
}
-void AbstractBytecodeParser::ParseNextFunction(Type* FType) {
+void AbstractBytecodeParser::ParseNextFunction(Function* Func) {
// Find {start, end} pointers and slot in the map. If not there, we're done.
- LazyFunctionMap::iterator Fi = LazyFunctionLoadMap.find(FType);
+ LazyFunctionMap::iterator Fi = LazyFunctionLoadMap.find(Func);
// Make sure we found it
if ( Fi == LazyFunctionLoadMap.end() ) {
- PARSE_ERROR("Unrecognized function of type " << FType->getDescription());
+ PARSE_ERROR("Unrecognized function of type " << Func->getType()->getDescription());
return;
}
BlockStart = At = Fi->second.Buf;
BlockEnd = Fi->second.Buf;
- assert(Fi->first == FType);
+ assert(Fi->first == Func);
LazyFunctionLoadMap.erase(Fi);
- this->ParseFunctionBody( FType );
+ this->ParseFunctionBody( Func );
}
-void AbstractBytecodeParser::ParseFunctionBody(const Type* FType ) {
+void AbstractBytecodeParser::ParseAllFunctionBodies() {
+ LazyFunctionMap::iterator Fi = LazyFunctionLoadMap.begin();
+ LazyFunctionMap::iterator Fe = LazyFunctionLoadMap.end();
+
+ while ( Fi != Fe ) {
+ Function* Func = Fi->first;
+ BlockStart = At = Fi->second.Buf;
+ BlockEnd = Fi->second.EndBuf;
+ this->ParseFunctionBody(Func);
+ ++Fi;
+ }
+}
+
+void AbstractBytecodeParser::ParseFunctionBody(Function* Func ) {
+ unsigned FuncSize = BlockEnd - At;
GlobalValue::LinkageTypes Linkage = GlobalValue::ExternalLinkage;
unsigned LinkageType = read_vbr_uint();
@@ -358,7 +372,8 @@
break;
}
- handler->handleFunctionBegin(FType,Linkage);
+ Func->setLinkage( Linkage );
+ handler->handleFunctionBegin(Func,FuncSize);
// Keep track of how many basic blocks we have read in...
unsigned BlockNum = 0;
@@ -405,26 +420,13 @@
align32();
}
- handler->handleFunctionEnd(FType);
+ handler->handleFunctionEnd(Func);
// Clear out function-level types...
FunctionTypes.clear();
CompactionTypeTable.clear();
}
-void AbstractBytecodeParser::ParseAllFunctionBodies() {
- LazyFunctionMap::iterator Fi = LazyFunctionLoadMap.begin();
- LazyFunctionMap::iterator Fe = LazyFunctionLoadMap.end();
-
- while ( Fi != Fe ) {
- const Type* FType = Fi->first;
- BlockStart = At = Fi->second.Buf;
- BlockEnd = Fi->second.EndBuf;
- this->ParseFunctionBody(FType);
- ++Fi;
- }
-}
-
void AbstractBytecodeParser::ParseCompactionTable() {
handler->handleCompactionTableBegin();
@@ -819,12 +821,14 @@
}
// We create functions by passing the underlying FunctionType to create...
- Ty = cast<PointerType>(Ty)->getElementType();
+ const FunctionType* FTy =
+ cast<FunctionType>(cast<PointerType>(Ty)->getElementType());
+ Function* Func = new Function(FTy, GlobalValue::ExternalLinkage);
// Save this for later so we know type of lazily instantiated functions
- FunctionSignatureList.push_back(Ty);
+ FunctionSignatureList.push_back(Func);
- handler->handleFunctionDeclaration(Ty);
+ handler->handleFunctionDeclaration(Func, FTy);
// Get Next function signature
FnSignature = read_vbr_uint();
@@ -1010,7 +1014,7 @@
unsigned initSlot) {}
void BytecodeHandler::handleType( const Type* Ty ) {}
void BytecodeHandler::handleFunctionDeclaration(
- const Type* FuncType) {}
+ Function* Func, const FunctionType* FuncType) {}
void BytecodeHandler::handleModuleGlobalsEnd() { }
void BytecodeHandler::handleCompactionTableBegin() { }
void BytecodeHandler::handleCompactionTablePlane( unsigned Ty,
@@ -1028,9 +1032,9 @@
void BytecodeHandler::handleSymbolTableValue( unsigned i, unsigned slot,
const std::string& name ) { }
void BytecodeHandler::handleSymbolTableEnd() { }
-void BytecodeHandler::handleFunctionBegin( const Type* FType,
- GlobalValue::LinkageTypes linkage ) { }
-void BytecodeHandler::handleFunctionEnd( const Type* FType) { }
+void BytecodeHandler::handleFunctionBegin( Function* Func,
+ unsigned Size ) {}
+void BytecodeHandler::handleFunctionEnd( Function* Func) { }
void BytecodeHandler::handleBasicBlockBegin( unsigned blocknum) { }
bool BytecodeHandler::handleInstruction( unsigned Opcode, const Type* iType,
std::vector<unsigned>& Operands, unsigned Size) {
Index: llvm/lib/Bytecode/Analyzer/Parser.h
diff -u llvm/lib/Bytecode/Analyzer/Parser.h:1.3 llvm/lib/Bytecode/Analyzer/Parser.h:1.4
--- llvm/lib/Bytecode/Analyzer/Parser.h:1.3 Thu Jun 10 03:09:13 2004
+++ llvm/lib/Bytecode/Analyzer/Parser.h Thu Jun 10 16:59:20 2004
@@ -90,7 +90,7 @@
/// @see ParseAllFunctionBodies
/// @see ParseBytecode
/// @brief Parse the next function of specific type
- void ParseNextFunction (Type* FType) ;
+ void ParseNextFunction (Function* Func) ;
/// @}
/// @name Parsing Units For Subclasses
@@ -116,7 +116,7 @@
void ParseFunctionLazily ();
/// @brief Parse a function body
- void ParseFunctionBody (const Type* FType);
+ void ParseFunctionBody (Function* Func);
/// @brief Parse a compaction table
void ParseCompactionTable ();
@@ -205,7 +205,7 @@
// for each function in the module. When the function is loaded, this type is
// used to instantiate the actual function object.
- std::vector<const Type*> FunctionSignatureList;
+ std::vector<Function*> FunctionSignatureList;
// Constant values are read in after global variables. Because of this, we
// must defer setting the initializers on global variables until after module
@@ -233,7 +233,7 @@
LazyFunctionInfo(const unsigned char *B = 0, const unsigned char *EB = 0)
: Buf(B), EndBuf(EB) {}
};
- typedef std::map<const Type*, LazyFunctionInfo> LazyFunctionMap;
+ typedef std::map<Function*, LazyFunctionInfo> LazyFunctionMap;
LazyFunctionMap LazyFunctionLoadMap;
private:
@@ -394,7 +394,8 @@
/// This method is called when the function prototype for a function is
/// encountered in the module globals block.
virtual void handleFunctionDeclaration(
- const Type* FuncType ///< The type of the function
+ Function* Func,
+ const FunctionType* FuncType ///< The type of the function
);
/// This method is called at the end of the module globals block.
@@ -458,13 +459,12 @@
/// @brief Handle the beginning of a function body
virtual void handleFunctionBegin(
- const Type* FType,
- GlobalValue::LinkageTypes linkage
+ Function* Func, unsigned Size
);
/// @brief Handle the end of a function body
virtual void handleFunctionEnd(
- const Type* FType
+ Function* Func
);
/// @brief Handle the beginning of a basic block
More information about the llvm-commits
mailing list