From 431bbac5a99abbccf33500e22aa353ec792eff94 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 13 May 2009 15:29:51 +0200 Subject: * adding -Wno-long-long to all Makefiles * adding execute operator to cinstruction * added labels map for better performance --- ue3/mycpu/cprogram.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'ue3/mycpu/cprogram.cpp') 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) /* let instruction parse the parameters. catch+throw exception */ try { + /* handle label instruction ourself, but still add a dummy instruction */ + if (instrname == "label") + { + if (instrparams.size() != 1) + throw runtime_error("Invalid paramater count - must be 1"); + string label = instrparams.front(); + if (label.length() < 2 || label[ label.length() - 1] != ':') + throw runtime_error("Label has invalid syntax"); + m_labels[ label.substr(0, label.length() - 1) ] = size(); + } instr->compile(instrparams); } catch(runtime_error& ex) @@ -123,6 +133,17 @@ void CProgram::compile(std::istream& in) /*----------------------------------------------------------------------------*/ +unsigned CProgram::findLabel(const std::string& label) const +{ + map::const_iterator it; + it = m_labels.find(label); + if (it == m_labels.end()) + throw runtime_error("Unknown label '" + label + "'"); + return it->second; +} + +/*----------------------------------------------------------------------------*/ + #if DEBUG void CProgram::dump(std::ostream& out) { -- cgit v1.2.3