Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/2983

Change subject: scons: arch: Generalize the switching header code.
......................................................................

scons: arch: Generalize the switching header code.

Factor out the ISA ness of the switching header generating funciton. Also
turn it into a SCons builder which builds a single header, and a wrapping
method which uses the builder on a group of header files which all target
the same subdirectory.

Change-Id: I87705f97b6ebd9baebd4ebcfea19cc1218a64ad0
---
M SConstruct
M src/arch/SConscript
2 files changed, 29 insertions(+), 31 deletions(-)



diff --git a/SConstruct b/SConstruct
index 64f08b6..3f44dcd 100755
--- a/SConstruct
+++ b/SConstruct
@@ -1383,38 +1383,38 @@

 ###################################################
 #
-# This function is used to set up a directory with switching headers
+# This builder and wrapper method are used to set up a directory with
+# switching headers. Those are headers which are in a generic location and
+# that include more specific headers from a directory chosen at build time
+# based on the current build settings.
 #
 ###################################################

-main['ALL_ISA_LIST'] = all_isa_list
 main['ALL_GPU_ISA_LIST'] = all_gpu_isa_list
-def make_switching_dir(dname, switch_headers, env):
-    # Generate the header.  target[0] is the full path of the output
-    # header to generate.  'source' is a dummy variable, since we get the
-    # list of ISAs from env['ALL_ISA_LIST'].
-    def gen_switch_hdr(target, source, env):
-        fname = str(target[0])
-        isa = env['TARGET_ISA'].lower()
-        try:
-            f = open(fname, 'w')
- print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname))
-            f.close()
-        except IOError:
-            print "Failed to create %s" % fname
-            raise

-    # Build SCons Action object. 'varlist' specifies env vars that this
-    # action depends on; when env['ALL_ISA_LIST'] changes these actions
-    # should get re-executed.
-    switch_hdr_action = MakeAction(gen_switch_hdr,
-                          Transform("GENERATE"), varlist=['ALL_ISA_LIST'])
+def build_switching_header(target, source, env):
+    path = str(target[0])
+    subdir = str(source[0])
+    dp, fp = os.path.split(path)
+    dp = os.path.relpath(os.path.realpath(dp),
+                         os.path.realpath(env['BUILDDIR']))
+    with open(path, 'w') as hdr:
+        print >>hdr, '#include "%s/%s/%s"' % (dp, subdir, fp)

-    # Instantiate actions for each header
-    for hdr in switch_headers:
-        env.Command(hdr, [], switch_hdr_action)
+switching_header_action = MakeAction(build_switching_header,
+                                     Transform('GENERATE'))

-Export('make_switching_dir')
+switching_header_builder = Builder(action=switching_header_action,
+                                   source_factory=Value,
+                                   single_source=True)
+
+main.Append(BUILDERS = { 'SwitchingHeader': switching_header_builder })
+
+def switching_headers(self, headers, source):
+    for header in headers:
+        self.SwitchingHeader(header, source)
+
+main.AddMethod(switching_headers, 'SwitchingHeaders')

 def make_gpu_switching_dir(dname, switch_headers, env):
     # Generate the header.  target[0] is the full path of the output
diff --git a/src/arch/SConscript b/src/arch/SConscript
index 54d97a4..891a5a2 100644
--- a/src/arch/SConscript
+++ b/src/arch/SConscript
@@ -43,8 +43,8 @@
 #
 #################################################################

-# List of headers to generate
-isa_switch_hdrs = Split('''
+env.SwitchingHeaders(
+    Split('''
         decoder.hh
         interrupts.hh
         isa.hh
@@ -63,10 +63,8 @@
         types.hh
         utility.hh
         vtophys.hh
-        ''')
-
-# Set up this directory to support switching headers
-make_switching_dir('arch', isa_switch_hdrs, env)
+        '''),
+    env.subst('${TARGET_ISA}'))

 if env['BUILD_GPU']:
     gpu_isa_switch_hdrs = Split('''

--
To view, visit https://gem5-review.googlesource.com/2983
To unsubscribe, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I87705f97b6ebd9baebd4ebcfea19cc1218a64ad0
Gerrit-Change-Number: 2983
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to