diff options
Diffstat (limited to 'ue3/mycpu/cprogram.cpp')
| -rw-r--r-- | ue3/mycpu/cprogram.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ue3/mycpu/cprogram.cpp b/ue3/mycpu/cprogram.cpp index f6fc3cb..f904bce 100644 --- a/ue3/mycpu/cprogram.cpp +++ b/ue3/mycpu/cprogram.cpp | |||
| @@ -107,6 +107,16 @@ void CProgram::compile(std::istream& in) | |||
| 107 | /* let instruction parse the parameters. catch+throw exception */ | 107 | /* let instruction parse the parameters. catch+throw exception */ |
| 108 | try | 108 | try |
| 109 | { | 109 | { |
| 110 | /* handle label instruction ourself, but still add a dummy instruction */ | ||
| 111 | if (instrname == "label") | ||
| 112 | { | ||
| 113 | if (instrparams.size() != 1) | ||
| 114 | throw runtime_error("Invalid paramater count - must be 1"); | ||
| 115 | string label = instrparams.front(); | ||
| 116 | if (label.length() < 2 || label[ label.length() - 1] != ':') | ||
| 117 | throw runtime_error("Label has invalid syntax"); | ||
| 118 | m_labels[ label.substr(0, label.length() - 1) ] = size(); | ||
| 119 | } | ||
| 110 | instr->compile(instrparams); | 120 | instr->compile(instrparams); |
| 111 | } | 121 | } |
| 112 | catch(runtime_error& ex) | 122 | catch(runtime_error& ex) |
| @@ -123,6 +133,17 @@ void CProgram::compile(std::istream& in) | |||
| 123 | 133 | ||
| 124 | /*----------------------------------------------------------------------------*/ | 134 | /*----------------------------------------------------------------------------*/ |
| 125 | 135 | ||
| 136 | unsigned CProgram::findLabel(const std::string& label) const | ||
| 137 | { | ||
| 138 | map<string, unsigned>::const_iterator it; | ||
| 139 | it = m_labels.find(label); | ||
| 140 | if (it == m_labels.end()) | ||
| 141 | throw runtime_error("Unknown label '" + label + "'"); | ||
| 142 | return it->second; | ||
| 143 | } | ||
| 144 | |||
| 145 | /*----------------------------------------------------------------------------*/ | ||
| 146 | |||
| 126 | #if DEBUG | 147 | #if DEBUG |
| 127 | void CProgram::dump(std::ostream& out) | 148 | void CProgram::dump(std::ostream& out) |
| 128 | { | 149 | { |
