Use "(id)" instead of "id" for types as temporary hack
authorClifford Wolf <clifford@clifford.at>
Mon, 14 Oct 2019 03:24:31 +0000 (05:24 +0200)
committerClifford Wolf <clifford@clifford.at>
Mon, 14 Oct 2019 03:24:31 +0000 (05:24 +0200)
Signed-off-by: Clifford Wolf <clifford@clifford.at>
12 files changed:
1  2 
Makefile
frontends/ast/ast.cc
frontends/ast/ast.h
frontends/verilog/verilog_parser.y
tests/svtypes/typedef_memory.sv
tests/svtypes/typedef_memory.ys
tests/svtypes/typedef_memory_2.sv
tests/svtypes/typedef_memory_2.ys
tests/svtypes/typedef_package.sv
tests/svtypes/typedef_param.sv
tests/svtypes/typedef_scopes.sv
tests/svtypes/typedef_simple.sv

diff --cc Makefile
Simple merge
Simple merge
Simple merge
index 4afd72b734b2aadebaf75d86683e8928f29b87e4,0024d47789c33b27d57bb1a4d40f149409f1209f..77f6d2051c32294fa82e15161114f4ba7479f946
@@@ -154,8 -158,8 +154,8 @@@ struct specify_rise_fall 
  %token TOK_INCREMENT TOK_DECREMENT TOK_UNIQUE TOK_PRIORITY
  
  %type <ast> range range_or_multirange  non_opt_range non_opt_multirange range_or_signed_int
 -%type <ast> wire_type wire_type_io expr basic_expr concat_list rvalue lvalue lvalue_concat_list
 -%type <string> opt_label opt_sva_label tok_prim_wrapper hierarchical_id
 +%type <ast> wire_type expr basic_expr concat_list rvalue lvalue lvalue_concat_list
- %type <string> opt_label opt_sva_label tok_prim_wrapper hierarchical_id
++%type <string> opt_label opt_sva_label tok_prim_wrapper hierarchical_id hierarchical_type_id
  %type <boolean> opt_signed opt_property unique_case_attr
  %type <al> attr case_attr
  
@@@ -290,6 -295,6 +291,9 @@@ hierarchical_id
                $$ = $1;
        };
  
++hierarchical_type_id:
++      '(' hierarchical_id ')' { $$ = $2; };
++
  module:
        attr TOK_MODULE TOK_ID {
                do_not_require_port_stubs = false;
@@@ -324,13 -329,13 +328,13 @@@ single_module_para
                astbuf1 = new AstNode(AST_PARAMETER);
                astbuf1->children.push_back(AstNode::mkconst_int(0, true));
                append_attr(astbuf1, $1);
-       } param_signed param_integer param_range single_param_decl |
 -      } int_param_type single_param_decl |
++      } param_type single_param_decl |
        attr TOK_LOCALPARAM {
                if (astbuf1) delete astbuf1;
                astbuf1 = new AstNode(AST_LOCALPARAM);
                astbuf1->children.push_back(AstNode::mkconst_int(0, true));
                append_attr(astbuf1, $1);
-       } param_signed param_integer param_range single_param_decl |
 -      } int_param_type single_param_decl |
++      } param_type single_param_decl |
        single_param_decl;
  
  module_args_opt:
@@@ -474,9 -480,18 +479,15 @@@ wire_type
                $$ = astbuf3;
        };
  
 -wire_type_io:
 -      {
 -              astbuf3 = new AstNode(AST_WIRE);
 -              current_wire_rand = false;
 -              current_wire_const = false;
 -      } io_wire_type_token_list delay {
 -              $$ = astbuf3;
 -      };
 -
  wire_type_token_list:
