aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-06-04 18:25:53 +0200
committerTristan Gingold <tgingold@free.fr>2019-06-04 18:25:53 +0200
commit25f61f81547d51ecc3983eb5779813fb94ca90ef (patch)
tree0e23044abd1a51ecf41c362299aebd1b3d6e1525
parentf653b8b1328f2ec6d13f221ee6f9817091de91f6 (diff)
downloadghdl-25f61f81547d51ecc3983eb5779813fb94ca90ef.tar.gz
ghdl-25f61f81547d51ecc3983eb5779813fb94ca90ef.tar.bz2
ghdl-25f61f81547d51ecc3983eb5779813fb94ca90ef.zip
vhdl: adjust formatters and add python bindings.
-rw-r--r--src/vhdl/python/libghdl.adb2
-rw-r--r--src/vhdl/python/libghdl/thin/vhdl/formatters.py14
-rw-r--r--src/vhdl/python/libghdl/thin/vhdl/sem.py3
-rw-r--r--src/vhdl/vhdl-formatters.adb15
-rw-r--r--src/vhdl/vhdl-formatters.ads2
5 files changed, 30 insertions, 6 deletions
diff --git a/src/vhdl/python/libghdl.adb b/src/vhdl/python/libghdl.adb
index cf87cb158..7226e5295 100644
--- a/src/vhdl/python/libghdl.adb
+++ b/src/vhdl/python/libghdl.adb
@@ -21,8 +21,10 @@ with Ghdllocal;
with Ghdlcomp;
with Errorout.Memory;
with Files_Map.Editor;
+with Vhdl.Formatters;
pragma Unreferenced (Errorout.Memory); -- At least from Ada code.
pragma Unreferenced (Files_Map.Editor);
+pragma Unreferenced (Vhdl.Formatters);
package body Libghdl is
function Set_Option (Opt : Thin_String_Ptr; Len : Natural) return Integer is
diff --git a/src/vhdl/python/libghdl/thin/vhdl/formatters.py b/src/vhdl/python/libghdl/thin/vhdl/formatters.py
new file mode 100644
index 000000000..9c8bf9afb
--- /dev/null
+++ b/src/vhdl/python/libghdl/thin/vhdl/formatters.py
@@ -0,0 +1,14 @@
+from libghdl import libghdl
+from ctypes import c_int32, c_char_p
+
+Indent_String = libghdl.vhdl__formatters__indent_string
+
+Allocate_Handle = libghdl.vhdl__formatters__allocate_handle
+
+Get_Length = libghdl.vhdl__formatters__get_length
+Get_Length.restype = c_int32
+
+Get_C_String = libghdl.vhdl__formatters__get_c_string
+Get_C_String.restype = c_char_p
+
+Free_Handle = libghdl.vhdl__formatters__free_handle
diff --git a/src/vhdl/python/libghdl/thin/vhdl/sem.py b/src/vhdl/python/libghdl/thin/vhdl/sem.py
new file mode 100644
index 000000000..df82435da
--- /dev/null
+++ b/src/vhdl/python/libghdl/thin/vhdl/sem.py
@@ -0,0 +1,3 @@
+from libghdl import libghdl
+
+Semantic = libghdl.vhdl__sem__semantic
diff --git a/src/vhdl/vhdl-formatters.adb b/src/vhdl/vhdl-formatters.adb
index 99d80f856..f6103f571 100644
--- a/src/vhdl/vhdl-formatters.adb
+++ b/src/vhdl/vhdl-formatters.adb
@@ -260,6 +260,9 @@ package body Vhdl.Formatters is
Init (Ctxt, Sfe);
Prints.Disp_Vhdl (Ctxt, F);
+ Close_File;
+ Scanner.Flag_Comment := False;
+ Scanner.Flag_Newline := False;
end Format;
package Indent_Disp_Ctxt is
@@ -520,7 +523,7 @@ package body Vhdl.Formatters is
return Grt.Vstrings.Get_C_String (Handle.all);
end Get_C_String;
- procedure Free (Handle : Vstring_Acc)
+ procedure Free_Handle (Handle : Vstring_Acc)
is
procedure Deallocate is new Ada.Unchecked_Deallocation
(Grt.Vstrings.Vstring, Vstring_Acc);
@@ -529,7 +532,7 @@ package body Vhdl.Formatters is
Grt.Vstrings.Free (Handle.all);
Handle1 := Handle;
Deallocate (Handle1);
- end Free;
+ end Free_Handle;
procedure Indent_String (F : Iir_Design_File;
Handle : Vstring_Acc;
@@ -542,6 +545,10 @@ package body Vhdl.Formatters is
begin
Init (Ctxt, Handle, Sfe, First_Line, Last_Line);
Prints.Disp_Vhdl (Ctxt, F);
+
+ Close_File;
+ Scanner.Flag_Comment := False;
+ Scanner.Flag_Newline := False;
end Indent_String;
procedure Indent (F : Iir_Design_File;
@@ -570,10 +577,8 @@ package body Vhdl.Formatters is
Res := Get_C_String (Handle);
Len := Get_Length (Handle);
Simple_IO.Put (Res (1 .. Len));
- Free (Handle);
+ Free_Handle (Handle);
end;
end if;
end Indent;
-
-
end Vhdl.Formatters;
diff --git a/src/vhdl/vhdl-formatters.ads b/src/vhdl/vhdl-formatters.ads
index f07abb5bb..029290107 100644
--- a/src/vhdl/vhdl-formatters.ads
+++ b/src/vhdl/vhdl-formatters.ads
@@ -41,5 +41,5 @@ package Vhdl.Formatters is
function Get_Length (Handle : Vstring_Acc) return Natural;
function Get_C_String (Handle : Vstring_Acc)
return Grt.Types.Ghdl_C_String;
- procedure Free (Handle : Vstring_Acc);
+ procedure Free_Handle (Handle : Vstring_Acc);
end Vhdl.Formatters;