aboutsummaryrefslogtreecommitdiffstats
path: root/src/vhdl
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2017-10-05 20:39:59 +0200
committerTristan Gingold <tgingold@free.fr>2017-10-05 20:39:59 +0200
commitf8bf562141e892483af1f568ed4f3a858fcde878 (patch)
tree3e6dd83568e990ac4819703d701dfa2651048c1f /src/vhdl
parent1dc7ae40402166d320b8b5ff309477ed3c236407 (diff)
downloadghdl-f8bf562141e892483af1f568ed4f3a858fcde878.tar.gz
ghdl-f8bf562141e892483af1f568ed4f3a858fcde878.tar.bz2
ghdl-f8bf562141e892483af1f568ed4f3a858fcde878.zip
pnodespy: generate std_names.py
Diffstat (limited to 'src/vhdl')
-rw-r--r--src/vhdl/Makefile7
-rwxr-xr-xsrc/vhdl/python/pnodespy.py47
2 files changed, 52 insertions, 2 deletions
diff --git a/src/vhdl/Makefile b/src/vhdl/Makefile
index 7f3f51245..df65960a0 100644
--- a/src/vhdl/Makefile
+++ b/src/vhdl/Makefile
@@ -26,7 +26,8 @@ PNODESPY=python/pnodespy.py
DEPS=iirs.ads nodes.ads $(PNODES)
GEN_FILES=iirs.adb nodes_meta.ads nodes_meta.adb \
- python/libghdl/iirs.py python/libghdl/nodes_meta.py
+ python/libghdl/iirs.py python/libghdl/nodes_meta.py \
+ python/libghdl/std_names.py
all: $(GEN_FILES)
@@ -55,6 +56,10 @@ python/libghdl/nodes_meta.py: $(DEPS) $(PNODESPY)
$(PNODESPY) libghdl-meta > $@
chmod -w $@
+python/libghdl/std_names.py: $(PNODESPY)
+ $(RM) $@
+ $(PNODESPY) libghdl-names > $@
+ chmod -w $@
clean:
$(RM) -f $(GEN_FILES)
diff --git a/src/vhdl/python/pnodespy.py b/src/vhdl/python/pnodespy.py
index b356ab9fc..93cc3b26c 100755
--- a/src/vhdl/python/pnodespy.py
+++ b/src/vhdl/python/pnodespy.py
@@ -6,6 +6,7 @@ import sys
sys.path.append("../xtools")
import pnodes
+import re
libname = 'libghdl'
@@ -94,9 +95,53 @@ get_field_attribute = libghdl.nodes_meta__get_field_attribute"""
do_has_subprg()
+def do_libghdl_names():
+ pat_name_first = re.compile(
+ ' Name_(\w+)\s+: constant Name_Id := (\d+);')
+ pat_name_def = re.compile(
+ ' Name_(\w+)\s+:\s+constant Name_Id :=\s+Name_(\w+)( \+ (\d+))?;')
+ dict = {}
+ lr = pnodes.linereader('../std_names.ads')
+ while True:
+ line = lr.get()
+ m = pat_name_first.match(line)
+ if m:
+ name_def = m.group(1)
+ val = int(m.group(2))
+ dict[name_def] = val
+ res = [(name_def, val)]
+ break
+ val_max = 1
+ while True:
+ line = lr.get()
+ if line == 'end Std_Names;\n':
+ break
+ if line.endswith(':=\n'):
+ line = line.rstrip() + lr.get()
+ m = pat_name_def.match(line)
+ if m:
+ name_def = m.group(1)
+ name_ref = m.group(2)
+ val = m.group(3)
+ if not val:
+ val = 0
+ val_ref = dict.get(name_ref, None)
+ if not val_ref:
+ raise pnodes.ParseError(
+ lr, "name {0} not found".format(name_ref))
+ val = val_ref + int(val)
+ val_max = max(val_max, val)
+ dict[name_def] = val
+ res.append((name_def, val))
+ print 'class Name:'
+ for n, v in res:
+ print ' {0} = {1}'.format(n, v)
+
+
pnodes.actions.update({'class-kinds': do_class_kinds,
'libghdl-iirs': do_libghdl_iirs,
- 'libghdl-meta': do_libghdl_meta})
+ 'libghdl-meta': do_libghdl_meta,
+ 'libghdl-names': do_libghdl_names})
pnodes.main()