diff options
author | Jonsba <jonasb@tranquille.ch> | 2016-06-28 04:26:18 +0200 |
---|---|---|
committer | tgingold <tgingold@users.noreply.github.com> | 2016-06-28 04:26:18 +0200 |
commit | 2ea6a59083a16e3093116101bc574fce623ff344 (patch) | |
tree | 79c94a95baf39f690cbd56f513d695c981ce6e1d | |
parent | dc8680d3b002df5dbc2c92e86b133803a9e68a39 (diff) | |
download | ghdl-2ea6a59083a16e3093116101bc574fce623ff344.tar.gz ghdl-2ea6a59083a16e3093116101bc574fce623ff344.tar.bz2 ghdl-2ea6a59083a16e3093116101bc574fce623ff344.zip |
Jonsba/master (#100)
* Add a --unbuffered option for simulation. It disables buffering for stdout, stderr and files opened in write or append mode (TEXTIO).
Fixes #87
* Some simplifications made on the previous commit. Documentation added for --unbuffered in Simulation_and_runtime.rst.
* Some more simplifications on unbuffered writes support for TEXTIO
* Fix a style issue failure reported by Travis-CI
-rw-r--r-- | doc/Simulation_and_runtime.rst | 5 | ||||
-rw-r--r-- | src/grt/grt-files.adb | 4 | ||||
-rw-r--r-- | src/grt/grt-options.adb | 5 | ||||
-rw-r--r-- | src/grt/grt-options.ads | 4 | ||||
-rw-r--r-- | src/grt/grt-stdio.ads | 7 |
5 files changed, 25 insertions, 0 deletions
diff --git a/doc/Simulation_and_runtime.rst b/doc/Simulation_and_runtime.rst index 9a925da4b..37a83521f 100644 --- a/doc/Simulation_and_runtime.rst +++ b/doc/Simulation_and_runtime.rst @@ -113,6 +113,11 @@ all options available, including the debugging one. design. +.. option:: --unbuffered + + Disable buffering on stdout, stderr and files opened in write or append mode (TEXTIO). + + .. option:: --vcd=<FILENAME> .. option:: --vcdgz=<FILENAME> diff --git a/src/grt/grt-files.adb b/src/grt/grt-files.adb index a47381289..694572362 100644 --- a/src/grt/grt-files.adb +++ b/src/grt/grt-files.adb @@ -26,6 +26,7 @@ with Grt.Errors; use Grt.Errors; with Grt.Stdio; use Grt.Stdio; with Grt.C; use Grt.C; with Grt.Table; +with Grt.Options; with System; use System; pragma Elaborate_All (Grt.Table); @@ -195,6 +196,9 @@ package body Grt.Files is if F = NULL_Stream then return Name_Error; end if; + if Grt.Options.Unbuffered_Writes and Mode /= Read_Mode then + setbuf (F, NULL_voids); + end if; end if; Sig := Files_Table.Table (File).Signature; if Sig /= null then diff --git a/src/grt/grt-options.adb b/src/grt/grt-options.adb index 81fa962f0..943ff9626 100644 --- a/src/grt/grt-options.adb +++ b/src/grt/grt-options.adb @@ -25,6 +25,7 @@ with Interfaces; use Interfaces; with Grt.Strings; use Grt.Strings; with Grt.Errors; use Grt.Errors; +with Grt.Stdio; use Grt.Stdio; with Grt.Astdio; with Grt.Hooks; @@ -477,6 +478,10 @@ package body Grt.Options is end if; Last_Generic_Override := Over; end; + elsif Option = "--unbuffered" then + Unbuffered_Writes := True; + setbuf (stdout, NULL_voids); + setbuf (stderr, NULL_voids); elsif not Grt.Hooks.Call_Option_Hooks (Option) then Error_C ("unknown option '"); Error_C (Option); diff --git a/src/grt/grt-options.ads b/src/grt/grt-options.ads index 7233232d8..bd3721921 100644 --- a/src/grt/grt-options.ads +++ b/src/grt/grt-options.ads @@ -140,6 +140,10 @@ package Grt.Options is -- CPUs. Nbr_Threads : Natural := 1; + -- If true, writes are made without buffering on a file opened in write_mode + -- or append_mode (TEXTIO) + Unbuffered_Writes : Boolean := False; + -- Set the time resolution. -- Only call this subprogram if you are allowed to set the time resolution. procedure Set_Time_Resolution (Res : Character); diff --git a/src/grt/grt-stdio.ads b/src/grt/grt-stdio.ads index 9084eab82..5e96d3535 100644 --- a/src/grt/grt-stdio.ads +++ b/src/grt/grt-stdio.ads @@ -38,6 +38,9 @@ package Grt.Stdio is -- NULL for a stream. NULL_Stream : constant FILEs; + -- NULL for a void pointer + NULL_voids : constant voids; + -- Predefined streams. function stdout return FILEs; function stderr return FILEs; @@ -47,6 +50,8 @@ package Grt.Stdio is function fopen (path: chars; mode : chars) return FILEs; + procedure setbuf (stream : FILEs; buffer : voids); + function fwrite (buffer : voids; size : size_t; count : size_t; stream : FILEs) return size_t; @@ -79,8 +84,10 @@ private -- of System). -- I am pretty sure the C definition of NULL is 0. NULL_Stream : constant FILEs := FILEs (System'To_Address (0)); + NULL_voids : constant voids := voids (System'To_Address (0)); pragma Import (C, fopen); + pragma Import (C, setbuf); pragma Import (C, fwrite); pragma Import (C, fread); |