summaryrefslogtreecommitdiff
path: root/verilator_example_c++
diff options
context:
space:
mode:
authorMartin Stensgård <mastensg@mastensg.net>2025-04-26 17:45:52 +0200
committerMartin Stensgård <mastensg@mastensg.net>2025-04-26 17:45:52 +0200
commita9859aebb4a1baf58b2cf383ca85ba80d4eea313 (patch)
tree5c4b075eb0868bf08ba156172c68e2ee1124b640 /verilator_example_c++
parent554b69e206027918e38c8da33099937da9332456 (diff)
verilator_example_c++: hello
Diffstat (limited to 'verilator_example_c++')
-rw-r--r--verilator_example_c++/.gitignore1
-rw-r--r--verilator_example_c++/Makefile12
-rw-r--r--verilator_example_c++/hello.v6
-rw-r--r--verilator_example_c++/sim_main.cc15
4 files changed, 34 insertions, 0 deletions
diff --git a/verilator_example_c++/.gitignore b/verilator_example_c++/.gitignore
new file mode 100644
index 0000000..d38e9f1
--- /dev/null
+++ b/verilator_example_c++/.gitignore
@@ -0,0 +1 @@
+/obj_dir
diff --git a/verilator_example_c++/Makefile b/verilator_example_c++/Makefile
new file mode 100644
index 0000000..42f6e54
--- /dev/null
+++ b/verilator_example_c++/Makefile
@@ -0,0 +1,12 @@
+all: obj_dir/Vhello
+
+check: all
+ obj_dir/Vhello
+
+clean:
+ rm -fr obj_dir
+
+.PHONY: all check clean
+
+obj_dir/Vhello: hello.v sim_main.cc
+ verilator --cc --exe --build -j 0 -Wall sim_main.cc hello.v
diff --git a/verilator_example_c++/hello.v b/verilator_example_c++/hello.v
new file mode 100644
index 0000000..8e163d5
--- /dev/null
+++ b/verilator_example_c++/hello.v
@@ -0,0 +1,6 @@
+module hello;
+ initial begin
+ $display("hello.");
+ $finish;
+ end
+endmodule
diff --git a/verilator_example_c++/sim_main.cc b/verilator_example_c++/sim_main.cc
new file mode 100644
index 0000000..6652dd9
--- /dev/null
+++ b/verilator_example_c++/sim_main.cc
@@ -0,0 +1,15 @@
+#include <cstdio>
+
+#include "Vhello.h"
+#include "verilated.h"
+
+int
+main(int argc, char **argv)
+{
+ VerilatedContext *cp = new VerilatedContext;
+ cp->commandArgs(argc, argv);
+ Vhello *top = new Vhello{cp};
+ while (!cp->gotFinish())
+ top->eval();
+ fprintf(stderr, "it finished.\n");
+}