aboutsummaryrefslogtreecommitdiffstats
path: root/src/vhdl/python
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2017-10-06 20:52:49 +0200
committerTristan Gingold <tgingold@free.fr>2017-10-06 20:52:49 +0200
commit09733cedabdaef6c1adba4473ce4abd863defa89 (patch)
treed6d936c31f4fa18ed2475937127c25c391cd8c72 /src/vhdl/python
parentf1c1deaa61dc79a1c6c15aafd1b90fb6be9d8b4c (diff)
downloadghdl-09733cedabdaef6c1adba4473ce4abd863defa89.tar.gz
ghdl-09733cedabdaef6c1adba4473ce4abd863defa89.tar.bz2
ghdl-09733cedabdaef6c1adba4473ce4abd863defa89.zip
python: add more interfaces.
Diffstat (limited to 'src/vhdl/python')
-rw-r--r--src/vhdl/python/libghdl/thin.py39
-rwxr-xr-xsrc/vhdl/python/pnodespy.py9
2 files changed, 42 insertions, 6 deletions
diff --git a/src/vhdl/python/libghdl/thin.py b/src/vhdl/python/libghdl/thin.py
index 6565045f6..ae12c3864 100644
--- a/src/vhdl/python/libghdl/thin.py
+++ b/src/vhdl/python/libghdl/thin.py
@@ -1,10 +1,12 @@
from libghdl import libghdl
-from ctypes import (c_char_p, c_int32)
+from ctypes import (c_char_p, c_int32, c_int, c_bool, sizeof)
import iirs
import nodes_meta
from nodes_meta import (Attr, types)
# from libghdl_defs import (fields, Iir_Kind, types, Attr)
+assert sizeof(c_bool) == 1
+
# libghdl
_set_option = libghdl.libghdl__set_option
@@ -39,9 +41,13 @@ Location_File_To_Line = libghdl.files_map__location_file_to_line
location_File_Line_To_Col = libghdl.files_map__location_file_line_to_col
+Get_File_Name = libghdl.files_map__get_file_name
+
Get_File_Buffer = libghdl.files_map__get_file_buffer
Get_File_Buffer.restype = c_char_p
+Get_File_Length = libghdl.files_map__get_file_length
+
Read_Source_File = libghdl.files_map__read_source_file
No_Source_File_Entry = 0
@@ -55,9 +61,35 @@ Get_Name_Ptr.restype = c_char_p
_Get_Identifier_With_Len = libghdl.name_table__get_identifier_with_len
+
def Get_Identifier(s):
return _Get_Identifier_With_Len(c_char_p(s), len(s))
+
+# Scanner
+class Scanner:
+ Set_File = libghdl.scanner__set_file
+
+ Scan = libghdl.scanner__scan
+
+ # This is a c_int, so you want to use its .value
+ Current_Token = c_int.in_dll(libghdl, "scanner__current_token")
+
+ Flag_Comment = c_bool.in_dll(libghdl, "scanner__flag_comment")
+
+ Get_Current_Line = libghdl.scanner__get_current_line
+
+ Get_Token_Column = libghdl.scanner__get_token_column
+
+ Get_Token_Position = libghdl.scanner__get_token_position
+
+ Get_Position = libghdl.scanner__get_position
+
+
+class Parse:
+ Parse_Design_File = libghdl.parse__parse_design_file
+
+
# std.standard
Standard_Package = c_int32.in_dll(libghdl, "std_package__standard_package")
@@ -128,6 +160,11 @@ def chain_iter(n):
n = iirs.Get_Chain(n)
+def chain_to_list(n):
+ """Convert a chain headed by node n to a python list"""
+ return [e for e in chain_iter(n)]
+
+
def nodes_iter(n):
"""Iterate of all nodes of n, including n.
Nodes are returned only once."""
diff --git a/src/vhdl/python/pnodespy.py b/src/vhdl/python/pnodespy.py
index 93cc3b26c..ced4931f6 100755
--- a/src/vhdl/python/pnodespy.py
+++ b/src/vhdl/python/pnodespy.py
@@ -12,13 +12,11 @@ libname = 'libghdl'
def print_enum(name, vals):
- n = 0
print
print
print 'class {0}:'.format(name)
- for k in vals:
+ for n, k in enumerate(vals):
print ' {0} = {1}'.format(k, n)
- n += 1
def do_class_kinds():
@@ -78,6 +76,7 @@ def do_libghdl_meta():
print 'from libghdl import libghdl'
print """
+
# From nodes_meta
get_fields_first = libghdl.nodes_meta__get_fields_first
@@ -97,9 +96,9 @@ get_field_attribute = libghdl.nodes_meta__get_field_attribute"""
def do_libghdl_names():
pat_name_first = re.compile(
- ' Name_(\w+)\s+: constant Name_Id := (\d+);')
+ r' Name_(\w+)\s+: constant Name_Id := (\d+);')
pat_name_def = re.compile(
- ' Name_(\w+)\s+:\s+constant Name_Id :=\s+Name_(\w+)( \+ (\d+))?;')
+ r' Name_(\w+)\s+:\s+constant Name_Id :=\s+Name_(\w+)( \+ (\d+))?;')
dict = {}
lr = pnodes.linereader('../std_names.ads')
while True: