mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 00:21:03 +00:00
Infrastructure for more compact bytecode files and REAL support for versioning
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5716 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -60,8 +60,12 @@ int BytecodeParser::insertValue(Value *Val, std::vector<ValueList> &ValueTab) {
|
|||||||
if (getTypeSlot(Val->getType(), type)) return -1;
|
if (getTypeSlot(Val->getType(), type)) return -1;
|
||||||
assert(type != Type::TypeTyID && "Types should never be insertValue'd!");
|
assert(type != Type::TypeTyID && "Types should never be insertValue'd!");
|
||||||
|
|
||||||
if (ValueTab.size() <= type)
|
while (ValueTab.size() <= type) {
|
||||||
ValueTab.resize(type+1, ValueList());
|
ValueTab.push_back(ValueList());
|
||||||
|
if (HasImplicitZeroInitializer) // add a zero initializer if appropriate
|
||||||
|
ValueTab.back().push_back(
|
||||||
|
Constant::getNullValue(getType(ValueTab.size()-1)));
|
||||||
|
}
|
||||||
|
|
||||||
//cerr << "insertValue Values[" << type << "][" << ValueTab[type].size()
|
//cerr << "insertValue Values[" << type << "][" << ValueTab[type].size()
|
||||||
// << "] = " << Val << "\n";
|
// << "] = " << Val << "\n";
|
||||||
@@ -194,8 +198,7 @@ bool BytecodeParser::ParseBasicBlock(const uchar *&Buf, const uchar *EndBuf,
|
|||||||
|
|
||||||
while (Buf < EndBuf) {
|
while (Buf < EndBuf) {
|
||||||
Instruction *Inst;
|
Instruction *Inst;
|
||||||
if (ParseInstruction(Buf, EndBuf, Inst,
|
if (ParseInstruction(Buf, EndBuf, Inst, /*HACK*/BB)) {
|
||||||
/*HACK*/BB)) {
|
|
||||||
delete BB;
|
delete BB;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -490,6 +493,38 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BytecodeParser::ParseVersionInfo(const uchar *&Buf, const uchar *EndBuf) {
|
||||||
|
unsigned Version;
|
||||||
|
if (read_vbr(Buf, EndBuf, Version)) return true;
|
||||||
|
|
||||||
|
// Unpack version number: low four bits are for flags, top bits = version
|
||||||
|
isBigEndian = Version & 1;
|
||||||
|
hasLongPointers = Version & 2;
|
||||||
|
RevisionNum = Version >> 4;
|
||||||
|
HasImplicitZeroInitializer = true;
|
||||||
|
|
||||||
|
switch (RevisionNum) {
|
||||||
|
case 0: // Initial revision
|
||||||
|
if (Version != 14) return true; // Unknown revision 0 flags?
|
||||||
|
FirstDerivedTyID = 14;
|
||||||
|
HasImplicitZeroInitializer = false;
|
||||||
|
isBigEndian = hasLongPointers = true;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
FirstDerivedTyID = 14;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Error = "Unknown bytecode version number!";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
BCR_TRACE(1, "Bytecode Rev = " << (unsigned)RevisionNum << "\n");
|
||||||
|
BCR_TRACE(1, "BigEndian/LongPointers = " << isBigEndian << ","
|
||||||
|
<< hasLongPointers << "\n");
|
||||||
|
BCR_TRACE(1, "HasImplicitZeroInit = " << HasImplicitZeroInitializer << "\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool BytecodeParser::ParseModule(const uchar *Buf, const uchar *EndBuf) {
|
bool BytecodeParser::ParseModule(const uchar *Buf, const uchar *EndBuf) {
|
||||||
unsigned Type, Size;
|
unsigned Type, Size;
|
||||||
if (readBlock(Buf, EndBuf, Type, Size)) return true;
|
if (readBlock(Buf, EndBuf, Type, Size)) return true;
|
||||||
@@ -502,9 +537,8 @@ bool BytecodeParser::ParseModule(const uchar *Buf, const uchar *EndBuf) {
|
|||||||
FunctionSignatureList.clear(); // Just in case...
|
FunctionSignatureList.clear(); // Just in case...
|
||||||
|
|
||||||
// Read into instance variables...
|
// Read into instance variables...
|
||||||
if (read_vbr(Buf, EndBuf, FirstDerivedTyID)) return true;
|
if (ParseVersionInfo(Buf, EndBuf)) return true;
|
||||||
if (align32(Buf, EndBuf)) return true;
|
if (align32(Buf, EndBuf)) return true;
|
||||||
BCR_TRACE(1, "FirstDerivedTyID = " << FirstDerivedTyID << "\n");
|
|
||||||
|
|
||||||
while (Buf < EndBuf) {
|
while (Buf < EndBuf) {
|
||||||
const unsigned char *OldBuf = Buf;
|
const unsigned char *OldBuf = Buf;
|
||||||
|
@@ -57,6 +57,12 @@ public:
|
|||||||
private: // All of this data is transient across calls to ParseBytecode
|
private: // All of this data is transient across calls to ParseBytecode
|
||||||
Module *TheModule; // Current Module being read into...
|
Module *TheModule; // Current Module being read into...
|
||||||
|
|
||||||
|
// Information about the module, extracted from the bytecode revision number.
|
||||||
|
unsigned char RevisionNum; // The rev # itself
|
||||||
|
unsigned char FirstDerivedTyID; // First variable index to use for type
|
||||||
|
bool HasImplicitZeroInitializer; // Is entry 0 of every slot implicity zeros?
|
||||||
|
bool isBigEndian, hasLongPointers;// Information about the target compiled for
|
||||||
|
|
||||||
typedef std::vector<Value *> ValueList;
|
typedef std::vector<Value *> ValueList;
|
||||||
typedef std::vector<ValueList> ValueTable;
|
typedef std::vector<ValueList> ValueTable;
|
||||||
ValueTable Values, LateResolveValues;
|
ValueTable Values, LateResolveValues;
|
||||||
@@ -78,9 +84,6 @@ private: // All of this data is transient across calls to ParseBytecode
|
|||||||
TypeValuesListTy ModuleTypeValues;
|
TypeValuesListTy ModuleTypeValues;
|
||||||
TypeValuesListTy FunctionTypeValues;
|
TypeValuesListTy FunctionTypeValues;
|
||||||
|
|
||||||
// Information read from the ModuleGlobalInfo section of the file...
|
|
||||||
unsigned FirstDerivedTyID;
|
|
||||||
|
|
||||||
// When the ModuleGlobalInfo section is read, we load the type of each
|
// When the ModuleGlobalInfo section is read, we load the type of each
|
||||||
// function and the 'ModuleValues' slot that it lands in. We then load a
|
// function and the 'ModuleValues' slot that it lands in. We then load a
|
||||||
// placeholder into its slot to reserve it. When the function is loaded, this
|
// placeholder into its slot to reserve it. When the function is loaded, this
|
||||||
@@ -90,6 +93,7 @@ private: // All of this data is transient across calls to ParseBytecode
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool ParseModule (const uchar * Buf, const uchar *End);
|
bool ParseModule (const uchar * Buf, const uchar *End);
|
||||||
|
bool ParseVersionInfo (const uchar *&Buf, const uchar *End);
|
||||||
bool ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End);
|
bool ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End);
|
||||||
bool ParseSymbolTable (const uchar *&Buf, const uchar *End, SymbolTable *);
|
bool ParseSymbolTable (const uchar *&Buf, const uchar *End, SymbolTable *);
|
||||||
bool ParseFunction (const uchar *&Buf, const uchar *End);
|
bool ParseFunction (const uchar *&Buf, const uchar *End);
|
||||||
|
Reference in New Issue
Block a user