]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/m2/gm2-libs/Debug.mod
Update copyright years.
[thirdparty/gcc.git] / gcc / m2 / gm2-libs / Debug.mod
1 (* Debug.mod provides some simple debugging routines.
2
3 Copyright (C) 2001-2023 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
5
6 This file is part of GNU Modula-2.
7
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
21
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. *)
26
27 IMPLEMENTATION MODULE Debug ;
28
29 FROM ASCII IMPORT cr, nul, lf ;
30 FROM NumberIO IMPORT CardToStr ;
31 FROM StdIO IMPORT Write ;
32 FROM libc IMPORT exit ;
33
34
35 (*
36 Halt - writes a message in the format:
37 Module:Line:Message
38
39 It then terminates by calling HALT.
40 *)
41
42 PROCEDURE Halt (Message: ARRAY OF CHAR;
43 LineNo: CARDINAL;
44 Module: ARRAY OF CHAR) ;
45 CONST
46 MaxNoOfDigits = 12 ; (* should be large enough for most source files.. *)
47 VAR
48 No : ARRAY [0..MaxNoOfDigits] OF CHAR ;
49 BEGIN
50 DebugString(Module) ;
51 CardToStr(LineNo, 0, No) ;
52 DebugString(':') ;
53 DebugString(No) ;
54 DebugString(':') ;
55 DebugString(Message) ;
56 DebugString('\n') ;
57 HALT
58 END Halt ;
59
60
61 (*
62 DebugString - writes a string to the debugging device (Scn.Write).
63 It interprets \n as carriage return, linefeed.
64 *)
65
66 PROCEDURE DebugString (a: ARRAY OF CHAR) ;
67 VAR
68 n, high: CARDINAL ;
69 BEGIN
70 high := HIGH( a ) ;
71 n := 0 ;
72 WHILE (n <= high) AND (a[n] # nul) DO
73 IF a[n]='\'
74 THEN
75 IF n+1<=high
76 THEN
77 IF a[n+1]='n'
78 THEN
79 WriteLn ;
80 INC(n)
81 ELSIF a[n+1]='\'
82 THEN
83 Write('\') ;
84 INC(n)
85 END
86 END
87 ELSE
88 Write( a[n] )
89 END ;
90 INC( n )
91 END
92 END DebugString ;
93
94
95 (*
96 WriteLn - writes a carriage return and a newline
97 character.
98 *)
99
100 PROCEDURE WriteLn ;
101 BEGIN
102 Write(cr) ;
103 Write(lf)
104 END WriteLn ;
105
106
107 END Debug.