Commit 49fde67a authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Index: ChangeLog

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

	Limit access to callee-save and caller-save registers.

	* dev/inst-solver-gen.py:
	Check use of callee-save and caller-save registers.
	* src/inst/inst-tasks.hh, src/inst/inst-tasks.cc:
	Add coresponding tasks.
parent c84cea90
2004-09-19 Benot Perrot <benoit@lrde.epita.fr>
Limit access to callee-save and caller-save registers.
* dev/inst-solver-gen.py:
Check use of callee-save and caller-save registers.
* src/inst/inst-tasks.hh, src/inst/inst-tasks.cc:
Add coresponding tasks.
2004-09-19 Benot Perrot <benoit@lrde.epita.fr>
Handle options waiting for an integer.
......
......@@ -59,9 +59,23 @@ namespace inst
protected ExpVisitor
{
public:
virtual ~ProgramSolver()
ProgramSolver():
program_(0),
max_callee_save_(8), max_caller_save_(10)
{}
virtual ~ProgramSolver()
{}
public:
void set_max_callee_save(int max_callee_save)
{
max_callee_save_ = max_callee_save;
}
void set_max_caller_save(int max_caller_save)
{
max_caller_save_ = max_caller_save;
}
public:
void solve(Program &program)
{
......@@ -98,6 +112,9 @@ for inst in instructions:
print """
protected:
Program *program_;
int max_callee_save_;
int max_caller_save_;
};
} // namespace inst
......@@ -116,88 +133,101 @@ sys.stdout = file("program_solver.cc.tmp", "w")
print license
print """#include \"inst/program_solver.hh\"
#include \"vm/cpu.hh\"
namespace inst
{
void
ProgramSolver::visit(IntExp &i)
{
i.set_immediate(i.get_integer());
}
void
ProgramSolver::visit(IntExp &i)
{
i.set_immediate(i.get_integer());
}
void
ProgramSolver::visit(LabelExp &l)
{
if (! program_->data_section().has_label(l.get_label()))
if (! program_->text_section().has_label(l.get_label()))
void
ProgramSolver::visit(LabelExp &l)
{
if (! program_->data_section().has_label(l.get_label()))
if (! program_->text_section().has_label(l.get_label()))
{
std::cerr << \"Undefined label: \" << l.get_label()
<< std::endl;
exit_set(exit_solve);
}
else
l.set_immediate(program_->text_section().
get_offset(l.get_label()) - pc_);
else
l.set_immediate(program_->data_section().get_offset(l.get_label()));
}
void
ProgramSolver::visit(OpExp &o)
{
o.get_left().accept(*this);
o.get_right().accept(*this);
switch (o.kind_)
{
case OpExp::add:
o.set_immediate(o.get_left().get_immediate() +
o.get_right().get_immediate());
break;
case OpExp::sub:
o.set_immediate(o.get_left().get_immediate() -
o.get_right().get_immediate());
break;
case OpExp::mul:
o.set_immediate(o.get_left().get_immediate() *
o.get_right().get_immediate());
break;
case OpExp::div:
o.set_immediate(o.get_left().get_immediate() /
o.get_right().get_immediate());
break;
}
}
void
ProgramSolver::solve_cpu_register(Register &reg) const
{
switch (reg.get_kind())
{
case Register::generic:
reg.set_kind(Register::general);
case Register::general:
if ((reg.get_index() == vm::Cpu::t9 && max_caller_save_ < 10)
|| (reg.get_index() == vm::Cpu::t8 && max_caller_save_ < 9)
|| (vm::Cpu::t0 + max_caller_save_ - 1 < reg.get_index()
&& reg.get_index() <= vm::Cpu::t7))
{
std::cerr << \"Undefined label: \" << l.get_label()
<< std::endl;
std::cerr << \"Caller-save register limited.\" << std::endl;
exit_set(exit_solve);
}
else
l.set_immediate(program_->text_section().
get_offset(l.get_label()) - pc_);
else
l.set_immediate(program_->data_section().get_offset(l.get_label()));
}
void
ProgramSolver::visit(OpExp &o)
{
o.get_left().accept(*this);
o.get_right().accept(*this);
switch (o.kind_)
{
case OpExp::add:
o.set_immediate(o.get_left().get_immediate() +
o.get_right().get_immediate());
break;
case OpExp::sub:
o.set_immediate(o.get_left().get_immediate() -
o.get_right().get_immediate());
break;
case OpExp::mul:
o.set_immediate(o.get_left().get_immediate() *
o.get_right().get_immediate());
break;
case OpExp::div:
o.set_immediate(o.get_left().get_immediate() /
o.get_right().get_immediate());
break;
}
}
void
ProgramSolver::solve_cpu_register(Register &reg) const
{
switch (reg.get_kind())
{
case Register::generic:
reg.set_kind(Register::general);
break;
case Register::general:
break;
case Register::unlimited:
if (!parse::unlimited_regs_p)
{
std::cerr << \"Unlimited registers prohibited.\" << std::endl;
exit_set(exit_solve);
}
break;
};
}
else if (vm::Cpu::s0 + max_callee_save_ - 1 < reg.get_index() &&
reg.get_index() <= vm::Cpu::s7)
{
std::cerr << \"Callee-save register limited.\" << std::endl;
exit_set(exit_solve);
}
break;
case Register::unlimited:
if (!parse::unlimited_regs_p)
{
std::cerr << \"Unlimited registers prohibited.\" << std::endl;
exit_set(exit_solve);
}
break;
};
}
void
ProgramSolver::solve_cop_register(Register &reg) const
{
if (reg.get_kind() != Register::generic)
{
std::cerr << \"Coprocessor registers must be generic.\" << std::endl;
exit_set(exit_solve);
}
}
void
ProgramSolver::solve_cop_register(Register &reg) const
{
if (reg.get_kind() != Register::generic)
{
std::cerr << \"Coprocessor registers must be generic.\" << std::endl;
exit_set(exit_solve);
}
}
"""
......
......@@ -39,6 +39,8 @@ namespace inst
prg_solve ()
{
inst::ProgramSolver program_solver;
program_solver.set_max_callee_save(max_callee_save);
program_solver.set_max_caller_save(max_caller_save);
program_solver.solve(* parse::tasks::program);
if (exit_status != exit_success)
exit (exit_status);
......
......@@ -37,6 +37,14 @@ namespace inst
"Resolve jump offsets and check bounds of immediates",
prg_solve, "parse");
INT_TASK_DECLARE ("callee-save",
"Set max number of callee-save registers",
max_callee_save, 8, 0, 8,
"");
INT_TASK_DECLARE ("caller-save",
"Set max number of caller-save registers",
max_caller_save, 10, 0, 10,
"");
} // namespace tasks
} // namespace inst
......
Supports Markdown
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