Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: static coverpoint #22

Open
amal-khailtash opened this issue Oct 16, 2024 · 0 comments
Open

Enhancement: static coverpoint #22

amal-khailtash opened this issue Oct 16, 2024 · 0 comments

Comments

@amal-khailtash
Copy link

FC4SC library allows us to create covergroups/coverpoints with more granularity than SystemVerilog. It allows us to sample individual coverpoints as we as the whole group. We have a use model where we want to share variables as well as coverpoints among a few covergroups. We have a base class that inherits from fc4sc::covergroup and defines a few coverpoints. To share coverpoints among multiple covergroups, we would like to define some covergroups as static memebers so that there is only one copy in inherited classes.

I have a bit of difficulty to create a static coverpoint for there are no static functions to register this coverpoint with the covergroup. I assume we need some static function to handle that.

#include <iostream>

#include <fc4sc.hpp>

class CoverBase
  : public fc4sc::covergroup
{
 public:

  CG_CONS(CoverBase)
  {
    this->option().per_instance = true;
    this->option().comment      = "CoverBase";

    // create new coverpoints dynamically?
  }

  bool a;

  static int             x;
  static coverpoint<int> cp_x;

  COVERPOINT(bool, cp_a, a)
  {
    bin<bool>("false", false),
    bin<bool>("true ", true ),
  };
};

class CoverA
  : public CoverBase
{
 public:

  // CG_CONS(CoverA)
  //, fc4sc::covergroup(inst_name, auto_inst_file_name, auto_line, cntxt)
    // , CoverBase        (inst_name, auto_inst_file_name, auto_line, cntxt)
  CoverA(std::string inst_name="")
    : CoverBase(inst_name)
  {
    this->option().per_instance = true;
    this->option().comment      = "CoverA";
  }
};

class CoverB
  : public CoverBase
{
 public:

  // CG_CONS(CoverB)
  //, fc4sc::covergroup(inst_name, auto_inst_file_name, auto_line, cntxt)
    // , CoverBase        (inst_name, auto_inst_file_name, auto_line, cntxt)
  CoverB(std::string inst_name="")
    : CoverBase(inst_name)
  {
    this->option().per_instance = true;
    this->option().comment      = "CoverB";
  }
};

CoverA cvg_a;
CoverB cvg_b;

CoverBase cvg;
//
int             CoverBase::x    = 0;  // = cvg.set_strings(&CoverBase::cp_x, &CoverBase::x, "cp_x", "x");
coverpoint<int> CoverBase::cp_x = coverpoint<int>{ bin<int>("0", 0), bin<int>("1", 1), bin<int>("2", 2) };

// = coverpoint<int>(&cvg, bin<int>("0", 0), bin<int>("1", 1), bin<int>("2", 2));

    // cvg_a.register_cvp<int>(
    //     &CoverBase::cp_x,
    //     "cp_x",
    //     []() -> int { return CoverBase::x; },
    //     std::string("x"),
    //     []() -> bool { return true; },
    //     std::string("")
    // );

int main(int argc, char* argv[])
{
  cvg.x = 0;
  cvg.a = false;
  cvg.sample();

  cvg_a.x = 0;
  cvg_a.a = false;
  cvg_a.sample();

  cvg_b.x = 1;
  cvg_b.a = true;
  cvg_b.sample();

  cvg_a.x = 1;
  cvg_a.a = true;
  cvg_a.sample();

  xml_printer::coverage_save("main.xml");

  std::cout << std::string(80, '-') << "\n";
  std::cout << "Coverage          = " << fc4sc::global::get_coverage() << "%\n";

  return 0;
}

The code above tries to create a static coverpoint without success. Any suggestions/fixes is appareciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant