diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-01-06 07:24:44 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-01-06 07:24:44 +0000 |
commit | 78d033e086e19e016273de014f9214aa6f3f844b (patch) | |
tree | 3af27ec8e6611c9380be3b8ce3e643138488851c /lib/Bytecode/Reader | |
parent | f8383def5c31acfab4fd55c9fb395d417fd65c45 (diff) |
For PR411:
Take an incremental step towards type plane elimination. This change
separates types from values in the symbol tables by finally making use
of the TypeSymbolTable class. This yields more natural interfaces for
dealing with types and unclutters the SymbolTable class.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32956 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Reader')
-rw-r--r-- | lib/Bytecode/Reader/Analyzer.cpp | 10 | ||||
-rw-r--r-- | lib/Bytecode/Reader/Reader.cpp | 47 | ||||
-rw-r--r-- | lib/Bytecode/Reader/Reader.h | 8 |
3 files changed, 43 insertions, 22 deletions
diff --git a/lib/Bytecode/Reader/Analyzer.cpp b/lib/Bytecode/Reader/Analyzer.cpp index 078360249c..899a534272 100644 --- a/lib/Bytecode/Reader/Analyzer.cpp +++ b/lib/Bytecode/Reader/Analyzer.cpp @@ -96,11 +96,12 @@ public: bca.BlockSizes[BytecodeFormat::ModuleBlockID] = theSize; bca.BlockSizes[BytecodeFormat::FunctionBlockID] = 0; bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID] = 0; - bca.BlockSizes[BytecodeFormat::SymbolTableBlockID] = 0; + bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID] = 0; bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID] = 0; bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID] = 0; bca.BlockSizes[BytecodeFormat::InstructionListBlockID] = 0; bca.BlockSizes[BytecodeFormat::CompactionTableBlockID] = 0; + bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID] = 0; } virtual void handleFinish() { @@ -636,8 +637,11 @@ void PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out ) print(Out, "Compaction Table Bytes", double(bca.BlockSizes[BytecodeFormat::CompactionTableBlockID]), double(bca.byteSize)); - print(Out, "Symbol Table Bytes", - double(bca.BlockSizes[BytecodeFormat::SymbolTableBlockID]), + print(Out, "Value Symbol Table Bytes", + double(bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID]), + double(bca.byteSize)); + print(Out, "Type Symbol Table Bytes", + double(bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID]), double(bca.byteSize)); print(Out, "Alignment Bytes", double(bca.numAlignment), double(bca.byteSize)); diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index afff24adb6..b1e4bf639c 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -24,6 +24,7 @@ #include "llvm/InlineAsm.h" #include "llvm/Instructions.h" #include "llvm/SymbolTable.h" +#include "llvm/TypeSymbolTable.h" #include "llvm/Bytecode/Format.h" #include "llvm/Config/alloca.h" #include "llvm/Support/GetElementPtrTypeIterator.h" @@ -1023,13 +1024,27 @@ unsigned BytecodeReader::ParseInstructionList(Function* F) { return BlockNo; } -/// Parse a symbol table. This works for both module level and function +/// Parse a type symbol table. +void BytecodeReader::ParseTypeSymbolTable(TypeSymbolTable *TST) { + // Type Symtab block header: [num entries] + unsigned NumEntries = read_vbr_uint(); + for (unsigned i = 0; i < NumEntries; ++i) { + // Symtab entry: [type slot #][name] + unsigned slot = read_vbr_uint(); + std::string Name = read_str(); + const Type* T = getType(slot); + TST->insert(Name, T); + } +} + +/// Parse a value symbol table. This works for both module level and function /// level symbol tables. For function level symbol tables, the CurrentFunction /// parameter must be non-zero and the ST parameter must correspond to /// CurrentFunction's symbol table. For Module level symbol tables, the /// CurrentFunction argument must be zero. -void BytecodeReader::ParseSymbolTable(Function *CurrentFunction, - SymbolTable *ST) { +void BytecodeReader::ParseValueSymbolTable(Function *CurrentFunction, + SymbolTable *ST) { + if (Handler) Handler->handleSymbolTableBegin(CurrentFunction,ST); // Allow efficient basic block lookup by number. @@ -1039,16 +1054,6 @@ void BytecodeReader::ParseSymbolTable(Function *CurrentFunction, E = CurrentFunction->end(); I != E; ++I) BBMap.push_back(I); - // Symtab block header: [num entries] - unsigned NumEntries = read_vbr_uint(); - for (unsigned i = 0; i < NumEntries; ++i) { - // Symtab entry: [def slot #][name] - unsigned slot = read_vbr_uint(); - std::string Name = read_str(); - const Type* T = getType(slot); - ST->insert(Name, T); - } - while (moreInBlock()) { // Symtab block header: [num entries][type id number] unsigned NumEntries = read_vbr_uint(); @@ -1683,8 +1688,12 @@ void BytecodeReader::ParseFunctionBody(Function* F) { break; } - case BytecodeFormat::SymbolTableBlockID: - ParseSymbolTable(F, &F->getSymbolTable()); + case BytecodeFormat::ValueSymbolTableBlockID: + ParseValueSymbolTable(F, &F->getValueSymbolTable()); + break; + + case BytecodeFormat::TypeSymbolTableBlockID: + error("Functions don't have type symbol tables"); break; default: @@ -2084,8 +2093,12 @@ void BytecodeReader::ParseModule() { ParseFunctionLazily(); break; - case BytecodeFormat::SymbolTableBlockID: - ParseSymbolTable(0, &TheModule->getSymbolTable()); + case BytecodeFormat::ValueSymbolTableBlockID: + ParseValueSymbolTable(0, &TheModule->getValueSymbolTable()); + break; + + case BytecodeFormat::TypeSymbolTableBlockID: + ParseTypeSymbolTable(&TheModule->getTypeSymbolTable()); break; default: diff --git a/lib/Bytecode/Reader/Reader.h b/lib/Bytecode/Reader/Reader.h index 1d2fe32af6..677c39f99f 100644 --- a/lib/Bytecode/Reader/Reader.h +++ b/lib/Bytecode/Reader/Reader.h @@ -29,6 +29,7 @@ namespace llvm { class BytecodeHandler; ///< Forward declare the handler interface +class TypeSymbolTable; ///< Forward declare /// This class defines the interface for parsing a buffer of bytecode. The /// parser itself takes no action except to call the various functions of @@ -199,8 +200,11 @@ protected: /// @brief Parse the ModuleGlobalInfo block void ParseModuleGlobalInfo(); - /// @brief Parse a symbol table - void ParseSymbolTable( Function* Func, SymbolTable *ST); + /// @brief Parse a value symbol table + void ParseTypeSymbolTable(TypeSymbolTable *ST); + + /// @brief Parse a value symbol table + void ParseValueSymbolTable(Function* Func, SymbolTable *ST); /// @brief Parse functions lazily. void ParseFunctionLazily(); |