diff options
| author | Tristan Gingold <tgingold@free.fr> | 2018-11-28 20:11:10 +0100 | 
|---|---|---|
| committer | Tristan Gingold <tgingold@free.fr> | 2018-11-28 20:11:10 +0100 | 
| commit | 0c0a05aecfab3ef42592166881cb5a253ea14709 (patch) | |
| tree | daf95696415484789c9500c4eebf12971e0e21e8 | |
| parent | d6556ba57fb0a340ab23197fbc5c6bf0b0b46b3b (diff) | |
| download | ghdl-0c0a05aecfab3ef42592166881cb5a253ea14709.tar.gz ghdl-0c0a05aecfab3ef42592166881cb5a253ea14709.tar.bz2 ghdl-0c0a05aecfab3ef42592166881cb5a253ea14709.zip  | |
Add logging and use it in files_map.
| -rw-r--r-- | src/files_map.adb | 54 | ||||
| -rw-r--r-- | src/files_map.ads | 3 | ||||
| -rw-r--r-- | src/logging.adb | 31 | ||||
| -rw-r--r-- | src/logging.ads | 22 | 
4 files changed, 85 insertions, 25 deletions
diff --git a/src/files_map.adb b/src/files_map.adb index 999b0468d..abbd0c48c 100644 --- a/src/files_map.adb +++ b/src/files_map.adb @@ -15,11 +15,11 @@  --  along with GHDL; see the file COPYING.  If not, write to the Free  --  Software Foundation, 59 Temple Place - Suite 330, Boston, MA  --  02111-1307, USA. -with Ada.Text_IO; use Ada.Text_IO;  with Ada.Unchecked_Deallocation;  with GNAT.OS_Lib;  with GNAT.SHA1;  with GNAT.Directory_Operations; +with Logging; use Logging;  with Name_Table; use Name_Table;  with Str_Table;  with Ada.Calendar; @@ -119,9 +119,9 @@ package body Files_Map is        --  Debug trace.        if False then -         Put_Line ("file" & Source_File_Entry'Image (File) -                   & " line" & Natural'Image (Line) -                   & " at position" & Source_Ptr'Image (Pos)); +         Log_Line ("file" & Source_File_Entry'Image (File) +                     & " line" & Natural'Image (Line) +                     & " at position" & Source_Ptr'Image (Pos));        end if;        --  The position of the first line is well-known. @@ -149,7 +149,7 @@ package body Files_Map is        else           --  If the line position is already known, it must be the same.           if Pos /= Source_File.Lines.Table (Line) then -            Put_Line ("file" & Source_File_Entry'Image (File) +            Log_Line ("file" & Source_File_Entry'Image (File)                          & " for line" & Natural'Image (Line)                          & " pos =" & Source_Ptr'Image (Pos)                          & ", lines_table = " @@ -1096,7 +1096,7 @@ package body Files_Map is        Offset : Natural;     begin        Location_To_Coord (Loc, File, Line_Pos, Line, Offset); -      Put_Line (Extract_Expanded_Line (File, Line_Pos)); +      Log_Line (Extract_Expanded_Line (File, Line_Pos));     end Debug_Source_Loc;     --  Disp sources lines of a file. @@ -1105,8 +1105,8 @@ package body Files_Map is     begin        Check_File (File);        for I in Lines_Tables.First .. Lines_Tables.Last (Source_File.Lines) loop -         Put_Line ("line" & Natural'Image (I) & " at offset" -                   & Source_Ptr'Image (Source_File.Lines.Table (I))); +         Log_Line ("line" & Natural'Image (I) & " at offset" +                     & Source_Ptr'Image (Source_File.Lines.Table (I)));        end loop;     end Debug_Source_Lines; @@ -1116,31 +1116,37 @@ package body Files_Map is           declare              F : Source_File_Record renames Source_Files.Table(I);           begin -            Put ('*'); -            Put (Source_File_Entry'Image (I)); -            Put (" name: " & Image (F.File_Name)); -            Put (" dir:" & Image (F.Directory)); -            Put (" length:" & Source_Ptr'Image (F.File_Length)); -            New_Line; -            Put (" location:" & Location_Type'Image (F.First_Location) +            Log ("*"); +            Log (Source_File_Entry'Image (I)); +            Log (" name: " & Image (F.File_Name)); +            Log (" dir:" & Image (F.Directory)); +            Log (" file length:" & Source_Ptr'Image (F.File_Length)); +            Log_Line; +            Log (" location:" & Location_Type'Image (F.First_Location)                     & " -" & Location_Type'Image (F.Last_Location)); -            New_Line; +            Log_Line;              if F.Checksum /= No_File_Checksum_Id then -               Put (" checksum: " & Get_File_Checksum_String (F.Checksum)); -               New_Line; +               Log (" checksum: " & Get_File_Checksum_String (F.Checksum)); +               Log_Line;              end if;              case F.Kind is                 when Source_File_File => -                  Put (" nbr lines:" +                  Log (" buf:" & Source_Ptr'Image (F.Source'First) +                         & " -" & Source_Ptr'Image (F.Source'Last)); +                  Log_Line; +                  Log (" nbr lines:"                           & Natural'Image (Lines_Tables.Last (F.Lines))); -                  New_Line; +                  Log_Line; +                  Log (" Gap:" & Source_Ptr'Image (F.Gap_Start) +                         & " -" & Source_Ptr'Image (F.Gap_Last)); +                  Log_Line;                 when Source_File_String =>                    null;                 when Source_File_Instance => -                  Put (" instance from:" & Source_File_Entry'Image (F.Ref)); -                  Put (", base:" & Source_File_Entry'Image (F.Base)); -                  Put (", loc:" & Image (F.Instance_Loc)); -                  New_Line; +                  Log (" instance from:" & Source_File_Entry'Image (F.Ref)); +                  Log (", base:" & Source_File_Entry'Image (F.Base)); +                  Log (", loc:" & Image (F.Instance_Loc)); +                  Log_Line;              end case;           end;        end loop; diff --git a/src/files_map.ads b/src/files_map.ads index 4f6ed2933..d2f2a0a4d 100644 --- a/src/files_map.ads +++ b/src/files_map.ads @@ -270,7 +270,8 @@ private        --  The buffer containing the file.        Source : File_Buffer_Acc; -      --  Length of the file, which is less than the length of the buffer. +      --  Position of the EOT character after the file.  Also the length of +      --  the file + 1, unless there is a gap.        File_Length : Source_Ptr;        Checksum : File_Checksum_Id; diff --git a/src/logging.adb b/src/logging.adb new file mode 100644 index 000000000..c582b3351 --- /dev/null +++ b/src/logging.adb @@ -0,0 +1,31 @@ +--  Very simple logging package. +--  Copyright (C) 2018 Tristan Gingold +-- +--  GHDL is free software; you can redistribute it and/or modify it under +--  the terms of the GNU General Public License as published by the Free +--  Software Foundation; either version 2, or (at your option) any later +--  version. +-- +--  GHDL is distributed in the hope that it will be useful, but WITHOUT ANY +--  WARRANTY; without even the implied warranty of MERCHANTABILITY or +--  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License +--  for more details. +-- +--  You should have received a copy of the GNU General Public License +--  along with GHDL; see the file COPYING.  If not, write to the Free +--  Software Foundation, 59 Temple Place - Suite 330, Boston, MA +--  02111-1307, USA. + +with Ada.Text_IO; use Ada.Text_IO; + +package body Logging is +   procedure Log (S : String) is +   begin +      Put (Standard_Error, S); +   end Log; + +   procedure Log_Line (S : String := "") is +   begin +      Put_Line (Standard_Error, S); +   end Log_Line; +end Logging; diff --git a/src/logging.ads b/src/logging.ads new file mode 100644 index 000000000..faf802193 --- /dev/null +++ b/src/logging.ads @@ -0,0 +1,22 @@ +--  Very simple logging package. +--  Copyright (C) 2018 Tristan Gingold +-- +--  GHDL is free software; you can redistribute it and/or modify it under +--  the terms of the GNU General Public License as published by the Free +--  Software Foundation; either version 2, or (at your option) any later +--  version. +-- +--  GHDL is distributed in the hope that it will be useful, but WITHOUT ANY +--  WARRANTY; without even the implied warranty of MERCHANTABILITY or +--  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License +--  for more details. +-- +--  You should have received a copy of the GNU General Public License +--  along with GHDL; see the file COPYING.  If not, write to the Free +--  Software Foundation, 59 Temple Place - Suite 330, Boston, MA +--  02111-1307, USA. + +package Logging is +   procedure Log (S : String); +   procedure Log_Line (S : String := ""); +end Logging;  | 
