Skip to content
Snippets Groups Projects
Commit e314c24d authored by Pawel Szostek's avatar Pawel Szostek
Browse files

Add ISE list generating

parent 4cc195d9
Branches
Tags
No related merge requests found
...@@ -43,7 +43,7 @@ def search_for_use(file): ...@@ -43,7 +43,7 @@ def search_for_use(file):
ret.append((m.group(1),m.group(2))) ret.append((m.group(1),m.group(2)))
f.close() f.close()
return ret return ret
def search_for_package(file): def search_for_package(file):
""" """
Reads a file and looks for package clase. Returns list of packages' names Reads a file and looks for package clase. Returns list of packages' names
...@@ -55,7 +55,7 @@ def search_for_package(file): ...@@ -55,7 +55,7 @@ def search_for_package(file):
if text is None: if text is None:
return [] return []
text = text.split("\n") text = text.split("\n")
ret = [] ret = []
package_pattern = re.compile("^[ \t]*package[ \t]+([^ \t]+)[ \t]+is[ \t]*$") package_pattern = re.compile("^[ \t]*package[ \t]+([^ \t]+)[ \t]+is[ \t]*$")
for line in text: for line in text:
...@@ -64,11 +64,12 @@ def search_for_package(file): ...@@ -64,11 +64,12 @@ def search_for_package(file):
ret.append(m.group(1)) ret.append(m.group(1))
f.close() f.close()
return ret return ret
def generate_deps_for_sv_files(files): def generate_deps_for_sv_files(files):
def search_for_sv_include(file): def search_for_sv_include(file):
f = open(file,"r") f = open(file,"r")
text = f.readlines() text = f.readlines()
ret = [] ret = []
package_pattern = re.compile("^[ \t]*`include[ \t]+\"([^ \t]+)\"[ \t]*$") package_pattern = re.compile("^[ \t]*`include[ \t]+\"([^ \t]+)\"[ \t]*$")
for line in text: for line in text:
...@@ -83,32 +84,32 @@ def generate_deps_for_sv_files(files): ...@@ -83,32 +84,32 @@ def generate_deps_for_sv_files(files):
file_file_dict = {} file_file_dict = {}
for file in files: for file in files:
file_file_dict[file] = search_for_sv_include(file) file_file_dict[file] = search_for_sv_include(file)
def generate_deps_for_vhdl_in_modules(modules_paths): def generate_deps_for_vhdl_in_modules(modules_paths):
if not isinstance(modules_paths, list): if not isinstance(modules_paths, list):
modules_paths = [modules_paths] modules_paths = [modules_paths]
from hdlmake import search_for_manifest from hdlmake import search_for_manifest
module_manifest_dict = {} module_manifest_dict = {}
for module in modules_paths: for module in modules_paths:
module_manifest_dict[module] = search_for_manifest(module) module_manifest_dict[module] = search_for_manifest(module)
from hdlmake import parse_manifest from hdlmake import parse_manifest
opt_map_dict = {} opt_map_dict = {}
for module in list(module_manifest_dict.keys()): for module in list(module_manifest_dict.keys()):
if module_manifest_dict[module] != None: if module_manifest_dict[module] != None:
opt_map_dict[module] = parse_manifest(module_manifest_dict[module]) opt_map_dict[module] = parse_manifest(module_manifest_dict[module])
module_files_dict = {} module_files_dict = {}
from path import make_list_of_files from path import make_list_of_files
for module in modules_paths: for module in modules_paths:
if module in opt_map_dict: if module in opt_map_dict:
module_files_dict[module] = make_list_of_files(module, opt_map_dict[module].files, os.path.dirname(module_manifest_dict[module])) module_files_dict[module] = make_list_of_files(module, opt_map_dict[module].files, os.path.dirname(module_manifest_dict[module]), file_type="vhd")
else: else:
module_files_dict[module] = make_list_of_files(module) module_files_dict[module] = make_list_of_files(module, file_type="vhd")
all_files = [] all_files = []
file_lib_dict = {} file_lib_dict = {}
for k in module_files_dict: for k in module_files_dict:
for x in module_files_dict[k]: for x in module_files_dict[k]:
if k in opt_map_dict: if k in opt_map_dict:
...@@ -117,15 +118,16 @@ def generate_deps_for_vhdl_in_modules(modules_paths): ...@@ -117,15 +118,16 @@ def generate_deps_for_vhdl_in_modules(modules_paths):
file_lib_dict[os.path.abspath(x)] = "work" file_lib_dict[os.path.abspath(x)] = "work"
all_files.append(os.path.abspath(x)) all_files.append(os.path.abspath(x))
all_files = list(set(all_files)) all_files = list(set(all_files))
p.pprint(all_files)
#all_files = [(opt_map_dict[k].library, os.path.abspath(x)) for k in module_files_dict for x in module_files_dict[k]] #all_files = [(opt_map_dict[k].library, os.path.abspath(x)) for k in module_files_dict for x in module_files_dict[k]]
all_vhdl_files = [x for x in all_files if os.path.splitext(x)[1] == '.vhd'] all_vhdl_files = [x for x in all_files if os.path.splitext(x)[1] == '.vhd']
p.vpprint(all_vhdl_files) p.vpprint(all_vhdl_files)
file_use_clause_dict = {} file_use_clause_dict = {}
for file in all_vhdl_files: for file in all_vhdl_files:
file_use_clause_dict[file] = search_for_use(file) file_use_clause_dict[file] = search_for_use(file)
p.vpprint(file_use_clause_dict) p.vpprint(file_use_clause_dict)
package_file_dict = {} package_file_dict = {}
for file in all_vhdl_files: for file in all_vhdl_files:
packages = search_for_package(file) #look for package definitions packages = search_for_package(file) #look for package definitions
...@@ -142,10 +144,10 @@ def generate_deps_for_vhdl_in_modules(modules_paths): ...@@ -142,10 +144,10 @@ def generate_deps_for_vhdl_in_modules(modules_paths):
p.echo("There might be a problem... Compilation unit " + file_purename + p.echo("There might be a problem... Compilation unit " + file_purename +
" has several instances:\n\t" + file + "\n\t" + package_file_dict[file_purename]) " has several instances:\n\t" + file + "\n\t" + package_file_dict[file_purename])
package_file_dict[file_purename.lower()] = file package_file_dict[file_purename.lower()] = file
p.vpprint(package_file_dict) p.vpprint(package_file_dict)
p.vpprint(file_lib_dict) p.vpprint(file_lib_dict)
file_file_dict = {} file_file_dict = {}
for file in all_vhdl_files: for file in all_vhdl_files:
file_units_list = file_use_clause_dict[file] file_units_list = file_use_clause_dict[file]
...@@ -169,6 +171,37 @@ def modelsim_ini_path(): ...@@ -169,6 +171,37 @@ def modelsim_ini_path():
vsim_path = os.popen("which vsim").read().strip() vsim_path = os.popen("which vsim").read().strip()
bin_path = os.path.dirname(vsim_path) bin_path = os.path.dirname(vsim_path)
return os.path.abspath(bin_path+"/../") return os.path.abspath(bin_path+"/../")
def generate_list_makefile(file_deps_dict, file_lib_dict):
from time import gmtime, strftime
import path
#p.vpprint(file_deps_dict)
#p.vpprint(file_lib_dict)
#from path import relpath as rp
date = strftime("%a, %d %b %Y %H:%M:%S", gmtime())
notices = """#######################################################################
# This makefile has been automatically generated by hdl-make
# for project """ + path.url_basename(global_mod.cwd) + """ on """ + date + """
#######################################################################
"""
filename = "ise_list"
rp = os.path.relpath
f = open("Makefile_list", "w")
f.write(notices)
f.write("file: create_a_file\n")
f.write("create_a_file:\n\t\t@printf \"\" > " + filename + "\n")
f.write("file: ")
for file in file_deps_dict:
f.write(rp(file)+"__print \\\n")
f.write("\n")
for file in file_deps_dict:
f.write(rp(file)+"__print: ")
f.write(' '.join( rp(x)+"__print" for x in file_deps_dict[file]))
f.write('\n')
f.write("\t\t@echo \'"+file_lib_dict[file]+';'+rp(file)+"\' >> ise_list\n\n")
f.write("\t\t@echo Done.")
def generate_makefile(file_deps_dict, file_lib_dict): def generate_makefile(file_deps_dict, file_lib_dict):
from time import gmtime, strftime from time import gmtime, strftime
import path import path
...@@ -226,7 +259,7 @@ clean: ...@@ -226,7 +259,7 @@ clean:
f.write('LIBS := ') f.write('LIBS := ')
f.write(' '.join(libs)) f.write(' '.join(libs))
f.write('\n') f.write('\n')
#tell hwo to make libraries #tell how to make libraries
f.write('LIB_IND := ') f.write('LIB_IND := ')
f.write(' '.join([lib+"/."+lib for lib in libs])) f.write(' '.join([lib+"/."+lib for lib in libs]))
f.write('\n') f.write('\n')
......
...@@ -29,7 +29,7 @@ def parse_repo_url(url) : ...@@ -29,7 +29,7 @@ def parse_repo_url(url) :
""" """
url_pat = re.compile("[ \t]*([^ \t]+)[ \t]*(@[ \t]*(.+))?[ \t]*") url_pat = re.compile("[ \t]*([^ \t]+)[ \t]*(@[ \t]*(.+))?[ \t]*")
url_match = re.match(url_pat, url) url_match = re.match(url_pat, url)
if url_match == None: if url_match == None:
p.echo("Skipping") p.echo("Skipping")
raise RuntimeError("Not a correct repo url: " + url) raise RuntimeError("Not a correct repo url: " + url)
...@@ -38,7 +38,31 @@ def parse_repo_url(url) : ...@@ -38,7 +38,31 @@ def parse_repo_url(url) :
else: else:
ret = url_match.group(1) ret = url_match.group(1)
return ret return ret
def make_list_of_modules(top_manifest, top_opt_map):
cur_manifest = top_manifest
modules = []
new_manifests = []
opt_map = top_opt_map
while True:
if opt_map.local != None:
modules.extend(opt_map.local)
for i in opt_map.local:
manifest = search_for_manifest(i)
if manifest != None:
new_manifests.append(manifest)
if len(new_manifests) == 0:
break;
cur_manifest = new_manifests.pop()
opt_map = parse_manifest(cur_manifest)
if os.path.exists(global_mod.hdlm_path):
modules += [global_mod.hdlm_path+"/"+x for x in os.listdir(global_mod.hdlm_path)]
if len(modules) == 0:
p.vprint("No modules were found in " + global_mod.hdlm_path)
return modules
def check_module_and_append(list, module): def check_module_and_append(list, module):
""" """
Appends a module to the list if it doesn't belong to it. If it is already there, complain Appends a module to the list if it doesn't belong to it. If it is already there, complain
...@@ -52,9 +76,9 @@ def check_module_and_append(list, module): ...@@ -52,9 +76,9 @@ def check_module_and_append(list, module):
return 1 return 1
list.append(module) list.append(module)
return 0 return 0
def parse_manifest(manifest_file): def parse_manifest(manifest_file):
def make_list(sth): def make_list(sth):
if sth != None: if sth != None:
if not isinstance(sth, (list,tuple)): if not isinstance(sth, (list,tuple)):
...@@ -62,9 +86,9 @@ def parse_manifest(manifest_file): ...@@ -62,9 +86,9 @@ def parse_manifest(manifest_file):
else: else:
sth = [] sth = []
return sth return sth
manifest_path = os.path.dirname(manifest_file) manifest_path = os.path.dirname(manifest_file)
manifest_parser = cfgparse.ConfigParser(allow_py = True) manifest_parser = cfgparse.ConfigParser(allow_py = True)
manifest_parser.add_option('root', default=None) manifest_parser.add_option('root', default=None)
manifest_parser.add_option('name', default=None) manifest_parser.add_option('name', default=None)
...@@ -77,13 +101,13 @@ def parse_manifest(manifest_file): ...@@ -77,13 +101,13 @@ def parse_manifest(manifest_file):
manifest_parser.add_option('rtl', default=None) manifest_parser.add_option('rtl', default=None)
manifest_parser.add_option('files', default=None) manifest_parser.add_option('files', default=None)
manifest_parser.add_file(manifest_file) manifest_parser.add_file(manifest_file)
#Take configuration parser from the global namespace #Take configuration parser from the global namespace
opt_map = manifest_parser.parse() opt_map = manifest_parser.parse()
if opt_map.root == None: if opt_map.root == None:
opt_map.root = "." opt_map.root = "."
if opt_map.rtl == None: if opt_map.rtl == None:
opt_map.rtl = ["."] opt_map.rtl = ["."]
elif not isinstance (opt_map.rtl, list): elif not isinstance (opt_map.rtl, list):
...@@ -91,7 +115,7 @@ def parse_manifest(manifest_file): ...@@ -91,7 +115,7 @@ def parse_manifest(manifest_file):
if opt_map.ise == None: if opt_map.ise == None:
opt_map.ise = "13.1" opt_map.ise = "13.1"
opt_map.local = make_list(opt_map.local) opt_map.local = make_list(opt_map.local)
for i in opt_map.local: for i in opt_map.local:
if path.is_abs_path(i): if path.is_abs_path(i):
...@@ -108,14 +132,14 @@ def convert_xise(xise): ...@@ -108,14 +132,14 @@ def convert_xise(xise):
if not os.path.exists(xise): if not os.path.exists(xise):
p.echo("Given .xise file does not exist:" + xise) p.echo("Given .xise file does not exist:" + xise)
quit() quit()
modules = ["."] modules = ["."]
modules.append(global_mod.hdlm_path) modules.append(global_mod.hdlm_path)
files = make_list_of_files(modules) files = make_list_of_files(modules)
ise = open(xise, "r") ise = open(xise, "r")
ise_lines = [x.strip() for x in ise.readlines()] ise_lines = [x.strip() for x in ise.readlines()]
new_ise = [] new_ise = []
file_pattern = re.compile('([ \t]*<file xil_pn:name=")([^"]+)(".*>)') file_pattern = re.compile('([ \t]*<file xil_pn:name=")([^"]+)(".*>)')
#print ise_lines #print ise_lines
...@@ -136,7 +160,7 @@ def convert_xise(xise): ...@@ -136,7 +160,7 @@ def convert_xise(xise):
new_ise.append(line) new_ise.append(line)
else: else:
new_ise.append(line + "\n") new_ise.append(line + "\n")
new_ise_file = open(xise + ".new", "w") new_ise_file = open(xise + ".new", "w")
def search_for_manifest(search_path): def search_for_manifest(search_path):
...@@ -177,16 +201,17 @@ def main(): ...@@ -177,16 +201,17 @@ def main():
parser.add_option("-o", "--convert-xise", dest="xise", default=None, help="convert paths in the given XISE_FILE", metavar="XISE_FILE") parser.add_option("-o", "--convert-xise", dest="xise", default=None, help="convert paths in the given XISE_FILE", metavar="XISE_FILE")
parser.add_option("-s", "--synth-server", dest="synth_server", default=None, help="use given SERVER for remote synthesis", metavar="SERVER") parser.add_option("-s", "--synth-server", dest="synth_server", default=None, help="use given SERVER for remote synthesis", metavar="SERVER")
parser.add_option("-u", "--synth-user", dest="synth_user", default=None, help="use given USER for remote synthesis", metavar="USER") parser.add_option("-u", "--synth-user", dest="synth_user", default=None, help="use given USER for remote synthesis", metavar="USER")
parser.add_option("--no-del", dest="no_del", default=None, help="do not delete catalog after remote synthesis") parser.add_option("--make-list", dest="make_list", action="store_true", default=None, help="make list of project files in ISE format")
parser.add_option("--no-del", dest="no_del", action="store_true", default=None, help="do not delete catalog after remote synthesis")
(global_mod.options, args) = parser.parse_args() (global_mod.options, args) = parser.parse_args()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#Check if any option was selected #Check if any option was selected
if global_mod.options.local == global_mod.options.fetch == global_mod.options.remote == global_mod.options.make == global_mod.options.clean == None: # if global_mod.options.local == global_mod.options.fetch == global_mod.options.remote == global_mod.options.make == global_mod.options.clean == None:
import sys # import sys
p.echo("Are you sure you didn't forget to specify an option? At least one?") # p.echo("Are you sure you didn't forget to specify an option? At least one?")
p.echo("Maybe you should try " + sys.argv[0] + " -h") # p.echo("Maybe you should try " + sys.argv[0] + " -h")
quit() # quit()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
if global_mod.options.xise != None: if global_mod.options.xise != None:
convert_xise(global_mod.options.xise) convert_xise(global_mod.options.xise)
...@@ -368,35 +393,20 @@ def main(): ...@@ -368,35 +393,20 @@ def main():
if global_mod.options.no_del != True: if global_mod.options.no_del != True:
p.echo("Deleting synthesis folder") p.echo("Deleting synthesis folder")
global_mod.ssh.system('rm -rf ' + dest_folder) global_mod.ssh.system('rm -rf ' + dest_folder)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
if global_mod.options.make_list == True:
import depend
modules = make_list_of_modules(global_mod.top_manifest, global_mod.opt_map)
p.vprint("Modules that will be taken into account in the makefile: " + str(modules))
deps, libs = depend.generate_deps_for_vhdl_in_modules(modules)
depend.generate_list_makefile(deps, libs)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
if global_mod.options.make == True: if global_mod.options.make == True:
import depend import depend
modules = make_list_of_modules(global_mod.top_manifest, global_mod.opt_map)
cur_manifest = global_mod.top_manifest
involved_modules = []
new_manifests = []
opt_map = global_mod.opt_map
while True:
if opt_map.local != None:
involved_modules.extend(opt_map.local)
for i in opt_map.local:
manifest = search_for_manifest(i)
if manifest != None:
new_manifests.append(manifest)
if len(new_manifests) == 0:
break;
cur_manifest = new_manifests.pop()
opt_map = parse_manifest(cur_manifest)
modules = involved_modules
if os.path.exists(global_mod.hdlm_path):
modules += [global_mod.hdlm_path+"/"+x for x in os.listdir(global_mod.hdlm_path)]
if len(modules) == 0:
p.vprint("No modules were found in " + global_mod.hdlm_path)
#modules += global_mod.opt_map.rtl
p.vprint("Modules that will be taken into account in the makefile: " + str(modules)) p.vprint("Modules that will be taken into account in the makefile: " + str(modules))
deps, libs = depend.generate_deps_for_vhdl_in_modules(modules) deps, libs = depend.generate_deps_for_vhdl_in_modules(modules)
depend.generate_makefile(deps, libs) depend.generate_makefile(deps, libs)
......
...@@ -60,11 +60,11 @@ def rel2abs(path, base = os.curdir): ...@@ -60,11 +60,11 @@ def rel2abs(path, base = os.curdir):
retval = os.path.join(base,path) retval = os.path.join(base,path)
return os.path.abspath(retval) return os.path.abspath(retval)
def make_list_of_files(modules, take_files = None, base_folder = None): def make_list_of_files(modules, take_files = None, base_folder = None, file_type = None):
""" """
Make list of all files included in the list of folders Make list of all files included in the list of folders
""" """
def getfiles(path): def getfiles(path, file_type = None):
""" """
Get lists of normal files and list folders recursively Get lists of normal files and list folders recursively
""" """
...@@ -73,17 +73,23 @@ def make_list_of_files(modules, take_files = None, base_folder = None): ...@@ -73,17 +73,23 @@ def make_list_of_files(modules, take_files = None, base_folder = None):
if filename[0] == ".": #a hidden file/catalogue -> skip if filename[0] == ".": #a hidden file/catalogue -> skip
continue continue
if os.path.isdir(path + "/" + filename): if os.path.isdir(path + "/" + filename):
ret.extend(getfiles(path + "/" + filename)) ret.extend(getfiles(path + "/" + filename, file_type))
else: else:
ret.append(path + "/" + filename) if file_type == None:
ret.append(path + "/" + filename)
else:
tmp = filename.rsplit('.')
ext = tmp[len(tmp)-1]
if ext == file_type:
ret.append(path + '/' + filename)
return ret return ret
files = [] files = []
if not isinstance(modules, list): if not isinstance(modules, list):
files = getfiles(modules) files = getfiles(modules, file_type)
else: else:
for module in modules: for module in modules:
files.extend(getfiles(module)) files.extend(getfiles(module, file_type))
if take_files != None and take_files != []: if take_files != None and take_files != []:
ret_files = [] ret_files = []
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment