]> gcc.gnu.org Git - gcc.git/blame - gcc/m2/gm2-libs-coroutines/Debug.mod
Year date changes for Modula-2 source tree.
[gcc.git] / gcc / m2 / gm2-libs-coroutines / Debug.mod
CommitLineData
7401123f
GM
1(* Debug.mod provides some simple debugging routines.
2
3d864fce 3Copyright (C) 2002-2022 Free Software Foundation, Inc.
7401123f
GM
4Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
5
6This file is part of GNU Modula-2.
7
8GNU Modula-2 is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GNU Modula-2 is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16General Public License for more details.
17
18Under Section 7 of GPL version 3, you are granted additional
19permissions described in the GCC Runtime Library Exception, version
203.1, as published by the Free Software Foundation.
21
22You should have received a copy of the GNU General Public License and
23a copy of the GCC Runtime Library Exception along with this program;
24see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25<http://www.gnu.org/licenses/>. *)
26
27IMPLEMENTATION MODULE Debug ;
28
29
30FROM ASCII IMPORT cr, nul, lf ;
31FROM NumberIO IMPORT CardToStr ;
32FROM libc IMPORT exit, write ;
33FROM SYSTEM IMPORT ADR ;
34
35
36CONST
37 MaxStack = 10 ;
38
39VAR
40 Stack: ARRAY [1..MaxStack] OF WriteP ;
41 Ptr : CARDINAL ;
42
43
44PROCEDURE Write (ch: CHAR) ;
45BEGIN
46 IF Ptr>0
47 THEN
48 Stack[Ptr](ch)
49 ELSE
50 LocalWrite(ch)
51 END
52END Write ;
53
54
55PROCEDURE LocalWrite (ch: CHAR) ;
56VAR
57 r: INTEGER ;
58BEGIN
59 r := write(2, ADR(ch), 1)
60END LocalWrite ;
61
62
63(*
64 PushOutput - pushes the output procedure, p, which is used Debug.
65*)
66
67PROCEDURE PushOutput (p: WriteP) ;
68BEGIN
69 IF Ptr=MaxStack
70 THEN
71 Halt(__FILE__, __LINE__, __FUNCTION__, 'stack exceeded')
72 ELSE
73 INC(Ptr) ;
74 Stack[Ptr] := p
75 END
76END PushOutput ;
77
78
79(*
80 PopOutput - pops the current output procedure from the stack.
81*)
82
83PROCEDURE PopOutput ;
84BEGIN
85 IF Ptr>1
86 THEN
87 DEC(Ptr)
88 END
89END PopOutput ;
90
91
92(*
93 Halt - writes a message in the format:
94 Module:Line:Message
95
96 It then terminates by calling HALT.
97*)
98
99PROCEDURE Halt (File : ARRAY OF CHAR;
100 LineNo : CARDINAL;
101 Function,
102 Message : ARRAY OF CHAR) ;
103CONST
104 MaxNoOfDigits = 12 ; (* should be large enough for most source files.. *)
105VAR
106 No : ARRAY [0..MaxNoOfDigits] OF CHAR ;
107BEGIN
108 DebugString(File) ;
109 CardToStr(LineNo, 0, No) ;
110 DebugString(':') ;
111 DebugString(No) ;
112 DebugString(':') ;
113 DebugString(Function) ;
114 DebugString(':') ;
115 DebugString(Message) ;
116 DebugString('\n') ;
117 HALT
118END Halt ;
119
120
121(*
122 DebugString - writes a string to the debugging device (Scn.Write).
123 It interprets \n as carriage return, linefeed.
124*)
125
126PROCEDURE DebugString (a: ARRAY OF CHAR) ;
127VAR
128 n, high: CARDINAL ;
129BEGIN
130 high := HIGH( a ) ;
131 n := 0 ;
132 WHILE (n <= high) AND (a[n] # nul) DO
133 IF a[n]='\'
134 THEN
135 IF n+1<=high
136 THEN
137 IF a[n+1]='n'
138 THEN
139 WriteLn ;
140 INC(n)
141 ELSIF a[n+1]='\'
142 THEN
143 Write('\') ;
144 INC(n)
145 END
146 END
147 ELSE
148 Write( a[n] )
149 END ;
150 INC( n )
151 END
152END DebugString ;
153
154
155(*
156 WriteLn - writes a carriage return and a newline
157 character.
158*)
159
160PROCEDURE WriteLn ;
161BEGIN
162 Write(cr) ;
163 Write(lf)
164END WriteLn ;
165
166
167(*
168 Init - initialises this module.
169*)
170
171PROCEDURE Init ;
172BEGIN
173 Ptr := 0 ;
174 PushOutput(LocalWrite)
175END Init ;
176
177
178BEGIN
179 Init
180END Debug.
This page took 0.070372 seconds and 5 git commands to generate.