mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-17 04:24:00 +00:00
write out the symtab for globals.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36374 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -18,6 +18,7 @@
|
|||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/TypeSymbolTable.h"
|
#include "llvm/TypeSymbolTable.h"
|
||||||
|
#include "llvm/ValueSymbolTable.h"
|
||||||
#include "llvm/Support/MathExtras.h"
|
#include "llvm/Support/MathExtras.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@ -126,39 +127,6 @@ static void WriteTypeTable(const ValueEnumerator &VE, BitstreamWriter &Stream) {
|
|||||||
Stream.ExitBlock();
|
Stream.ExitBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// WriteTypeSymbolTable - Emit a block for the specified type symtab.
|
|
||||||
static void WriteTypeSymbolTable(const TypeSymbolTable &TST,
|
|
||||||
const ValueEnumerator &VE,
|
|
||||||
BitstreamWriter &Stream) {
|
|
||||||
if (TST.empty()) return;
|
|
||||||
|
|
||||||
Stream.EnterSubblock(bitc::TYPE_SYMTAB_BLOCK_ID, 3);
|
|
||||||
|
|
||||||
// FIXME: Set up the abbrev, we know how many types there are!
|
|
||||||
// FIXME: We know if the type names can use 7-bit ascii.
|
|
||||||
|
|
||||||
SmallVector<unsigned, 64> NameVals;
|
|
||||||
|
|
||||||
for (TypeSymbolTable::const_iterator TI = TST.begin(), TE = TST.end();
|
|
||||||
TI != TE; ++TI) {
|
|
||||||
unsigned AbbrevToUse = 0;
|
|
||||||
|
|
||||||
// TST_ENTRY: [typeid, namelen, namechar x N]
|
|
||||||
NameVals.push_back(VE.getTypeID(TI->second));
|
|
||||||
|
|
||||||
const std::string &Str = TI->first;
|
|
||||||
NameVals.push_back(Str.size());
|
|
||||||
for (unsigned i = 0, e = Str.size(); i != e; ++i)
|
|
||||||
NameVals.push_back(Str[i]);
|
|
||||||
|
|
||||||
// Emit the finished record.
|
|
||||||
Stream.EmitRecord(bitc::TST_ENTRY_CODE, NameVals, AbbrevToUse);
|
|
||||||
NameVals.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
Stream.ExitBlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned getEncodedLinkage(const GlobalValue *GV) {
|
static unsigned getEncodedLinkage(const GlobalValue *GV) {
|
||||||
switch (GV->getLinkage()) {
|
switch (GV->getLinkage()) {
|
||||||
default: assert(0 && "Invalid linkage!");
|
default: assert(0 && "Invalid linkage!");
|
||||||
@ -302,6 +270,71 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// WriteTypeSymbolTable - Emit a block for the specified type symtab.
|
||||||
|
static void WriteTypeSymbolTable(const TypeSymbolTable &TST,
|
||||||
|
const ValueEnumerator &VE,
|
||||||
|
BitstreamWriter &Stream) {
|
||||||
|
if (TST.empty()) return;
|
||||||
|
|
||||||
|
Stream.EnterSubblock(bitc::TYPE_SYMTAB_BLOCK_ID, 3);
|
||||||
|
|
||||||
|
// FIXME: Set up the abbrev, we know how many types there are!
|
||||||
|
// FIXME: We know if the type names can use 7-bit ascii.
|
||||||
|
|
||||||
|
SmallVector<unsigned, 64> NameVals;
|
||||||
|
|
||||||
|
for (TypeSymbolTable::const_iterator TI = TST.begin(), TE = TST.end();
|
||||||
|
TI != TE; ++TI) {
|
||||||
|
unsigned AbbrevToUse = 0;
|
||||||
|
|
||||||
|
// TST_ENTRY: [typeid, namelen, namechar x N]
|
||||||
|
NameVals.push_back(VE.getTypeID(TI->second));
|
||||||
|
|
||||||
|
const std::string &Str = TI->first;
|
||||||
|
NameVals.push_back(Str.size());
|
||||||
|
for (unsigned i = 0, e = Str.size(); i != e; ++i)
|
||||||
|
NameVals.push_back(Str[i]);
|
||||||
|
|
||||||
|
// Emit the finished record.
|
||||||
|
Stream.EmitRecord(bitc::TST_ENTRY_CODE, NameVals, AbbrevToUse);
|
||||||
|
NameVals.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream.ExitBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Emit names for globals/functions etc.
|
||||||
|
static void WriteValueSymbolTable(const ValueSymbolTable &VST,
|
||||||
|
const ValueEnumerator &VE,
|
||||||
|
BitstreamWriter &Stream) {
|
||||||
|
if (VST.empty()) return;
|
||||||
|
Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 3);
|
||||||
|
|
||||||
|
// FIXME: Set up the abbrev, we know how many values there are!
|
||||||
|
// FIXME: We know if the type names can use 7-bit ascii.
|
||||||
|
SmallVector<unsigned, 64> NameVals;
|
||||||
|
|
||||||
|
for (ValueSymbolTable::const_iterator SI = VST.begin(), SE = VST.end();
|
||||||
|
SI != SE; ++SI) {
|
||||||
|
unsigned AbbrevToUse = 0;
|
||||||
|
|
||||||
|
// VST_ENTRY: [valueid, namelen, namechar x N]
|
||||||
|
NameVals.push_back(VE.getValueID(SI->getValue()));
|
||||||
|
|
||||||
|
NameVals.push_back(SI->getKeyLength());
|
||||||
|
for (const char *P = SI->getKeyData(),
|
||||||
|
*E = SI->getKeyData()+SI->getKeyLength(); P != E; ++P)
|
||||||
|
NameVals.push_back((unsigned char)*P);
|
||||||
|
|
||||||
|
// Emit the finished record.
|
||||||
|
Stream.EmitRecord(bitc::VST_ENTRY_CODE, NameVals, AbbrevToUse);
|
||||||
|
NameVals.clear();
|
||||||
|
}
|
||||||
|
Stream.ExitBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// WriteModule - Emit the specified module to the bitstream.
|
/// WriteModule - Emit the specified module to the bitstream.
|
||||||
static void WriteModule(const Module *M, BitstreamWriter &Stream) {
|
static void WriteModule(const Module *M, BitstreamWriter &Stream) {
|
||||||
Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3);
|
Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3);
|
||||||
@ -327,6 +360,10 @@ static void WriteModule(const Module *M, BitstreamWriter &Stream) {
|
|||||||
|
|
||||||
// Emit the type symbol table information.
|
// Emit the type symbol table information.
|
||||||
WriteTypeSymbolTable(M->getTypeSymbolTable(), VE, Stream);
|
WriteTypeSymbolTable(M->getTypeSymbolTable(), VE, Stream);
|
||||||
|
|
||||||
|
// Emit names for globals/functions etc.
|
||||||
|
WriteValueSymbolTable(M->getValueSymbolTable(), VE, Stream);
|
||||||
|
|
||||||
Stream.ExitBlock();
|
Stream.ExitBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user