Download | Plain Text | No Line Numbers


  1. /**
  2.  * @module cprogram
  3.  * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
  4.  * @brief CProgram extends std::vector and adds a method for parsing programfile
  5.  * @date 10.05.2009
  6.  */
  7.  
  8. #ifndef CPROGRAM_H
  9. #define CPROGRAM_H 1
  10.  
  11. #include <vector>
  12. #include <set>
  13. #include <map>
  14. #include "cinstruction.h"
  15.  
  16. /**
  17.  * @class CProgram
  18.  *
  19.  * CProgram extends std::vector and adds a method for parsing
  20.  * programfile. This adds instances of CInstruction to CProgram itself.
  21.  */
  22. class CProgram
  23. : public std::vector<CInstruction *>
  24. {
  25. public:
  26. /**
  27.   * @method CProgram
  28.   * @brief Default ctor
  29.   * @param -
  30.   * @return -
  31.   * @globalvars none
  32.   * @exception none
  33.   * @conditions none
  34.   */
  35. CProgram();
  36.  
  37. /**
  38.   * @method ~CProgram
  39.   * @brief Default dtor
  40.   * @param -
  41.   * @return -
  42.   * @globalvars none
  43.   * @exception none
  44.   * @conditions none
  45.   */
  46. ~CProgram();
  47.  
  48. /**
  49.   * @method getLabels
  50.   * @brief get reference to labels map
  51.   * @param -
  52.   * @return reference to labels map
  53.   * @globalvars none
  54.   * @exception none
  55.   * @conditions none
  56.   */
  57. const std::map<std::string, unsigned>& getLabels() const
  58. {
  59. return m_labels;
  60. }
  61.  
  62. /**
  63.   * @method findLabel
  64.   * @brief search for label
  65.   * @param label name of label to search for
  66.   * @return index of found label in program
  67.   * @globalvars none
  68.   * @exception std::runtime_error
  69.   * @conditions none
  70.   */
  71. unsigned findLabel(const std::string& label) const;
  72.  
  73. /**
  74.   * @method compile
  75.   * @brief create instructions from parsing stream
  76.   * @param in inputstream to read from
  77.   * @return void
  78.   * @globalvars none
  79.   * @exception std::runtime_error
  80.   * @conditions none
  81.   */
  82. void compile(std::istream& in);
  83.  
  84. #if DEBUG
  85. /**
  86.   * @method dump
  87.   * @brief dumps contents to outputstream
  88.   * @param out outputstream to write to
  89.   * @return void
  90.   * @globalvars none
  91.   * @exception none
  92.   * @conditions none
  93.   */
  94. void dump(std::ostream& out);
  95. #endif
  96.  
  97. private:
  98. /* members */
  99. /** set of known instructions */
  100. std::set<CInstruction *> m_instrset;
  101. std::map<std::string, unsigned> m_labels;
  102. };
  103.  
  104. #endif
  105.  
  106. /* vim: set et sw=2 ts=2: */
  107.