Commit bce877f2 authored by Etienne Renault's avatar Etienne Renault

Provide support for python 3.

* build-aux/gitlog-to-changelog,
dev/nolimips.py,
doc/inst-set.texi.gen.py,
src/inst/nodes.gen.py,
src/inst/nodes.mk.gen.py,
src/inst/program_builder.hh.gen.py,
src/inst/program_solver.gen.py,
src/parse/asm-parse.yy.gen.py,
src/parse/asm-scan.ll.gen.py: here.
parent eec6f00c
......@@ -3,13 +3,13 @@ eval '(exit $?0)' && eval 'exec perl -wS "$0" ${1+"$@"}'
if 0;
# Convert git log output to ChangeLog format.
my $VERSION = '2012-07-29 06:11'; # UTC
my $VERSION = '2015-06-11 01:03'; # UTC
# The definition above must lie within the first 8 lines in order
# for the Emacs time-stamp write hook (at end) to update it.
# If you change this file with Emacs, please let the write hook
# do its job. Otherwise, update this string manually.
# Copyright (C) 2008-2013 Free Software Foundation, Inc.
# Copyright (C) 2008-2015 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -72,6 +72,9 @@ OPTIONS:
directory can be derived.
--since=DATE convert only the logs since DATE;
the default is to convert all log entries.
--until=DATE convert only the logs older than DATE.
--ignore-matching=PAT ignore commit messages whose first lines match PAT.
--ignore-line=PAT ignore lines of commit messages that match PAT.
--format=FMT set format string for commit subject and body;
see 'man git-log' for the list of format metacharacters;
the default is '%s%n%b%n'
......@@ -220,10 +223,13 @@ sub git_dir_option($)
{
my $since_date;
my $until_date;
my $format_string = '%s%n%b%n';
my $amend_file;
my $append_dot = 0;
my $cluster = 1;
my $ignore_matching;
my $ignore_line;
my $strip_tab = 0;
my $strip_cherry_pick = 0;
my $srcdir;
......@@ -232,10 +238,13 @@ sub git_dir_option($)
help => sub { usage 0 },
version => sub { print "$ME version $VERSION\n"; exit },
'since=s' => \$since_date,
'until=s' => \$until_date,
'format=s' => \$format_string,
'amend=s' => \$amend_file,
'append-dot' => \$append_dot,
'cluster!' => \$cluster,
'ignore-matching=s' => \$ignore_matching,
'ignore-line=s' => \$ignore_line,
'strip-tab' => \$strip_tab,
'strip-cherry-pick' => \$strip_cherry_pick,
'srcdir=s' => \$srcdir,
......@@ -243,6 +252,8 @@ sub git_dir_option($)
defined $since_date
and unshift @ARGV, "--since=$since_date";
defined $until_date
and unshift @ARGV, "--until=$until_date";
# This is a hash that maps an SHA1 to perl code (i.e., s/old/new/)
# that makes a correction in the log or attribution of that commit.
......@@ -259,6 +270,7 @@ sub git_dir_option($)
my $prev_multi_paragraph;
my $prev_date_line = '';
my @prev_coauthors = ();
my @skipshas = ();
while (1)
{
defined (my $in = <PIPE>)
......@@ -279,6 +291,21 @@ sub git_dir_option($)
$sha =~ /^[0-9a-fA-F]{40}$/
or die "$ME:$.: invalid SHA1: $sha\n";
my $skipflag = 0;
if (@skipshas)
{
foreach(@skipshas)
{
if ($sha =~ /^$_/)
{
$skipflag = 1;
## Perhaps only warn if a pattern matches more than once?
warn "$ME: warning: skipping $sha due to $_\n";
last;
}
}
}
# If this commit's log requires any transformation, do it now.
my $code = $amend_code->{$sha};
if (defined $code)
......@@ -306,7 +333,7 @@ sub git_dir_option($)
$rest =~ s/^\s*\(cherry picked from commit [\da-f]+\)\n//m;
}
my @line = split "\n", $rest;
my @line = split /[ \t]*\n/, $rest;
my $author_line = shift @line;
defined $author_line
or die "$ME:$.: unexpected EOF\n";
......@@ -316,17 +343,18 @@ sub git_dir_option($)
# Format 'Copyright-paperwork-exempt: Yes' as a standard ChangeLog
# `(tiny change)' annotation.
my $tiny = (grep (/^Copyright-paperwork-exempt:\s+[Yy]es$/, @line)
my $tiny = (grep (/^(?:Copyright-paperwork-exempt|Tiny-change):\s+[Yy]es$/, @line)
? ' (tiny change)' : '');
my $date_line = sprintf "%s %s$tiny\n",
strftime ("%F", localtime ($1)), $2;
strftime ("%Y-%m-%d", localtime ($1)), $2;
my @coauthors = grep /^Co-authored-by:.*$/, @line;
# Omit meta-data lines we've already interpreted.
@line = grep !/^(?:Signed-off-by:[ ].*>$
|Co-authored-by:[ ]
|Copyright-paperwork-exempt:[ ]
|Tiny-change:[ ]
)/x, @line;
# Remove leading and trailing blank lines.
......@@ -336,6 +364,37 @@ sub git_dir_option($)
while ($line[$#line] =~ /^\s*$/) { pop @line; }
}
# Handle Emacs gitmerge.el "skipped" commits.
# Yes, this should be controlled by an option. So sue me.
if ( grep /^(; )?Merge from /, @line )
{
my $found = 0;
foreach (@line)
{
if (grep /^The following commit.*skipped:$/, $_)
{
$found = 1;
## Reset at each merge to reduce chance of false matches.
@skipshas = ();
next;
}
if ($found && $_ =~ /^([0-9a-fA-F]{7,}) [^ ]/)
{
push ( @skipshas, $1 );
}
}
}
# Ignore commits that match the --ignore-matching pattern, if specified.
if (! ($skipflag || (defined $ignore_matching
&& @line && $line[0] =~ /$ignore_matching/)))
{
if (defined $ignore_line && @line)
{
@line = grep ! /$ignore_line/, @line;
while ($line[$#line] =~ /^\s*$/) { pop @line; }
}
# Record whether there are two or more paragraphs.
my $multi_paragraph = grep /^\s*$/, @line;
......@@ -352,7 +411,7 @@ sub git_dir_option($)
}
# If clustering of commit messages has been disabled, if this header
# would be different from the previous date/name/email/coauthors header,
# would be different from the previous date/name/etc. header,
# or if this or the previous entry consists of two or more paragraphs,
# then print the header.
if ( ! $cluster
......@@ -399,6 +458,7 @@ sub git_dir_option($)
print "\n", join ("\n", @line), "\n";
}
}
defined ($in = <PIPE>)
or last;
......
#!/usr/bin/env python
##
## This file is part of Nolimips, a MIPS simulator with unlimited registers
## Copyright (C) 2003, 2004, 2005, 2006 Benoit Perrot <benoit@lrde.epita.fr>
## Copyright (C) 2003, 2004, 2005, 2006, 2015 Benoit Perrot <benoit@lrde.epita.fr>
##
## Nolimips is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
......@@ -64,12 +64,12 @@ def depth(root):
def lazy_overwrite(ref, new):
if not os.path.isfile(ref) or \
not filecmp.cmp(ref, new):
print "> Overwrite: " + ref
print ("> Overwrite: " + ref)
shutil.copy(new, ref)
## Return a conventional macro identifier
def define_id(s):
return string.upper(s)
return s.upper()
## Return a conventional C++ class identifier
def class_id(s):
......@@ -81,7 +81,7 @@ def class_id(s):
for i in range(0, len(s)):
if s[i] in string.ascii_letters or s[i] in string.digits:
if non_ascii:
res = res + string.upper(s[i])
res = res + s[i].upper()
non_ascii = False
else:
res = res + s[i]
......@@ -91,11 +91,11 @@ def class_id(s):
## Return a conventional file name
def file_id(s):
return string.lower(s)
return s.lower()
## Return a valid C++ variable name
def var_id(s):
s = string.lower(s)
s = s.lower()#string.lower(s)
if s in ["and", "or", "xor"]:
s = s + "_";
return s
......@@ -294,7 +294,7 @@ class InstructionSetHandler(ContentHandler):
elif name == "format":
self.format_b = FormatBuilder()
if attrs.has_key("type"):
if attrs.__contains__("type"):
self.format_b.type = attrs["type"]
elif name == "predefinedAttributes":
self.format_b = FormatBuilder()
......@@ -302,24 +302,24 @@ class InstructionSetHandler(ContentHandler):
elif name == "attribute":
self.attr_b.reset()
self.attr_b.type = attrs["type"]
if attrs.has_key("restriction"):
if attrs.__contains__("restriction"):
self.attr_b.restriction = attrs["restriction"]
self.attr_b.name = attrs["name"]
elif name == "syntax":
self.syntax_b.reset()
if attrs.has_key("alias"):
if attrs.__contains__("alias"):
self.syntax_b.alias = attrs["alias"]
if attrs.has_key("level"):
if attrs.__contains__("level"):
self.syntax_b.level = attrs["level"]
else:
self.syntax_b.level = self.inst_b.level
elif name == "predefinedSyntax":
alias = ""
if attrs.has_key("alias"):
if attrs.__contains__("alias"):
alias = attrs["alias"]
level = ""
if attrs.has_key("level"):
if attrs.__contains__("level"):
level = attrs["level"]
else:
level = self.inst_b.level
......@@ -327,11 +327,11 @@ class InstructionSetHandler(ContentHandler):
elif name == "token":
self.token_b.reset()
self.token_b.kind = attrs["kind"]
if attrs.has_key("name"):
if attrs.__contains__("name"):
self.token_b.name = attrs["name"]
if attrs.has_key("default"):
if attrs.__contains__("default"):
self.token_b.default = attrs["default"]
if attrs.has_key("value"):
if attrs.__contains__("value"):
self.token_b.value = attrs["value"]
def endElement(self, name):
......
#!/usr/bin/env python
##
## This file is part of Nolimips, a MIPS simulator with unlimited registers
## Copyright (C) 2003, 2004 Benoit Perrot <benoit@lrde.epita.fr>
## Copyright (C) 2003, 2004, 2015 Benoit Perrot <benoit@lrde.epita.fr>
##
## Nolimips is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
......@@ -25,43 +25,43 @@ import nolimips
#### Nolimips' instruction set texi generator --------------
if __name__ != "__main__" or len(sys.argv) != 2:
print "Usage: .. SRCDIR"
print ("Usage: .. SRCDIR")
sys.exit(1)
srcdir = sys.argv[1]
parser = nolimips.InstructionSetParser()
instructions = parser.parse(sys.stdin)
sys.stdout = file("inst-set.texi.tmp", "w")
sys.stdout = open("inst-set.texi.tmp", "w")
print """@comment Generated, do not edit by hand.
print ("""@comment Generated, do not edit by hand.
@node The Nolimips supported instruction set
@section The Nolimips supported instruction set"""
@section The Nolimips supported instruction set""")
## Menu
print "@menu"
print ("@menu")
kind = ""
for inst in instructions:
if kind != inst.kind:
kind = inst.kind
print "* " + string.capwords(kind) + " instructions ::"
print "@end menu"
print ("* " + string.capwords(kind) + " instructions ::")
print ("@end menu")
## Subsections
kind = ""
for inst in instructions:
if kind != inst.kind:
kind = inst.kind
print "@node " + string.capwords(kind) + " instructions"
print "@subsection " + string.capwords(kind) + " instructions"
print ("@node " + string.capwords(kind) + " instructions")
print ("@subsection " + string.capwords(kind) + " instructions")
desc = string.replace(inst.desc, "\n", " ")
desc = string.replace(desc, " ", " ")
desc = inst.desc.replace("\n", " ")
desc = desc.replace(" ", " ")
print "@subsubsection " + string.upper(inst.opcode)
print "@findex " + string.upper(inst.opcode)
print desc
print ("@subsubsection " + inst.opcode.upper())
print ("@findex " + inst.opcode.upper())
print (desc)
## Epilogue
sys.stdout.close()
......
#!/usr/bin/env python
##
## This file is part of Nolimips, a MIPS simulator with unlimited registers
## Copyright (C) 2003, 2004, 2006 Benoit Perrot <benoit@lrde.epita.fr>
## Copyright (C) 2003, 2004, 2006, 2015 Benoit Perrot <benoit@lrde.epita.fr>
##
## Nolimips is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
......@@ -25,7 +25,7 @@ import nolimips
#### Nolimips' instruction classes generator ---------------
if __name__ != "__main__" or len(sys.argv) != 2:
print "Usage: .. SRCDIR"
print ("Usage: .. SRCDIR")
sys.exit(1)
srcdir = sys.argv[1]
......@@ -46,51 +46,50 @@ def class_generate(inst):
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")
header = open(file_id + ".hh.tmp", "w")
inline = open(file_id + ".hxx.tmp", "w")
impl = open(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
print (banner)
# Document the file
print "/** \\file inst/" + file_id + "." + ext
print " \\brief " + brief + " of " + class_id + " */"
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)
print ("#ifndef INST_" + (inst.opcode + "_" + ext).upper())
print ("# define INST_" + (inst.opcode + "_" + ext).upper())
sys.stdout = header
print """
# include \"inst/register.hh\"
# include \"inst/exp.hh\"
# include \"inst/inst.hh\""""
print ("# include \"inst/register.hh\"")
print ("# include \"inst/exp.hh\"")
print ("# include \"inst/inst.hh\"")
sys.stdout = impl
print "#include \"inst/visitor.hh\""
print ("#include \"inst/visitor.hh\"")
for f in [inline, impl]:
sys.stdout = f
print "#include \"inst/" + file_id + ".hh\""
print ("#include \"inst/" + file_id + ".hh\"")
# Open namespace
for f in [header, inline, impl]:
sys.stdout = f
print """
print ("""
namespace inst
{
"""
""")
## Declare class
sys.stdout = header
print " /// Declare " + class_id + "."
print " /** " + inst.desc + " */"
print " class " + class_id + ":"
print " public Inst"
print " {"
print (" /// Declare " + class_id + ".")
print (" /** " + inst.desc + " */")
print (" class " + class_id + ":")
print (" public Inst")
print (" {")
# Constructor and destructor
args = ""
......@@ -106,76 +105,76 @@ namespace inst
args = args + attribute.type + " *"
args = args + attribute.name + ", "
init = init + attribute.name + "_(" + attribute.name + "), "
args = string.rstrip(args, ", ")
init = string.rstrip(init, ", ")
args = args.rstrip(", ")
init = init.rstrip(", ")
sys.stdout = header
print """ /** \\name Ctor & dtor.
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 " /** \\} */"
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"
print " " + class_id + "::" + class_id + "(" + args + ")" + ":"
print (" inline")
print (" " + class_id + "::" + class_id + "(" + args + ")" + ":")
if init == "":
print " Inst(" + format_type_to_enum[format.type] + ")"
print (" Inst(" + format_type_to_enum[format.type] + ")")
else:
print " Inst(" + format_type_to_enum[format.type] + "),"
print " " + init
print " {}\n"
print (" Inst(" + format_type_to_enum[format.type] + "),")
print (" " + init)
print (" {}\n")
sys.stdout = impl
print " " + class_id + "::~" + class_id + "()"
print " {"
print (" " + class_id + "::~" + class_id + "()")
print (" {")
for attribute in format.attributes:
# FIXME: there should be some preconditions
if attribute.type != "Register" and attribute.type != "Exp":
print " delete " + attribute.name + "_;"
print " }\n"
print (" delete " + attribute.name + "_;")
print (" }\n")
# Methods: accessors
sys.stdout = header
print """
print ("""
/** \\name Accessors.
\\{ */
public:"""
public:""")
for attribute in format.attributes:
for c in ["const ", ""]:
sys.stdout = header
print " /// Return " + string.lower (attribute.name)
print " " + c + attribute.type + \
" &\t\tget_" + attribute.name + "() " + c + ";"
print (" /// Return " + (attribute.name).lower())
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 (" inline")
print (" " + c + attribute.type + " &")
print (" " + class_id + "::get_" + attribute.name + "() " + c)
print (" {")
if attribute.type == "Register":
print " return " + attribute.name + "_;"
print (" return " + attribute.name + "_;")
else:
print " return *" + attribute.name + "_;"
print " }"
print (" return *" + attribute.name + "_;")
print (" }")
sys.stdout = header
print " /** \\} */"
print (" /** \\} */")
# Method: visitor entry point
sys.stdout = inline
print ""
print ("")
sys.stdout = impl
print " void"
print " " + class_id + "::accept (ConstVisitor& v) const"
print """ {
print (" void")
print (" " + class_id + "::accept (ConstVisitor& v) const")
print (""" {
v.visit(*this);
}"""
print " void"
print " " + class_id + "::accept (Visitor& v)"
print """ {
}""")
print (" void")
print (" " + class_id + "::accept (Visitor& v)")
print (""" {
v.visit(*this);
}"""
}""")
sys.stdout = header
print """
print ("""
/** \\name Visitors entry point.
\\{ */
public:
......@@ -184,19 +183,19 @@ namespace inst
/// Accept a non-const visitor \\a v.
virtual void accept(Visitor& v);
/** \\} */
"""
""")
# Method: print
sys.stdout = header
print """ public:
print (""" public:
/// Print this
virtual void\twrite(std::ostream &ostr) const;
"""
""")
sys.stdout = impl
print """
void"""
print " " + class_id + "::write(std::ostream &ostr) const"
print " {"
print ("""
void""")
print (" " + class_id + "::write(std::ostream &ostr) const")
print (" {")
s = ""
i = 0
while i < len(format.attributes):
......@@ -212,36 +211,36 @@ namespace inst
s = s + "*"
s = s + format.attributes[i].name + "_ << \", \""
i = i + 1
s = string.rstrip(s, "<< \", \"")
print " ostr << \"" + inst.opcode + "\\t\"" + s + ";"
print " }"
s = s.rstrip("<< \", \"")
print (" ostr << \"" + inst.opcode + "\\t\"" + s + ";")
print (" }")
# Declare attributes
sys.stdout = header
if len(format.attributes) > 0:
print " protected:"
print (" protected:")
for attribute in format.attributes:
id = attribute.name + "_"
if attribute.type == "Register":
print " " + attribute.type + "\t" + id + ";"
print (" " + attribute.type + "\t" + id + ";")
elif attribute.type == "Exp":
print " CountedExp\t" + id + ";"
print (" CountedExp\t" + id + ";")
else:
print " " + attribute.type + "\t*" + id + ";"
print (" " + attribute.type + "\t*" + id + ";")
# End of declaration
print " };"
print (" };")
## 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"
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)
print ("\n# include \"inst/" + file_id + ".hxx\"")
print ("\n#endif // !INST_" + (inst.opcode + "_" + ext).upper())
# Check differences between old and new files
sys.stdout = sys.__stdout__
f.close()
......@@ -259,25 +258,25 @@ for inst in instructions:
class_generate(inst)
## Generate all-includer
sys.stdout = file("all.hh.tmp", "w")