From 32af9e8cc54eb85340c1ff1b46e0d5a3afc3db4a Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Sat, 6 Jan 2007 07:24:44 +0000 Subject: 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. llvm-svn: 32956 --- llvm/lib/Bytecode/Writer/Writer.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'llvm/lib/Bytecode/Writer/Writer.cpp') diff --git a/llvm/lib/Bytecode/Writer/Writer.cpp b/llvm/lib/Bytecode/Writer/Writer.cpp index 58cc13a1414..37e4abfae2f 100644 --- a/llvm/lib/Bytecode/Writer/Writer.cpp +++ b/llvm/lib/Bytecode/Writer/Writer.cpp @@ -27,6 +27,7 @@ #include "llvm/Instructions.h" #include "llvm/Module.h" #include "llvm/SymbolTable.h" +#include "llvm/TypeSymbolTable.h" #include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Support/Compressor.h" #include "llvm/Support/MathExtras.h" @@ -837,8 +838,11 @@ BytecodeWriter::BytecodeWriter(std::vector &o, const Module *M) for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) outputFunction(I); - // If needed, output the symbol table for the module... - outputSymbolTable(M->getSymbolTable()); + // Output the symbole table for types + outputTypeSymbolTable(M->getTypeSymbolTable()); + + // Output the symbol table for values + outputValueSymbolTable(M->getValueSymbolTable()); } void BytecodeWriter::outputTypes(unsigned TypeNum) { @@ -1112,7 +1116,7 @@ void BytecodeWriter::outputFunction(const Function *F) { outputInstructions(F); // If needed, output the symbol table for the function... - outputSymbolTable(F->getSymbolTable()); + outputValueSymbolTable(F->getValueSymbolTable()); Table.purgeFunction(); } @@ -1187,24 +1191,33 @@ void BytecodeWriter::outputCompactionTable() { } } -void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) { - // Do not output the Bytecode block for an empty symbol table, it just wastes +void BytecodeWriter::outputTypeSymbolTable(const TypeSymbolTable &TST) { + // Do not output the block for an empty symbol table, it just wastes // space! - if (MST.isEmpty()) return; + if (TST.empty()) return; - BytecodeBlock SymTabBlock(BytecodeFormat::SymbolTableBlockID, *this, + // Create a header for the symbol table + BytecodeBlock SymTabBlock(BytecodeFormat::TypeSymbolTableBlockID, *this, true/*ElideIfEmpty*/); - // Write the number of types - output_vbr(MST.num_types()); + output_vbr(TST.size()); // Write each of the types - for (SymbolTable::type_const_iterator TI = MST.type_begin(), - TE = MST.type_end(); TI != TE; ++TI) { + for (TypeSymbolTable::const_iterator TI = TST.begin(), TE = TST.end(); + TI != TE; ++TI) { // Symtab entry:[def slot #][name] output_typeid((unsigned)Table.getSlot(TI->second)); output(TI->first); } +} + +void BytecodeWriter::outputValueSymbolTable(const SymbolTable &MST) { + // Do not output the Bytecode block for an empty symbol table, it just wastes + // space! + if (MST.isEmpty()) return; + + BytecodeBlock SymTabBlock(BytecodeFormat::ValueSymbolTableBlockID, *this, + true/*ElideIfEmpty*/); // Now do each of the type planes in order. for (SymbolTable::plane_const_iterator PI = MST.plane_begin(), -- cgit v1.2.3