namespace mlir {
class Builder;
-class Function;
//===----------------------------------------------------------------------===//
// OpAsmPrinter
}
}
virtual void printType(Type type) = 0;
- virtual void printFunctionReference(Function *func) = 0;
virtual void printAttribute(Attribute attr) = 0;
virtual void printAttributeAndType(Attribute attr) = 0;
// Support printing anything that isn't convertible to one of the above types,
// even if it isn't exactly one of them. For example, we want to print
-// FunctionType with the Type& version above, not have it match this.
+// FunctionType with the Type version above, not have it match this.
template <typename T, typename std::enable_if<
!std::is_convertible<T &, Value &>::value &&
!std::is_convertible<T &, Type &>::value &&
virtual ParseResult
parseOptionalAttributeDict(SmallVectorImpl<NamedAttribute> &result) = 0;
- /// Parse a function name like '@foo' and return the name in a form that can
- /// be passed to resolveFunctionName when a function type is available.
- virtual ParseResult parseFunctionName(StringRef &result,
- llvm::SMLoc &loc) = 0;
-
- /// Parse a function name like '@foo` if present and return the name without
- /// the sigil in `result`. Return true if the next token is not a function
- /// name and keep `result` unchanged.
- virtual ParseResult parseOptionalFunctionName(StringRef &result,
- llvm::SMLoc &loc) = 0;
-
/// This is the representation of an operand reference.
struct OperandType {
llvm::SMLoc location; // Location of the token.
}
void print(Module *module);
- void printFunctionReference(Function *func);
void printAttributeAndType(Attribute attr) {
printAttributeOptionalType(attr, /*includeType=*/true);
}
os << str;
}
-void ModulePrinter::printFunctionReference(Function *func) {
- os << '@' << func->getName();
-}
-
void ModulePrinter::printLocation(Location loc) {
if (printPrettyDebugInfo) {
printLocationInternal(loc, /*pretty=*/true);
void printAttributeAndType(Attribute attr) override {
ModulePrinter::printAttributeAndType(attr);
}
- void printFunctionReference(Function *func) override {
- return ModulePrinter::printFunctionReference(func);
- }
void printOperand(Value *value) override { printValueID(value); }
void printOptionalAttrDict(ArrayRef<NamedAttribute> attrs,
SmallVector<NamedAttribute, 4> attrs;
SmallVector<OpAsmParser::OperandType, 8> operands;
Type type;
- StringRef calleeName;
- llvm::SMLoc calleeLoc, trailingTypeLoc;
+ FunctionAttr funcAttr;
+ llvm::SMLoc trailingTypeLoc;
// Parse an operand list that will, in practice, contain 0 or 1 operand. In
// case of an indirect call, there will be 1 operand before `(`. In case of a
// Optionally parse a function identifier.
if (isDirect)
- if (parser->parseFunctionName(calleeName, calleeLoc))
+ if (parser->parseAttribute(funcAttr, "callee", attrs))
return failure();
if (parser->parseOperandList(operands, /*requiredOperandCount=*/-1,
if (!funcType)
return parser->emitError(trailingTypeLoc, "expected function type");
if (isDirect) {
- // Add the direct callee as an Op attribute.
- auto funcAttr = parser->getBuilder().getFunctionAttr(calleeName);
- attrs.push_back(parser->getBuilder().getNamedAttr("callee", funcAttr));
-
// Make sure types match.
if (parser->resolveOperands(operands, funcType.getInputs(),
parser->getNameLoc(), result->operands))
return parser.parseAttributeDict(result);
}
- /// Parse a function name like '@foo' and return the name in a form that can
- /// be passed to resolveFunctionName when a function type is available.
- ParseResult parseFunctionName(StringRef &result, llvm::SMLoc &loc) override {
- if (parseOptionalFunctionName(result, loc))
- return emitError(loc, "expected function name");
- return success();
- }
-
- /// Parse a function name like '@foo` if present and return the name without
- /// the sigil in `result`. Return true if the next token is not a function
- /// name and keep `result` unchanged.
- ParseResult parseOptionalFunctionName(StringRef &result,
- llvm::SMLoc &loc) override {
- loc = parser.getToken().getLoc();
-
- if (parser.getToken().isNot(Token::at_identifier))
- return failure();
-
- result = parser.getTokenSpelling().drop_front();
- parser.consumeToken(Token::at_identifier);
- return success();
- }
-
ParseResult parseOperand(OperandType &result) override {
FunctionParser::SSAUseInfo useInfo;
if (parser.parseSSAUse(useInfo))
//===----------------------------------------------------------------------===//
static ParseResult parseCallOp(OpAsmParser *parser, OperationState *result) {
- StringRef calleeName;
- llvm::SMLoc calleeLoc;
+ FunctionAttr calleeAttr;
FunctionType calleeType;
SmallVector<OpAsmParser::OperandType, 4> operands;
- if (parser->parseFunctionName(calleeName, calleeLoc) ||
+ auto calleeLoc = parser->getNameLoc();
+ if (parser->parseAttribute(calleeAttr, "callee", result->attributes) ||
parser->parseOperandList(operands, /*requiredOperandCount=*/-1,
OpAsmParser::Delimiter::Paren) ||
parser->parseOptionalAttributeDict(result->attributes) ||
result->operands))
return failure();
- result->addAttribute("callee",
- parser->getBuilder().getFunctionAttr(calleeName));
return success();
}