Skip to content

Commit

Permalink
Add HDL interface and lib parser w/ Makefile out
Browse files Browse the repository at this point in the history
Add HDL interface_ip.tcl and library *_ip.tcl and *_hw.tcl parser.
Add HDL library Makefile writer.

Signed-off-by: Jorge Marques <[email protected]>
  • Loading branch information
gastmaier committed Jun 6, 2024
1 parent 1572b25 commit ad8b153
Show file tree
Hide file tree
Showing 10 changed files with 549 additions and 26 deletions.
83 changes: 71 additions & 12 deletions adi_doctools/cli/hdl_gen.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import click
import subprocess
import re
from os import path, walk
from os import path, walk, pardir
from glob import glob

from ..typings.hdl import vendors, Library, Carrier
from ..parser.hdl import parse_hdl_regmap
from ..parser.hdl import resolve_hdl_regmap
from ..parser.hdl import expand_hdl_regmap
from ..parser.hdl import parse_hdl_vendor
from ..parser.hdl import parse_hdl_library
from ..parser.hdl import resolve_hdl_library
from ..parser.hdl import parse_hdl_interfaces
from ..writer.hdl import write_hdl_regmap

from ..writer.hdl import write_hdl_library_makefile

log = {
'hdl_f': "{} not found, are you sure this is the HDL repo?",
Expand Down Expand Up @@ -61,23 +65,78 @@ def dir_assert(file, msg):
has_tb = False if dir_assert(tbdir, log['hdl_tb']) else True

# Generate HDL carrier dictionary
carrier = {}
carrier = Carrier()
path_ = path.join(hdldir, 'projects', 'scripts')
glob_ = path.join(path_, "adi_project_*.tcl")
filenames = glob(glob_)
for file_ in filenames:
m = re.search("adi_project_(\\w+)\\.tcl", file_)
if not bool(m):
continue

vendor_name = m.group(1)
carrier[vendor_name], msg = parse_hdl_vendor(file_)
for v in vendors:
file_ = path.join(path_, f"adi_project_{v}.tcl")
carrier[v], msg = parse_hdl_vendor(file_)
for m in msg:
click.echo(f"{file_}: {m}")

# TODO do something with the parsed carriers, like get/validate library and
# project dicts

# Generate HDL Library dictionary
types = ['*_ip.tcl', '*_hw.tcl']
files = {}
library = {}
interfaces_ip_files = []
for v in vendors:
files[v] = []
for typ, v in zip(types, vendors):
glob_ = path.join(hdldir, 'library', '**', typ)
files[v].extend(glob(glob_, recursive=True))

for v in files:
for f in files[v]:
if 'interfaces_ip.tcl' in f:
files[v].remove(f)
interfaces_ip_files.append(f)

# Generate the HDL interfaces dictionary
interfaces_ip = {}
for f in interfaces_ip_files:
interfaces_ip[path.dirname(f)], msg = parse_hdl_interfaces(f)
for m in msg:
click.echo(f"{f}: {m}")

intf_key_file = {}
for f in interfaces_ip:
for k in interfaces_ip[f]:
intf_key_file[k['name']] = f

for typ, v in zip(types, files):
for f in files[v]:
key = path.dirname(f)
lib = path.basename(key)
lib2 = path.basename(f)[:-len(typ)+1]
if lib != lib2:
click.echo(f"{f}: path basename '{lib}' does not match "
f"filename '{lib2}'")
lib_, msg = parse_hdl_library(f, lib2)
for m in msg:
click.echo(f"{f}: {m}")
if lib_:
if key not in library:
library[key] = Library(
name=lib2,
vendor={},
generic={}
)
library[key]['vendor'][v] = lib_

for key in library:
resolve_hdl_library(library[key], intf_key_file, hdldir, key)

for key in library:
write_hdl_library_makefile(key, hdldir, library[key])

# Generate HDL Project dictionary
files = []
glob_ = path.join(hdldir, 'projects', '**', 'system_project.tcl')
files.extend(glob(glob_, recursive=True))
# TODO parse HDL Project, write Project Makefile

# Generate HDL Register Map dictionary
rm = {}
regdir = path.join(hdldir, 'docs', 'regmap')
Expand Down
2 changes: 1 addition & 1 deletion adi_doctools/directive/hdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def tables(self, subnode, obj, key):
# Underscore with word-breaking 0 width space
default = default.replace("_", "_\u200B")
# Ensure `` parsed as pre in formulas
for a in ['+', '-', '/', '*', '^']:
for a in ['+', '-', '/', '*', '^', '~', '!']:
default = default.replace(a + "``", a + " ``")

if type(bits) is tuple:
Expand Down
Loading

0 comments on commit ad8b153

Please sign in to comment.