mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-03 00:33:09 +00:00
move some code around, fix a bug in the reader reading globalinits (which
I just introduced), stub out function reading, purge aggregate values from the value table before reading functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36463 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
eb0107af86
commit
198f34ac35
@ -408,10 +408,10 @@ bool BitcodeReader::ResolveGlobalAndAliasInits() {
|
|||||||
AliasInitWorklist.swap(AliasInits);
|
AliasInitWorklist.swap(AliasInits);
|
||||||
|
|
||||||
while (!GlobalInitWorklist.empty()) {
|
while (!GlobalInitWorklist.empty()) {
|
||||||
unsigned ValID = GlobalInits.back().second;
|
unsigned ValID = GlobalInitWorklist.back().second;
|
||||||
if (ValID >= ValueList.size()) {
|
if (ValID >= ValueList.size()) {
|
||||||
// Not ready to resolve this yet, it requires something later in the file.
|
// Not ready to resolve this yet, it requires something later in the file.
|
||||||
GlobalInitWorklist.push_back(GlobalInits.back());
|
GlobalInits.push_back(GlobalInitWorklist.back());
|
||||||
} else {
|
} else {
|
||||||
if (Constant *C = dyn_cast<Constant>(ValueList[ValID]))
|
if (Constant *C = dyn_cast<Constant>(ValueList[ValID]))
|
||||||
GlobalInitWorklist.back().first->setInitializer(C);
|
GlobalInitWorklist.back().first->setInitializer(C);
|
||||||
@ -826,7 +826,7 @@ bool BitcodeReader::ParseModule(BitstreamReader &Stream,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// ALIAS: [alias type, aliasee val#, linkage]
|
// ALIAS: [alias type, aliasee val#, linkage]
|
||||||
case bitc::MODULE_CODE_ALIAS:
|
case bitc::MODULE_CODE_ALIAS: {
|
||||||
if (Record.size() < 3)
|
if (Record.size() < 3)
|
||||||
return Error("Invalid MODULE_ALIAS record");
|
return Error("Invalid MODULE_ALIAS record");
|
||||||
const Type *Ty = getTypeByID(Record[0]);
|
const Type *Ty = getTypeByID(Record[0]);
|
||||||
@ -839,6 +839,14 @@ bool BitcodeReader::ParseModule(BitstreamReader &Stream,
|
|||||||
AliasInits.push_back(std::make_pair(NewGA, Record[1]));
|
AliasInits.push_back(std::make_pair(NewGA, Record[1]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/// MODULE_CODE_PURGEVALS: [numvals]
|
||||||
|
case bitc::MODULE_CODE_PURGEVALS:
|
||||||
|
// Trim down the value list to the specified size.
|
||||||
|
if (Record.size() < 1 || Record[0] > ValueList.size())
|
||||||
|
return Error("Invalid MODULE_PURGEVALS record");
|
||||||
|
ValueList.shrinkTo(Record[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
Record.clear();
|
Record.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,11 @@ public:
|
|||||||
Value *back() const { return Uses.back(); }
|
Value *back() const { return Uses.back(); }
|
||||||
void pop_back() { Uses.pop_back(); --NumOperands; }
|
void pop_back() { Uses.pop_back(); --NumOperands; }
|
||||||
bool empty() const { return NumOperands == 0; }
|
bool empty() const { return NumOperands == 0; }
|
||||||
|
void shrinkTo(unsigned N) {
|
||||||
|
assert(N < NumOperands && "Invalid shrinkTo request!");
|
||||||
|
Uses.resize(N);
|
||||||
|
NumOperands = N;
|
||||||
|
}
|
||||||
virtual void print(std::ostream&) const {}
|
virtual void print(std::ostream&) const {}
|
||||||
|
|
||||||
Constant *getConstantFwdRef(unsigned Idx, const Type *Ty);
|
Constant *getConstantFwdRef(unsigned Idx, const Type *Ty);
|
||||||
|
@ -324,69 +324,6 @@ 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::VST_CODE_ENTRY, 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_CODE_ENTRY, NameVals, AbbrevToUse);
|
|
||||||
NameVals.clear();
|
|
||||||
}
|
|
||||||
Stream.ExitBlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void WriteConstants(unsigned FirstVal, unsigned LastVal,
|
static void WriteConstants(unsigned FirstVal, unsigned LastVal,
|
||||||
const ValueEnumerator &VE,
|
const ValueEnumerator &VE,
|
||||||
BitstreamWriter &Stream) {
|
BitstreamWriter &Stream) {
|
||||||
@ -541,15 +478,85 @@ static void WriteModuleConstants(const ValueEnumerator &VE,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void WriteFunction(const Function &F, ValueEnumerator &VE,
|
||||||
|
BitstreamWriter &Stream) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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::VST_CODE_ENTRY, 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_CODE_ENTRY, 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);
|
||||||
|
|
||||||
// Emit the version number if it is non-zero.
|
// Emit the version number if it is non-zero.
|
||||||
if (CurVersion) {
|
if (CurVersion) {
|
||||||
SmallVector<unsigned, 1> VersionVals;
|
SmallVector<unsigned, 1> Vals;
|
||||||
VersionVals.push_back(CurVersion);
|
Vals.push_back(CurVersion);
|
||||||
Stream.EmitRecord(bitc::MODULE_CODE_VERSION, VersionVals);
|
Stream.EmitRecord(bitc::MODULE_CODE_VERSION, Vals);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Analyze the module, enumerating globals, functions, etc.
|
// Analyze the module, enumerating globals, functions, etc.
|
||||||
@ -565,6 +572,19 @@ static void WriteModule(const Module *M, BitstreamWriter &Stream) {
|
|||||||
// Emit constants.
|
// Emit constants.
|
||||||
WriteModuleConstants(VE, Stream);
|
WriteModuleConstants(VE, Stream);
|
||||||
|
|
||||||
|
// FIXME: Purge aggregate values from the VE, emit a record that indicates how
|
||||||
|
// many to purge.
|
||||||
|
int NumNonAggregates = VE.PurgeAggregateValues();
|
||||||
|
if (NumNonAggregates != -1) {
|
||||||
|
SmallVector<unsigned, 1> Vals;
|
||||||
|
Vals.push_back(NumNonAggregates);
|
||||||
|
Stream.EmitRecord(bitc::MODULE_CODE_PURGEVALS, Vals);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Emit function bodies.
|
||||||
|
for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
|
||||||
|
WriteFunction(*I, VE, Stream);
|
||||||
|
|
||||||
// Emit the type symbol table information.
|
// Emit the type symbol table information.
|
||||||
WriteTypeSymbolTable(M->getTypeSymbolTable(), VE, Stream);
|
WriteTypeSymbolTable(M->getTypeSymbolTable(), VE, Stream);
|
||||||
|
|
||||||
|
@ -140,6 +140,22 @@ void ValueEnumerator::EnumerateType(const Type *Ty) {
|
|||||||
EnumerateType(*I);
|
EnumerateType(*I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// PurgeAggregateValues - If there are any aggregate values at the end of the
|
||||||
|
/// value list, remove them and return the count of the remaining values. If
|
||||||
|
/// there are none, return -1.
|
||||||
|
int ValueEnumerator::PurgeAggregateValues() {
|
||||||
|
// If there are no aggregate values at the end of the list, return -1.
|
||||||
|
if (Values.empty() || Values.back().first->getType()->isFirstClassType())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// Otherwise, remove aggregate values...
|
||||||
|
while (!Values.empty() && !Values.back().first->getType()->isFirstClassType())
|
||||||
|
Values.pop_back();
|
||||||
|
|
||||||
|
// ... and return the new size.
|
||||||
|
return Values.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -64,6 +64,11 @@ public:
|
|||||||
const ValueList &getValues() const { return Values; }
|
const ValueList &getValues() const { return Values; }
|
||||||
const TypeList &getTypes() const { return Types; }
|
const TypeList &getTypes() const { return Types; }
|
||||||
|
|
||||||
|
/// PurgeAggregateValues - If there are any aggregate values at the end of the
|
||||||
|
/// value list, remove them and return the count of the remaining values. If
|
||||||
|
/// there are none, return -1.
|
||||||
|
int PurgeAggregateValues();
|
||||||
|
|
||||||
/// incorporateFunction/purgeFunction - If you'd like to deal with a function,
|
/// incorporateFunction/purgeFunction - If you'd like to deal with a function,
|
||||||
/// use these two methods to get its data into the ValueEnumerator!
|
/// use these two methods to get its data into the ValueEnumerator!
|
||||||
///
|
///
|
||||||
|
Loading…
x
Reference in New Issue
Block a user