Skip to content

Commit f1986ba

Browse files
intel-rbarbalhoalastairreid
authored andcommitted
System-C runtime support
This adds a new runtime system based on the System-C library. This library gives a significant performance benefit when using hardware model checkers. Note that this adds an additional submodule dependency. Signed-off-by: Rafael Barbalho <[email protected]> Signed-off-by: Alastair Reid <[email protected]>
1 parent 2e171a9 commit f1986ba

File tree

11 files changed

+771
-8
lines changed

11 files changed

+771
-8
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[submodule "ac_types"]
22
path = runtime/external/ac_types
33
url = https://github.com/hlslibs/ac_types.git
4+
[submodule "systemc"]
5+
path = runtime/external/systemc
6+
url = https://github.com/accellera-official/systemc.git
47
[submodule "runtime/external/googletest"]
58
path = runtime/external/googletest
69
url = https://github.com/google/googletest.git

Makefile

+15-2
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,17 @@ runtime_test:
6363
lit_test: build
6464
env PATH="`pwd`/tests/scripts:${PATH}" ${LIT} tests/lit -v
6565

66+
TEST_ENV += AC_TYPES_DIR="`pwd`/runtime/external/ac_types"
67+
TEST_ENV += SC_TYPES_DIR="`pwd`/runtime/external/systemc/build-install"
68+
6669
WIDE_BITINT_SUPPORTED := `$(MAKE) -C runtime/test wide_bitint_supported`
6770

68-
BACKENDS := interpreter c23 ac fallback
71+
BACKENDS = interpreter c23 ac fallback sc
6972

7073
test_backends: ${addprefix test_backend_, ${BACKENDS}}
7174

7275
test_backend_%: build
73-
env PATH="${CURDIR}/tests/scripts:$${PATH}" AC_TYPES_DIR="`pwd`/runtime/external/ac_types" ASL_BACKEND=$* ${LIT} tests/backends -v
76+
env PATH="${CURDIR}/tests/scripts:$${PATH}" ${TEST_ENV} ASL_BACKEND=$* ${LIT} tests/backends -v
7477

7578

7679
test_demos: ${addprefix test_demo_, $(filter-out interpreter ac, ${BACKENDS})}
@@ -84,6 +87,16 @@ test_demo_interpreter : build
8487
demo_interpreter : build
8588
$(MAKE) -C demo demo
8689

90+
build_systemc:
91+
test -f runtime/external/systemc/build-install/lib/libsystemc.a || \
92+
( mkdir -p runtime/external/systemc/build && \
93+
mkdir -p runtime/external/systemc/build-install && \
94+
cmake runtime/external/systemc/ -B runtime/external/systemc/build -DCMAKE_INSTALL_PREFIX=runtime/external/systemc/build-install -DCMAKE_CXX_STANDARD=17 -DBUILD_SHARED_LIBS=OFF && \
95+
cmake --build runtime/external/systemc/build && \
96+
cmake --install runtime/external/systemc/build )
97+
98+
test_backend_sc: build_systemc
99+
87100
################################################################
88101
# End
89102
################################################################

bin/asl2c.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,16 @@ def run(cmd):
230230
ac_types_dir = os.environ.get('AC_TYPES_DIR')
231231
ac_types_include = [f"-I{ac_types_dir}/include"] if ac_types_dir else []
232232

233+
sc_types_dir = os.environ.get('SC_TYPES_DIR')
234+
sc_types_include = [f"-I{sc_types_dir}/include"] if sc_types_dir else []
235+
233236
backend_c_flags = {
234237
'ac': ['-DASL_AC'] + ac_types_include,
235238
'c23': ['-DASL_C23'],
236239
'interpreter': [],
237240
'fallback': ['-DASL_FALLBACK'],
238241
'orig': ['-DASL_FALLBACK'],
242+
'sc': ['-DASL_SC'] + sc_types_include,
239243
}
240244

241245
def get_c_flags(asli, backend):
@@ -259,6 +263,7 @@ def get_c_flags(asli, backend):
259263
'interpreter': [],
260264
'fallback': [],
261265
'orig': [],
266+
'sc': ["-lsystemc"],
262267
}
263268

264269
def get_ld_flags(asli, backend):
@@ -273,6 +278,11 @@ def get_ld_flags(asli, backend):
273278
rootdir = os.path.dirname(bindir)
274279
path = os.path.join(rootdir, "runtime/libASL.a")
275280
ld_flags = [path]
281+
if backend == "sc":
282+
sc_types_dir = os.environ.get('SC_TYPES_DIR')
283+
if not sc_types_dir:
284+
raise EnvironmentError("SC_TYPES_DIR environment variable must be set for SystemC backend")
285+
ld_flags.append(f"-L{sc_types_dir}/lib")
276286
ld_flags.extend(backend_ld_flags[backend])
277287
return ld_flags
278288

