Commit 9fcaec4d authored by Akim Demaille's avatar Akim Demaille

style: untabify Python programs

* 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:
Untabify.
parent 70269b03
......@@ -7,12 +7,12 @@
## 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.
##
##
## Nolimips 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 Nolimips. If not, see <http://www.gnu.org/licenses/>.
##
......@@ -31,12 +31,12 @@ license = """//
// 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.
//
//
// Nolimips 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 Nolimips. If not, see <http://www.gnu.org/licenses/>.
//
......@@ -181,7 +181,7 @@ class TokenBuilder:
def reset(self):
self.kind = ""
self.name = ""
self.value = ""
self.value = ""
self.default = ""
def __init__(self):
self.reset()
......@@ -281,17 +281,17 @@ class InstructionSetHandler(ContentHandler):
self.content = ""
def __init__(self):
self.reset()
def startElement(self, name, attrs):
if name == "instruction":
self.inst_b.reset()
self.inst_b.opcode = attrs["opcode"]
self.inst_b.level = attrs["level"]
self.inst_b.kind = attrs["kind"]
elif name == "description":
self.content = ""
elif name == "format":
self.format_b = FormatBuilder()
if attrs.has_key("type"):
......@@ -339,17 +339,17 @@ class InstructionSetHandler(ContentHandler):
self.syntax_b.tokens.append(self.token_b.get())
elif name == "syntax" or name == "predefinedSyntax":
self.inst_b.syntaxes.append(self.syntax_b.get())
if name == "attribute":
self.format_b.attributes.append(self.attr_b.get())
elif name == "predefinedAttributes":
self.inst_b.format = self.format_b.get()
elif name == "format":
self.inst_b.format = self.format_b.get()
elif name == "description":
self.inst_b.desc = self.content
elif name == "instruction":
self.instructions.append(self.inst_b.get())
......@@ -365,7 +365,7 @@ class InstructionSetParser:
h = InstructionSetHandler()
# Tell the parser to use our handler
parser.setContentHandler(h)
# Parse the input
parser.parse(file)
......
......@@ -7,12 +7,12 @@
## 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.
##
##
## Nolimips 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 Nolimips. If not, see <http://www.gnu.org/licenses/>.
##
......@@ -55,10 +55,10 @@ for inst in instructions:
kind = inst.kind
print "@node " + string.capwords(kind) + " instructions"
print "@subsection " + string.capwords(kind) + " instructions"
desc = string.replace(inst.desc, "\n", " ")
desc = string.replace(desc, " ", " ")
print "@subsubsection " + string.upper(inst.opcode)
print "@findex " + string.upper(inst.opcode)
print desc
......
......@@ -7,12 +7,12 @@
## 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.
##
##
## Nolimips 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 Nolimips. If not, see <http://www.gnu.org/licenses/>.
##
......@@ -44,12 +44,12 @@ def class_generate(inst):
file_id = nolimips.file_id(inst.opcode)
banner = nolimips.license + "\n" + nolimips.generated_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")]:
......@@ -71,7 +71,7 @@ def class_generate(inst):
sys.stdout = impl
print "#include \"inst/visitor.hh\""
for f in [inline, impl]:
sys.stdout = f
print "#include \"inst/" + file_id + ".hh\""
......@@ -91,13 +91,13 @@ namespace inst
print " class " + class_id + ":"
print " public Inst"
print " {"
# Constructor and destructor
args = ""
init = ""
dels = ""
for attribute in format.attributes:
if attribute.type == "Register":
args = args + "const " + attribute.type + " &"
elif attribute.type == "Exp":
......@@ -159,7 +159,7 @@ namespace inst
print " }"
sys.stdout = header
print " /** \\} */"
# Method: visitor entry point
sys.stdout = inline
print ""
......
......@@ -7,12 +7,12 @@
## 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.
##
##
## Nolimips 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 Nolimips. If not, see <http://www.gnu.org/licenses/>.
##
......@@ -28,13 +28,13 @@ from nolimips import depth
parser = nolimips.InstructionSetParser()
instructions = parser.parse(sys.stdin)
print "FROM_NODES_GEN_PY = \\"
print "FROM_NODES_GEN_PY = \\"
for i in range(0, len(instructions)):
if instructions[i].level == "native":
line = "\t"
for ext in ["hh", "hxx", "cc"]:
line = line + instructions[i].opcode + "." + ext + " "
print line + "\t\t\\"
print """ fwd.hh \\
all.hh \\
visitor.hh"""
print """ fwd.hh \\
all.hh \\
visitor.hh"""
......@@ -7,12 +7,12 @@
## 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.
##
##
## Nolimips 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 Nolimips. If not, see <http://www.gnu.org/licenses/>.
##
......@@ -52,7 +52,7 @@ namespace inst
{
using vm::Cpu;
class ProgramBuilder
{
public:
......@@ -62,9 +62,9 @@ namespace inst
void reset();
void set_nop_after_branch(bool nop_after_branch_p);
Program *get();
public:
void define_inst_label(const misc::unique_string &id);
void define_data_label(const misc::unique_string &id);
......@@ -95,7 +95,7 @@ for inst in instructions:
for syntax in inst.syntaxes:
if (syntax.alias != "") or (syntax.level == "pseudo"):
continue
if syntax.level == "native":
proto = ""
call = ""
......@@ -112,14 +112,14 @@ for inst in instructions:
print " program_->text_section().add_inst (" + call + ");"
if inst.kind == "branch":
print " if (nop_after_branch_p_)"
print " program_->text_section()."
print " add_inst (new Sll(Register(Register::general, " + \
print " program_->text_section()."
print " add_inst (new Sll(Register(Register::general, " + \
"Cpu::zero), "
print " Register(Register::general, " + \
print " Register(Register::general, " + \
"Cpu::zero), "
print " new IntExp(0)));"
print " new IntExp(0)));"
print " }"
else: # syntax.level == "complex"
proto = ""
for token in syntax.tokens:
......@@ -129,7 +129,7 @@ for inst in instructions:
proto = proto + ", "
proto = string.rstrip(proto, ", ")
print " void\tadd_" + inst.opcode + "(" + proto + ");"
print """
protected:
Program *program_;
......
......@@ -7,12 +7,12 @@
## 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.
##
##
## Nolimips 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 Nolimips. If not, see <http://www.gnu.org/licenses/>.
##
......@@ -52,7 +52,7 @@ namespace inst
{
class ProgramSolver:
protected Visitor,
protected Visitor,
protected ExpVisitor
{
public:
......@@ -84,9 +84,9 @@ namespace inst
print " protected:"
for inst in instructions:
if inst.level == "native":
print " virtual void visit(" +\
print " virtual void visit(" +\
nolimips.class_id(inst.opcode) + " &);"
print """
protected:
Program *program_;
......@@ -144,14 +144,14 @@ namespace inst
{
if (! program_->data_section().has_label(l.get_name()))
if (! program_->text_section().has_label(l.get_name()))
{
std::cerr << \"Undefined label: \" << l.get_name()
<< std::endl;
exit_set(exit_solve);
}
{
std::cerr << \"Undefined label: \" << l.get_name()
<< std::endl;
exit_set(exit_solve);
}
else
l.set_immediate(program_->text_section().
get_offset(l.get_name()) - pc_);
l.set_immediate(program_->text_section().
get_offset(l.get_name()) - pc_);
else
l.set_immediate(program_->data_section().get_offset(l.get_name()));
}
......@@ -164,21 +164,21 @@ namespace inst
switch (o.kind_)
{
case OpExp::add:
o.set_immediate(o.get_left().get_immediate() +
o.get_right().get_immediate());
break;
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;
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;
o.set_immediate(o.get_left().get_immediate() /
o.get_right().get_immediate());
break;
}
}
......@@ -188,46 +188,46 @@ namespace inst
switch (reg.get_kind())
{
case Register::generic:
reg.set_kind(Register::general);
reg.set_kind(Register::general);
case Register::general:
if ((reg.get_index() == vm::Cpu::t9 && max_caller_save_ < 10)
|| (reg.get_index() == vm::Cpu::t8 && max_caller_save_ < 9)
|| (vm::Cpu::t0 + max_caller_save_ - 1 < reg.get_index()
&& reg.get_index() <= vm::Cpu::t7))
{
std::cerr << \"Caller-save register limited.\" << std::endl;
exit_set(exit_solve);
}
else if (vm::Cpu::s0 + max_callee_save_ - 1 < reg.get_index() &&
reg.get_index() <= vm::Cpu::s7)
{
std::cerr << \"Callee-save register limited.\" << std::endl;
exit_set(exit_solve);
}
if ((reg.get_index() == vm::Cpu::t9 && max_caller_save_ < 10)
|| (reg.get_index() == vm::Cpu::t8 && max_caller_save_ < 9)
|| (vm::Cpu::t0 + max_caller_save_ - 1 < reg.get_index()
&& reg.get_index() <= vm::Cpu::t7))
{
std::cerr << \"Caller-save register limited.\" << std::endl;
exit_set(exit_solve);
}
else if (vm::Cpu::s0 + max_callee_save_ - 1 < reg.get_index() &&
reg.get_index() <= vm::Cpu::s7)
{
std::cerr << \"Callee-save register limited.\" << std::endl;
exit_set(exit_solve);
}
else if (vm::Cpu::a0 + max_args_ - 1 < reg.get_index() &&
reg.get_index() <= vm::Cpu::a3)
reg.get_index() <= vm::Cpu::a3)
{
std::cerr << \"Argument register limited.\" << std::endl;
exit_set(exit_solve);
std::cerr << \"Argument register limited.\" << std::endl;
exit_set(exit_solve);
}
break;
break;
case Register::unlimited:
if (!unlimited_regs_enabled_)
{
std::cerr << \"Unlimited registers prohibited.\" << std::endl;
exit_set(exit_solve);
}
break;
if (!unlimited_regs_enabled_)
{
std::cerr << \"Unlimited registers prohibited.\" << std::endl;
exit_set(exit_solve);
}
break;
};
}
void
ProgramSolver::solve_cop_register(Register &reg) const
{
if (reg.get_kind() != Register::generic)
{
std::cerr << \"Coprocessor registers must be generic.\" << std::endl;
exit_set(exit_solve);
std::cerr << \"Coprocessor registers must be generic.\" << std::endl;
exit_set(exit_solve);
}
}
......@@ -236,7 +236,7 @@ namespace inst
for inst in instructions:
if inst.level == "native":
var_id = nolimips.var_id(inst.opcode)
content = ""
for attribute in inst.format.attributes:
if attribute.type == "Exp":
......@@ -248,7 +248,7 @@ for inst in instructions:
else:
content = content + " solve_cpu_register("
content = content + var_id + ".get_" + attribute.name + "());\n"
print " void"
if content != "":
print " ProgramSolver::visit(" + nolimips.class_id(inst.opcode) + \
......@@ -258,7 +258,7 @@ for inst in instructions:
print " ProgramSolver::visit(" + nolimips.class_id(inst.opcode) + " &)"
print " {"
print " }"
print """
} // namespace inst"""
......
......@@ -7,12 +7,12 @@
## 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.
##
##
## Nolimips 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 Nolimips. If not, see <http://www.gnu.org/licenses/>.
##
......@@ -36,7 +36,7 @@ instructions = parser.parse(sys.stdin)
sys.stdout = file("asm-parse.yy.tmp", "w")
## Prologue --------------------------
print "%{ // -*- C++ -*-"
print "%{ // -*- C++ -*-"
print nolimips.license
print nolimips.generated_by_hand
print """
......@@ -73,9 +73,9 @@ using namespace inst;
%union
{
int i;
std::string *s;
misc::unique_string *id;
int i;
std::string *s;
misc::unique_string *id;
inst::Label *label;
inst::Register *reg;
inst::Exp *exp;
......@@ -84,8 +84,8 @@ using namespace inst;
#include \"parse/asm-scan.hh\"
%}
%token <id> LABEL \"label\"
%token <id> LABEL_DEF \"label definition\"
%token <id> LABEL \"label\"
%token <id> LABEL_DEF \"label definition\"
%token <i> INTEGER \"integer\"
%token <s> STRING \"string\"
%token <reg> REGISTER \"register\"
......@@ -100,10 +100,10 @@ using namespace inst;
%type <exp> exp
%token YYEOF 0 \"end of file\"
%token LPAREN \"(\"
%token RPAREN \")\"
%token COMMA \",\"
%token YYEOF 0 \"end of file\"
%token LPAREN \"(\"
%token RPAREN \")\"
%token COMMA \",\"
%left EXP_ADD EXP_SUB
%left EXP_MUL EXP_DIV
......@@ -119,15 +119,15 @@ using namespace inst;
%token DIR_ASCII \".ascii\"
%token DIR_ASCIIZ \".asciiz\"
"""
for i in instructions:
print "%token " + define_id(i.opcode) + '\t\t"' + i.opcode + '"'
print """
%start program
%%
//
//
program
:
| program DIR_TEXT instructions
......@@ -228,7 +228,7 @@ for inst in instructions:
i = i + 1
if i >= len(prod):
break
# Compute token indices
tokidx = {}
i = 0
......@@ -238,7 +238,7 @@ for inst in instructions:
if token[1] != "":
assert(not tokidx.has_key(token[1]))
tokidx[token[1]] = i
# Build rule and action
rule = "|"
action = "program_builder.add_"
......@@ -255,7 +255,7 @@ for inst in instructions:
rule = rule + " " + token[0]
value = "$" + str(i)
if token[2] != "":
value = re.sub(r"\$\{([^}]*)\}",
value = re.sub(r"\$\{([^}]*)\}",
(lambda m: "$" + str(tokidx[m.groups(0)[0]])),
token[2])
if token[0] in tokid_map.values():
......
......@@ -7,12 +7,12 @@
## 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.
##
##
## Nolimips 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 Nolimips. If not, see <http://www.gnu.org/licenses/>.
##
......@@ -53,7 +53,7 @@ print """
#define YY_NEVER_INTERACTIVE 1
#define YY_USER_ACTION \\
#define YY_USER_ACTION \\
yylloc->columns (yyleng);
using inst::Register;
......@@ -68,40 +68,40 @@ typedef yy::parser::token token;
%option debug
%x STATE_STRING
eol \\n|\\r|\\n\\r|\\r\\n
eol \\n|\\r|\\n\\r|\\r\\n
dec_int [0-9]+
hex_int 0x[0-9A-Fa-f]+
dec_int [0-9]+
hex_int 0x[0-9A-Fa-f]+
id [a-zA-Z_][a-zA-Z_0-9]*
id [a-zA-Z_][a-zA-Z_0-9]*
%%
%{
yylloc->step ();
%}
[ \\t]+ yylloc->step ();
[#;][^\\n\\r]* yylloc->step ();
{eol} yylloc->lines (1); yylloc->step ();
[ \\t]+ yylloc->step ();
[#;][^\\n\\r]* yylloc->step ();
{eol} yylloc->lines (1); yylloc->step ();
\"(\" return token::LPAREN;
\")\" return token::RPAREN;
\",\" return token::COMMA;
\"(\" return token::LPAREN;
\")\" return token::RPAREN;
\",\" return token::COMMA;