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 licence given in the file "Licence"
6 * distributed in the NASM archive.
17 #include "insns.h" /* For MAX_KEYWORD */
19 int globalbits = 0; /* defined in nasm.h, works better here for ASM+DISASM */
21 static efunc nasm_malloc_error;
27 void nasm_set_malloc_error(efunc error)
29 nasm_malloc_error = error;
31 logfp = fopen("malloc.log", "w");
32 setvbuf(logfp, NULL, _IOLBF, BUFSIZ);
33 fprintf(logfp, "null pointer is %p\n", NULL);
38 void *nasm_malloc_log(int8_t *file, int line, size_t size)
40 void *nasm_malloc(size_t size)
43 void *p = malloc(size);
45 nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
48 fprintf(logfp, "%s %d malloc(%ld) returns %p\n",
49 file, line, (int32_t)size, p);
55 void *nasm_realloc_log(int8_t *file, int line, void *q, size_t size)
57 void *nasm_realloc(void *q, size_t size)
60 void *p = q ? realloc(q, size) : malloc(size);
62 nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
65 fprintf(logfp, "%s %d realloc(%p,%ld) returns %p\n",
66 file, line, q, (int32_t)size, p);
68 fprintf(logfp, "%s %d malloc(%ld) returns %p\n",
69 file, line, (int32_t)size, p);
75 void nasm_free_log(int8_t *file, int line, void *q)
77 void nasm_free(void *q)
83 fprintf(logfp, "%s %d free(%p)\n", file, line, q);
89 int8_t *nasm_strdup_log(int8_t *file, int line, const int8_t *s)
91 int8_t *nasm_strdup(const int8_t *s)
95 int size = strlen(s) + 1;
99 nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
102 fprintf(logfp, "%s %d strdup(%ld) returns %p\n",
103 file, line, (int32_t)size, p);
110 int8_t *nasm_strndup_log(int8_t *file, int line, int8_t *s, size_t len)
112 int8_t *nasm_strndup(int8_t *s, size_t len)
120 nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
123 fprintf(logfp, "%s %d strndup(%ld) returns %p\n",
124 file, line, (int32_t)size, p);
131 #if !defined(stricmp) && !defined(strcasecmp)
132 int nasm_stricmp(const int8_t *s1, const int8_t *s2)
134 while (*s1 && tolower(*s1) == tolower(*s2))
138 else if (tolower(*s1) < tolower(*s2))
145 #if !defined(strnicmp) && !defined(strncasecmp)
146 int nasm_strnicmp(const int8_t *s1, const int8_t *s2, int n)
148 while (n > 0 && *s1 && tolower(*s1) == tolower(*s2))
150 if ((!*s1 && !*s2) || n == 0)
152 else if (tolower(*s1) < tolower(*s2))
159 #define lib_isnumchar(c) ( isalnum(c) || (c) == '$')
160 #define numvalue(c) ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0')
162 int64_t readnum(int8_t *str, int *error)
166 uint64_t result, checklimit;
174 r++; /* find start of number */
177 * If the number came from make_tok_num (as a result of an %assign), it
178 * might have a '-' built into it (rather than in a preceeding token).
187 while (lib_isnumchar(*q))
188 q++; /* find end of number */
191 * If it begins 0x, 0X or $, or ends in H, it's in hex. if it
192 * ends in Q, it's octal. if it ends in B, it's binary.
193 * Otherwise, it's ordinary decimal.
195 if (*r == '0' && (r[1] == 'x' || r[1] == 'X'))
199 else if (q[-1] == 'H' || q[-1] == 'h')
201 else if (q[-1] == 'Q' || q[-1] == 'q' || q[-1] == 'O' || q[-1] == 'o')
203 else if (q[-1] == 'B' || q[-1] == 'b')
209 * If this number has been found for us by something other than
210 * the ordinary scanners, then it might be malformed by having
211 * nothing between the prefix and the suffix. Check this case
220 * `checklimit' must be 2**(32|64) / radix. We can't do that in
221 * 32/64-bit arithmetic, which we're (probably) using, so we
222 * cheat: since we know that all radices we use are even, we
223 * can divide 2**(31|63) by radix/2 instead.
225 if (globalbits == 64)
226 checklimit = 0x8000000000000000ULL / (radix >> 1);
228 checklimit = 0x80000000UL / (radix >> 1);
231 * Calculate the highest allowable value for the last digit of a
232 * 32-bit constant... in radix 10, it is 6, otherwise it is 0
234 last = (radix == 10 ? 6 : 0);
237 while (*r && r < q) {
238 if (*r < '0' || (*r > '9' && *r < 'A')
239 || (digit = numvalue(*r)) >= radix) {
243 if (result > checklimit || (result == checklimit && digit >= last)) {
247 result = radix * result + digit;
252 nasm_malloc_error(ERR_WARNING | ERR_PASS1 | ERR_WARN_NOV,
253 "numeric constant %s does not fit in 32 bits",
256 return result * sign;
259 int64_t readstrnum(int8_t *str, int length, int *warn)
261 int64_t charconst = 0;
267 if (globalbits == 64) {
268 for (i = 0; i < length; i++) {
269 if (charconst & 0xFF00000000000000ULL)
271 charconst = (charconst << 8) + (uint8_t)*--str;
274 for (i = 0; i < length; i++) {
275 if (charconst & 0xFF000000UL)
277 charconst = (charconst << 8) + (uint8_t)*--str;
283 static int32_t next_seg;
290 int32_t seg_alloc(void)
292 return (next_seg += 2) - 2;
295 void fwriteint16_t(int data, FILE * fp)
297 fputc((int)(data & 255), fp);
298 fputc((int)((data >> 8) & 255), fp);
301 void fwriteint32_t(int32_t data, FILE * fp)
303 fputc((int)(data & 255), fp);
304 fputc((int)((data >> 8) & 255), fp);
305 fputc((int)((data >> 16) & 255), fp);
306 fputc((int)((data >> 24) & 255), fp);
309 void standard_extension(int8_t *inname, int8_t *outname, int8_t *extension,
314 if (*outname) /* file name already exists, */
315 return; /* so do nothing */
319 *p++ = *q++; /* copy, and find end of string */
320 *p = '\0'; /* terminate it */
321 while (p > outname && *--p != '.') ; /* find final period (or whatever) */
324 p++; /* go back to end if none found */
325 if (!strcmp(p, extension)) { /* is the extension already there? */
327 error(ERR_WARNING | ERR_NOFILE,
328 "file name already ends in `%s': "
329 "output will be in `nasm.out'", extension);
331 error(ERR_WARNING | ERR_NOFILE,
332 "file name already has no extension: "
333 "output will be in `nasm.out'");
334 strcpy(outname, "nasm.out");
336 strcpy(p, extension);
339 #define LEAFSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_LEAF))
340 #define BRANCHSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_BRANCH))
342 #define LAYERSIZ(r) ( (r)->layers==0 ? RAA_BLKSIZE : RAA_LAYERSIZE )
344 static struct RAA *real_raa_init(int layers)
350 r = nasm_malloc(LEAFSIZ);
352 memset(r->u.l.data, 0, sizeof(r->u.l.data));
355 r = nasm_malloc(BRANCHSIZ);
357 for (i = 0; i < RAA_LAYERSIZE; i++)
358 r->u.b.data[i] = NULL;
359 r->stepsize = RAA_BLKSIZE;
361 r->stepsize *= RAA_LAYERSIZE;
366 struct RAA *raa_init(void)
368 return real_raa_init(0);
371 void raa_free(struct RAA *r)
377 for (p = r->u.b.data; p - r->u.b.data < RAA_LAYERSIZE; p++)
383 int32_t raa_read(struct RAA *r, int32_t posn)
385 if (posn >= r->stepsize * LAYERSIZ(r))
386 return 0; /* Return 0 for undefined entries */
387 while (r->layers > 0) {
389 l = ldiv(posn, r->stepsize);
390 r = r->u.b.data[l.quot];
393 return 0; /* Return 0 for undefined entries */
395 return r->u.l.data[posn];
398 struct RAA *raa_write(struct RAA *r, int32_t posn, int32_t value)
403 nasm_malloc_error(ERR_PANIC, "negative position in raa_write");
405 while (r->stepsize * LAYERSIZ(r) <= posn) {
412 s = nasm_malloc(BRANCHSIZ);
413 for (i = 0; i < RAA_LAYERSIZE; i++)
414 s->u.b.data[i] = NULL;
415 s->layers = r->layers + 1;
416 s->stepsize = LAYERSIZ(r) * r->stepsize;
423 while (r->layers > 0) {
426 l = ldiv(posn, r->stepsize);
427 s = &r->u.b.data[l.quot];
429 *s = real_raa_init(r->layers - 1);
434 r->u.l.data[posn] = value;
439 #define SAA_MAXLEN 8192
441 struct SAA *saa_init(int32_t elem_len)
445 if (elem_len > SAA_MAXLEN)
446 nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
447 "SAA with huge elements");
449 s = nasm_malloc(sizeof(struct SAA));
450 s->posn = s->start = 0L;
451 s->elem_len = elem_len;
452 s->length = SAA_MAXLEN - (SAA_MAXLEN % elem_len);
453 s->data = nasm_malloc(s->length);
460 void saa_free(struct SAA *s)
472 void *saa_wstruct(struct SAA *s)
476 if (s->end->length - s->end->posn < s->elem_len) {
477 s->end->next = nasm_malloc(sizeof(struct SAA));
478 s->end->next->start = s->end->start + s->end->posn;
479 s->end = s->end->next;
480 s->end->length = s->length;
483 s->end->data = nasm_malloc(s->length);
486 p = s->end->data + s->end->posn;
487 s->end->posn += s->elem_len;
491 void saa_wbytes(struct SAA *s, const void *data, int32_t len)
493 const int8_t *d = data;
496 int32_t l = s->end->length - s->end->posn;
501 memcpy(s->end->data + s->end->posn, d, l);
504 memset(s->end->data + s->end->posn, 0, l);
509 s->end->next = nasm_malloc(sizeof(struct SAA));
510 s->end->next->start = s->end->start + s->end->posn;
511 s->end = s->end->next;
512 s->end->length = s->length;
515 s->end->data = nasm_malloc(s->length);
520 void saa_rewind(struct SAA *s)
526 void *saa_rstruct(struct SAA *s)
533 if (s->rptr->posn - s->rpos < s->elem_len) {
534 s->rptr = s->rptr->next;
536 return NULL; /* end of array */
540 p = s->rptr->data + s->rpos;
541 s->rpos += s->elem_len;
545 void *saa_rbytes(struct SAA *s, int32_t *len)
552 p = s->rptr->data + s->rpos;
553 *len = s->rptr->posn - s->rpos;
554 s->rptr = s->rptr->next;
559 void saa_rnbytes(struct SAA *s, void *data, int32_t len)
569 l = s->rptr->posn - s->rpos;
573 memcpy(d, s->rptr->data + s->rpos, l);
579 s->rptr = s->rptr->next;
585 void saa_fread(struct SAA *s, int32_t posn, void *data, int32_t len)
589 int8_t *cdata = data;
591 if (!s->rptr || posn < s->rptr->start)
594 while (posn >= p->start + p->posn) {
597 return; /* what else can we do?! */
600 pos = posn - p->start;
602 int64_t l = p->posn - pos;
605 memcpy(cdata, p->data + pos, l);
616 void saa_fwrite(struct SAA *s, int32_t posn, void *data, int32_t len)
620 int8_t *cdata = data;
622 if (!s->rptr || posn < s->rptr->start)
625 while (posn >= p->start + p->posn) {
628 return; /* what else can we do?! */
631 pos = posn - p->start;
633 int64_t l = p->posn - pos;
636 memcpy(p->data + pos, cdata, l);
647 void saa_fpwrite(struct SAA *s, FILE * fp)
653 while ((data = saa_rbytes(s, &len)))
654 fwrite(data, 1, len, fp);
658 * Register, instruction, condition-code and prefix keywords used
662 static const int8_t *special_names[] = {
663 "byte", "dword", "far", "long", "near", "nosplit", "qword",
664 "short", "strict", "to", "tword", "word"
666 static const int8_t *prefix_names[] = {
667 "a16", "a32", "lock", "o16", "o32", "rep", "repe", "repne",
668 "repnz", "repz", "times"
672 * Standard scanner routine used by parser.c and some output
673 * formats. It keeps a succession of temporary-storage strings in
674 * stdscan_tempstorage, which can be cleared using stdscan_reset.
676 static int8_t **stdscan_tempstorage = NULL;
677 static int stdscan_tempsize = 0, stdscan_templen = 0;
678 #define STDSCAN_TEMP_DELTA 256
680 static void stdscan_pop(void)
682 nasm_free(stdscan_tempstorage[--stdscan_templen]);
685 void stdscan_reset(void)
687 while (stdscan_templen > 0)
692 * Unimportant cleanup is done to avoid confusing people who are trying
693 * to debug real memory leaks
695 void nasmlib_cleanup(void)
698 nasm_free(stdscan_tempstorage);
701 static int8_t *stdscan_copy(int8_t *p, int len)
705 text = nasm_malloc(len + 1);
706 strncpy(text, p, len);
709 if (stdscan_templen >= stdscan_tempsize) {
710 stdscan_tempsize += STDSCAN_TEMP_DELTA;
711 stdscan_tempstorage = nasm_realloc(stdscan_tempstorage,
715 stdscan_tempstorage[stdscan_templen++] = text;
720 int8_t *stdscan_bufptr = NULL;
721 int stdscan(void *private_data, struct tokenval *tv)
723 int8_t ourcopy[MAX_KEYWORD + 1], *r, *s;
725 (void)private_data; /* Don't warn that this parameter is unused */
727 while (isspace(*stdscan_bufptr))
729 if (!*stdscan_bufptr)
730 return tv->t_type = 0;
732 /* we have a token; either an id, a number or a char */
733 if (isidstart(*stdscan_bufptr) ||
734 (*stdscan_bufptr == '$' && isidstart(stdscan_bufptr[1]))) {
735 /* now we've got an identifier */
739 if (*stdscan_bufptr == '$') {
744 r = stdscan_bufptr++;
745 /* read the entire buffer to advance the buffer pointer but... */
746 while (isidchar(*stdscan_bufptr))
749 /* ... copy only up to IDLEN_MAX-1 characters */
750 tv->t_charptr = stdscan_copy(r, stdscan_bufptr - r < IDLEN_MAX ?
751 stdscan_bufptr - r : IDLEN_MAX - 1);
753 if (is_sym || stdscan_bufptr - r > MAX_KEYWORD)
754 return tv->t_type = TOKEN_ID; /* bypass all other checks */
756 for (s = tv->t_charptr, r = ourcopy; *s; s++)
759 /* right, so we have an identifier sitting in temp storage. now,
760 * is it actually a register or instruction name, or what? */
761 if ((tv->t_integer = bsi(ourcopy, reg_names,
762 elements(reg_names))) >= 0) {
763 tv->t_integer += EXPR_REG_START;
764 return tv->t_type = TOKEN_REG;
765 } else if ((tv->t_integer = bsi(ourcopy, insn_names,
766 elements(insn_names))) >= 0) {
767 return tv->t_type = TOKEN_INSN;
769 for (i = 0; i < elements(icn); i++)
770 if (!strncmp(ourcopy, icn[i], strlen(icn[i]))) {
771 int8_t *p = ourcopy + strlen(icn[i]);
772 tv->t_integer = ico[i];
773 if ((tv->t_inttwo = bsi(p, conditions,
774 elements(conditions))) >= 0)
775 return tv->t_type = TOKEN_INSN;
777 if ((tv->t_integer = bsi(ourcopy, prefix_names,
778 elements(prefix_names))) >= 0) {
779 tv->t_integer += PREFIX_ENUM_START;
780 return tv->t_type = TOKEN_PREFIX;
782 if ((tv->t_integer = bsi(ourcopy, special_names,
783 elements(special_names))) >= 0)
784 return tv->t_type = TOKEN_SPECIAL;
785 if (!nasm_stricmp(ourcopy, "seg"))
786 return tv->t_type = TOKEN_SEG;
787 if (!nasm_stricmp(ourcopy, "wrt"))
788 return tv->t_type = TOKEN_WRT;
789 return tv->t_type = TOKEN_ID;
790 } else if (*stdscan_bufptr == '$' && !isnumchar(stdscan_bufptr[1])) {
792 * It's a $ sign with no following hex number; this must
793 * mean it's a Here token ($), evaluating to the current
794 * assembly location, or a Base token ($$), evaluating to
795 * the base of the current segment.
798 if (*stdscan_bufptr == '$') {
800 return tv->t_type = TOKEN_BASE;
802 return tv->t_type = TOKEN_HERE;
803 } else if (isnumstart(*stdscan_bufptr)) { /* now we've got a number */
806 r = stdscan_bufptr++;
807 while (isnumchar(*stdscan_bufptr))
810 if (*stdscan_bufptr == '.') {
812 * a floating point constant
815 while (isnumchar(*stdscan_bufptr) ||
816 ((stdscan_bufptr[-1] == 'e'
817 || stdscan_bufptr[-1] == 'E')
818 && (*stdscan_bufptr == '-' || *stdscan_bufptr == '+'))) {
821 tv->t_charptr = stdscan_copy(r, stdscan_bufptr - r);
822 return tv->t_type = TOKEN_FLOAT;
824 r = stdscan_copy(r, stdscan_bufptr - r);
825 tv->t_integer = readnum(r, &rn_error);
828 return tv->t_type = TOKEN_ERRNUM; /* some malformation occurred */
829 tv->t_charptr = NULL;
830 return tv->t_type = TOKEN_NUM;
831 } else if (*stdscan_bufptr == '\'' || *stdscan_bufptr == '"') { /* a char constant */
832 int8_t quote = *stdscan_bufptr++, *r;
834 r = tv->t_charptr = stdscan_bufptr;
835 while (*stdscan_bufptr && *stdscan_bufptr != quote)
837 tv->t_inttwo = stdscan_bufptr - r; /* store full version */
838 if (!*stdscan_bufptr)
839 return tv->t_type = TOKEN_ERRNUM; /* unmatched quotes */
840 stdscan_bufptr++; /* skip over final quote */
841 tv->t_integer = readstrnum(r, tv->t_inttwo, &rn_warn);
842 /* FIXME: rn_warn is not checked! */
843 return tv->t_type = TOKEN_NUM;
844 } else if (*stdscan_bufptr == ';') { /* a comment has happened - stay */
845 return tv->t_type = 0;
846 } else if (stdscan_bufptr[0] == '>' && stdscan_bufptr[1] == '>') {
848 return tv->t_type = TOKEN_SHR;
849 } else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '<') {
851 return tv->t_type = TOKEN_SHL;
852 } else if (stdscan_bufptr[0] == '/' && stdscan_bufptr[1] == '/') {
854 return tv->t_type = TOKEN_SDIV;
855 } else if (stdscan_bufptr[0] == '%' && stdscan_bufptr[1] == '%') {
857 return tv->t_type = TOKEN_SMOD;
858 } else if (stdscan_bufptr[0] == '=' && stdscan_bufptr[1] == '=') {
860 return tv->t_type = TOKEN_EQ;
861 } else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '>') {
863 return tv->t_type = TOKEN_NE;
864 } else if (stdscan_bufptr[0] == '!' && stdscan_bufptr[1] == '=') {
866 return tv->t_type = TOKEN_NE;
867 } else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '=') {
869 return tv->t_type = TOKEN_LE;
870 } else if (stdscan_bufptr[0] == '>' && stdscan_bufptr[1] == '=') {
872 return tv->t_type = TOKEN_GE;
873 } else if (stdscan_bufptr[0] == '&' && stdscan_bufptr[1] == '&') {
875 return tv->t_type = TOKEN_DBL_AND;
876 } else if (stdscan_bufptr[0] == '^' && stdscan_bufptr[1] == '^') {
878 return tv->t_type = TOKEN_DBL_XOR;
879 } else if (stdscan_bufptr[0] == '|' && stdscan_bufptr[1] == '|') {
881 return tv->t_type = TOKEN_DBL_OR;
882 } else /* just an ordinary char */
883 return tv->t_type = (uint8_t)(*stdscan_bufptr++);
887 * Return TRUE if the argument is a simple scalar. (Or a far-
888 * absolute, which counts.)
890 int is_simple(expr * vect)
892 while (vect->type && !vect->value)
896 if (vect->type != EXPR_SIMPLE)
900 } while (vect->type && !vect->value);
901 if (vect->type && vect->type < EXPR_SEGBASE + SEG_ABS)
907 * Return TRUE if the argument is a simple scalar, _NOT_ a far-
910 int is_really_simple(expr * vect)
912 while (vect->type && !vect->value)
916 if (vect->type != EXPR_SIMPLE)
920 } while (vect->type && !vect->value);
927 * Return TRUE if the argument is relocatable (i.e. a simple
928 * scalar, plus at most one segment-base, plus possibly a WRT).
930 int is_reloc(expr * vect)
932 while (vect->type && !vect->value) /* skip initial value-0 terms */
934 if (!vect->type) /* trivially return TRUE if nothing */
935 return 1; /* is present apart from value-0s */
936 if (vect->type < EXPR_SIMPLE) /* FALSE if a register is present */
938 if (vect->type == EXPR_SIMPLE) { /* skip over a pure number term... */
941 } while (vect->type && !vect->value);
942 if (!vect->type) /* ...returning TRUE if that's all */
945 if (vect->type == EXPR_WRT) { /* skip over a WRT term... */
948 } while (vect->type && !vect->value);
949 if (!vect->type) /* ...returning TRUE if that's all */
952 if (vect->value != 0 && vect->value != 1)
953 return 0; /* segment base multiplier non-unity */
954 do { /* skip over _one_ seg-base term... */
956 } while (vect->type && !vect->value);
957 if (!vect->type) /* ...returning TRUE if that's all */
959 return 0; /* And return FALSE if there's more */
963 * Return TRUE if the argument contains an `unknown' part.
965 int is_unknown(expr * vect)
967 while (vect->type && vect->type < EXPR_UNKNOWN)
969 return (vect->type == EXPR_UNKNOWN);
973 * Return TRUE if the argument contains nothing but an `unknown'
976 int is_just_unknown(expr * vect)
978 while (vect->type && !vect->value)
980 return (vect->type == EXPR_UNKNOWN);
984 * Return the scalar part of a relocatable vector. (Including
985 * simple scalar vectors - those qualify as relocatable.)
987 int64_t reloc_value(expr * vect)
989 while (vect->type && !vect->value)
993 if (vect->type == EXPR_SIMPLE)
1000 * Return the segment number of a relocatable vector, or NO_SEG for
1003 int32_t reloc_seg(expr * vect)
1005 while (vect->type && (vect->type == EXPR_WRT || !vect->value))
1007 if (vect->type == EXPR_SIMPLE) {
1010 } while (vect->type && (vect->type == EXPR_WRT || !vect->value));
1015 return vect->type - EXPR_SEGBASE;
1019 * Return the WRT segment number of a relocatable vector, or NO_SEG
1020 * if no WRT part is present.
1022 int32_t reloc_wrt(expr * vect)
1024 while (vect->type && vect->type < EXPR_WRT)
1026 if (vect->type == EXPR_WRT) {
1035 int bsi(int8_t *string, const int8_t **array, int size)
1037 int i = -1, j = size; /* always, i < index < j */
1038 while (j - i >= 2) {
1039 int k = (i + j) / 2;
1040 int l = strcmp(string, array[k]);
1041 if (l < 0) /* it's in the first half */
1043 else if (l > 0) /* it's in the second half */
1045 else /* we've got it :) */
1048 return -1; /* we haven't got it :( */
1051 static int8_t *file_name = NULL;
1052 static int32_t line_number = 0;
1054 int8_t *src_set_fname(int8_t *newname)
1056 int8_t *oldname = file_name;
1057 file_name = newname;
1061 int32_t src_set_linnum(int32_t newline)
1063 int32_t oldline = line_number;
1064 line_number = newline;
1068 int32_t src_get_linnum(void)
1073 int src_get(int32_t *xline, int8_t **xname)
1075 if (!file_name || !*xname || strcmp(*xname, file_name)) {
1077 *xname = file_name ? nasm_strdup(file_name) : NULL;
1078 *xline = line_number;
1081 if (*xline != line_number) {
1082 int32_t tmp = line_number - *xline;
1083 *xline = line_number;
1089 void nasm_quote(int8_t **str)
1091 int ln = strlen(*str);
1092 int8_t q = (*str)[0];
1094 if (ln > 1 && (*str)[ln - 1] == q && (q == '"' || q == '\''))
1097 if (strchr(*str, q))
1099 p = nasm_malloc(ln + 3);
1100 strcpy(p + 1, *str);
1102 p[ln + 1] = p[0] = q;
1107 int8_t *nasm_strcat(int8_t *one, int8_t *two)
1110 int l1 = strlen(one);
1111 rslt = nasm_malloc(l1 + strlen(two) + 1);
1113 strcpy(rslt + l1, two);
1117 void null_debug_init(struct ofmt *of, void *id, FILE * fp, efunc error)
1120 void null_debug_linenum(const int8_t *filename, int32_t linenumber, int32_t segto)
1123 void null_debug_deflabel(int8_t *name, int32_t segment, int32_t offset,
1124 int is_global, int8_t *special)
1127 void null_debug_routine(const int8_t *directive, const int8_t *params)
1130 void null_debug_typevalue(int32_t type)
1133 void null_debug_output(int type, void *param)
1136 void null_debug_cleanup(void)
1140 struct dfmt null_debug_form = {
1141 "Null debug format",
1145 null_debug_deflabel,
1147 null_debug_typevalue,
1152 struct dfmt *null_debug_arr[2] = { &null_debug_form, NULL };