Portability fixes
[platform/upstream/nasm.git] / nasmlib.c
1 /* nasmlib.c    library routines for the Netwide Assembler
2  *
3  * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
4  * Julian Hall. All rights reserved. The software is
5  * redistributable under the licence given in the file "Licence"
6  * distributed in the NASM archive.
7  */
8
9 #include "compiler.h"
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <ctype.h>
15 #include <inttypes.h>
16
17 #include "nasm.h"
18 #include "nasmlib.h"
19 #include "insns.h"
20
21 int globalbits = 0;    /* defined in nasm.h, works better here for ASM+DISASM */
22 efunc nasm_malloc_error;        /* Exported for the benefit of vsnprintf.c */
23
24 #ifdef LOGALLOC
25 static FILE *logfp;
26 #endif
27
28 void nasm_set_malloc_error(efunc error)
29 {
30     nasm_malloc_error = error;
31 #ifdef LOGALLOC
32     logfp = fopen("malloc.log", "w");
33     setvbuf(logfp, NULL, _IOLBF, BUFSIZ);
34     fprintf(logfp, "null pointer is %p\n", NULL);
35 #endif
36 }
37
38 #ifdef LOGALLOC
39 void *nasm_malloc_log(char *file, int line, size_t size)
40 #else
41 void *nasm_malloc(size_t size)
42 #endif
43 {
44     void *p = malloc(size);
45     if (!p)
46         nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
47 #ifdef LOGALLOC
48     else
49         fprintf(logfp, "%s %d malloc(%ld) returns %p\n",
50                 file, line, (long)size, p);
51 #endif
52     return p;
53 }
54
55 #ifdef LOGALLOC
56 void *nasm_zalloc_log(char *file, int line, size_t size)
57 #else
58 void *nasm_zalloc(size_t size)
59 #endif
60 {
61     void *p = calloc(size, 1);
62     if (!p)
63         nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
64 #ifdef LOGALLOC
65     else
66         fprintf(logfp, "%s %d calloc(%ld, 1) returns %p\n",
67                 file, line, (long)size, p);
68 #endif
69     return p;
70 }
71
72 #ifdef LOGALLOC
73 void *nasm_realloc_log(char *file, int line, void *q, size_t size)
74 #else
75 void *nasm_realloc(void *q, size_t size)
76 #endif
77 {
78     void *p = q ? realloc(q, size) : malloc(size);
79     if (!p)
80         nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
81 #ifdef LOGALLOC
82     else if (q)
83         fprintf(logfp, "%s %d realloc(%p,%ld) returns %p\n",
84                 file, line, q, (long)size, p);
85     else
86         fprintf(logfp, "%s %d malloc(%ld) returns %p\n",
87                 file, line, (long)size, p);
88 #endif
89     return p;
90 }
91
92 #ifdef LOGALLOC
93 void nasm_free_log(char *file, int line, void *q)
94 #else
95 void nasm_free(void *q)
96 #endif
97 {
98     if (q) {
99         free(q);
100 #ifdef LOGALLOC
101         fprintf(logfp, "%s %d free(%p)\n", file, line, q);
102 #endif
103     }
104 }
105
106 #ifdef LOGALLOC
107 char *nasm_strdup_log(char *file, int line, const char *s)
108 #else
109 char *nasm_strdup(const char *s)
110 #endif
111 {
112     char *p;
113     int size = strlen(s) + 1;
114
115     p = malloc(size);
116     if (!p)
117         nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
118 #ifdef LOGALLOC
119     else
120         fprintf(logfp, "%s %d strdup(%ld) returns %p\n",
121                 file, line, (long)size, p);
122 #endif
123     strcpy(p, s);
124     return p;
125 }
126
127 #ifdef LOGALLOC
128 char *nasm_strndup_log(char *file, int line, char *s, size_t len)
129 #else
130 char *nasm_strndup(char *s, size_t len)
131 #endif
132 {
133     char *p;
134     int size = len + 1;
135
136     p = malloc(size);
137     if (!p)
138         nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
139 #ifdef LOGALLOC
140     else
141         fprintf(logfp, "%s %d strndup(%ld) returns %p\n",
142                 file, line, (long)size, p);
143 #endif
144     strncpy(p, s, len);
145     p[len] = '\0';
146     return p;
147 }
148
149 #ifndef nasm_stricmp
150 int nasm_stricmp(const char *s1, const char *s2)
151 {
152     while (*s1 && tolower(*s1) == tolower(*s2))
153         s1++, s2++;
154     if (!*s1 && !*s2)
155         return 0;
156     else if (tolower(*s1) < tolower(*s2))
157         return -1;
158     else
159         return 1;
160 }
161 #endif
162
163 #ifndef nasm_strnicmp
164 int nasm_strnicmp(const char *s1, const char *s2, int n)
165 {
166     while (n > 0 && *s1 && tolower(*s1) == tolower(*s2))
167         s1++, s2++, n--;
168     if ((!*s1 && !*s2) || n == 0)
169         return 0;
170     else if (tolower(*s1) < tolower(*s2))
171         return -1;
172     else
173         return 1;
174 }
175 #endif
176
177 #ifndef nasm_strsep
178 char *nasm_strsep(char **stringp, const char *delim)
179 {
180         char *s = *stringp;
181         char *e;
182
183         if (!s)
184                 return NULL;
185
186         e = strpbrk(s, delim);
187         if (e)
188                 *e++ = '\0';
189
190         *stringp = e;
191         return s;
192 }
193 #endif
194
195
196 #define lib_isnumchar(c)   ( isalnum(c) || (c) == '$')
197 #define numvalue(c)  ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0')
198
199 int64_t readnum(char *str, int *error)
200 {
201     char *r = str, *q;
202     int32_t radix;
203     uint64_t result, checklimit;
204     int digit, last;
205     int warn = FALSE;
206     int sign = 1;
207
208     *error = FALSE;
209
210     while (isspace(*r))
211         r++;                    /* find start of number */
212
213     /*
214      * If the number came from make_tok_num (as a result of an %assign), it
215      * might have a '-' built into it (rather than in a preceeding token).
216      */
217     if (*r == '-') {
218         r++;
219         sign = -1;
220     }
221
222     q = r;
223
224     while (lib_isnumchar(*q))
225         q++;                    /* find end of number */
226
227     /*
228      * If it begins 0x, 0X or $, or ends in H, it's in hex. if it
229      * ends in Q, it's octal. if it ends in B, it's binary.
230      * Otherwise, it's ordinary decimal.
231      */
232     if (*r == '0' && (r[1] == 'x' || r[1] == 'X'))
233         radix = 16, r += 2;
234     else if (*r == '$')
235         radix = 16, r++;
236     else if (q[-1] == 'H' || q[-1] == 'h')
237         radix = 16, q--;
238     else if (q[-1] == 'Q' || q[-1] == 'q' || q[-1] == 'O' || q[-1] == 'o')
239         radix = 8, q--;
240     else if (q[-1] == 'B' || q[-1] == 'b')
241         radix = 2, q--;
242     else
243         radix = 10;
244
245     /*
246      * If this number has been found for us by something other than
247      * the ordinary scanners, then it might be malformed by having
248      * nothing between the prefix and the suffix. Check this case
249      * now.
250      */
251     if (r >= q) {
252         *error = TRUE;
253         return 0;
254     }
255     
256     /*
257      * `checklimit' must be 2**(32|64) / radix. We can't do that in
258      * 32/64-bit arithmetic, which we're (probably) using, so we
259      * cheat: since we know that all radices we use are even, we
260      * can divide 2**(31|63) by radix/2 instead.
261      */
262     if (globalbits == 64)
263         checklimit = 0x8000000000000000ULL / (radix >> 1);
264     else
265         checklimit = 0x80000000UL / (radix >> 1);
266
267     /*
268      * Calculate the highest allowable value for the last digit of a
269      * 32-bit constant... in radix 10, it is 6, otherwise it is 0
270      */
271     last = (radix == 10 ? 6 : 0);
272
273     result = 0;
274     while (*r && r < q) {
275         if (*r < '0' || (*r > '9' && *r < 'A')
276             || (digit = numvalue(*r)) >= radix) {
277             *error = TRUE;
278             return 0;
279         }
280         if (result > checklimit || (result == checklimit && digit >= last)) {
281             warn = TRUE;
282         }
283
284         result = radix * result + digit;
285         r++;
286     }
287
288     if (warn)
289         nasm_malloc_error(ERR_WARNING | ERR_PASS1 | ERR_WARN_NOV,
290                           "numeric constant %s does not fit in 32 bits",
291                           str);
292
293     return result * sign;
294 }
295
296 int64_t readstrnum(char *str, int length, int *warn)
297 {
298     int64_t charconst = 0;
299     int i;
300
301     *warn = FALSE;
302
303     str += length;
304     if (globalbits == 64) {
305         for (i = 0; i < length; i++) {
306             if (charconst & 0xFF00000000000000ULL)
307                 *warn = TRUE;
308             charconst = (charconst << 8) + (uint8_t)*--str;
309         }
310     } else {
311         for (i = 0; i < length; i++) {
312             if (charconst & 0xFF000000UL)
313                 *warn = TRUE;
314             charconst = (charconst << 8) + (uint8_t)*--str;
315         }
316     }
317     return charconst;
318 }
319
320 static int32_t next_seg;
321
322 void seg_init(void)
323 {
324     next_seg = 0;
325 }
326
327 int32_t seg_alloc(void)
328 {
329     return (next_seg += 2) - 2;
330 }
331
332 void fwriteint16_t(int data, FILE * fp)
333 {
334     fputc((int)(data & 255), fp);
335     fputc((int)((data >> 8) & 255), fp);
336 }
337
338 void fwriteint32_t(int32_t data, FILE * fp)
339 {
340     fputc((int)(data & 255), fp);
341     fputc((int)((data >> 8) & 255), fp);
342     fputc((int)((data >> 16) & 255), fp);
343     fputc((int)((data >> 24) & 255), fp);
344 }
345
346 void fwriteint64_t(int64_t data, FILE * fp)
347 {
348     fputc((int)(data & 255), fp);
349     fputc((int)((data >> 8) & 255), fp);
350     fputc((int)((data >> 16) & 255), fp);
351     fputc((int)((data >> 24) & 255), fp);
352     fputc((int)((data >> 32) & 255), fp);
353     fputc((int)((data >> 40) & 255), fp);
354     fputc((int)((data >> 48) & 255), fp);
355     fputc((int)((data >> 56) & 255), fp);
356 }
357
358 void standard_extension(char *inname, char *outname, char *extension,
359                         efunc error)
360 {
361     char *p, *q;
362
363     if (*outname)               /* file name already exists, */
364         return;                 /* so do nothing */
365     q = inname;
366     p = outname;
367     while (*q)
368         *p++ = *q++;            /* copy, and find end of string */
369     *p = '\0';                  /* terminate it */
370     while (p > outname && *--p != '.') ;        /* find final period (or whatever) */
371     if (*p != '.')
372         while (*p)
373             p++;                /* go back to end if none found */
374     if (!strcmp(p, extension)) {        /* is the extension already there? */
375         if (*extension)
376             error(ERR_WARNING | ERR_NOFILE,
377                   "file name already ends in `%s': "
378                   "output will be in `nasm.out'", extension);
379         else
380             error(ERR_WARNING | ERR_NOFILE,
381                   "file name already has no extension: "
382                   "output will be in `nasm.out'");
383         strcpy(outname, "nasm.out");
384     } else
385         strcpy(p, extension);
386 }
387
388 #define LEAFSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_LEAF))
389 #define BRANCHSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_BRANCH))
390
391 #define LAYERSIZ(r) ( (r)->layers==0 ? RAA_BLKSIZE : RAA_LAYERSIZE )
392
393 static struct RAA *real_raa_init(int layers)
394 {
395     struct RAA *r;
396     int i;
397
398     if (layers == 0) {
399         r = nasm_zalloc(LEAFSIZ);
400         r->stepsize = 1L;
401     } else {
402         r = nasm_malloc(BRANCHSIZ);
403         r->layers = layers;
404         for (i = 0; i < RAA_LAYERSIZE; i++)
405             r->u.b.data[i] = NULL;
406         r->stepsize = RAA_BLKSIZE;
407         while (--layers)
408             r->stepsize *= RAA_LAYERSIZE;
409     }
410     return r;
411 }
412
413 struct RAA *raa_init(void)
414 {
415     return real_raa_init(0);
416 }
417
418 void raa_free(struct RAA *r)
419 {
420     if (r->layers == 0)
421         nasm_free(r);
422     else {
423         struct RAA **p;
424         for (p = r->u.b.data; p - r->u.b.data < RAA_LAYERSIZE; p++)
425             if (*p)
426                 raa_free(*p);
427     }
428 }
429
430 int32_t raa_read(struct RAA *r, int32_t posn)
431 {
432     if (posn >= r->stepsize * LAYERSIZ(r))
433         return 0;               /* Return 0 for undefined entries */
434     while (r->layers > 0) {
435         ldiv_t l;
436         l = ldiv(posn, r->stepsize);
437         r = r->u.b.data[l.quot];
438         posn = l.rem;
439         if (!r)
440             return 0;           /* Return 0 for undefined entries */
441     }
442     return r->u.l.data[posn];
443 }
444
445 struct RAA *raa_write(struct RAA *r, int32_t posn, int32_t value)
446 {
447     struct RAA *result;
448
449     if (posn < 0)
450         nasm_malloc_error(ERR_PANIC, "negative position in raa_write");
451
452     while (r->stepsize * LAYERSIZ(r) <= posn) {
453         /*
454          * Must add a layer.
455          */
456         struct RAA *s;
457         int i;
458
459         s = nasm_malloc(BRANCHSIZ);
460         for (i = 0; i < RAA_LAYERSIZE; i++)
461             s->u.b.data[i] = NULL;
462         s->layers = r->layers + 1;
463         s->stepsize = LAYERSIZ(r) * r->stepsize;
464         s->u.b.data[0] = r;
465         r = s;
466     }
467
468     result = r;
469
470     while (r->layers > 0) {
471         ldiv_t l;
472         struct RAA **s;
473         l = ldiv(posn, r->stepsize);
474         s = &r->u.b.data[l.quot];
475         if (!*s)
476             *s = real_raa_init(r->layers - 1);
477         r = *s;
478         posn = l.rem;
479     }
480
481     r->u.l.data[posn] = value;
482
483     return result;
484 }
485
486 #define SAA_MAXLEN 8192
487
488 struct SAA *saa_init(int32_t elem_len)
489 {
490     struct SAA *s;
491
492     if (elem_len > SAA_MAXLEN)
493         nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
494                           "SAA with huge elements");
495
496     s = nasm_malloc(sizeof(struct SAA));
497     s->posn = s->start = 0L;
498     s->elem_len = elem_len;
499     s->length = SAA_MAXLEN - (SAA_MAXLEN % elem_len);
500     s->data = nasm_malloc(s->length);
501     s->next = NULL;
502     s->end = s;
503
504     return s;
505 }
506
507 void saa_free(struct SAA *s)
508 {
509     struct SAA *t;
510
511     while (s) {
512         t = s->next;
513         nasm_free(s->data);
514         nasm_free(s);
515         s = t;
516     }
517 }
518
519 void *saa_wstruct(struct SAA *s)
520 {
521     void *p;
522
523     if (s->end->length - s->end->posn < s->elem_len) {
524         s->end->next = nasm_malloc(sizeof(struct SAA));
525         s->end->next->start = s->end->start + s->end->posn;
526         s->end = s->end->next;
527         s->end->length = s->length;
528         s->end->next = NULL;
529         s->end->posn = 0L;
530         s->end->data = nasm_malloc(s->length);
531     }
532
533     p = s->end->data + s->end->posn;
534     s->end->posn += s->elem_len;
535     return p;
536 }
537
538 void saa_wbytes(struct SAA *s, const void *data, int32_t len)
539 {
540     const char *d = data;
541
542     while (len > 0) {
543         int32_t l = s->end->length - s->end->posn;
544         if (l > len)
545             l = len;
546         if (l > 0) {
547             if (d) {
548                 memcpy(s->end->data + s->end->posn, d, l);
549                 d += l;
550             } else
551                 memset(s->end->data + s->end->posn, 0, l);
552             s->end->posn += l;
553             len -= l;
554         }
555         if (len > 0) {
556             s->end->next = nasm_malloc(sizeof(struct SAA));
557             s->end->next->start = s->end->start + s->end->posn;
558             s->end = s->end->next;
559             s->end->length = s->length;
560             s->end->next = NULL;
561             s->end->posn = 0L;
562             s->end->data = nasm_malloc(s->length);
563         }
564     }
565 }
566
567 void saa_rewind(struct SAA *s)
568 {
569     s->rptr = s;
570     s->rpos = 0L;
571 }
572
573 void *saa_rstruct(struct SAA *s)
574 {
575     void *p;
576
577     if (!s->rptr)
578         return NULL;
579
580     if (s->rptr->posn - s->rpos < s->elem_len) {
581         s->rptr = s->rptr->next;
582         if (!s->rptr)
583             return NULL;        /* end of array */
584         s->rpos = 0L;
585     }
586
587     p = s->rptr->data + s->rpos;
588     s->rpos += s->elem_len;
589     return p;
590 }
591
592 void *saa_rbytes(struct SAA *s, int32_t *len)
593 {
594     void *p;
595
596     if (!s->rptr)
597         return NULL;
598
599     p = s->rptr->data + s->rpos;
600     *len = s->rptr->posn - s->rpos;
601     s->rptr = s->rptr->next;
602     s->rpos = 0L;
603     return p;
604 }
605
606 void saa_rnbytes(struct SAA *s, void *data, int32_t len)
607 {
608     char *d = data;
609
610     while (len > 0) {
611         int32_t l;
612
613         if (!s->rptr)
614             return;
615
616         l = s->rptr->posn - s->rpos;
617         if (l > len)
618             l = len;
619         if (l > 0) {
620             memcpy(d, s->rptr->data + s->rpos, l);
621             d += l;
622             s->rpos += l;
623             len -= l;
624         }
625         if (len > 0) {
626             s->rptr = s->rptr->next;
627             s->rpos = 0L;
628         }
629     }
630 }
631
632 void saa_fread(struct SAA *s, int32_t posn, void *data, int32_t len)
633 {
634     struct SAA *p;
635     int64_t pos;
636     char *cdata = data;
637
638     if (!s->rptr || posn < s->rptr->start)
639         saa_rewind(s);
640     p = s->rptr;
641     while (posn >= p->start + p->posn) {
642         p = p->next;
643         if (!p)
644             return;             /* what else can we do?! */
645     }
646
647     pos = posn - p->start;
648     while (len) {
649         int64_t l = p->posn - pos;
650         if (l > len)
651             l = len;
652         memcpy(cdata, p->data + pos, l);
653         len -= l;
654         cdata += l;
655         p = p->next;
656         if (!p)
657             return;
658         pos = 0LL;
659     }
660     s->rptr = p;
661 }
662
663 void saa_fwrite(struct SAA *s, int32_t posn, void *data, int32_t len)
664 {
665     struct SAA *p;
666     int64_t pos;
667     char *cdata = data;
668
669     if (!s->rptr || posn < s->rptr->start)
670         saa_rewind(s);
671     p = s->rptr;
672     while (posn >= p->start + p->posn) {
673         p = p->next;
674         if (!p)
675             return;             /* what else can we do?! */
676     }
677
678     pos = posn - p->start;
679     while (len) {
680         int64_t l = p->posn - pos;
681         if (l > len)
682             l = len;
683         memcpy(p->data + pos, cdata, l);
684         len -= l;
685         cdata += l;
686         p = p->next;
687         if (!p)
688             return;
689         pos = 0LL;
690     }
691     s->rptr = p;
692 }
693
694 void saa_fpwrite(struct SAA *s, FILE * fp)
695 {
696     char *data;
697     int32_t len;
698
699     saa_rewind(s);
700 //    while ((data = saa_rbytes(s, &len)))
701     for (; (data = saa_rbytes(s, &len));)
702         fwrite(data, 1, len, fp);
703 }
704
705 /*
706  * Common list of prefix names
707  */
708 static const char *prefix_names[] = {
709     "a16", "a32", "lock", "o16", "o32", "rep", "repe", "repne",
710     "repnz", "repz", "times"
711 };
712
713 const char *prefix_name(int token)
714 {
715     unsigned int prefix = token-PREFIX_ENUM_START;
716     if (prefix > sizeof prefix_names / sizeof(const char *))
717         return NULL;
718
719     return prefix_names[prefix];
720 }
721
722 /*
723  * Binary search.
724  */
725 int bsi(char *string, const char **array, int size)
726 {
727     int i = -1, j = size;       /* always, i < index < j */
728     while (j - i >= 2) {
729         int k = (i + j) / 2;
730         int l = strcmp(string, array[k]);
731         if (l < 0)              /* it's in the first half */
732             j = k;
733         else if (l > 0)         /* it's in the second half */
734             i = k;
735         else                    /* we've got it :) */
736             return k;
737     }
738     return -1;                  /* we haven't got it :( */
739 }
740
741 int bsii(char *string, const char **array, int size)
742 {
743     int i = -1, j = size;       /* always, i < index < j */
744     while (j - i >= 2) {
745         int k = (i + j) / 2;
746         int l = nasm_stricmp(string, array[k]);
747         if (l < 0)              /* it's in the first half */
748             j = k;
749         else if (l > 0)         /* it's in the second half */
750             i = k;
751         else                    /* we've got it :) */
752             return k;
753     }
754     return -1;                  /* we haven't got it :( */
755 }
756
757 static char *file_name = NULL;
758 static int32_t line_number = 0;
759
760 char *src_set_fname(char *newname)
761 {
762     char *oldname = file_name;
763     file_name = newname;
764     return oldname;
765 }
766
767 int32_t src_set_linnum(int32_t newline)
768 {
769     int32_t oldline = line_number;
770     line_number = newline;
771     return oldline;
772 }
773
774 int32_t src_get_linnum(void)
775 {
776     return line_number;
777 }
778
779 int src_get(int32_t *xline, char **xname)
780 {
781     if (!file_name || !*xname || strcmp(*xname, file_name)) {
782         nasm_free(*xname);
783         *xname = file_name ? nasm_strdup(file_name) : NULL;
784         *xline = line_number;
785         return -2;
786     }
787     if (*xline != line_number) {
788         int32_t tmp = line_number - *xline;
789         *xline = line_number;
790         return tmp;
791     }
792     return 0;
793 }
794
795 void nasm_quote(char **str)
796 {
797     int ln = strlen(*str);
798     char q = (*str)[0];
799     char *p;
800     if (ln > 1 && (*str)[ln - 1] == q && (q == '"' || q == '\''))
801         return;
802     q = '"';
803     if (strchr(*str, q))
804         q = '\'';
805     p = nasm_malloc(ln + 3);
806     strcpy(p + 1, *str);
807     nasm_free(*str);
808     p[ln + 1] = p[0] = q;
809     p[ln + 2] = 0;
810     *str = p;
811 }
812
813 char *nasm_strcat(char *one, char *two)
814 {
815     char *rslt;
816     int l1 = strlen(one);
817     rslt = nasm_malloc(l1 + strlen(two) + 1);
818     strcpy(rslt, one);
819     strcpy(rslt + l1, two);
820     return rslt;
821 }
822
823 void null_debug_init(struct ofmt *of, void *id, FILE * fp, efunc error)
824 {
825         (void)of;
826         (void)id;
827         (void)fp;
828         (void)error;
829 }
830 void null_debug_linenum(const char *filename, int32_t linenumber, int32_t segto)
831 {
832         (void)filename;
833         (void)linenumber;
834         (void)segto;    
835 }
836 void null_debug_deflabel(char *name, int32_t segment, int32_t offset,
837                          int is_global, char *special)
838 {
839         (void)name;
840         (void)segment;
841         (void)offset;
842         (void)is_global;
843         (void)special;
844 }
845 void null_debug_routine(const char *directive, const char *params)
846 {
847         (void)directive;
848         (void)params;
849 }
850 void null_debug_typevalue(int32_t type)
851 {
852         (void)type;
853 }
854 void null_debug_output(int type, void *param)
855 {
856         (void)type;
857         (void)param;
858 }
859 void null_debug_cleanup(void)
860 {
861 }
862
863 struct dfmt null_debug_form = {
864     "Null debug format",
865     "null",
866     null_debug_init,
867     null_debug_linenum,
868     null_debug_deflabel,
869     null_debug_routine,
870     null_debug_typevalue,
871     null_debug_output,
872     null_debug_cleanup
873 };
874
875 struct dfmt *null_debug_arr[2] = { &null_debug_form, NULL };