Parsing and basic structure of try_apply. Not yet properly

threaded into IRGen; tests to follow when that's done.

I made a preliminary effort to make the inliner do the
right thing with try_apply, but otherwise tried to avoid
touching the optimizer any more than was required by the
removal of ApplyInstBase.

Swift SVN r26747
This commit is contained in:
John McCall
2015-03-31 02:41:03 +00:00
parent 1c8fcec3b9
commit 6d8fff9c06
21 changed files with 723 additions and 222 deletions

View File

@@ -617,6 +617,31 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
S.writeSubstitutions(AI->getSubstitutions(), SILAbbrCodes);
break;
}
case ValueKind::TryApplyInst: {
// Format: attributes such as transparent and number of substitutions,
// the callee's substituted and unsubstituted types, a value for
// the callee and a list of values for the arguments. Each value in the list
// is represented with 2 IDs: ValueID and ValueResultNumber. The final two
// entries in the list are the basic block destinations. The record
// is followed by the substitution list.
const TryApplyInst *AI = cast<TryApplyInst>(&SI);
SmallVector<ValueID, 4> Args;
for (auto Arg: AI->getArguments()) {
Args.push_back(addValueRef(Arg));
Args.push_back(Arg.getResultNumber());
}
Args.push_back(BasicBlockMap[AI->getNormalBB()]);
Args.push_back(BasicBlockMap[AI->getErrorBB()]);
SILInstApplyLayout::emitRecord(Out, ScratchRecord,
SILAbbrCodes[SILInstApplyLayout::Code], 0/*Apply*/,
AI->getSubstitutions().size(),
S.addTypeRef(AI->getCallee().getType().getSwiftRValueType()),
S.addTypeRef(AI->getSubstCalleeType()),
addValueRef(AI->getCallee()), AI->getCallee().getResultNumber(),
Args);
S.writeSubstitutions(AI->getSubstitutions(), SILAbbrCodes);
break;
}
case ValueKind::PartialApplyInst: {
const PartialApplyInst *PAI = cast<PartialApplyInst>(&SI);
SmallVector<ValueID, 4> Args;