Commit d0a692ef authored by Benoit Perrot's avatar Benoit Perrot
Browse files

2005-03-08 Benoît Perrot <benoit@lrde.epita.fr>

	Prefer explicit function calls to constructor optional arguments
	to set non-mandatory attributes (e.g. trace flags).

	* src/vm/cpu.hh, src/vm/cpu.cc, src/vm/virtual_machine.hh,
	* dev/inst-builder-gen.py (Cpu, VirtualMachine, ProgramBuilder): 
	Remove uncomprehensible boolean arguments from constructor, add
	corresponding switches.
	* src/vm-tasks.cc, src/shell/shell.cc, src/parse/libparse.cc:
	Update accordingly.
parent 4f697717
2005-03-08 Benoît Perrot <benoit@lrde.epita.fr>
Prefer explicit function calls to constructor optional arguments
to set non-mandatory attributes (e.g. trace flags).
* src/vm/cpu.hh, src/vm/cpu.cc, src/vm/virtual_machine.hh,
* dev/inst-builder-gen.py (Cpu, VirtualMachine, ProgramBuilder):
Remove uncomprehensible boolean arguments from constructor, add
corresponding switches.
* src/vm-tasks.cc, src/shell/shell.cc, src/parse/libparse.cc:
Update accordingly.
2005-03-08 Benoît Perrot <benoit@lrde.epita.fr>
Remove redundant accessors from virtual machine.
......
......@@ -54,17 +54,21 @@ namespace inst
class ProgramBuilder
{
public:
ProgramBuilder(bool nop_after_branch_p = false):
program_(0), nop_after_branch_p_(nop_after_branch_p)
ProgramBuilder():
program_(0), nop_after_branch_p_(false)
{
}
public:
void reset(bool nop_after_branch_p = false)
void reset()
{
nop_after_branch_p_ = nop_after_branch_p;
program_ = new Program();
}
void set_nop_after_branch(bool nop_after_branch_p)
{
nop_after_branch_p_ = nop_after_branch_p;
}
Program* get()
{
......
......@@ -41,7 +41,8 @@ namespace parse
parse (const std::string &filename)
{
inst::ProgramBuilder program_builder;
program_builder.reset(nop_after_branch_p);
program_builder.reset();
program_builder.set_nop_after_branch(nop_after_branch_p);
std::string dummy(filename);
yy::parser parser = yy::parser(dummy, program_builder);
......
......@@ -39,9 +39,10 @@ namespace shell
// --------------------------------------------------------------------------
Shell::Shell():
program_(0),
vm_(true, false)
program_(0)
{
vm_.get_cpu().set_check_callee_save(true);
vm_.get_cpu().set_trace(false);
map_token_["run"] = Cmd::id_run;
map_token_["quit"] = Cmd::id_quit;
......
......@@ -33,7 +33,9 @@ namespace vm
void
execute ()
{
vm::VirtualMachine vm(check_callee_save_p, trace_exec_p);
vm::VirtualMachine vm;
vm.get_cpu().set_check_callee_save(check_callee_save_p);
vm.get_cpu().set_trace(trace_exec_p);
vm.load_program(* parse::tasks::program);
if (exit_status != exit_success)
exit(exit_status);
......
......@@ -33,13 +33,11 @@ namespace vm
Cpu::Cpu(Mmu& mmu,
Cp0 &cp0,
std::istream& istr,
std::ostream& ostr,
bool check_callee_save_p,
bool trace_p):
std::ostream& ostr):
mmu_(mmu), cp0_(cp0),
istr_(istr), ostr_(ostr),
check_callee_save_p_(check_callee_save_p),
trace_p_(trace_p),
check_callee_save_p_(false),
trace_p_(false),
bubble_(new inst::Sll(inst::Register(inst::Register::general, Cpu::zero),
inst::Register(inst::Register::general, Cpu::zero),
new inst::IntExp(0)))
......
......@@ -70,9 +70,7 @@ namespace vm
Cpu(Mmu& mmu,
Cp0 &cp0,
std::istream& istr,
std::ostream& ostr,
bool check_callee_save_p_,
bool trace_p);
std::ostream& ostr);
/// Destroy a CPU.
virtual ~Cpu();
/** \} */
......@@ -303,6 +301,10 @@ namespace vm
{
return call_stack_;
}
void set_check_callee_save(bool check_callee_save_p)
{
check_callee_save_p_ = check_callee_save_p;
}
protected:
std::vector<register_type> call_stack_;
......
......@@ -58,15 +58,13 @@ namespace vm
/** \name Constructor and destructor.
\{ */
public:
VirtualMachine(bool check_callee_save_p,
bool trace_exec_p,
mode_type mode = normal,
VirtualMachine(mode_type mode = normal,
std::istream& istr = std::cin,
std::ostream& ostr = std::cout):
mode_(mode),
status_(stop),
mmu_(cp0_, memory_),
cpu_(mmu_, cp0_, istr, ostr, check_callee_save_p, trace_exec_p)
cpu_(mmu_, cp0_, istr, ostr)
{
}
/** \} */
......@@ -135,7 +133,9 @@ namespace vm
}
const Cp0 &get_cp0() const { return cp0_; }
const Cpu &get_cpu() const { return cpu_; }
Cpu &get_cpu() { return cpu_; }
protected:
/// The virtual machine mode.
......
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