1// DESCRIPTION: Verilator: Verilog Test module 2// 3// This file ONLY is placed under the Creative Commons Public Domain, for 4// any use, without warranty, 2020 by Wilson Snyder. 5// SPDX-License-Identifier: CC0-1.0 6 7`define TRY_ASSIGN(a,b) a = b 8`define TRY_CAST(a,b) a = type(a)'(b) 9`ifdef VERILATOR 10`define TRY_DYNAMIC(a,b) // UNSUP $cast 11`define TRY_BAD(a,b) // UNSUP $cast 12`else 13`define TRY_DYNAMIC(a,b) if (1 != $cast(a, b)) $stop 14`define TRY_BAD(a,b) if (0 != $cast(a, b)) $stop 15`endif 16 17`define MATCHING(a,b) `TRY_ASSIGN(a,b) 18`define EQUIVALENT(a,b) `TRY_ASSIGN(a,b) 19`define COMPATIBLE(a,b) `TRY_ASSIGN(a,b) 20`define CAST_COMPATIBLE(a,b) `TRY_CAST(a,b) 21`define CAST_COMPATIBLE_ENUM(a,b) `TRY_CAST(a,b) 22`define CAST_COMPATIBLE_DYNAMIC(a,b) `TRY_DYNAMIC(a,b) 23`define INCOMPATIBLE(a,b) `TRY_BAD(a,b) 24 25`define STRING_LITERAL "literal" // IEEE 5.9 - to packed or unpacked per IEEE 6.24 26 27class Base; 28endclass 29class BaseExtended extends Base; 30endclass 31class Other; 32endclass 33 34typedef enum { A_ZERO, A_ONE } Enum_A_t; 35typedef enum { B_ZERO, B_ONE } Enum_B_t; 36 37typedef int int_t; 38 39typedef struct packed { int a; int b; } stpack_t; 40 41typedef bit signed [7:0] simple_a_t; 42typedef bit signed [7:0] simple_a1_t; 43 44module t (/*AUTOARG*/); 45 46 real v_real; // IEEE 6.12.2 - by rounding 47 string v_string; 48 int v_int; 49 int_t v_int_t; 50 chandle v_chandle; 51 Enum_A_t v_enum_a; 52 Enum_A_t v_enum_a1; 53 Enum_B_t v_enum_b; 54 stpack_t v_stpack_a; 55 stpack_t v_stpack_a1; 56 simple_a_t v_simple_a; 57 simple_a1_t v_simple_a1; 58 int v_unpk_a[2][3]; 59 int v_unpk_a1[2][3]; 60 int v_assoc_a[string]; 61 int v_assoc_a1[string]; 62 int v_assoc_b[int]; 63 int v_assoc_c[bit[31:0]]; 64 65 int v_q_a[$]; 66 int v_q_a1[$]; 67 real v_q_b[$]; 68 69 bit [3:0][7:0] v_2thirtytwo_a; 70 bit [3:0][7:0] v_2thirtytwo_b; 71 logic [3:0][7:0] v_4thirtytwo_a; 72 logic [3:0][7:0] v_4thirtytwo_b; 73 74 Base v_cls_a; 75 Base v_cls_a1; 76 BaseExtended v_cls_ab; 77 Other v_cls_b; 78 79 // verilator lint_off REALCVT 80 81 initial begin 82 // 6.22.1 83 `MATCHING(v_real, v_real); 84 `MATCHING(v_string, v_string); 85 `MATCHING(v_int, v_int); 86 `MATCHING(v_chandle, v_chandle); 87 `MATCHING(v_int, v_int_t); 88 `MATCHING(v_stpack_a, v_stpack_a1); 89 `MATCHING(v_simple_a, v_simple_a1); 90 `MATCHING(v_unpk_a, v_unpk_a1); 91 `MATCHING(v_assoc_a, v_assoc_a1); 92 `MATCHING(v_q_a, v_q_a1); 93 `MATCHING(v_int, v_2thirtytwo_a); 94 `MATCHING(v_cls_a, v_cls_a1); 95 `MATCHING(v_cls_a, v_cls_ab); 96 // 6.22.2 97 `EQUIVALENT(v_int, v_2thirtytwo_a); 98`ifndef NC 99`ifndef VCS 100 `EQUIVALENT(v_assoc_b, v_assoc_c); // Spec says equivalent, but simulators disagree 101`endif 102`endif 103 // 6.22.3 104 `COMPATIBLE(v_string, `STRING_LITERAL); 105 `COMPATIBLE(v_int, v_enum_a); 106 `COMPATIBLE(v_int, v_real); 107 `COMPATIBLE(v_real, v_int); 108 // 6.22.4->5.9 109`ifndef NC 110 `CAST_COMPATIBLE(v_string, v_int); 111`endif 112 // 6.22.4->6.19.3 113`ifndef NC 114 `CAST_COMPATIBLE_ENUM(v_enum_a, v_int); 115 `CAST_COMPATIBLE_ENUM(v_enum_a, v_enum_b); 116`endif 117 `CAST_COMPATIBLE_DYNAMIC(v_cls_ab, v_cls_a); 118 // 6.22.5 incompatible 119 `INCOMPATIBLE(v_cls_ab, v_int); 120`ifndef VCS 121 `INCOMPATIBLE(v_real, v_assoc_a); 122 `INCOMPATIBLE(v_real, v_q_a); 123`endif 124`ifndef VCS 125 `ifndef VERILATOR 126 `INCOMPATIBLE(v_chandle, v_int); 127 `endif 128`endif 129`ifndef NC 130 `INCOMPATIBLE(v_cls_a, v_cls_b); 131`endif 132 133 $write("*-* All Finished *-*\n"); 134 $finish; 135 end 136endmodule 137