Commit 0253aaae authored by Benoit Perrot's avatar Benoit Perrot
Browse files

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 @@
+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,
+	* dev/inst-nodes-gen.py,
+	* dev/parse-asm-parse-gen.py,
+	* dev/parse-asm-scan-gen.py:
+	Use new mipsy.py package.	
+
parent 07584f19
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.
2004-01-08 Benot Perrot <benoit@lrde.epita.fr> 2004-01-08 Benot Perrot <benoit@lrde.epita.fr>
* dev/parse-asm-scan.py: Simplify scanner register generation. * dev/parse-asm-scan.py: Simplify scanner register generation.
......
...@@ -111,9 +111,8 @@ for inst in instructions: ...@@ -111,9 +111,8 @@ for inst in instructions:
if syntax.level == "native": if syntax.level == "native":
proto = "" proto = ""
call = "" call = ""
for attribute in inst.format.params: for attribute in inst.format.attributes:
proto = proto + type_map[attribute.kind] + " " + \ proto = proto + attribute.type + "& " + attribute.name + ", "
attribute.name + ", "
call = call + attribute.name + ", " call = call + attribute.name + ", "
proto = string.rstrip(proto, ", ") proto = string.rstrip(proto, ", ")
call = string.rstrip(call, ", ") call = string.rstrip(call, ", ")
...@@ -133,10 +132,10 @@ for inst in instructions: ...@@ -133,10 +132,10 @@ for inst in instructions:
else: # syntax.level == "complex" else: # syntax.level == "complex"
proto = "" proto = ""
for param in syntax.params: for token in syntax.tokens:
proto = proto + type_map[param.kind] proto = proto + type_map[token.kind]
if param.name: if token.name:
proto = proto + " " + param.name proto = proto + " " + token.name
proto = proto + ", " proto = proto + ", "
proto = string.rstrip(proto, ", ") proto = string.rstrip(proto, ", ")
print " void\tadd_" + inst.opcode + "(" + proto + ");" print " void\tadd_" + inst.opcode + "(" + proto + ");"
......
...@@ -59,8 +59,8 @@ namespace inst ...@@ -59,8 +59,8 @@ namespace inst
print " public:" print " public:"
proto = "" proto = ""
init = "" init = ""
for attribute in format.params: for attribute in format.attributes:
proto = proto + type_map[attribute.kind] + " " + attribute.name + ", " proto = proto + attribute.type + "& " + attribute.name + ", "
init = init + attribute.name + "(" + attribute.name + "), " init = init + attribute.name + "(" + attribute.name + "), "
proto = string.rstrip(proto, ", ") proto = string.rstrip(proto, ", ")
init = string.rstrip(init, ", ") init = string.rstrip(init, ", ")
...@@ -81,14 +81,14 @@ namespace inst ...@@ -81,14 +81,14 @@ namespace inst
## Methods: accessors ## Methods: accessors
print """ print """
public:""" public:"""
for attribute in format.params: for attribute in format.attributes:
type = type_map[attribute.kind] type = attribute.type
print " const " + type + "\t\tget_" + attribute.name + " () const" print " const " + type + "&\t\tget_" + attribute.name + " () const"
print " {" print " {"
print " return " + attribute.name + ";" print " return " + attribute.name + ";"
print " }" print " }"
if type != "int": if type != "int":
print " " + type + "\t\tget_" + attribute.name + " ()" print " " + type + "&\t\tget_" + attribute.name + " ()"
print " {" print " {"
print " return " + attribute.name + ";" print " return " + attribute.name + ";"
print " }" print " }"
...@@ -113,15 +113,15 @@ namespace inst ...@@ -113,15 +113,15 @@ namespace inst
{""" {"""
s = "" s = ""
i = 0 i = 0
while i < len(format.params): while i < len(format.attributes):
if (i < len(format.params) - 1) and \ if (i < len(format.attributes) - 1) and \
(format.params[i].kind == "immediate") and \ (format.attributes[i].type == "Exp") and \
(format.params[i + 1].kind == "register"): (format.attributes[i + 1].type == "Register"):
s = s + " << " + format.params[i].name + \ s = s + " << " + format.attributes[i].name + \
" << '(' << " + format.params[i + 1].name + " << ')' " " << '(' << " + format.attributes[i + 1].name + " << ')' "
i = i + 1 i = i + 1
else: else:
s = s + " << " + format.params[i].name + " << \", \"" s = s + " << " + format.attributes[i].name + " << \", \""
i = i + 1 i = i + 1
s = string.rstrip(s, "<< \", \"") s = string.rstrip(s, "<< \", \"")
print " ostr << \"" + inst.opcode + "\\t\"" + s + ";" print " ostr << \"" + inst.opcode + "\\t\"" + s + ";"
...@@ -130,8 +130,8 @@ namespace inst ...@@ -130,8 +130,8 @@ namespace inst
## Print attributes ## Print attributes
print " protected:" print " protected:"
for attribute in format.params: for attribute in format.attributes:
print " " + type_map[attribute.kind] + "\t\t" + attribute.name + ";" print " " + attribute.type + "&\t\t" + attribute.name + ";"
print " };" print " };"
print """ print """
} // namespace inst } // namespace inst
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
## ##
import string import string
import os.path, filecmp, shutil import sys, os.path, filecmp, shutil
from xml.sax import ContentHandler, make_parser from xml.sax import ContentHandler, make_parser
## --------------------------------------------------------------------------- ## ---------------------------------------------------------------------------
...@@ -90,148 +90,192 @@ def file_id(s): ...@@ -90,148 +90,192 @@ def file_id(s):
return string.lower(s) return string.lower(s)
## ------------------------------------- ## -------------------------------------
class Param: class Attribute:
def __init__(self, kind, name, value, default): def __init__(self, type, name, value):
self.kind = kind self.type = type
self.name = name self.name = name
self.value = value self.value = value # FIXME: useless
self.default = default def __str__(self):
def display(self): return "<attribute type=\"" + self.type + "\" name=\"" + self.name +"\" />"
print self.kind + " " + self.name + " = " + self.value class AttributeBuilder:
class ParamBuilder:
def reset(self): def reset(self):
self.kind = "" self.type = ""
self.name = "" self.name = ""
self.value = "" self.value = ""# FIXME: useless
self.default = ""
def __init__(self): def __init__(self):
self.reset() self.reset()
def get(self): def get(self):
return Param(self.kind, self.name, self.value, self.default) assert(self.type != "" and self.name != "")
return Attribute(self.type, self.name, self.value)
## -------------------------------------
class Format: class Format:
def __init__(self, params): def __init__(self, attributes):
self.params = params self.attributes = attributes
def __str__(self):
def display(self): res = " <format>"
for p in self.params: for p in self.attributes:
p.display() res = res + "\n " + str(p)
return res + "\n </format>"
class FormatBuilder: class FormatBuilder:
def reset(self): def reset(self):
self.params = [] self.attributes = []
def __init__(self): def __init__(self):
self.reset() self.reset()
def get(self):
return Format(self.attributes)
## -------------------------------------
class Token:
def __init__(self, kind, name, value, default):
self.kind = kind
self.name = name
self.value = value
self.default = default
def __str__(self):
res = "<token kind=\"" + self.kind + "\" "
if self.name != "":
res = res + "name=\"" + self.name + "\" "
if self.value != "":
res = res + "value=\"" + self.value + "\" "
if self.default != "":
res = res + "default=\"" + self.default + "\" "
return res + "/>"
class TokenBuilder:
def reset(self):
self.kind = ""
self.name = ""
self.value = ""
self.default = ""
def __init__(self):
self.reset()
def get(self): def get(self):
return Format(self.params) assert(self.kind != "")
return Token(self.kind, self.name, self.value, self.default)
## -------------------------------------
class Syntax: class Syntax:
def __init__(self, params, alias, level): def __init__(self, tokens, alias, level):
self.params = params self.tokens = tokens
self.alias = alias self.alias = alias
self.level = level self.level = level
def __str__(self):
def display(self): res = " <syntax"
if self.alias != "": if self.alias != "":
print self.alias res = res + " alias=\"" + self.alias + "\""
for p in self.params: res = res + ">"
p.display() for t in self.tokens:
res = res + "\n " + str(t)
return res + "\n </syntax>"
class SyntaxBuilder: class SyntaxBuilder:
def reset(self): def reset(self):
self.params = [] self.tokens = []
self.alias = "" self.alias = ""
def __init__(self): def __init__(self):
self.reset() self.reset()
def get(self): def get(self):
return Syntax(self.params, self.alias, self.level) return Syntax(self.tokens, self.alias, self.level)
## ------------------------------------- ## -------------------------------------
class Instruction: class Instruction:
def __init__(self, opcode, level, kind, format, syntaxes): def __init__(self, opcode, level, kind, desc, format, syntaxes):
self.opcode = opcode self.opcode = opcode
self.level = level self.level = level
self.kind = kind self.kind = kind
self.desc = desc
self.format = format self.format = format
self.syntaxes = syntaxes self.syntaxes = syntaxes
def __str__(self):
def display(self): res = "<instruction opcode=\"" + self.opcode + \
print self.opcode + " >>" "\" level=\"" + self.level + \
self.format.display() "\" kind=\"" + self.kind + ">\n" + \
" <description>" + self.desc + "</description>\n" + \
str(self.format) + "\n"
for s in self.syntaxes: for s in self.syntaxes:
print "<syntax>" res = res + str(s) + "\n"
s.display() return res + "</instruction>"
print "</syntax>"
class InstructionBuilder: class InstructionBuilder:
def reset(self): def reset(self):
self.opcode = "" self.opcode = ""
self.level = "" self.level = ""
self.kind = "" self.kind = ""
self.desc = ""
self.format = Format("") self.format = Format("")
self.syntaxes = [] self.syntaxes = []
def __init__(self): def __init__(self):
self.reset() self.reset()
def get(self): def get(self):
return Instruction(self.opcode, self.level, self.kind, assert(self.opcode != "" and self.level != "" and self.kind != "")
return Instruction(self.opcode, self.level, self.kind, self.desc,
self.format, self.syntaxes) self.format, self.syntaxes)
## -------------------------------------
## -------------------------------------
class InstructionSetHandler(ContentHandler): class InstructionSetHandler(ContentHandler):
pb = ParamBuilder() def reset(self):
sb = SyntaxBuilder() self.attr_b = AttributeBuilder()
fb = None self.format_b = None
ib = InstructionBuilder() self.token_b = TokenBuilder()
instructions = [] self.syntax_b = SyntaxBuilder()
self.inst_b = InstructionBuilder()
self.instructions = []
self.content = ""
def __init__(self):
self.reset()
def startElement(self, name, attrs): def startElement(self, name, attrs):
if name == "instruction": if name == "instruction":
self.ib.reset() self.inst_b.reset()
self.ib.opcode = attrs["opcode"] self.inst_b.opcode = attrs["opcode"]
self.ib.level = attrs["level"] self.inst_b.level = attrs["level"]
self.ib.kind = attrs["kind"] self.inst_b.kind = attrs["kind"]
elif name == "description":
self.content = ""
elif name == "format": elif name == "format":
self.fb = FormatBuilder() self.format_b = FormatBuilder()
elif name == "attribute":
self.attr_b.reset()
self.attr_b.type = attrs["type"]
self.attr_b.name = attrs["name"]
# if attrs.has_key("default"):
# self.attr_b.default = attrs["default"]
# if attrs.has_key("value"):
# self.attr_b.value = attrs["value"]
elif name == "syntax": elif name == "syntax":
self.sb.reset() self.syntax_b.reset()
if attrs.has_key("alias"): if attrs.has_key("alias"):
self.sb.alias = attrs["alias"] self.syntax_b.alias = attrs["alias"]
if attrs.has_key("level"): if attrs.has_key("level"):
self.sb.level = attrs["level"] self.syntax_b.level = attrs["level"]
else: else:
self.sb.level = self.ib.level self.syntax_b.level = self.inst_b.level
elif name in ["register", "immediate", "label", "address", "hidden"]: elif name == "token":
self.pb.reset() self.token_b.reset()
self.pb.kind = name self.token_b.kind = attrs["kind"]
if attrs.has_key("name"): if attrs.has_key("name"):
self.pb.name = attrs["name"] self.token_b.name = attrs["name"]
if attrs.has_key("default"): if attrs.has_key("default"):
self.pb.default = attrs["default"] self.token_b.default = attrs["default"]
if attrs.has_key("value"): if attrs.has_key("value"):
self.pb.value = attrs["value"] self.token_b.value = attrs["value"]
def endElement(self, name): def endElement(self, name):
if name in ["register", "immediate", "label", "address", "hidden"]: if name == "token":
if self.fb != None: self.syntax_b.tokens.append(self.token_b.get())
self.fb.params.append(self.pb.get())
else:
self.sb.params.append(self.pb.get())
elif name == "syntax": elif name == "syntax":
self.ib.syntaxes.append(self.sb.get()) self.inst_b.syntaxes.append(self.syntax_b.get())
if name == "attribute":
self.format_b.attributes.append(self.attr_b.get())
elif name == "format": elif name == "format":
self.ib.format = self.fb.get() self.inst_b.format = self.format_b.get()
self.fb = None elif name == "description":
self.inst_b.desc = self.content
elif name == "instruction": elif name == "instruction":
self.instructions.append(self.ib.get()) self.instructions.append(self.inst_b.get())
def characters (self, content):
self.content = self.content + content
class InstructionSetParser: class InstructionSetParser:
......
This diff is collapsed.
...@@ -155,7 +155,7 @@ for inst in instructions: ...@@ -155,7 +155,7 @@ for inst in instructions:
## Build paths from params ## Build paths from params
paths = [] paths = []
for param in syntax.params: for param in syntax.tokens:
token = token_map[param.kind] token = token_map[param.kind]
if param.kind == "address": if param.kind == "address":
paths.append(["LPAREN"]) paths.append(["LPAREN"])
......
...@@ -22,7 +22,7 @@ import sys ...@@ -22,7 +22,7 @@ import sys
import string, re import string, re
import mipsy import mipsy
from mipsy import license, depth, define_id from mipsy import license, define_id
parser = mipsy.InstructionSetParser() parser = mipsy.InstructionSetParser()
instructions = parser.parse(sys.stdin) instructions = parser.parse(sys.stdin)
......
...@@ -2,25 +2,29 @@ ...@@ -2,25 +2,29 @@
(Created-By-Prcs-Version 1 3 2) (Created-By-Prcs-Version 1 3 2)
(Project-Description "") (Project-Description "")
(Project-Version mipsy 0 60) (Project-Version mipsy 0 61)
(Parent-Version mipsy 0 59) (Parent-Version mipsy 0 60)
(Version-Log (Version-Log
"Index: ChangeLog "Index: ChangeLog
--- ChangeLog Thu, 08 Jan 2004 14:42:41 +0100 noe (mipsy/2_ChangeLog 1.53 604) --- ChangeLog Thu, 08 Jan 2004 15:27:18 +0100 noe (mipsy/2_ChangeLog 1.54 604)
+++ ChangeLog Thu, 08 Jan 2004 15:24:49 +0100 noe (mipsy/2_ChangeLog 1.53 604) +++ ChangeLog Sat, 10 Jan 2004 22:21:15 +0100 noe (mipsy/2_ChangeLog 1.54 604)
@@ -1,5 +1,11 @@ @@ -1,3 +1,13 @@
2004-01-08 Benot Perrot <benoit@lrde.epita.fr> +2004-01-10 Benot Perrot <benoit@lrde.epita.fr>
+
+ * dev/parse-asm-scan.py: Simplify scanner register generation. + * dev/mipsy.xml: Use a better DTD.
+ * dev/mipsy.py: Remove useless accessors. Use a '__str__' method + * dev/mipsy.py: Use new DTD.
+ instead of 'display'. + * 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 "Thu, 08 Jan 2004 15:27:18 +0100") (Checkin-Time "Sat, 10 Jan 2004 22:25:29 +0100")
(Checkin-Login noe) (Checkin-Login noe)
(Files (Files
...@@ -28,7 +32,7 @@ ...@@ -28,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.54 604)) (ChangeLog (mipsy/2_ChangeLog 1.55 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))
...@@ -41,13 +45,13 @@ ...@@ -41,13 +45,13 @@
(config/Makefile.am (mipsy/7_Makefile.a 1.1 604)) (config/Makefile.am (mipsy/7_Makefile.a 1.1 604))
;; ./dev/ ;; ./dev/
(dev/inst-builder-gen.py (mipsy/15_mipsy-buil 1.6 705)) (dev/inst-builder-gen.py (mipsy/15_mipsy-buil 1.7 705))
(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.3 705)) (dev/inst-nodes-gen.py (mipsy/12_mipsy-inst 1.4 705))
(dev/mipsy.py (mipsy/16_mipsy.py 1.6 604)) (dev/mipsy.py (mipsy/16_mipsy.py 1.7 705))
(dev/mipsy.xml (mipsy/17_mipsy.xml 1.11 604)) (dev/mipsy.xml (mipsy/17_mipsy.xml 1.12 604))
(dev/parse-asm-parse-gen.py (mipsy/13_mipsy-pars 1.5 705)) (dev/parse-asm-parse-gen.py (mipsy/13_mipsy-pars 1.6 705))
(dev/parse-asm-scan-gen.py (mipsy/14_mipsy-scan 1.8 705)) (dev/parse-asm-scan-gen.py (mipsy/14_mipsy-scan 1.9 705))
;; ./doc/ ;; ./doc/
(doc/Makefile.am (mipsy/b/9_Makefile.a 1.1 604)) (doc/Makefile.am (mipsy/b/9_Makefile.a 1.1 604))
......
Markdown is supported
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