Learning How to Use Yosys (5. Trying to Create My Own Pass)

Let's start by building a simple Pass for Yosys. It is called mypass, and it is a Pass that does nothing.

  • yosys/passes/tests/mypass.cc
struct MyPass : public Pass {
  MyPass() : Pass("mypass", "My Pass") { }
  void help() override
  {
    //    |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
    log ("\n");
    log ("    mypass\n");
    log ("\n");
  }

  void execute(std::vector<std::string> args, RTLIL::Design*) override
  {
    log ("Hello!\n");
  }

} MyPass;

We also add it to Makefile.inc.

diff --git a/passes/tests/Makefile.inc b/passes/tests/Makefile.inc
index 531943d78..8abacef0e 100644
--- a/passes/tests/Makefile.inc
+++ b/passes/tests/Makefile.inc
@@ -2,4 +2,4 @@
 OBJS += passes/tests/test_autotb.o
 OBJS += passes/tests/test_cell.o
 OBJS += passes/tests/test_abcloop.o
-
+OBJS += passes/tests/mypass.o

We add mypass to the command script to try out the new Pass.

read -sv2009 adder.sv
mypass

Here is the execution result. The output of log() was displayed correctly. That is the first step done.

1. Executing Verilog-2005 frontend: adder.sv
Parsing SystemVerilog input from `adder.sv' to AST representation.
Storing AST representation for module `$abstract\adder'.
Successfully finished Verilog frontend.
Hello!

This is an English translation of the original Japanese post: Yosysの使い方を勉強する (5. 自分のPassを作ってみる)