CIRCT 20.0.0git
Loading...
Searching...
No Matches
CustomDirectiveImpl.h
Go to the documentation of this file.
1//===- CustomDirectiveImpl.h - Custom TableGen directives -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides common custom directives for table-gen assembly formats.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_SUPPORT_CUSTOMDIRECTIVEIMPL_H
14#define CIRCT_SUPPORT_CUSTOMDIRECTIVEIMPL_H
15
16#include "circt/Support/LLVM.h"
17#include "mlir/IR/Builders.h"
18#include "mlir/IR/OpImplementation.h"
19
20namespace circt {
21
22//===----------------------------------------------------------------------===//
23// ImplicitSSAName Custom Directive
24//===----------------------------------------------------------------------===//
25
26/// Parse an implicit SSA name string attribute. If the name is not provided in
27/// the input text, its value is inferred from the SSA name of the operation's
28/// first result.
29///
30/// implicit-name ::= (`name` str-attr)?
31ParseResult parseImplicitSSAName(OpAsmParser &parser, StringAttr &attr);
32
33/// Parse an attribute dictionary and ensure that it contains a `name` field by
34/// inferring its value from the SSA name of the operation's first result if
35/// necessary.
36ParseResult parseImplicitSSAName(OpAsmParser &parser, NamedAttrList &attrs);
37
38/// Ensure that `attrs` contains a `name` attribute by inferring its value from
39/// the SSA name of the operation's first result if necessary. Returns true if a
40/// name was inferred, false if `attrs` already contained a `name`.
41bool inferImplicitSSAName(OpAsmParser &parser, NamedAttrList &attrs);
42
43/// Print an implicit SSA name string attribute. If the given string attribute
44/// does not match the SSA name of the operation's first result, the name is
45/// explicitly printed. Prints a leading space in front of `name` if any name is
46/// present.
47///
48/// implicit-name ::= (`name` str-attr)?
49void printImplicitSSAName(OpAsmPrinter &p, Operation *op, StringAttr attr);
50
51/// Print an attribute dictionary and elide the `name` field if its value
52/// matches the SSA name of the operation's first result.
53void printImplicitSSAName(OpAsmPrinter &p, Operation *op, DictionaryAttr attrs,
54 ArrayRef<StringRef> extraElides = {});
55
56/// Check if the `name` attribute in `attrs` matches the SSA name of the
57/// operation's first result. If it does, add `name` to `elides`. This is
58/// helpful during printing of attribute dictionaries in order to determine if
59/// the inclusion of the `name` field would be redundant.
60void elideImplicitSSAName(OpAsmPrinter &printer, Operation *op,
61 DictionaryAttr attrs,
62 SmallVectorImpl<StringRef> &elides);
63
64/// Print/parse binary operands type only when types are different.
65/// optional-bin-op-types := type($lhs) (, type($rhs))?
66void printOptionalBinaryOpTypes(OpAsmPrinter &p, Operation *op, Type lhs,
67 Type rhs);
68ParseResult parseOptionalBinaryOpTypes(OpAsmParser &parser, Type &lhs,
69 Type &rhs);
70
71//===----------------------------------------------------------------------===//
72// KeywordBool Custom Directive
73//===----------------------------------------------------------------------===//
74
75/// Parse a boolean as one of two keywords. The `trueKeyword` will result in a
76/// true boolean; the `falseKeyword` will result in a false boolean.
77///
78/// labeled-bool ::= (true-label | false-label)
79ParseResult parseKeywordBool(OpAsmParser &parser, BoolAttr &attr,
80 StringRef trueKeyword, StringRef falseKeyword);
81
82/// Print a boolean as one of two keywords. If the boolean is true, the
83/// `trueKeyword` is used; if it is false, the `falseKeyword` is used.
84///
85/// labeled-bool ::= (true-label | false-label)
86void printKeywordBool(OpAsmPrinter &printer, Operation *op, BoolAttr attr,
87 StringRef trueKeyword, StringRef falseKeyword);
88
89} // namespace circt
90
91#endif // CIRCT_SUPPORT_CUSTOMDIRECTIVEIMPL_H
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
ParseResult parseKeywordBool(OpAsmParser &parser, BoolAttr &attr, StringRef trueKeyword, StringRef falseKeyword)
Parse a boolean as one of two keywords.
void printOptionalBinaryOpTypes(OpAsmPrinter &p, Operation *op, Type lhs, Type rhs)
Print/parse binary operands type only when types are different.
void elideImplicitSSAName(OpAsmPrinter &printer, Operation *op, DictionaryAttr attrs, SmallVectorImpl< StringRef > &elides)
Check if the name attribute in attrs matches the SSA name of the operation's first result.
ParseResult parseImplicitSSAName(OpAsmParser &parser, StringAttr &attr)
Parse an implicit SSA name string attribute.
void printKeywordBool(OpAsmPrinter &printer, Operation *op, BoolAttr attr, StringRef trueKeyword, StringRef falseKeyword)
Print a boolean as one of two keywords.
bool inferImplicitSSAName(OpAsmParser &parser, NamedAttrList &attrs)
Ensure that attrs contains a name attribute by inferring its value from the SSA name of the operation...
void printImplicitSSAName(OpAsmPrinter &p, Operation *op, StringAttr attr)
Print an implicit SSA name string attribute.
ParseResult parseOptionalBinaryOpTypes(OpAsmParser &parser, Type &lhs, Type &rhs)