--      wire_type_token | wire_type_token_list wire_type_token |
--      wire_type_token_io ;
++      wire_type_token |
++      wire_type_token_list wire_type_token |
++      wire_type_token_io |
++      hierarchical_type_id {
++              astbuf3->is_custom_type = true;
++              astbuf3->children.push_back(new AstNode(AST_WIRETYPE));
++              astbuf3->children.back()->str = *$1;
++      };
  
  wire_type_token_io:
        TOK_INPUT {
@@@ -591,7 -617,7 +602,7 @@@ module_body
        /* empty */;
  
  module_body_stmt:
-       task_func_decl | specify_block |param_decl | localparam_decl | defparam_decl | specparam_declaration | wire_decl | assign_stmt | cell_stmt |
 -      task_func_decl | specify_block |param_decl | localparam_decl | typedef_decl | defparam_decl | specparam_declaration | wire_decl | assign_stmt | cell_stmt |
++      task_func_decl | specify_block | param_decl | localparam_decl | typedef_decl | defparam_decl | specparam_declaration | wire_decl | assign_stmt | cell_stmt |
        always_stmt | TOK_GENERATE module_gen_body TOK_ENDGENERATE | defattr | assert_property | checker_decl | ignored_specify_block;
  
  checker_decl:
@@@ -1149,6 -1175,19 +1160,14 @@@ param_range
                }
        };
  
 -custom_param_type:
 -      hierarchical_id {
++param_type:
++      param_signed param_integer param_real param_range |
++      hierarchical_type_id {
+               astbuf1->is_custom_type = true;
+               astbuf1->children.push_back(new AstNode(AST_WIRETYPE));
+               astbuf1->children.back()->str = *$1;
+       };
 -param_type:
 -      param_signed param_integer param_real param_range | custom_param_type;
 -
 -int_param_type:
 -      param_signed param_integer param_range | custom_param_type;
 -
  param_decl:
        attr TOK_PARAMETER {
                astbuf1 = new AstNode(AST_PARAMETER);
@@@ -1163,7 -1202,7 +1182,7 @@@ localparam_decl
                astbuf1 = new AstNode(AST_LOCALPARAM);
                astbuf1->children.push_back(AstNode::mkconst_int(0, true));
                append_attr(astbuf1, $1);
-       } param_signed param_integer param_real param_range param_decl_list ';' {
 -      }  param_type param_decl_list ';' {
++      } param_type param_decl_list ';' {
                delete astbuf1;
        };
  
index 0000000000000000000000000000000000000000,37e63c1d00140f576a47afeffaea0aa3f29f2e9b..577e484adaf1875953ad7192ca2484731aae8a4e
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,10 +1,10 @@@
 -      ram16x4_t mem;
+ module top(input [3:0] addr, wdata, input clk, wen, output reg [3:0] rdata);
+       typedef logic [3:0] ram16x4_t[0:15];
++      (ram16x4_t) mem;
+       always @(posedge clk) begin
+               if (wen) mem[addr] <= wdata;
+               rdata <= mem[addr];
+       end
+ endmodule
index 0000000000000000000000000000000000000000,d0b8cf5bf486ab1db5ed19ddbb8a11497720269b..93cf47bbe6f7981990b44bee2f457a676327fbd8
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,3 +1,3 @@@
 -read -sv typedef_memory.sv
++read_verilog -sv typedef_memory.sv
+ prep -top top
+ select -assert-count 1 t:$mem r:SIZE=16 %i r:WIDTH=4 %i
index 0000000000000000000000000000000000000000,6d65131db21b01372076e053c3df0805705b73f5..f3089bf55ba027a54bea7f15946e1d915d8173ab
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,10 +1,10 @@@
 -      nibble mem[0:15];
+ module top(input [3:0] addr, wdata, input clk, wen, output reg [3:0] rdata);
+       typedef logic [3:0] nibble;
++      (nibble) mem[0:15];
+       always @(posedge clk) begin
+               if (wen) mem[addr] <= wdata;
+               rdata <= mem[addr];
+       end
+ endmodule
index 0000000000000000000000000000000000000000,0997beeea5b7a675b96dfe5a60406ce835cf795d..854e554f389dd3c144a8a0db272e6f79dc847259
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,4 +1,4 @@@
 -read -sv typedef_memory_2.sv
++read_verilog -sv typedef_memory_2.sv
+ prep -top top
+ dump
+ select -assert-count 1 t:$mem r:SIZE=16 %i r:WIDTH=4 %i
index 0000000000000000000000000000000000000000,bee88b7ae9e3883aeb4902145b100edc4efdb0e7..a1e16d4b1b67b6bb4db6c2547dc21e441e814995
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,11 +1,11 @@@
 -      (* keep *) pkg::uint8_t a = 8'hAA;
+ package pkg;
+       typedef logic [7:0] uint8_t;
+ endpackage
+ module top;
++      (* keep *) (pkg::uint8_t) a = 8'hAA;
+       always @* assert(a == 8'hAA);
+ endmodule
index 0000000000000000000000000000000000000000,d838dd828e35f6fd8f8954a8c39128cb714c4ca6..ddbd471e0c9c91c9b15b63deee0187020bf84d4f
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,22 +1,22 @@@
 -      typedef int8_t char_t;
+ `define STRINGIFY(x) `"x`"
+ `define STATIC_ASSERT(x) if(!(x)) $error({"assert failed: ", `STRINGIFY(x)})
+ module top;
+       typedef logic [1:0] uint2_t;
+       typedef logic signed [3:0] int4_t;
+       typedef logic signed [7:0] int8_t;
 -      parameter uint2_t int2 = 2'b10;
 -      localparam int4_t int4 = -1;
 -      localparam int8_t int8 = int4;
 -      localparam char_t ch = int8;
