125,126d124
< # CPU-model-specific substitutions are handled later (in GenCode).
< template = self.parser.protectCpuSymbols(template)
221,223c219
< # Convert to string. This handles the case when a template with a
< # CPU-specific term gets interpolated into another template or into
< # an output block.
---
> # Convert to string.
225c221
< return self.parser.expandCpuSymbolsToString(self.template)
---
> return self.template
287,291c283,285
< # decoder.cc). The exec_output attribute is a dictionary with a key
< # for each CPU model name; the value associated with a particular key
< # is the string of code for that CPU model's exec.cc file. The
< # has_decode_default attribute is used in the decode block to allow
< # explicit default clauses to override default default clauses.
---
> # decoder.cc). The exec_output attribute is the string of code for the
> # exec.cc file. The has_decode_default attribute is used in the decode block
> # to allow explicit default clauses to override default default clauses.
294,297c288
< # Constructor. At this point we substitute out all CPU-specific
< # symbols. For the exec output, these go into the per-model
< # dictionary. For all other output types they get collapsed into
< # a single string.
---
> # Constructor.
302,303c293,294
< self.header_output = parser.expandCpuSymbolsToString(header_output)
< self.decoder_output = parser.expandCpuSymbolsToString(decoder_output)
---
> self.header_output = header_output
> self.decoder_output = decoder_output
1465,1471d1455
< class CpuModel(object):
< def __init__(self, name, filename, includes, strings):
< self.name = name
< self.filename = filename
< self.includes = includes
< self.strings = strings
<
1478,1484d1461
< self.cpuModels = [
< ISAParser.CpuModel('ExecContext',
< 'generic_cpu_exec.cc',
< '#include "cpu/exec_context.hh"',
< { "CPU_exec_context" : "ExecContext" }),
< ]
<
1628c1605
< # instruction execution per-CPU model
---
> # instruction execution
1630,1631c1607,1620
< for cpu in self.cpuModels:
< for i in range(1, splits+1):
---
> for i in range(1, splits+1):
> file = 'generic_cpu_exec.cc'
> if splits > 1:
> file = extn.sub(r'_%d\1' % i, file)
> with self.open(file) as f:
> fn = 'exec-g.cc.inc'
> assert(fn in self.files)
> f.write('#include "%s"\n' % fn)
> f.write('#include "cpu/exec_context.hh"\n')
> f.write('#include "decoder.hh"\n')
>
> fn = 'exec-ns.cc.inc'
> assert(fn in self.files)
> print >>f, 'namespace %s {' % self.namespace
1633,1639c1622,1624
< file = extn.sub(r'_%d\1' % i, cpu.filename)
< else:
< file = cpu.filename
< with self.open(file) as f:
< fn = 'exec-g.cc.inc'
< assert(fn in self.files)
< f.write('#include "%s"\n' % fn)
---
> print >>f, '#define __SPLIT %u' % i
> print >>f, '#include "%s"' % fn
> print >>f, '}'
1641,1655d1625
< f.write(cpu.includes+"\n")
<
< fn = 'decoder.hh'
< f.write('#include "%s"\n' % fn)
<
< fn = 'exec-ns.cc.inc'
< assert(fn in self.files)
< print >>f, 'namespace %s {' % self.namespace
< print >>f, '#define CPU_EXEC_CONTEXT %s' \
< % cpu.strings['CPU_exec_context']
< if splits > 1:
< print >>f, '#define __SPLIT %u' % i
< print >>f, '#include "%s"' % fn
< print >>f, '}'
<
1924,1925c1894
< # indicate template substitutions (or CPU-specific symbols, which
< # get handled in GenCode) by doubling them first so that the
---
> # indicate template substitutions by doubling them first so that the
1929,1930d1897
< # protects cpu-specific symbols too
< s = self.protectCpuSymbols(s)
2429,2462d2395
< def expandCpuSymbolsToDict(self, template):
< '''Expand template with CPU-specific references into a
< dictionary with an entry for each CPU model name. The entry
< key is the model name and the corresponding value is the
< template with the CPU-specific refs substituted for that
< model.'''
<
< # Protect '%'s that don't go with CPU-specific terms
< t = re.sub(r'%(?!\(CPU_)', '%%', template)
< result = {}
< for cpu in self.cpuModels:
< result[cpu.name] = t % cpu.strings
< return result
<
< def expandCpuSymbolsToString(self, template):
< '''*If* the template has CPU-specific references, return a
< single string containing a copy of the template for each CPU
< model with the corresponding values substituted in. If the
< template has no CPU-specific references, it is returned
< unmodified.'''
<
< if template.find('%(CPU_') != -1:
< return reduce(lambda x,y: x+y,
< self.expandCpuSymbolsToDict(template).values())
< else:
< return template
<
< def protectCpuSymbols(self, template):
< '''Protect CPU-specific references by doubling the
< corresponding '%'s (in preparation for substituting a different
< set of references into the template).'''
<
< return re.sub(r'%(?=\(CPU_)', '%%', template)
<