Commit 7b931e51 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Index: ChangeLog

from  Benoît Perrot  <benoit@lrde.epita.fr>

        * src/vm/virtual_machine.hh, src/vm/virtual_machine.cc,
        * src/vm/vm-tasks.hh, src/vm/vm-tasks.cc:
        Check preservation of callee save registers on demand.
        * src/parse/parse-tasks.cc: Remove useless includes.

        * TODO: Update.
parent 6a47a2e9
2003-07-20 Benot Perrot <benoit@lrde.epita.fr>
* src/vm/virtual_machine.hh, src/vm/virtual_machine.cc,
* src/vm/vm-tasks.hh, src/vm/vm-tasks.cc:
Check preservation of callee save registers on demand.
* src/parse/parse-tasks.cc: Remove useless includes.
* TODO: Update.
2003-07-18 Benot Perrot <benoit@lrde.epita.fr>
* src/inst/register.hh, src/vm/cpu.hh:
......
* Make a test suite and machinery
* Complete simple instruction set
* Use delay slot
* Complete supported directives
......
......@@ -21,8 +21,6 @@
#include "misc/contract.hh"
#include "parse/libparse.hh"
#include "inst/program_solver.hh"
#include "vm/virtual_machine.hh"
#include "parse/parse-tasks.hh"
// Parse module related tasks' implementation.
......
......@@ -376,8 +376,8 @@ namespace vm
void
VirtualMachine::visit(const inst::Jr& jr)
{
// Close scope
end_scope();
// Assume it is a ret
ret();
cpu.set_pc(cpu.get_register(jr.get_dest()));
}
......@@ -388,8 +388,8 @@ namespace vm
cpu.set_ra(cpu.get_pc());
cpu.set_pc(cpu.get_ra() + jal.get_label());
// Open scope
begin_scope();
// Assume it is a call
call();
}
void
VirtualMachine::visit(const inst::Jalr& jalr)
......@@ -397,8 +397,8 @@ namespace vm
cpu.set_ra(cpu.get_pc());
cpu.set_pc(cpu.get_register(jalr.get_dest()));
// Open scope
begin_scope();
// Assume it is a call
call();
}
......@@ -429,8 +429,8 @@ namespace vm
{
if (cpu.get_register(bgezal.get_src ()) >= 0)
{
// Open scope
begin_scope();
// Assume it is a call
call();
cpu.set_ra(cpu.get_pc());
cpu.set_pc(cpu.get_pc() + bgezal.get_label());
......@@ -461,8 +461,8 @@ namespace vm
{
if (cpu.get_register(bltzal.get_src ()) < 0)
{
// Open scope
begin_scope();
// Assume it is a call
call();
cpu.set_ra(cpu.get_pc());
cpu.set_pc(cpu.get_pc() + bltzal.get_label());
......
......@@ -20,6 +20,7 @@
# define VM_VIRTUAL_MACHINE_HH
# include <iostream>
# include <stack>
# include "misc/contract.hh"
# include "common.hh"
......@@ -37,8 +38,10 @@ namespace vm
protected inst::ConstVisitor
{
public:
VirtualMachine(std::istream& istr = std::cin,
VirtualMachine(bool check_callee_save_p,
std::istream& istr = std::cin,
std::ostream& ostr = std::cout):
check_callee_save_p(check_callee_save_p),
istr(istr), ostr(ostr),
program(0), text_section(0)
{
......@@ -143,17 +146,38 @@ namespace vm
virtual void visit(const inst::Syscall& sycall);
protected:
void begin_scope()
void call()
{
if (check_callee_save_p)
for (int i = Cpu::s0; i <= Cpu::s7; ++i)
cpu.set_unlimited(-i, cpu.get_register((Cpu::kind_t) i));
call_stack.push(cpu.get_pc ());
cpu.begin_scope();
}
void end_scope()
void ret()
{
cpu.end_scope();
if (check_callee_save_p)
for (int i = Cpu::s0; i <= Cpu::s7; ++i)
if (cpu.get_unlimited(-i) != cpu.get_register((Cpu::kind_t) i))
{
std::cerr
<< "Warning: callee save register `$s" << i - Cpu::s0
<< "' was not preserved across last call to 0x"
<< std::hex << call_stack.top() << std::dec << std::endl;
cpu.set_register((Cpu::kind_t) i, cpu.get_unlimited(-i));
exit_set(exit_runtime);
}
call_stack.pop();
}
std::stack<register_t> call_stack;
protected:
bool halt;
bool check_callee_save_p;
std::istream& istr;
std::ostream& ostr;
......
......@@ -29,6 +29,13 @@ namespace vm
namespace tasks
{
static bool check_callee_save_p = false;
void
check_callee_save ()
{
check_callee_save_p = true;
}
static bool trace_exec_p = false;
void
trace_exec ()
......@@ -39,7 +46,7 @@ namespace vm
void
execute ()
{
vm::VirtualMachine vm;
vm::VirtualMachine vm(check_callee_save_p);
vm.load_program(* parse::tasks::program);
if (exit_status != exit_success)
exit(exit_status);
......
......@@ -29,11 +29,17 @@ namespace vm
TASK_MODULE ("3. Virtual Machine");
TASK_DECLARE ("check-callee-save",
"Warn if a callee save register "
"is not preserved across a call",
check_callee_save, "");
TASK_DECLARE ("trace-exec", "Trace the execution",
trace_exec, "");
TASK_DECLARE ("execute", "Execute the program on virtual machine",
execute, "prg-solve");
} // namespace tasks
} // namespace vm
......
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