[gem5-dev] Change in gem5/gem5[develop]: scons: Turn the Blob method into a builder.

2021-08-27 Thread Gabe Black (Gerrit) via gem5-dev
Gabe Black has submitted this change. (  
https://gem5-review.googlesource.com/c/public/gem5/+/48136 )




5 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the  
submitted one.

Change subject: scons: Turn the Blob method into a builder.
..

scons: Turn the Blob method into a builder.

Build the blob .cc and .hh files in the same directory as the file
they're based off of. Move the GDB XML files into the arch directories
they go with.

Change-Id: I12fe48873312c3aba5910989d6e3049ebd5e5bbf
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/48136
Reviewed-by: Gabe Black 
Reviewed-by: Bobby R. Bruce 
Maintainer: Gabe Black 
Tested-by: kokoro 
---
M SConstruct
M src/SConscript
M src/arch/arm/SConscript
A src/arch/arm/gdb-xml/SConscript
R src/arch/arm/gdb-xml/aarch64-core.xml
R src/arch/arm/gdb-xml/aarch64-fpu.xml
R src/arch/arm/gdb-xml/aarch64.xml
R src/arch/arm/gdb-xml/arm-core.xml
R src/arch/arm/gdb-xml/arm-vfpv3.xml
R src/arch/arm/gdb-xml/arm-with-neon.xml
M src/arch/arm/remote_gdb.cc
M src/arch/mips/SConscript
A src/arch/mips/gdb-xml/SConscript
R src/arch/mips/gdb-xml/mips.xml
M src/arch/mips/remote_gdb.cc
M src/arch/power/SConscript
A src/arch/power/gdb-xml/SConscript
R src/arch/power/gdb-xml/power-core.xml
R src/arch/power/gdb-xml/power-fpu.xml
R src/arch/power/gdb-xml/power64-core.xml
R src/arch/power/gdb-xml/powerpc-32.xml
R src/arch/power/gdb-xml/powerpc-64.xml
M src/arch/power/remote_gdb.cc
M src/arch/riscv/SConscript
A src/arch/riscv/gdb-xml/SConscript
R src/arch/riscv/gdb-xml/riscv-64bit-cpu.xml
R src/arch/riscv/gdb-xml/riscv-64bit-csr.xml
R src/arch/riscv/gdb-xml/riscv-64bit-fpu.xml
R src/arch/riscv/gdb-xml/riscv.xml
M src/arch/riscv/remote_gdb.cc
30 files changed, 229 insertions(+), 85 deletions(-)

Approvals:
  Gabe Black: Looks good to me, but someone else must approve; Looks good  
to me, approved

  Bobby R. Bruce: Looks good to me, approved
  kokoro: Regressions pass




diff --git a/SConstruct b/SConstruct
index 4091d4b..396dc59 100755
--- a/SConstruct
+++ b/SConstruct
@@ -619,9 +619,6 @@
 main.SConscript(os.path.join(root, 'SConscript'),
 variant_dir=os.path.join(build_root, build_dir))

-gdb_xml_dir = os.path.join(ext_dir, 'gdb-xml')
-Export('gdb_xml_dir')
-

 
 #
diff --git a/src/SConscript b/src/SConscript
index a92dd17..a99f2a1 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -287,71 +287,69 @@
 code.dedent()
 code('};')

-def blobToCpp(data, symbol, cpp_code, hpp_code, namespace):
+def build_blob(target, source, env):
 '''
-Convert bytes data into C++ .cpp and .hh uint8_t byte array
-code containing that binary data.
+Embed an arbitrary blob into the gem5 executable,
+and make it accessible to C++ as a byte array.
+'''

-:param data: binary data to be converted to C++
-:param symbol: name of the symbol
-:param cpp_code: append the generated cpp_code to this object
-:param hpp_code: append the generated hpp_code to this object
- Also include it in the .cpp file.
-:param namespace: namespace to put the symbol into.
-'''
-hpp_code('''\
+with open(str(source[0]), 'rb') as f:
+data = f.read()
+symbol = str(source[1])
+cc, hh = target
+
+hh_code = code_formatter()
+hh_code('''\
 #include 
 #include 

-namespace ${namespace}
+namespace gem5
+{
+namespace Blobs
 {

 extern const std::size_t ${symbol}_len;
 extern const std::uint8_t ${symbol}[];

-}
+} // namespace Blobs
+} // namespace gem5
 ''')
+hh_code.write(str(hh))

-cpp_code('''\
-#include "blobs/${symbol}.hh"
+include_path = os.path.relpath(hh.abspath, env['BUILDDIR'])

-namespace ${namespace}
+cc_code = code_formatter()
+cc_code('''\
+#include "${include_path}"
+
+namespace gem5
+{
+namespace Blobs
 {

 const std::size_t ${symbol}_len = ${{len(data)}};
 ''')
-bytesToCppArray(cpp_code, symbol, data)
-cpp_code('} // namespace ${namespace}')
+bytesToCppArray(cc_code, symbol, data)
+cc_code('''
+} // namespace Blobs
+} // namespace gem5
+''')
+cc_code.write(str(cc))

-def Blob(blob_path, symbol):
-'''
-Embed an arbitrary blob into the gem5 executable,
-and make it accessible to C++ as a byte array.
-'''
-blob_path = os.path.abspath(blob_path)
-blob_out_dir = os.path.join(env['BUILDDIR'], 'blobs')
-path_noext = os.path.join(blob_out_dir, symbol)
-cpp_path = path_noext + '.cc'
-hpp_path = path_noext + '.hh'
-def embedBlob(target, source, env):
-with open(str(source[0]), 'rb') as f:
-data = f.read()
-cpp_code = code_formatter()
-hpp_code = code_formatter()
-blobToCpp(data, symbol, cpp_code, hpp_code, namespace='Blobs')
-cpp_path = str(target[0])
-hpp_path = 

[gem5-dev] Change in gem5/gem5[develop]: scons: Turn the Blob method into a builder.

2021-07-15 Thread Gabe Black (Gerrit) via gem5-dev
Gabe Black has uploaded this change for review. (  
https://gem5-review.googlesource.com/c/public/gem5/+/48136 )



Change subject: scons: Turn the Blob method into a builder.
..

scons: Turn the Blob method into a builder.

Build the blob .cc and .hh files in the same directory as the file
they're based off of. Move the GDB XML files into the arch directories
they go with.

Change-Id: I12fe48873312c3aba5910989d6e3049ebd5e5bbf
---
M SConstruct
M src/SConscript
M src/arch/arm/SConscript
A src/arch/arm/gdb-xml/SConscript
R src/arch/arm/gdb-xml/aarch64-core.xml
R src/arch/arm/gdb-xml/aarch64-fpu.xml
R src/arch/arm/gdb-xml/aarch64.xml
R src/arch/arm/gdb-xml/arm-core.xml
R src/arch/arm/gdb-xml/arm-vfpv3.xml
R src/arch/arm/gdb-xml/arm-with-neon.xml
M src/arch/arm/remote_gdb.cc
M src/arch/mips/SConscript
A src/arch/mips/gdb-xml/SConscript
R src/arch/mips/gdb-xml/mips.xml
M src/arch/mips/remote_gdb.cc
M src/arch/power/SConscript
A src/arch/power/gdb-xml/SConscript
R src/arch/power/gdb-xml/power-core.xml
R src/arch/power/gdb-xml/power-fpu.xml
R src/arch/power/gdb-xml/power64-core.xml
R src/arch/power/gdb-xml/powerpc-32.xml
R src/arch/power/gdb-xml/powerpc-64.xml
M src/arch/power/remote_gdb.cc
M src/arch/riscv/SConscript
A src/arch/riscv/gdb-xml/SConscript
R src/arch/riscv/gdb-xml/riscv-64bit-cpu.xml
R src/arch/riscv/gdb-xml/riscv-64bit-csr.xml
R src/arch/riscv/gdb-xml/riscv-64bit-fpu.xml
R src/arch/riscv/gdb-xml/riscv.xml
M src/arch/riscv/remote_gdb.cc
30 files changed, 243 insertions(+), 99 deletions(-)



diff --git a/SConstruct b/SConstruct
index 086b3ca..2b2e39c 100755
--- a/SConstruct
+++ b/SConstruct
@@ -615,9 +615,6 @@
 main.SConscript(os.path.join(root, 'SConscript'),
 variant_dir=os.path.join(build_root, build_dir))

-gdb_xml_dir = os.path.join(ext_dir, 'gdb-xml')
-Export('gdb_xml_dir')
-

 
 #
diff --git a/src/SConscript b/src/SConscript
index 175b8cf..1272c06 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -286,71 +286,69 @@
 code.dedent()
 code('};')

-def blobToCpp(data, symbol, cpp_code, hpp_code, namespace):
-'''
-Convert bytes data into C++ .cpp and .hh uint8_t byte array
-code containing that binary data.
-
-:param data: binary data to be converted to C++
-:param symbol: name of the symbol
-:param cpp_code: append the generated cpp_code to this object
-:param hpp_code: append the generated hpp_code to this object
- Also include it in the .cpp file.
-:param namespace: namespace to put the symbol into.
-'''
-hpp_code('''\
-#include 
-#include 
-
-namespace ${namespace}
-{
-
-extern const std::size_t ${symbol}_len;
-extern const std::uint8_t ${symbol};
-
-}
-''')
-
-cpp_code('''\
-#include "blobs/${symbol}.hh"
-
-namespace ${namespace}
-{
-
-const std::size_t ${symbol}_len = ${{len(data)}};
-''')
-bytesToCode(cpp_code, symbol, data)
-cpp_code('}')
-
-def Blob(blob_path, symbol):
+def build_blob(target, source, env):
 '''
 Embed an arbitrary blob into the gem5 executable,
 and make it accessible to C++ as a byte array.
 '''
-blob_path = os.path.abspath(blob_path)
-blob_out_dir = os.path.join(env['BUILDDIR'], 'blobs')
-path_noext = os.path.join(blob_out_dir, symbol)
-cpp_path = path_noext + '.cc'
-hpp_path = path_noext + '.hh'
-def embedBlob(target, source, env):
-with open(str(source[0]), 'rb') as f:
-data = f.read()
-cpp_code = code_formatter()
-hpp_code = code_formatter()
-blobToCpp(data, symbol, cpp_code, hpp_code, namespace='Blobs')
-cpp_path = str(target[0])
-hpp_path = str(target[1])
-cpp_dir = os.path.split(cpp_path)[0]
-if not os.path.exists(cpp_dir):
-os.makedirs(cpp_dir)
-cpp_code.write(cpp_path)
-hpp_code.write(hpp_path)
-env.Command([cpp_path, hpp_path], blob_path,
-MakeAction(embedBlob, Transform("EMBED BLOB")))
-Source(cpp_path)
+
+with open(str(source[0]), 'rb') as f:
+data = f.read()
+symbol = str(source[1])
+cc, hh = target
+
+hh_code = code_formatter()
+hh_code('''\
+#include 
+#include 
+
+namespace gem5
+{
+namespace Blobs
+{
+
+extern const std::size_t ${symbol}_len;
+extern const std::uint8_t ${symbol}[];
+
+} // namespace Blobs
+} // namespace gem5
+''')
+hh_code.write(str(hh))
+
+include_path = os.path.relpath(hh.abspath, env['BUILDDIR'])
+
+cc_code = code_formatter()
+cc_code('''\
+#include "${include_path}"
+
+namespace gem5
+{
+namespace Blobs
+{
+
+const std::size_t ${symbol}_len = ${{len(data)}};
+''')
+bytesToCppArray(cc_code, symbol, data)
+cc_code('''
+} // namespace Blobs
+} // namespace gem5
+''')
+cc_code.write(str(cc))
+
+blob_action = MakeAction(build_blob, Transform("EMBED BLOB"))
+
+def