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/instructions.cpp | 65 +++------------------------------------------- 1 file changed, 4 insertions(+), 61 deletions(-) (limited to 'ue3/mycpu/instructions.cpp') diff --git a/ue3/mycpu/instructions.cpp b/ue3/mycpu/instructions.cpp index 609cd1c..a6ac611 100644 --- a/ue3/mycpu/instructions.cpp +++ b/ue3/mycpu/instructions.cpp @@ -5,6 +5,7 @@ * @date 10.05.2009 */ +#include #include "instructions.h" using namespace std; @@ -210,27 +211,6 @@ void CInstructionTest::execute(CCPU *cpu) /*============================================================================*/ -void CInstructionLabel::compile(std::list& params) -{ - if (params.size() != 1) - throw runtime_error("Invalid paramater count - must be 1"); - string label = params.front(); - params.pop_front(); - if (label.length() < 2 || label[ label.length() - 1] != ':') - throw runtime_error("Label has invalid syntax"); - m_label = label.substr(0, label.length() - 1); -} - -/*----------------------------------------------------------------------------*/ - -void CInstructionLabel::execute(CCPU *cpu) -{ - if (m_label.empty()) - throw runtime_error("Empty label"); -} - -/*============================================================================*/ - void CInstructionJumpA::compile(std::list& params) { if (params.size() != 1) @@ -245,18 +225,7 @@ void CInstructionJumpA::execute(CCPU *cpu) { if (m_addr.empty()) throw runtime_error("Empty address"); - - const CProgram *progam = cpu->getProgram(); - for(unsigned i = 0; i < progam->size(); i++) - { - if (progam->at(i)->isLabel() && progam->at(i)->getLabelName() == m_addr) - { - cpu->getRegisters()[ 0 ] = i; - return; - } - } - - throw runtime_error("Unknown label '" + m_addr + "'"); + cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); } /*============================================================================*/ @@ -275,20 +244,7 @@ void CInstructionJumpZ::execute(CCPU *cpu) { if (!cpu->getFlagZero()) return; - if (m_addr.empty()) - throw runtime_error("Empty address"); - - const CProgram *progam = cpu->getProgram(); - for(unsigned i = 0; i < progam->size(); i++) - { - if (progam->at(i)->isLabel() && progam->at(i)->getLabelName() == m_addr) - { - cpu->getRegisters()[ 0 ] = i; - return; - } - } - - throw runtime_error("Unknown label '" + m_addr + "'"); + cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); } /*============================================================================*/ @@ -307,20 +263,7 @@ void CInstructionJumpS::execute(CCPU *cpu) { if (!cpu->getFlagSign()) return; - if (m_addr.empty()) - throw runtime_error("Empty address"); - - const CProgram *progam = cpu->getProgram(); - for(unsigned i = 0; i < progam->size(); i++) - { - if (progam->at(i)->isLabel() && progam->at(i)->getLabelName() == m_addr) - { - cpu->getRegisters()[ 0 ] = i; - return; - } - } - - throw runtime_error("Unknown label '" + m_addr + "'"); + cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); } /*============================================================================*/ -- cgit v1.2.3