mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 00:21:03 +00:00
ensure that every error return sets a message (and goes through Error, for
easy breakpointing). Fix bugs reading constantexpr geps. We now can disassemble kc++ global initializers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36398 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -161,7 +161,9 @@ bool BitcodeReader::ParseTypeTable(BitstreamReader &Stream) {
|
|||||||
if (Code == bitc::END_BLOCK) {
|
if (Code == bitc::END_BLOCK) {
|
||||||
if (NumRecords != TypeList.size())
|
if (NumRecords != TypeList.size())
|
||||||
return Error("Invalid type forward reference in TYPE_BLOCK");
|
return Error("Invalid type forward reference in TYPE_BLOCK");
|
||||||
return Stream.ReadBlockEnd();
|
if (Stream.ReadBlockEnd())
|
||||||
|
return Error("Error at end of type table block");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Code == bitc::ENTER_SUBBLOCK) {
|
if (Code == bitc::ENTER_SUBBLOCK) {
|
||||||
@@ -299,8 +301,11 @@ bool BitcodeReader::ParseTypeSymbolTable(BitstreamReader &Stream) {
|
|||||||
std::string TypeName;
|
std::string TypeName;
|
||||||
while (1) {
|
while (1) {
|
||||||
unsigned Code = Stream.ReadCode();
|
unsigned Code = Stream.ReadCode();
|
||||||
if (Code == bitc::END_BLOCK)
|
if (Code == bitc::END_BLOCK) {
|
||||||
return Stream.ReadBlockEnd();
|
if (Stream.ReadBlockEnd())
|
||||||
|
return Error("Error at end of type symbol table block");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (Code == bitc::ENTER_SUBBLOCK) {
|
if (Code == bitc::ENTER_SUBBLOCK) {
|
||||||
// No known subblocks, always skip them.
|
// No known subblocks, always skip them.
|
||||||
@@ -344,9 +349,11 @@ bool BitcodeReader::ParseValueSymbolTable(BitstreamReader &Stream) {
|
|||||||
SmallString<128> ValueName;
|
SmallString<128> ValueName;
|
||||||
while (1) {
|
while (1) {
|
||||||
unsigned Code = Stream.ReadCode();
|
unsigned Code = Stream.ReadCode();
|
||||||
if (Code == bitc::END_BLOCK)
|
if (Code == bitc::END_BLOCK) {
|
||||||
return Stream.ReadBlockEnd();
|
if (Stream.ReadBlockEnd())
|
||||||
|
return Error("Error at end of value symbol table block");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (Code == bitc::ENTER_SUBBLOCK) {
|
if (Code == bitc::ENTER_SUBBLOCK) {
|
||||||
// No known subblocks, always skip them.
|
// No known subblocks, always skip them.
|
||||||
Stream.ReadSubBlockID();
|
Stream.ReadSubBlockID();
|
||||||
@@ -420,7 +427,9 @@ bool BitcodeReader::ParseConstants(BitstreamReader &Stream) {
|
|||||||
if (NextCstNo != ValueList.size())
|
if (NextCstNo != ValueList.size())
|
||||||
return Error("Invalid constant reference!");
|
return Error("Invalid constant reference!");
|
||||||
|
|
||||||
return Stream.ReadBlockEnd();
|
if (Stream.ReadBlockEnd())
|
||||||
|
return Error("Error at end of constants block");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Code == bitc::ENTER_SUBBLOCK) {
|
if (Code == bitc::ENTER_SUBBLOCK) {
|
||||||
@@ -515,21 +524,25 @@ bool BitcodeReader::ParseConstants(BitstreamReader &Stream) {
|
|||||||
case bitc::CST_CODE_CE_BINOP: { // CE_BINOP: [opcode, opval, opval]
|
case bitc::CST_CODE_CE_BINOP: { // CE_BINOP: [opcode, opval, opval]
|
||||||
if (Record.size() < 3) return Error("Invalid CE_BINOP record");
|
if (Record.size() < 3) return Error("Invalid CE_BINOP record");
|
||||||
int Opc = GetDecodedBinaryOpcode(Record[0], CurTy);
|
int Opc = GetDecodedBinaryOpcode(Record[0], CurTy);
|
||||||
if (Opc < 0) return UndefValue::get(CurTy); // Unknown binop.
|
if (Opc < 0) {
|
||||||
|
V = UndefValue::get(CurTy); // Unknown binop.
|
||||||
|
} else {
|
||||||
Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy);
|
Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy);
|
||||||
Constant *RHS = ValueList.getConstantFwdRef(Record[2], CurTy);
|
Constant *RHS = ValueList.getConstantFwdRef(Record[2], CurTy);
|
||||||
V = ConstantExpr::get(Opc, LHS, RHS);
|
V = ConstantExpr::get(Opc, LHS, RHS);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitc::CST_CODE_CE_CAST: { // CE_CAST: [opcode, opty, opval]
|
case bitc::CST_CODE_CE_CAST: { // CE_CAST: [opcode, opty, opval]
|
||||||
if (Record.size() < 3) return Error("Invalid CE_CAST record");
|
if (Record.size() < 3) return Error("Invalid CE_CAST record");
|
||||||
int Opc = GetDecodedCastOpcode(Record[0]);
|
int Opc = GetDecodedCastOpcode(Record[0]);
|
||||||
if (Opc < 0) return UndefValue::get(CurTy); // Unknown cast.
|
if (Opc < 0) {
|
||||||
|
V = UndefValue::get(CurTy); // Unknown cast.
|
||||||
|
} else {
|
||||||
const Type *OpTy = getTypeByID(Record[1]);
|
const Type *OpTy = getTypeByID(Record[1]);
|
||||||
Constant *Op = ValueList.getConstantFwdRef(Record[2], OpTy);
|
Constant *Op = ValueList.getConstantFwdRef(Record[2], OpTy);
|
||||||
V = ConstantExpr::getCast(Opc, Op, CurTy);
|
V = ConstantExpr::getCast(Opc, Op, CurTy);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitc::CST_CODE_CE_GEP: { // CE_GEP: [n x operands]
|
case bitc::CST_CODE_CE_GEP: { // CE_GEP: [n x operands]
|
||||||
@@ -540,7 +553,8 @@ bool BitcodeReader::ParseConstants(BitstreamReader &Stream) {
|
|||||||
if (!ElTy) return Error("Invalid CE_GEP record");
|
if (!ElTy) return Error("Invalid CE_GEP record");
|
||||||
Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy));
|
Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy));
|
||||||
}
|
}
|
||||||
return ConstantExpr::getGetElementPtr(Elts[0], &Elts[1], Elts.size()-1);
|
V = ConstantExpr::getGetElementPtr(Elts[0], &Elts[1], Elts.size()-1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case bitc::CST_CODE_CE_SELECT: // CE_SELECT: [opval#, opval#, opval#]
|
case bitc::CST_CODE_CE_SELECT: // CE_SELECT: [opval#, opval#, opval#]
|
||||||
if (Record.size() < 3) return Error("Invalid CE_SELECT record");
|
if (Record.size() < 3) return Error("Invalid CE_SELECT record");
|
||||||
@@ -634,7 +648,9 @@ bool BitcodeReader::ParseModule(BitstreamReader &Stream,
|
|||||||
if (Code == bitc::END_BLOCK) {
|
if (Code == bitc::END_BLOCK) {
|
||||||
if (!GlobalInits.empty())
|
if (!GlobalInits.empty())
|
||||||
return Error("Malformed global initializer set");
|
return Error("Malformed global initializer set");
|
||||||
return Stream.ReadBlockEnd();
|
if (Stream.ReadBlockEnd())
|
||||||
|
return Error("Error at end of module block");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Code == bitc::ENTER_SUBBLOCK) {
|
if (Code == bitc::ENTER_SUBBLOCK) {
|
||||||
|
@@ -58,6 +58,7 @@ class BitcodeReader : public ModuleProvider {
|
|||||||
BitcodeReaderValueList ValueList;
|
BitcodeReaderValueList ValueList;
|
||||||
std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits;
|
std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits;
|
||||||
public:
|
public:
|
||||||
|
BitcodeReader() : ErrorString(0) {}
|
||||||
virtual ~BitcodeReader() {}
|
virtual ~BitcodeReader() {}
|
||||||
|
|
||||||
virtual void FreeState() {}
|
virtual void FreeState() {}
|
||||||
|
@@ -51,6 +51,7 @@ bool BitcodeFileReader::Read(std::string *ErrMsg) {
|
|||||||
unsigned char *Buffer = reinterpret_cast<unsigned char*>(File.base());
|
unsigned char *Buffer = reinterpret_cast<unsigned char*>(File.base());
|
||||||
if (!ParseBitcode(Buffer, File.size(), Filename))
|
if (!ParseBitcode(Buffer, File.size(), Filename))
|
||||||
return false;
|
return false;
|
||||||
|
assert(getErrorString() && "Didn't set an error string?");
|
||||||
if (ErrMsg) *ErrMsg = getErrorString();
|
if (ErrMsg) *ErrMsg = getErrorString();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user