SConscript (13709:dd6b7ac5801f) | SConscript (13730:2c34d4c9089b) |
---|---|
1# -*- mode:python -*- 2 3# Copyright (c) 2018 ARM Limited 4# 5# The license below extends only to copyright in the software and shall 6# not be construed as granting a license to any other intellectual 7# property including but not limited to intellectual property relating 8# to a hardware implementation of the functionality of the software --- 31 unchanged lines hidden (view full) --- 40# Authors: Nathan Binkert 41 42from __future__ import print_function 43 44import array 45import bisect 46import functools 47import imp | 1# -*- mode:python -*- 2 3# Copyright (c) 2018 ARM Limited 4# 5# The license below extends only to copyright in the software and shall 6# not be construed as granting a license to any other intellectual 7# property including but not limited to intellectual property relating 8# to a hardware implementation of the functionality of the software --- 31 unchanged lines hidden (view full) --- 40# Authors: Nathan Binkert 41 42from __future__ import print_function 43 44import array 45import bisect 46import functools 47import imp |
48import marshal | |
49import os 50import re | 48import os 49import re |
51import subprocess | |
52import sys 53import zlib 54 55from os.path import basename, dirname, exists, isdir, isfile, join as joinpath 56 57import SCons 58 59from gem5_scons import Transform --- 1065 unchanged lines hidden (view full) --- 1125 1126# version tags 1127tags = \ 1128env.Command('sim/tags.cc', None, 1129 MakeAction('util/cpt_upgrader.py --get-cc-file > $TARGET', 1130 Transform("VER TAGS"))) 1131env.AlwaysBuild(tags) 1132 | 50import sys 51import zlib 52 53from os.path import basename, dirname, exists, isdir, isfile, join as joinpath 54 55import SCons 56 57from gem5_scons import Transform --- 1065 unchanged lines hidden (view full) --- 1123 1124# version tags 1125tags = \ 1126env.Command('sim/tags.cc', None, 1127 MakeAction('util/cpt_upgrader.py --get-cc-file > $TARGET', 1128 Transform("VER TAGS"))) 1129env.AlwaysBuild(tags) 1130 |
1131# Build a small helper that marshals the Python code using the same 1132# version of Python as gem5. This is in an unorthodox location to 1133# avoid building it for every variant. 1134py_marshal = env.Program('python/marshal.cc')[0] 1135 |
|
1133# Embed python files. All .py files that have been indicated by a 1134# PySource() call in a SConscript need to be embedded into the M5 1135# library. To do that, we compile the file to byte code, marshal the 1136# byte code, compress it, and then generate a c++ file that 1137# inserts the result into an array. 1138def embedPyFile(target, source, env): 1139 def c_str(string): 1140 if string is None: 1141 return "0" 1142 return '"%s"' % string 1143 | 1136# Embed python files. All .py files that have been indicated by a 1137# PySource() call in a SConscript need to be embedded into the M5 1138# library. To do that, we compile the file to byte code, marshal the 1139# byte code, compress it, and then generate a c++ file that 1140# inserts the result into an array. 1141def embedPyFile(target, source, env): 1142 def c_str(string): 1143 if string is None: 1144 return "0" 1145 return '"%s"' % string 1146 |
1144 '''Action function to compile a .py into a code object, marshal 1145 it, compress it, and stick it into an asm file so the code appears 1146 as just bytes with a label in the data section''' | 1147 '''Action function to compile a .py into a code object, marshal it, 1148 compress it, and stick it into an asm file so the code appears as 1149 just bytes with a label in the data section. The action takes two 1150 sources: |
1147 | 1151 |
1148 src = file(str(source[0]), 'r').read() | 1152 source[0]: Binary used to marshal Python sources 1153 source[1]: Python script to marshal 1154 ''' |
1149 | 1155 |
1150 pysource = PySource.tnodes[source[0]] 1151 compiled = compile(src, pysource.abspath, 'exec') 1152 marshalled = marshal.dumps(compiled) | 1156 import subprocess 1157 1158 marshalled = subprocess.check_output([source[0].abspath, str(source[1])]) 1159 |
1153 compressed = zlib.compress(marshalled) 1154 data = compressed | 1160 compressed = zlib.compress(marshalled) 1161 data = compressed |
1162 pysource = PySource.tnodes[source[1]] |
|
1155 sym = pysource.symname 1156 1157 code = code_formatter() 1158 code('''\ 1159#include "sim/init.hh" 1160 1161namespace { 1162 --- 10 unchanged lines hidden (view full) --- 1173 ${{len(data)}}, 1174 ${{len(marshalled)}}); 1175 1176} // anonymous namespace 1177''') 1178 code.write(str(target[0])) 1179 1180for source in PySource.all: | 1163 sym = pysource.symname 1164 1165 code = code_formatter() 1166 code('''\ 1167#include "sim/init.hh" 1168 1169namespace { 1170 --- 10 unchanged lines hidden (view full) --- 1181 ${{len(data)}}, 1182 ${{len(marshalled)}}); 1183 1184} // anonymous namespace 1185''') 1186 code.write(str(target[0])) 1187 1188for source in PySource.all: |
1181 env.Command(source.cpp, source.tnode, | 1189 env.Command(source.cpp, [ py_marshal, source.tnode ], |
1182 MakeAction(embedPyFile, Transform("EMBED PY"))) 1183 Source(source.cpp, tags=source.tags, add_tags='python') 1184 1185######################################################################## 1186# 1187# Define binaries. Each different build type (debug, opt, etc.) gets 1188# a slightly different build environment. 1189# --- 217 unchanged lines hidden --- | 1190 MakeAction(embedPyFile, Transform("EMBED PY"))) 1191 Source(source.cpp, tags=source.tags, add_tags='python') 1192 1193######################################################################## 1194# 1195# Define binaries. Each different build type (debug, opt, etc.) gets 1196# a slightly different build environment. 1197# --- 217 unchanged lines hidden --- |