<commit_before>/*
 * Copyright (c) 1998-2014 <NAME> (<EMAIL>)
 *
 *    This source code is free software; you can redistribute it
 *    and/or modify it in source code form under the terms of the GNU
 *    General Public License as published by the Free Software
 *    Foundation; either version 2 of the License, or (at your option)
 *    any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

# include "config.h"

/*
 * This file provides the pform_dump function, that dumps the module
 * passed as a parameter. The dump is as much as possible in Verilog
 * syntax, so that a human can tell that it really does describe the
 * module in question.
 */
# include  "pform.h"
# include  "PClass.h"
# include  "PEvent.h"
# include  "PGenerate.h"
# include  "PPackage.h"
# include  "PSpec.h"
# include  "discipline.h"
# include  "ivl_target_priv.h"
# include  <iostream>
# include  <iomanip>
# include  <typeinfo>

ostream& operator << (ostream&out, const PExpr&obj)
{
      obj.dump(out);
      return out;
}

ostream& operator << (ostream&out, const PEventStatement&obj)
{
      obj.dump_inline(out);
      return out;
}

ostream& operator << (ostream&o, const PDelays&d)
{
      d.dump_delays(o);
      return o;
}

ostream& operator<< (ostream&out, const index_component_t&that)
{
      out << "[";
      switch (that.sel) {
	  case index_component_t::SEL_BIT:
	    out << *that.msb;
	    break;
	  case index_component_t::SEL_BIT_LAST:
	    out << "$";
	    break;
	  case index_component_t::SEL_PART:
	    out << *that.msb << ":" << *that.lsb;
	    break;
	  case index_component_t::SEL_IDX_UP:
	    out << *that.msb << "+:" << *that.lsb;
	    break;
	  case index_component_t::SEL_IDX_DO:
	    out << *that.msb << "-:" << *that.lsb;
	    break;
	  default:
	    out << "???";
	    break;
      }
      out << "]";
      return out;
}

ostream& operator<< (ostream&out, const name_component_t&that)
{
      out << that.name.str();

      typedef std::list<index_component_t>::const_iterator index_it_t;
      for (index_it_t idx = that.index.begin()
		 ; idx != that.index.end() ; ++ idx ) {

	    out << *idx;
      }
      return out;
}

ostream& operator<< (ostream&o, const pform_name_t&that)
{
      pform_name_t::const_iterator cur;

      cur = that.begin();
      o << *cur;

      ++ cur;
      while (cur != that.end()) {
	    o << "." << *cur;
	    ++ cur;
      }

      return o;
}

std::ostream& operator << (std::ostream&out, ivl_process_type_t pt)
{
      switch (pt) {
	  case IVL_PR_INITIAL:
	    out << "initial";
	    break;
	  case IVL_PR_ALWAYS:
	    out << "always";
	    break;
	  case IVL_PR_FINAL:
	    out << "final";
	    break;
      }
      return out;
}

std::ostream& operator << (std::ostream&out, ivl_dis_domain_t dom)
{
      switch (dom) {
	  case IVL_DIS_NONE:
	    out << "no-domain";
	    break;
	  case IVL_DIS_DISCRETE:
	    out << "discrete";
	    break;
	  case IVL_DIS_CONTINUOUS:
	    out << "continuous";
	    break;
	  default:
	    assert(0);
	    break;
      }
      return out;
}

void data_type_t::pform_dump(ostream&out, unsigned indent) const
{
      out << setw(indent) << "" << typeid(*this).name() << endl;
}

void void_type_t::pform_dump(ostream&out, unsigned indent) const
{
      out << setw(indent) << "" << "void" << endl;
}

void parray_type_t::pform_dump(ostream&out, unsigned indent) const
{
      out << setw(indent) << "" << "Packed array " << "[...]"
	  << " of:" << endl;
      base_type->pform_dump(out, indent+4);
}

