Deleted Added
sdiff udiff text old ( 3953:300d526414e6 ) new ( 3954:d689b611d9dc )
full compact
1# Copyright (c) 2003-2005 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

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

1012 myDict = None
1013
1014 # Protect non-Python-dict substitutions (e.g. if there's a printf
1015 # in the templated C++ code)
1016 template = protect_non_subst_percents(self.template)
1017 # CPU-model-specific substitutions are handled later (in GenCode).
1018 template = protect_cpu_symbols(template)
1019
1020 # if we're dealing with an InstObjParams object, we need to be a
1021 # little more sophisticated. Otherwise, just do what we've always
1022 # done
1023 if isinstance(d, InstObjParams):
1024 # The instruction wide parameters are already formed, but the
1025 # parameters which are only function wide still need to be
1026 # generated.
1027 perFuncNames = ['op_decl', 'op_src_decl', 'op_dest_decl', \
1028 'op_rd', 'op_wb', 'mem_acc_size', 'mem_acc_type']
1029 compositeCode = ''
1030
1031 myDict = templateMap.copy()
1032 myDict.update(d.__dict__)
1033 # The "operands" and "snippets" attributes of the InstObjParams
1034 # objects are for internal use and not substitution.
1035 del myDict['operands']
1036 del myDict['snippets']
1037
1038 for name in labelRE.findall(template):
1039 # Don't try to find a snippet to go with things that will
1040 # match against attributes of d, or that are other templates,
1041 # or that we're going to generate later, or that we've already
1042 # found.
1043 if not hasattr(d, name) and \
1044 not templateMap.has_key(name) and \
1045 not myDict.has_key(name) and \
1046 name not in perFuncNames:
1047 myDict[name] = d.snippets[name]
1048 if isinstance(myDict[name], str):
1049 myDict[name] = substMungedOpNames(substBitOps(myDict[name]))
1050 compositeCode += (" " + myDict[name])
1051
1052 compositeCode += (" " + template)
1053
1054 operands = SubOperandList(compositeCode, d.operands)
1055
1056 myDict['op_decl'] = operands.concatAttrStrings('op_decl')
1057
1058 is_src = lambda op: op.is_src
1059 is_dest = lambda op: op.is_dest
1060
1061 myDict['op_src_decl'] = \
1062 operands.concatSomeAttrStrings(is_src, 'op_src_decl')
1063 myDict['op_dest_decl'] = \
1064 operands.concatSomeAttrStrings(is_dest, 'op_dest_decl')
1065
1066 myDict['op_rd'] = operands.concatAttrStrings('op_rd')
1067 myDict['op_wb'] = operands.concatAttrStrings('op_wb')
1068
1069 if d.operands.memOperand:
1070 myDict['mem_acc_size'] = d.operands.memOperand.mem_acc_size
1071 myDict['mem_acc_type'] = d.operands.memOperand.mem_acc_type
1072
1073 else:
1074 # Start with the template namespace. Make a copy since we're
1075 # going to modify it.
1076 myDict = templateMap.copy()
1077 # if the argument is a dictionary, we just use it.
1078 if isinstance(d, dict):
1079 myDict.update(d)
1080 # if the argument is an object, we use its attribute map.
1081 elif hasattr(d, '__dict__'):
1082 myDict.update(d.__dict__)
1083 else:
1084 raise TypeError, "Template.subst() arg must be or have dictionary"
1085 return template % myDict
1086
1087 # Convert to string. This handles the case when a template with a
1088 # CPU-specific term gets interpolated into another template or into
1089 # an output block.
1090 def __str__(self):
1091 return expand_cpu_symbols_to_string(self.template)
1092

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

1660assignRE = re.compile(r'\s*=(?!=)', re.MULTILINE)
1661
1662# Munge operand names in code string to make legal C++ variable names.
1663# This means getting rid of the type extension if any.
1664# (Will match base_name attribute of Operand object.)
1665def substMungedOpNames(code):
1666 return operandsWithExtRE.sub(r'\1', code)
1667
1668def joinLists(t):
1669 return map(string.join, t)
1670
1671def makeFlagConstructor(flag_list):
1672 if len(flag_list) == 0:
1673 return ''
1674 # filter out repeated flags
1675 flag_list.sort()
1676 i = 1
1677 while i < len(flag_list):

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

1687# Assume all instruction flags are of the form 'IsFoo'
1688instFlagRE = re.compile(r'Is.*')
1689
1690# OpClass constants end in 'Op' except No_OpClass
1691opClassRE = re.compile(r'.*Op|No_OpClass')
1692
1693class InstObjParams:
1694 def __init__(self, mnem, class_name, base_class = '',
1695 snippets = None, opt_args = []):
1696 self.mnemonic = mnem
1697 self.class_name = class_name
1698 self.base_class = base_class
1699 compositeCode = ''
1700 if snippets:
1701 if not isinstance(snippets, dict):
1702 snippets = {'code' : snippets}
1703 for snippet in snippets.values():
1704 if isinstance(snippet, str):
1705 compositeCode += (" " + snippet)
1706 self.snippets = snippets
1707
1708 self.operands = OperandList(compositeCode)
1709 self.constructor = self.operands.concatAttrStrings('constructor')
1710 self.constructor += \
1711 '\n\t_numSrcRegs = %d;' % self.operands.numSrcRegs
1712 self.constructor += \
1713 '\n\t_numDestRegs = %d;' % self.operands.numDestRegs

--- 174 unchanged lines hidden ---