@felixtensor/tree-sitter-mlir 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/grammar.js +35 -11
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/@felixtensor+tree-sitter-mlir.node +0 -0
- package/prebuilds/darwin-x64/@felixtensor+tree-sitter-mlir.node +0 -0
- package/prebuilds/linux-arm64/@felixtensor+tree-sitter-mlir.node +0 -0
- package/prebuilds/linux-x64/@felixtensor+tree-sitter-mlir.node +0 -0
- package/prebuilds/win32-arm64/@felixtensor+tree-sitter-mlir.node +0 -0
- package/prebuilds/win32-x64/@felixtensor+tree-sitter-mlir.node +0 -0
- package/src/grammar.json +297 -122
- package/src/node-types.json +53 -0
- package/src/parser.c +37800 -33770
- package/tree-sitter-mlir.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
[](https://github.com/felixtensor/tree-sitter-mlir/actions/workflows/ci.yml)
|
|
4
4
|
[](https://crates.io/crates/tree-sitter-mlir)
|
|
5
5
|
[](https://pypi.org/project/tree-sitter-mlir/)
|
|
6
|
+
[](https://www.npmjs.com/package/@felixtensor/tree-sitter-mlir)
|
|
6
7
|
|
|
7
8
|
[MLIR](https://mlir.llvm.org) grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
|
|
8
9
|
|
package/grammar.js
CHANGED
|
@@ -50,6 +50,8 @@ export default grammar({
|
|
|
50
50
|
_digit: $ => /[0-9]/,
|
|
51
51
|
integer_literal: $ => choice($._decimal_literal, $._hexadecimal_literal),
|
|
52
52
|
_decimal_literal: $ => token(seq(optional(/[-+]/), repeat1(/[0-9]/))),
|
|
53
|
+
_unsigned_decimal_literal: $ => token(repeat1(/[0-9]/)),
|
|
54
|
+
_unsigned_integer_literal: $ => choice($._unsigned_decimal_literal, $._hexadecimal_literal),
|
|
53
55
|
_hexadecimal_literal: $ => token(seq('0x', repeat1(/[0-9a-fA-F]/))),
|
|
54
56
|
float_literal: $ => token(seq(
|
|
55
57
|
optional(/[-+]/), repeat1(/[0-9]/), '.', repeat(/[0-9]/),
|
|
@@ -182,6 +184,15 @@ export default grammar({
|
|
|
182
184
|
func_operation: $ => prec.right(seq(
|
|
183
185
|
field('name', choice(token(prec(20, 'func.func')), token(prec(20, 'llvm.func')))),
|
|
184
186
|
field('visibility', optional(choice('private', 'public'))),
|
|
187
|
+
// Optional leading specifier keywords between the function name and its
|
|
188
|
+
// symbol. Covers MLIR symbol visibility (`nested`) and the LLVM dialect's
|
|
189
|
+
// llvm.func linkage / calling-convention / unnamed_addr / visibility
|
|
190
|
+
// keywords (internal, external, linkonce, fastcc, amdgpu_kernelcc,
|
|
191
|
+
// local_unnamed_addr, hidden, ...). MLIR's CConv enum alone has ~50
|
|
192
|
+
// keywords, so rather than enumerate a brittle list we accept bare_id-
|
|
193
|
+
// shaped specifiers here; the trailing `@symbol` (symbol_ref_id) is an
|
|
194
|
+
// unambiguous terminator.
|
|
195
|
+
repeat(field('specifier', alias($.bare_id, $.function_specifier))),
|
|
185
196
|
field('sym_name', $.symbol_ref_id),
|
|
186
197
|
field('arguments', $.func_arg_list),
|
|
187
198
|
field('return', optional($.func_return)),
|
|
@@ -250,18 +261,22 @@ export default grammar({
|
|
|
250
261
|
prec(2, $.type), // !type, i32, memref<...>, etc.
|
|
251
262
|
$.attribute, // #attr, {dict}, affine_map<...>
|
|
252
263
|
$.region, // { ... } (regions with operations)
|
|
264
|
+
$._custom_body_value_group, // {%v : type, ...}
|
|
253
265
|
$._custom_body_paren, // ( ... )
|
|
254
266
|
$._custom_body_bracket, // [ ... ]
|
|
255
267
|
$._custom_body_angle_group, // < ... >
|
|
256
268
|
$._literal, // 42, 3.14, "string", true, dense<...>
|
|
257
269
|
'array', // property names may collide with array<...>
|
|
270
|
+
'vector', // OpenACC keyword may collide with vector<...>
|
|
258
271
|
'ceildiv', 'floordiv', 'mod', // inline affine keywords
|
|
259
272
|
$.bare_id, // keywords: to, from, step, ins, outs, etc.
|
|
260
|
-
',', '=', ':', '->', '*', '+', '-', '/', '&', '|', '~',
|
|
273
|
+
',', '=', ':', '->', '*', '?', $.dimension_separator, '+', '-', '/', '&', '|', '~',
|
|
261
274
|
),
|
|
262
275
|
|
|
263
276
|
_custom_body_paren: $ => seq('(', repeat($._nested_custom_body_element), ')'),
|
|
264
277
|
_custom_body_bracket: $ => seq('[', repeat($._nested_custom_body_element), ']'),
|
|
278
|
+
_custom_body_value_group: $ => seq('{', $.value_use, ':', $.type,
|
|
279
|
+
repeat(seq(',', $.value_use, ':', $.type)), '}'),
|
|
265
280
|
_custom_body_angle_group: $ => seq('<', repeat($._nested_custom_body_element), '>'),
|
|
266
281
|
// Only nested groups accept `trailing_location` as a body element.
|
|
267
282
|
// At the top level it is omitted on purpose so the operation rule
|
|
@@ -271,11 +286,11 @@ export default grammar({
|
|
|
271
286
|
|
|
272
287
|
// =========================================================================
|
|
273
288
|
// Blocks
|
|
274
|
-
// block ::= block-label operation
|
|
289
|
+
// block ::= block-label operation*
|
|
275
290
|
// block-label ::= block-id block-arg-list? `:`
|
|
276
291
|
// caret-id ::= `^` suffix-id
|
|
277
292
|
// =========================================================================
|
|
278
|
-
block: $ => seq($.block_label,
|
|
293
|
+
block: $ => seq($.block_label, repeat($.operation)),
|
|
279
294
|
block_label: $ => seq($._block_id, optional($.block_arg_list), ':'),
|
|
280
295
|
_block_id: $ => $.caret_id,
|
|
281
296
|
caret_id: $ => seq('^', $._suffix_id),
|
|
@@ -336,9 +351,9 @@ export default grammar({
|
|
|
336
351
|
$.type,
|
|
337
352
|
prec(2, $.attribute),
|
|
338
353
|
$._literal,
|
|
339
|
-
'dense', 'sparse', 'array',
|
|
354
|
+
'dense', 'sparse', 'array', 'vector', 'tensor', 'opaque',
|
|
340
355
|
$.bare_id,
|
|
341
|
-
',', ':', '=', '->', '(', ')', '[', ']', '{', '}', '*',
|
|
356
|
+
',', ':', '=', '->', '(', ')', '[', ']', '{', '}', '*', '?',
|
|
342
357
|
'@', '#',
|
|
343
358
|
token(prec(-1, /[^<>]/))
|
|
344
359
|
)),
|
|
@@ -357,9 +372,13 @@ export default grammar({
|
|
|
357
372
|
repeat1(seq($.dimension_separator, $._dialect_dim_primitive)))),
|
|
358
373
|
_dialect_dim_primitive: $ => choice(
|
|
359
374
|
prec(1, $.type),
|
|
375
|
+
prec(1, $._pretty_dialect_body_type),
|
|
360
376
|
alias($.integer_literal, $.dimension_size),
|
|
361
377
|
'?',
|
|
362
378
|
'*'),
|
|
379
|
+
_pretty_dialect_body_type: $ => seq(
|
|
380
|
+
choice($.bare_id, 'array'),
|
|
381
|
+
$.pretty_dialect_item_body),
|
|
363
382
|
|
|
364
383
|
// Builtin types
|
|
365
384
|
builtin_type: $ => choice(
|
|
@@ -400,7 +419,7 @@ export default grammar({
|
|
|
400
419
|
optional(seq(',', $.tensor_encoding)), '>'),
|
|
401
420
|
tensor_encoding: $ => $.attribute_value,
|
|
402
421
|
|
|
403
|
-
vector_type: $ => seq(token('vector'), '<', repeat($.vector_dim_list), $._prim_type, '>'),
|
|
422
|
+
vector_type: $ => prec(1, seq(token('vector'), '<', repeat($.vector_dim_list), $._prim_type, '>')),
|
|
404
423
|
vector_dim_list: $ => prec.left(choice(seq($._static_dim_list, 'x',
|
|
405
424
|
optional(seq('[', $._static_dim_list, ']', 'x'))), seq('[', $._static_dim_list, ']', 'x'))),
|
|
406
425
|
_static_dim_list: $ => seq($.dimension_size, repeat(seq('x', $.dimension_size))),
|
|
@@ -420,11 +439,12 @@ export default grammar({
|
|
|
420
439
|
attribute_entry: $ => choice(
|
|
421
440
|
seq(choice($.bare_id, $.string_literal), optional(seq('=', $.attribute_value))),
|
|
422
441
|
// Array-valued entry (e.g. {["op.name"]} in transform dialect)
|
|
423
|
-
|
|
424
|
-
repeat(seq(',', $._attribute_value_nobracket)), ']'),
|
|
442
|
+
$._attribute_array,
|
|
425
443
|
),
|
|
426
|
-
attribute_value: $ => choice(
|
|
427
|
-
|
|
444
|
+
attribute_value: $ => choice($._attribute_array, $._attribute_value_nobracket),
|
|
445
|
+
_attribute_array: $ => seq('[', optional($._attribute_array_element),
|
|
446
|
+
repeat(seq(',', $._attribute_array_element)), ']'),
|
|
447
|
+
_attribute_array_element: $ => choice($._attribute_array, $._attribute_value_nobracket),
|
|
428
448
|
_attribute_value_nobracket: $ => choice($.attribute_alias, $.dialect_attribute,
|
|
429
449
|
$.builtin_attribute, $.dictionary_attribute, $._literal_and_type, $.type,
|
|
430
450
|
$.function_type, $._affine_map_like, $.symbol_ref_id, $.trailing_location,
|
|
@@ -445,9 +465,13 @@ export default grammar({
|
|
|
445
465
|
prec(1, $.affine_map),
|
|
446
466
|
prec(1, $.affine_set),
|
|
447
467
|
$.dense_resource_literal,
|
|
468
|
+
$.distinct_attribute,
|
|
448
469
|
),
|
|
449
470
|
dense_resource_literal: $ => seq(token('dense_resource'), '<',
|
|
450
471
|
choice($.bare_id, $.string_literal), '>'),
|
|
472
|
+
distinct_attribute: $ => seq(token('distinct'), '[',
|
|
473
|
+
alias($._unsigned_integer_literal, $.integer_literal), ']',
|
|
474
|
+
'<', optional($.attribute_value), '>'),
|
|
451
475
|
strided_layout: $ => seq(token('strided'), '<', '[', optional($._stride_list_comma), ']',
|
|
452
476
|
optional(seq(',', token('offset'), ':', $._stride_primitive)), '>'),
|
|
453
477
|
_stride_list_comma: $ => seq($._stride_primitive, repeat(seq(',', $._stride_primitive))),
|
|
@@ -485,7 +509,7 @@ export default grammar({
|
|
|
485
509
|
func_arg_list: $ => seq('(', optional(choice($.variadic,
|
|
486
510
|
$._value_id_and_type_attr_list)), ')'),
|
|
487
511
|
_value_id_and_type_attr_list: $ => seq($._value_id_and_type_attr,
|
|
488
|
-
repeat(seq(',', $._value_id_and_type_attr
|
|
512
|
+
repeat(seq(',', choice($._value_id_and_type_attr, $.variadic)))),
|
|
489
513
|
_value_id_and_type_attr: $ => seq($._function_arg, optional($.attribute),
|
|
490
514
|
optional($.trailing_location)),
|
|
491
515
|
_function_arg: $ => choice(seq($.value_use, ':', choice($.type, $.function_type)), $.value_use, $.type, $.function_type),
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|