summaryrefslogtreecommitdiffstats
path: root/ue3/mycpu/cprogram.h
diff options
context:
space:
mode:
Diffstat (limited to 'ue3/mycpu/cprogram.h')
-rw-r--r--ue3/mycpu/cprogram.h112
1 files changed, 56 insertions, 56 deletions
diff --git a/ue3/mycpu/cprogram.h b/ue3/mycpu/cprogram.h
index 25d0ce2..27e7647 100644
--- a/ue3/mycpu/cprogram.h
+++ b/ue3/mycpu/cprogram.h
@@ -1,51 +1,41 @@
1/** 1/**
2 * @module cprogram 2 * @module cprogram
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) 3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief class for parsing and saving the program instuctions. 4 * @brief CProgram extends std::vector and adds a method for parsing programfile
5 * @date 17.04.2009 5 * @date 10.05.2009
6 */ 6 */
7 7
8#ifndef CPROGRAM_H 8#ifndef CPROGRAM_H
9#define CPROGRAM_H 9#define CPROGRAM_H 1
10 10
11#include <stdexcept>
12#include <string>
13#include <vector> 11#include <vector>
12#include <set>
14#include <map> 13#include <map>
15#ifdef DEBUG 14#include "cinstruction.h"
16# include <iostream> 15
17#endif
18#include "cdat.h"
19/** 16/**
20 * @class CProgram 17 * @class CProgram
21 * 18 *
22 * Parses a simple line based scriptfile with some limitations: 19 * CProgram extends std::vector and adds a method for parsing
23 * first function (starting a block) must be a read-command, 20 * programfile. This adds instances of CInstruction to CProgram itself.
24 * last must be a write-command (ending this block).
25 *
26 * read- and write-commands have hard coded parameters, number#1 being a filetype.
27 * Classes handling certain filetypes must be of type CFile.
28 * Custom functions will be passed to CFile::callFunc().
29 *
30 * On error ParserError will be thrown.
31 */ 21 */
32class CProgram 22class CProgram
23 : public std::vector<CInstruction *>
33{ 24{
34 public: 25 public:
35
36 /** 26 /**
37 * @method CProgram 27 * @method CProgram
38 * @brief Default ctor 28 * @brief Default ctor
39 * @param programfile filename 29 * @param -
40 * @return - 30 * @return -
41 * @globalvars none 31 * @globalvars none
42 * @exception bad_alloc 32 * @exception none
43 * @conditions none 33 * @conditions none
44 */ 34 */
45 CProgram(const std::string& progfile); 35 CProgram();
46 36
47 /** 37 /**
48 * @method ~CScriptparser 38 * @method ~CProgram
49 * @brief Default dtor 39 * @brief Default dtor
50 * @param - 40 * @param -
51 * @return - 41 * @return -
@@ -55,50 +45,60 @@ class CProgram
55 */ 45 */
56 ~CProgram(); 46 ~CProgram();
57 47
58 CDat getMaxProgramCount() 48 /**
59 { 49 * @method getLabels
60 return CDat(m_progsource.size()); 50 * @brief get reference to labels map
61 } 51 * @param -
62 52 * @return reference to labels map
63 std::vector<std::string>& getInstruction(CDat linenr) 53 * @globalvars none
64 { 54 * @exception none
65 return m_progsource[linenr.getTypeValue()]; 55 * @conditions none
66 } 56 */
67 57 const std::map<std::string, unsigned>& getLabels() const
68 std::map<std::string, unsigned int>& getJumpAddrs()
69 { 58 {
70 return m_jumpaddr; 59 return m_labels;
71 } 60 }
72#ifdef DEBUG 61
73 /** 62 /**
74 * @method dump 63 * @method findLabel
75 * @brief Dumps the program source to ostream 64 * @brief search for label
76 * @param out output stream 65 * @param label name of label to search for
77 * @return - 66 * @return index of found label in program
78 * @globalvars 67 * @globalvars none
79 * @exception 68 * @exception std::runtime_error
80 * @conditions 69 * @conditions none
81 */ 70 */
82 void dump(std::ostream& out); 71 unsigned findLabel(const std::string& label) const;
83#endif
84 72
85 protected:
86 /** 73 /**
87 * @method parse 74 * @method compile
88 * @brief parse the program file 75 * @brief create instructions from parsing stream
89 * @param - 76 * @param in inputstream to read from
90 * @return - 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
91 * @globalvars none 90 * @globalvars none
92 * @exception ParserError 91 * @exception none
93 * @conditions none 92 * @conditions none
94 */ 93 */
95 void parse(); 94 void dump(std::ostream& out);
96 95#endif
96
97 private: 97 private:
98 /* members */ 98 /* members */
99 std::string m_programfile; 99 /** set of known instructions */
100 std::vector<std::vector<std::string> > m_progsource; 100 std::set<CInstruction *> m_instrset;
101 std::map<std::string, unsigned int> m_jumpaddr; 101 std::map<std::string, unsigned> m_labels;
102}; 102};
103 103
104#endif 104#endif