Deleted Added
sdiff udiff text old ( 3841:9fe36a649632 ) new ( 3949:b6664282d899 )
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

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

803
804################
805# Format object.
806#
807# A format object encapsulates an instruction format. It must provide
808# a defineInst() method that generates the code for an instruction
809# definition.
810
811exportContextSymbols = ('InstObjParams', 'CodeBlock',
812 'makeList', 're', 'string')
813
814exportContext = {}
815
816def updateExportContext():
817 exportContext.update(exportDict(*exportContextSymbols))
818 exportContext.update(templateMap)
819
820def exportDict(*symNames):

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

998
999
1000####################
1001# Template objects.
1002#
1003# Template objects are format strings that allow substitution from
1004# the attribute spaces of other objects (e.g. InstObjParams instances).
1005
1006class Template:
1007 def __init__(self, t):
1008 self.template = t
1009
1010 def subst(self, d):
1011 # Start with the template namespace. Make a copy since we're
1012 # going to modify it.
1013 myDict = templateMap.copy()
1014 # if the argument is a dictionary, we just use it.
1015 if isinstance(d, dict):
1016 myDict.update(d)
1017 # if the argument is an object, we use its attribute map.
1018 elif hasattr(d, '__dict__'):
1019 myDict.update(d.__dict__)
1020 else:
1021 raise TypeError, "Template.subst() arg must be or have dictionary"
1022 # Protect non-Python-dict substitutions (e.g. if there's a printf
1023 # in the templated C++ code)
1024 template = protect_non_subst_percents(self.template)
1025 # CPU-model-specific substitutions are handled later (in GenCode).
1026 template = protect_cpu_symbols(template)
1027 return template % myDict
1028
1029 # Convert to string. This handles the case when a template with a
1030 # CPU-specific term gets interpolated into another template or into
1031 # an output block.
1032 def __str__(self):
1033 return expand_cpu_symbols_to_string(self.template)
1034

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

1291 return 1
1292
1293 def isControlReg(self):
1294 return 1
1295
1296 def makeConstructor(self):
1297 c = ''
1298 if self.is_src:
1299 c += '\n\t_srcRegIdx[%d] = %s;' % \
1300 (self.src_reg_idx, self.reg_spec)
1301 if self.is_dest:
1302 c += '\n\t_destRegIdx[%d] = %s;' % \
1303 (self.dest_reg_idx, self.reg_spec)
1304 return c
1305
1306 def makeRead(self):
1307 bit_select = 0
1308 if (self.ctype == 'float' or self.ctype == 'double'):
1309 error(0, 'Attempt to read control register as FP')
1310 base = 'xc->readMiscRegWithEffect(%s)' % self.reg_spec
1311 if self.size == self.dflt_size:
1312 return '%s = %s;\n' % (self.base_name, base)
1313 else:
1314 return '%s = bits(%s, %d, 0);\n' % \
1315 (self.base_name, base, self.size-1)
1316
1317 def makeWrite(self):
1318 if (self.ctype == 'float' or self.ctype == 'double'):
1319 error(0, 'Attempt to write control register as FP')
1320 wb = 'xc->setMiscRegWithEffect(%s, %s);\n' % (self.reg_spec, self.base_name)
1321 wb += 'if (traceData) { traceData->setData(%s); }' % \
1322 self.base_name
1323 return wb
1324
1325class MemOperand(Operand):
1326 def isMem(self):
1327 return 1
1328

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

1545 # like concatAttrLists, but only include the values for the operands
1546 # for which the provided filter function returns true
1547 def concatSomeAttrLists(self, filter, attr_name):
1548 return self.__internalConcatAttrs(attr_name, filter, [])
1549
1550 def sort(self):
1551 self.items.sort(lambda a, b: a.sort_pri - b.sort_pri)
1552
1553# Regular expression object to match C++ comments
1554# (used in findOperands())
1555commentRE = re.compile(r'//.*\n')
1556
1557# Regular expression object to match assignment statements
1558# (used in findOperands())
1559assignRE = re.compile(r'\s*=(?!=)', re.MULTILINE)
1560

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

