Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows 10 compatibility #17

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
41 changes: 36 additions & 5 deletions hlsclt/build_commands/build_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@
import click
import os
import subprocess
from hlsclt.helper_funcs import find_solution_num
from hlsclt.helper_funcs import *
from hlsclt.report_commands.report_commands import open_report
import shutil
import platform
import hlsclt
OS=platform.system()

### Supporting Functions ###
# Function to generate the 'pre-amble' within the HLS Tcl build script.
def do_start_build_stuff(ctx):
config = ctx.obj.config
#print("config=",config)
solution_num = ctx.obj.solution_num
exts=('jpg', 'png','h')
try:
file = click.open_file("run_hls.tcl","w")
file.write("open_project " + config["project_name"] + "\n")
Expand All @@ -26,9 +31,22 @@ def do_start_build_stuff(ctx):
else:
cf = ""
for src_file in config["src_files"]:
file.write("add_files " + config["src_dir_name"] + "/" + src_file + cf + "\n")
f, ext = os.path.splitext(src_file)
cf_temp = cf if ext[1:].lower() not in exts else ""
file.write("add_files " + config["src_dir_name"] + "/" + src_file + cf_temp + "\n")

if config.get("cflags_tb","") != "":
cf_tb = " -cflags \"%s\"" % config["cflags_tb"]
else:
cf_tb = ""
for tb_file in config["tb_files"]:
file.write("add_files -tb " + config["tb_dir_name"] + "/" + tb_file + "\n")
f, ext = os.path.splitext(tb_file)
cf_tb_temp = cf_tb if ext[1:].lower() not in exts else ""
add_str="add_files -tb " + config["tb_dir_name"] + "/" + tb_file + cf_tb_temp + "\n"
#print("add_str=",add_str)
#print("cf_tb_temp=", cf_tb_temp)
file.write(add_str)

if ctx.params['keep']:
file.write("open_solution -reset \"solution" + str(solution_num) + "\"" + "\n")
else:
Expand Down Expand Up @@ -119,7 +137,7 @@ def do_end_build_stuff(ctx,sub_command_returns,report):
# If we are overwriting an existing solution delete the source directory first.
if ctx.params['keep'] == 0:
shutil.rmtree(destiny_src, ignore_errors=True)
shutil.copytree("src", destiny_src)
shutil.copytree(config["src_dir_name"], destiny_src)
shutil.copyfile("hls_config.py", destiny_config)

# Check for reporting flag
Expand All @@ -146,14 +164,27 @@ def build(ctx,keep,report):
@build.resultcallback()
@click.pass_context
def build_end_callback(ctx,sub_command_returns,keep,report):
config = ctx.obj.config
# Catch the case where no subcommands have been issued and offer a default build
if not sub_command_returns:
if click.confirm("No build stages specified, would you like to run a default sequence using all the build stages?", abort=True):
do_default_build(ctx)
ctx.obj.file.write("exit" + "\n")
ctx.obj.file.close()
# Call the Vivado HLS process
returncode = subprocess.call(["vivado_hls -f run_hls.tcl"],shell=True)
print("vivado_hls is now launching in %s!"%OS)
vivado_hls="vivado_hls"
if OS=="Windows":
returncode = subprocess.call([vivado_hls, "-f", "run_hls.tcl"],shell=True)
else:
# CANNOT USE SHELL=TRUE IN LINUX
if OS=="Linux":
if config.get("vivado_hls_version","") != "":
vivado_hls2=os.path.join("/","tools","Xilinx","Vivado",config["vivado_hls_version"],"bin","vivado_hls")
else:
vivado_hls2=vivado_hls
print("vivado_hls=%s"%vivado_hls2)
returncode = subprocess.call([vivado_hls2, "-f", "run_hls.tcl"])
# Check return status of the HLS process.
if returncode < 0:
raise click.Abort()
Expand Down
10 changes: 10 additions & 0 deletions hlsclt/examples/simple_adder/run_hls.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
open_project proj_simple_adder
set_top simple_adder
add_files src/dut.h
add_files src/dut.cpp
add_files -tb tb/testbench.cpp
open_solution "solution1"
set_part xc7z020clg484-1
create_clock -period 10 -name default
csim_design -clean
exit
23 changes: 18 additions & 5 deletions hlsclt/helper_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@

### Imports ###
import click
import sys
import os
import imp
#import imp
import importlib
from glob import glob
from .classes import *

### Function Definitions ###
# Function to generate the default config dicttionary
def generate_default_config():
proj_name=os.path.relpath(".","..")
config = {
"project_name" : "proj_" + os.path.relpath(".",".."),
"project_name" : "proj_" + proj_name,
"vivado_hls_version" : "",
"top_level_function_name" : "",
"src_dir_name" : "src",
"tb_dir_name" : "tb",
"cflags": "",
"cflags_tb": "",
"src_files" : "",
"compiler": "",
"tb_files" : "",
Expand All @@ -29,11 +34,18 @@ def generate_default_config():
}
return config

def osfsdecode(name):
if sys.version_info[0] > 3:
return os.fsdecode(name)
return name

# Function to read in the config from a local file and generate a config structure.
def get_vars_from_file(filename):
try:
with click.open_file(filename) as f:
config = imp.load_source('config', '', f)
#print("filename=",os.path.abspath(filename))
#with click.open_file(filename) as f:
#config = imp.load_source('config', '', f)
config = importlib.machinery.SourceFileLoader('config', filename).load_module()
return config
except (OSError, IOError):
click.echo("Error: No hls_config.py found, please create a config file for your project. For an example config file please see the 'examples' folder within the hlsclt install directory.")
Expand All @@ -48,7 +60,8 @@ def parse_config_vars(config_loaded, config, errors):
del_list = [];
for name in config:
# Catch optional config entries which don't need defaults
if str(name) == "compiler" or str(name) == "cflags":
# if str(name) == "compiler" or str(name) == "cflags":
if str(name) == "compiler" or "cflags" in str(name):
if str(name) not in options_defined:
del_list.append(name)
else:
Expand Down
4 changes: 2 additions & 2 deletions hlsclt/report_commands/report_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os
import subprocess
from glob import glob
from hlsclt.helper_funcs import find_solution_num
from hlsclt.helper_funcs import *

### Supporting Functions ###
# Function to check if project exists
Expand Down Expand Up @@ -41,7 +41,7 @@ def open_report(ctx,report):
# Function for opening the HLS GUI
def open_project_in_gui(ctx):
config = ctx.obj.config
hls_process = subprocess.Popen(["vivado_hls", "-p", config["project_name"]])
hls_process = subprocess.Popen([vivado_hls, "-p", config["project_name"]])

# Function for gathering the project status
def gather_project_status(ctx):
Expand Down