]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/m2/pge-boot/GDebug.c
Merge modula-2 front end onto gcc.
[thirdparty/gcc.git] / gcc / m2 / pge-boot / GDebug.c
1 /* do not edit automatically generated by mc from Debug. */
2 /* Debug.mod provides some simple debugging routines.
3
4 Copyright (C) 2001-2021 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6
7 This file is part of GNU Modula-2.
8
9 GNU Modula-2 is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
13
14 GNU Modula-2 is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 Under Section 7 of GPL version 3, you are granted additional
20 permissions described in the GCC Runtime Library Exception, version
21 3.1, as published by the Free Software Foundation.
22
23 You should have received a copy of the GNU General Public License and
24 a copy of the GCC Runtime Library Exception along with this program;
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
26 <http://www.gnu.org/licenses/>. */
27
28 # if !defined (PROC_D)
29 # define PROC_D
30 typedef void (*PROC_t) (void);
31 typedef struct { PROC_t proc; } PROC;
32 # endif
33
34 #include <string.h>
35 #include <limits.h>
36 #define _Debug_H
37 #define _Debug_C
38
39 # include "GASCII.h"
40 # include "GNumberIO.h"
41 # include "GStdIO.h"
42 # include "Glibc.h"
43 # include "GM2RTS.h"
44
45 # define MaxNoOfDigits 12
46
47 /*
48 Halt - writes a message in the format:
49 Module:Line:Message
50
51 It then terminates by calling HALT.
52 */
53
54 extern "C" void Debug_Halt (const char *Message_, unsigned int _Message_high, unsigned int LineNo, const char *Module_, unsigned int _Module_high);
55
56 /*
57 DebugString - writes a string to the debugging device (Scn.Write).
58 It interprets
59 as carriage return, linefeed.
60 */
61
62 extern "C" void Debug_DebugString (const char *a_, unsigned int _a_high);
63
64 /*
65 WriteLn - writes a carriage return and a newline
66 character.
67 */
68
69 static void WriteLn (void);
70
71
72 /*
73 WriteLn - writes a carriage return and a newline
74 character.
75 */
76
77 static void WriteLn (void)
78 {
79 StdIO_Write (ASCII_cr);
80 StdIO_Write (ASCII_lf);
81 }
82
83
84 /*
85 Halt - writes a message in the format:
86 Module:Line:Message
87
88 It then terminates by calling HALT.
89 */
90
91 extern "C" void Debug_Halt (const char *Message_, unsigned int _Message_high, unsigned int LineNo, const char *Module_, unsigned int _Module_high)
92 {
93 typedef struct Halt__T1_a Halt__T1;
94
95 struct Halt__T1_a { char array[MaxNoOfDigits+1]; };
96 Halt__T1 No;
97 char Message[_Message_high+1];
98 char Module[_Module_high+1];
99
100 /* make a local copy of each unbounded array. */
101 memcpy (Message, Message_, _Message_high+1);
102 memcpy (Module, Module_, _Module_high+1);
103
104 Debug_DebugString ((const char *) Module, _Module_high); /* should be large enough for most source files.. */
105 NumberIO_CardToStr (LineNo, 0, (char *) &No.array[0], MaxNoOfDigits);
106 Debug_DebugString ((const char *) ":", 1);
107 Debug_DebugString ((const char *) &No.array[0], MaxNoOfDigits);
108 Debug_DebugString ((const char *) ":", 1);
109 Debug_DebugString ((const char *) Message, _Message_high);
110 Debug_DebugString ((const char *) "\\n", 2);
111 M2RTS_HALT (-1);
112 __builtin_unreachable ();
113 }
114
115
116 /*
117 DebugString - writes a string to the debugging device (Scn.Write).
118 It interprets
119 as carriage return, linefeed.
120 */
121
122 extern "C" void Debug_DebugString (const char *a_, unsigned int _a_high)
123 {
124 unsigned int n;
125 unsigned int high;
126 char a[_a_high+1];
127
128 /* make a local copy of each unbounded array. */
129 memcpy (a, a_, _a_high+1);
130
131 high = _a_high;
132 n = 0;
133 while ((n <= high) && (a[n] != ASCII_nul))
134 {
135 if (a[n] == '\\')
136 {
137 /* avoid dangling else. */
138 if ((n+1) <= high)
139 {
140 /* avoid gcc warning by using compound statement even if not strictly necessary. */
141 if (a[n+1] == 'n')
142 {
143 WriteLn ();
144 n += 1;
145 }
146 else if (a[n+1] == '\\')
147 {
148 /* avoid dangling else. */
149 StdIO_Write ('\\');
150 n += 1;
151 }
152 }
153 }
154 else
155 {
156 StdIO_Write (a[n]);
157 }
158 n += 1;
159 }
160 }
161
162 extern "C" void _M2_Debug_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
163 {
164 }
165
166 extern "C" void _M2_Debug_finish (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
167 {
168 }