microasm.isa (4349:b223256d0a79) microasm.isa (4371:c5003760793e)
1// -*- mode:c++ -*-
2
3// Copyright (c) 2007 The Hewlett-Packard Development Company
4// All rights reserved.
5//
6// Redistribution and use of this software in source and binary forms,
7// with or without modification, are permitted provided that the
8// following conditions are met:

--- 71 unchanged lines hidden (view full) ---

80 text = ""
81 for val in vals:
82 if val:
83 text += ", true"
84 else:
85 text += ", false"
86 return text
87
1// -*- mode:c++ -*-
2
3// Copyright (c) 2007 The Hewlett-Packard Development Company
4// All rights reserved.
5//
6// Redistribution and use of this software in source and binary forms,
7// with or without modification, are permitted provided that the
8// following conditions are met:

--- 71 unchanged lines hidden (view full) ---

80 text = ""
81 for val in vals:
82 if val:
83 text += ", true"
84 else:
85 text += ", false"
86 return text
87
88 def getAllocator(self, *microFlags):
88 def getAllocator(self, mnemonic, *microFlags):
89 args = ''
90 signature = "<"
91 emptySig = True
92 for arg in self.args:
93 if not emptySig:
94 signature += ", "
95 emptySig = False
96 if arg.has_key("operandImm"):
97 args += ", %s" % arg["operandImm"]
98 signature += ImmOpType
99 elif arg.has_key("operandReg"):
100 args += ", %s" % arg["operandReg"]
101 signature += RegOpType
102 elif arg.has_key("operandLabel"):
103 raise Exception, "Found a label while creating allocator string."
104 else:
105 raise Exception, "Unrecognized operand type."
106 signature += ">"
89 args = ''
90 signature = "<"
91 emptySig = True
92 for arg in self.args:
93 if not emptySig:
94 signature += ", "
95 emptySig = False
96 if arg.has_key("operandImm"):
97 args += ", %s" % arg["operandImm"]
98 signature += ImmOpType
99 elif arg.has_key("operandReg"):
100 args += ", %s" % arg["operandReg"]
101 signature += RegOpType
102 elif arg.has_key("operandLabel"):
103 raise Exception, "Found a label while creating allocator string."
104 else:
105 raise Exception, "Unrecognized operand type."
106 signature += ">"
107 return 'new %s%s(machInst%s%s)' % (self.className, signature, self.microFlagsText(microFlags), args)
107 return 'new %s%s(machInst, %s%s%s)' % (self.className, signature, mnemonic, self.microFlagsText(microFlags), args)
108}};
109
110let{{
111 def assembleMicro(name, Name, code):
112
113 # This function takes in a block of microcode assembly and returns
114 # a python list of objects which describe it.
115
116 # Keep this around in case we need it later
117 orig_code = code
118 # A list of the statements we've found thus far
119 statements = []
120
121 # Regular expressions to pull each piece of the statement out at a
122 # time. Each expression expects the thing it's looking for to be at
123 # the beginning of the line, so the previous component is stripped
124 # before continuing.
125 labelRe = re.compile(r'^[ \t]*(?P<label>\w\w*)[ \t]:')
108}};
109
110let{{
111 def assembleMicro(name, Name, code):
112
113 # This function takes in a block of microcode assembly and returns
114 # a python list of objects which describe it.
115
116 # Keep this around in case we need it later
117 orig_code = code
118 # A list of the statements we've found thus far
119 statements = []
120
121 # Regular expressions to pull each piece of the statement out at a
122 # time. Each expression expects the thing it's looking for to be at
123 # the beginning of the line, so the previous component is stripped
124 # before continuing.
125 labelRe = re.compile(r'^[ \t]*(?P<label>\w\w*)[ \t]:')
126 lineRe = re.compile(r'^(?P<line>[^\n][^\n]*)$')
126 lineRe = re.compile(r'^(?P<line>..*)(\n|$)')
127 classRe = re.compile(r'^[ \t]*(?P<className>[a-zA-Z_]\w*)')
128 # This recognizes three different flavors of operands:
129 # 1. Raw decimal numbers composed of digits between 0 and 9
130 # 2. Code beginning with "{" and continuing until the first "}"
131 # ^ This one might need revising
132 # 3. A label, which starts with a capital or small letter, or
133 # underscore, which is optionally followed by a sequence of
134 # capital or small letters, underscores, or digts between 0 and 9

--- 5 unchanged lines hidden (view full) ---

140 r'(\$(?P<operandImm0>\w\w*))|' +
141 r'(\$\{(?P<operandImm1>[^}]*)\}))')
142 lineMatch = lineRe.search(code)
143 while lineMatch != None:
144 statement = MicroOpStatement()
145 # Get a line and seperate it from the rest of the code
146 line = lineMatch.group("line")
147 orig_line = line
127 classRe = re.compile(r'^[ \t]*(?P<className>[a-zA-Z_]\w*)')
128 # This recognizes three different flavors of operands:
129 # 1. Raw decimal numbers composed of digits between 0 and 9
130 # 2. Code beginning with "{" and continuing until the first "}"
131 # ^ This one might need revising
132 # 3. A label, which starts with a capital or small letter, or
133 # underscore, which is optionally followed by a sequence of
134 # capital or small letters, underscores, or digts between 0 and 9

--- 5 unchanged lines hidden (view full) ---

140 r'(\$(?P<operandImm0>\w\w*))|' +
141 r'(\$\{(?P<operandImm1>[^}]*)\}))')
142 lineMatch = lineRe.search(code)
143 while lineMatch != None:
144 statement = MicroOpStatement()
145 # Get a line and seperate it from the rest of the code
146 line = lineMatch.group("line")
147 orig_line = line
148 # print "Parsing line %s" % line
148 #print "Parsing line %s" % line
149 code = lineRe.sub('', code, 1)
150
151 # Find the label, if any
152 labelMatch = labelRe.search(line)
153 if labelMatch != None:
154 statement.label = labelMatch.group("label")
149 code = lineRe.sub('', code, 1)
150
151 # Find the label, if any
152 labelMatch = labelRe.search(line)
153 if labelMatch != None:
154 statement.label = labelMatch.group("label")
155 # print "Found label %s." % statement.label
155 #print "Found label %s." % statement.label
156 # Clear the label from the statement
157 line = labelRe.sub('', line, 1)
158
159 # Find the class name which is roughly equivalent to the op name
160 classMatch = classRe.search(line)
161 if classMatch == None:
162 raise Exception, "Couldn't find class name in statement: %s" \
163 % orig_line
164 else:
165 statement.className = classMatch.group("className")
156 # Clear the label from the statement
157 line = labelRe.sub('', line, 1)
158
159 # Find the class name which is roughly equivalent to the op name
160 classMatch = classRe.search(line)
161 if classMatch == None:
162 raise Exception, "Couldn't find class name in statement: %s" \
163 % orig_line
164 else:
165 statement.className = classMatch.group("className")
166 # print "Found class name %s." % statement.className
166 #print "Found class name %s." % statement.className
167
168 # Clear the class name from the statement
169 line = classRe.sub('', line, 1)
170
171 #Find as many arguments as you can
172 statement.args = []
173 opMatch = opRe.search(line)
174 while opMatch is not None:

