(file) Return to insn.hh CVS log (file) (dir) Up to [venge] / src / antigen

File: [venge] / src / antigen / insn.hh (download)
Revision: 1.1, Wed Jan 22 13:54:23 2003 UTC (7 years, 7 months ago) by graydon
Branch: MAIN
CVS Tags: HEAD
antigen

#ifndef __INSN_HH__
#define __INSN_HH__

#include <boost/mpl/at.hpp>
#include <boost/mpl/pop_front.hpp>

#include <string>
#include <iostream>

#include "antigen.hh"
#include "insn_io.hh"

template < char const * & MNEMONIC >
struct mnem
{
  static std::string get() { return std::string(MNEMONIC); }
};

template < typename ASMSPEC > 
struct assembly 
{
  typedef ASMSPEC spec;
  typedef typename boost::mpl::pop_front<ASMSPEC>::type operands;
  static inline std::string get_mnem() 
  { 
    return boost::mpl::at_c<ASMSPEC,0>::type::get(); 
  }
};


template < typename ENCSPEC >
struct encoding
{
  typedef ENCSPEC spec;
  typedef typename boost::mpl::pop_front<ENCSPEC>::type operands;
  static const uint opcode = boost::mpl::at_c<ENCSPEC,0>::type::value;
};

template < typename RTL >
struct semantics
{
  typedef RTL rtl;
};

template < typename ASM,
	   typename ENC,
	   typename SEM >
struct insn
{
  typedef ASM assembly;
  typedef ENC encoding;
  typedef SEM semantics;

  template <typename HW,
	    typename FIELDS>
  struct dyn_insn : public model<HW, FIELDS>::base_dyn_insn
  {

    typedef HW hardware;
    typedef FIELDS fields;


    virtual void extract(char const * & buf, fields & f) 
    { mem_insn_reader<fields,typename encoding::operands>::read_mem_operands(buf, f); }

    virtual void insert(char * & buf, fields & f) 
    { 
      *buf++ = encoding::opcode;
      mem_insn_writer<fields,typename encoding::operands>::write_mem_operands(buf, f); 
    }

    virtual void read(std::istream & in, fields & f) 
    { asm_insn_reader<fields,typename assembly::operands>::read_asm_operands(in, f); }

    virtual void write(std::ostream & out, fields const & f) 
    { 
      out << assembly::get_mnem();
      asm_insn_writer<fields,typename assembly::operands>::write_asm_operands(out, f); 
    }
    
    virtual void exec(hardware & hw, fields const & f) 
    { SEM::rtl::apply(hw,f); }
  };
};

#endif // __INSN_HH__

graydon hoare
Powered by
ViewCVS 0.9.2