1578 del flag_list[i]
1579 else:
1580 i += 1
1581 pre = '\n\tflags['
1582 post = '] = true;'
1583 code = pre + string.join(flag_list, post + pre) + post
1584 return code
1585
1586class CodeBlock:
1587 def __init__(self, code):
1588 self.orig_code = code
1589 self.operands = OperandList(code)
1590 self.code = substMungedOpNames(substBitOps(code))
1591 self.constructor = self.operands.concatAttrStrings('constructor')
1592 self.constructor += \
1593 '\n\t_numSrcRegs = %d;' % self.operands.numSrcRegs
1594 self.constructor += \
1595 '\n\t_numDestRegs = %d;' % self.operands.numDestRegs
1596 self.constructor += \
1597 '\n\t_numFPDestRegs = %d;' % self.operands.numFPDestRegs
1598 self.constructor += \
1599 '\n\t_numIntDestRegs = %d;' % self.operands.numIntDestRegs
1600
1601 self.op_decl = self.operands.concatAttrStrings('op_decl')
1602
1603 is_src = lambda op: op.is_src
1604 is_dest = lambda op: op.is_dest
1605
1606 self.op_src_decl = \
1607 self.operands.concatSomeAttrStrings(is_src, 'op_src_decl')
1608 self.op_dest_decl = \
1609 self.operands.concatSomeAttrStrings(is_dest, 'op_dest_decl')
1610
1611 self.op_rd = self.operands.concatAttrStrings('op_rd')
1612 self.op_wb = self.operands.concatAttrStrings('op_wb')
1613
1614 self.flags = self.operands.concatAttrLists('flags')
1615
1616 if self.operands.memOperand:
1617 self.mem_acc_size = self.operands.memOperand.mem_acc_size
1618 self.mem_acc_type = self.operands.memOperand.mem_acc_type
1619
1620 # Make a basic guess on the operand class (function unit type).
1621 # These are good enough for most cases, and will be overridden
1622 # later otherwise.
1623 if 'IsStore' in self.flags:
1624 self.op_class = 'MemWriteOp'
1625 elif 'IsLoad' in self.flags or 'IsPrefetch' in self.flags:
1626 self.op_class = 'MemReadOp'
1627 elif 'IsFloating' in self.flags:
1628 self.op_class = 'FloatAddOp'
1629 else:
1630 self.op_class = 'IntAluOp'
1631
1632# Assume all instruction flags are of the form 'IsFoo'
1633instFlagRE = re.compile(r'Is.*')
1634
1635# OpClass constants end in 'Op' except No_OpClass
1636opClassRE = re.compile(r'.*Op|No_OpClass')
1637
1638class InstObjParams:
1639 def __init__(self, mnem, class_name, base_class = '',
1640 code = None, opt_args = [], extras = {}):
1641 self.mnemonic = mnem
1642 self.class_name = class_name
1643 self.base_class = base_class
1644 if code:
1645 #If the user already made a CodeBlock, pick the parts from it
1646 if isinstance(code, CodeBlock):
1647 origCode = code.orig_code
1648 codeBlock = code
1649 else:
1650 origCode = code
1651 codeBlock = CodeBlock(code)
1652 stringExtras = {}
1653 otherExtras = {}
1654 for (k, v) in extras.items():
1655 if type(v) == str:
1656 stringExtras[k] = v
1657 else:
1658 otherExtras[k] = v
1659 compositeCode = "\n".join([origCode] + stringExtras.values())
1660 # compositeCode = '\n'.join([origCode] +
1661 # [pair[1] for pair in extras])
1662 compositeBlock = CodeBlock(compositeCode)
1663 for code_attr in compositeBlock.__dict__.keys():
1664 setattr(self, code_attr, getattr(compositeBlock, code_attr))
1665 for (key, snippet) in stringExtras.items():
1666 setattr(self, key, CodeBlock(snippet).code)
1667 for (key, item) in otherExtras.items():
1668 setattr(self, key, item)
1669 self.code = codeBlock.code
1670 self.orig_code = origCode
1671 else:
1672 self.constructor = ''
1673 self.flags = []
1674 # Optional arguments are assumed to be either StaticInst flags
1675 # or an OpClass value. To avoid having to import a complete
1676 # list of these values to match against, we do it ad-hoc
1677 # with regexps.
1678 for oa in opt_args:
1679 if instFlagRE.match(oa):
1680 self.flags.append(oa)
1681 elif opClassRE.match(oa):

--- 148 unchanged lines hidden ---