Skip to content

Commit

Permalink
Add support for constraint blocks in macros (`uvm_do_with)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmlarumbe committed Aug 11, 2024
1 parent 260cd0b commit 94861a8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
11 changes: 10 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4531,7 +4531,11 @@ const rules = {

list_of_actual_arguments: $ => list_of_args($, 'list_of_arguments', $.actual_argument),

actual_argument: $ => $.param_expression, // Out of LRM, needed to support parameterized data types as macro args (common in the UVM)
actual_argument: $ => choice(
// Out of LRM, needed to support parameterized data types and constraints as macro args (common in the UVM)
$.param_expression, // e.g: `uvm_component_utils_param
$.constraint_block // e.g: `uvm_do_with
),

undefine_compiler_directive: $ => seq(directive('undef'), $.text_macro_identifier),

Expand Down Expand Up @@ -6029,6 +6033,11 @@ module.exports = grammar({
[$.sequence_instance, $.tf_call, $.constant_primary, $.hierarchical_identifier],
[$.sequence_instance, $.tf_call, $.hierarchical_identifier],
[$.sequence_instance, $.tf_call],


// Allow constraint blocks on text_macro_usage
[$.constraint_block, $.empty_unpacked_array_concatenation],

],

});
Expand Down
49 changes: 49 additions & 0 deletions test/corpus/core/directives/uvm_do_with.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
============================================
core/directives/uvm_do_with
============================================

`uvm_do_with(arg, { x == 1; y == 2; });

----

(source_file
(text_macro_usage
(simple_identifier)
(list_of_actual_arguments
(actual_argument
(param_expression
(mintypmax_expression
(expression
(primary
(hierarchical_identifier
(simple_identifier)))))))
(actual_argument
(constraint_block
(constraint_block_item
(constraint_expression
(expression_or_dist
(expression
left: (expression
(primary
(hierarchical_identifier
(simple_identifier))))
right: (expression
(primary
(primary_literal
(integral_number
(decimal_number
(unsigned_number))))))))))
(constraint_block_item
(constraint_expression
(expression_or_dist
(expression
left: (expression
(primary
(hierarchical_identifier
(simple_identifier))))
right: (expression
(primary
(primary_literal
(integral_number
(decimal_number
(unsigned_number)))))))))))))))
1 change: 1 addition & 0 deletions test/files/core/directives/uvm_do_with.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`uvm_do_with(arg, { x == 1; y == 2; });

0 comments on commit 94861a8

Please sign in to comment.