Commit 219dd9e9 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Index: ChangeLog

from  Benoît Perrot  <benoit@lrde.epita.fr>
        * src/vm/cpu.hh, src/vm/virtual_machine.hh, src/vm/vm-tasks.cc:
        Make the CPU responsible of its instruction flow.
parent 7300eb69
2003-10-11 Benot Perrot <benoit@lrde.epita.fr>
* src/vm/cpu.hh, src/vm/virtual_machine.hh, src/vm/vm-tasks.cc:
Make the CPU responsible of its instruction flow.
2003-10-11 Benot Perrot <benoit@lrde.epita.fr>
* src/vm/cpu.hh, src/vm/cpu.cc: Uniformize register accessors,
......
......@@ -2,20 +2,20 @@
(Created-By-Prcs-Version 1 3 2)
(Project-Description "")
(Project-Version mipsy 0 56)
(Parent-Version mipsy 0 55)
(Project-Version mipsy 0 57)
(Parent-Version mipsy 0 56)
(Version-Log
"Index: ChangeLog
from Benot Perrot <benoit@lrde.epita.fr>
* src/vm/cpu.hh, src/vm/virtual_machine.hh, src/vm/vm-tasks.cc:
Make the CPU responsible of its instruction flow.
* src/vm/cpu.hh, src/vm/cpu.cc: Uniformize register accessors,
removing deprecated ones.
")
(New-Version-Log
"")
(Checkin-Time "Sat, 11 Oct 2003 15:22:01 +0200")
(Checkin-Time "Sat, 11 Oct 2003 15:48:01 +0200")
(Checkin-Login benoit)
(Files
......@@ -23,7 +23,7 @@ from Beno
;; ./
(AUTHORS (mipsy/0_AUTHORS 1.1 644))
(COPYING (mipsy/1_COPYING 1.1 644))
(ChangeLog (mipsy/2_ChangeLog 1.50 644))
(ChangeLog (mipsy/2_ChangeLog 1.51 644))
(Makefile.am (mipsy/3_Makefile.a 1.6 644))
(NEWS (mipsy/b/25_NEWS 1.5 644))
(README (mipsy/4_README 1.2 644))
......@@ -100,13 +100,13 @@ from Beno
;; ./src/vm/
(src/vm/Makefile.am (mipsy/b/0_Makefile.a 1.3 644))
(src/vm/cpu.hh (mipsy/b/1_cpu.hh 1.8 644))
(src/vm/cpu.hh (mipsy/b/1_cpu.hh 1.9 644))
(src/vm/cpu.cc (mipsy/b/5_virtual_ma 1.17 604))
(src/vm/memory.hh (mipsy/b/2_memory.hh 1.7 644))
(src/vm/segment.hh (mipsy/b/3_segment.hh 1.2 644))
(src/vm/table.hh (mipsy/b/4_table.hh 1.2 644))
(src/vm/virtual_machine.hh (mipsy/b/6_virtual_ma 1.11 604))
(src/vm/vm-tasks.cc (mipsy/b/7_vm-tasks.c 1.4 604))
(src/vm/virtual_machine.hh (mipsy/b/6_virtual_ma 1.12 604))
(src/vm/vm-tasks.cc (mipsy/b/7_vm-tasks.c 1.5 604))
(src/vm/vm-tasks.hh (mipsy/b/8_vm-tasks.h 1.3 604))
;; ./tests/
......
......@@ -26,6 +26,7 @@
# include "inst/visitor.hh"
# include "inst/register.hh"
# include "inst/program.hh"
# include "vm/memory.hh"
# include "vm/table.hh"
......@@ -37,7 +38,7 @@ namespace vm
typedef uint32_t uregister_t;
class Cpu:
public inst::ConstVisitor // FIXME: might be protected
protected inst::ConstVisitor
{
public:
enum kind_t
......@@ -60,10 +61,12 @@ namespace vm
Cpu(Memory& mem,
std::istream& istr,
std::ostream& ostr,
bool check_callee_save_p):
bool check_callee_save_p,
bool trace_p):
memory(mem),
istr(istr), ostr(ostr),
check_callee_save_p(check_callee_save_p)
check_callee_save_p(check_callee_save_p),
trace_p(trace_p)
{
reset();
}
......@@ -253,6 +256,24 @@ namespace vm
protected:
std::stack<register_t> call_stack;
bool check_callee_save_p;
public:
void step()
{
const inst::Inst& ri = (*text_section)[pc / 4];
pc = pc + 4;
if (trace_p)
std::cout << ri << std::endl;
ri.accept(*this);
}
void set_text_section(const inst::TextSection& s)
{
text_section = &s;
}
protected:
const inst::TextSection* text_section;
bool trace_p;
};
} // namespace vm
......
......@@ -36,10 +36,11 @@ namespace vm
{
public:
VirtualMachine(bool check_callee_save_p,
bool trace_exec_p,
std::istream& istr = std::cin,
std::ostream& ostr = std::cout):
cpu(memory, istr, ostr, check_callee_save_p),
program(0), text_section(0)
cpu(memory, istr, ostr, check_callee_save_p, trace_exec_p),
program(0)
{
}
......@@ -54,35 +55,24 @@ namespace vm
return;
}
this->program = &program;
text_section = &(program.text_section ());
memory.store(program.data_section());
cpu.set_pc(text_section->get_offset(inst::Label("main")));
cpu.set_text_section(program.text_section ());
cpu.set_pc(program.text_section ().get_offset(inst::Label("main")));
}
public:
bool step(bool trace = false)
{
const inst::Inst& ri = (*text_section)[cpu.get_pc() / 4];
cpu.set_pc(cpu.get_pc() + 4);
if (trace)
std::cout << ri << std::endl;
ri.accept(cpu);
return cpu.get_halt();
}
void execute(bool trace = false)
void execute()
{
precondition(program);
while (!step(trace));
while (!cpu.get_halt())
cpu.step();
}
protected:
Cpu cpu;
const inst::Program* program;
const inst::TextSection* text_section;
Memory memory;
};
......
......@@ -46,11 +46,11 @@ namespace vm
void
execute ()
{
vm::VirtualMachine vm(check_callee_save_p);
vm::VirtualMachine vm(check_callee_save_p, trace_exec_p);
vm.load_program(* parse::tasks::program);
if (exit_status != exit_success)
exit(exit_status);
vm.execute(trace_exec_p);
vm.execute();
}
} // namespace tasks
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment