Index: ChangeLog
from BenoƮt Perrot <benoit(a)lrde.epita.fr>
* src/vm/virtual_machine.hh: Move the implementation of
rarely used methods to...
* src/vm/virtual_machine.cc: This file.
Index: src/vm/virtual_machine.hh
--- src/vm/virtual_machine.hh (revision 109)
+++ src/vm/virtual_machine.hh (working copy)
@@ -73,9 +73,8 @@
public:
/// Reset the vm
- void reset()
- {
- }
+ void reset();
+
/// Print the vm
void print(std::ostream& ostr) const
{
@@ -86,31 +85,11 @@
public:
/// Load a program into memory.
- void load_program(const inst::Program& program)
- {
- if (! program.text_section ().has_label(inst::Label("main")))
- {
- std::cerr << "No `main' label in assembly file." <<
std::endl;
- exit_set(exit_runtime);
- return;
- }
- mmu_.data_store(program.data_section());
- mmu_.inst_store(program.text_section());
- cpu_.set_pc(program.text_section ().get_offset(inst::Label("main")));
- }
+ void load_program(const inst::Program& program);
public:
/// Execute a program.
- void execute()
- {
- // FIXME: precondition on loaded program
-
- while (!cpu_.get_halt())
- {
- cpu_.step();
- cp0_.set_count(cp0_.get_count() + 1);
- }
- }
+ void execute();
/** \name Shell entry point
\{ */
@@ -129,48 +108,10 @@
public:
/// Execute a program
- void execute(bool trace_p)
- {
- if (status_ == stop)
- return;
-
- cpu_.set_trace(trace_p);
- while (status_ == run)
- {
- cpu_.step();
- cp0_.set_count(cp0_.get_count() + 1);
- if (cpu_.get_halt())
- {
- status_ = halt;
- std::cerr << "Program exited." << std::endl;
- break;
- }
- if (has(breakpoints_, cpu_.get_pc()))
- {
- std::cout << "Breakpoint at pc = " << cpu_.get_pc() <<
std::endl;
- status_ = pause;
- }
- if (mode_ == step)
- status_ = pause;
- }
- }
+ void execute(bool trace_p);
/// Add a breakpoint
- void add_breakpoint(const std::string& label)
- {
- int offset;
-
- if (!has_label(label))
- {
- std::cerr << "Label " << label << " not found"
<< std::endl;
- return;
- }
- offset = get_offset(label);
-
- std::cout << "Breakpoint " << label
- << " at " << offset << " (+4)" <<
std::endl;
- breakpoints_.push_back(offset + 4);
- }
+ void add_breakpoint(const std::string& label);
protected:
/// The list of breakpoints
Index: src/vm/Makefile.am
--- src/vm/Makefile.am (revision 109)
+++ src/vm/Makefile.am (working copy)
@@ -9,5 +9,5 @@
cpu.hh cpu.cc \
segment.hh \
memory.hh \
- virtual_machine.hh \
+ virtual_machine.hh virtual_machine.cc \
vm-tasks.hh vm-tasks.cc
Index: src/vm/virtual_machine.cc
--- src/vm/virtual_machine.cc (revision 0)
+++ src/vm/virtual_machine.cc (revision 0)
@@ -0,0 +1,100 @@
+//
+// This file is part of Nolimips, a MIPS simulator with unlimited registers
+// Copyright (C) 2003, 2004 Benoit Perrot <benoit(a)lrde.epita.fr>
+//
+// Nolimips is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// Nolimips is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+#include "vm/virtual_machine.hh"
+
+namespace vm
+{
+
+ void
+ VirtualMachine::reset()
+ {
+ }
+
+ void
+ VirtualMachine::load_program(const inst::Program &program)
+ {
+ if (! program.text_section ().has_label(inst::Label("main")))
+ {
+ std::cerr << "No `main' label in assembly file." <<
std::endl;
+ exit_set(exit_runtime);
+ return;
+ }
+ mmu_.data_store(program.data_section());
+ mmu_.inst_store(program.text_section());
+ cpu_.set_pc(program.text_section ().get_offset(inst::Label("main")));
+ }
+
+ void
+ VirtualMachine::execute()
+ {
+ // FIXME: precondition on loaded program
+
+ while (!cpu_.get_halt())
+ {
+ cpu_.step();
+ cp0_.set_count(cp0_.get_count() + 1);
+ }
+ }
+
+ void
+ VirtualMachine::execute(bool trace_p)
+ {
+ if (status_ == stop)
+ return;
+
+ cpu_.set_trace(trace_p);
+ while (status_ == run)
+ {
+ cpu_.step();
+ cp0_.set_count(cp0_.get_count() + 1);
+ if (cpu_.get_halt())
+ {
+ status_ = halt;
+ std::cerr << "Program exited." << std::endl;
+ break;
+ }
+ if (has(breakpoints_, cpu_.get_pc()))
+ {
+ std::cout << "Breakpoint at pc = " << cpu_.get_pc() <<
std::endl;
+ status_ = pause;
+ }
+ if (mode_ == step)
+ status_ = pause;
+ }
+ }
+
+ void
+ VirtualMachine::add_breakpoint(const std::string& label)
+ {
+ int offset;
+
+ if (!has_label(label))
+ {
+ std::cerr << "Label " << label << " not found"
<< std::endl;
+ return;
+ }
+ offset = get_offset(label);
+
+ std::cout << "Breakpoint " << label
+ << " at " << offset << " (+4)" <<
std::endl;
+ breakpoints_.push_back(offset + 4);
+ }
+
+
+} // namespace vm