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

More syntaxes and neg{,u}.

parent 51eb58e9
2003-06-29 Benot Perrot <benoit@lrde.epita.fr>
* dev/mipsy.xml, dev/mipsy.py:
Allow level of instruction override in syntax.
Rename "neg" as "negu".
* dev/mipsy-builder-gen.py:
Adjust.
* src/inst/program_builder.cc:
Support more syntaxes on branch instructions, support neg.
* src/vm/virtual_machine.cc:
Adjust overflow detection.
2003-06-29 Benot Perrot <benoit@lrde.epita.fr>
* dev/mipsy-parser-gen.py, dev/mipsy-scanner-gen.py,
......
......@@ -100,29 +100,26 @@ type_map = {
}
for inst in instructions:
if inst.level == "pseudo":
continue
if inst.level == "native":
proto = ""
call = ""
for attribute in inst.format.params:
proto = proto + type_map[attribute.kind] + " " + \
attribute.name + ", "
call = call + attribute.name + ", "
proto = string.rstrip(proto, ", ")
call = string.rstrip(call, ", ")
print " void\tadd_" + inst.opcode + "(" + proto + ")"
print " {"
call = "* new " + class_id(inst.opcode) + "(" + call + ")"
print " _program->text_section().add_inst (" + call + ");"
print " }"
for syntax in inst.syntaxes:
if (syntax.alias != "") or (syntax.level == "pseudo"):
continue
else: # inst.level == "complex"
for syntax in inst.syntaxes:
if syntax.alias != "":
continue
if syntax.level == "native":
proto = ""
call = ""
for attribute in inst.format.params:
proto = proto + type_map[attribute.kind] + " " + \
attribute.name + ", "
call = call + attribute.name + ", "
proto = string.rstrip(proto, ", ")
call = string.rstrip(call, ", ")
print " void\tadd_" + inst.opcode + "(" + proto + ")"
print " {"
call = "* new " + class_id(inst.opcode) + "(" + call + ")"
print " _program->text_section().add_inst (" + call + ");"
print " }"
else: # syntax.level == "complex"
proto = ""
for param in syntax.params:
proto = proto + type_map[param.kind]
......
......@@ -127,9 +127,10 @@ class FormatBuilder:
## -------------------------------------
class Syntax:
def __init__(self, params, alias):
def __init__(self, params, alias, level):
self.params = params
self.alias = alias
self.level = level
def display(self):
if self.alias != "":
......@@ -146,10 +147,12 @@ class SyntaxBuilder:
def set_alias(self, alias):
self.alias = alias
def set_level(self, level):
self.level = level
def add_param(self, param):
self.params.append(param)
def get(self):
return Syntax(self.params, self.alias)
return Syntax(self.params, self.alias, self.level)
## -------------------------------------
......@@ -208,6 +211,10 @@ class InstructionSetHandler(ContentHandler):
self.sb.reset()
if attrs.has_key("alias"):
self.sb.set_alias(attrs["alias"])
if attrs.has_key("level"):
self.sb.set_level(attrs["level"])
else:
self.sb.set_level(self.ib.level)
elif name in ["register", "immediate", "label", "address", "hidden"]:
self.pb.reset()
self.pb.set_kind(name)
......
......@@ -142,7 +142,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</instruction>
<instruction opcode="neg" level="pseudo">
<instruction opcode="neg" level="complex">
<syntax>
<register />
<register default="@0"/>
</syntax>
</instruction>
<instruction opcode="negu" level="pseudo">
<syntax alias="sub">
<register />
<hidden value="* new Register(Register::zero)" />
......@@ -151,6 +157,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</instruction>
<instruction opcode="mul" level="native">
<format>
<register name="dest" />
......@@ -428,28 +435,28 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</instruction>
<instruction opcode="bge" level="complex">
<format>
<register name="src1"/>
<register name="src2"/>
<label name="label"/>
</format>
<syntax>
<register />
<register />
<label />
</syntax>
<syntax>
<register />
<immediate />
<label />
</syntax>
</instruction>
<instruction opcode="bgeu" level="complex">
<format>
<register name="src1"/>
<register name="src2"/>
<label name="label"/>
</format>
<syntax>
<register />
<register />
<label />
</syntax>
<syntax>
<register />
<immediate />
<label />
</syntax>
</instruction>
<instruction opcode="bgez" level="native">
<format>
......@@ -478,6 +485,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<register />
<label />
</syntax>
<syntax>
<register />
<immediate />
<label />
</syntax>
</instruction>
<instruction opcode="bgtu" level="complex">
<syntax>
......@@ -485,6 +497,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<register />
<label />
</syntax>
<syntax>
<register />
<immediate />
<label />
</syntax>
</instruction>
<instruction opcode="bgtz" level="native">
<format>
......@@ -503,18 +520,23 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<register />
<label />
</syntax>
<syntax>
<register />
<immediate />
<label />
</syntax>
</instruction>
<instruction opcode="bleu" level="complex">
<format>
<register name="src1"/>
<register name="src2"/>
<label name="label"/>
</format>
<syntax>
<register />
<register />
<label />
</syntax>
<syntax>
<register />
<immediate />
<label />
</syntax>
</instruction>
<instruction opcode="blez" level="native">
<format>
......@@ -528,28 +550,28 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</instruction>
<instruction opcode="blt" level="complex">
<format>
<register name="src1"/>
<register name="src2"/>
<label name="label"/>
</format>
<syntax>
<register />
<register />
<label />
</syntax>
<syntax>
<register />
<immediate />
<label />
</syntax>
</instruction>
<instruction opcode="bltu" level="complex">
<format>
<register name="src1"/>
<register name="src2"/>
<label name="label"/>
</format>
<syntax>
<register />
<register />
<label />
</syntax>
<syntax>
<register />
<immediate />
<label />
</syntax>
</instruction>
<instruction opcode="bltz" level="native">
<format>
......
......@@ -23,6 +23,16 @@
namespace inst
{
// Arithmetics instructions ------------------------------
void
ProgramBuilder::add_neg(Register& dest, Register& src)
{
_program->text_section ().add_inst(* new Xori(dest, src, *new IntExp(~0)));
_program->text_section ().add_inst(* new Addi(dest, dest, *new IntExp(1)));
}
// Test instructions -------------------------------------
void
......@@ -77,12 +87,30 @@ namespace inst
_program->text_section ().add_inst(* new Bgez(at, dest));
}
void
ProgramBuilder::add_bge(Register& src1, Exp& src2, Label& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Addi(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Bgez(at, dest));
}
void
ProgramBuilder::add_bgeu(Register& src1, Register& src2, Label& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Subu(at, src1, src2));
_program->text_section ().add_inst(* new Bgez(at, dest));
}
void
ProgramBuilder::add_bgeu(Register& src1, Exp& src2, Label& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Addiu(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Bgez(at, dest));
}
void
ProgramBuilder::add_bgt(Register& src1, Register& src2, Label& dest)
......@@ -92,12 +120,30 @@ namespace inst
_program->text_section ().add_inst(* new Bgtz(at, dest));
}
void
ProgramBuilder::add_bgt(Register& src1, Exp& src2, Label& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Addi(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Bgtz(at, dest));
}
void
ProgramBuilder::add_bgtu(Register& src1, Register& src2, Label& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Subu(at, src1, src2));
_program->text_section ().add_inst(* new Bgtz(at, dest));
}
void
ProgramBuilder::add_bgtu(Register& src1, Exp& src2, Label& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Addiu(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Bgtz(at, dest));
}
// Lower
void
......@@ -108,12 +154,30 @@ namespace inst
_program->text_section ().add_inst(* new Blez(at, dest));
}
void
ProgramBuilder::add_ble(Register& src1, Exp& src2, Label& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Addi(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Blez(at, dest));
}
void
ProgramBuilder::add_bleu(Register& src1, Register& src2, Label& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Subu(at, src1, src2));
_program->text_section ().add_inst(* new Blez(at, dest));
}
void
ProgramBuilder::add_bleu(Register& src1, Exp& src2, Label& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Addiu(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Blez(at, dest));
}
void
ProgramBuilder::add_blt(Register& src1, Register& src2, Label& dest)
......@@ -123,12 +187,30 @@ namespace inst
_program->text_section ().add_inst(* new Bltz(at, dest));
}
void
ProgramBuilder::add_blt(Register& src1, Exp& src2, Label& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Addi(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Bltz(at, dest));
}
void
ProgramBuilder::add_bltu(Register& src1, Register& src2, Label& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Subu(at, src1, src2));
_program->text_section ().add_inst(* new Bltz(at, dest));
}
void
ProgramBuilder::add_bltu(Register& src1, Exp& src2, Label& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Addiu(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Bltz(at, dest));
}
// Load address ------------------------------------------
void
......
......@@ -37,9 +37,9 @@ namespace vm
cpu.set_register(add.get_dest (), c);
// FIXME: might be accelerated by testing only the sign bit.
if ((a < 0 && b < 0 & c > 0) ||
(a > 0 && b > 0 & c < 0))
std::cerr << "Overflow" << std::endl;
if ((a < 0 && b < 0 && c > 0) ||
(a > 0 && b > 0 && c < 0))
std::cerr << "Runtime Exception: Overflow" << std::endl;
}
void
VirtualMachine::visit(const inst::Addi& addi)
......@@ -51,9 +51,9 @@ namespace vm
cpu.set_register(addi.get_dest (), c);
// FIXME: might be accelerated by testing only the sign bit.
if ((a < 0 && b < 0 & c > 0) ||
(a > 0 && b > 0 & c < 0))
std::cerr << "Overflow" << std::endl;
if ((a < 0 && b < 0 && c > 0) ||
(a > 0 && b > 0 && c < 0))
std::cerr << "Runtime Exception: Overflow" << std::endl;
}
void
VirtualMachine::visit(const inst::Addu& addu)
......
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