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+"$@"}' ...@@ -3,13 +3,13 @@ eval '(exit $?0)' && eval 'exec perl -wS "$0" ${1+"$@"}'
if 0; if 0;
# Convert git log output to ChangeLog format. # 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 # The definition above must lie within the first 8 lines in order
# for the Emacs time-stamp write hook (at end) to update it. # for the Emacs time-stamp write hook (at end) to update it.
# If you change this file with Emacs, please let the write hook # If you change this file with Emacs, please let the write hook
# do its job. Otherwise, update this string manually. # 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 # 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 # it under the terms of the GNU General Public License as published by
...@@ -72,6 +72,9 @@ OPTIONS: ...@@ -72,6 +72,9 @@ OPTIONS:
directory can be derived. directory can be derived.
--since=DATE convert only the logs since DATE; --since=DATE convert only the logs since DATE;
the default is to convert all log entries. 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; --format=FMT set format string for commit subject and body;
see 'man git-log' for the list of format metacharacters; see 'man git-log' for the list of format metacharacters;
the default is '%s%n%b%n' the default is '%s%n%b%n'
...@@ -220,10 +223,13 @@ sub git_dir_option($) ...@@ -220,10 +223,13 @@ sub git_dir_option($)
{ {
my $since_date; my $since_date;
my $until_date;
my $format_string = '%s%n%b%n'; my $format_string = '%s%n%b%n';
my $amend_file; my $amend_file;
my $append_dot = 0; my $append_dot = 0;
my $cluster = 1; my $cluster = 1;
my $ignore_matching;
my $ignore_line;
my $strip_tab = 0; my $strip_tab = 0;
my $strip_cherry_pick = 0; my $strip_cherry_pick = 0;
my $srcdir; my $srcdir;
...@@ -232,10 +238,13 @@ sub git_dir_option($) ...@@ -232,10 +238,13 @@ sub git_dir_option($)
help => sub { usage 0 }, help => sub { usage 0 },
version => sub { print "$ME version $VERSION\n"; exit }, version => sub { print "$ME version $VERSION\n"; exit },
'since=s' => \$since_date, 'since=s' => \$since_date,
'until=s' => \$until_date,
'format=s' => \$format_string, 'format=s' => \$format_string,
'amend=s' => \$amend_file, 'amend=s' => \$amend_file,
'append-dot' => \$append_dot, 'append-dot' => \$append_dot,
'cluster!' => \$cluster, 'cluster!' => \$cluster,
'ignore-matching=s' => \$ignore_matching,
'ignore-line=s' => \$ignore_line,
'strip-tab' => \$strip_tab, 'strip-tab' => \$strip_tab,
'strip-cherry-pick' => \$strip_cherry_pick, 'strip-cherry-pick' => \$strip_cherry_pick,
'srcdir=s' => \$srcdir, 'srcdir=s' => \$srcdir,
...@@ -243,6 +252,8 @@ sub git_dir_option($) ...@@ -243,6 +252,8 @@ sub git_dir_option($)
defined $since_date defined $since_date
and unshift @ARGV, "--since=$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/) # 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. # that makes a correction in the log or attribution of that commit.
...@@ -259,6 +270,7 @@ sub git_dir_option($) ...@@ -259,6 +270,7 @@ sub git_dir_option($)
my $prev_multi_paragraph; my $prev_multi_paragraph;
my $prev_date_line = ''; my $prev_date_line = '';
my @prev_coauthors = (); my @prev_coauthors = ();
my @skipshas = ();
while (1) while (1)
{ {
defined (my $in = <PIPE>) defined (my $in = <PIPE>)
...@@ -279,6 +291,21 @@ sub git_dir_option($) ...@@ -279,6 +291,21 @@ sub git_dir_option($)
$sha =~ /^[0-9a-fA-F]{40}$/ $sha =~ /^[0-9a-fA-F]{40}$/
or die "$ME:$.: invalid SHA1: $sha\n"; 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. # If this commit's log requires any transformation, do it now.
my $code = $amend_code->{$sha}; my $code = $amend_code->{$sha};
if (defined $code) if (defined $code)
...@@ -306,7 +333,7 @@ sub git_dir_option($) ...@@ -306,7 +333,7 @@ sub git_dir_option($)
$rest =~ s/^\s*\(cherry picked from commit [\da-f]+\)\n//m; $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; my $author_line = shift @line;
defined $author_line defined $author_line
or die "$ME:$.: unexpected EOF\n"; or die "$ME:$.: unexpected EOF\n";
...@@ -316,17 +343,18 @@ sub git_dir_option($) ...@@ -316,17 +343,18 @@ sub git_dir_option($)
# Format 'Copyright-paperwork-exempt: Yes' as a standard ChangeLog # Format 'Copyright-paperwork-exempt: Yes' as a standard ChangeLog
# `(tiny change)' annotation. # `(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)' : ''); ? ' (tiny change)' : '');
my $date_line = sprintf "%s %s$tiny\n", 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; my @coauthors = grep /^Co-authored-by:.*$/, @line;
# Omit meta-data lines we've already interpreted. # Omit meta-data lines we've already interpreted.
@line = grep !/^(?:Signed-off-by:[ ].*>$ @line = grep !/^(?:Signed-off-by:[ ].*>$
|Co-authored-by:[ ] |Co-authored-by:[ ]
|Copyright-paperwork-exempt:[ ] |Copyright-paperwork-exempt:[ ]
|Tiny-change:[ ]
)/x, @line; )/x, @line;
# Remove leading and trailing blank lines. # Remove leading and trailing blank lines.
...@@ -336,68 +364,100 @@ sub git_dir_option($) ...@@ -336,68 +364,100 @@ sub git_dir_option($)
while ($line[$#line] =~ /^\s*$/) { pop @line; } while ($line[$#line] =~ /^\s*$/) { pop @line; }
} }
# Record whether there are two or more paragraphs. # Handle Emacs gitmerge.el "skipped" commits.
my $multi_paragraph = grep /^\s*$/, @line; # Yes, this should be controlled by an option. So sue me.
if ( grep /^(; )?Merge from /, @line )
# Format 'Co-authored-by: A U Thor <email@example.com>' lines in {
# standard multi-author ChangeLog format. my $found = 0;
for (@coauthors) 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/)))
{ {
s/^Co-authored-by:\s*/\t /; if (defined $ignore_line && @line)
s/\s*</ </; {
@line = grep ! /$ignore_line/, @line;
while ($line[$#line] =~ /^\s*$/) { pop @line; }
}
/<.*?@.*\..*>/ # Record whether there are two or more paragraphs.
or warn "$ME: warning: missing email address for " my $multi_paragraph = grep /^\s*$/, @line;
. substr ($_, 5) . "\n";
}
# If clustering of commit messages has been disabled, if this header # Format 'Co-authored-by: A U Thor <email@example.com>' lines in
# would be different from the previous date/name/email/coauthors header, # standard multi-author ChangeLog format.
# or if this or the previous entry consists of two or more paragraphs, for (@coauthors)
# then print the header. {
if ( ! $cluster s/^Co-authored-by:\s*/\t /;
|| $date_line ne $prev_date_line s/\s*</ </;
|| "@coauthors" ne "@prev_coauthors"
|| $multi_paragraph
|| $prev_multi_paragraph)
{
$prev_date_line eq ''
or print "\n";
print $date_line;
@coauthors
and print join ("\n", @coauthors), "\n";
}
$prev_date_line = $date_line;
@prev_coauthors = @coauthors;
$prev_multi_paragraph = $multi_paragraph;
# If there were any lines /<.*?@.*\..*>/
if (@line == 0) or warn "$ME: warning: missing email address for "
{ . substr ($_, 5) . "\n";
warn "$ME: warning: empty commit message:\n $date_line\n"; }
}
else # If clustering of commit messages has been disabled, if this header
{ # would be different from the previous date/name/etc. header,
if ($append_dot) # or if this or the previous entry consists of two or more paragraphs,
# then print the header.
if ( ! $cluster
|| $date_line ne $prev_date_line
|| "@coauthors" ne "@prev_coauthors"
|| $multi_paragraph
|| $prev_multi_paragraph)
{ {
# If the first line of the message has enough room, then $prev_date_line eq ''
if (length $line[0] < 72) or print "\n";
print $date_line;
@coauthors
and print join ("\n", @coauthors), "\n";
}
$prev_date_line = $date_line;
@prev_coauthors = @coauthors;
$prev_multi_paragraph = $multi_paragraph;
# If there were any lines
if (@line == 0)
{
warn "$ME: warning: empty commit message:\n $date_line\n";
}
else
{
if ($append_dot)
{ {
# append a dot if there is no other punctuation or blank # If the first line of the message has enough room, then
# at the end. if (length $line[0] < 72)
$line[0] =~ /[[:punct:]\s]$/ {
or $line[0] .= '.'; # append a dot if there is no other punctuation or blank
# at the end.
$line[0] =~ /[[:punct:]\s]$/
or $line[0] .= '.';
}
} }
}
# Remove one additional leading TAB from each line. # Remove one additional leading TAB from each line.
$strip_tab $strip_tab
and map { s/^\t// } @line; and map { s/^\t// } @line;
# Prefix each non-empty line with a TAB. # Prefix each non-empty line with a TAB.
@line = map { length $_ ? "\t$_" : '' } @line; @line = map { length $_ ? "\t$_" : '' } @line;
print "\n", join ("\n", @line), "\n"; print "\n", join ("\n", @line), "\n";
}
} }
defined ($in = <PIPE>) defined ($in = <PIPE>)
......
#!/usr/bin/env python #!/usr/bin/env python
## ##
## This file is part of Nolimips, a MIPS simulator with unlimited registers ## 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 ## Nolimips is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by ## it under the terms of the GNU General Public License as published by
...@@ -64,12 +64,12 @@ def depth(root): ...@@ -64,12 +64,12 @@ def depth(root):
def lazy_overwrite(ref, new): def lazy_overwrite(ref, new):
if not os.path.isfile(ref) or \ if not os.path.isfile(ref) or \
not filecmp.cmp(ref, new): not filecmp.cmp(ref, new):
print "> Overwrite: " + ref print ("> Overwrite: " + ref)
shutil.copy(new, ref) shutil.copy(new, ref)
## Return a conventional macro identifier ## Return a conventional macro identifier
def define_id(s): def define_id(s):
return string.upper(s) return s.upper()
## Return a conventional C++ class identifier ## Return a conventional C++ class identifier
def class_id(s): def class_id(s):
...@@ -81,7 +81,7 @@ def class_id(s): ...@@ -81,7 +81,7 @@ def class_id(s):
for i in range(0, len(s)): for i in range(0, len(s)):
if s[i] in string.ascii_letters or s[i] in string.digits: if s[i] in string.ascii_letters or s[i] in string.digits:
if non_ascii: if non_ascii:
res = res + string.upper(s[i]) res = res + s[i].upper()
non_ascii = False non_ascii = False
else: else:
res = res + s[i] res = res + s[i]
...@@ -91,11 +91,11 @@ def class_id(s): ...@@ -91,11 +91,11 @@ def class_id(s):
## Return a conventional file name ## Return a conventional file name
def file_id(s): def file_id(s):
return string.lower(s) return s.lower()
## Return a valid C++ variable name ## Return a valid C++ variable name
def var_id(s): def var_id(s):
s = string.lower(s) s = s.lower()#string.lower(s)
if s in ["and", "or", "xor"]: if s in ["and", "or", "xor"]:
s = s + "_"; s = s + "_";
return s return s
...@@ -294,7 +294,7 @@ class InstructionSetHandler(ContentHandler): ...@@ -294,7 +294,7 @@ class InstructionSetHandler(ContentHandler):
elif name == "format": elif name == "format":
self.format_b = FormatBuilder() self.format_b = FormatBuilder()
if attrs.has_key("type"): if attrs.__contains__("type"):
self.format_b.type = attrs["type"] self.format_b.type = attrs["type"]
elif name == "predefinedAttributes": elif name == "predefinedAttributes":
self.format_b = FormatBuilder() self.format_b = FormatBuilder()
...@@ -302,24 +302,24 @@ class InstructionSetHandler(ContentHandler): ...@@ -302,24 +302,24 @@ class InstructionSetHandler(ContentHandler):
elif name == "attribute": elif name == "attribute":
self.attr_b.reset() self.attr_b.reset()
self.attr_b.type = attrs["type"] self.attr_b.type = attrs["type"]
if attrs.has_key("restriction"): if attrs.__contains__("restriction"):
self.attr_b.restriction = attrs["restriction"] self.attr_b.restriction = attrs["restriction"]
self.attr_b.name = attrs["name"] self.attr_b.name = attrs["name"]
elif name == "syntax": elif name == "syntax":
self.syntax_b.reset() self.syntax_b.reset()
if attrs.has_key("alias"): if attrs.__contains__("alias"):
self.syntax_b.alias = attrs["alias"] self.syntax_b.alias = attrs["alias"]
if attrs.has_key("level"): if attrs.__contains__("level"):
self.syntax_b.level = attrs["level"] self.syntax_b.level = attrs["level"]
else: else:
self.syntax_b.level = self.inst_b.level self.syntax_b.level = self.inst_b.level
elif name == "predefinedSyntax": elif name == "predefinedSyntax":
alias = "" alias = ""
if attrs.has_key("alias"): if attrs.__contains__("alias"):
alias = attrs["alias"] alias = attrs["alias"]
level = "" level = ""
if attrs.has_key("level"): if attrs.__contains__("level"):
level = attrs["level"] level = attrs["level"]
else: else:
level = self.inst_b.level level = self.inst_b.level
...@@ -327,11 +327,11 @@ class InstructionSetHandler(ContentHandler): ...@@ -327,11 +327,11 @@ class InstructionSetHandler(ContentHandler):
elif name == "token": elif name == "token":
self.token_b.reset() self.token_b.reset()
self.token_b.kind = attrs["kind"] self.token_b.kind = attrs["kind"]
if attrs.has_key("name"): if attrs.__contains__("name"):
self.token_b.name = attrs["name"] self.token_b.name = attrs["name"]
if attrs.has_key("default"): if attrs.__contains__("default"):
self.token_b.default = attrs["default"] self.token_b.default = attrs["default"]
if attrs.has_key("value"): if attrs.__contains__("value"):
self.token_b.value = attrs["value"] self.token_b.value = attrs["value"]
def endElement(self, name): def endElement(self, name):
......
#!/usr/bin/env python #!/usr/bin/env python
## ##
## This file is part of Nolimips, a MIPS simulator with unlimited registers ## 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 ## Nolimips is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by ## it under the terms of the GNU General Public License as published by
...@@ -25,43 +25,43 @@ import nolimips ...@@ -25,43 +25,43 @@ import nolimips
#### Nolimips' instruction set texi generator -------------- #### Nolimips' instruction set texi generator --------------
if __name__ != "__main__" or len(sys.argv) != 2: if __name__ != "__main__" or len(sys.argv) != 2:
print "Usage: .. SRCDIR" print ("Usage: .. SRCDIR")
sys.exit(1) sys.exit(1)
srcdir = sys.argv[1] srcdir = sys.argv[1]
parser = nolimips.InstructionSetParser() parser = nolimips.InstructionSetParser()
instructions = parser.parse(sys.stdin) 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 @node The Nolimips supported instruction set
@section The Nolimips supported instruction set""" @section The Nolimips supported instruction set""")
## Menu ## Menu
print "@menu" print ("@menu")
kind = "" kind = ""
for inst in instructions: for inst in instructions:
if kind != inst.kind: if kind != inst.kind:
kind = inst.kind kind = inst.kind
print "* " + string.capwords(kind) + " instructions ::" print ("* " + string.capwords(kind) + " instructions ::")
print "@end menu" print ("@end menu")
## Subsections ## Subsections
kind = "" kind = ""
for inst in instructions: for inst in instructions:
if kind != inst.kind: if kind != inst.kind:
kind = inst.kind kind = inst.kind
print "@node " + string.capwords(kind) + " instructions" print ("@node " + string.capwords(kind) + " instructions")
print "@subsection " + string.capwords(kind) + " instructions" print ("@subsection " + string.capwords(kind) + " instructions")
desc = string.replace(inst.desc, "\n", " ") desc = inst.desc.replace("\n", " ")
desc = string.replace(desc, " ", " ") desc = desc.replace(" ", " ")
print "@subsubsection " + string.upper(inst.opcode) print ("@subsubsection " + inst.opcode.upper())
print "@findex " + string.upper(inst.opcode) print ("@findex " + inst.opcode.upper())
print desc print (desc)
## Epilogue ## Epilogue
sys.stdout.close() sys.stdout.close()
......
#!/usr/bin/env python #!/usr/bin/env python
## ##
## This file is part of Nolimips, a MIPS simulator with unlimited registers ## 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 ## Nolimips is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by ## it under the terms of the GNU General Public License as published by
...@@ -25,7 +25,7 @@ import nolimips ...@@ -25,7 +25,7 @@ import nolimips
#### Nolimips' instruction classes generator --------------- #### Nolimips' instruction classes generator ---------------
if __name__ != "__main__" or len(sys.argv) != 2: if __name__ != "__main__" or len(sys.argv) != 2:
print "Usage: .. SRCDIR" print ("Usage: .. SRCDIR")
sys.exit(1) sys.exit(1)
srcdir = sys.argv[1] srcdir = sys.argv[1]
...@@ -46,51 +46,50 @@ def class_generate(inst): ...@@ -46,51 +46,50 @@ def class_generate(inst):
format = inst.format format = inst.format
## Open header, inline and implementation files ## Open header, inline and implementation files
header = file(file_id + ".hh.tmp", "w") header = open(file_id + ".hh.tmp", "w")
inline = file(file_id + ".hxx.tmp", "w") inline = open(file_id + ".hxx.tmp", "w")
impl = file(file_id + ".cc.tmp", "w") impl = open(file_id + ".cc.tmp", "w")
for f, ext, brief in [(header, "hh", "Declare the interface"), for f, ext, brief in [(header, "hh", "Declare the interface"),
(inline, "hxx", "Inline methods"), (inline, "hxx", "Inline methods"),
(impl, "cc", "Implementation")]: (impl, "cc", "Implementation")]:
sys.stdout = f sys.stdout = f
print banner print (banner)
# Document the file # Document the file
print "/** \\file inst/" + file_id + "." + ext print ("/** \\file inst/" + file_id + "." + ext)
print " \\brief " + brief + " of " + class_id + " */" print (" \\brief " + brief + " of " + class_id + " */")
# Open multiple inclusion protection # Open multiple inclusion protection
if ext != "cc":