Download | Plain Text | No Line Numbers


  1. /**
  2.  * @module cinstruction
  3.  * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
  4.  * @brief Abstract class for displays
  5.  * @date 13.05.2009
  6.  */
  7.  
  8. #include <sstream>
  9. #include <stdexcept>
  10. #include <boost/lexical_cast.hpp>
  11. #include <assert.h>
  12. #include "cinstruction.h"
  13. #include "ccpu.h"
  14.  
  15. using namespace std;
  16.  
  17. const unsigned CInstruction::parseRegister(const std::string& str)
  18. {
  19. unsigned reg;
  20. if (str.length() < 2 || str[0] != 'r')
  21. throw runtime_error("Invalid syntax of register");
  22.  
  23. try
  24. {
  25. reg = boost::lexical_cast<unsigned>(str.substr(1));
  26. }
  27. catch(boost::bad_lexical_cast& ex)
  28. {
  29. throw runtime_error("Invalid syntax of register");
  30. }
  31.  
  32. return reg;
  33. }
  34.  
  35. /*----------------------------------------------------------------------------*/
  36.  
  37. inline void CInstruction::checkRegister(CCPU *cpu, const unsigned regidx)
  38. {
  39. assert(cpu != NULL);
  40. if (regidx >= cpu->getRegisterCount())
  41. {
  42. stringstream sstr;
  43. sstr << "Register R" << regidx << " doesn't exist (out of bound)";
  44. throw runtime_error(sstr.str());
  45. }
  46. }
  47.  
  48. /* vim: set et sw=2 ts=2: */
  49.