From a523865a36f56882d1d0653ba9b98c65138627f5 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Fri, 16 Aug 2019 09:01:11 +0200 Subject: testsuite/python: fix test name (to follow the testsuite.sh convention) --- testsuite/python/units01/demo.vhdl | 7 ++++++ testsuite/python/units01/show_units.py | 46 ++++++++++++++++++++++++++++++++++ testsuite/python/units01/testsuite.sh | 7 ++++++ 3 files changed, 60 insertions(+) create mode 100644 testsuite/python/units01/demo.vhdl create mode 100755 testsuite/python/units01/show_units.py create mode 100755 testsuite/python/units01/testsuite.sh (limited to 'testsuite/python/units01') diff --git a/testsuite/python/units01/demo.vhdl b/testsuite/python/units01/demo.vhdl new file mode 100644 index 000000000..4e40f7e94 --- /dev/null +++ b/testsuite/python/units01/demo.vhdl @@ -0,0 +1,7 @@ +entity e1 is +end e1; + +architecture behav of e1 is +begin + assert false report "arch" severity note; +end behav; diff --git a/testsuite/python/units01/show_units.py b/testsuite/python/units01/show_units.py new file mode 100755 index 000000000..ad002312f --- /dev/null +++ b/testsuite/python/units01/show_units.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +import libghdl +import libghdl.thin.name_table as name_table +import libghdl.thin.files_map as files_map +import libghdl.thin.vhdl.nodes as nodes +import libghdl.thin.vhdl.sem_lib as sem_lib + +def init(): + """Initialization: set options and then load libaries""" + libghdl.set_option(b'--std=08') + libghdl.analyze_init() + +def get_identifier_ptr(n): + """Return the python string from node :param n: identifier""" + return name_table.Get_Name_Ptr(nodes.Get_Identifier(n)).decode('utf-8') + +def list_units(filename): + # Load the file + file_id = name_table.Get_Identifier(filename.encode('utf_8')) + sfe = files_map.Read_Source_File(name_table.Null_Identifier, file_id) + if sfe == files_map.No_Source_File_Entry: + print("cannot open file '{}'".format(filename)) + return + + # Parse and analyze + file = sem_lib.Load_File(sfe) + + # Display all design units + unit = nodes.Get_First_Design_Unit(file) + while unit != nodes.Null_Iir: + lib_unit = nodes.Get_Library_Unit(unit) + if nodes.Get_Kind(lib_unit) == nodes.Iir_Kind.Entity_Declaration: + print('entity {}'.format(get_identifier_ptr(lib_unit))) + elif nodes.Get_Kind(lib_unit) == nodes.Iir_Kind.Architecture_Body: + print('architecture {}'.format(get_identifier_ptr(lib_unit))) + else: + print('unknown unit!') + unit = nodes.Get_Chain(unit) + + +def main(): + init() + list_units('demo.vhdl') + +if __name__ == '__main__': + main() diff --git a/testsuite/python/units01/testsuite.sh b/testsuite/python/units01/testsuite.sh new file mode 100755 index 000000000..43ba6cd0f --- /dev/null +++ b/testsuite/python/units01/testsuite.sh @@ -0,0 +1,7 @@ +#! /bin/sh + +. ../../testenv.sh + +$PYTHON show_units.py + +echo "Test successful" -- cgit v1.2.3