Commit 6a47a2e9 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Move general register indices from Register.hh into Cpu.

parent 7e88b679
2003-07-18 Benot Perrot <benoit@lrde.epita.fr>
* src/inst/register.hh, src/vm/cpu.hh:
Move general register indices from Register.hh into Cpu.
* src/inst/program_builder.cc,
* dev/mipsy.xml, dev/mipsy-parser-gen.py, dev/mipsy-scanner-gen.py:
Adjust.
2003-07-18 Benot Perrot <benoit@lrde.epita.fr>
* src/vm/cpu.hh: Add a checker for unlimited register existence.
......
......@@ -43,6 +43,8 @@ print """
#include \"inst/register.hh\"
#include \"inst/all.hh\"
#include \"vm/cpu.hh\"
#include \"parse/libparse.hh\"
namespace yy
......@@ -51,6 +53,7 @@ namespace yy
}
using namespace inst;
using vm::Cpu;
%}
%error-verbose
......
......@@ -38,6 +38,8 @@ print """
#include \"common.hh\"
#include \"misc/escape.hh\"
#include \"vm/cpu.hh\"
#include \"parse/asm-scan.hh\"
#define YY_NEVER_INTERACTIVE 1
......@@ -54,6 +56,7 @@ print """
static std::string current_file;
using inst::Register;
using vm::Cpu;
%}
......@@ -101,36 +104,36 @@ for inst in instructions:
## Epilogue ----------------------------
print """
\"$zero\" {
yylval->reg = new Register(Register::zero);
yylval->reg = new Register(Register::general, Cpu::zero);
return REGISTER;
}"""
for i in range(2):
print "\"$v" + str(i) + "\" {"
print " yylval->reg = new Register(Register::v" + str(i) + ");"
print " yylval->reg = new Register(Register::general, Cpu::v" + str(i)+ ");"
print " return REGISTER;\n}"
for i in range(4):
print "\"$a" + str(i) + "\" {"
print " yylval->reg = new Register(Register::a" + str(i) + ");"
print " yylval->reg = new Register(Register::general, Cpu::a" + str(i)+ ");"
print " return REGISTER;\n}"
for i in range(10):
print "\"$t" + str(i) + "\" {"
print " yylval->reg = new Register(Register::t" + str(i) + ");"
print " yylval->reg = new Register(Register::general, Cpu::t" + str(i)+ ");"
print " return REGISTER;\n}"
for i in range(8):
print "\"$s" + str(i) + "\" {"
print " yylval->reg = new Register(Register::s" + str(i) + ");"
print " yylval->reg = new Register(Register::general, Cpu::s" + str(i)+ ");"
print " return REGISTER;\n}"
print """
\"$sp\" {
yylval->reg = new Register(Register::sp);
yylval->reg = new Register(Register::general, Cpu::sp);
return REGISTER;
}
\"$fp\" {
yylval->reg = new Register(Register::fp);
yylval->reg = new Register(Register::general, Cpu::fp);
return REGISTER;
}
\"$ra\" {
yylval->reg = new Register(Register::ra);
yylval->reg = new Register(Register::general, Cpu::ra);
return REGISTER;
}
......@@ -142,7 +145,7 @@ print """
// << \"(use --FIXME to enable it)\" << std::endl;
// exit_set (exit_scan);
// }
yylval->reg = new Register(atoi(yytext +2));
yylval->reg = new Register(Register::unlimited, atoi(yytext +2));
return REGISTER;
}
......
......@@ -118,14 +118,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<instruction opcode="neg" level="pseudo">
<syntax alias="sub">
<register />
<hidden value="* new Register(Register::zero)" />
<hidden value="* new Register(Register::general, Cpu::zero)" />
<register default="@0" />
</syntax>
</instruction>
<instruction opcode="negu" level="pseudo">
<syntax alias="subu">
<register />
<hidden value="* new Register(Register::zero)" />
<hidden value="* new Register(Register::general, Cpu::zero)" />
<register default="@0" />
</syntax>
</instruction>
......@@ -439,7 +439,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<syntax alias="nor">
<register />
<register default="@0"/>
<hidden value="* new Register(Register::zero)" />
<hidden value="* new Register(Register::general, Cpu::zero)" />
</syntax>
</instruction>
......@@ -628,7 +628,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<instruction opcode="beqz" level="pseudo">
<syntax alias="beq">
<register />
<hidden value="* new Register(Register::zero)"/>
<hidden value="* new Register(Register::general, Cpu::zero)"/>
<label />
</syntax>
</instruction>
......@@ -653,7 +653,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<instruction opcode="bnez" level="pseudo">
<syntax alias="bne">
<register />
<hidden value="* new Register(Register::zero)"/>
<hidden value="* new Register(Register::general, Cpu::zero)"/>
<label />
</syntax>
</instruction>
......@@ -957,7 +957,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<syntax alias="add">
<register />
<register />
<hidden value="*new Register(Register::zero)"/>
<hidden value="*new Register(Register::general, Cpu::zero)"/>
</syntax>
</instruction>
......@@ -1010,8 +1010,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<instruction opcode="nop" level="pseudo">
<syntax alias="sll">
<hidden value="* new Register(Register::zero)" />
<hidden value="* new Register(Register::zero)" />
<hidden value="* new Register(Register::general, Cpu::zero)" />
<hidden value="* new Register(Register::general, Cpu::zero)" />
<hidden value="* new IntExp(0)" />
</syntax>
</instruction>
......
......@@ -19,6 +19,9 @@
#include "common.hh"
#include "inst/program_builder.hh"
#include "vm/cpu.hh"
using vm::Cpu;
namespace inst
{
......@@ -30,10 +33,12 @@ namespace inst
{
// FIXME: this move should be in the delay slot
_program->text_section ().
add_inst(* new Add(dest, src, *new Register(Register::zero)));
add_inst(* new Add(dest, src,
* new Register(Register::general, Cpu::zero)));
_program->text_section ().add_inst(* new Bgez(src, *new IntExp(4)));
_program->text_section ().
add_inst(* new Sub(dest, * new Register(Register::zero), src));
add_inst(* new Sub(dest,
* new Register(Register::general, Cpu::zero), src));
}
void
......@@ -47,7 +52,7 @@ namespace inst
ProgramBuilder::add_div(Register& dest, Register& src1, Exp& src2)
{
// FIXME: program_solver must warn and/or break when exp is zero
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Li(at, src2));
_program->text_section ().add_inst(* new Div(src1, at));
_program->text_section ().add_inst(* new Mflo(dest));
......@@ -63,7 +68,7 @@ namespace inst
ProgramBuilder::add_divu(Register& dest, Register& src1, Exp& src2)
{
// FIXME: program_solver must warn and/or break when exp is zero
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Li(at, src2));
_program->text_section ().add_inst(* new Divu(src1, at));
_program->text_section ().add_inst(* new Mflo(dest));
......@@ -90,9 +95,10 @@ namespace inst
void
ProgramBuilder::add_rol(Register& dest, Register& src1, Register& src2)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().
add_inst(* new Subu(at, * new Register(Register::zero), src2));
add_inst(* new Subu(at,
* new Register(Register::general, Cpu::zero), src2));
_program->text_section ().add_inst(* new Srlv(at, src1, at));
_program->text_section ().add_inst(* new Sllv(dest, src1, src2));
_program->text_section ().add_inst(* new Or(dest, dest, at));
......@@ -101,7 +107,7 @@ namespace inst
void
ProgramBuilder::add_rol(Register& dest, Register& src1, Exp& src2)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Sll(at, src1, src2));
_program->text_section ().
add_inst(* new Srl(dest, src1,
......@@ -111,9 +117,10 @@ namespace inst
void
ProgramBuilder::add_ror(Register& dest, Register& src1, Register& src2)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().
add_inst(* new Subu(at, * new Register(Register::zero), src2));
add_inst(* new Subu(at,
* new Register(Register::general, Cpu::zero), src2));
_program->text_section ().add_inst(* new Sllv(at, src1, at));
_program->text_section ().add_inst(* new Srlv(dest, src1, src2));
_program->text_section ().add_inst(* new Or(dest, dest, at));
......@@ -121,7 +128,7 @@ namespace inst
void
ProgramBuilder::add_ror(Register& dest, Register& src1, Exp& src2)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Srl(at, src1, src2));
_program->text_section ().
add_inst(* new Sll(dest, src1,
......@@ -134,7 +141,8 @@ namespace inst
{
_program->text_section ().add_inst(* new Ori(dest, src1, src2));
_program->text_section ().
add_inst(* new Nor(dest, dest, * new Register(Register::zero)));
add_inst(* new Nor(dest, dest,
* new Register(Register::general, Cpu::zero)));
}
// Test instructions -------------------------------------
......@@ -160,14 +168,16 @@ namespace inst
{
_program->text_section ().add_inst(* new Xor(dest, src1, src2));
_program->text_section ().
add_inst(* new Sltu(dest, *new Register(Register::zero), dest));
add_inst(* new Sltu(dest,
* new Register(Register::general, Cpu::zero), dest));
}
void
ProgramBuilder::add_sne(Register& dest, Register& src, Exp& exp)
{
_program->text_section ().add_inst(* new Xori(dest, src, exp));
_program->text_section ().
add_inst(* new Sltu(dest, *new Register(Register::zero), dest));
add_inst(* new Sltu(dest,
* new Register(Register::general, Cpu::zero), dest));
}
// Greater
......@@ -199,14 +209,14 @@ namespace inst
void
ProgramBuilder::add_sgt(Register& dest, Register& src1, Exp& src2)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Li(at, src2));
_program->text_section ().add_inst(* new Slt(dest, at, src1));
}
void
ProgramBuilder::add_sgtu(Register& dest, Register& src1, Exp& src2)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Li(at, src2));
_program->text_section ().add_inst(* new Sltu(dest, at, src1));
}
......@@ -221,7 +231,7 @@ namespace inst
void
ProgramBuilder::add_sle(Register& dest, Register& src1, Exp& src2)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Li(at, src2));
_program->text_section ().add_inst(* new Slt(dest, at, src1));
_program->text_section ().add_inst(* new Xori(dest, dest, *new IntExp(1)));
......@@ -235,7 +245,7 @@ namespace inst
void
ProgramBuilder::add_sleu(Register& dest, Register& src1, Exp& src2)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Li(at, src2));
_program->text_section ().add_inst(* new Sltu(dest, at, src1));
_program->text_section ().add_inst(* new Xori(dest, dest, *new IntExp(1)));
......@@ -248,7 +258,7 @@ namespace inst
void
ProgramBuilder::add_bne(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Li(at, src2));
_program->text_section ().add_inst(* new Bne(src1, at, dest));
// FIXME: nop in delay slot
......@@ -256,7 +266,7 @@ namespace inst
void
ProgramBuilder::add_beq(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Li(at, src2));
_program->text_section ().add_inst(* new Beq(src1, at, dest));
// FIXME: nop in delay slot
......@@ -266,78 +276,86 @@ namespace inst
void
ProgramBuilder::add_bge(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Slt(at, src1, src2));
_program->text_section ().
add_inst(* new Beq(at, * new Register(Register::zero), dest));
add_inst(* new Beq(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bge(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Slti(at, src1, src2));
_program->text_section ().
add_inst(* new Beq(at, * new Register(Register::zero), dest));
add_inst(* new Beq(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bgeu(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Sltu(at, src1, src2));
_program->text_section ().
add_inst(* new Beq(at, * new Register(Register::zero), dest));
add_inst(* new Beq(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bgeu(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Sltiu(at, src1, src2));
_program->text_section ().
add_inst(* new Beq(at, * new Register(Register::zero), dest));
add_inst(* new Beq(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bgt(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Slt(at, src2, src1));
_program->text_section ().
add_inst(* new Bne(at, * new Register(Register::zero), dest));
add_inst(* new Bne(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bgt(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().
add_inst(* new Slti(at, src1,
* new OpExp(src2, OpExp::add, *new IntExp(1))));
_program->text_section ().
add_inst(* new Beq(at, * new Register(Register::zero), dest));
add_inst(* new Beq(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bgtu(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Sltu(at, src2, src1));
_program->text_section ().
add_inst(* new Bne(at, * new Register(Register::zero), dest));
add_inst(* new Bne(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bgtu(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().
add_inst(* new Sltiu(at, src1,
* new OpExp(src2, OpExp::add, *new IntExp(1))));
_program->text_section ().
add_inst(* new Beq(at, * new Register(Register::zero), dest));
add_inst(* new Beq(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
......@@ -345,78 +363,86 @@ namespace inst
void
ProgramBuilder::add_ble(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Slt(at, src2, src1));
_program->text_section ().
add_inst(* new Beq(at, * new Register(Register::zero), dest));
add_inst(* new Beq(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_ble(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().
add_inst(* new Slti(at, src1,
* new OpExp(src2, OpExp::add, *new IntExp(1))));
_program->text_section ().
add_inst(* new Bne(at, * new Register(Register::zero), dest));
add_inst(* new Bne(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bleu(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Sltu(at, src2, src1));
_program->text_section ().
add_inst(* new Beq(at, * new Register(Register::zero), dest));
add_inst(* new Beq(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bleu(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().
add_inst(* new Sltiu(at, src1,
* new OpExp(src2, OpExp::add, *new IntExp(1))));
_program->text_section ().
add_inst(* new Bne(at, * new Register(Register::zero), dest));
add_inst(* new Bne(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_blt(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Slt(at, src1, src2));
_program->text_section ().
add_inst(* new Bne(at, * new Register(Register::zero), dest));
add_inst(* new Bne(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_blt(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Slti(at, src1, src2));
_program->text_section ().
add_inst(* new Bne(at, * new Register(Register::zero), dest));
add_inst(* new Bne(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bltu(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Sltu(at, src1, src2));
_program->text_section ().
add_inst(* new Bne(at, * new Register(Register::zero), dest));
add_inst(* new Bne(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bltu(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
Register& at = * new Register(Register::general, Cpu::at);
_program->text_section ().add_inst(* new Sltiu(at, src1, src2));
_program->text_section ().
add_inst(* new Bne(at, * new Register(Register::zero), dest));
add_inst(* new Bne(at,
* new Register(Register::general, Cpu::zero), dest));
// FIXME: nop in delay slot
}
......
......@@ -31,26 +31,13 @@ namespace inst
public:
enum kind_t
{
zero = 0,
at,
v0, v1,
a0, a1, a2, a3,
t0, t1, t2, t3, t4, t5, t6, t7,
s0, s1, s2, s3, s4, s5, s6, s7,
t8, t9,
sp = 29,
fp,
ra,
general,
unlimited
};
public:
Register (kind_t kind):
kind(kind), index(-1)
{
}
Register (int index):
kind(unlimited), index(index)
Register (kind_t kind, int index):
kind(kind), index(index)
{
}
Register& operator=(const Register& reg)
......@@ -74,7 +61,7 @@ namespace inst
void print (std::ostream& ostr) const
{
if (kind != unlimited)
ostr << "$" << kind;
ostr << "$" << index;
else
ostr << "$x" << index;
}
......
......@@ -34,6 +34,23 @@ namespace vm
class Cpu
{
public:
enum kind_t
{
zero = 0,
at,
v0, v1,
a0, a1, a2, a3,
t0, t1, t2, t3, t4, t5, t6, t7,
s0, s1, s2, s3, s4, s5, s6, s7,
t8, t9,
k0, k1,
gp,
sp,
fp,
ra = 31
};
public:
Cpu()
{
......@@ -45,42 +62,38 @@ namespace vm
{
for (unsigned i = 0; i < 32; ++i)
GPR[i] = 0;
GPR[inst::Register::sp] = Memory::stack_bottom;
GPR[inst::Register::fp] = Memory::stack_bottom;
GPR[sp] = Memory::stack_bottom;
GPR[fp] = Memory::stack_bottom;
lo = 0;