如何避免Quartus II自動將未宣告的信號視為wire? (SOC) (Verilog) (Quartus II)
2010-09-28 19:26
751 查看
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非常類似。
在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非常類似。
相关文章推荐
- (筆記) 如何避免Quartus II自動將未宣告的信號視為wire? (SOC) (Verilog) (Quartus II)
- 如何使用SignalTap II觀察reg與wire值? (SOC) (Verilog) (Quartus II) (SignalTap II)
- (转)如何使用SignalTap II觀察reg與wire值? (SOC) (Verilog) (Quartus II) (SignalTap II)
- 如何使用SignalTap II觀察reg與wire值? (SOC) (Verilog) (Quartus II) (SignalTap II)
- 如何使用SignalTap II觀察reg與wire值? (SOC) (Verilog) (Quartus II) (SignalTap II)
- (原創) 如何使用SignalTap II觀察reg與wire值? (SOC) (Verilog) (Quartus II) (SignalTap II)
- 【转】如何使用SignalTap II觀察reg與wire值? (SOC) (Verilog) (Quartus II) (SignalTap II)
- (原創) 如何在安裝SELinux的環境執行Quartus II? (SOC) (Quartus II) (Linux) (RedHat)
- (筆記) 如何讓所有project共用Verilog PLI的dll? (SOC) (Verilog PLI)
- (原創) 如何將parallel轉成serial?如何將serial轉成parallel? (SOC) (Verilog)
- (原創) 如何計算浮點數? (SOC) (Verilog)
- (原創) 如何做functional simulation? (SOC) (Quartus II) (ModelSim)
- (筆記) 如何設計邊緣檢測電路? (SOC) (Verilog)
- (筆記) Altera所提供的在線技術培訓 (SOC) (Quartus II) (Nios II) (SOPC Builder) (SignalTap II) (Verilog) (VHDL)
- (原創) 如何讓Quartus II 8.0的Programmer不要另開新視窗? (SOC) (Quartus II)
- (原創) 如何實現Real Time的Binary Image? (SOC) (Verilog) (Image Processing) (DE2-70) (TRDB-D5M) (TRDB-LTM)
- (原創) 如何解決DE2-70的『Error: Can't place pins assigned to pin location Pin_AD25 (IOC_X95_Y2_N1)』的錯誤訊息? (SOC) (Quartus II) (DE2-70)
- 如何實現Real Time的Sobel Edge Detector? (SOC) (Verilog) (Image Processing) (DE2-70) (TRDB-D5M) (TRDB-LTM)
- (筆記) 如何設計D Latch與D Flip-Flop? (SOC) (Verilog)
- 如何破解Quartus II 8.0? (SOC) (Quartus II) (Nios II)