++      typedef (int8_t) char_t;
++      parameter (uint2_t) int2 = 2'b10;
++      localparam (int4_t) int4 = -1;
++      localparam (int8_t) int8 = int4;
++      localparam (char_t) ch = int8;
+       `STATIC_ASSERT(int2 == 2'b10);
+       `STATIC_ASSERT(int4 == 4'b1111);
+       `STATIC_ASSERT(int8 == 8'b11111111);
+       `STATIC_ASSERT(ch   == 8'b11111111);
+ endmodule
index 0000000000000000000000000000000000000000,340defbbb14e4d8b67aa7c20b293b331cb249fc1..faa385bd65ee3aeaa36f0e4f70863302cc9315c2
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,23 +1,23 @@@
 -      outer_uint4_t u4_i = 8'hA5;
+ typedef logic [3:0] outer_uint4_t;
+ module top;
 -      inner_type inner_i1 = 8'h5A;
++      (outer_uint4_t) u4_i = 8'hA5;
+       always @(*) assert(u4_i == 4'h5);
+       typedef logic [3:0] inner_type;
 -              inner_type inner_gb_i = 8'hA5;
++      (inner_type) inner_i1 = 8'h5A;
+       always @(*) assert(inner_i1 == 4'hA);
+       if (1) begin: genblock
+               typedef logic [7:0] inner_type;
 -      inner_type inner_i2 = 8'h42;
++              (inner_type) inner_gb_i = 8'hA5;
+               always @(*) assert(inner_gb_i == 8'hA5);
+       end
++      (inner_type) inner_i2 = 8'h42;
+       always @(*) assert(inner_i2 == 4'h2);
+ endmodule
index 0000000000000000000000000000000000000000,8f89910e5c97c520d3db5e5897f79caa7485e6ea..7e760dee4799128a079e2647b4dfa12dfb81ffd3
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,19 +1,19 @@@
 -      typedef int8_t char_t;
+ module top;
+       typedef logic [1:0] uint2_t;
+       typedef logic signed [3:0] int4_t;
+       typedef logic signed [7:0] int8_t;
 -      (* keep *) uint2_t int2 = 2'b10;
 -      (* keep *) int4_t int4 = -1;
 -      (* keep *) int8_t int8 = int4;
 -      (* keep *) char_t ch = int8;
++      typedef (int8_t) char_t;
++      (* keep *) (uint2_t) int2 = 2'b10;
++      (* keep *) (int4_t) int4 = -1;
++      (* keep *) (int8_t) int8 = int4;
++      (* keep *) (char_t) ch = int8;
+       always @* assert(int2 == 2'b10);
+       always @* assert(int4 == 4'b1111);
+       always @* assert(int8 == 8'b11111111);
+       always @* assert(ch   == 8'b11111111);
+ endmodule