Fix double free in %depend
[nasm/avx512.git] / nasmlib.c
bloba4e7915e21f874dfcf28550580bcb99f5f1555ed
1 /* nasmlib.c library routines for the Netwide Assembler
3 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
4 * Julian Hall. All rights reserved. The software is
5 * redistributable under the license given in the file "LICENSE"
6 * distributed in the NASM archive.
7 */
9 #include "compiler.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <ctype.h>
15 #include <inttypes.h>
17 #include "nasm.h"
18 #include "nasmlib.h"
19 #include "insns.h"
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 */
24 #ifdef LOGALLOC
25 static FILE *logfp;
26 #endif
28 void nasm_set_malloc_error(efunc error)
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
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
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;
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
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;
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
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;
92 #ifdef LOGALLOC
93 void nasm_free_log(char *file, int line, void *q)
94 #else
95 void nasm_free(void *q)
96 #endif
98 if (q) {
99 #ifdef LOGALLOC
100 fprintf(logfp, "%s %d free(%p)\n", file, line, q);
101 #endif
102 free(q);
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
112 char *p;
113 int size = strlen(s) + 1;
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;
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
133 char *p;
134 int size = len + 1;
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;
149 #ifndef nasm_stricmp
150 int nasm_stricmp(const char *s1, const char *s2)
152 unsigned char c1, c2;
153 int d;
155 while (1) {
156 c1 = *s1++;
157 c2 = *s2++;
158 d = c1-c2;
160 if (d)
161 return d;
162 if (!c1)
163 break;
165 return 0;
167 #endif
169 #ifndef nasm_strnicmp
170 int nasm_strnicmp(const char *s1, const char *s2, size_t n)
172 unsigned char c1, c2;
173 int d;
175 while (n--) {
176 c1 = *s1++;
177 c2 = *s2++;
178 d = c1-c2;
180 if (d)
181 return d;
182 if (!c1)
183 break;
185 return 0;
187 #endif
189 int nasm_memicmp(const char *s1, const char *s2, size_t n)
191 unsigned char c1, c2;
192 int d;
194 while (n--) {
195 c1 = tolower(*s1++);
196 c2 = tolower(*s2++);
197 d = c1-c2;
198 if (d)
199 return d;
201 return 0;
204 #ifndef nasm_strsep
205 char *nasm_strsep(char **stringp, const char *delim)
207 char *s = *stringp;
208 char *e;
210 if (!s)
211 return NULL;
213 e = strpbrk(s, delim);
214 if (e)
215 *e++ = '\0';
217 *stringp = e;
218 return s;
220 #endif
223 #define lib_isnumchar(c) (isalnum(c) || (c) == '$' || (c) == '_')
224 #define numvalue(c) ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0')
226 static int radix_letter(char c)
228 switch (c) {
229 case 'b': case 'B':
230 case 'y': case 'Y':
231 return 2; /* Binary */
232 case 'o': case 'O':
233 case 'q': case 'Q':
234 return 8; /* Octal */
235 case 'h': case 'H':
236 case 'x': case 'X':
237 return 16; /* Hexadecimal */
238 case 'd': case 'D':
239 case 't': case 'T':
240 return 10; /* Decimal */
241 default:
242 return 0; /* Not a known radix letter */
246 int64_t readnum(char *str, bool *error)
248 char *r = str, *q;
249 int32_t pradix, sradix, radix;
250 int plen, slen, len;
251 uint64_t result, checklimit;
252 int digit, last;
253 bool warn = false;
254 int sign = 1;
256 *error = false;
258 while (isspace(*r))
259 r++; /* find start of number */
262 * If the number came from make_tok_num (as a result of an %assign), it
263 * might have a '-' built into it (rather than in a preceeding token).
265 if (*r == '-') {
266 r++;
267 sign = -1;
270 q = r;
272 while (lib_isnumchar(*q))
273 q++; /* find end of number */
275 len = q-r;
276 if (!len) {
277 /* Not numeric */
278 *error = true;
279 return 0;
283 * Handle radix formats:
285 * 0<radix-letter><string>
286 * $<string> (hexadecimal)
287 * <string><radix-letter>
289 pradix = sradix = 0;
290 plen = slen = 0;
292 if (len > 2 && *r == '0' && (pradix = radix_letter(r[1])) != 0)
293 plen = 2;
294 else if (len > 1 && *r == '$')
295 pradix = 16, plen = 1;
297 if (len > 1 && (sradix = radix_letter(q[-1])) != 0)
298 slen = 1;
300 if (pradix > sradix) {
301 radix = pradix;
302 r += plen;
303 } else if (sradix > pradix) {
304 radix = sradix;
305 q -= slen;
306 } else {
307 /* Either decimal, or invalid -- if invalid, we'll trip up
308 further down. */
309 radix = 10;
313 * `checklimit' must be 2**64 / radix. We can't do that in
314 * 64-bit arithmetic, which we're (probably) using, so we
315 * cheat: since we know that all radices we use are even, we
316 * can divide 2**63 by radix/2 instead.
318 checklimit = 0x8000000000000000ULL / (radix >> 1);
321 * Calculate the highest allowable value for the last digit of a
322 * 64-bit constant... in radix 10, it is 6, otherwise it is 0
324 last = (radix == 10 ? 6 : 0);
326 result = 0;
327 while (*r && r < q) {
328 if (*r != '_') {
329 if (*r < '0' || (*r > '9' && *r < 'A')
330 || (digit = numvalue(*r)) >= radix) {
331 *error = true;
332 return 0;
334 if (result > checklimit ||
335 (result == checklimit && digit >= last)) {
336 warn = true;
339 result = radix * result + digit;
341 r++;
344 if (warn)
345 nasm_malloc_error(ERR_WARNING | ERR_PASS1 | ERR_WARN_NOV,
346 "numeric constant %s does not fit in 64 bits",
347 str);
349 return result * sign;
352 int64_t readstrnum(char *str, int length, bool *warn)
354 int64_t charconst = 0;
355 int i;
357 *warn = false;
359 str += length;
360 if (globalbits == 64) {
361 for (i = 0; i < length; i++) {
362 if (charconst & 0xFF00000000000000ULL)
363 *warn = true;
364 charconst = (charconst << 8) + (uint8_t)*--str;
366 } else {
367 for (i = 0; i < length; i++) {
368 if (charconst & 0xFF000000UL)
369 *warn = true;
370 charconst = (charconst << 8) + (uint8_t)*--str;
373 return charconst;
376 static int32_t next_seg;
378 void seg_init(void)
380 next_seg = 0;
383 int32_t seg_alloc(void)
385 return (next_seg += 2) - 2;
388 #if X86_MEMORY
390 void fwriteint16_t(uint16_t data, FILE * fp)
392 fwrite(&data, 1, 2, fp);
395 void fwriteint32_t(uint32_t data, FILE * fp)
397 fwrite(&data, 1, 4, fp);
400 void fwriteint64_t(uint64_t data, FILE * fp)
402 fwrite(&data, 1, 8, fp);
405 void fwriteaddr(uint64_t data, int size, FILE * fp)
407 fwrite(&data, 1, size, fp);
410 #else /* !X86_MEMORY */
412 void fwriteint16_t(uint16_t data, FILE * fp)
414 char buffer[2], *p = buffer;
415 WRITESHORT(p, data);
416 fwrite(buffer, 1, 2, fp);
419 void fwriteint32_t(uint32_t data, FILE * fp)
421 char buffer[4], *p = buffer;
422 WRITELONG(p, data);
423 fwrite(buffer, 1, 4, fp);
426 void fwriteint64_t(uint64_t data, FILE * fp)
428 char buffer[8], *p = buffer;
429 WRITEDLONG(p, data);
430 fwrite(buffer, 1, 8, fp);
433 void fwriteaddr(uint64_t data, int size, FILE * fp)
435 char buffer[8], *p = buffer;
436 WRITEADDR(p, data, size);
437 fwrite(buffer, 1, size, fp);
440 #endif
442 void standard_extension(char *inname, char *outname, char *extension,
443 efunc error)
445 char *p, *q;
447 if (*outname) /* file name already exists, */
448 return; /* so do nothing */
449 q = inname;
450 p = outname;
451 while (*q)
452 *p++ = *q++; /* copy, and find end of string */
453 *p = '\0'; /* terminate it */
454 while (p > outname && *--p != '.') ; /* find final period (or whatever) */
455 if (*p != '.')
456 while (*p)
457 p++; /* go back to end if none found */
458 if (!strcmp(p, extension)) { /* is the extension already there? */
459 if (*extension)
460 error(ERR_WARNING | ERR_NOFILE,
461 "file name already ends in `%s': "
462 "output will be in `nasm.out'", extension);
463 else
464 error(ERR_WARNING | ERR_NOFILE,
465 "file name already has no extension: "
466 "output will be in `nasm.out'");
467 strcpy(outname, "nasm.out");
468 } else
469 strcpy(p, extension);
472 #define LEAFSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_LEAF))
473 #define BRANCHSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_BRANCH))
475 #define LAYERSHIFT(r) ( (r)->layers==0 ? RAA_BLKSHIFT : RAA_LAYERSHIFT )
477 static struct RAA *real_raa_init(int layers)
479 struct RAA *r;
480 int i;
482 if (layers == 0) {
483 r = nasm_zalloc(LEAFSIZ);
484 r->shift = 0;
485 } else {
486 r = nasm_malloc(BRANCHSIZ);
487 r->layers = layers;
488 for (i = 0; i < RAA_LAYERSIZE; i++)
489 r->u.b.data[i] = NULL;
490 r->shift = (RAA_BLKSHIFT-RAA_LAYERSHIFT) + layers*RAA_LAYERSHIFT;
492 return r;
495 struct RAA *raa_init(void)
497 return real_raa_init(0);
500 void raa_free(struct RAA *r)
502 if (r->layers) {
503 struct RAA **p;
504 for (p = r->u.b.data; p - r->u.b.data < RAA_LAYERSIZE; p++)
505 if (*p)
506 raa_free(*p);
508 nasm_free(r);
511 int64_t raa_read(struct RAA *r, int32_t posn)
513 if ((uint32_t)posn >= (UINT32_C(1) << (r->shift + LAYERSHIFT(r))))
514 return 0; /* Return 0 for undefined entries */
515 while (r->layers > 0) {
516 int32_t l = posn >> r->shift;
517 posn &= (UINT32_C(1) << r->shift)-1;
518 r = r->u.b.data[l];
519 if (!r)
520 return 0; /* Return 0 for undefined entries */
522 return r->u.l.data[posn];
525 struct RAA *raa_write(struct RAA *r, int32_t posn, int64_t value)
527 struct RAA *result;
529 if (posn < 0)
530 nasm_malloc_error(ERR_PANIC, "negative position in raa_write");
532 while ((UINT32_C(1) << (r->shift+LAYERSHIFT(r))) <= (uint32_t)posn) {
534 * Must add a layer.
536 struct RAA *s;
537 int i;
539 s = nasm_malloc(BRANCHSIZ);
540 for (i = 0; i < RAA_LAYERSIZE; i++)
541 s->u.b.data[i] = NULL;
542 s->layers = r->layers + 1;
543 s->shift = LAYERSHIFT(r) + r->shift;
544 s->u.b.data[0] = r;
545 r = s;
548 result = r;
550 while (r->layers > 0) {
551 struct RAA **s;
552 int32_t l = posn >> r->shift;
553 posn &= (UINT32_C(1) << r->shift)-1;
554 s = &r->u.b.data[l];
555 if (!*s)
556 *s = real_raa_init(r->layers - 1);
557 r = *s;
560 r->u.l.data[posn] = value;
562 return result;
565 /* Aggregate SAA components smaller than this */
566 #define SAA_BLKLEN 65536
568 struct SAA *saa_init(size_t elem_len)
570 struct SAA *s;
571 char *data;
573 s = nasm_zalloc(sizeof(struct SAA));
575 if (elem_len >= SAA_BLKLEN)
576 s->blk_len = elem_len;
577 else
578 s->blk_len = SAA_BLKLEN - (SAA_BLKLEN % elem_len);
580 s->elem_len = elem_len;
581 s->length = s->blk_len;
582 data = nasm_malloc(s->blk_len);
583 s->nblkptrs = s->nblks = 1;
584 s->blk_ptrs = nasm_malloc(sizeof(char *));
585 s->blk_ptrs[0] = data;
586 s->wblk = s->rblk = &s->blk_ptrs[0];
588 return s;
591 void saa_free(struct SAA *s)
593 char **p;
594 size_t n;
596 for (p = s->blk_ptrs, n = s->nblks; n; p++, n--)
597 nasm_free(*p);
599 nasm_free(s->blk_ptrs);
600 nasm_free(s);
603 /* Add one allocation block to an SAA */
604 static void saa_extend(struct SAA *s)
606 size_t blkn = s->nblks++;
608 if (blkn >= s->nblkptrs) {
609 size_t rindex = s->rblk - s->blk_ptrs;
610 size_t windex = s->wblk - s->blk_ptrs;
612 s->nblkptrs <<= 1;
613 s->blk_ptrs = nasm_realloc(s->blk_ptrs, s->nblkptrs*sizeof(char *));
615 s->rblk = s->blk_ptrs + rindex;
616 s->wblk = s->blk_ptrs + windex;
619 s->blk_ptrs[blkn] = nasm_malloc(s->blk_len);
620 s->length += s->blk_len;
623 void *saa_wstruct(struct SAA *s)
625 void *p;
627 if (s->wpos % s->elem_len)
628 nasm_malloc_error(ERR_PANIC|ERR_NOFILE,
629 "misaligned wpos in saa_wstruct");
631 if (s->wpos + s->elem_len > s->blk_len) {
632 if (s->wpos != s->blk_len)
633 nasm_malloc_error(ERR_PANIC|ERR_NOFILE,
634 "unfilled block in saa_wstruct");
636 if (s->wptr + s->elem_len > s->length)
637 saa_extend(s);
638 s->wblk++;
639 s->wpos = 0;
642 p = *s->wblk + s->wpos;
643 s->wpos += s->elem_len;
644 s->wptr += s->elem_len;
646 if (s->wptr > s->datalen)
647 s->datalen = s->wptr;
649 return p;
652 void saa_wbytes(struct SAA *s, const void *data, size_t len)
654 const char *d = data;
656 while (len) {
657 size_t l = s->blk_len - s->wpos;
658 if (l > len)
659 l = len;
660 if (l) {
661 if (d) {
662 memcpy(*s->wblk + s->wpos, d, l);
663 d += l;
664 } else
665 memset(*s->wblk + s->wpos, 0, l);
666 s->wpos += l;
667 s->wptr += l;
668 len -= l;
670 if (s->datalen < s->wptr)
671 s->datalen = s->wptr;
673 if (len) {
674 if (s->wptr >= s->length)
675 saa_extend(s);
676 s->wblk++;
677 s->wpos = 0;
682 /* write unsigned LEB128 value to SAA */
683 void saa_wleb128u(struct SAA *psaa, int value)
685 char temp[64], *ptemp;
686 uint8_t byte;
687 int len;
689 ptemp = temp;
690 len = 0;
693 byte = value & 127;
694 value >>= 7;
695 if (value != 0) /* more bytes to come */
696 byte |= 0x80;
697 *ptemp = byte;
698 ptemp++;
699 len++;
700 } while (value != 0);
701 saa_wbytes(psaa, temp, len);
704 /* write signed LEB128 value to SAA */
705 void saa_wleb128s(struct SAA *psaa, int value)
707 char temp[64], *ptemp;
708 uint8_t byte;
709 bool more, negative;
710 int size, len;
712 ptemp = temp;
713 more = 1;
714 negative = (value < 0);
715 size = sizeof(int) * 8;
716 len = 0;
717 while(more)
719 byte = value & 0x7f;
720 value >>= 7;
721 if (negative)
722 /* sign extend */
723 value |= - (1 <<(size - 7));
724 /* sign bit of byte is second high order bit (0x40) */
725 if ((value == 0 && ! (byte & 0x40)) ||
726 ((value == -1) && (byte & 0x40)))
727 more = 0;
728 else
729 byte |= 0x80;
730 *ptemp = byte;
731 ptemp++;
732 len++;
734 saa_wbytes(psaa, temp, len);
737 void saa_rewind(struct SAA *s)
739 s->rblk = s->blk_ptrs;
740 s->rpos = s->rptr = 0;
743 void *saa_rstruct(struct SAA *s)
745 void *p;
747 if (s->rptr + s->elem_len > s->datalen)
748 return NULL;
750 if (s->rpos % s->elem_len)
751 nasm_malloc_error(ERR_PANIC|ERR_NOFILE,
752 "misaligned rpos in saa_rstruct");
754 if (s->rpos + s->elem_len > s->blk_len) {
755 s->rblk++;
756 s->rpos = 0;
759 p = *s->rblk + s->rpos;
760 s->rpos += s->elem_len;
761 s->rptr += s->elem_len;
763 return p;
766 const void *saa_rbytes(struct SAA *s, size_t *lenp)
768 const void *p;
769 size_t len;
771 if (s->rptr >= s->datalen) {
772 *lenp = 0;
773 return NULL;
776 if (s->rpos >= s->blk_len) {
777 s->rblk++;
778 s->rpos = 0;
781 len = *lenp;
782 if (len > s->datalen - s->rptr)
783 len = s->datalen - s->rptr;
784 if (len > s->blk_len - s->rpos)
785 len = s->blk_len - s->rpos;
787 *lenp = len;
788 p = *s->rblk + s->rpos;
790 s->rpos += len;
791 s->rptr += len;
793 return p;
796 void saa_rnbytes(struct SAA *s, void *data, size_t len)
798 char *d = data;
800 if (s->rptr + len > s->datalen) {
801 nasm_malloc_error(ERR_PANIC|ERR_NOFILE, "overrun in saa_rnbytes");
802 return;
805 while (len) {
806 size_t l;
807 const void *p;
809 l = len;
810 p = saa_rbytes(s, &l);
812 memcpy(d, p, l);
813 d += l;
814 len -= l;
818 /* Same as saa_rnbytes, except position the counter first */
819 void saa_fread(struct SAA *s, size_t posn, void *data, size_t len)
821 size_t ix;
823 if (posn+len > s->datalen) {
824 nasm_malloc_error(ERR_PANIC|ERR_NOFILE, "overrun in saa_fread");
825 return;
828 ix = posn / s->blk_len;
829 s->rptr = posn;
830 s->rpos = posn % s->blk_len;
831 s->rblk = &s->blk_ptrs[ix];
833 saa_rnbytes(s, data, len);
836 /* Same as saa_wbytes, except position the counter first */
837 void saa_fwrite(struct SAA *s, size_t posn, const void *data, size_t len)
839 size_t ix;
841 if (posn > s->datalen) {
842 /* Seek beyond the end of the existing array not supported */
843 nasm_malloc_error(ERR_PANIC|ERR_NOFILE, "overrun in saa_fwrite");
844 return;
847 ix = posn / s->blk_len;
848 s->wptr = posn;
849 s->wpos = posn % s->blk_len;
850 s->wblk = &s->blk_ptrs[ix];
852 if (!s->wpos) {
853 s->wpos = s->blk_len;
854 s->wblk--;
857 saa_wbytes(s, data, len);
860 void saa_fpwrite(struct SAA *s, FILE * fp)
862 const char *data;
863 size_t len;
865 saa_rewind(s);
866 while (len = s->datalen, (data = saa_rbytes(s, &len)) != NULL)
867 fwrite(data, 1, len, fp);
871 * Common list of prefix names
873 static const char *prefix_names[] = {
874 "a16", "a32", "lock", "o16", "o32", "rep", "repe", "repne",
875 "repnz", "repz", "times"
878 const char *prefix_name(int token)
880 unsigned int prefix = token-PREFIX_ENUM_START;
881 if (prefix > elements(prefix_names))
882 return NULL;
884 return prefix_names[prefix];
888 * Binary search.
890 int bsi(const char *string, const char **array, int size)
892 int i = -1, j = size; /* always, i < index < j */
893 while (j - i >= 2) {
894 int k = (i + j) / 2;
895 int l = strcmp(string, array[k]);
896 if (l < 0) /* it's in the first half */
897 j = k;
898 else if (l > 0) /* it's in the second half */
899 i = k;
900 else /* we've got it :) */
901 return k;
903 return -1; /* we haven't got it :( */
906 int bsii(const char *string, const char **array, int size)
908 int i = -1, j = size; /* always, i < index < j */
909 while (j - i >= 2) {
910 int k = (i + j) / 2;
911 int l = nasm_stricmp(string, array[k]);
912 if (l < 0) /* it's in the first half */
913 j = k;
914 else if (l > 0) /* it's in the second half */
915 i = k;
916 else /* we've got it :) */
917 return k;
919 return -1; /* we haven't got it :( */
922 static char *file_name = NULL;
923 static int32_t line_number = 0;
925 char *src_set_fname(char *newname)
927 char *oldname = file_name;
928 file_name = newname;
929 return oldname;
932 int32_t src_set_linnum(int32_t newline)
934 int32_t oldline = line_number;
935 line_number = newline;
936 return oldline;
939 int32_t src_get_linnum(void)
941 return line_number;
944 int src_get(int32_t *xline, char **xname)
946 if (!file_name || !*xname || strcmp(*xname, file_name)) {
947 nasm_free(*xname);
948 *xname = file_name ? nasm_strdup(file_name) : NULL;
949 *xline = line_number;
950 return -2;
952 if (*xline != line_number) {
953 int32_t tmp = line_number - *xline;
954 *xline = line_number;
955 return tmp;
957 return 0;
960 char *nasm_strcat(char *one, char *two)
962 char *rslt;
963 int l1 = strlen(one);
964 rslt = nasm_malloc(l1 + strlen(two) + 1);
965 strcpy(rslt, one);
966 strcpy(rslt + l1, two);
967 return rslt;
970 void null_debug_init(struct ofmt *of, void *id, FILE * fp, efunc error)
972 (void)of;
973 (void)id;
974 (void)fp;
975 (void)error;
977 void null_debug_linenum(const char *filename, int32_t linenumber, int32_t segto)
979 (void)filename;
980 (void)linenumber;
981 (void)segto;
983 void null_debug_deflabel(char *name, int32_t segment, int64_t offset,
984 int is_global, char *special)
986 (void)name;
987 (void)segment;
988 (void)offset;
989 (void)is_global;
990 (void)special;
992 void null_debug_routine(const char *directive, const char *params)
994 (void)directive;
995 (void)params;
997 void null_debug_typevalue(int32_t type)
999 (void)type;
1001 void null_debug_output(int type, void *param)
1003 (void)type;
1004 (void)param;
1006 void null_debug_cleanup(void)
1010 struct dfmt null_debug_form = {
1011 "Null debug format",
1012 "null",
1013 null_debug_init,
1014 null_debug_linenum,
1015 null_debug_deflabel,
1016 null_debug_routine,
1017 null_debug_typevalue,
1018 null_debug_output,
1019 null_debug_cleanup
1022 struct dfmt *null_debug_arr[2] = { &null_debug_form, NULL };