add directives comment

This commit is contained in:
setsumi 2024-12-13 11:34:50 +00:00
parent 1090face1e
commit 1142aa324f

View File

@ -5,6 +5,7 @@ use tower_lsp::lsp_types::*;
/// date: 2024.12.13 /// date: 2024.12.13
pub const VLOG_DIRECTIVES: &[(&str, &str, &str)] = &[ pub const VLOG_DIRECTIVES: &[(&str, &str, &str)] = &[
// 1800-2009 22.13 `__FILE__ and `__LINE__
( (
"__FILE__", "__FILE__",
"`__FILE__", "`__FILE__",
@ -37,43 +38,7 @@ module test;
endmodule endmodule
``` ```
"#), "#),
( // 19.1 `celldefine and `endcelldefine
"begin_keywords",
"`begin_keywords\n$1\n`end_keywords ",
r#"`begin_keywords` 和 `end_keywords` 是用于指定 Verilog 语言版本的编译指令。它们允许设计者在同一个文件中使用不同版本的 Verilog 语法,从而实现兼容性或逐步迁移到新版本。
`begin_keywords` Verilog
- `1364-1995`Verilog-1995
- `1364-2001`Verilog-2001
- `1364-2005`Verilog-2005
- `1800-2009`SystemVerilog-2009
- `1800-2012`SystemVerilog-2012
```verilog
// 使用 begin_keywords 和 end_keywords 指定 Verilog 版本
`begin_keywords "1364-2001" // 指定 Verilog-2001 语法
module my_module;
reg [7:0] data;
initial begin
data = 8'hFF; // 使用 Verilog-2001 的语法
$display("Verilog-2001 语法: data = %h", data);
end
endmodule
`end_keywords // 结束 Verilog-2001 语法
// 恢复默认的 Verilog 语法
module another_module;
reg [7:0] data;
initial begin
data = 8'hAA; // 使用默认的 Verilog 语法
$display("默认语法: data = %h", data);
end
endmodule
```
"#),
( (
"celldefine", "celldefine",
"`celldefine\n$1\n`endcelldefine", "`celldefine\n$1\n`endcelldefine",
@ -123,11 +88,18 @@ endmodule
- `celldefine` 仿 - `celldefine` 仿
- 使 celldefine - 使 celldefine
"#), "#),
(
"endcelldefine",
"`endcelldefine",
"结束单元格定义"
),
// 19.2 `default_nettype
( (
"default_nettype", "default_nettype",
"`default_nettype $1", "`default_nettype $1",
"设置默认的网络类型" "设置默认的网络类型"
), ),
// 19.3 `define and `undef
( (
"define", "define",
"`define $1 $2", "`define $1 $2",
@ -166,30 +138,17 @@ endmodule
``` ```
"#), "#),
( (
"else", "undef",
"`else", "`undef $1",
"条件编译的 else 分支" "取消定义一个宏"
), ),
// 1800-2009 22.5 `define, `undef and `undefineall
( (
"elsif", "undefineall",
"`elsif $1", "`undefineall",
"条件编译的 elsif 分支" "取消定义所有宏"
),
(
"end_keywords",
"`end_keywords",
"结束关键字版本指定"
),
(
"endcelldefine",
"`endcelldefine",
"结束单元格定义"
),
(
"endif",
"`endif",
"结束条件编译"
), ),
// 19.4 `ifdef, `else, `elsif, `endif, `ifndef
( (
"ifdef", "ifdef",
"`ifdef $1\n\t//ifdef\n\t$2\n`else\n//else\n\t$3\n`endif", "`ifdef $1\n\t//ifdef\n\t$2\n`else\n//else\n\t$3\n`endif",
@ -235,16 +194,53 @@ endmodule
"# "#
), ),
(
"else",
"`else",
"条件编译的 else 分支"
),
(
"elsif",
"`elsif $1",
"条件编译的 elsif 分支"
),
(
"endif",
"`endif",
"结束条件编译"
),
( (
"ifndef", "ifndef",
"`ifndef $1", "`ifndef $1",
"如果未定义宏,则编译代码" "如果未定义宏,则编译代码"
), ),
// 19.5 `include
( (
"include", "include",
"`include $1", "`include $1",
"包含一个外部文件" "包含一个外部文件"
), ),
// 19.6 `resetall
(
"resetall",
"`resetall",
// resetall 也常用于开始
// 1834-2005中指出建议的用法是将 `resetall 放在每个源文本文件的开头,后面紧跟着文件中所需的指令。
// 通常可用于源文本开头,避免该文件受到其他文件代码的影响。或放置在末尾,避免编译器设置的进一步传递
r#"`resetall` 用于重置所有编译器设置为默认值。它通常用于在模块或文件的末尾清除所有编译器设置,以确保后续代码不受之前设置的影响。
```verilog
`timescale 1ns/1ps // 设置时间单位和精度
module test;
// 一些 verilog 代码
endmodule
`resetall // 重置所有编译器设置,上文的 timescale 设置自此开始无效
```
"#
),
// 19.7 `line
( (
"line", "line",
"`line $1 $2 $3", "`line $1 $2 $3",
@ -269,55 +265,14 @@ endmodule
``` ```
"# "#
), ),
( // 19.8 `timescale
"unconnected_drive",
"`unconnected_drive ${1:pull1}\n$2\n`nounconnected_drive\n",
r#"`nounconnected_drive` 和 `unconnected_drive` 是配合使用的编译指令,用于控制未连接端口的驱动行为。它们通常成对出现,分别用于禁用和启用未连接端口的驱动处理。
###
```verilog
`unconnected_drive (pull1 | pull0) // 启用未连接端口的驱动,若为 pull1则默认驱动为高电平若为 pull0则默认为低电平
// 你的 verilog 代码
`nounconnected_drive // 禁用未连接端口的驱动
```
"#
),
(
"nounconnected_drive",
"`nounconnected_drive",
r#"`nounconnected_drive` 和 `unconnected_drive` 是配合使用的编译指令,用于控制未连接端口的驱动行为。它们通常成对出现,分别用于禁用和启用未连接端口的驱动处理。
###
```verilog
`unconnected_drive (pull1 | pull0) // 启用未连接端口的驱动,若为 pull1则默认驱动为高电平若为 pull0则默认为低电平
// 你的 verilog 代码
`nounconnected_drive // 禁用未连接端口的驱动
```
"#
),
(
"pragma",
"`pragma $1",
"编译指示,用于传递编译器指令"
),
(
"resetall",
"`resetall",
r#"`resetall` 用于重置所有编译器设置为默认值。它通常用于在模块或文件的末尾清除所有编译器设置,以确保后续代码不受之前设置的影响。
```verilog
`timescale 1ns/1ps // 设置时间单位和精度
module test;
// 一些 verilog 代码
endmodule
`resetall // 重置所有编译器设置,上文的 timescale 设置自此开始无效
```
"#
),
( (
"timescale", "timescale",
"`timescale ${1:1ns}/${2:1ps}", "`timescale ${1:1ns}/${2:1ps}",
// 原文是The time_precision argument shall be at least as precise as the time_unit argument; it cannot specify a longer unit of time than time_unit.
// 也即是,仿真时间单位必须大于等于时间精度
// `timescale 1ns/1ns不会报错但是`timescale 1ps/1ns会报错
// [Synth 8-522] parsing error: error in timescale or timeprecision statement. <timeprecision> must be at least as precise as <timeunit>
r#"设置时间单位和精度,设置时间单位和精度,格式为 <code> `timescale </code> 仿真时间单位/时间精度,<code>仿真时间单位</code> 必须大于 <code>时间精度</code>,例如 r#"设置时间单位和精度,设置时间单位和精度,格式为 <code> `timescale </code> 仿真时间单位/时间精度,<code>仿真时间单位</code> 必须大于 <code>时间精度</code>,例如
```verilog ```verilog
`timescale 1ns/1ps `timescale 1ns/1ps
@ -334,16 +289,100 @@ endmodule
`timescale` `timescale` `resetall` `timescale` `timescale` `resetall`
"#), "#),
// 19.9 `unconnected_drive and `nounconnected_drive
( (
"undef", "unconnected_drive",
"`undef $1", "`unconnected_drive ${1:pull1}\n$2\n`nounconnected_drive\n",
"取消定义一个宏" r#"`nounconnected_drive` 和 `unconnected_drive` 是配合使用的编译指令,用于控制未连接端口的驱动行为。它们通常成对出现,分别用于禁用和启用未连接端口的驱动处理。
###
```verilog
`unconnected_drive (pull1 | pull0) // 启用未连接端口的驱动,若为 pull1则默认驱动为高电平若为 pull0则默认为低电平
// 你的 verilog 代码
`nounconnected_drive // 禁用未连接端口的驱动
```
###
```verilog
// 使用 `line 指令指定行号和文件名
`unconnected_drive pull1
module my_and(y, a, b);
output y;
input a, b;
assign y = a & b;
endmodule
module test(y,b);
output y;
input b;
my_and ul(y, ,b);
endmodule
`nounconnected_drive
```
"#
), ),
( (
"undefineall", "nounconnected_drive",
"`undefineall", "`nounconnected_drive",
"取消定义所有宏" r#"`nounconnected_drive` 和 `unconnected_drive` 是配合使用的编译指令,用于控制未连接端口的驱动行为。它们通常成对出现,分别用于禁用和启用未连接端口的驱动处理。
###
```verilog
`unconnected_drive (pull1 | pull0) // 启用未连接端口的驱动,若为 pull1则默认驱动为高电平若为 pull0则默认为低电平
// 你的 verilog 代码
`nounconnected_drive // 禁用未连接端口的驱动
```
"#
), ),
// 19.10 `pragma
(
"pragma",
"`pragma $1",
"编译指示,用于传递编译器指令"
),
// 19.11 `begin_keywords, `end_keywords
(
"begin_keywords",
"`begin_keywords\n$1\n`end_keywords ",
// begin_keywords并不是指定Verilog的编译版本而是指定使用的Verilog关键字版本
r#"`begin_keywords` 和 `end_keywords` 是用于指定 Verilog 语言版本的编译指令。它们允许设计者在同一个文件中使用不同版本的 Verilog 语法,从而实现兼容性或逐步迁移到新版本。
`begin_keywords` Verilog
- `1364-1995`Verilog-1995
- `1364-2001`Verilog-2001
- `1364-2005`Verilog-2005
- `1800-2009`SystemVerilog-2009
- `1800-2012`SystemVerilog-2012
```verilog
// 使用 begin_keywords 和 end_keywords 指定 Verilog 版本
`begin_keywords "1364-2001" // 指定 Verilog-2001 语法
module my_module;
reg [7:0] data;
initial begin
data = 8'hFF; // 使用 Verilog-2001 的语法
$display("Verilog-2001 语法: data = %h", data);
end
endmodule
`end_keywords // 结束 Verilog-2001 语法
// 恢复默认的 Verilog 语法
module another_module;
reg [7:0] data;
initial begin
data = 8'hAA; // 使用默认的 Verilog 语法
$display("默认语法: data = %h", data);
end
endmodule
```
"#),
(
"end_keywords",
"`end_keywords",
"结束关键字版本指定"
),
// Annex D Compiler directives
( (
"default_decay_time", "default_decay_time",
"`default_decay_time $1", "`default_decay_time $1",