summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean McLoughlin <smclough@protonmail.com>2021-03-10 21:35:14 -0800
committerDavid Peter <sharkdp@users.noreply.github.com>2021-03-15 07:21:15 +0100
commitd89fa3ebc2639375b0184437607003a639d8ecef (patch)
treefecaf9f14629994c72bee62fb4c7470a4aea7cc0
parentdb57454f3fff5720e80b2783cd827a31dd2c90ae (diff)
Add SystemVerilog support
-rw-r--r--.gitmodules3
-rw-r--r--CHANGELOG.md1
-rw-r--r--assets/syntaxes.binbin685887 -> 694122 bytes
m---------assets/syntaxes/02_Extra/SystemVerilog0
-rw-r--r--src/assets.rs1
-rw-r--r--tests/no_duplicate_extensions.rs3
-rw-r--r--tests/syntax-tests/highlighted/SystemVerilog/output.sv103
-rw-r--r--tests/syntax-tests/source/SystemVerilog/output.sv103
8 files changed, 214 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules
index 3dcbc519..09231226 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -216,3 +216,6 @@
[submodule "assets/syntaxes/02_Extra/gnuplot"]
path = assets/syntaxes/02_Extra/gnuplot
url = https://github.com/hesstobi/sublime_gnuplot
+[submodule "assets/syntaxes/02_Extra/SystemVerilog"]
+ path = assets/syntaxes/02_Extra/SystemVerilog
+ url = git@github.com:TheClams/SystemVerilog.git
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a709eacf..2b02eb41 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
# unreleased
## Features
+- Add SystemVerilog file syntax, see #1580 (@SeanMcLoughlin)
## Bugfixes
diff --git a/assets/syntaxes.bin b/assets/syntaxes.bin
index f4266b48..36ab4385 100644
--- a/assets/syntaxes.bin
+++ b/assets/syntaxes.bin
Binary files differ
diff --git a/assets/syntaxes/02_Extra/SystemVerilog b/assets/syntaxes/02_Extra/SystemVerilog
new file mode 160000
+Subproject 7eca705e87f87b94478fe222fc91d54d488cc8e
diff --git a/src/assets.rs b/src/assets.rs
index 19650a27..bac0c430 100644
--- a/src/assets.rs
+++ b/src/assets.rs
@@ -450,6 +450,7 @@ mod tests {
assert_eq!(test.syntax_for_file("test.sass"), "Sass");
assert_eq!(test.syntax_for_file("test.js"), "JavaScript (Babel)");
assert_eq!(test.syntax_for_file("test.fs"), "F#");
+ assert_eq!(test.syntax_for_file("test.v"), "Verilog");
}
#[test]
diff --git a/tests/no_duplicate_extensions.rs b/tests/no_duplicate_extensions.rs
index 7bfe431a..b2be5e4e 100644
--- a/tests/no_duplicate_extensions.rs
+++ b/tests/no_duplicate_extensions.rs
@@ -17,6 +17,9 @@ fn no_duplicate_extensions() {
// The '.fs' extension appears in F# and GLSL.
// We default to F#.
"fs",
+ // SystemVerilog and Verilog both use .v files.
+ // We default to Verilog.
+ "v",
];
let assets = HighlightingAssets::from_binary();
diff --git a/tests/syntax-tests/highlighted/SystemVerilog/output.sv b/tests/syntax-tests/highlighted/SystemVerilog/output.sv
new file mode 100644
index 00000000..67d05516
--- /dev/null
+++ b/tests/syntax-tests/highlighted/SystemVerilog/output.sv
@@ -0,0 +1,103 @@
+`timescale 1ns/1ps
+
+// Design Code
+module ADDER(
+ input clk,
+ input [7:0] a,
+ input [7:0] b,
+ input bIsPos,
+ output reg [8:0] result
+);
+
+ always @ (posedge clk) begin
+ if (bIsPos) begin 
+ result <= a + b;
+ end else begin
+ result <= a - b;
+ end
+ end
+
+endmodule: ADDER
+
+interface adder_if(
+ input bit clk,
+ input [7:0] a,
+ input [7:0] b,
+ input bIsPos,
+ input [8:0] result
+);
+
+ clocking cb @(posedge clk);
+ output a;
+ output b;
+ output bIsPos;
+ input result;
+ endclocking : cb
+
+endinterface: adder_if
+
+
+bind ADDER adder_if my_adder_if(
+ .clk(clk),
+ .a(a),
+ .b(b),
+ .bIsPos(bIsPos),
+ .result(result)
+);
+
+
+// Testbench Code
+import uvm_pkg::*;
+`include "uvm_macros.svh"
+
+class testbench_env extends uvm_env;
+
+ virtual adder_if m_if;
+
+ function new(string name, uvm_component parent = null);
+ super.new(name, parent);
+ endfunction
+ 
+ function void connect_phase(uvm_phase phase);
+ assert(uvm_resource_db#(virtual adder_if)::read_by_name(get_full_name(), "adder_if", m_if));
+ endfunction: connect_phase
+
+ task run_phase(uvm_phase phase);
+ phase.raise_objection(this);
+ `uvm_info(get_name(), "Starting test!", UVM_HIGH);
+ begin
+ int a = 8'h4, b = 8'h5;
+ @(m_if.cb);
+ m_if.cb.a <= a;
+ m_if.cb.b <= b;
+ m_if.cb.bIsPos <= 1'b1;
+ repeat(2) @(m_if.cb);
+ `uvm_info(get_name(), $sformatf("%0d + %0d = %0d", a, b, m_if.cb.result), UVM_LOW);
+ end
+ `uvm_info(get_name(), "Ending test!", UVM_HIGH);
+ phase.drop_objection(this);
+ endtask: run_phase
+endclass
+
+
+module top;
+
+ bit clk;
+ env environment;
+ ADDER dut(.clk (clk));
+
+ initial begin
+ environment = new("testbench_env");
+ uvm_resource_db#(virtual adder_if)::set("env", "adder_if", dut.my_adder_if);
+ clk = 0;
+ run_test();
+ end
+
+ // Clock generation 
+ initial begin
+ forever begin
+ #(1) clk = ~clk;
+ end
+ end
+ 
+endmodule
diff --git a/tests/syntax-tests/source/SystemVerilog/output.sv b/tests/syntax-tests/source/SystemVerilog/output.sv
new file mode 100644
index 00000000..699cf04e
--- /dev/null
+++ b/tests/syntax-tests/source/SystemVerilog/output.sv
@@ -0,0 +1,103 @@
+`timescale 1ns/1ps
+
+// Design Code
+module ADDER(
+ input clk,
+ input [7:0] a,
+ input [7:0] b,
+ input bIsPos,
+ output reg [8:0] result
+);
+
+ always @ (posedge clk) begin
+ if (bIsPos) begin
+ result <= a + b;
+ end else begin
+ result <= a - b;
+ end
+ end
+
+endmodule: ADDER
+
+interface adder_if(
+ input bit clk,
+ input [7:0] a,
+ input [7:0] b,
+ input bIsPos,
+ input [8:0] result
+);
+
+ clocking cb @(posedge clk);
+ output a;
+ output b;
+ output bIsPos;
+ input result;
+ endclocking : cb
+
+endinterface: adder_if
+
+
+bind ADDER adder_if my_adder_if(
+ .clk(clk),
+ .a(a),
+ .b(b),
+ .bIsPos(bIsPos),
+ .result(result)
+);
+
+
+// Testbench Code
+import uvm_pkg::*;
+`include "uvm_macros.svh"
+
+class testbench_env extends uvm_env;
+
+ virtual adder_if m_if;
+
+ function new(string name, uvm_component parent = null);
+ super.new(name, parent);
+ endfunction
+
+ function void connect_phase(uvm_phase phase);
+ assert(uvm_resource_db#(virtual adder_if)::read_by_name(get_full_name(), "adder_if", m_if));
+ endfunction: connect_phase
+
+ task run_phase(uvm_phase phase);
+ phase.raise_objection(this);
+ `uvm_info(get_name(), "Starting test!", UVM_HIGH);
+ begin
+ int a = 8'h4, b = 8'h5;
+ @(m_if.cb);
+ m_if.cb.a <= a;
+ m_if.cb.b <= b;
+ m_if.cb.bIsPos <= 1'b1;
+ repeat(2) @(m_if.cb);
+ `uvm_info(get_name(), $sformatf("%0d + %0d = %0d", a, b, m_if.cb.result), UVM_LOW);
+ end
+ `uvm_info(get_name(), "Ending test!", UVM_HIGH);
+ phase.drop_objection(this);
+ endtask: run_phase
+endclass
+
+
+module top;
+
+ bit clk;
+ env environment;
+ ADDER dut(.clk (clk));
+
+ initial begin
+ environment = new("testbench_env");
+ uvm_resource_db#(virtual adder_if)::set("env", "adder_if", dut.my_adder_if);
+ clk = 0;
+ run_test();
+ end
+
+ // Clock generation
+ initial begin
+ forever begin
+ #(1) clk = ~clk;
+ end
+ end
+
+endmodule