IR: Add MDExpression::ExprOperand

Port `DIExpression::Operand` over to `MDExpression::ExprOperand`.  The
logic is needed directly in `MDExpression` to support printing in
assembly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229002 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-02-13 01:07:46 +00:00
parent 191690dc8c
commit 7473485c0f
4 changed files with 148 additions and 0 deletions

View File

@ -350,6 +350,38 @@ MDExpression *MDExpression::getImpl(LLVMContext &Context,
DEFINE_GETIMPL_STORE_NO_OPS(MDExpression, (Elements));
}
unsigned MDExpression::ExprOperand::getSize() const {
switch (getOp()) {
case dwarf::DW_OP_bit_piece:
return 3;
case dwarf::DW_OP_plus:
return 2;
default:
return 1;
}
}
bool MDExpression::isValid() const {
for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
// Check that there's space for the operand.
if (I->get() + I->getSize() > E->get())
return false;
// Check that the operand is valid.
switch (I->getOp()) {
default:
return false;
case dwarf::DW_OP_bit_piece:
// Piece expressions must be at the end.
return I->get() + I->getSize() == E->get();
case dwarf::DW_OP_plus:
case dwarf::DW_OP_deref:
break;
}
}
return true;
}
MDObjCProperty *MDObjCProperty::getImpl(
LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
MDString *GetterName, MDString *SetterName, unsigned Attributes,