Added comment token · Wheest/llvm-project@0cb9de9 (original) (raw)
`@@ -561,6 +561,9 @@ class OperationParser : public Parser {
`
561
561
`/// Parse an operation instance that is in the generic form.
`
562
562
` Operation *parseGenericOperation();
`
563
563
``
``
564
`+
/// Parse a comment
`
``
565
`+
Operation *parseComment();
`
``
566
+
564
567
`/// Parse different components, viz., use-info of operand(s), successor(s),
`
565
568
`/// region(s), attribute(s) and function-type, of the generic form of an
`
566
569
`/// operation instance and populate the input operation-state 'result' with
`
`@@ -1184,8 +1187,7 @@ ParseResult OperationParser::parseOperation() {
`
1184
1187
`else if (nameTok.isCodeCompletion())
`
1185
1188
`return codeCompleteDialectOrElidedOpName(loc);
`
1186
1189
`else if (nameTok.is(Token::line_comment)) {
`
1187
``
`-
// Empty case, no action taken
`
1188
``
`-
op = parseGenericOperation();
`
``
1190
`+
op = parseComment();
`
1189
1191
` } else
`
1190
1192
`return emitWrongTokenError("expected operation name in quotes");
`
1191
1193
``
`@@ -1399,6 +1401,25 @@ ParseResult OperationParser::parseGenericOperationAfterOpName(
`
1399
1401
`return success();
`
1400
1402
`}
`
1401
1403
``
``
1404
`+
Operation *OperationParser::parseComment() {
`
``
1405
`+
Token tok = getToken();
`
``
1406
`+
auto srcLocation = getEncodedSourceLocation(getToken().getLoc());
`
``
1407
`+
StringRef bytes = tok.getSpelling();
`
``
1408
`+
std::string comment;
`
``
1409
`+
comment.reserve(bytes.size());
`
``
1410
`+
for (unsigned i = 0, e = bytes.size(); i != e;) {
`
``
1411
`+
auto c = bytes[i++];
`
``
1412
`+
comment.push_back(c);
`
``
1413
`+
}
`
``
1414
+
``
1415
`+
consumeToken(Token::line_comment);
`
``
1416
+
``
1417
`+
OperationState result(srcLocation, comment);
`
``
1418
`+
CleanupOpStateRegions guard{result};
`
``
1419
`+
Operation *op = opBuilder.create(result);
`
``
1420
`+
return op;
`
``
1421
`+
}
`
``
1422
+
1402
1423
`Operation *OperationParser::parseGenericOperation() {
`
1403
1424
`// Get location information for the operation.
`
1404
1425
`auto srcLocation = getEncodedSourceLocation(getToken().getLoc());
`
`@@ -1440,26 +1461,26 @@ Operation *OperationParser::parseGenericOperation() {
`
1440
1461
`if (parseGenericOperationAfterOpName(result))
`
1441
1462
`return nullptr;
`
1442
1463
``
1443
``
`-
// Operation::create() is not allowed to fail, however setting the properties
`
1444
``
`-
// from an attribute is a failable operation. So we save the attribute here
`
1445
``
`-
// and set it on the operation post-parsing.
`
``
1464
`+
// Operation::create() is not allowed to fail, however setting the
`
``
1465
`+
// properties from an attribute is a failable operation. So we save the
`
``
1466
`+
// attribute here and set it on the operation post-parsing.
`
1446
1467
` Attribute properties;
`
1447
1468
`std::swap(properties, result.propertiesAttr);
`
1448
1469
``
1449
1470
`// If we don't have properties in the textual IR, but the operation now has
`
1450
``
`-
// support for properties, we support some backward-compatible generic syntax
`
1451
``
`-
// for the operation and as such we accept inherent attributes mixed in the
`
1452
``
`-
// dictionary of discardable attributes. We pre-validate these here because
`
1453
``
`-
// invalid attributes can't be casted to the properties storage and will be
`
1454
``
`-
// silently dropped. For example an attribute { foo = 0 : i32 } that is
`
1455
``
`-
// declared as F32Attr in ODS would have a C++ type of FloatAttr in the
`
``
1471
`+
// support for properties, we support some backward-compatible generic
`
``
1472
`+
// syntax for the operation and as such we accept inherent attributes mixed
`
``
1473
`+
// in the dictionary of discardable attributes. We pre-validate these here
`
``
1474
`+
// because invalid attributes can't be casted to the properties storage and
`
``
1475
`+
// will be silently dropped. For example an attribute { foo = 0 : i32 } that
`
``
1476
`+
// is declared as F32Attr in ODS would have a C++ type of FloatAttr in the
`
1456
1477
`// properties array. When setting it we would do something like:
`
1457
1478
`//
`
1458
1479
`// properties.foo = dyn_cast(fooAttr);
`
1459
1480
`//
`
1460
``
`-
// which would end up with a null Attribute. The diagnostic from the verifier
`
1461
``
`-
// would be "missing foo attribute" instead of something like "expects a 32
`
1462
``
`-
// bits float attribute but got a 32 bits integer attribute".
`
``
1481
`+
// which would end up with a null Attribute. The diagnostic from the
`
``
1482
`+
// verifier would be "missing foo attribute" instead of something like
`
``
1483
`+
// "expects a 32 bits float attribute but got a 32 bits integer attribute".
`
1463
1484
`if (!properties && !result.getRawProperties()) {
`
1464
1485
` std::optional info =
`
1465
1486
` result.name.getRegisteredInfo();
`
`@@ -1589,8 +1610,8 @@ class CustomOpAsmParser : public AsmParserImpl {
`
1589
1610
`return {"", ~0U};
`
1590
1611
` }
`
1591
1612
``
1592
``
`-
/// Return the number of declared SSA results. This returns 4 for the foo.op
`
1593
``
`-
/// example in the comment for getResultName.
`
``
1613
`+
/// Return the number of declared SSA results. This returns 4 for the
`
``
1614
`+
/// foo.op example in the comment for getResultName.
`
1594
1615
`size_t getNumResults() const override {
`
1595
1616
`size_t count = 0;
`
1596
1617
`for (auto &entry : resultIDs)
`
`@@ -1628,8 +1649,8 @@ class CustomOpAsmParser : public AsmParserImpl {
`
1628
1649
`return std::nullopt;
`
1629
1650
` }
`
1630
1651
``
1631
``
`-
/// Parse zero or more SSA comma-separated operand references with a specified
`
1632
``
`-
/// surrounding delimiter, and an optional required operand count.
`
``
1652
`+
/// Parse zero or more SSA comma-separated operand references with a
`
``
1653
`+
/// specified surrounding delimiter, and an optional required operand count.
`
1633
1654
` ParseResult parseOperandList(SmallVectorImpl &result,
`
1634
1655
` Delimiter delimiter = Delimiter::None,
`
1635
1656
`bool allowResultNumber = true,
`
`@@ -1781,7 +1802,8 @@ class CustomOpAsmParser : public AsmParserImpl {
`
1781
1802
`//===--------------------------------------------------------------------===//
`
1782
1803
``
1783
1804
`` /// Parse a region that takes arguments of argTypes types. This
``
1784
``
`` -
/// effectively defines the SSA values of arguments and assigns their type.
``
``
1805
`` +
/// effectively defines the SSA values of arguments and assigns their
``
``
1806
`+
/// type.
`
1785
1807
` ParseResult parseRegion(Region ®ion, ArrayRef arguments,
`
1786
1808
`bool enableNameShadowing) override {
`
1787
1809
`// Try to parse the region.
`
`@@ -2150,8 +2172,8 @@ ParseResult OperationParser::parseRegionBody(Region ®ion, SMLoc startLoc,
`
2150
2172
` Block *block = owningBlock.get();
`
2151
2173
``
2152
2174
`// If this block is not defined in the source file, add a definition for it
`
2153
``
`-
// now in the assembly state. Blocks with a name will be defined when the name
`
2154
``
`-
// is parsed.
`
``
2175
`+
// now in the assembly state. Blocks with a name will be defined when the
`
``
2176
`+
// name is parsed.
`
2155
2177
`if (state.asmState && getToken().isNot(Token::caret_identifier))
`
2156
2178
` state.asmState->addDefinition(block, startLoc);
`
2157
2179
``
`@@ -2259,15 +2281,15 @@ ParseResult OperationParser::parseBlock(Block *&block) {
`
2259
2281
` blockAndLoc.block = inflightBlock.get();
`
2260
2282
` }
`
2261
2283
``
2262
``
`-
// Otherwise, the block has a forward declaration. Forward declarations are
`
2263
``
`-
// removed once defined, so if we are defining a existing block and it is
`
2264
``
`-
// not a forward declaration, then it is a redeclaration. Fail if the block
`
2265
``
`-
// was already defined.
`
``
2284
`+
// Otherwise, the block has a forward declaration. Forward declarations
`
``
2285
`+
// are removed once defined, so if we are defining a existing block and it
`
``
2286
`+
// is not a forward declaration, then it is a redeclaration. Fail if the
`
``
2287
`+
// block was already defined.
`
2266
2288
` } else if (!eraseForwardRef(blockAndLoc.block)) {
`
2267
2289
`return emitError(nameLoc, "redefinition of block '") << name << "'";
`
2268
2290
` } else {
`
2269
``
`-
// This was a forward reference block that is now floating. Keep track of it
`
2270
``
`-
// as inflight in case of error, so that it gets cleaned up properly.
`
``
2291
`+
// This was a forward reference block that is now floating. Keep track of
`
``
2292
`+
// it as inflight in case of error, so that it gets cleaned up properly.
`
2271
2293
` inflightBlock.reset(blockAndLoc.block);
`
2272
2294
` }
`
2273
2295
``
`@@ -2286,8 +2308,8 @@ ParseResult OperationParser::parseBlock(Block *&block) {
`
2286
2308
`// Parse the body of the block.
`
2287
2309
` ParseResult res = parseBlockBody(block);
`
2288
2310
``
2289
``
`-
// If parsing was successful, drop the inflight block. We relinquish ownership
`
2290
``
`-
// back up to the caller.
`
``
2311
`+
// If parsing was successful, drop the inflight block. We relinquish
`
``
2312
`+
// ownership back up to the caller.
`
2291
2313
`if (succeeded(res))
`
2292
2314
` (void)inflightBlock.release();
`
2293
2315
`return res;
`
`@@ -2322,8 +2344,8 @@ Block *OperationParser::getBlockNamed(StringRef name, SMLoc loc) {
`
2322
2344
`return blockDef.block;
`
2323
2345
`}
`
2324
2346
``
2325
``
`-
/// Parse a (possibly empty) list of SSA operands with types as block arguments
`
2326
``
`-
/// enclosed in parentheses.
`
``
2347
`+
/// Parse a (possibly empty) list of SSA operands with types as block
`
``
2348
`+
/// arguments enclosed in parentheses.
`
2327
2349
`///
`
2328
2350
`` /// value-id-and-type-list ::= value-id-and-type (, ssa-id-and-type)*
``
2329
2351
`` /// block-arg-list ::= ( value-id-and-type-list? )
``
`@@ -2386,8 +2408,8 @@ ParseResult OperationParser::codeCompleteSSAUse() {
`
2386
2408
`continue;
`
2387
2409
` Value frontValue = it.second.front().value;
`
2388
2410
``
2389
``
`-
// If the value isn't a forward reference, we also add the name of the op
`
2390
``
`-
// to the detail.
`
``
2411
`+
// If the value isn't a forward reference, we also add the name of the
`
``
2412
`+
// op to the detail.
`
2391
2413
`if (auto result = dyn_cast(frontValue)) {
`
2392
2414
`if (!forwardRefPlaceholders.count(result))
`
2393
2415
` detailOS << result.getOwner()->getName() << ": ";
`
`@@ -2400,8 +2422,8 @@ ParseResult OperationParser::codeCompleteSSAUse() {
`
2400
2422
` detailOS << frontValue.getType();
`
2401
2423
``
2402
2424
`// FIXME: We should define a policy for packed values, e.g. with a limit
`
2403
``
`-
// on the detail size, but it isn't clear what would be useful right now.
`
2404
``
`-
// For now we just only emit the first type.
`
``
2425
`+
// on the detail size, but it isn't clear what would be useful right
`
``
2426
`+
// now. For now we just only emit the first type.
`
2405
2427
`if (it.second.size() > 1)
`
2406
2428
` detailOS << ", ...";
`
2407
2429
``