如何避免Quartus II自動將未宣告的信號視為wire? (SOC) (Verilog) (Quartus II)

本文介绍Verilog2001引入的`default_nettypenone特性,该特性避免将未声明的信号默认为wire,增强了QuartusII编译器的错误检查能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Abstract
在Verilog 1995規定,對於沒宣告的信號會自動視為wire,這樣常常造成debug的困難,Verilog 2001另外定義了`default_nettype none,將不再自動產生wire,且目前Quartus II 8.1已經支援。

Introduction
很多人抱怨Quartus II對Verilog語法檢查能力很差,如以下的code,Quartus II竟然可以編譯成功。

default_nettype_none.v / Verilog

1 module default_nettype_none (
2   input n0,
3   input n1,
4   output o1
5 );
6 
7 assign ol = n0 & n1; // no error here, only warning
8 
9 endmodule


因為打錯,而將o1打成ol,Quartus II並未抓出這個錯誤,竟然順利編譯成功,雖然有warning,不過因為Quartus II一向有太多的warning,假如用了Nios II與SOPC,warning更可能多到不小心就忽略了這個warning。

像這種狀況,比較理想的方式是如同C/C++一樣,由Compiler強行產生error,讓編譯不成功,強迫coder去改code。

default_nettype_none.v / Verilog

1 `default_nettype none
2 
3 module default_nettype_none (
4   input n0,
5   input n1,
6   output o1
7 );
8 
9 assign ol = n0 & n1; // compiler error here
10 
11 endmodule


第1行加了`default_nettype none,這是Verilog 2001新增的compiler directive,避免Verilog將未宣告的信號視為wire,重要的是Quartus II 8.1有支援,並且產生了錯誤訊息,阻止繼續編譯。

Conclusion
看到Verilog 2001的`default_nettype none,使我想到了VB6與VBScript,VB因為是個弱型別語言,類似Verilog 1995一樣,只要沒宣告過的變數,VB6/VBScript會自動幫你宣告,這是C/C++這種強型別語言所不允許的,也因為如此,VB6/VBScript常因為打錯字而造成debug困難,後來VB6/VBScript提出了option explicit這個compiler directive,將VB6/VBScript變成一個強型別語言,這與Verilog 2001的`default_nettype none非常類似。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值