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