degate  0.1.2
Public Member Functions | Protected Member Functions
degate::VerilogTBCodeTemplateGenerator Class Reference

A code template generator for Verilog. More...

#include <VerilogTBCodeTemplateGenerator.h>

Inheritance diagram for degate::VerilogTBCodeTemplateGenerator:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 VerilogTBCodeTemplateGenerator (std::string const &entity_name, std::string const &description, std::string const &logic_class)
virtual ~VerilogTBCodeTemplateGenerator ()
virtual std::string generate () const

Protected Member Functions

virtual std::string generate_header () const
virtual std::string generate_module (std::string const &device_type_name) const
std::string generate_all_assignments (std::vector< std::string > const &in_port_idents, std::vector< std::string > const &out_port_idents) const

Detailed Description

A code template generator for Verilog.

Definition at line 38 of file VerilogTBCodeTemplateGenerator.h.


Constructor & Destructor Documentation

VerilogTBCodeTemplateGenerator::VerilogTBCodeTemplateGenerator ( std::string const &  entity_name,
std::string const &  description,
std::string const &  logic_class 
)

Definition at line 37 of file VerilogTBCodeTemplateGenerator.cc.

                                                                {
}

Member Function Documentation

std::string VerilogTBCodeTemplateGenerator::generate ( ) const [virtual]

Reimplemented from degate::VerilogCodeTemplateGenerator.

Definition at line 40 of file VerilogTBCodeTemplateGenerator.cc.

References degate::CodeTemplateGenerator::entity_name, generate_header(), generate_module(), degate::CodeTemplateGenerator::get_inports(), and degate::CodeTemplateGenerator::get_outports().

                                                         {

  port_map_type port_map;
  BOOST_FOREACH(std::string const& port_name, get_inports()) 
    port_map[port_name] = port_name;
  BOOST_FOREACH(std::string const& port_name, get_outports())
    port_map[port_name] = port_name;

  return
    generate_header() +
    generate_module(entity_name);
                          
}

Here is the call graph for this function:

std::string VerilogTBCodeTemplateGenerator::generate_all_assignments ( std::vector< std::string > const &  in_port_idents,
std::vector< std::string > const &  out_port_idents 
) const [protected]

Definition at line 167 of file VerilogTBCodeTemplateGenerator.cc.

References increment().

Referenced by generate_module().

                                                    {

  // left side: {a, b, c, ... }
  std::string assignment_dst = 
    "{" +
    boost::algorithm::join(generate_identifier<std::vector<std::string> >(in_port_idents), ", ") + 
    "}";

  // right side prefix
  boost::format f_prefix("%1%'b");
  f_prefix % in_port_idents.size();
  std::string prefix = f_prefix.str();


  std::string testcode;

  std::vector<int> assignment(in_port_idents.size()); // initialized with 0
  while(increment(assignment)) {

    std::string assignment2;
    BOOST_FOREACH(int i, assignment) 
      assignment2.push_back(boost::lexical_cast<char>(i));
    std::reverse(assignment2.begin(), assignment2.end());

    // generate assignemt string
    boost::format f("    %1% = %2%%3%;\n"
                    "    #10;\n");
    f % assignment_dst % prefix % assignment2;

    testcode += f.str();
    BOOST_FOREACH(std::string const& oport,
                  generate_identifier<std::vector<std::string> >(out_port_idents)) {
      boost::format f2("    assert(%1% === 1'bX); // please edit\n\n");
      f2 % oport;
      testcode += f2.str();
    }

  }

  return testcode;
}

Here is the call graph for this function:

Here is the caller graph for this function:

std::string VerilogTBCodeTemplateGenerator::generate_header ( ) const [protected, virtual]

Reimplemented from degate::VerilogCodeTemplateGenerator.

Definition at line 54 of file VerilogTBCodeTemplateGenerator.cc.

References degate::CodeTemplateGenerator::entity_name.

Referenced by generate().

                                                                {
  boost::format f("/**\n"
                  " * This is Verilog testbench for a gate of type %1%\n"
                  " *\n"
                  " *  Please customize this code template according to your needs.\n"
                  " */\n\n"
                  "`timescale 1ns/100ps\n"
                  "\n\n");
  f % entity_name;
  return f.str();
}

Here is the caller graph for this function:

std::string VerilogTBCodeTemplateGenerator::generate_module ( std::string const &  device_type_name) const [protected, virtual]

Definition at line 67 of file VerilogTBCodeTemplateGenerator.cc.

References generate_all_assignments(), degate::VerilogCodeTemplateGenerator::generate_identifier(), degate::CodeTemplateGenerator::get_inports(), degate::CodeTemplateGenerator::get_outports(), and degate::CodeTemplateGenerator::get_ports().

Referenced by generate().

                                                                                                 {
    
  std::string inports = 
    boost::algorithm::join(generate_identifier<std::vector<std::string> >(get_inports()), ", ");
  
  std::string outports = 
    boost::algorithm::join(generate_identifier<std::vector<std::string> >(get_outports()), ", ");
  
  std::list<std::string> port_wiring;
  BOOST_FOREACH(std::string const & pname, 
                generate_identifier(get_ports())) {
    boost::format f(".%1%(%2%)");
    f % pname % pname;
    port_wiring.push_back(f.str());
  }
  
  std::string inport_init;
  BOOST_FOREACH(std::string const & pname, 
                generate_identifier(get_inports())) {
      boost::format f("    %1% <= 1'b0;\n");
      f % pname;
      inport_init += f.str();
  }
  
  boost::format f("module testbench_%1%;\n"
                  "  reg %2%;\n"
                  "  wire %3%;\n"
                  "\n"
                  "  // helper task to simulate a C-style assert() function\n"
                  "  task assert;\n"
                  "    input asserted_value;\n"
                  "    begin\n"
                  "      if(!asserted_value) begin\n"
                  "        $display(\"Assertion failed.\");\n"
                  "        $finish;\n"
                  "      end\n"
                  "    end\n"
                  "  endtask\n"
                  "\n"
                  "  // create an instance of the device to test\n"
                  "  %4% unit(%5%);\n"
                  "\n"
                  "  // initialize\n"
                  "  initial begin\n"
                  "    // Enable signal dumping\n"
                  "    // Generate a VCD dump file. Please, do not change the filename.\n"
                  "    $dumpfile(\"test.vcd\"); \n"
                  "    $dumpvars(0, testbench_%6%); // for this module\n"
                  "\n"
                  "    // initialize signals on ports\n"
                  "%7%"
                  "  end\n"
                  "\n"
                  "  initial begin\n"
                  "    #10; // wait 10 ns for port initialisation\n"
                  "\n"
                  "%8%"
                  "\n"
                  "    #10; // wait 10 ns\n"
                  "\n"
                  "  end\n"
                  "\n"
                  "endmodule // testbench_%9%");
  f % generate_identifier(device_type_name, "dg_")
    % inports
    % outports
    % generate_identifier(device_type_name, "dg_") % boost::algorithm::join(port_wiring, ", ")
    % generate_identifier(device_type_name, "dg_")
    % inport_init
    
    % generate_all_assignments(get_inports(), get_outports())
    
    % generate_identifier(device_type_name, "dg_");

  return f.str();    
}

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: