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

Index: ChangeLog

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

        * dev/mipsy.py:
        Add a C++ variable identifier writer.
        * dev/inst-solver-gen.py:
        Generate program solver (interface and implementation).
        * dev/inst-makefile-gen.py:
        Use the generator.
        * src/inst/program_solver.hh:
        Remove now generated file.
parent b9021fd0
2004-04-05 Benot Perrot <benoit@lrde.epita.fr>
* dev/mipsy.py:
Add a C++ variable identifier writer.
* dev/inst-solver-gen.py:
Generate program solver (interface and implementation).
* dev/inst-makefile-gen.py:
Use the generator.
* src/inst/program_solver.hh:
Remove now generated file.
2004-04-03 Benot Perrot <benoit@lrde.epita.fr>
* src/common.hh,
......
......@@ -47,7 +47,9 @@ print """ decl.hh \\
print """
BUILT_SOURCES = \\
$(FROM_INST_NODES_GEN_PY) inst-nodes-gen.log \\
program_builder.hh inst-builder-gen.log
program_builder.hh inst-builder-gen.log \\
program_solver.hh program_solver.cc inst-solver-gen.log
inst-nodes-gen.log: $(top_srcdir)/dev/inst-nodes-gen.py $(top_srcdir)/dev/mipsy.xml
$(top_srcdir)/dev/inst-nodes-gen.py < $(top_srcdir)/dev/mipsy.xml
......@@ -59,7 +61,16 @@ inst-builder-gen.log: $(top_srcdir)/dev/inst-builder-gen.py $(top_srcdir)/dev/mi
touch $@
program_builder.hh: inst-builder-gen.log
MAINTAINERCLEANFILES = $(FROM_INST_NODES_GEN_PY) program_builder.hh
inst-solver-gen.log: $(top_srcdir)/dev/inst-solver-gen.py $(top_srcdir)/dev/mipsy.xml
$(top_srcdir)/dev/inst-solver-gen.py < $(top_srcdir)/dev/mipsy.xml
touch $@
program_solver.hh program_solver.cc: inst-solver-gen.log
MAINTAINERCLEANFILES = \\
$(FROM_INST_NODES_GEN_PY) \\
program_builder.hh \\
program_solver.hh program_solver.cc
noinst_LIBRARIES = libinst.a
libinst_a_SOURCES = \\
......@@ -75,7 +86,7 @@ libinst_a_SOURCES = \\
data_section.hh data_section.cc \\
program.hh \\
program_builder.hh program_builder.cc inst-builder-gen.log \\
program_solver.hh \\
program_solver.hh program_solver.cc inst-solver-gen.log \\
inst-tasks.hh inst-tasks.cc"""
## Epilogue
......
#!/usr/bin/env python
##
## This file is part of Mipsy, a tiny MIPS simulator
## Copyright (C) 2003, 2004 Benoit Perrot <benoit@lrde.epita.fr>
##
## Mipsy is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## Mipsy is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
import sys, os
import string, re
import mipsy
from mipsy import license, depth, class_id
#### Mipsy's program solver generator ----------------------
parser = mipsy.InstructionSetParser()
instructions = parser.parse(sys.stdin)
## Generate interface
sys.stdout = file("program_solver.hh.tmp", "w")
print license
print """#ifndef INST_PROGRAM_SOLVER_HH
# define INST_PROGRAM_SOLVER_HH
// FIXME: lack of compatibility
# include <stdint.h>
# include \"common.hh\"
# include \"inst/exp-visitor.hh\"
# include \"inst/exp.hh\"
# include \"inst/visitor.hh\"
# include \"inst/all.hh\"
# include \"inst/program.hh\"
// FIXME: dirty access unlimited registers flag
# include \"parse/libparse.hh\"
namespace inst
{
class ProgramSolver:
protected Visitor,
protected ExpVisitor
{
public:
virtual ~ProgramSolver()
{}
public:
void solve(Program &program)
{
program_ = &program;
int i;
for (i = 0, pc_ = 4; i < program.text_section().size(); ++i, pc_ += 4)
program_->text_section()[i].accept(*this);
}
protected:
int pc_;
protected:
void solve_exp(Exp &exp)
{
exp.accept(*this);
}
virtual void visit(IntExp &i);
virtual void visit(LabelExp &l);
virtual void visit(OpExp &o);
"""
print " protected:"
for inst in instructions:
if inst.level == "native":
print " virtual void visit(" + mipsy.class_id(inst.opcode) + " &);"
print """
protected:
Program *program_;
};
} // namespace inst
#endif // !INST_PROGRAM_SOLVER_HH
"""
sys.stdout.close()
sys.stdout = sys.__stdout__
mipsy.lazy_overwrite("program_solver.hh", "program_solver.hh.tmp")
os.remove("program_solver.hh.tmp")
## Generate implementation
sys.stdout = file("program_solver.cc.tmp", "w")
print license
print """#include \"inst/program_solver.hh\"
namespace inst
{
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()))
{
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;
}
}
"""
for inst in instructions:
if inst.level == "native":
var_id = mipsy.var_id(inst.opcode)
content = ""
for attribute in inst.format.attributes:
if attribute.type in "Exp":
content = content + " solve_exp(" + \
var_id + ".get_" + attribute.name + "());\n"
print " void"
if content != "":
print " ProgramSolver::visit(" + mipsy.class_id(inst.opcode) + \
" &" + var_id + ")"
print " {\n" + content + " }"
else:
print " ProgramSolver::visit(" + mipsy.class_id(inst.opcode) + " &)"
print " {"
print " }"
print """
} // namespace inst"""
sys.stdout.close()
sys.stdout = sys.__stdout__
mipsy.lazy_overwrite("program_solver.cc", "program_solver.cc.tmp")
os.remove("program_solver.cc.tmp")
......@@ -89,6 +89,13 @@ def class_id(s):
def file_id(s):
return string.lower(s)
## Return a valid C++ variable name
def var_id(s):
s = string.lower(s)
if s in ["and", "or", "xor"]:
s = s + "_";
return s
## -------------------------------------
class Attribute:
def __init__(self, type, name, value):
......
......@@ -2,23 +2,27 @@
(Created-By-Prcs-Version 1 3 2)
(Project-Description "")
(Project-Version mipsy 0 80)
(Parent-Version mipsy 0 79)
(Project-Version mipsy 0 81)
(Parent-Version mipsy 0 80)
(Version-Log
"Index: ChangeLog
from Benot Perrot <benoit@lrde.epita.fr>
* src/common.hh,
* src/mipsy.cc,
* src/inst/exp.hh,
* src/inst/register.hh,
* src/vm/cpu.hh, src/vm/cpu.cc:
Use STL type naming style on enumerations.
* dev/mipsy.py:
Add a C++ variable identifier writer.
* dev/inst-solver-gen.py:
Generate program solver (interface and implementation).
* dev/inst-makefile-gen.py:
Use the generator.
* src/inst/program_solver.hh:
Remove now generated file.
")
(New-Version-Log
"")
(Checkin-Time "Sat, 03 Apr 2004 15:46:26 +0200")
(Checkin-Time "Sun, 04 Apr 2004 16:26:16 +0200")
(Checkin-Login benoit)
(Files
......@@ -26,7 +30,7 @@ from Beno
;; ./
(AUTHORS (mipsy/0_AUTHORS 1.1 644))
(COPYING (mipsy/1_COPYING 1.1 644))
(ChangeLog (mipsy/2_ChangeLog 1.74 604))
(ChangeLog (mipsy/2_ChangeLog 1.75 604))
(INSTALL (mipsy/b/12_INSTALL 1.1 604))
(Makefile.am (mipsy/3_Makefile.a 1.8 604))
(NEWS (mipsy/b/25_NEWS 1.6 604))
......@@ -42,9 +46,10 @@ from Beno
;; ./dev/
(dev/doc-inst-set-gen.py (mipsy/c/21_doc-inst-s 1.3 705))
(dev/inst-builder-gen.py (mipsy/15_mipsy-buil 1.12 705))
(dev/inst-makefile-gen.py (mipsy/b/15_mipsy-mk-i 1.8 705))
(dev/inst-makefile-gen.py (mipsy/b/15_mipsy-mk-i 1.9 705))
(dev/inst-nodes-gen.py (mipsy/12_mipsy-inst 1.10 705))
(dev/mipsy.py (mipsy/16_mipsy.py 1.8 705))
(dev/inst-solver-gen.py (mipsy/b/13_inst-solve 1.1 755))
(dev/mipsy.py (mipsy/16_mipsy.py 1.9 705))
(dev/mipsy.xml (mipsy/17_mipsy.xml 1.16 604))
(dev/parse-asm-parse-gen.py (mipsy/13_mipsy-pars 1.10 705))
(dev/parse-asm-scan-gen.py (mipsy/14_mipsy-scan 1.11 705))
......@@ -76,7 +81,6 @@ from Beno
(src/inst/label.hh (mipsy/b/20_label.hh 1.4 604))
(src/inst/program.hh (mipsy/28_program.hh 1.4 644))
(src/inst/program_builder.cc (mipsy/29_program_bu 1.14 604))
(src/inst/program_solver.hh (mipsy/30_program_so 1.8 644))
(src/inst/register.hh (mipsy/31_register.h 1.7 644))
(src/inst/section.hh (mipsy/b/24_section.hh 1.8 604))
(src/inst/text_section.hh (mipsy/32_text_secti 1.8 604))
......
//
// This file is part of Mipsy, a tiny MIPS simulator
// Copyright (C) 2003, 2004 Benoit Perrot <benoit@lrde.epita.fr>
//
// Mipsy is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Mipsy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#ifndef INST_PROGRAM_SOLVER_HH
# define INST_PROGRAM_SOLVER_HH
// FIXME: lack of compatibility
# include <stdint.h>
# include "common.hh"
# include "inst/exp-visitor.hh"
# include "inst/exp.hh"
# include "inst/visitor.hh"
# include "inst/all.hh"
# include "inst/program.hh"
namespace inst
{
class ProgramSolver:
protected Visitor,
protected ExpVisitor
{
public:
virtual ~ProgramSolver()
{
}
public:
void solve(Program& program)
{
program_ = &program;
int i;
for (i = 0, pc_ = 4; i < program.text_section().size(); ++i, pc_ += 4)
program_->text_section()[i].accept(*this);
}
protected:
int pc_;
protected:
void resolve_exp(Exp& exp)
{
exp.accept(*this);
}
virtual void visit(IntExp& i)
{
i.set_immediate(i.get_integer());
}
virtual void 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()));
}
virtual void 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;
}
}
protected:
virtual void visit(Add&) {}
virtual void visit(Addi& addi)
{
resolve_exp(addi.get_imm());
}
virtual void visit(Addu&) {}
virtual void visit(Addiu& addiu)
{
resolve_exp(addiu.get_imm());
}
virtual void visit(Sub&) {}
virtual void visit(Subu&) {}
virtual void visit(Sll& sll)
{
resolve_exp(sll.get_imm());
}
virtual void visit(Sllv&) {}
virtual void visit(Sra& sra)
{
resolve_exp(sra.get_imm());
}
virtual void visit(Srav&) {}
virtual void visit(Srl& srl)
{
resolve_exp(srl.get_imm());
}
virtual void visit(Srlv&) {}
virtual void visit(Mul&) {}
virtual void visit(Div&) {}
virtual void visit(Divu&) {}
protected:
virtual void visit(And&) {}
virtual void visit(Andi& andi)
{
resolve_exp(andi.get_imm());
}
virtual void visit(Or&) {}
virtual void visit(Ori& ori)
{
resolve_exp(ori.get_imm());
}
virtual void visit(Nor&) {}
virtual void visit(Xor&) {}
virtual void visit(Xori& xori)
{
resolve_exp(xori.get_imm());
}
protected:
virtual void visit(Slt&) {}
virtual void visit(Slti& slti)
{
resolve_exp(slti.get_imm());
}
virtual void visit(Sltu&) {}
virtual void visit(Sltiu& sltiu)
{
resolve_exp(sltiu.get_imm());
}
protected:
virtual void visit(Beq& beq)
{
resolve_exp(beq.get_label());
}
virtual void visit(Bne& bne)
{
resolve_exp(bne.get_label());
}
virtual void visit(Bgez& bgez)
{
resolve_exp(bgez.get_label());
}
virtual void visit(Bgezal& bgezal)
{
resolve_exp(bgezal.get_label());
}
virtual void visit(Bgtz& bgtz)
{
resolve_exp(bgtz.get_label());
}
virtual void visit(Blez& blez)
{
resolve_exp(blez.get_label());
}
virtual void visit(Bltz& bltz)
{
resolve_exp(bltz.get_label());
}
virtual void visit(Bltzal& bltzal)
{
resolve_exp(bltzal.get_label());
}
virtual void visit(Jmp& jmp)
{
resolve_exp(jmp.get_label());
}
virtual void visit(Jr&) {}
virtual void visit(Jal& jal)
{
resolve_exp(jal.get_label());
}
virtual void visit(Jalr&) {}
protected:
virtual void visit(Lb& lb)
{
resolve_exp(lb.get_offset());
}
virtual void visit(Lbu& lbu)
{
resolve_exp(lbu.get_offset());
}
virtual void visit(Lw& lw)
{
resolve_exp(lw.get_offset());
}
virtual void visit(Li& li)
{
resolve_exp(li.get_imm());
}
virtual void visit(Sb& sb)
{
resolve_exp(sb.get_offset());
}
virtual void visit(Sw& sw)
{
resolve_exp(sw.get_offset());
}
protected:
virtual void visit(Mfhi&) {}
virtual void visit(Mflo&) {}
virtual void visit(Mthi&) {}
virtual void visit(Mtlo&) {}
protected:
virtual void visit(Syscall&) {}
protected:
Program* program_;
};
} // namespace inst
#endif // !INST_PROGRAM_SOLVER_HH
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