From d679149045aaf9eab462b98f67d4064791e2ff40 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Thu, 13 Dec 2018 18:55:45 +0100 Subject: python: generate errorout.py --- src/vhdl/Makefile | 7 ++++++- src/vhdl/python/pnodespy.py | 50 ++++++++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/vhdl/Makefile b/src/vhdl/Makefile index 3fadbeacc..e4a7c91d5 100644 --- a/src/vhdl/Makefile +++ b/src/vhdl/Makefile @@ -29,7 +29,7 @@ GEN_FILES=iirs.adb nodes_meta.ads nodes_meta.adb \ elocations.adb elocations_meta.ads elocations_meta.adb \ python/libghdl/iirs.py python/libghdl/nodes_meta.py \ python/libghdl/std_names.py python/libghdl/tokens.py \ - python/libghdl/elocations.py + python/libghdl/elocations.py python/libghdl/errorout.py ELOCATIONS_FLAGS=--node-file=elocations.ads --field-file=elocations.adb.in \ --template-file=elocations.adb.in --meta-basename=elocations_meta @@ -91,5 +91,10 @@ python/libghdl/elocations.py: $(PNODESPY) elocations.ads $(PNODESPY) $(ELOCATIONS_FLAGS) libghdl-elocs > $@ chmod -w $@ +python/libghdl/errorout.py: $(PNODESPY) errorout.ads + $(RM) $@ + $(PNODESPY) $(ELOCATIONS_FLAGS) libghdl-errorout > $@ + chmod -w $@ + clean: $(RM) -f $(GEN_FILES) diff --git a/src/vhdl/python/pnodespy.py b/src/vhdl/python/pnodespy.py index 4c8353fca..96e66b54a 100755 --- a/src/vhdl/python/pnodespy.py +++ b/src/vhdl/python/pnodespy.py @@ -96,13 +96,19 @@ def do_class_fields(): print_enum('fields', [f.name for f in pnodes.funcs]) -def read_spec_enum(type_name, prefix, class_name): - """Read an enumeration declaration from iirs.ads""" +def read_enum(filename, type_name, prefix, class_name, g=lambda m:m.group(1)): + """Read an enumeration declaration from :param filename:""" pat_decl = re.compile(r' type {0} is$'.format(type_name)) - pat_enum = re.compile(r' {0}(\w+),?(-- .*)?$'.format(prefix)) - lr = pnodes.linereader(pnodes.kind_file) + pat_enum = re.compile(r' {0}(\w+),?( *-- .*)?$'.format(prefix)) + pat_comment = re.compile(r' *-- .*$') + lr = pnodes.linereader(filename) while not pat_decl.match(lr.get()): pass + line = lr.get() + if line != ' (\n': + raise pnodes.ParseError( + lr, "{}:{}: missing open parenthesis".format( + filename, lr.lineno)) toks = [] while True: line = lr.get() @@ -110,10 +116,24 @@ def read_spec_enum(type_name, prefix, class_name): break m = pat_enum.match(line) if m: - toks.append(m.group(1)) + toks.append(g(m)) + elif pat_comment.match(line): + pass + elif line == '\n': + pass + else: + print(line, file=sys.stderr) + raise pnodes.ParseError( + lr, "{}:{}: incorrect line in enum {}".format( + filename, lr.lineno, type_name)) print_enum(class_name, toks) +def read_spec_enum(type_name, prefix, class_name): + """Read an enumeration declaration from iirs.ads""" + read_enum(pnodes.kind_file, type_name, prefix, class_name) + + def do_libghdl_iirs(): print('from libghdl import libghdl') do_class_kinds() @@ -197,17 +217,12 @@ def do_libghdl_names(): def do_libghdl_tokens(): - pat_token = re.compile(r' Tok_(\w+),?\s*(--.*)?$') - lr = pnodes.linereader('tokens.ads') - toks = [] - while True: - line = lr.get() - if line == ' );\n': - break - m = pat_token.match(line) - if m: - toks.append(m.group(1)) - print_enum("Tok", toks) + read_enum("tokens.ads", "Token_Type", "Tok_", "Tok") + + +def do_libghdl_errorout(): + read_enum("errorout.ads", "Msgid_Type", "(Msgid|Warnid)_", "Msgid", + g=lambda m: m.group(1) + '_' + m.group(2)) pnodes.actions.update({'class-kinds': do_class_kinds, @@ -215,7 +230,8 @@ pnodes.actions.update({'class-kinds': do_class_kinds, 'libghdl-meta': do_libghdl_meta, 'libghdl-names': do_libghdl_names, 'libghdl-tokens': do_libghdl_tokens, - 'libghdl-elocs': do_libghdl_elocations}) + 'libghdl-elocs': do_libghdl_elocations, + 'libghdl-errorout': do_libghdl_errorout}) pnodes.main() -- cgit v1.2.3