void struct_type_t::pform_dump(ostream&out, unsigned indent) const
{
      out << setw(indent) << "" << "Struct " << (packed_flag?"packed":"unpacked")
	  << " with " << (members.get()==0? 0 : members->size()) << " members" << endl;
      if (members.get()==0)
	    return;

      for (list<struct_member_t*>::iterator cur = members->begin()
		 ; cur != members->end() ; ++ cur) {
	    struct_member_t*curp = *cur;
	    curp->pform_dump(out, indent+4);
      }
}

void uarray_type_t::pform_dump(ostream&out, unsigned indent) const
{
      out << setw(indent) << "" << "Unpacked array " << "[...]"
	  << " of:" << endl;
      base_type->pform_dump(out, indent+4);
}

void vector_type_t::pform_dump(ostream&fd, unsigned indent) const
{
      fd << setw(indent) << "" << "vector of " << base_type;
      for (list<pform_range_t>::iterator cur = pdims->begin()
		 ; cur != pdims->end() ; ++cur) {
	    fd << "[" << *(cur->first) << ":" << *(cur->second) << "]";
      }
      fd << endl;
}

void class_type_t::pform_dump(ostream&out, unsigned indent) const
{
      out << setw(indent) << "" << "class " << name;

      if (base_type) out << " extends <type>";
      if (! base_args.empty()) {
	    out << " (";
	    for (list<PExpr*>::const_iterator cur = base_args.begin()
		       ; cur != base_args.end() ; ++cur) {
		  const PExpr*curp = *cur;
		  if (cur != base_args.begin())
			out << ", ";
		  curp->dump(out);
	    }
	    out << ")";
      }

      out << " {";
      for (map<perm_string,prop_info_t>::const_iterator cur = properties.begin()<commit_msg>Don't try to print the vector size if it is empty (a single bit)<commit_after>/*
 * Copyright (c) 1998-2014 <NAME> (<EMAIL>)
 *
 *    This source code is free software; you can redistribute it
 *    and/or modify it in source code form under the terms of the GNU
 *    General Public License as published by the Free Software
 *    Foundation; either version 2 of the License, or (at your option)
 *    any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

# include "config.h"

/*
 * This file provides the pform_dump function, that dumps the module
 * passed as a parameter. The dump is as much as possible in Verilog
 * syntax, so that a human can tell that it really does describe the
 * module in question.
 */
# include  "pform.h"
# include  "PClass.h"
# include  "PEvent.h"
# include  "PGenerate.h"
# include  "PPackage.h"
# include  "PSpec.h"
# include  "discipline.h"
# include  "ivl_target_priv.h"
# include  <iostream>
# include  <iomanip>
# include  <typeinfo>

ostream& operator << (ostream&out, const PExpr&obj)
{
      obj.dump(out);
      return out;
}

ostream& operator << (ostream&out, const PEventStatement&obj)
{
      obj.dump_inline(out);
      return out;
}

ostream& operator << (ostream&o, const PDelays&d)
{
      d.dump_delays(o);
      return o;
}

ostream& operator<< (ostream&out, const index_component_t&that)
{
      out << "[";
      switch (that.sel) {
	  case index_component_t::SEL_BIT:
	    out << *that.msb;
	    break;
	  case index_component_t::SEL_BIT_LAST:
	    out << "$";
	    break;
	  case index_component_t::SEL_PART:
	    out << *that.msb << ":" << *that.lsb;
	    break;
	  case index_component_t::SEL_IDX_UP:
	    out << *that.msb << "+:" << *that.lsb;
	    break;
	  case index_component_t::SEL_IDX_DO:
	    out << *that.msb << "-:" << *that.lsb;
	    break;
	  default:
	    out << "???";
	    break;
      }
      out << "]";
      return out;
}

ostream& operator<< (ostream&out, const name_component_t&that)
{
      out << that.name.str();

      typedef std::list<index_component_t>::const_iterator index_it_t;
      for (index_it_t idx = that.index.begin()
		 ; idx != that.index.end() ; ++ idx ) {

	    out << *idx;
      }
      return out;
}

ostream& operator<< (ostream&o, const pform_name_t&that)
{
      pform_name_t::const_iterator cur;

      cur = that.begin();
      o << *cur;

      ++ cur;
      while (cur != that.end()) {
	    o << "." << *cur;
	    ++ cur;
      }

      return o;
}

std::ostream& operator << (std::ostream&out, ivl_process_type_t pt)
{
      switch (pt) {
	  case IVL_PR_INITIAL:
	    out << "initial";
	    break;
	  case IVL_PR_ALWAYS:
	    out << "always";
	    break;
	  case IVL_PR_FINAL:
	    out << "final";
	    break;
      }
      return out;
}

std::ostream& operator << (std::ostream&out, ivl_dis_domain_t dom)
{
      switch (dom) {
	  case IVL_DIS_NONE:
	    out << "no-domain";
	    break;
	  case IVL_DIS_DISCRETE:
	    out << "discrete";
	    break;
	  case IVL_DIS_CONTINUOUS:
	    out << "continuous";
	    break;
	  default:
	    assert(0);
	    break;
      }
      return out;
}

void data_type_t::pform_dump(ostream&out, unsigned indent) const
{
      out << setw(indent) << "" << typeid(*this).name() << endl;
}

void void_type_t::pform_dump(ostream&out, unsigned indent) const
{
      out << setw(indent) << "" << "void" << endl;
}

void parray_type_t::pform_dump(ostream&out, unsigned indent) const
{
      out << setw(indent) << "" << "Packed array " << "[...]"
	  << " of:" << endl;
      base_type->pform_dump(out, indent+4);
}

void struct_type_t::pform_dump(ostream&out, unsigned indent) const
{
      out << setw(indent) << "" << "Struct " << (packed_flag?"packed":"unpacked")
	  << " with " << (members.get()==0? 0 : members->size()) << " members" << endl;
      if (members.get()==0)
	    return;

      for (list<struct_member_t*>::iterator cur = members->begin()
		 ; cur != members->end() ; ++ cur) {
	    struct_member_t*curp = *cur;
	    curp->pform_dump(out, indent+4);
      }
}

void uarray_type_t::pform_dump(ostream&out, unsigned indent) const
{
      out << setw(indent) << "" << "Unpacked array " << "[...]"
	  << " of:" << endl;
      base_type->pform_dump(out, indent+4);
}

void vector_type_t::pform_dump(ostream&fd, unsigned indent) const
{
      fd << setw(indent) << "" << "vector of " << base_type;
      if (pdims.get()) {
	    for (list<pform_range_t>::iterator cur = pdims->begin()
		       ; cur != pdims->end() ; ++cur) {
		  fd << "[" << *(cur->first) << ":" << *(cur->second) << "]";
	    }
      }
      fd << endl;
}

void class_type_t::pform_dump(ostream&out, unsigned indent) const
{
      out << setw(indent) << "" << "class " << name;

      if (base_type) out << " extends <type>";
      if (! base_args.empty()) {
	    out << " (";
	    for (list<PExpr*>::const_iterator cur = base_args.begin()
		       ; cur != base_args.end() ; ++cur) {
		  const PExpr*curp = *cur;
		  if (cur != base_args.begin())
			out << ", ";
		  curp->dump(out);
	    }
	    out << ")";
      }

      out << " {";
      for (map<perm_string,prop_info_t>::const_iterator cur = properties.begin()
{'fraction_non_alphanumeric': 0.15860142380823647, 'fraction_numerical': 0.004866180048661801, 'mean_word_length': 2.842797783933518, 'pattern_counts': {'":': 6, '<': 345, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '174268', 'n_tokens_mistral': 4007, 'n_tokens_neox': 3804, 'n_words': 968}