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

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 @@
 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.
+	
+2004-01-10  Benoît Perrot  <benoit@lrde.epita.fr>
+
 	* dev/mipsy.xml: Use a better DTD.
 	* dev/mipsy.py: Use new DTD.
 	* dev/inst-builder-gen.py,
parent 0253aaae
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.
2004-01-10 Benot Perrot <benoit@lrde.epita.fr>
* dev/mipsy.xml: Use a better DTD.
......
......@@ -27,12 +27,12 @@
</format>
<syntax>
<token kind="register" name="dest" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
<token kind="register" />
</syntax>
<syntax alias="addi">
<token kind="register" name="dest" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
<token kind="immediate" />
</syntax>
</instruction>
......@@ -45,12 +45,12 @@
</format>
<syntax>
<token kind="register" name="dest" />
<token kind="register" default="@0"/>
<token kind="register" default="${dest}"/>
<token kind="register" />
</syntax>
<syntax alias="addiu">
<token kind="register" name="dest" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
<token kind="immediate" />
</syntax>
</instruction>
......@@ -64,7 +64,7 @@
</format>
<syntax>
<token kind="register" name="dest" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
<token kind="immediate" />
</syntax>
</instruction>
......@@ -77,7 +77,7 @@
</format>
<syntax>
<token kind="register" name="dest" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
<token kind="immediate" />
</syntax>
</instruction>
......@@ -97,7 +97,7 @@
<syntax alias="addi">
<token kind="register" />
<token kind="register" />
<token kind="immediate" name="imm" value="*new OpExp(*new IntExp(0), OpExp::sub, @2)" />
<token kind="immediate" name="imm" value="*new OpExp(*new IntExp(0), OpExp::sub, ${imm})" />
</syntax>
</instruction>
<instruction opcode="subu" level="native" kind="arithmetic">
......@@ -115,7 +115,7 @@
<syntax alias="addiu">
<token kind="register" />
<token kind="register" />
<token kind="immediate" name="imm" value="*new OpExp(*new IntExp(0), OpExp::sub, @2)" />
<token kind="immediate" name="imm" value="*new OpExp(*new IntExp(0), OpExp::sub, ${imm})" />
</syntax>
</instruction>
......@@ -124,7 +124,7 @@
<syntax alias="sub">
<token kind="register" name="dest" />
<token kind="hidden" value="* new Register(Register::general, Cpu::zero)" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
</syntax>
</instruction>
<instruction opcode="negu" level="pseudo" kind="arithmetic">
......@@ -132,7 +132,7 @@
<syntax alias="subu">
<token kind="register" name="dest" />
<token kind="hidden" value="* new Register(Register::general, Cpu::zero)" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
</syntax>
</instruction>
......@@ -140,7 +140,7 @@
<description>FIXME</description>
<syntax>
<token kind="register" name="dest" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
</syntax>
</instruction>
......@@ -359,12 +359,12 @@
</format>
<syntax>
<token kind="register" name="dest" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
<token kind="register" />
</syntax>
<syntax alias="andi">
<token kind="register" name="dest" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
<token kind="immediate" />
</syntax>
</instruction>
......@@ -391,12 +391,12 @@
</format>
<syntax>
<token kind="register" name="dest" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
<token kind="register" />
</syntax>
<syntax alias="ori">
<token kind="register" name="dest" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
<token kind="immediate" />
</syntax>
</instruction>
......@@ -423,12 +423,12 @@
</format>
<syntax>
<token kind="register" name="dest" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
<token kind="register" />
</syntax>
<syntax alias="xori">
<token kind="register" name="dest" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
<token kind="immediate" />
</syntax>
</instruction>
......@@ -455,12 +455,12 @@
</format>
<syntax>
<token kind="register" name="dest" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
<token kind="register" />
</syntax>
<syntax level="complex">
<token kind="register" name="dest" />
<token kind="register" default="@0" />
<token kind="register" default="${dest}" />
<token kind="immediate" />
</syntax>
</instruction>
......@@ -469,7 +469,7 @@
<instruction opcode="not" level="pseudo" kind="bitwise">
<syntax alias="nor">
<token kind="register" name="dest" />
<token kind="register" default="@0"/>
<token kind="register" default="${dest}"/>
<token kind="hidden" value="* new Register(Register::general, Cpu::zero)" />
</syntax>
</instruction>
......@@ -529,8 +529,8 @@
<instruction opcode="sgt" level="complex" kind="comparison">
<syntax alias="slt">
<token kind="register" />
<token kind="register" name="src1" value="@2"/>
<token kind="register" name="src2" value="@1"/>
<token kind="register" name="src1" value="${src2}"/>
<token kind="register" name="src2" value="${src1}"/>
</syntax>
<syntax>
<token kind="register" />
......@@ -541,8 +541,8 @@
<instruction opcode="sgtu" level="complex" kind="comparison">
<syntax alias="sltu">
<token kind="register" />
<token kind="register" name="src1" value="@2"/>
<token kind="register" name="src2" value="@1"/>
<token kind="register" name="src1" value="${src2}"/>
<token kind="register" name="src2" value="${src1}"/>
</syntax>
<syntax>
<token kind="register" />
......
......@@ -24,11 +24,10 @@ import string, re
import mipsy
from mipsy import license, depth, define_id
#### Mipsy's Bison assembly parser generator ---------------
parser = mipsy.InstructionSetParser()
instructions = parser.parse(sys.stdin)
#### Mipsy Bison parser generator --------------------------
## Prologue --------------------------
print "%{ // -*- C++ -*-"
print license
......@@ -141,100 +140,92 @@ instruction
// Opcodes"""
## Body ------------------------------
token_map = {
"register": "REGISTER",
## Body ------------------------------
tokid_map = {
"register" : "REGISTER",
"immediate": "exp",
"label": "exp",
"address": "REGISTER",
"hidden": ""
"label" : "exp",
"address" : "REGISTER",
"hidden" : ""
}
for inst in instructions:
for syntax in inst.syntaxes:
## Build paths from params
paths = []
for param in syntax.tokens:
token = token_map[param.kind]
if param.kind == "address":
paths.append(["LPAREN"])
## Compute productions
# A token is a tuple (token id, token name, token value)
prods = [[(define_id(inst.opcode), "", "")]]
for i, token in enumerate(syntax.tokens):
if token.kind == "address":
prods.append([("LPAREN", "", "")])
if token.default != "":
prods.append([(tokid_map[token.kind], token.name, token.value),
("", token.name, token.default)])
else:
paths.append(["COMMA"])
prods.append([(tokid_map[token.kind], token.name, token.value)])
if token.kind == "address":
prods.append([("RPAREN", "", "")])
prods = depth(prods)
if param.value != "":
token = token + "=" + param.value
if param.default != "":
paths.append([token, "=" + param.default])
else:
paths.append([token])
if param.kind == "address":
paths.append(["RPAREN"])
## Expand paths
paths = depth(paths)
## Add opcode and remove useless COMMAs (COMMA before default, etc.)
prods = []
if paths == []:
prods = [[define_id(inst.opcode)]]
for path in paths:
prod = [define_id(inst.opcode)]
for i in range(1, len(path)):
token = path[i]
if token == "COMMA":
if ((i < len(path) - 2) and \
(path[i + 1][0] == "=") and (path[i + 2] == "COMMA")) or \
((i == len(path) - 2) and (path[i + 1][0] == "=")) or \
((i == 2) and (path[1][0] == "=")):
continue
prod.append(token)
prods.append(prod)
## Build action(s) from production(s)
## Display rules and actions
for prod in prods:
## Compute values of token
values = []
# Add COMMAs
tokidx = {}
lparen_p = False
i = 0
while True:
token = prod[i]
if token[0] != "":
if i > 1:
if token[0] == "LPAREN":
lparen_p = (prod[i - 1][0] != "")
if not lparen_p:
prod.insert(i, ("COMMA", "", ""))
i = i + 1
if token[0] == "LPAREN":
lparen_p = True
elif token[0] == "RPAREN":
lparen_p = False
i = i + 1
if i >= len(prod):
break
# Compute token indices
tokidx = {}
i = 0
for token in prod:
token = string.split(token, "=")[0]
if token != "":
if token[0] != "":
i = i + 1
if token in token_map.values():
if token == "INTEGER":
values = values + ["$" + str(i)]
else:
values = values + ["*$" + str(i)]
## Build action, expanding values
if token[1] != "":
assert(not tokidx.has_key(token[1]))
tokidx[token[1]] = i
# Build rule and action
rule = "|"
action = "program_builder.add_"
if syntax.alias != "":
action = syntax.alias + "("
action = action + syntax.alias + "("
else:
action = inst.opcode + "("
action = action + inst.opcode + "("
i = 0
rule = "|"
for token in prod:
l = string.split(token, "=")
value = ""
if len(l) > 1:
value = re.sub(r"@([0-9]+)",
(lambda m: values[string.atoi(m.groups(0)[0])]),
l[1])
if l[0] != "":
rule = rule + " " + l[0]
if value != "":
if token[0] != "":
i = i + 1
rule = rule + " " + token[0]
value = "*$" + str(i)
if token[2] != "":
value = re.sub(r"\$\{([^}]*)\}",
(lambda m: "*$" + str(tokidx[m.groups(0)[0]])),
token[2])
if token[0] in tokid_map.values():
action = action + value + ", "
else:
if l[0] in token_map.values():
action = action + values[i] + ", "
i = i + 1
action = string.rstrip(action, ", ") + ")"
## Print production followed by action
# Dump rule and associated action
print rule
print "{ program_builder.add_" + action + "; }"
print "{ " + action + "; }"
## Epilogue --------------------------
......
......@@ -2,29 +2,29 @@
(Created-By-Prcs-Version 1 3 2)
(Project-Description "")
(Project-Version mipsy 0 61)
(Parent-Version mipsy 0 60)
(Project-Version mipsy 0 62)
(Parent-Version mipsy 0 61)
(Version-Log
"Index: ChangeLog
--- ChangeLog Thu, 08 Jan 2004 15:27:18 +0100 noe (mipsy/2_ChangeLog 1.54 604)
+++ ChangeLog Sat, 10 Jan 2004 22:21:15 +0100 noe (mipsy/2_ChangeLog 1.54 604)
@@ -1,3 +1,13 @@
--- 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 @@
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.
+
+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/inst-nodes-gen.py,
+ * dev/parse-asm-parse-gen.py,
+ * dev/parse-asm-scan-gen.py:
+ Use new mipsy.py package.
+
* dev/mipsy.xml: Use a better DTD.
* dev/mipsy.py: Use new DTD.
* dev/inst-builder-gen.py,
")
(New-Version-Log
"")
(Checkin-Time "Sat, 10 Jan 2004 22:25:29 +0100")
(Checkin-Time "Sat, 10 Jan 2004 22:32:29 +0100")
(Checkin-Login noe)
(Files
......@@ -32,7 +32,7 @@
;; ./
(AUTHORS (mipsy/0_AUTHORS 1.1 604))
(COPYING (mipsy/1_COPYING 1.1 604))
(ChangeLog (mipsy/2_ChangeLog 1.55 604))
(ChangeLog (mipsy/2_ChangeLog 1.56 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))
......@@ -49,8 +49,8 @@
(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/mipsy.py (mipsy/16_mipsy.py 1.7 705))
(dev/mipsy.xml (mipsy/17_mipsy.xml 1.12 604))
(dev/parse-asm-parse-gen.py (mipsy/13_mipsy-pars 1.6 705))
(dev/mipsy.xml (mipsy/17_mipsy.xml 1.13 604))
(dev/parse-asm-parse-gen.py (mipsy/13_mipsy-pars 1.7 705))
(dev/parse-asm-scan-gen.py (mipsy/14_mipsy-scan 1.9 705))
;; ./doc/
......
Supports Markdown
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