--- 5 unchanged lines hidden (view full) ---

180 for opType in ("operandLabel0", "operandReg0", "operandImm0",
181 "operandLabel1", "operandReg1", "operandImm1"):
182 if opMatch.group(opType):
183 statement.args[-1][opType[:-1]] = opMatch.group(opType)
184 if len(statement.args[-1]) == 0:
185 print "Problem parsing operand in statement: %s" \
186 % orig_line
187 line = opRe.sub('', line, 1)
167
168 # Clear the class name from the statement
169 line = classRe.sub('', line, 1)
170
171 #Find as many arguments as you can
172 statement.args = []
173 opMatch = opRe.search(line)
174 while opMatch is not None:

--- 5 unchanged lines hidden (view full) ---

180 for opType in ("operandLabel0", "operandReg0", "operandImm0",
181 "operandLabel1", "operandReg1", "operandImm1"):
182 if opMatch.group(opType):
183 statement.args[-1][opType[:-1]] = opMatch.group(opType)
184 if len(statement.args[-1]) == 0:
185 print "Problem parsing operand in statement: %s" \
186 % orig_line
187 line = opRe.sub('', line, 1)
188 # print "Found operand %s." % statement.args[-1]
188 #print "Found operand %s." % statement.args[-1]
189 opMatch = opRe.search(line)
189 opMatch = opRe.search(line)
190 # print "Found operands", statement.args
190 #print "Found operands", statement.args
191
192 # Add this statement to our collection
193 statements.append(statement)
194
195 # Get the next line
196 lineMatch = lineRe.search(code)
197
198 # Decode the labels into displacements

--- 11 unchanged lines hidden (view full) ---

210 if not labels.has_key(arg["operandLabel"]):
211 raise Exception, "Unrecognized label: %s." % arg["operandLabel"]
212 # This is assuming that intra microcode branches go to
213 # the next micropc + displacement, or
214 # micropc + 1 + displacement.
215 arg["operandImm"] = labels[arg["operandLabel"]] - micropc - 1
216 micropc += 1
217
191
192 # Add this statement to our collection
193 statements.append(statement)
194
195 # Get the next line
196 lineMatch = lineRe.search(code)
197
198 # Decode the labels into displacements

--- 11 unchanged lines hidden (view full) ---

210 if not labels.has_key(arg["operandLabel"]):
211 raise Exception, "Unrecognized label: %s." % arg["operandLabel"]
212 # This is assuming that intra microcode branches go to
213 # the next micropc + displacement, or
214 # micropc + 1 + displacement.
215 arg["operandImm"] = labels[arg["operandLabel"]] - micropc - 1
216 micropc += 1
217
218 if len(statements) == 0:
219 raise Exception, "Didn't find any microops in microcode: \n%s" % orig_code
220
218 # If we can implement this instruction with exactly one microop, just
219 # use that directly.
220 if len(statements) == 1:
221 decode_block = "return %s;" % \
221 # If we can implement this instruction with exactly one microop, just
222 # use that directly.
223 if len(statements) == 1:
224 decode_block = "return %s;" % \
222 statements[0].getAllocator()
225 statements[0].getAllocator('"' + name + '"')
223 return ('', '', decode_block, '')
224 else:
225 # Build a macroop to contain the sequence of microops we've
226 # been given.
227 return genMacroOp(name, Name, statements)
228}};
226 return ('', '', decode_block, '')
227 else:
228 # Build a macroop to contain the sequence of microops we've
229 # been given.
230 return genMacroOp(name, Name, statements)
231}};