diff --git a/README.md b/README.md index bd76bc2..0cacd78 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,8 @@ Each Vivado HLS project requires a 'config.py' file in order to use hlsclt. This |Device String |part_name |A device string as used by Vivado HLS (see examples)|Yes| |Clock Period |clock_period |A value in nanoseconds input as a string, e.g. "10"|Yes| |HDL Language |language |Either "vhdl" or "verilog" |No (Default is "vhdl")| +|Compiler |Compiler |Either "gcc" or "clang" |No (HLS defaults to gcc)| +|Compiler Options |cflags |Any flag for GCC (e.g. --std=c++11)|No| Here is an example file taken from the [simple_adder](hlsclt/examples/simple_adder) example shipped with the tool (note that some of the optional items have been commented out in order to use the defaults): @@ -139,6 +141,7 @@ Here is an example file taken from the [simple_adder](hlsclt/examples/simple_add top_level_function_name = "simple_adder" #src_dir_name = "src" #tb_dir_name = "tb" +# cflags = "" src_files = ["dut.h","dut.cpp"] tb_files = ["testbench.cpp"] part_name = "xc7z020clg484-1" diff --git a/hlsclt/_version.py b/hlsclt/_version.py index 26d7acc..071a662 100644 --- a/hlsclt/_version.py +++ b/hlsclt/_version.py @@ -1 +1 @@ -__version__ = '1.0.0.a3' +__version__ = '1.0.0.a4' diff --git a/hlsclt/build_commands/build_commands.py b/hlsclt/build_commands/build_commands.py index a14150f..3373f7c 100644 --- a/hlsclt/build_commands/build_commands.py +++ b/hlsclt/build_commands/build_commands.py @@ -20,8 +20,12 @@ def do_start_build_stuff(ctx): file = click.open_file("run_hls.tcl","w") file.write("open_project " + config["project_name"] + "\n") file.write("set_top " + config["top_level_function_name"] + "\n") + if config.get("cflags","") != "": + cf = " -cflags \"%s\"" % config["cflags"] + else: + cf = "" for src_file in config["src_files"]: - file.write("add_files " + config["src_dir_name"] + "/" + src_file + "\n") + file.write("add_files " + config["src_dir_name"] + "/" + src_file + cf + "\n") for tb_file in config["tb_files"]: file.write("add_files -tb " + config["tb_dir_name"] + "/" + tb_file + "\n") if ctx.params['keep']: @@ -39,7 +43,7 @@ def do_start_build_stuff(ctx): def do_default_build(ctx): config = ctx.obj.config file = ctx.obj.file - file.write("csim_design -clean" + "\n") + file.write("csim_design -clean" + (" -compiler clang" if config.get("compiler","") == "clang" else "") + " \n") file.write("csynth_design" + "\n") file.write("cosim_design -O -rtl " + config["language"] + "\n") file.write("export_design -format ip_catalog" + "\n") @@ -48,7 +52,8 @@ def do_default_build(ctx): # Function which defines the main actions of the 'csim' command. def do_csim_stuff(ctx): file = ctx.obj.file - file.write("csim_design -clean" + "\n") + config = ctx.obj.config + file.write("csim_design -clean" + (" -compiler clang" if config.get("compiler","") == "clang" else "") + "\n") # Function which defines the main actions of the 'syn' command. def do_syn_stuff(ctx): @@ -134,11 +139,11 @@ def build_end_callback(ctx,sub_command_returns,keep,report): ctx.obj.file.write("exit" + "\n") ctx.obj.file.close() # Call the Vivado HLS process - hls_processs = subprocess.run(["vivado_hls", "-f", "run_hls.tcl"]) + returncode = subprocess.call(["vivado_hls -f run_hls.tcl"],shell=True) # Check return status of the HLS process. - if hls_processs.returncode < 0: + if returncode < 0: raise click.Abort() - elif hls_processs.returncode > 0: + elif returncode > 0: click.echo("Warning: HLS Process returned an error, skipping report opening!") raise click.Abort() else: diff --git a/hlsclt/examples/simple_adder/hls_config.py b/hlsclt/examples/simple_adder/hls_config.py index 25bb97b..b48f1f5 100644 --- a/hlsclt/examples/simple_adder/hls_config.py +++ b/hlsclt/examples/simple_adder/hls_config.py @@ -9,3 +9,5 @@ part_name = "xc7z020clg484-1" clock_period = "10" language = "vhdl" +#compiler = "" +#cflags = "" diff --git a/hlsclt/helper_funcs.py b/hlsclt/helper_funcs.py index 2a98e4d..c77e5f2 100644 --- a/hlsclt/helper_funcs.py +++ b/hlsclt/helper_funcs.py @@ -9,6 +9,7 @@ import os import imp from glob import glob +from .classes import * ### Function Definitions ### # Function to generate the default config dicttionary @@ -18,7 +19,9 @@ def generate_default_config(): "top_level_function_name" : "", "src_dir_name" : "src", "tb_dir_name" : "tb", + "cflags": "", "src_files" : "", + "compiler": "", "tb_files" : "", "part_name" : "", "clock_period" : "", @@ -42,15 +45,24 @@ def parse_config_vars(config_loaded, config, errors): config_loaded_set = set(config_loaded_dict) config_set = set(config) options_defined = config_loaded_set.intersection(config_set) + del_list = []; for name in config: - if str(name) in options_defined: + # Catch optional config entries which don't need defaults + if str(name) == "compiler" or str(name) == "cflags": + if str(name) not in options_defined: + del_list.append(name) + else: + config[name] = config_loaded_dict[name] + elif str(name) in options_defined: config[name] = config_loaded_dict[name] - try: - if not config[name]: - raise ConfigError("Error: " + name + " is not defined in config file. No default exists, please define a value in the config file.") - except ConfigError as err: - errors.append(err) - continue + try: + if not config[name]: + raise ConfigError("Error: " + name + " is not defined in config file. No default exists, please define a value in the config file.") + except ConfigError as err: + errors.append(err) + continue + for name in del_list: + del config[name] # Function to find the highest solution number within a HLS project. def find_solution_num(ctx):