06-16-09-Regs t

From Msim

Jump to: navigation, search

This page discusses the code added to regs.c and regs.h to provide the output operator (operator<<) for regs_t. The operator output matches the output desired by the eio requirements.

regs.h

The following prototypes must be provided in regs.h

std::ostream & operator << (std::ostream & out, const regs_t & source);
std::istream & operator >> (std::istream & in, regs_t & target);

regs.c

In order to output data in hex we use the iomanip library.

#include<iomanip>

The output operator is defined as follows (input is stubbed here):

std::ostream & operator << (std::ostream & out, const regs_t & source)
{
 out << "/* misc regs icnt, PC, NPC, etc... */" << std::endl;
 
 //sim_num_insn is always zero... instructions counts can't be stored here.
 out << "(" << 0 << ", ";
 
 //regs_PC, regs_NPC, regs_C.fpcr, regs_C.uniq
 out << "0x" << std::hex << source.regs_PC << ", ";
 out << "0x" << source.regs_NPC << ", ";
 out << std::dec << source.regs_C.fpcr << ", ";
 out << source.regs_C.uniq << ")" << std::endl;
 
 out << std::endl;
 out << "/* integer regs */" << std::endl;
 out << "(";
 for(unsigned int i = 0;i<source.regs_R.size();i++)
 {
  out << "0x" << std::hex << source.regs_R[i];
  if((i+1)<source.regs_R.size())
  {
   out << ", ";
  }
 }
 out << ")" << std::endl;
 
 out << std::endl;
 out << "/* FP regs (integer format) */" << std::endl;
 out << "(";
 for(unsigned int i = 0;i<source.regs_F.size();i++)
 {
  out << "0x" << std::hex << source.regs_F[i].q;
  if((i+1)<source.regs_F.size())
  {
   out << ", ";
  }
 }
 out << ")" << std::endl;
 
 out << std::dec << std::endl;
 return out;
}

std::istream & operator >> (std::istream & in, regs_t & target)
{
 return in;
}
Personal tools