@@ -289,6 +299,7 @@ def mk_script(args, output_directory):
289299
'c23': f'generate_c_new {ffi} --runtime=c23',
290300
'fallback': f'generate_c_new {ffi} --runtime=fallback',
291301
'orig': 'generate_c',
302+
'sc': f'generate_c_new {ffi} --runtime=sc',
292303
}
293304
generate_c = backend_generator[args.backend]
294305

@@ -397,6 +408,8 @@ def compile_and_link(use_cxx, c_files, extra_c, exe_file, working_directory, c_f
397408
cc = [ "clang-16" ]
398409
elif subprocess.run(['which', 'clang'], capture_output=True).returncode == 0:
399410
cc = [ "clang" ]
411+
elif use_cxx:
412+
cc = [ "g++" ]
400413
else:
401414
cc = [ "gcc" ]
402415
if use_cxx:
@@ -479,7 +492,7 @@ def main() -> int:
479492
parser.add_argument("--instrument-unknown", help="instrument assignments of UNKNOWN", action=argparse.BooleanOptionalAction)
480493
parser.add_argument("--wrap-variables", help="wrap global variables into functions", action=argparse.BooleanOptionalAction)
481494
parser.add_argument("-O0", help="perform minimal set of transformations", action=argparse.BooleanOptionalAction)
482-
parser.add_argument("--backend", help="select backend (default: orig)", choices=['ac', 'c23', 'interpreter', 'fallback', 'orig'], default='orig')
495+
parser.add_argument("--backend", help="select backend (default: orig)", choices=['ac', 'c23', 'interpreter', 'fallback', 'orig', 'sc'], default='orig')
483496
parser.add_argument("--print-c-flags", help="print the C flags needed to use the selected ASL C runtime", action=argparse.BooleanOptionalAction)
484497
parser.add_argument("--print-ld-flags", help="print the Linker flags needed to use the selected ASL C runtime", action=argparse.BooleanOptionalAction)
485498
parser.add_argument("--build", help="compile and link the ASL code", action='store_true')
@@ -507,7 +520,7 @@ def main() -> int:
507520
if args.backend == "interpreter" and not args.run:
508521
print("Error: must specify --run with asli backend")
509522
exit(1)
510-
if args.backend in ['ac']: args.generate_cxx = True
523+
if args.backend in ['ac', 'sc']: args.generate_cxx = True
511524
if args.const_ref and not args.generate_cxx:
512525
print("Error: must specify --generate-cxx with --const-ref")
513526
exit(1)

libASL/backend_c_new.ml

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ open Utils
2121
module type RuntimeLib = Runtime.RuntimeLib
2222
let runtime = ref (module Runtime_fallback.Runtime : RuntimeLib)
2323

24-
let runtimes = ["ac"; "c23"; "fallback"]
24+
let runtimes = ["ac"; "c23"; "fallback"; "sc"]
2525

2626
let is_cxx = ref false
2727

2828
let set_runtime (rt : string) : unit =
2929
runtime := if rt = "ac" then (module Runtime_ac.Runtime : RuntimeLib)
3030
else if rt = "c23" then (module Runtime_c23.Runtime : RuntimeLib)
31-
else (module Runtime_fallback.Runtime : RuntimeLib)
31+
else if rt = "sc" then (module Runtime_sc.Runtime : RuntimeLib)
32+
else (module Runtime_fallback.Runtime : RuntimeLib);
33+
is_cxx := (rt = "ac") || (rt = "sc")
3234

3335
let include_line_info : bool ref = ref false
3436
let new_ffi : bool ref = ref false
@@ -773,7 +775,8 @@ let rec lexpr (loc : Loc.t) (fmt : PP.formatter) (x : AST.lexpr) : unit =
773775
| LExpr_BitTuple _
774776
| LExpr_Fields _
775777
| LExpr_ReadWrite _
776-
| LExpr_Slices _
778+
| LExpr_Slices _ ->
779+
lexpr loc fmt x
777780
| LExpr_Tuple _
778781
| LExpr_Write _ ->
779782
let pp fmt = FMT.lexpr fmt x in

libASL/dune

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
runtime_c23
5353
runtime_ac
5454
runtime_fallback
55+
runtime_sc
5556
scope
5657
scopeStack
5758
tcheck

0 commit comments

Comments
 (0)