Commit 7de525af authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Index: ChangeLog

--- ChangeLog Sat, 10 Jan 2004 22:32:29 +0100 noe (mipsy/2_ChangeLog 1.56 604)
+++ ChangeLog Sat, 10 Jan 2004 23:23:14 +0100 noe (mipsy/2_ChangeLog 1.56 604)
@@ -1,5 +1,13 @@
 2004-01-10  Benoît Perrot  <benoit@lrde.epita.fr>
 
+	* dev/inst-nodes-gen.py: Generate interface of classes in
+	.hh files, inline methods in .hxx files, implementation in .cc.
+	* dev/inst-makefile-gen.py:
+	Distribute .hh, .hxx, .cc files of each class.
+	Use a stamp file to avoid useness launching of generators.
+
+2004-01-10  Benoît Perrot  <benoit@lrde.epita.fr>
+
 	* dev/mipsy.xml, dev/parse-asm-parse-gen.py:
 	Use human readable identifiers to locate tokens.
parent b3e2382e
2004-01-10 Benot Perrot <benoit@lrde.epita.fr>
* dev/inst-nodes-gen.py: Generate interface of classes in
.hh files, inline methods in .hxx files, implementation in .cc.
* dev/inst-makefile-gen.py:
Distribute .hh, .hxx, .cc files of each class.
Use a stamp file to avoid useness launching of generators.
2004-01-10 Benot Perrot <benoit@lrde.epita.fr>
* dev/mipsy.xml, dev/parse-asm-parse-gen.py:
......
......@@ -33,37 +33,43 @@ print """INCLUDES = -I $(top_srcdir)/src -I $(top_builddir)/src
FROM_MIPSY_INST_GEN_PY = \\"""
for i in range(0, len(instructions)):
if instructions[i].level == "native":
print "\t" + instructions[i].opcode + ".hh\t\t\t\t\\"
line = "\t"
for ext in ["hh", "hxx", "cc"]:
line = line + instructions[i].opcode + "." + ext + " "
print line + "\t\t\\"
print """ decl.hh \\
all.hh \\
visitor.hh"""
print """
BUILT_SOURCES = $(FROM_MIPSY_INST_GEN_PY) program_builder.hh
BUILT_SOURCES = \\
$(FROM_MIPSY_INST_GEN_PY) inst-nodes-gen.log \\
program_builder.hh
$(FROM_MIPSY_INST_GEN_PY): $(top_srcdir)/dev/inst-nodes-gen.py $(top_srcdir)/dev/mipsy.xml
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
touch $@
$(FROM_MIPSY_INST_GEN_PY): inst-nodes-gen.log
program_builder.hh: $(top_srcdir)/dev/inst-builder-gen.py $(top_srcdir)/dev/mipsy.xml
$(top_srcdir)/dev/inst-builder-gen.py < $(top_srcdir)/dev/mipsy.xml \
> $@
MAINTAINERCLEANFILES = $(FROM_MIPSY_INST_GEN_PY) program_builder.hh"""
MAINTAINERCLEANFILES = $(FROM_MIPSY_INST_GEN_PY) program_builder.hh
print """
noinst_LIBRARIES = libinst.a
libinst_a_SOURCES = \\
$(FROM_MIPSY_INST_GEN_PY) \\
register.hh \\
exp.hh \\
exp-visitor.hh \\
inst.hh \\
program.hh \\
label.hh label.cc \\
section.hh \\
text_section.hh \\
data_section.hh \\
program.hh \\
program_builder.hh program_builder.cc \\
program_solver.hh \\
libinst_a_SOURCES = \\
$(FROM_MIPSY_INST_GEN_PY) inst-nodes-gen.log \\
register.hh \\
exp.hh \\
exp-visitor.hh \\
inst.hh \\
program.hh \\
label.hh label.cc \\
section.hh \\
text_section.hh \\
data_section.hh \\
program.hh \\
program_builder.hh program_builder.cc \\
program_solver.hh \\
inst-tasks.hh inst-tasks.cc"""
......@@ -18,142 +18,206 @@
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
import sys
import string, re
import sys, os
import string
import mipsy
from mipsy import license, depth, define_id, class_id
#### Mipsy's instruction classes generator -----------------
#### Mipsy Instruction generator --------------------------
## Generate the class corresponding to an instruction
def class_generate(inst):
def header(inst):
type_map = {
"register": "Register&",
"immediate": "Exp&",
"label": "Exp&",
"address": "Register&"
}
print license
header_macro = "INST_" + define_id(inst.opcode) + "_HH"
print "#ifndef " + header_macro
print "# define " + header_macro
## Shortands
class_id = mipsy.class_id(inst.opcode)
define_id = mipsy.define_id(inst.opcode)
file_id = mipsy.file_id(inst.opcode)
banner = mipsy.license + "\n// Generated, do not edit by hand."
format = inst.format
## Open header, inline and implementation files
header = file(file_id + ".hh.tmp", "w")
inline = file(file_id + ".hxx.tmp", "w")
impl = file(file_id + ".cc.tmp", "w")
for f, ext, brief in [(header, "hh", "Declare the interface"),
(inline, "hxx", "Inline methods"),
(impl, "cc", "Implementation")]:
sys.stdout = f
print banner
# Document the file
print "/** \\file inst/" + file_id + "." + ext
print " \\brief " + brief + " of " + class_id + " */"
# Open multiple inclusion protection
if ext != "cc":
print "#ifndef INST_" + string.upper(inst.opcode + "_" + ext)
print "# define INST_" + string.upper(inst.opcode + "_" + ext)
sys.stdout = header
print """
#include \"inst/register.hh\"
#include \"inst/exp.hh\"
#include \"inst/inst.hh\"
#include \"inst/visitor.hh\"
# include \"inst/register.hh\"
# include \"inst/exp.hh\"
# include \"inst/inst.hh\"
# include \"inst/visitor.hh\"
"""
for f in [inline, impl]:
sys.stdout = f
print "#include \"inst/" + file_id + ".hh\""
# Open namespace
for f in [header, inline, impl]:
sys.stdout = f
print "\nnamespace inst\n{\n"
namespace inst
{
"""
## Declare class
print " class " + class_id(inst.opcode) + ":"
sys.stdout = header
print " /// Declare " + class_id + "."
print " /** " + inst.desc + " */"
print " class " + class_id + ":"
print " public Inst"
print " {"
format = inst.format
## Print ctor and dtor
print " public:"
proto = ""
# Constructor and destructor
args = ""
init = ""
dels = ""
for attribute in format.attributes:
proto = proto + attribute.type + "& " + attribute.name + ", "
init = init + attribute.name + "(" + attribute.name + "), "
proto = string.rstrip(proto, ", ")
args = args + attribute.type + "& " + attribute.name + ", "
init = init + attribute.name + "_(" + attribute.name + "), "
args = string.rstrip(args, ", ")
init = string.rstrip(init, ", ")
ctor = class_id(inst.opcode) + "(" + proto + ")"
if proto != "":
print " " + ctor + ":"
print " " + init
sys.stdout = header
print """ /** \\name Ctor & dtor.
\\{ */
public:"""
print " /// Construct a(n) " + class_id + " node."
print " " + class_id + "(" + args + ");"
print " /// Destroy a(n) " + class_id + " node."
print " virtual ~" + class_id + "();"
print " /** \\} */"
sys.stdout = inline
print " inline"
if args == "":
print " " + class_id + "::" + class_id + "()"
else:
print " " + ctor
print " {"
print " }"
print " virtual ~" + class_id(inst.opcode) + "()"
print " {"
print " }"
## Methods: accessors
print " " + class_id + "::" + class_id + "(" + args + ")" + ":"
print " " + init
print " {}\n"
sys.stdout = impl
print " " + class_id + "::~" + class_id + "()"
print " {}\n"
# Methods: accessors
sys.stdout = header
print """
/** \\name Accessors.
\\{ */
public:"""
for attribute in format.attributes:
type = attribute.type
print " const " + type + "&\t\tget_" + attribute.name + " () const"
print " {"
print " return " + attribute.name + ";"
print " }"
if type != "int":
print " " + type + "&\t\tget_" + attribute.name + " ()"
print " {"
print " return " + attribute.name + ";"
print " }"
## Method: visitor entry point
for c in ["const ", ""]:
sys.stdout = header
print " /// Return " + string.lower (attribute.name)
print " " + c + attribute.type + \
" &\t\tget_" + attribute.name + "() " + c + ";"
sys.stdout = inline
print " inline"
print " " + c + attribute.type + " &"
print " " + class_id + "::get_" + attribute.name + "() " + c
print " {"
print " return " + attribute.name + "_;"
print " }"
sys.stdout = header
print " /** \\} */"
# Method: visitor entry point
sys.stdout = inline
print ""
sys.stdout = impl
print " void"
print " " + class_id + "::accept (ConstVisitor& v) const"
print """ {
v.visit(*this);
}"""
print " void"
print " " + class_id + "::accept (Visitor& v)"
print """ {
v.visit(*this);
}"""
sys.stdout = header
print """
/** \\name Visitors entry point.
\\{ */
public:
virtual void accept (ConstVisitor& v) const
{
v.visit(*this);
}
virtual void accept (Visitor& v)
{
v.visit(*this);
}"""
/// Accept a const visitor \\a v.
virtual void accept(ConstVisitor& v) const;
/// Accept a non-const visitor \\a v.
virtual void accept(Visitor& v);
/** \\} */
"""
## Method: print
# Method: print
sys.stdout = header
print """ public:
/// Print this
virtual void\tprint(std::ostream &ostr) const;
"""
sys.stdout = impl
print """
public:
virtual void print(std::ostream& ostr) const
{"""
void"""
print " " + class_id + "::print(std::ostream &ostr) const"
print " {"
s = ""
i = 0
while i < len(format.attributes):
for i, v in enumerate(format.attributes):
if (i < len(format.attributes) - 1) and \
(format.attributes[i].type == "Exp") and \
(format.attributes[i + 1].type == "Register"):
s = s + " << " + format.attributes[i].name + \
" << '(' << " + format.attributes[i + 1].name + " << ')' "
i = i + 1
s = s + " << " + format.attributes[i].name + "_" + \
" << '(' << " + format.attributes[i + 1].name + "_ << ')' "
else:
s = s + " << " + format.attributes[i].name + " << \", \""
i = i + 1
s = s + " << " + format.attributes[i].name + "_ << \", \""
s = string.rstrip(s, "<< \", \"")
print " ostr << \"" + inst.opcode + "\\t\"" + s + ";"
print " }"
## Print attributes
print " protected:"
for attribute in format.attributes:
print " " + attribute.type + "&\t\t" + attribute.name + ";"
print " ostr << \"" + inst.opcode + "\\t\"" + s + ";"
print " }"
# Declare attributes
sys.stdout = header
if len(format.attributes) > 0:
print " protected:"
for attribute in format.attributes:
id = attribute.name + "_"
print " " + attribute.type + "\t&" + id + ";"
# End of declaration
print " };"
print """
} // namespace inst
"""
print "#endif // !" + header_macro
#### -------------------------------------------------------
## Close files
for f, ext in [(header, "hh"), (inline, "hxx"), (impl, "cc")]:
# Close namespace and inclusion protection system
sys.stdout = f
print "\n} // namespace inst"
if ext != "cc":
if ext == "hh":
print "\n# include \"inst/" + file_id + ".hxx\""
print "\n#endif // !INST_" + string.upper(inst.opcode + "_" + ext)
# Check differences between old and new files
sys.stdout = sys.__stdout__
f.close()
mipsy.lazy_overwrite(file_id + "." + ext, file_id + "." + ext + ".tmp")
os.remove(file_id + "." + ext + ".tmp")
## Main --------------------------------
parser = mipsy.InstructionSetParser()
instructions = parser.parse(sys.stdin)
## Generate headers --------------------
## Generate classes files
for inst in instructions:
if inst.level == "native":
sys.stdout = open(inst.opcode + ".hh", "w")
header(inst)
class_generate(inst)
## Generate all-includer ---------------
## Generate all-includer
sys.stdout = open("all.hh", "w")
print license
print mipsy.license
print "#ifndef INST_ALL_HH"
print "# define INST_ALL_HH"
for inst in instructions:
......@@ -162,9 +226,9 @@ for inst in instructions:
print "#endif // !INST_ALL_HH"
## Generate all-declarator -------------
## Generate all-declarator
sys.stdout = open("decl.hh", "w")
print license
print mipsy.license
print "#ifndef INST_DECL_HH"
print "# define INST_DECL_HH"
print """
......@@ -173,7 +237,7 @@ namespace inst
"""
for inst in instructions:
if inst.level == "native":
print " class " + class_id(inst.opcode) + ";"
print " class " + mipsy.class_id(inst.opcode) + ";"
print """
} // namespace inst
......@@ -181,9 +245,9 @@ print """
"""
## Generate visitor -----------
## Generate visitor
sys.stdout = open("visitor.hh", "w")
print license
print mipsy.license
print """#ifndef INST_VISITOR_HH
# define INST_VISITOR_HH
......@@ -207,7 +271,7 @@ namespace inst
for inst in instructions:
if inst.level == "native":
print " virtual void\tvisit(typename select_const<K, " \
+ class_id(inst.opcode) + ">::t&) = 0;"
+ mipsy.class_id(inst.opcode) + ">::t&) = 0;"
print """
};
......
......@@ -2,29 +2,32 @@
(Created-By-Prcs-Version 1 3 2)
(Project-Description "")
(Project-Version mipsy 0 62)
(Parent-Version mipsy 0 61)
(Project-Version mipsy 0 63)
(Parent-Version mipsy 0 62)
(Version-Log
"Index: ChangeLog
--- ChangeLog Sat, 10 Jan 2004 22:25:29 +0100 noe (mipsy/2_ChangeLog 1.55 604)
+++ ChangeLog Sat, 10 Jan 2004 22:31:04 +0100 noe (mipsy/2_ChangeLog 1.55 604)
@@ -1,5 +1,10 @@
--- ChangeLog Sat, 10 Jan 2004 22:32:29 +0100 noe (mipsy/2_ChangeLog 1.56 604)
+++ ChangeLog Sat, 10 Jan 2004 23:23:14 +0100 noe (mipsy/2_ChangeLog 1.56 604)
@@ -1,5 +1,13 @@
2004-01-10 Benot Perrot <benoit@lrde.epita.fr>
+ * dev/mipsy.xml, dev/parse-asm-parse-gen.py:
+ Use human readable identifiers to locate tokens.
+
+ * dev/inst-nodes-gen.py: Generate interface of classes in
+ .hh files, inline methods in .hxx files, implementation in .cc.
+ * dev/inst-makefile-gen.py:
+ Distribute .hh, .hxx, .cc files of each class.
+ Use a stamp file to avoid useness launching of generators.
+
+2004-01-10 Benot Perrot <benoit@lrde.epita.fr>
+
* dev/mipsy.xml: Use a better DTD.
* dev/mipsy.py: Use new DTD.
* dev/inst-builder-gen.py,
* dev/mipsy.xml, dev/parse-asm-parse-gen.py:
Use human readable identifiers to locate tokens.
")
(New-Version-Log
"")
(Checkin-Time "Sat, 10 Jan 2004 22:32:29 +0100")
(Checkin-Time "Sat, 10 Jan 2004 23:58:50 +0100")
(Checkin-Login noe)
(Files
......@@ -32,7 +35,7 @@
;; ./
(AUTHORS (mipsy/0_AUTHORS 1.1 604))
(COPYING (mipsy/1_COPYING 1.1 604))
(ChangeLog (mipsy/2_ChangeLog 1.56 604))
(ChangeLog (mipsy/2_ChangeLog 1.57 604))
(Makefile.am (mipsy/3_Makefile.a 1.7 604))
(NEWS (mipsy/b/25_NEWS 1.5 604))
(README (mipsy/4_README 1.2 604))
......@@ -46,8 +49,8 @@
;; ./dev/
(dev/inst-builder-gen.py (mipsy/15_mipsy-buil 1.7 705))
(dev/inst-makefile-gen.py (mipsy/b/15_mipsy-mk-i 1.4 705))
(dev/inst-nodes-gen.py (mipsy/12_mipsy-inst 1.4 705))
(dev/inst-makefile-gen.py (mipsy/b/15_mipsy-mk-i 1.5 705))
(dev/inst-nodes-gen.py (mipsy/12_mipsy-inst 1.5 705))
(dev/mipsy.py (mipsy/16_mipsy.py 1.7 705))
(dev/mipsy.xml (mipsy/17_mipsy.xml 1.13 604))
(dev/parse-asm-parse-gen.py (mipsy/13_mipsy-pars 1.7 705))
......
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