#!/usr/bin/perl -w # This software is OSI Certified Open Source Software. # OSI Certified is a certification mark of the Open Source Initiative. # # Title: povrd_lint.pl # # Version 1.4 May 1, 2002 # # o The first revisions corrected typos in the test cases. # # Version 1.5 Jan 28, 2002 # # David Hamilton [e-mail dahamilt at cisco.com] suggested the # following improvements - # # o Based on recommendations in Section 7.3.1.2 on Page 156, # added six tests for using lower case for wires, regs, # ports, and instances, and upper case for `defines # and parameters: # Section7_3_1_2a # Section7_3_1_2b # Section7_3_1_2c # Section7_3_1_2d # Section7_3_1_2e # Section7_3_1_2f # # o Corrected all examples using parameter w to use upper-case # parameter W. # # o Based on deprication of casez in Section 8.4.1.3 on Page 190 # added test for diagnosis of casez usage: # Section_8_4_1_3 # # o Added a "total score out of 600" system, corresponding # to the six scoring categories. # # # Future versions: # # Definitive versions of this "Bening & Foster" script # with updates as they occur are available on the # web at http://www.verfiableRTL.com # # Your inputs regarding this script are welcome. Whether # they can result it changes to the script depend # upon the volume of inputs sent, compared with # the time available, and whether the inputs are # in-line with the values described in the book, # "Principles of Verifiable RTL Design" 2nd Edition # by Lionel Bening and Harry Foster, (Kluwer Academic # Publishers). # # Description: # # This perl script measures the quality of a # linting tool by running small examples of Verilog modules # through the tool. For most tests, if the tool can identify # the error and take an "exit(1), the tool passes the test # for that example. # # Lint tools must allow "forgiveness" of intentional # feedback and latches. If a test case has intentional # feedback and latches with a latch forgiveness pragma, # it must take an exit(0). # # This scrip scores the testing for the examples based on # the categories: # Case, NoXstate, Organization, Structure, Style, TypeCheck # 20% off for the 1st undiagnosed problem in each of the # above classifications, 1% off for each additional # undiagnosed problem of the same classification. # # The Example and Section numbers refer to the book, # "Principles of Verifiable RTL Design" 2nd Edition # by Lionel Bening and Harry Foster, (Kluwer Academic # Publishers). Explanations of why diagnosis of the # problems in the Verilog samples is important are # in the book. # # # # Table of Contents # # 1.0 License # # 2.0 Declarations # 2.1 Constants # 2.2 Initialization # # 3.0 Test Cases # Chapter 7 RTL Style # Section7_1_3a Page 135 # Section7_1_3b Page 135 # Figure7_1 Page 136 # Example7_5a Page 137 # Example7_5b Page 137 # Example7_5c Page 137 # Example7_6a Page 138 # Example7_6b Page 138 # Example7_7a Page 140 # Example7_7b Page 140 # Example7_8 Page 142 # Example7_10 Page 145 # Example7_16a Page 153 # Example7_16b Page 153 # Example7_16c Page 153 # Example7_16d Page 153 # Section7_2_3a Page 154 # Section7_2_3b Page 155 # Section7_2_3c Page 155 # | Section7_3_1_2a Page 156 # | Section7_3_1_2b Page 156 # | Section7_3_1_2c Page 156 # | Section7_3_1_2d Page 156 # | Section7_3_1_2e Page 156 # | Section7_3_1_2f Page 156 # Section7_5_2_4a Page 170 # Section7_5_2_4b Page 170 # # Chapter 8 The Bad Stuff # Example8_01a Page 175 # Example8_02 Page 176 # Example8_03 Page 177 # Example8_05a Page 178 # Example8_05b Page 178 # Example8_07 Page 179 # Example8_08a Page 180 # Example8_09 Page 181 # Example8_10 Page 182 # Example8_12 Page 184 # Example8_13 Page 186 # Example8_14 Page 187 # Example8_15 Page 189 # Example8_16 Page 190 # | Section_8_4_1_3 Page 190 # Example8_17a Page 191 # Example8_17b Page 191 # Example8_17c Page 191 # Example8_19 Page 193 # Section_8_4_2_2a Page 192 # Section_8_4_2_2b Page 192 # Example8_22a Page 197 # Example8_23a Page 198 # Example8_24 Page 199 # Example8_25 Page 199 # Example8_26 Page 200 # Table_8_2_and Page 205 # Table_8_2_nor Page 205 # Table_8_2_or Page 205 # Table_8_2_xnor Page 205 # Table_8_2_xor Page 205 # # Chapter 9 Verifiable RTL Tutorial # Section9_5_1_1plus Page 218 # Section9_5_1_1minus Page 218 # Section9_5_1_1mod Page 218 # Section9_5_1_1bwand Page 219 # Section9_5_1_1bwor Page 219 # Section9_5_1_1bwxor Page 219 # Section9_5_1_1bwnxor Page 219 # Section9_5_1_1land Page 219 # Section9_5_1_1lor Page 219 # Section9_5_1_1leq Page 219 # Section9_5_1_1lneq Page 219 # Section9_5_1_1lgt Page 219 # Section9_5_1_1geq Page 219 # Section9_5_1_1leq Page 219 # Section9_5_1_1lgt Page 219 # Section9_5_1_1llt Page 219 # Section9_5_1_2bwnot Page 219 # Section9_5_1_2lnot Page 220 # Section9_5_1_3condexp Page 220 # Section9_5_1_3louminus Page 221 # Section9_5_1_3louminusOK Page 221 # Section9_5_1_3lomult Page 221 # Section9_5_1_3lomultOK Page 221 # Section9_5_1_3lodiv Page 221 # Section9_5_1_3lodivOK Page 221 # Section9_5_1_3loeq Page 221 # Section9_5_1_3loeqOK Page 221 # Section9_5_1_3loneq Page 221 # Section9_5_1_3loneqOK Page 221 # Example9_10 Page 221 # Example9_11_1a Page 223 # Example9_11_1b Page 223 # Example9_11_2 Page 223 # Example9_14call Page 224 # Example9_14return Page 224 # Figure9_6 Page 225 # Example9_16rule1 Page 226 # Example9_16rule2 Page 226 # Example9_16rule2a Page 226 # Example9_16rule2b Page 226 # Example9_17 Page 227 # Example9_18 Page 227 # Section9_6_2_2a Page 228 # Section9_6_2_2b Page 228 # # 4.0 Scoring # 4.1 Case tests # 4.2 NoXstate tests # 4.3 Organization tests # 4.4 Structure tests # 4.5 Style tests # 4.6 Typing tests # 4.7 Total scores # # 5.0 Clean # # 6.0 Subs # 6.1 logstatus # 6.2 usage # #---------------------------------------------------------------------- #---------------------------------------------------------------------- # 1.0 License #---------------------------------------------------------------------- # # The following is based on the "zlib/libpng License" as described in # http://www.opensource.org/licenses/index.html # # Copyright (c) 2002 Lionel Bening # # This software is provided 'as-is', without # any express or implied warranty. In no event will the # authors be held liable for any damages arising # from the use of this software. # # Permission is granted to anyone to use this # software for any purpose, including commercial # applications, and to alter it and redistribute # it freely, subject to the following restrictions: # # 1. The origin of this software must not # be misrepresented; you must not claim that # you wrote the original software. If you # use this software in a product, an # acknowledgment in the product documentation # would be appreciated but is not # required. # # 2. Altered source versions must be plainly # marked as such, and must not be # misrepresented as being the original software. # # 3. This notice may not be removed or altered from # any source distribution. #---------------------------------------------------------------------- # 2.0 Declarations #---------------------------------------------------------------------- #---------------------------------------------------------------------- # 2.1 Constants #---------------------------------------------------------------------- use subs qw( usage ); # The following constants supply vendor names to determine whether # a lint tool can diagnose proprietary non-standard pragmas in # Verilog that text. # # Choose and plug in "X" and "Y" for synthvend and covtool names. $synthvend = "X"; $covtool = "Y"; $synthesis_off="$synthvend translate_off"; $synthesis_on="$synthvend translate_on"; $coverage_off="$covtool coverage off"; $coverage_on="$covtool coverage on"; #---------------------------------------------------------------------- # 2.2 Initialization #---------------------------------------------------------------------- $CaseScore=0; $CaseTests=0; $NoXstateScore=0; $NoXstateTests=0; $OrganizationScore=0; $OrganizationTests=0; $StructureScore=0; $StructureTests=0; $StyleScore=0; $StyleTests=0; $TypingScore=0; $TypingTests=0; $clean=""; if (defined($_ = shift)) { if ($_ eq "-h") { usage(); } else { if ($_ eq "clean") { $clean=$_; } else { # Customize and add to the following sections for the specific lint tools # that you want to evaluate. if ($_ eq "linttool") { $lint_tool="/eda3pt/vendorX/bin/linttool"; $latch_forgiveness_prefix = "//rtl_lint latchcheck off"; $latch_forgiveness_online = ""; $latch_forgiveness_suffix = "//rtl_lint latchcheck on"; } else { if ($_ eq "inhouse") { $lint_tool="/edarsn/cv2c_6.5/hppa10.20/bin/cv2c -LOA -O3"; $latch_forgiveness_prefix = ""; $latch_forgiveness_online = "// rtl_lint latch"; $latch_forgiveness_suffix = ""; $feedback_forgiveness_prefix = ""; $feedback_forgiveness_online = "// rtl_lint feedback"; $feedback_forgiveness_suffix = ""; } else { printf("***** Unknown option *****\n\n"); usage(); } } } } } else { printf("***** Option required *****\n\n"); usage(); } #---------------------------------------------------------------------- # 3.0 Test Cases #---------------------------------------------------------------------- #---------------------------------------------------------------------- # Section7_1_3a Page 135 #---------------------------------------------------------------------- $test="Section7_1_3a"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (r, s, q); input r, s; output q; wire q, q_L; assign q = ~(q_L | r); assign q_L = ~(q | s); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StructureTests; $StructureScore += logstatus (($status != 0),"Structure",$test,"Real feedback"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section7_1_3b Page 135 #---------------------------------------------------------------------- $test="Section7_1_3b"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (r, s, q); input r, s; output q; $feedback_forgiveness_prefix wire q, q_L; $feedback_forgiveness_suffix assign q = ~(q_L | r); $feedback_forgiveness_online assign q_L = ~(q | s); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StructureTests; $StructureScore += logstatus (($status == 0),"Structure",$test,"Real feedback forgiveness"); } else { push @files, $test; } #---------------------------------------------------------------------- # Figure7_1 Page 136 #---------------------------------------------------------------------- $test="Figure7_1"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (s, a, b, y, z); input s; input a, b; output y, z; wire s, a, b; wire y, z; assign y = s ? a : z; assign z = s ? y : b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StructureTests; $StructureScore += logstatus (($status != 0),"Structure",$test,"False path feedback"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example7_5a Page 137 #---------------------------------------------------------------------- $test="Example7_5a"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (a, d); input a; output d; reg b, d; wire c; always @(a or c) begin b = a; d = c; end assign c = b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StructureTests; $StructureScore += logstatus (($status != 0),"Structure",$test,"Apparent (not real) feedback"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example7_5b Page 137 #---------------------------------------------------------------------- $test="Example7_5b"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (a, d); input a; output d; reg b, c, d; always @(a) begin b = a; c = b; d = c; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StructureTests; $StructureScore += logstatus (($status == 0),"Structure",$test,"Eliminated feedback"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example7_5c Page 137 #---------------------------------------------------------------------- $test="Example7_5c"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (a, d); input a; output d; wire b, c, d; assign b = a; assign d = c; assign c = b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StructureTests; $StructureScore += logstatus (($status == 0),"Structure",$test,"Eliminated feedback"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example7_6a Page 138 #---------------------------------------------------------------------- $test="Example7_6a"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (r_o, c_n); input [1:0] r_o; output [1:0] c_n; reg [1:0] c_n; always @(r_o) case (r_o) // rtl_synthesis full_case 2'b00 : c_n = 2'b01; 2'b01 : c_n = 2'b10; 2'b10 : c_n = 2'b00; endcase endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$CaseTests; $CaseScore += logstatus (($status != 0),"Case",$test,"Incompletely specified case"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example7_6b Page 138 #---------------------------------------------------------------------- $test="Example7_6b"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (r_o, c_n); input [1:0] r_o; output [1:0] c_n; reg [1:0] c_n; always @(r_o) case (r_o) 2'b00 : c_n = 2'b01; 2'b01 : c_n = 2'b10; 2'b10 : c_n = 2'b00; 2'b11 : c_n = 2'b00; endcase endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$CaseTests; $CaseScore += logstatus (($status == 0),"Case",$test,"Completely specified case"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example7_7a Page 140 #---------------------------------------------------------------------- $test="Example7_7a"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (c_hot,c_code); input [7:0] c_hot; output [2:0] c_code; reg [2:0] c_code; always @ (c_hot) begin case (c_hot) // RTL synthesis full_case 8'b10000000: c_code = 3'b000; 8'b01000000: c_code = 3'b001; 8'b00100000: c_code = 3'b010; 8'b00010000: c_code = 3'b011; 8'b00001000: c_code = 3'b100; 8'b00000100: c_code = 3'b101; 8'b00000010: c_code = 3'b110; 8'b00000001: c_code = 3'b111; endcase end // always (c_hot) endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$CaseTests; $CaseScore += logstatus (($status != 0),"Case",$test,"Completely specified case"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example7_7b Page 140 #---------------------------------------------------------------------- $test="Example7_7b"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (c_hot,c_code); input [7:0] c_hot; output [2:0] c_code; reg [2:0] c_code; always @ (c_hot) begin case (c_hot) // RTL synthesis full_case 8'b10000000: c_code = 3'b000; 8'b01000000: c_code = 3'b001; 8'b00100000: c_code = 3'b010; 8'b00010000: c_code = 3'b011; 8'b00001000: c_code = 3'b100; 8'b00000100: c_code = 3'b101; 8'b00000010: c_code = 3'b110; 8'b00000001: c_code = 3'b111; default: c_code = 3'b000; // causes 3X gates endcase end // always (c_hot) endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$CaseTests; $CaseScore += logstatus (($status == 0),"Case",$test,"Completely specified case"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example7_8 Page 142 #---------------------------------------------------------------------- $test="Example7_8"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test(c_hot,c_code); input [7:0] c_hot; output [2:0] c_code; reg [2:0] c_code; reg [2:0] c_code0,c_code1,c_code2,c_code3; reg [2:0] c_code4,c_code5,c_code6; always @ (c_hot) begin c_code6 = (c_hot [6]) ? 3'b001 : 3'b000; c_code5 = (c_hot [5]) ? 3'b010 : 3'b000; c_code4 = (c_hot [4]) ? 3'b011 : 3'b000; c_code3 = (c_hot [3]) ? 3'b100 : 3'b000; c_code2 = (c_hot [2]) ? 3'b101 : 3'b000; c_code1 = (c_hot [1]) ? 3'b110 : 3'b000; c_code0 = (c_hot [0]) ? 3'b111 : 3'b000; c_code = c_code0 | c_code1 | c_code2 | c_code3 | c_code4 | c_code5 | c_code6; end // always (c_hot) endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$CaseTests; $CaseScore += logstatus (($status == 0),"Case",$test,"Fully-specified one-hot decoding with minimum gates"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example7_10 Page 145 #---------------------------------------------------------------------- $test="Example7_10"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (pin,qin,ck,dis); parameter W = 3; output [W-1:0] pin; input [W-1:0] qin; input ck; input dis; reg [W-1:0] qout; always @(posedge ck) qout <= qin; tri [W-1:0] pin = !dis ? qout : {W{1'bZ}}; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status == 0),"Style",$test,"Tri-state drivers"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example7_16a Page 153 #---------------------------------------------------------------------- $test="Example7_16a"; if ($clean ne "clean") { $library=$test . "_ff.vlib"; $module=$test . "_ff"; open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (r_head, ck, c_head); output [3:0] r_head; input ck; input [3:0] c_head; $module #(4) reg_head (r_head, ck, c_head ); endmodule // $test EOF close (VLOG); open(VLOG, "> $library") || die "failed\n"; print VLOG<<"EOF"; module $module (q, ck, d); parameter W = 1; input ck; input [W-1:0] d; output [W-1:0] q; reg [W-1:0] q; always @(posedge ck) q <= d; endmodule // $module EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Implicit port connnections on small library module"); } else { push @files, $test; push @files, ($test . "_ff");} #---------------------------------------------------------------------- # Example7_16b Page 153 #---------------------------------------------------------------------- $test="Example7_16b"; if ($clean ne "clean") { $library=$test . "_ff.vlib"; $module=$test . "_ff"; open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (r_head, ck, c_head, c_mask); output [3:0] r_head; input ck; input [3:0] c_head; input [3:0] c_mask; $module #(4) reg_head ( .d(c_head ^ c_mask), .ck(ck), .q(r_head)); endmodule // $test EOF close (VLOG); open(VLOG, "> $library") || die "failed\n"; print VLOG<<"EOF"; module $module (q, ck, d); parameter W = 1; input ck; input [W-1:0] d; output [W-1:0] q; reg [W-1:0] q; always @(posedge ck) q <= d; endmodule // $module EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Port expression not observable"); } else { push @files, $test; push @files, ($test . "_ff");} #---------------------------------------------------------------------- # Example7_16c Page 153 #---------------------------------------------------------------------- $test="Example7_16c"; if ($clean ne "clean") { $library=$test . "_ff.vlib"; $module=$test . "_ff"; open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (r_head, ck, c_head, c_mask); output [3:0] r_head; input ck; input [3:0] c_head; input [3:0] c_mask; wire [3:0] c_obsrv = c_head ^ c_mask; $module #(4) reg_head ( .d(c_obsrv), .ck(ck), .q(r_head)); endmodule // $test EOF close (VLOG); open(VLOG, "> $library") || die "failed\n"; print VLOG<<"EOF"; module $module (q, ck, d); parameter W = 1; input ck; input [W-1:0] d; output [W-1:0] q; reg [W-1:0] q; always @(posedge ck) q <= d; endmodule // $module EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status == 0),"Style",$test,"Port expression made observable"); } else { push @files, $test; push @files, ($test . "_ff");} #---------------------------------------------------------------------- # Example7_16d Page 153 #---------------------------------------------------------------------- $test="Example7_16d"; if ($clean ne "clean") { $library=$test . "_ff.vlib"; $module=$test . "_ff"; open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (r_head, ck, c_he, c_ad); output [3:0] r_head; input ck; input [1:0] c_he; input [1:0] c_ad; $module #(4) reg_head ( .d( {c_he, c_ad} ), .ck(ck), .q(r_head)); endmodule // $test EOF close (VLOG); open(VLOG, "> $library") || die "failed\n"; print VLOG<<"EOF"; module $module (q, ck, d); parameter W = 1; input ck; input [W-1:0] d; output [W-1:0] q; reg [W-1:0] q; always @(posedge ck) q <= d; endmodule // $module EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status == 0),"Style",$test,"Concatenation expression ok on port"); } else { push @files, $test; push @files, ($test . "_ff");} #---------------------------------------------------------------------- # Section7_2_3a Page 154 #---------------------------------------------------------------------- $test="Section7_2_3a"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test(c_hdr_data, r_tm_hdr_len, r_tm_data_len); output [1:0] c_hdr_data; input [1:0] r_tm_hdr_len; input [3:0] r_tm_data_len; reg [1:0] c_hdr_data; always @(r_tm_hdr_len or r_tm_data_len) if (((r_tm_hdr_len == 2'h1) && (!(r_tm_data_len))) || ((r_tm_hdr_len == 2'h0) && (r_tm_data_len == 4'h1))) c_hdr_data = 4'h0; else c_hdr_data = 4'hf; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Use of logical operator with multi-bit operand"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section7_2_3b Page 155 #---------------------------------------------------------------------- $test="Section7_2_3b"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test(c_x, r_a, r_b, r_c); output [23:0] c_x; input [7:0] r_a; input [7:0] r_b; input [7:0] r_c; reg [23:0] c_x; always @(r_a or r_b or r_c) begin c_x [23:16] = r_a; c_x [15:8] = r_b; c_x [7:0] = r_c; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Use of subrange assignments"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section7_2_3c Page 155 #---------------------------------------------------------------------- $test="Section7_2_3c"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test(cam_1,s); output cam_1; input [31:0] s; reg cam_1; always @(s) begin cam_1 = s[30] | s[26] | s[22] | s[18] | s[14] | s[10] | s[6] | s[2]; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Replace bit visits with parallel value operation"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section7_3_1_2a Page 156 #---------------------------------------------------------------------- $test="Section7_3_1_2a"; if ($clean ne "clean") { $library=$test . "_ff.v"; $module=$test . "_ff"; open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (r_head, clk, c_head, c_mask); output [3:0] r_head; input clk; input [3:0] c_head; input [3:0] c_mask; wire [3:0] C_obsrv = c_head ^ c_mask; $module #(4) reg_head ( .d ( C_obsrv), .clk( clk ), .q ( r_head )); endmodule // $test EOF close (VLOG); open(VLOG, "> $library") || die "failed\n"; print VLOG<<"EOF"; module $module (q, clk, d); parameter W = 1; input clk; input [W-1:0] d; output [W-1:0] q; reg [W-1:0] q; always @(posedge clk) q <= d; endmodule // $module EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Wire names should be lower case"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section7_3_1_2b Page 156 #---------------------------------------------------------------------- $test="Section7_3_1_2b"; if ($clean ne "clean") { $library=$test . "_ff.v"; $module=$test . "_ff"; open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (r_head, clk, c_head, c_mask); output [3:0] r_head; input clk; input [3:0] c_head; input [3:0] c_mask; reg [3:0] C_obsrv; always @(c_head or c_mask) begin C_obsrv = c_head ^ c_mask; end $module #(4) reg_head ( .d ( C_obsrv), .clk( clk ), .q ( r_head )); endmodule // $test EOF close (VLOG); open(VLOG, "> $library") || die "failed\n"; print VLOG<<"EOF"; module $module (q, clk, d); parameter W = 1; input clk; input [W-1:0] d; output [W-1:0] q; reg [W-1:0] q; always @(posedge clk) q <= d; endmodule // $module EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"reg names should be lower case"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section7_3_1_2c Page 156 #---------------------------------------------------------------------- $test="Section7_3_1_2c"; if ($clean ne "clean") { $library=$test . "_ff.v"; $module=$test . "_ff"; open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (r_head, clk, c_head, c_mask); output [3:0] r_head; input clk; input [3:0] c_head; input [3:0] c_mask; wire [3:0] c_obsrv = c_head ^ c_mask; $module #(4) REG_HEAD ( .d ( c_obsrv), .clk( clk ), .q ( r_head )); endmodule // $test EOF close (VLOG); open(VLOG, "> $library") || die "failed\n"; print VLOG<<"EOF"; module $module (q, clk, d); parameter W = 1; input clk; input [W-1:0] d; output [W-1:0] q; reg [W-1:0] q; always @(posedge clk) q <= d; endmodule // $module EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"instance names should be lower case"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section7_3_1_2d Page 156 #---------------------------------------------------------------------- $test="Section7_3_1_2d"; if ($clean ne "clean") { $library=$test . "_ff.v"; $module=$test . "_ff"; open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (R_head, CLK, C_head, C_mask); output [3:0] R_head; input CLK; input [3:0] C_head; input [3:0] C_mask; wire [3:0] c_obsrv = C_head ^ C_mask; $module #(4) reg_head ( .d ( c_obsrv), .clk( CLK ), .q ( R_head )); endmodule // $test EOF close (VLOG); open(VLOG, "> $library") || die "failed\n"; print VLOG<<"EOF"; module $module (q, clk, d); parameter W = 1; input clk; input [W-1:0] d; output [W-1:0] q; reg [W-1:0] q; always @(posedge clk) q <= d; endmodule // $module EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"port names should be lower case"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section7_3_1_2e Page 156 #---------------------------------------------------------------------- $test="Section7_3_1_2e"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; `define width 16 module $test (a,b); input [`width-1:0] a; output [`width-1:0] b; reg [`width-1:0] b; always @ (a) begin b = ~a; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"macro (\`define) names should be upper case"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section7_3_1_2f Page 156 #---------------------------------------------------------------------- $test="Section7_3_1_2f"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (a,b); parameter width = 16; input [width-1:0] a; output [width-1:0] b; reg [width-1:0] b; always @ (a) begin b = ~a; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"parameter names should be upper case"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section7_5_2_4a Page 170 #---------------------------------------------------------------------- $test="Section7_5_2_4a"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (r_o, c_n); input [1:0] r_o; output [1:0] c_n; reg [1:0] c_n; // $coverage_off // $synthesis_off always @(r_o) case (r_o) 2'b00 : c_n = 2'b01; 2'b01 : c_n = 2'b10; 2'b10 : c_n = 2'b00; 2'b11 : c_n = 2'b11; endcase // $synthesis_on // $coverage_on endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Use of vendor-specific pragmas"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section7_5_2_4b Page 170 #---------------------------------------------------------------------- $test="Section7_5_2_4b"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (r_o, c_n); input [1:0] r_o; output [1:0] c_n; reg [1:0] c_n; // rtl_coverage off // rtl_synthese translate_off always @(r_o) case (r_o) 2'b00 : c_n = 2'b01; 2'b01 : c_n = 2'b10; 2'b10 : c_n = 2'b00; 2'b11 : c_n = 2'b11; endcase // rtl_coverage on // rtl_synthese translate_on endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status == 0),"Style",$test,"Use of generic pragmas"); } else { push @files, $test; } #---------------------------------------------------------------------- # 5.0 Chapter 8 Bad Stuff #---------------------------------------------------------------------- #---------------------------------------------------------------------- # Example8_01a Page 175 #---------------------------------------------------------------------- $test="Example8_01a"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (ck250,r_rcs,r_del,r_avail, r_n1, r_n2, r_n3, r_n4, r_n5, r_n6, rst_, c_rcs, c_del, c_avail, c_n1, c_n2, c_n3, c_n4, c_n5, c_n6); input ck250; output r_rcs,r_del,r_avail; output [4:0] r_n1, r_n2, r_n3, r_n4, r_n5, r_n6; input rst_, c_rcs, c_del, c_avail; input [4:0] c_n1, c_n2, c_n3, c_n4, c_n5, c_n6; reg r_rcs,r_del,r_avail; reg [4:0] r_n1, r_n2, r_n3, r_n4, r_n5, r_n6; always @(posedge ck250) begin r_rcs <= rst_ ? c_rcs : 1'b0; r_del <= c_del; r_avail <= c_avail; r_n1 <= rst_ ? c_n1 : 5'd0; r_n2 <= rst_ ? c_n2 : 5'd0; r_n3 <= rst_ ? c_n3 : 5'd0; r_n4 <= rst_ ? c_n4 : 5'd0; r_n5 <= rst_ ? c_n5 : 5'd0; r_n6 <= rst_ ? c_n6 : 5'd0; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status != 0),"Organization",$test,"Flip-flop outside library"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_02 Page 176 #---------------------------------------------------------------------- $test="Example8_02"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (a, b); input [15:0] b; output [15:0] a; reg [15:0] a; always @(b) begin a = b + 16'b000000000000X000 ; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$NoXstateTests; $NoXstateScore += logstatus (($status != 0),"NoXstate",$test,"Verifiable RTL forbids X state assignments"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_03 Page 177 #---------------------------------------------------------------------- $test="Example8_03"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (e,d); output [1:0] e; input [1:0] d; reg [1:0] e; always @(d) begin case (d) 2'b00 : e = 2'b01; 2'b01 : e = 2'b11; 2'b10 : e = 2'b10; 2'b11 : e = 2'b00; default : e = 2'bXX; endcase end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$NoXstateTests; $NoXstateScore += logstatus (($status != 0),"NoXstate",$test,"Verifiable RTL forbids X state assignments"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_05a Page 178 #---------------------------------------------------------------------- $test="Example8_05a"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (g,f); output [1:0] g; input f; reg [1:0] g; always @(f) begin if (f === 1'b0) g = 2'b00; else if (f === 1'bX) g = 2'b0X; else g = 2'b01; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$NoXstateTests; $NoXstateScore += logstatus (($status != 0),"NoXstate",$test,"Verifiable RTL forbids X state assignments"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_05b Page 178 #---------------------------------------------------------------------- $test="Example8_05b"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (e,d); output [1:0] e; input [1:0] d; reg [1:0] e; always @(d) begin case (d) 2'b00 : e = 2'b01; 2'b0X : e = 2'bX1; 2'b01 : e = 2'b11; 2'bX0 : e = 2'bXX; 2'bXX : e = 2'bXX; 2'bX1 : e = 2'bXX; 2'b10 : e = 2'b10; 2'b1X : e = 2'bX0; 2'b11 : e = 2'b00; endcase end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$NoXstateTests; $NoXstateScore += logstatus (($status != 0),"NoXstate",$test,"Verifiable RTL forbids X state tests, assignments"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_07 Page 179 #---------------------------------------------------------------------- $test="Example8_07"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (mux,sel,a,b,c,d); output [15:0] mux; input [1:0] sel; input [15:0] a,b,c,d; reg [15:0] mux; always @(sel or a or b or c or d) case (sel) 2'b00 : mux = a; 2'b01 : mux = b; 2'b10 : mux = c; 2'b11 : mux = d; default : mux = 'bX; endcase endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$NoXstateTests; $NoXstateScore += logstatus (($status != 0),"NoXstate",$test,"Verifiable RTL forbids X state assignments"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_08a Page 180 #---------------------------------------------------------------------- $test="Example8_08a"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (c_ecc_out_1,c_in); output c_ecc_out_1; input [39:0] c_in; reg c_ecc_out_1; always @(c_in) c_ecc_out_1 =c_in [10] ^ c_in[11] ^ c_in[12] ^ c_in[13] ^ c_in[14] ^ c_in[15] ^ c_in[16] ^ c_in[17] ^ c_in[18] ^ c_in[19] ^ c_in[20] ^ c_in[21] ^ c_in[22] ^ c_in[23] ^ c_in[24] ^ c_in[25] ^ c_in[26] ^ c_in[27] ^ c_in[28] ^ c_in[32] ^ c_in[35] ^ c_in[38] ^ c_in[39]; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Replace bit visits with parallel value operation"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_09 Page 181 #---------------------------------------------------------------------- $test="Example8_09"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (encoder,indata); output [2:0] encoder; input [7:0] indata; fifo #(3,8,1) inst (encoder,indata); endmodule // $test module fifo (encoder,indata); parameter DEPTH = 13; parameter WIDTH = 13; parameter ENCODE = 0; output [DEPTH-1:0] encoder; input [WIDTH-1:0] indata; reg [DEPTH-1:0] encoder; always @(indata) begin if (ENCODE != 0) encoder = {{DEPTH-1{1'b0}},1'b1} << indata; else encoder = indata; end endmodule // fifo EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Simulation run time parameter value test"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_10 Page 182 #---------------------------------------------------------------------- $test="Example8_10"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; `define N 16 module $test (a,b); input [`N-1:0] a; output [`N-1:0] b; reg [`N-1:0] b; integer i; always @ (a) begin for (i=0; i<=`N-1; i=i+1) b[i] = ~a[i]; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status != 0),"Organization",$test,"For-loop outside of library"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_12 Page 184 #---------------------------------------------------------------------- $test="Example8_12"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (clk, fifo_depth,reset_L_ff, w_addr_ff,write_data); input clk; input [5:0] fifo_depth; input reset_L_ff; input [5:0] w_addr_ff; input [15:0] write_data; reg [15:0] entry_ff [37:0]; integer i; always @(posedge clk) for(i = 32'd0; i < {26'd0,fifo_depth}; i = i+32'd1) begin case({reset_L_ff, {26'd0,w_addr_ff} == i}) 2'b00, 2'b01: entry_ff[i] <= 16'd0; 2'b11: entry_ff[i] <= write_data; 2'b10: entry_ff[i] <= entry_ff[i]; endcase end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status != 0),"Organization",$test,"For-loop outside of library"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_13 Page 186 #---------------------------------------------------------------------- $test="Example8_13"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (r_o, c_n); input [1:0] r_o; output [1:0] c_n; reg [1:0] c_n; always @(r_o) case (r_o) // rtl_synthesis full_case 2'b00 : c_n = 2'b01; 2'b01 : c_n = 2'b10; 2'b10 : c_n = 2'b00; endcase endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$CaseTests; $CaseScore += logstatus (($status != 0),"Case",$test,"Incompletely-specified case statement"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_14 Page 187 #---------------------------------------------------------------------- $test="Example8_14"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (c_code, c_hot ); output [2:0] c_code; input [7:0] c_hot; reg [2:0] c_code; always @(c_hot) casex (c_hot) // RTL synthesis parallel_case 8'b1???????: c_code = 3'b000; 8'b?1??????: c_code = 3'b001; 8'b??1?????: c_code = 3'b010; 8'b???1????: c_code = 3'b011; 8'b????1???: c_code = 3'b100; 8'b?????1??: c_code = 3'b101; 8'b??????1?: c_code = 3'b110; 8'b???????1: c_code = 3'b111; endcase endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$CaseTests; $CaseScore += logstatus (($status != 0),"Case",$test,"Incompletely-specified case statement"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_15 Page 189 #---------------------------------------------------------------------- $test="Example8_15"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (c_code, c_hot ); output [2:0] c_code; input [7:0] c_hot; reg [2:0] c_code; always @(c_hot) casex (1'b1) // RTL synthesis parallel_case c_hot[7] : c_code = 3'b000; c_hot[6] : c_code = 3'b001; c_hot[5] : c_code = 3'b010; c_hot[4] : c_code = 3'b011; c_hot[3] : c_code = 3'b100; c_hot[2] : c_code = 3'b101; c_hot[1] : c_code = 3'b110; c_hot[0] : c_code = 3'b111; endcase endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$CaseTests; $CaseScore += logstatus (($status != 0),"Case",$test,"Case statement dialect unsupported"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_16 Page 190 #---------------------------------------------------------------------- $test="Example8_16"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (e1,ck); input ck; output [1:0] e1; reg [1:0] e1; always begin @(posedge ck); e1 <= 2'b00; @(posedge ck); e1 <= 2'b01; @(posedge ck); e1 <= 2'b11; @(posedge ck); e1 <= 2'b10; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$CaseTests; $CaseScore += logstatus (($status != 0),"Case",$test,"Implicit state machine dialect unsupported"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section_8_4_1_3 Page 190 #---------------------------------------------------------------------- $test="Section_8_4_1_3"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (c_code, c_hot ); output [2:0] c_code; input [7:0] c_hot; reg [2:0] c_code; always @(c_hot) casez (c_hot) // RTL synthesis parallel_case 8'b1???????: c_code = 3'b000; 8'b01??????: c_code = 3'b001; 8'b001?????: c_code = 3'b010; 8'b0001????: c_code = 3'b011; 8'b00001???: c_code = 3'b100; 8'b000001??: c_code = 3'b101; 8'b0000001?: c_code = 3'b110; 8'b00000001: c_code = 3'b111; default: c_code = 3'b000; // causes 3X gates endcase endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$CaseTests; $CaseScore += logstatus (($status != 0),"Case",$test,"Use of casez"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_17a Page 191 #---------------------------------------------------------------------- $test="Example8_17a"; if ($clean ne "clean") { $module=$test . "_ff"; $library=$test . "_ff.vlib"; open(VLOG, "> $library"); print VLOG<<"EOF"; module $module (q, d, ck); output [7:0] q; input [7:0] d; input ck; reg [7:0] q; always @(posedge ck) q <= d; // $synthesis_off initial q = 8'h00; // $synthesis_on endmodule // $module EOF close (VLOG); open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (q, d, ck); output [7:0] q; input [7:0] d; input ck; $module inst (.q (q), .d (d), .ck(ck)); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status != 0),"Organization",$test,"Flip-flop in library, but with static initialization"); } else { push @files, $test; push @files, ($test . "_ff");} #---------------------------------------------------------------------- # Example8_17b Page 191 #---------------------------------------------------------------------- $test="Example8_17b"; if ($clean ne "clean") { $module=$test . "_ff"; $library=$test . "_ff.vlib"; open(VLOG, "> $library"); print VLOG<<"EOF"; module $module (q, d, ck); output [7:0] q; input [7:0] d; input ck; reg [7:0] q; always @(posedge ck) q <= d; endmodule // $module EOF close (VLOG); open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (q, d, ck); output [7:0] q; input [7:0] d; input ck; $module inst (.q (q), .d (d), .ck(ck)); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status != 0),"Organization",$test,"Flip-flop in library, but without \$InitReg"); } else { push @files, $test; push @files, ($test . "_ff");} #---------------------------------------------------------------------- # Example8_17c Page 191 #---------------------------------------------------------------------- $test="Example8_17c"; if ($clean ne "clean") { $module=$test . "_ff"; $library=$test . "_ff.vlib"; open(VLOG, "> $library"); print VLOG<<"EOF"; module $module (q, d, ck); output [7:0] q; input [7:0] d; input ck; reg [7:0] q; always @(posedge ck) q <= d; // $synthesis_off initial \$InitReg(q); // $synthesis_on endmodule // $module EOF close (VLOG); open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (q, d, ck); output [7:0] q; input [7:0] d; input ck; $module inst (.q (q), .d (d), .ck(ck)); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status == 0),"Organization",$test,"Flip-flop outside of library, with \$InitReg"); } else { push @files, $test; push @files, ($test . "_ff");} #---------------------------------------------------------------------- # Example8_18 page 192 #---------------------------------------------------------------------- $test="Example8_18"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (p, w, x, y, z); input [7:0] w, x, y, z; output [7:0] p; wire [7:0] w, x, y, z; reg [7:0] p, r, s; always @(w or x or y) // or z omitted begin r = w | x; s = y | z; p = r & s; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StructureTests; $StructureScore += logstatus (($status != 0),"Structure",$test,"Identifier omitted from sensitivity list"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_19 Page 193 #---------------------------------------------------------------------- $test="Example8_19"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (p, w, x, y, z); input [7:0] w, x, y, z; output [7:0] p; wire [7:0] w, x, y, z; reg [7:0] p, r, s; always @(w or x or y or z) begin r = w | x; // rank 1 p = r & s; // rank 2 s = y | z; // rank 1 end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StructureTests; $StructureScore += logstatus (($status != 0),"Structure",$test,"Procedural assignment statement sequence error"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section_8_4_2_2a Page 192 #---------------------------------------------------------------------- $test="Section_8_4_2_2a"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (d1,s1,din); output [3:0] d1; input s1; input [3:0] din; reg [3:0] d1; always @ (s1 or din) if (s1 == 1'b1) d1 = din; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StructureTests; $StructureScore += logstatus (($status != 0),"Structure",$test,"Latch inference omits latch intention pragma"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section_8_4_2_2b Page 192 #---------------------------------------------------------------------- $test="Section_8_4_2_2b"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (d1,s1,din); output [3:0] d1; input s1; input [3:0] din; $latch_forgiveness_prefix reg [3:0] d1; $latch_forgiveness_suffix always @ (s1 or din) if (s1 == 1'b1) $latch_forgiveness_online d1 = din; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StructureTests; $StructureScore += logstatus (($status == 0),"Structure",$test,"Latch inference includes latch intention pragma"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_22a Page 197 #---------------------------------------------------------------------- $test="Example8_22a"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (ck,c,a); input ck; output [15:0] c; input [15:0] a; reg [15:0] b,c; always @(posedge ck) begin b = a; end always @(posedge ck) begin c = b; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Blocking assignments with a race"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_23a Page 198 #---------------------------------------------------------------------- $test="Example8_23a"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (done,count_ff); output done; input [4:0] count_ff; assign done = & (count_ff[4:0]+1); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Bit width mismatch across + operator"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_24 Page 199 #---------------------------------------------------------------------- $test="Example8_24"; if ($clean ne "clean") { open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (a_r,b_c,d_out); input a_r; input [7:0] b_c; output [7:0] d_out; reg [7:0] d_c; wire [7:0] d_out; always @(a_r or b_c) begin if (a_r == 1'b1) d_c = d_c + b_c; else d_c = d_c - b_c; end assign d_out = d_c; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Identifier reference before being assigned"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example8_25 Page 199 #---------------------------------------------------------------------- $test="Example8_25"; if ($clean ne "clean") { $module=$test . "_ff"; $library=$test . "_ff.vlib"; open(VLOG, "> $library"); print VLOG<<"EOF"; module $module (clk,reset_,pad_o,pad_ff); input clk, reset_; input [31:0] pad_o; output [31:0] pad_ff; reg [31:0] pad_ff; always @(posedge clk or reset_) pad_ff <= reset_ ? pad_o : 32'h0; endmodule // $module EOF close (VLOG); open(VLOG, "> $test.v"); print VLOG<<"EOF"; module $test (clk,reset_,pad_o,pad_ff); input clk, reset_; input [31:0] pad_o; output [31:0] pad_ff; Example8_25_ff inst (.clk (clk), .reset_(reset_), .pad_o(pad_o), .pad_ff( pad_ff)); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Problematic reset behavior in flip-flop"); } else { push @files, $test; push @files, ($test . "_ff");} #---------------------------------------------------------------------- # Example8_26 Page 200 #---------------------------------------------------------------------- $test="Example8_26"; if ($clean ne "clean") { $module=$test . "_ff"; $library=$test . "_ff.vlib"; open(VLOG, "> $library"); print VLOG<<"EOF"; module $module (s1,clk,reset_L,d0_ready,d1_ready); input s1,clk,reset_L,d0_ready; output d1_ready; reg d1_ready; always @(posedge s1) d1_ready <= (reset_L) ? 1'b1 : 1'b0; always @(negedge clk) d1_ready <= ~d0_ready & d1_ready; endmodule // $module EOF close (VLOG); open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (s1,clk,reset_L,d0_ready,d1_ready); input s1,clk,reset_L,d0_ready; output d1_ready; $module inst ( .s1(s1), .clk(clk), .reset_L(reset_L), .d0_ready(d0_ready), .d1_ready(d1_ready)); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"FF assignments from multiple procedural blocks"); } else { push @files, $test; push @files, ($test . "_ff");} #---------------------------------------------------------------------- # Table_8_2_and Page 205 #---------------------------------------------------------------------- $test="Table_8_2_and"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,i1,i2); output o; input i1,i2; and inst (o,i1,i2); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Unsupported Verilog keyword and"); } else { push @files, $test; } #---------------------------------------------------------------------- # Table_8_2_nor Page 205 #---------------------------------------------------------------------- $test="Table_8_2_nor"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,i1,i2); output o; input i1,i2; nor inst (o,i1,i2); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Unsupported Verilog keyword nor"); } else { push @files, $test; } #---------------------------------------------------------------------- # Table_8_2_or Page 205 #---------------------------------------------------------------------- $test="Table_8_2_or"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,i1,i2); output o; input i1,i2; or inst (o,i1,i2); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Unsupported Verilog keyword or"); } else { push @files, $test; } #---------------------------------------------------------------------- # Table_8_2_xnor Page 205 #---------------------------------------------------------------------- $test="Table_8_2_xnor"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,i1,i2); output o; input i1,i2; xnor inst (o,i1,i2); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Unsupported Verilog keyword xnor"); } else { push @files, $test; } #---------------------------------------------------------------------- # Table_8_2_xor Page 205 #---------------------------------------------------------------------- $test="Table_8_2_xor"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,i1,i2); output o; input i1,i2; xor inst (o,i1,i2); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Unsupported Verilog keyword xor"); } else { push @files, $test; } #---------------------------------------------------------------------- # Chapter 9 Verifiable RTL Tutorial #---------------------------------------------------------------------- #---------------------------------------------------------------------- # Section9_5_1_1plus Page 218 #---------------------------------------------------------------------- $test="Section9_5_1_1plus"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output [15:0] o; input [15:0] a; input [14:0] b; wire [15:0] o; assign o = a + b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Bit width mismatch across + operator"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_1minus Page 218 #---------------------------------------------------------------------- $test="Section9_5_1_1minus"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output [15:0] o; input [15:0] a; input [14:0] b; wire [15:0] o; assign o = a - b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Bit width mismatch across - operator"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_1mod Page 218 #---------------------------------------------------------------------- $test="Section9_5_1_1mod"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a); output [16:0] o; input [16:0] a; wire [16:0] o; assign o = a % 4'd5; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Right operand of 'mod' operator must be integer power of '2'" ); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_1bwand Page 219 #---------------------------------------------------------------------- $test="Section9_5_1_1bwand"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output [16:0] o; input [16:0] a; input [15:0] b; wire [16:0] o; assign o = a & b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Bit width mismatch across & operator"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_1bwor Page 219 #---------------------------------------------------------------------- $test="Section9_5_1_1bwor"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output [16:0] o; input [16:0] a; input [15:0] b; wire [16:0] o; assign o = a | b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Bit width mismatch across | operator"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_1bwxor Page 219 #---------------------------------------------------------------------- $test="Section9_5_1_1bwxor"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output [16:0] o; input [16:0] a; input [15:0] b; wire [16:0] o; assign o = a ^ b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Bit width mismatch across ^ operator"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_1bwnxor Page 219 #---------------------------------------------------------------------- $test="Section9_5_1_1bwnxor"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output [16:0] o; input [16:0] a; input [15:0] b; wire [16:0] o; assign o = a ~^ b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Bit width mismatch across ~^ operator"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_1land Page 219 #---------------------------------------------------------------------- $test="Section9_5_1_1land"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output o; input [16:0] a; input b; wire o; assign o = a && b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Logical operator && applied to multi-bit operand(s)"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_1lor Page 219 #---------------------------------------------------------------------- $test="Section9_5_1_1lor"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output o; input [16:0] a; input [16:0] b; wire o; assign o = a || b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Logical operator || applied to multi-bit operand(s)"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_1leq Page 219 #---------------------------------------------------------------------- $test="Section9_5_1_1leq"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a); output o; input [16:0] a; wire o; assign o = a <= 32; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Bit width mismatch across <= relational operator"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_1lneq Page 219 #---------------------------------------------------------------------- $test="Section9_5_1_1lneq"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output o; input [16:0] a; input [31:0] b; wire o; assign o = a != b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Bit width mismatch across != relational operator"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_1lgt Page 219 #---------------------------------------------------------------------- $test="Section9_5_1_1lgt"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output o; input [9:0] a; input [7:0] b; wire o; assign o = a > b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Bit width mismatch across > relational operator"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_1llt Page 219 #---------------------------------------------------------------------- $test="Section9_5_1_1llt"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a); output o; input [16:0] a; wire o; assign o = 0 < a; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Bit width mismatch across < relational operator"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_1geq Page 219 #---------------------------------------------------------------------- $test="Section9_5_1_1geq"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a); output o; input [9:0] a; wire o; assign o = a >= 3; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Bit width mismatch across >= relational operator"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_2bwnot Page 219 #---------------------------------------------------------------------- $test="Section9_5_1_2bwnot"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a); output [9:0] o; input [7:0] a; wire [9:0] o; assign o = ~a; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Bit width mismatch across ~ assignment"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_2lnot Page 220 #---------------------------------------------------------------------- $test="Section9_5_1_2lnot"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a); output o; input [7:0] a; wire o; assign o = !a; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Logical operator ! applied to multi-bit variable"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_3condexp Page 220 #---------------------------------------------------------------------- $test="Section9_5_1_3condexp"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (x,m,q,r); output [3:0] x; input [3:0] m; input [7:4] q; input [5:0] r; wire [3:0] x; assign x = (m[3:0] == 4'd5) ? q[7:4] : r[5:0]; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Width mismatch across == operator"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_3louminus Page 221 #---------------------------------------------------------------------- $test="Section9_5_1_3louminus"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a); output [7:0] o; input [7:0] a; wire [7:0] o,a; assign o = -a; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status != 0),"Organization",$test,"Operator unary - outside of library"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_3louminusOK Page 221 #---------------------------------------------------------------------- $test="Section9_5_1_3louminusOK"; if ($clean ne "clean") { $module=$test . "_uminus"; $library=$test . "_uminus.vlib"; open(VLOG, "> $library"); print VLOG<<"EOF"; module $module (o, a); output [7:0] o; input [7:0] a; wire [7:0] o; assign o = -a; endmodule // $module EOF close (VLOG); open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o, a); output [7:0] o; input [7:0] a; wire [7:0] o,a; $module inst (.o (o), .a (a)); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status == 0),"Organization",$test,"Operator unary - in library"); } else { push @files, $test; push @files, ($test . "_uminus");} #---------------------------------------------------------------------- # Section9_5_1_3lomult Page 221 #---------------------------------------------------------------------- $test="Section9_5_1_3lomult"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output [7:0] o; input [7:0] a,b; wire [7:0] o,a,b; assign o = a*b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status != 0),"Organization",$test,"Operator * outside of library"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_3lomultOK Page 221 #---------------------------------------------------------------------- $test="Section9_5_1_3lomultOK"; if ($clean ne "clean") { $module=$test . "_mult"; $library=$test . "_mult.vlib"; open(VLOG, "> $library"); print VLOG<<"EOF"; module $module (o,a,b); output [7:0] o; input [7:0] a,b; wire [7:0] o; assign o = a*b; endmodule // $module EOF close (VLOG); open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output [7:0] o; input [7:0] a,b; wire [7:0] o,a,b; $module inst (.o (o), .a (a), .b (b)); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status == 0),"Organization",$test,"Operator * in library"); } else { push @files, $test; push @files, ($test . "_mult");} #---------------------------------------------------------------------- # Section9_5_1_3lodiv Page 221 #---------------------------------------------------------------------- $test="Section9_5_1_3lodiv"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output [7:0] o; input [7:0] a,b; wire [7:0] o,a,b; assign o = a/b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status != 0),"Organization",$test,"Operator / outside of library"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_3lodivOK Page 221 #---------------------------------------------------------------------- $test="Section9_5_1_3lodivOK"; if ($clean ne "clean") { $module=$test . "_div"; $library=$test . "_div.vlib"; open(VLOG, "> $library"); print VLOG<<"EOF"; module $module (o,a,b); output [7:0] o; input [7:0] a,b; wire [7:0] o; assign o = a/b; endmodule // $module EOF close (VLOG); open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output [7:0] o; input [7:0] a,b; wire [7:0] o,a,b; $module inst (.o (o), .a (a), .b (b)); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status == 0),"Organization",$test,"Operator / in library"); } else { push @files, $test; push @files, ($test . "_div");} #---------------------------------------------------------------------- # Section9_5_1_3loeq Page 221 #---------------------------------------------------------------------- $test="Section9_5_1_3loeq"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output o; input [7:0] a,b; wire o; wire [7:0] a,b; assign o = (a === b); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status != 0),"Organization",$test,"Operator === outside of library"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_3loeqOK Page 221 #---------------------------------------------------------------------- $test="Section9_5_1_3loeqOK"; if ($clean ne "clean") { $module=$test . "_eq"; $library=$test . "_eq.vlib"; open(VLOG, "> $library"); print VLOG<<"EOF"; module $module (o,a,b); output o; input [7:0] a,b; wire o; assign o = (a === b); endmodule // $module EOF close (VLOG); open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output o; input [7:0] a,b; wire o; wire [7:0] a,b; $module inst (.o (o), .a (a), .b (b)); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status == 0),"Organization",$test,"Operator === in library"); } else { push @files, $test; push @files, ($test . "_eq");} #---------------------------------------------------------------------- # Section9_5_1_3loneq Page 221 #---------------------------------------------------------------------- $test="Section9_5_1_3loneq"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output o; input [7:0] a,b; wire o; wire [7:0] a,b; assign o = (a !== b); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status != 0),"Organization",$test,"Operator !== outside of library"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_5_1_3loneqOK Page 221 #---------------------------------------------------------------------- $test="Section9_5_1_3loneqOK"; if ($clean ne "clean") { $module=$test . "_neq"; $library=$test . "_neq.vlib"; open(VLOG, "> $library"); print VLOG<<"EOF"; module $module (o,a,b); output o; input [7:0] a,b; wire o; assign o = (a !== b); endmodule // $module EOF close (VLOG); open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (o,a,b); output o; input [7:0] a,b; wire o; wire [7:0] a,b; $module inst (.o (o), .a (a), .b (b)); endmodule // $test EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status == 0),"Organization",$test,"Operator !== in library"); } else { push @files, $test; push @files, ($test . "_neq");} #---------------------------------------------------------------------- # Example9_10 Page 221 #---------------------------------------------------------------------- $test="Example9_10"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (c,a,b); output c; input a; input [7:0] b; wire c; assign c = a | | b; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StyleTests; $StyleScore += logstatus (($status != 0),"Style",$test,"Operator precedence ambiguity"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example9_11_1a Page 223 #---------------------------------------------------------------------- $test="Example9_11_1a"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (p, w, x, y, z); input [7:0] w, x, y, z; output [7:0] p; wire [7:0] w, x, y, z; reg [7:0] p, r, s; always @(w or x or y) // or z omitted/ begin r = w | x; s = y | z; p = r & s; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StructureTests; $StructureScore += logstatus (($status != 0),"Structure",$test,"Identifier omitted from sensitivity list"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example9_11_1b Page 223 #---------------------------------------------------------------------- $test="Example9_11_1b"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (p, w, x, y, z); input [7:0] w, x, y, z; output [7:0] p; wire [7:0] w, x, y, z; reg [7:0] p, r, s; always @(w or x or y or z or s) begin r = w | x; s = y | z; p = r & s; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StructureTests; $StructureScore += logstatus (($status != 0),"Structure",$test,"Identifier 's' appears both as an assignment target and in the 'always' sensitivity list"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example9_11_2 Page 223 #---------------------------------------------------------------------- $test="Example9_11_2"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (p, w, x, y, z); input [7:0] w, x, y, z; output [7:0] p; wire [7:0] w, x, y, z; reg [7:0] p, r, s; always @(w or x or y or z) begin r = w | x; p = r & s; s = y | z; end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$StructureTests; $StructureScore += logstatus (($status != 0),"Structure",$test,"Procedural assignment statement sequence error"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example9_14call Page 224 #---------------------------------------------------------------------- $test="Example9_14call"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (ap_in0,ap_in1, ap_out0,ap_out1); input [40:0] ap_in0; input [39:0] ap_in1; output [47:0] ap_out0, ap_out1; reg [47:0] ap_out0, ap_out1; function [47:0] c_ecc_out; input [39:0] c_data_in; begin c_ecc_out = { (^ (c_data_in & 40'h00000007f8)), (^ (c_data_in & 40'h003ffff893)), (^ (c_data_in & 40'h0fc03f5c06)), (^ (c_data_in & 40'h71c3cfa84d)), (^ (c_data_in & 40'hb6445533ff)), (^ (c_data_in & 40'hd298e2fa38)), (^ (c_data_in & 40'h0f294bc17f)), (^ (c_data_in & 40'hea360cfc67)) , c_data_in}; end endfunction always @(ap_in0 or ap_in1) begin ap_out0 = c_ecc_out (ap_in0); ap_out1 = c_ecc_out (ap_in1); end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Function call actual parameter 1 does not match formal type"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example9_14return Page 224 #---------------------------------------------------------------------- $test="Example9_14return"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (ap_in0,ap_in1, ap_out0,ap_out1); input [39:0] ap_in0, ap_in1; output [47:0] ap_out0; output [46:0] ap_out1; reg [47:0] ap_out0; reg [46:0] ap_out1; function [47:0] c_ecc_out; input [39:0] c_data_in; begin c_ecc_out = { (^ (c_data_in & 40'h00000007f8)), (^ (c_data_in & 40'h003ffff893)), (^ (c_data_in & 40'h0fc03f5c06)), (^ (c_data_in & 40'h71c3cfa84d)), (^ (c_data_in & 40'hb6445533ff)), (^ (c_data_in & 40'hd298e2fa38)), (^ (c_data_in & 40'h0f294bc17f)), (^ (c_data_in & 40'hea360cfc67)) , c_data_in}; end endfunction always @(ap_in0 or ap_in1) begin ap_out0 = c_ecc_out (ap_in0); ap_out1 = c_ecc_out (ap_in1); end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Function return width mismatch across assignment"); } else { push @files, $test; } #---------------------------------------------------------------------- # Figure9_6 Page 225 #---------------------------------------------------------------------- $test="Figure9_6"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (p, q, s, w, x, y, z); input s; input [7:0] w, x, y, z; output [7:0] p, q; wire s; wire [7:0] w, x, y, z; reg [7:0] p, q; always @(s or w or x or y or z) begin if (s == 1'b1) begin p = w | y; end else begin p = x; q = z; end end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status != 0),"Organization",$test,"Variable not assign in both branches"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example9_16rule1 Page 226 #---------------------------------------------------------------------- $test="Example9_16rule1"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (p, s, w, x, y, z); input [1:0] s; input [7:0] w, x, y, z; output [7:0] p; wire [1:0] s; wire [7:0] w, x, y, z; reg [7:0] p; always @(s or w or x or y or z) case (s) 2'b00 : p = w; 2'b01 : p = x; 2'b10 : p = y; 3'b11 : p = z; endcase endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$TypingTests; $TypingScore += logstatus (($status != 0),"Typing",$test,"Width mismatch between case literals"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example9_16rule2 Page 226 #---------------------------------------------------------------------- $test="Example9_16rule2"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (p, s, w, x, y, z); input [1:0] s; input [7:0] w, x, y, z; output [7:0] p; wire [1:0] s; wire [7:0] w, x, y, z; reg [7:0] p; always @(s or w or x or y or z) case (s) 2'b00 : p = w | z; 2'b01 : p = x; 2'b10 : p = y; endcase endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$CaseTests; $CaseScore += logstatus (($status != 0),"Case",$test,"Incomplete case statement has no default"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example9_16rule2a Page 226 #---------------------------------------------------------------------- $test="Example9_16rule2a"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (p, s, w, x, y, z); input [1:0] s; input [7:0] w, x, y, z; output [7:0] p; wire [1:0] s; wire [7:0] w, x, y, z; reg [7:0] p; always @(s or w or x or y or z) case (s) 2'b01 : p = x; 2'b10 : p = y; default : p = w | z; endcase endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$CaseTests; $CaseScore += logstatus (($status == 0),"Case",$test,"Incomplete case statement has default"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example9_16rule2b Page 226 #---------------------------------------------------------------------- $test="Example9_16rule2b"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (p, s, w, x, y, z); input [1:0] s; input [7:0] w, x, y, z; output [7:0] p; wire [1:0] s; wire [7:0] w, x, y, z; reg [7:0] p; always @(s or w or x or y or z) begin p = w | z; case (s) 2'b01 : p = x; 2'b10 : p = y; endcase end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$CaseTests; $CaseScore += logstatus (($status == 0),"Case",$test,"Incomplete case statement preceded by default assignment"); } else { push @files, $test; } #---------------------------------------------------------------------- # Example9_17 Page 227 #---------------------------------------------------------------------- $test="Example9_17"; if ($clean ne "clean") { $library=$test . "_ff.vlib"; $module=$test . "_ff"; open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (ck ,rst , r_gc); input ck ,rst; output [1:0] r_gc; wire [1:0] r_gc; reg [1:0] n; always @(r_gc) case (r_gc) 2'b00 : n = 2'b01; 2'b01 : n = 2'b11; 2'b11 : n = 2'b10; 2'b10 : n = 2'b00; endcase $module #(2) reg_r ( .q(r_gc), .ck(ck), .d(n), .rst (rst) ); endmodule // $test EOF close (VLOG); open(VLOG, "> $library") || die "failed\n"; print VLOG<<"EOF"; module $module (q, ck ,rst , d); parameter W = 1; input ck ,rst; input [W-1:0] d; output [W-1:0] q; reg [W-1:0] q; always @(posedge ck) q <= (rst == 1'b0) ? d : {W{1'b0}}; endmodule // $module EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status == 0),"Organization",$test,"Flip-flop in library"); } else { push @files, $test; push @files, ($test . "_ff");} #---------------------------------------------------------------------- # Example9_18 Page 227 #---------------------------------------------------------------------- $test="Example9_18"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (c_error_vector, c_code); input [4:0] c_error_vector; output [2:0] c_code; reg [2:0] c_code; always @ (c_error_vector) begin casex (c_error_vector) 5'b1????: c_code = 3'h1; 5'b01???: c_code = 3'h2; 5'b001??: c_code = 3'h3; 5'b0001?: c_code = 3'h4; 5'b00001: c_code = 3'h5; 5'b00000: c_code = 3'h0; endcase end endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$CaseTests; $CaseScore += logstatus (($status == 0),"Case",$test,"Fully-specified case allowed"); } else { push @files, $test; } #---------------------------------------------------------------------- # Section9_6_2_2a Page 228 #---------------------------------------------------------------------- $test="Section9_6_2_2a"; if ($clean ne "clean") { $library=$test . "_ff.vlib"; $module=$test . "_ff"; open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (m, en, d); input en; input [1:0] d; output [1:0] m; $module #(2) latch ( .m(m), .en(en), .d(d)); endmodule // $test EOF close (VLOG); open(VLOG, "> $library") || die "failed\n"; print VLOG<<"EOF"; module $module (m, en, d); parameter W = 1; input en; input [W-1:0] d; output [W-1:0] m; reg [W-1:0] m; always @(en or d) if (en == 1'b1) m = d; endmodule // $module EOF close (VLOG); $vlog_args = "$test.v -v $library"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status != 0),"Organization",$test,"Latch requires pragma"); } else { push @files, $test; push @files, ($test . "_ff");} #---------------------------------------------------------------------- # Section9_6_2_2b Page 228 #---------------------------------------------------------------------- $test="Section9_6_2_2b"; if ($clean ne "clean") { open(VLOG, "> $test.v") || die "failed\n"; print VLOG<<"EOF"; module $test (m, en, d); input en; input [1:0] d; output [1:0] m; $latch_forgiveness_prefix reg [1:0] m; $latch_forgiveness_suffix always @(en or d) if (en == 1'b1) $latch_forgiveness_online m = d; endmodule // $test EOF close (VLOG); $vlog_args = "$test.v"; $status = system ( "$lint_tool $vlog_args > $test.out 2> $test.err" ); ++$OrganizationTests; $OrganizationScore += logstatus (($status != 0),"Organization",$test,"Latch outside of library"); } else { push @files, $test; } if ($clean ne "clean") { #---------------------------------------------------------------------- # 4.0 Scoring #---------------------------------------------------------------------- $TotalScore = 0; #---------------------------------------------------------------------- # 4.1 Case tests #---------------------------------------------------------------------- $Score = 100.0; print "Case tests: $CaseScore out of $CaseTests tests pass\n"; $PenaltyFactor = 0.80; for ($i=$CaseScore; $i < $CaseTests; $i++) { $Score = $Score * $PenaltyFactor; $PenaltyFactor = 0.98; } $TotalScore = $TotalScore + $Score; #---------------------------------------------------------------------- # 4.2 NoXstate tests #---------------------------------------------------------------------- $Score = 100.0; print "NoXstate tests: $NoXstateScore out of $NoXstateTests tests pass\n"; $PenaltyFactor = 0.80; for ($i=$NoXstateScore; $i < $NoXstateTests; $i++) { $Score = $Score * $PenaltyFactor; $PenaltyFactor = 0.98; } $TotalScore = $TotalScore + $Score; #---------------------------------------------------------------------- # 4.3 Organization tests #---------------------------------------------------------------------- $Score = 100.0; print "Organization tests: $OrganizationScore out of $OrganizationTests tests pass\n"; $PenaltyFactor = 0.80; for ($i=$OrganizationScore; $i < $OrganizationTests; $i++) { $Score = $Score * $PenaltyFactor; $PenaltyFactor = 0.98; } $TotalScore = $TotalScore + $Score; #---------------------------------------------------------------------- # 4.4 Structure tests #---------------------------------------------------------------------- $Score = 100.0; print "Structure tests: $StructureScore out of $StructureTests tests pass\n"; $PenaltyFactor = 0.80; for ($i=$StructureScore; $i < $StructureTests; $i++) { $Score = $Score * $PenaltyFactor; $PenaltyFactor = 0.98; } $TotalScore = $TotalScore + $Score; #---------------------------------------------------------------------- # 4.5 Style tests #---------------------------------------------------------------------- $Score = 100.0; print "Style tests: $StyleScore out of $StyleTests tests pass\n"; $PenaltyFactor = 0.80; for ($i=$StyleScore; $i < $StyleTests; $i++) { $Score = $Score * $PenaltyFactor; $PenaltyFactor = 0.98; } $TotalScore = $TotalScore + $Score;; #---------------------------------------------------------------------- # 4.6 Typing tests #---------------------------------------------------------------------- $Score = 100.0; print "Typing tests: $TypingScore out of $TypingTests tests pass\n"; $PenaltyFactor = 0.80; for ($i=$TypingScore; $i < $TypingTests; $i++) { $Score = $Score * $PenaltyFactor; $PenaltyFactor = 0.98; } printf (" Score = %5.1f\n",$Score); $TotalScore = $TotalScore + $Score; #---------------------------------------------------------------------- # 4.7 Total scores #---------------------------------------------------------------------- printf ("\nTotal Score = %5.1f out of a possible 600\n",$TotalScore); printf (" Total tests passed = %3d\n", $CaseScore + $NoXstateScore + $OrganizationScore + $StructureScore + $StyleScore + $TypingScore); printf (" Total tests run = %3d\n", $CaseTests + $NoXstateTests + $OrganizationTests + $StructureTests + $StyleTests + $TypingTests); } #---------------------------------------------------------------------- # 5.0 Clean #---------------------------------------------------------------------- else { print ("Cleaning\n"); while (@files) { $file = shift @files; system("rm $file.*"); } } #---------------------------------------------------------------------- # 6.0 Sub's #---------------------------------------------------------------------- #---------------------------------------------------------------------- # 6.1 logstatus #---------------------------------------------------------------------- sub logstatus { my $statusOK = shift(@_); my $category = shift(@_); my $test = shift(@_); my $comment = shift(@_); if ($statusOK) { printf ("%25s %-14s OK Diagnostic: %s\n",$test,$category,$comment); return 1; } else { printf ("%25s %-14s NG Not diagnosed: %s\n",$test,$category,$comment); return 0; } } #---------------------------------------------------------------------- # 6.2 Usage #---------------------------------------------------------------------- sub usage { print <<"EOF"; Usage lint_eval.pl -h : Report usage options lint_eval.pl : Run test cases using inhouse vendorX lint_eval.pl clean : Delete test case files Before using: Edit section 2.1 Constants, replacing "X" and "Y" with actual vendor names. Edit section 2.2 Initialization. Fill in "linttool" with actual vendor names, and fill in latch and feedback forgiveness with pragmas specific to each tool. EOF exit(0); }