811,812c811
< exportContextSymbols = ('InstObjParams', 'CodeBlock',
< 'makeList', 're', 'string')
---
> exportContextSymbols = ('InstObjParams', 'makeList', 're', 'string')
1005a1005,1006
> labelRE = re.compile(r'[^%]%\(([^\)]+)\)[sd]')
>
1011,1021c1012,1013
< # Start with the template namespace. Make a copy since we're
< # going to modify it.
< myDict = templateMap.copy()
< # if the argument is a dictionary, we just use it.
< if isinstance(d, dict):
< myDict.update(d)
< # if the argument is an object, we use its attribute map.
< elif hasattr(d, '__dict__'):
< myDict.update(d.__dict__)
< else:
< raise TypeError, "Template.subst() arg must be or have dictionary"
---
> myDict = None
>
1026a1019,1081
>
> # if we're dealing with an InstObjParams object, we need to be a
> # little more sophisticated. Otherwise, just do what we've always
> # done
> if isinstance(d, InstObjParams):
> # The instruction wide parameters are already formed, but the
> # parameters which are only function wide still need to be
> # generated.
> perFuncNames = ['op_decl', 'op_src_decl', 'op_dest_decl', \
> 'op_rd', 'op_wb', 'mem_acc_size', 'mem_acc_type']
> compositeCode = ''
>
> myDict = templateMap.copy()
> myDict.update(d.__dict__)
> # The "operands" and "snippets" attributes of the InstObjParams
> # objects are for internal use and not substitution.
> del myDict['operands']
> del myDict['snippets']
>
> for name in labelRE.findall(template):
> # Don't try to find a snippet to go with things that will
> # match against attributes of d, or that are other templates,
> # or that we're going to generate later, or that we've already
> # found.
> if not hasattr(d, name) and \
> not templateMap.has_key(name) and \
> not myDict.has_key(name) and \
> name not in perFuncNames:
> myDict[name] = d.snippets[name]
> if isinstance(myDict[name], str):
> myDict[name] = substMungedOpNames(substBitOps(myDict[name]))
> compositeCode += (" " + myDict[name])
> operands = SubOperandList(compositeCode, d.operands)
>
> myDict['op_decl'] = operands.concatAttrStrings('op_decl')
>
> is_src = lambda op: op.is_src
> is_dest = lambda op: op.is_dest
>
> myDict['op_src_decl'] = \
> operands.concatSomeAttrStrings(is_src, 'op_src_decl')
> myDict['op_dest_decl'] = \
> operands.concatSomeAttrStrings(is_dest, 'op_dest_decl')
>
> myDict['op_rd'] = operands.concatAttrStrings('op_rd')
> myDict['op_wb'] = operands.concatAttrStrings('op_wb')
>
> if d.operands.memOperand:
> myDict['mem_acc_size'] = d.operands.memOperand.mem_acc_size
> myDict['mem_acc_type'] = d.operands.memOperand.mem_acc_type
>
> else:
> # Start with the template namespace. Make a copy since we're
> # going to modify it.
> myDict = templateMap.copy()
> # if the argument is a dictionary, we just use it.
> if isinstance(d, dict):
> myDict.update(d)
> # if the argument is an object, we use its attribute map.
> elif hasattr(d, '__dict__'):
> myDict.update(d.__dict__)
> else:
> raise TypeError, "Template.subst() arg must be or have dictionary"
1299c1354
< c += '\n\t_srcRegIdx[%d] = %s;' % \
---
> c += '\n\t_srcRegIdx[%d] = %s + Ctrl_Base_DepTag;' % \
1302c1357
< c += '\n\t_destRegIdx[%d] = %s;' % \
---
> c += '\n\t_destRegIdx[%d] = %s + Ctrl_Base_DepTag;' % \
1310c1365
< base = 'xc->readMiscReg(%s)' % self.reg_spec
---
> base = 'xc->readMiscRegOperand(this, %s)' % self.src_reg_idx
1320c1375,1376
< wb = 'xc->setMiscRegWithEffect(%s, %s);\n' % (self.reg_spec, self.base_name)
---
> wb = 'xc->setMiscRegOperandWithEffect(this, %s, %s);\n' % \
> (self.dest_reg_idx, self.base_name)
1552a1609,1650
> class SubOperandList(OperandList):
>
> # Find all the operands in the given code block. Returns an operand
> # descriptor list (instance of class OperandList).
> def __init__(self, code, master_list):
> self.items = []
> self.bases = {}
> # delete comments so we don't match on reg specifiers inside
> code = commentRE.sub('', code)
> # search for operands
> next_pos = 0
> while 1:
> match = operandsRE.search(code, next_pos)
> if not match:
> # no more matches: we're done
> break
> op = match.groups()
> # regexp groups are operand full name, base, and extension
> (op_full, op_base, op_ext) = op
> # find this op in the master list
> op_desc = master_list.find_base(op_base)
> if not op_desc:
> error(0, 'Found operand %s which is not in the master list!' \
> ' This is an internal error' % \
> op_base)
> else:
> # See if we've already found this operand
> op_desc = self.find_base(op_base)
> if not op_desc:
> # if not, add a reference to it to this sub list
> self.append(master_list.bases[op_base])
>
> # start next search after end of current match
> next_pos = match.end()
> self.sort()
> self.memOperand = None
> for op_desc in self.items:
> if op_desc.isMem():
> if self.memOperand:
> error(0, "Code block has more than one memory operand.")
> self.memOperand = op_desc
>
1586,1590c1684,1705
< class CodeBlock:
< def __init__(self, code):
< self.orig_code = code
< self.operands = OperandList(code)
< self.code = substMungedOpNames(substBitOps(code))
---
> # Assume all instruction flags are of the form 'IsFoo'
> instFlagRE = re.compile(r'Is.*')
>
> # OpClass constants end in 'Op' except No_OpClass
> opClassRE = re.compile(r'.*Op|No_OpClass')
>
> class InstObjParams:
> def __init__(self, mnem, class_name, base_class = '',
> snippets = None, opt_args = []):
> self.mnemonic = mnem
> self.class_name = class_name
> self.base_class = base_class
> compositeCode = ''
> if snippets:
> if not isinstance(snippets, dict):
> snippets = {'code' : snippets}
> for snippet in snippets.values():
> if isinstance(snippet, str):
> compositeCode += (" " + snippet)
> self.snippets = snippets
>
> self.operands = OperandList(compositeCode)
1600,1613d1714
<
< self.op_decl = self.operands.concatAttrStrings('op_decl')
<
< is_src = lambda op: op.is_src
< is_dest = lambda op: op.is_dest
<
< self.op_src_decl = \
< self.operands.concatSomeAttrStrings(is_src, 'op_src_decl')
< self.op_dest_decl = \
< self.operands.concatSomeAttrStrings(is_dest, 'op_dest_decl')
<
< self.op_rd = self.operands.concatAttrStrings('op_rd')
< self.op_wb = self.operands.concatAttrStrings('op_wb')
<
1616,1619d1716
< if self.operands.memOperand:
< self.mem_acc_size = self.operands.memOperand.mem_acc_size
< self.mem_acc_type = self.operands.memOperand.mem_acc_type
<
1621c1718
< # These are good enough for most cases, and will be overridden
---
> # These are good enough for most cases, and can be overridden
1632,1673d1728
< # Assume all instruction flags are of the form 'IsFoo'
< instFlagRE = re.compile(r'Is.*')
<
< # OpClass constants end in 'Op' except No_OpClass
< opClassRE = re.compile(r'.*Op|No_OpClass')
<
< class InstObjParams:
< def __init__(self, mnem, class_name, base_class = '',
< code = None, opt_args = [], extras = {}):
< self.mnemonic = mnem
< self.class_name = class_name
< self.base_class = base_class
< if code:
< #If the user already made a CodeBlock, pick the parts from it
< if isinstance(code, CodeBlock):
< origCode = code.orig_code
< codeBlock = code
< else:
< origCode = code
< codeBlock = CodeBlock(code)
< stringExtras = {}
< otherExtras = {}
< for (k, v) in extras.items():
< if type(v) == str:
< stringExtras[k] = v
< else:
< otherExtras[k] = v
< compositeCode = "\n".join([origCode] + stringExtras.values())
< # compositeCode = '\n'.join([origCode] +
< # [pair[1] for pair in extras])
< compositeBlock = CodeBlock(compositeCode)
< for code_attr in compositeBlock.__dict__.keys():
< setattr(self, code_attr, getattr(compositeBlock, code_attr))
< for (key, snippet) in stringExtras.items():
< setattr(self, key, CodeBlock(snippet).code)
< for (key, item) in otherExtras.items():
< setattr(self, key, item)
< self.code = codeBlock.code
< self.orig_code = origCode
< else:
< self.constructor = ''
< self.flags = []