+# The ISA is generated twice: the first time to find out what it generates,
+# and the second time to make scons happy by telling the ISADesc builder
+# what it will make before it builds it.
+def scan_isa_deps(target, source, env):
+ # Process dependency file generated by the ISA parser --
+ # add the listed files to the dependency tree of the build.
+ source = source[0]
+ archbase = source.dir.up().path
+
+ try:
+ depfile = open(source.abspath, 'r')
+ except:
+ print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \
+ (source.path,os.getcwd())
+ raise
+
+ # Scan through the lines
+ targets = {}
+ for line in depfile:
+ # Read the dependency line with the format
+ # <target file>: [ <dependent file>* ]
+ m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line)
+ assert(m)
+ targ, extn = m.group(1,2)
+ deps = m.group(3).split()
+
+ files = [ targ ] + deps
+ for f in files:
+ targets[f] = True
+ # Eliminate unnecessary re-generation if we already generated it
+ env.Precious(os.path.join(archbase, 'generated', f))
+
+ files = [ os.path.join(archbase, 'generated', f) for f in files ]
+
+ if extn == 'cc':
+ Source(os.path.join(archbase,'generated', targ))
+ depfile.close()
+ env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys()
+
+ isa = env.ISADesc(os.path.join(archbase,'isa','main.isa'))
+ for t in targets:
+ env.Depends('#all-isas', isa)
+
+env.Append(BUILDERS = {'ScanISA' :
+ Builder(action=MakeAction(scan_isa_deps,
+ Transform("NEW DEPS", 1)))})
+
+DebugFlag('IntRegs')
+DebugFlag('FloatRegs')
+DebugFlag('CCRegs')
+DebugFlag('MiscRegs')
+CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ])