nasm/nasmlib.c

1171 lines
30 KiB
C
Raw Normal View History

2002-05-01 04:51:32 +08:00
/* nasmlib.c library routines for the Netwide Assembler
*
* The Netwide Assembler is copyright (C) 1996 Simon Tatham and
* Julian Hall. All rights reserved. The software is
* redistributable under the licence given in the file "Licence"
* distributed in the NASM archive.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
2002-05-01 04:51:32 +08:00
#include "nasm.h"
#include "nasmlib.h"
2005-01-16 06:15:51 +08:00
#include "insns.h" /* For MAX_KEYWORD */
2002-05-01 04:51:32 +08:00
int globalbits = 0; /* defined in nasm.h, works better here for ASM+DISASM */
2002-05-01 04:51:32 +08:00
static efunc nasm_malloc_error;
2002-05-01 04:52:08 +08:00
#ifdef LOGALLOC
static FILE *logfp;
#endif
2005-01-16 06:15:51 +08:00
void nasm_set_malloc_error(efunc error)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:51:32 +08:00
nasm_malloc_error = error;
2002-05-01 04:52:08 +08:00
#ifdef LOGALLOC
2005-01-16 06:15:51 +08:00
logfp = fopen("malloc.log", "w");
setvbuf(logfp, NULL, _IOLBF, BUFSIZ);
fprintf(logfp, "null pointer is %p\n", NULL);
2002-05-01 04:52:08 +08:00
#endif
2002-05-01 04:51:32 +08:00
}
2002-05-01 04:52:08 +08:00
#ifdef LOGALLOC
void *nasm_malloc_log(char *file, int line, size_t size)
2002-05-01 04:52:08 +08:00
#else
2005-01-16 06:15:51 +08:00
void *nasm_malloc(size_t size)
2002-05-01 04:52:08 +08:00
#endif
{
2002-05-01 04:51:32 +08:00
void *p = malloc(size);
if (!p)
2005-01-16 06:15:51 +08:00
nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
2002-05-01 04:52:08 +08:00
#ifdef LOGALLOC
else
2005-01-16 06:15:51 +08:00
fprintf(logfp, "%s %d malloc(%ld) returns %p\n",
file, line, (int32_t)size, p);
2002-05-01 04:52:08 +08:00
#endif
2002-05-01 04:51:32 +08:00
return p;
}
2002-05-01 04:52:08 +08:00
#ifdef LOGALLOC
void *nasm_realloc_log(char *file, int line, void *q, size_t size)
2002-05-01 04:52:08 +08:00
#else
2005-01-16 06:15:51 +08:00
void *nasm_realloc(void *q, size_t size)
2002-05-01 04:52:08 +08:00
#endif
{
2002-05-01 04:51:32 +08:00
void *p = q ? realloc(q, size) : malloc(size);
if (!p)
2005-01-16 06:15:51 +08:00
nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
2002-05-01 04:52:08 +08:00
#ifdef LOGALLOC
else if (q)
2005-01-16 06:15:51 +08:00
fprintf(logfp, "%s %d realloc(%p,%ld) returns %p\n",
file, line, q, (int32_t)size, p);
2002-05-01 04:52:08 +08:00
else
2005-01-16 06:15:51 +08:00
fprintf(logfp, "%s %d malloc(%ld) returns %p\n",
file, line, (int32_t)size, p);
2002-05-01 04:52:08 +08:00
#endif
2002-05-01 04:51:32 +08:00
return p;
}
2002-05-01 04:52:08 +08:00
#ifdef LOGALLOC
void nasm_free_log(char *file, int line, void *q)
2002-05-01 04:52:08 +08:00
#else
2005-01-16 06:15:51 +08:00
void nasm_free(void *q)
2002-05-01 04:52:08 +08:00
#endif
{
if (q) {
2005-01-16 06:15:51 +08:00
free(q);
2002-05-01 04:52:08 +08:00
#ifdef LOGALLOC
2005-01-16 06:15:51 +08:00
fprintf(logfp, "%s %d free(%p)\n", file, line, q);
2002-05-01 04:52:08 +08:00
#endif
}
2002-05-01 04:51:32 +08:00
}
2002-05-01 04:52:08 +08:00
#ifdef LOGALLOC
char *nasm_strdup_log(char *file, int line, const char *s)
2002-05-01 04:52:08 +08:00
#else
char *nasm_strdup(const char *s)
2002-05-01 04:52:08 +08:00
#endif
{
char *p;
2005-01-16 06:15:51 +08:00
int size = strlen(s) + 1;
2002-05-01 04:51:32 +08:00
2002-05-01 04:52:08 +08:00
p = malloc(size);
if (!p)
2005-01-16 06:15:51 +08:00
nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
2002-05-01 04:52:08 +08:00
#ifdef LOGALLOC
else
2005-01-16 06:15:51 +08:00
fprintf(logfp, "%s %d strdup(%ld) returns %p\n",
file, line, (int32_t)size, p);
2002-05-01 04:52:08 +08:00
#endif
2005-01-16 06:15:51 +08:00
strcpy(p, s);
2002-05-01 04:51:32 +08:00
return p;
}
2002-05-01 04:52:49 +08:00
#ifdef LOGALLOC
char *nasm_strndup_log(char *file, int line, char *s, size_t len)
2002-05-01 04:52:49 +08:00
#else
char *nasm_strndup(char *s, size_t len)
2002-05-01 04:52:49 +08:00
#endif
{
char *p;
2005-01-16 06:15:51 +08:00
int size = len + 1;
2002-05-01 04:52:49 +08:00
p = malloc(size);
if (!p)
2005-01-16 06:15:51 +08:00
nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory");
2002-05-01 04:52:49 +08:00
#ifdef LOGALLOC
else
2005-01-16 06:15:51 +08:00
fprintf(logfp, "%s %d strndup(%ld) returns %p\n",
file, line, (int32_t)size, p);
2002-05-01 04:52:49 +08:00
#endif
2005-01-16 06:15:51 +08:00
strncpy(p, s, len);
2002-05-01 04:52:49 +08:00
p[len] = '\0';
return p;
}
2002-05-01 04:59:21 +08:00
#if !defined(stricmp) && !defined(strcasecmp)
int nasm_stricmp(const char *s1, const char *s2)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:59:21 +08:00
while (*s1 && tolower(*s1) == tolower(*s2))
2005-01-16 06:15:51 +08:00
s1++, s2++;
2002-05-01 04:51:32 +08:00
if (!*s1 && !*s2)
2005-01-16 06:15:51 +08:00
return 0;
2002-05-01 04:59:21 +08:00
else if (tolower(*s1) < tolower(*s2))
2005-01-16 06:15:51 +08:00
return -1;
2002-05-01 04:51:32 +08:00
else
2005-01-16 06:15:51 +08:00
return 1;
2002-05-01 04:51:32 +08:00
}
2002-05-01 04:59:21 +08:00
#endif
2002-05-01 04:51:32 +08:00
2002-05-01 04:59:21 +08:00
#if !defined(strnicmp) && !defined(strncasecmp)
int nasm_strnicmp(const char *s1, const char *s2, int n)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:59:21 +08:00
while (n > 0 && *s1 && tolower(*s1) == tolower(*s2))
2005-01-16 06:15:51 +08:00
s1++, s2++, n--;
if ((!*s1 && !*s2) || n == 0)
return 0;
2002-05-01 04:59:21 +08:00
else if (tolower(*s1) < tolower(*s2))
2005-01-16 06:15:51 +08:00
return -1;
2002-05-01 04:51:32 +08:00
else
2005-01-16 06:15:51 +08:00
return 1;
2002-05-01 04:51:32 +08:00
}
2002-05-01 04:59:21 +08:00
#endif
2002-05-01 04:51:32 +08:00
2002-05-01 04:52:08 +08:00
#define lib_isnumchar(c) ( isalnum(c) || (c) == '$')
2002-05-01 04:51:32 +08:00
#define numvalue(c) ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0')
int64_t readnum(char *str, int *error)
2002-05-01 04:53:55 +08:00
{
char *r = str, *q;
int32_t radix;
uint64_t result, checklimit;
2002-05-01 04:53:55 +08:00
int digit, last;
2002-05-01 04:52:49 +08:00
int warn = FALSE;
2002-05-01 04:53:55 +08:00
int sign = 1;
2002-05-01 04:51:32 +08:00
*error = FALSE;
2005-01-16 06:15:51 +08:00
while (isspace(*r))
r++; /* find start of number */
2002-05-01 04:53:55 +08:00
/*
* If the number came from make_tok_num (as a result of an %assign), it
* might have a '-' built into it (rather than in a preceeding token).
*/
2005-01-16 06:15:51 +08:00
if (*r == '-') {
r++;
sign = -1;
2002-05-01 04:53:55 +08:00
}
2002-05-01 04:51:32 +08:00
q = r;
2005-01-16 06:15:51 +08:00
while (lib_isnumchar(*q))
q++; /* find end of number */
2002-05-01 04:51:32 +08:00
/*
* If it begins 0x, 0X or $, or ends in H, it's in hex. if it
* ends in Q, it's octal. if it ends in B, it's binary.
* Otherwise, it's ordinary decimal.
*/
2005-01-16 06:15:51 +08:00
if (*r == '0' && (r[1] == 'x' || r[1] == 'X'))
radix = 16, r += 2;
else if (*r == '$')
radix = 16, r++;
else if (q[-1] == 'H' || q[-1] == 'h')
radix = 16, q--;
else if (q[-1] == 'Q' || q[-1] == 'q' || q[-1] == 'O' || q[-1] == 'o')
radix = 8, q--;
else if (q[-1] == 'B' || q[-1] == 'b')
radix = 2, q--;
2002-05-01 04:51:32 +08:00
else
2005-01-16 06:15:51 +08:00
radix = 10;
2002-05-01 04:51:32 +08:00
2002-05-01 04:52:49 +08:00
/*
* If this number has been found for us by something other than
* the ordinary scanners, then it might be malformed by having
* nothing between the prefix and the suffix. Check this case
* now.
*/
if (r >= q) {
2005-01-16 06:15:51 +08:00
*error = TRUE;
return 0;
2002-05-01 04:52:49 +08:00
}
2002-05-01 04:52:49 +08:00
/*
* `checklimit' must be 2**(32|64) / radix. We can't do that in
* 32/64-bit arithmetic, which we're (probably) using, so we
2002-05-01 04:52:49 +08:00
* cheat: since we know that all radices we use are even, we
* can divide 2**(31|63) by radix/2 instead.
2002-05-01 04:52:49 +08:00
*/
if (globalbits == 64)
checklimit = 0x8000000000000000ULL / (radix >> 1);
else
checklimit = 0x80000000UL / (radix >> 1);
2002-05-01 04:52:49 +08:00
2002-05-01 04:53:55 +08:00
/*
* Calculate the highest allowable value for the last digit of a
* 32-bit constant... in radix 10, it is 6, otherwise it is 0
2002-05-01 04:53:55 +08:00
*/
last = (radix == 10 ? 6 : 0);
2002-05-01 04:51:32 +08:00
result = 0;
while (*r && r < q) {
2005-01-16 06:15:51 +08:00
if (*r < '0' || (*r > '9' && *r < 'A')
|| (digit = numvalue(*r)) >= radix) {
*error = TRUE;
return 0;
}
if (result > checklimit || (result == checklimit && digit >= last)) {
warn = TRUE;
}
result = radix * result + digit;
r++;
2002-05-01 04:51:32 +08:00
}
2002-05-01 04:52:49 +08:00
if (warn)
2005-01-16 06:15:51 +08:00
nasm_malloc_error(ERR_WARNING | ERR_PASS1 | ERR_WARN_NOV,
"numeric constant %s does not fit in 32 bits",
str);
2002-05-01 04:52:49 +08:00
2005-01-16 06:15:51 +08:00
return result * sign;
2002-05-01 04:53:55 +08:00
}
int64_t readstrnum(char *str, int length, int *warn)
2002-05-01 04:53:55 +08:00
{
int64_t charconst = 0;
2002-05-01 04:53:55 +08:00
int i;
*warn = FALSE;
str += length;
if (globalbits == 64) {
for (i = 0; i < length; i++) {
if (charconst & 0xFF00000000000000ULL)
*warn = TRUE;
charconst = (charconst << 8) + (uint8_t)*--str;
}
} else {
for (i = 0; i < length; i++) {
if (charconst & 0xFF000000UL)
*warn = TRUE;
charconst = (charconst << 8) + (uint8_t)*--str;
2005-01-16 06:15:51 +08:00
}
2002-05-01 04:53:55 +08:00
}
return charconst;
2002-05-01 04:51:32 +08:00
}
static int32_t next_seg;
2002-05-01 04:51:32 +08:00
2005-01-16 06:15:51 +08:00
void seg_init(void)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:51:32 +08:00
next_seg = 0;
}
int32_t seg_alloc(void)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:51:32 +08:00
return (next_seg += 2) - 2;
}
void fwriteint16_t(int data, FILE * fp)
2002-05-01 04:53:55 +08:00
{
2005-01-16 06:15:51 +08:00
fputc((int)(data & 255), fp);
fputc((int)((data >> 8) & 255), fp);
2002-05-01 04:51:32 +08:00
}
void fwriteint32_t(int32_t data, FILE * fp)
2002-05-01 04:53:55 +08:00
{
2005-01-16 06:15:51 +08:00
fputc((int)(data & 255), fp);
fputc((int)((data >> 8) & 255), fp);
fputc((int)((data >> 16) & 255), fp);
fputc((int)((data >> 24) & 255), fp);
2002-05-01 04:51:32 +08:00
}
void standard_extension(char *inname, char *outname, char *extension,
2005-01-16 06:15:51 +08:00
efunc error)
2002-05-01 04:53:55 +08:00
{
char *p, *q;
2002-05-01 04:51:32 +08:00
2005-01-16 06:15:51 +08:00
if (*outname) /* file name already exists, */
return; /* so do nothing */
2002-05-01 04:51:32 +08:00
q = inname;
p = outname;
2005-01-16 06:15:51 +08:00
while (*q)
*p++ = *q++; /* copy, and find end of string */
*p = '\0'; /* terminate it */
while (p > outname && *--p != '.') ; /* find final period (or whatever) */
if (*p != '.')
while (*p)
p++; /* go back to end if none found */
if (!strcmp(p, extension)) { /* is the extension already there? */
if (*extension)
error(ERR_WARNING | ERR_NOFILE,
"file name already ends in `%s': "
"output will be in `nasm.out'", extension);
else
error(ERR_WARNING | ERR_NOFILE,
"file name already has no extension: "
"output will be in `nasm.out'");
strcpy(outname, "nasm.out");
2002-05-01 04:51:32 +08:00
} else
2005-01-16 06:15:51 +08:00
strcpy(p, extension);
2002-05-01 04:51:32 +08:00
}
#define LEAFSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_LEAF))
#define BRANCHSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_BRANCH))
#define LAYERSIZ(r) ( (r)->layers==0 ? RAA_BLKSIZE : RAA_LAYERSIZE )
2005-01-16 06:15:51 +08:00
static struct RAA *real_raa_init(int layers)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:51:32 +08:00
struct RAA *r;
int i;
2002-05-01 04:51:32 +08:00
if (layers == 0) {
2005-01-16 06:15:51 +08:00
r = nasm_malloc(LEAFSIZ);
r->layers = 0;
memset(r->u.l.data, 0, sizeof(r->u.l.data));
r->stepsize = 1L;
2002-05-01 04:51:32 +08:00
} else {
2005-01-16 06:15:51 +08:00
r = nasm_malloc(BRANCHSIZ);
r->layers = layers;
for (i = 0; i < RAA_LAYERSIZE; i++)
r->u.b.data[i] = NULL;
r->stepsize = RAA_BLKSIZE;
while (--layers)
r->stepsize *= RAA_LAYERSIZE;
2002-05-01 04:51:32 +08:00
}
return r;
}
2005-01-16 06:15:51 +08:00
struct RAA *raa_init(void)
2002-05-01 04:53:55 +08:00
{
2005-01-16 06:15:51 +08:00
return real_raa_init(0);
2002-05-01 04:51:32 +08:00
}
2005-01-16 06:15:51 +08:00
void raa_free(struct RAA *r)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:51:32 +08:00
if (r->layers == 0)
2005-01-16 06:15:51 +08:00
nasm_free(r);
2002-05-01 04:51:32 +08:00
else {
2005-01-16 06:15:51 +08:00
struct RAA **p;
for (p = r->u.b.data; p - r->u.b.data < RAA_LAYERSIZE; p++)
if (*p)
raa_free(*p);
2002-05-01 04:51:32 +08:00
}
}
int32_t raa_read(struct RAA *r, int32_t posn)
2002-05-01 04:53:55 +08:00
{
2002-09-13 06:03:10 +08:00
if (posn >= r->stepsize * LAYERSIZ(r))
2005-01-16 06:15:51 +08:00
return 0; /* Return 0 for undefined entries */
2002-05-01 04:51:32 +08:00
while (r->layers > 0) {
2005-01-16 06:15:51 +08:00
ldiv_t l;
l = ldiv(posn, r->stepsize);
r = r->u.b.data[l.quot];
posn = l.rem;
if (!r)
return 0; /* Return 0 for undefined entries */
2002-05-01 04:51:32 +08:00
}
return r->u.l.data[posn];
}
struct RAA *raa_write(struct RAA *r, int32_t posn, int32_t value)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:51:32 +08:00
struct RAA *result;
if (posn < 0)
2005-01-16 06:15:51 +08:00
nasm_malloc_error(ERR_PANIC, "negative position in raa_write");
2002-05-01 04:51:32 +08:00
2002-09-13 06:03:10 +08:00
while (r->stepsize * LAYERSIZ(r) <= posn) {
2005-01-16 06:15:51 +08:00
/*
* Must add a layer.
*/
struct RAA *s;
int i;
s = nasm_malloc(BRANCHSIZ);
for (i = 0; i < RAA_LAYERSIZE; i++)
s->u.b.data[i] = NULL;
s->layers = r->layers + 1;
s->stepsize = LAYERSIZ(r) * r->stepsize;
s->u.b.data[0] = r;
r = s;
2002-05-01 04:51:32 +08:00
}
result = r;
while (r->layers > 0) {
2005-01-16 06:15:51 +08:00
ldiv_t l;
struct RAA **s;
l = ldiv(posn, r->stepsize);
s = &r->u.b.data[l.quot];
if (!*s)
*s = real_raa_init(r->layers - 1);
r = *s;
posn = l.rem;
2002-05-01 04:51:32 +08:00
}
r->u.l.data[posn] = value;
return result;
}
#define SAA_MAXLEN 8192
struct SAA *saa_init(int32_t elem_len)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:51:32 +08:00
struct SAA *s;
if (elem_len > SAA_MAXLEN)
2005-01-16 06:15:51 +08:00
nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
"SAA with huge elements");
2002-05-01 04:51:32 +08:00
2005-01-16 06:15:51 +08:00
s = nasm_malloc(sizeof(struct SAA));
2002-05-01 04:51:32 +08:00
s->posn = s->start = 0L;
s->elem_len = elem_len;
s->length = SAA_MAXLEN - (SAA_MAXLEN % elem_len);
2005-01-16 06:15:51 +08:00
s->data = nasm_malloc(s->length);
2002-05-01 04:51:32 +08:00
s->next = NULL;
s->end = s;
return s;
}
2005-01-16 06:15:51 +08:00
void saa_free(struct SAA *s)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:51:32 +08:00
struct SAA *t;
while (s) {
2005-01-16 06:15:51 +08:00
t = s->next;
nasm_free(s->data);
nasm_free(s);
s = t;
2002-05-01 04:51:32 +08:00
}
}
2005-01-16 06:15:51 +08:00
void *saa_wstruct(struct SAA *s)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:51:32 +08:00
void *p;
if (s->end->length - s->end->posn < s->elem_len) {
2005-01-16 06:15:51 +08:00
s->end->next = nasm_malloc(sizeof(struct SAA));
s->end->next->start = s->end->start + s->end->posn;
s->end = s->end->next;
s->end->length = s->length;
s->end->next = NULL;
s->end->posn = 0L;
s->end->data = nasm_malloc(s->length);
2002-05-01 04:51:32 +08:00
}
p = s->end->data + s->end->posn;
s->end->posn += s->elem_len;
return p;
}
void saa_wbytes(struct SAA *s, const void *data, int32_t len)
2002-05-01 04:53:55 +08:00
{
const char *d = data;
2002-05-01 04:51:32 +08:00
while (len > 0) {
int32_t l = s->end->length - s->end->posn;
2005-01-16 06:15:51 +08:00
if (l > len)
l = len;
if (l > 0) {
if (d) {
memcpy(s->end->data + s->end->posn, d, l);
d += l;
} else
memset(s->end->data + s->end->posn, 0, l);
s->end->posn += l;
len -= l;
}
if (len > 0) {
s->end->next = nasm_malloc(sizeof(struct SAA));
s->end->next->start = s->end->start + s->end->posn;
s->end = s->end->next;
s->end->length = s->length;
s->end->next = NULL;
s->end->posn = 0L;
s->end->data = nasm_malloc(s->length);
}
2002-05-01 04:51:32 +08:00
}
}
2005-01-16 06:15:51 +08:00
void saa_rewind(struct SAA *s)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:51:32 +08:00
s->rptr = s;
s->rpos = 0L;
}
2005-01-16 06:15:51 +08:00
void *saa_rstruct(struct SAA *s)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:51:32 +08:00
void *p;
if (!s->rptr)
2005-01-16 06:15:51 +08:00
return NULL;
2002-05-01 04:51:32 +08:00
if (s->rptr->posn - s->rpos < s->elem_len) {
2005-01-16 06:15:51 +08:00
s->rptr = s->rptr->next;
if (!s->rptr)
return NULL; /* end of array */
s->rpos = 0L;
2002-05-01 04:51:32 +08:00
}
p = s->rptr->data + s->rpos;
s->rpos += s->elem_len;
return p;
}
void *saa_rbytes(struct SAA *s, int32_t *len)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:51:32 +08:00
void *p;
if (!s->rptr)
2005-01-16 06:15:51 +08:00
return NULL;
2002-05-01 04:51:32 +08:00
p = s->rptr->data + s->rpos;
*len = s->rptr->posn - s->rpos;
s->rptr = s->rptr->next;
s->rpos = 0L;
return p;
}
void saa_rnbytes(struct SAA *s, void *data, int32_t len)
2002-05-01 04:53:55 +08:00
{
char *d = data;
2002-05-01 04:51:32 +08:00
while (len > 0) {
int32_t l;
2005-01-16 06:15:51 +08:00
if (!s->rptr)
return;
l = s->rptr->posn - s->rpos;
if (l > len)
l = len;
if (l > 0) {
memcpy(d, s->rptr->data + s->rpos, l);
d += l;
s->rpos += l;
len -= l;
}
if (len > 0) {
s->rptr = s->rptr->next;
s->rpos = 0L;
}
2002-05-01 04:51:32 +08:00
}
}
void saa_fread(struct SAA *s, int32_t posn, void *data, int32_t len)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:51:32 +08:00
struct SAA *p;
int64_t pos;
char *cdata = data;
2002-05-01 04:51:32 +08:00
2002-05-01 04:53:55 +08:00
if (!s->rptr || posn < s->rptr->start)
2005-01-16 06:15:51 +08:00
saa_rewind(s);
2002-05-01 04:53:55 +08:00
p = s->rptr;
while (posn >= p->start + p->posn) {
2005-01-16 06:15:51 +08:00
p = p->next;
if (!p)
return; /* what else can we do?! */
2002-05-01 04:51:32 +08:00
}
2002-05-01 04:53:55 +08:00
pos = posn - p->start;
2002-05-01 04:51:32 +08:00
while (len) {
int64_t l = p->posn - pos;
2005-01-16 06:15:51 +08:00
if (l > len)
l = len;
memcpy(cdata, p->data + pos, l);
len -= l;
cdata += l;
p = p->next;
if (!p)
return;
pos = 0LL;
2002-05-01 04:51:32 +08:00
}
2002-05-01 04:53:55 +08:00
s->rptr = p;
2002-05-01 04:51:32 +08:00
}
void saa_fwrite(struct SAA *s, int32_t posn, void *data, int32_t len)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:51:32 +08:00
struct SAA *p;
int64_t pos;
char *cdata = data;
2002-05-01 04:51:32 +08:00
2002-05-01 04:53:55 +08:00
if (!s->rptr || posn < s->rptr->start)
2005-01-16 06:15:51 +08:00
saa_rewind(s);
2002-05-01 04:53:55 +08:00
p = s->rptr;
while (posn >= p->start + p->posn) {
2005-01-16 06:15:51 +08:00
p = p->next;
if (!p)
return; /* what else can we do?! */
2002-05-01 04:51:32 +08:00
}
2002-05-01 04:53:55 +08:00
pos = posn - p->start;
2002-05-01 04:51:32 +08:00
while (len) {
int64_t l = p->posn - pos;
2005-01-16 06:15:51 +08:00
if (l > len)
l = len;
memcpy(p->data + pos, cdata, l);
len -= l;
cdata += l;
p = p->next;
if (!p)
return;
pos = 0LL;
2002-05-01 04:51:32 +08:00
}
2002-05-01 04:53:55 +08:00
s->rptr = p;
2002-05-01 04:51:32 +08:00
}
2005-01-16 06:15:51 +08:00
void saa_fpwrite(struct SAA *s, FILE * fp)
2002-05-01 04:53:55 +08:00
{
char *data;
int32_t len;
2002-05-01 04:51:32 +08:00
2005-01-16 06:15:51 +08:00
saa_rewind(s);
// while ((data = saa_rbytes(s, &len)))
for (; (data = saa_rbytes(s, &len));)
2005-01-16 06:15:51 +08:00
fwrite(data, 1, len, fp);
2002-05-01 04:51:32 +08:00
}
2002-05-01 04:52:49 +08:00
/*
* Register, instruction, condition-code and prefix keywords used
* by the scanner.
*/
#include "names.c"
static const char *special_names[] = {
2002-05-01 04:52:49 +08:00
"byte", "dword", "far", "long", "near", "nosplit", "qword",
"short", "strict", "to", "tword", "word"
2002-05-01 04:52:49 +08:00
};
static const char *prefix_names[] = {
2002-05-01 04:52:49 +08:00
"a16", "a32", "lock", "o16", "o32", "rep", "repe", "repne",
"repnz", "repz", "times"
};
/*
* Standard scanner routine used by parser.c and some output
* formats. It keeps a succession of temporary-storage strings in
* stdscan_tempstorage, which can be cleared using stdscan_reset.
*/
static char **stdscan_tempstorage = NULL;
2002-05-01 04:52:49 +08:00
static int stdscan_tempsize = 0, stdscan_templen = 0;
#define STDSCAN_TEMP_DELTA 256
2005-01-16 06:15:51 +08:00
static void stdscan_pop(void)
2002-05-01 04:53:55 +08:00
{
2005-01-16 06:15:51 +08:00
nasm_free(stdscan_tempstorage[--stdscan_templen]);
2002-05-01 04:52:49 +08:00
}
2005-01-16 06:15:51 +08:00
void stdscan_reset(void)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:52:49 +08:00
while (stdscan_templen > 0)
2005-01-16 06:15:51 +08:00
stdscan_pop();
2002-05-01 04:52:49 +08:00
}
2002-05-01 04:53:55 +08:00
/*
* Unimportant cleanup is done to avoid confusing people who are trying
* to debug real memory leaks
*/
2005-01-16 06:15:51 +08:00
void nasmlib_cleanup(void)
2002-05-01 04:53:55 +08:00
{
stdscan_reset();
2005-01-16 06:15:51 +08:00
nasm_free(stdscan_tempstorage);
2002-05-01 04:53:55 +08:00
}
static char *stdscan_copy(char *p, int len)
2002-05-01 04:53:55 +08:00
{
char *text;
2002-05-01 04:52:49 +08:00
2005-01-16 06:15:51 +08:00
text = nasm_malloc(len + 1);
strncpy(text, p, len);
2002-05-01 04:52:49 +08:00
text[len] = '\0';
if (stdscan_templen >= stdscan_tempsize) {
2005-01-16 06:15:51 +08:00
stdscan_tempsize += STDSCAN_TEMP_DELTA;
stdscan_tempstorage = nasm_realloc(stdscan_tempstorage,
stdscan_tempsize *
sizeof(char *));
2002-05-01 04:52:49 +08:00
}
stdscan_tempstorage[stdscan_templen++] = text;
return text;
}
char *stdscan_bufptr = NULL;
2005-01-16 06:15:51 +08:00
int stdscan(void *private_data, struct tokenval *tv)
2002-05-01 04:53:55 +08:00
{
char ourcopy[MAX_KEYWORD + 1], *r, *s;
2002-05-01 04:53:55 +08:00
2005-01-16 06:15:51 +08:00
(void)private_data; /* Don't warn that this parameter is unused */
2002-05-01 04:52:49 +08:00
2005-01-16 06:15:51 +08:00
while (isspace(*stdscan_bufptr))
stdscan_bufptr++;
2002-05-01 04:52:49 +08:00
if (!*stdscan_bufptr)
2005-01-16 06:15:51 +08:00
return tv->t_type = 0;
2002-05-01 04:52:49 +08:00
/* we have a token; either an id, a number or a char */
if (isidstart(*stdscan_bufptr) ||
2005-01-16 06:15:51 +08:00
(*stdscan_bufptr == '$' && isidstart(stdscan_bufptr[1]))) {
/* now we've got an identifier */
int i;
int is_sym = FALSE;
if (*stdscan_bufptr == '$') {
is_sym = TRUE;
stdscan_bufptr++;
}
r = stdscan_bufptr++;
/* read the entire buffer to advance the buffer pointer but... */
while (isidchar(*stdscan_bufptr))
stdscan_bufptr++;
/* ... copy only up to IDLEN_MAX-1 characters */
tv->t_charptr = stdscan_copy(r, stdscan_bufptr - r < IDLEN_MAX ?
stdscan_bufptr - r : IDLEN_MAX - 1);
if (is_sym || stdscan_bufptr - r > MAX_KEYWORD)
return tv->t_type = TOKEN_ID; /* bypass all other checks */
for (s = tv->t_charptr, r = ourcopy; *s; s++)
*r++ = tolower(*s);
*r = '\0';
/* right, so we have an identifier sitting in temp storage. now,
* is it actually a register or instruction name, or what? */
if ((tv->t_integer = bsi(ourcopy, reg_names,
elements(reg_names))) >= 0) {
tv->t_integer += EXPR_REG_START;
return tv->t_type = TOKEN_REG;
} else if ((tv->t_integer = bsi(ourcopy, insn_names,
elements(insn_names))) >= 0) {
return tv->t_type = TOKEN_INSN;
}
for (i = 0; i < elements(icn); i++)
if (!strncmp(ourcopy, icn[i], strlen(icn[i]))) {
char *p = ourcopy + strlen(icn[i]);
2005-01-16 06:15:51 +08:00
tv->t_integer = ico[i];
if ((tv->t_inttwo = bsi(p, conditions,
elements(conditions))) >= 0)
return tv->t_type = TOKEN_INSN;
}
if ((tv->t_integer = bsi(ourcopy, prefix_names,
elements(prefix_names))) >= 0) {
tv->t_integer += PREFIX_ENUM_START;
return tv->t_type = TOKEN_PREFIX;
}
if ((tv->t_integer = bsi(ourcopy, special_names,
elements(special_names))) >= 0)
return tv->t_type = TOKEN_SPECIAL;
if (!nasm_stricmp(ourcopy, "seg"))
return tv->t_type = TOKEN_SEG;
if (!nasm_stricmp(ourcopy, "wrt"))
return tv->t_type = TOKEN_WRT;
return tv->t_type = TOKEN_ID;
2002-05-01 04:52:49 +08:00
} else if (*stdscan_bufptr == '$' && !isnumchar(stdscan_bufptr[1])) {
2005-01-16 06:15:51 +08:00
/*
* It's a $ sign with no following hex number; this must
* mean it's a Here token ($), evaluating to the current
* assembly location, or a Base token ($$), evaluating to
* the base of the current segment.
*/
stdscan_bufptr++;
if (*stdscan_bufptr == '$') {
stdscan_bufptr++;
return tv->t_type = TOKEN_BASE;
}
return tv->t_type = TOKEN_HERE;
} else if (isnumstart(*stdscan_bufptr)) { /* now we've got a number */
int rn_error;
r = stdscan_bufptr++;
while (isnumchar(*stdscan_bufptr))
stdscan_bufptr++;
if (*stdscan_bufptr == '.') {
/*
* a floating point constant
*/
stdscan_bufptr++;
while (isnumchar(*stdscan_bufptr) ||
((stdscan_bufptr[-1] == 'e'
|| stdscan_bufptr[-1] == 'E')
&& (*stdscan_bufptr == '-' || *stdscan_bufptr == '+'))) {
stdscan_bufptr++;
}
tv->t_charptr = stdscan_copy(r, stdscan_bufptr - r);
return tv->t_type = TOKEN_FLOAT;
}
r = stdscan_copy(r, stdscan_bufptr - r);
tv->t_integer = readnum(r, &rn_error);
stdscan_pop();
if (rn_error)
return tv->t_type = TOKEN_ERRNUM; /* some malformation occurred */
tv->t_charptr = NULL;
return tv->t_type = TOKEN_NUM;
} else if (*stdscan_bufptr == '\'' || *stdscan_bufptr == '"') { /* a char constant */
char quote = *stdscan_bufptr++, *r;
2005-01-16 06:15:51 +08:00
int rn_warn;
r = tv->t_charptr = stdscan_bufptr;
while (*stdscan_bufptr && *stdscan_bufptr != quote)
stdscan_bufptr++;
tv->t_inttwo = stdscan_bufptr - r; /* store full version */
if (!*stdscan_bufptr)
return tv->t_type = TOKEN_ERRNUM; /* unmatched quotes */
stdscan_bufptr++; /* skip over final quote */
tv->t_integer = readstrnum(r, tv->t_inttwo, &rn_warn);
/* FIXME: rn_warn is not checked! */
return tv->t_type = TOKEN_NUM;
} else if (*stdscan_bufptr == ';') { /* a comment has happened - stay */
return tv->t_type = 0;
2002-05-01 04:52:49 +08:00
} else if (stdscan_bufptr[0] == '>' && stdscan_bufptr[1] == '>') {
2005-01-16 06:15:51 +08:00
stdscan_bufptr += 2;
return tv->t_type = TOKEN_SHR;
2002-05-01 04:52:49 +08:00
} else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '<') {
2005-01-16 06:15:51 +08:00
stdscan_bufptr += 2;
return tv->t_type = TOKEN_SHL;
2002-05-01 04:52:49 +08:00
} else if (stdscan_bufptr[0] == '/' && stdscan_bufptr[1] == '/') {
2005-01-16 06:15:51 +08:00
stdscan_bufptr += 2;
return tv->t_type = TOKEN_SDIV;
2002-05-01 04:52:49 +08:00
} else if (stdscan_bufptr[0] == '%' && stdscan_bufptr[1] == '%') {
2005-01-16 06:15:51 +08:00
stdscan_bufptr += 2;
return tv->t_type = TOKEN_SMOD;
2002-05-01 04:52:49 +08:00
} else if (stdscan_bufptr[0] == '=' && stdscan_bufptr[1] == '=') {
2005-01-16 06:15:51 +08:00
stdscan_bufptr += 2;
return tv->t_type = TOKEN_EQ;
2002-05-01 04:52:49 +08:00
} else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '>') {
2005-01-16 06:15:51 +08:00
stdscan_bufptr += 2;
return tv->t_type = TOKEN_NE;
2002-05-01 04:52:49 +08:00
} else if (stdscan_bufptr[0] == '!' && stdscan_bufptr[1] == '=') {
2005-01-16 06:15:51 +08:00
stdscan_bufptr += 2;
return tv->t_type = TOKEN_NE;
2002-05-01 04:52:49 +08:00
} else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '=') {
2005-01-16 06:15:51 +08:00
stdscan_bufptr += 2;
return tv->t_type = TOKEN_LE;
2002-05-01 04:52:49 +08:00
} else if (stdscan_bufptr[0] == '>' && stdscan_bufptr[1] == '=') {
2005-01-16 06:15:51 +08:00
stdscan_bufptr += 2;
return tv->t_type = TOKEN_GE;
2002-05-01 04:52:49 +08:00
} else if (stdscan_bufptr[0] == '&' && stdscan_bufptr[1] == '&') {
2005-01-16 06:15:51 +08:00
stdscan_bufptr += 2;
return tv->t_type = TOKEN_DBL_AND;
2002-05-01 04:52:49 +08:00
} else if (stdscan_bufptr[0] == '^' && stdscan_bufptr[1] == '^') {
2005-01-16 06:15:51 +08:00
stdscan_bufptr += 2;
return tv->t_type = TOKEN_DBL_XOR;
2002-05-01 04:52:49 +08:00
} else if (stdscan_bufptr[0] == '|' && stdscan_bufptr[1] == '|') {
2005-01-16 06:15:51 +08:00
stdscan_bufptr += 2;
return tv->t_type = TOKEN_DBL_OR;
} else /* just an ordinary char */
return tv->t_type = (uint8_t)(*stdscan_bufptr++);
2002-05-01 04:52:49 +08:00
}
/*
* Return TRUE if the argument is a simple scalar. (Or a far-
* absolute, which counts.)
*/
2005-01-16 06:15:51 +08:00
int is_simple(expr * vect)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:52:49 +08:00
while (vect->type && !vect->value)
2005-01-16 06:15:51 +08:00
vect++;
2002-05-01 04:52:49 +08:00
if (!vect->type)
2005-01-16 06:15:51 +08:00
return 1;
2002-05-01 04:52:49 +08:00
if (vect->type != EXPR_SIMPLE)
2005-01-16 06:15:51 +08:00
return 0;
2002-05-01 04:52:49 +08:00
do {
2005-01-16 06:15:51 +08:00
vect++;
2002-05-01 04:52:49 +08:00
} while (vect->type && !vect->value);
2005-01-16 06:15:51 +08:00
if (vect->type && vect->type < EXPR_SEGBASE + SEG_ABS)
return 0;
2002-05-01 04:52:49 +08:00
return 1;
}
/*
* Return TRUE if the argument is a simple scalar, _NOT_ a far-
* absolute.
*/
2005-01-16 06:15:51 +08:00
int is_really_simple(expr * vect)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:52:49 +08:00
while (vect->type && !vect->value)
2005-01-16 06:15:51 +08:00
vect++;
2002-05-01 04:52:49 +08:00
if (!vect->type)
2005-01-16 06:15:51 +08:00
return 1;
2002-05-01 04:52:49 +08:00
if (vect->type != EXPR_SIMPLE)
2005-01-16 06:15:51 +08:00
return 0;
2002-05-01 04:52:49 +08:00
do {
2005-01-16 06:15:51 +08:00
vect++;
2002-05-01 04:52:49 +08:00
} while (vect->type && !vect->value);
2005-01-16 06:15:51 +08:00
if (vect->type)
return 0;
2002-05-01 04:52:49 +08:00
return 1;
}
/*
* Return TRUE if the argument is relocatable (i.e. a simple
* scalar, plus at most one segment-base, plus possibly a WRT).
*/
2005-01-16 06:15:51 +08:00
int is_reloc(expr * vect)
2002-05-01 04:53:55 +08:00
{
2005-01-16 06:15:51 +08:00
while (vect->type && !vect->value) /* skip initial value-0 terms */
vect++;
if (!vect->type) /* trivially return TRUE if nothing */
return 1; /* is present apart from value-0s */
if (vect->type < EXPR_SIMPLE) /* FALSE if a register is present */
return 0;
if (vect->type == EXPR_SIMPLE) { /* skip over a pure number term... */
do {
vect++;
} while (vect->type && !vect->value);
if (!vect->type) /* ...returning TRUE if that's all */
return 1;
2002-05-01 04:52:49 +08:00
}
2005-01-16 06:15:51 +08:00
if (vect->type == EXPR_WRT) { /* skip over a WRT term... */
do {
vect++;
} while (vect->type && !vect->value);
if (!vect->type) /* ...returning TRUE if that's all */
return 1;
2002-05-01 04:53:16 +08:00
}
if (vect->value != 0 && vect->value != 1)
2005-01-16 06:15:51 +08:00
return 0; /* segment base multiplier non-unity */
do { /* skip over _one_ seg-base term... */
vect++;
2002-05-01 04:53:16 +08:00
} while (vect->type && !vect->value);
2005-01-16 06:15:51 +08:00
if (!vect->type) /* ...returning TRUE if that's all */
return 1;
return 0; /* And return FALSE if there's more */
2002-05-01 04:52:49 +08:00
}
/*
* Return TRUE if the argument contains an `unknown' part.
*/
2005-01-16 06:15:51 +08:00
int is_unknown(expr * vect)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:52:49 +08:00
while (vect->type && vect->type < EXPR_UNKNOWN)
2005-01-16 06:15:51 +08:00
vect++;
2002-05-01 04:52:49 +08:00
return (vect->type == EXPR_UNKNOWN);
}
/*
* Return TRUE if the argument contains nothing but an `unknown'
* part.
*/
2005-01-16 06:15:51 +08:00
int is_just_unknown(expr * vect)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:52:49 +08:00
while (vect->type && !vect->value)
2005-01-16 06:15:51 +08:00
vect++;
2002-05-01 04:52:49 +08:00
return (vect->type == EXPR_UNKNOWN);
}
/*
* Return the scalar part of a relocatable vector. (Including
* simple scalar vectors - those qualify as relocatable.)
*/
int64_t reloc_value(expr * vect)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:52:49 +08:00
while (vect->type && !vect->value)
2005-01-16 06:15:51 +08:00
vect++;
if (!vect->type)
return 0;
2002-05-01 04:52:49 +08:00
if (vect->type == EXPR_SIMPLE)
2005-01-16 06:15:51 +08:00
return vect->value;
2002-05-01 04:52:49 +08:00
else
2005-01-16 06:15:51 +08:00
return 0;
2002-05-01 04:52:49 +08:00
}
/*
* Return the segment number of a relocatable vector, or NO_SEG for
* simple scalars.
*/
int32_t reloc_seg(expr * vect)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:52:49 +08:00
while (vect->type && (vect->type == EXPR_WRT || !vect->value))
2005-01-16 06:15:51 +08:00
vect++;
2002-05-01 04:52:49 +08:00
if (vect->type == EXPR_SIMPLE) {
2005-01-16 06:15:51 +08:00
do {
vect++;
} while (vect->type && (vect->type == EXPR_WRT || !vect->value));
2002-05-01 04:52:49 +08:00
}
if (!vect->type)
2005-01-16 06:15:51 +08:00
return NO_SEG;
2002-05-01 04:52:49 +08:00
else
2005-01-16 06:15:51 +08:00
return vect->type - EXPR_SEGBASE;
2002-05-01 04:52:49 +08:00
}
/*
* Return the WRT segment number of a relocatable vector, or NO_SEG
* if no WRT part is present.
*/
int32_t reloc_wrt(expr * vect)
2002-05-01 04:53:55 +08:00
{
2002-05-01 04:52:49 +08:00
while (vect->type && vect->type < EXPR_WRT)
2005-01-16 06:15:51 +08:00
vect++;
2002-05-01 04:52:49 +08:00
if (vect->type == EXPR_WRT) {
2005-01-16 06:15:51 +08:00
return vect->value;
2002-05-01 04:52:49 +08:00
} else
2005-01-16 06:15:51 +08:00
return NO_SEG;
2002-05-01 04:52:49 +08:00
}
/*
* Binary search.
*/
int bsi(char *string, const char **array, int size)
2002-05-01 04:53:55 +08:00
{
2005-01-16 06:15:51 +08:00
int i = -1, j = size; /* always, i < index < j */
while (j - i >= 2) {
int k = (i + j) / 2;
int l = strcmp(string, array[k]);
if (l < 0) /* it's in the first half */
j = k;
else if (l > 0) /* it's in the second half */
i = k;
else /* we've got it :) */
return k;
2002-05-01 04:52:49 +08:00
}
2005-01-16 06:15:51 +08:00
return -1; /* we haven't got it :( */
2002-05-01 04:52:49 +08:00
}
2002-05-01 04:53:55 +08:00
static char *file_name = NULL;
static int32_t line_number = 0;
2002-05-01 04:53:55 +08:00
char *src_set_fname(char *newname)
2002-05-01 04:53:55 +08:00
{
char *oldname = file_name;
2002-05-01 04:53:55 +08:00
file_name = newname;
return oldname;
}
int32_t src_set_linnum(int32_t newline)
2002-05-01 04:53:55 +08:00
{
int32_t oldline = line_number;
2002-05-01 04:53:55 +08:00
line_number = newline;
return oldline;
}
int32_t src_get_linnum(void)
2002-05-01 04:53:55 +08:00
{
return line_number;
}
int src_get(int32_t *xline, char **xname)
2002-05-01 04:53:55 +08:00
{
2005-01-16 06:15:51 +08:00
if (!file_name || !*xname || strcmp(*xname, file_name)) {
nasm_free(*xname);
*xname = file_name ? nasm_strdup(file_name) : NULL;
*xline = line_number;
return -2;
2002-05-01 04:53:55 +08:00
}
2005-01-16 06:15:51 +08:00
if (*xline != line_number) {
int32_t tmp = line_number - *xline;
2005-01-16 06:15:51 +08:00
*xline = line_number;
return tmp;
2002-05-01 04:53:55 +08:00
}
return 0;
}
void nasm_quote(char **str)
2002-05-01 04:53:55 +08:00
{
2005-01-16 06:15:51 +08:00
int ln = strlen(*str);
char q = (*str)[0];
char *p;
2005-01-16 06:15:51 +08:00
if (ln > 1 && (*str)[ln - 1] == q && (q == '"' || q == '\''))
return;
2002-05-01 04:53:55 +08:00
q = '"';
2005-01-16 06:15:51 +08:00
if (strchr(*str, q))
q = '\'';
p = nasm_malloc(ln + 3);
strcpy(p + 1, *str);
2002-05-01 04:53:55 +08:00
nasm_free(*str);
2005-01-16 06:15:51 +08:00
p[ln + 1] = p[0] = q;
p[ln + 2] = 0;
2002-05-01 04:53:55 +08:00
*str = p;
}
2005-01-16 06:15:51 +08:00
char *nasm_strcat(char *one, char *two)
2002-05-01 04:53:55 +08:00
{
char *rslt;
2005-01-16 06:15:51 +08:00
int l1 = strlen(one);
rslt = nasm_malloc(l1 + strlen(two) + 1);
2002-05-01 04:53:55 +08:00
strcpy(rslt, one);
2005-01-16 06:15:51 +08:00
strcpy(rslt + l1, two);
2002-05-01 04:53:55 +08:00
return rslt;
}
2005-01-16 06:15:51 +08:00
void null_debug_init(struct ofmt *of, void *id, FILE * fp, efunc error)
{
2007-04-14 08:46:25 +08:00
(void)of;
(void)id;
(void)fp;
(void)error;
2005-01-16 06:15:51 +08:00
}
void null_debug_linenum(const char *filename, int32_t linenumber, int32_t segto)
2005-01-16 06:15:51 +08:00
{
2007-04-14 08:46:25 +08:00
(void)filename;
(void)linenumber;
(void)segto;
2005-01-16 06:15:51 +08:00
}
void null_debug_deflabel(char *name, int32_t segment, int32_t offset,
int is_global, char *special)
2005-01-16 06:15:51 +08:00
{
2007-04-14 08:46:25 +08:00
(void)name;
(void)segment;
(void)offset;
(void)is_global;
(void)special;
2005-01-16 06:15:51 +08:00
}
void null_debug_routine(const char *directive, const char *params)
2005-01-16 06:15:51 +08:00
{
2007-04-14 08:46:25 +08:00
(void)directive;
(void)params;
2005-01-16 06:15:51 +08:00
}
void null_debug_typevalue(int32_t type)
2005-01-16 06:15:51 +08:00
{
2007-04-14 08:46:25 +08:00
(void)type;
2005-01-16 06:15:51 +08:00
}
void null_debug_output(int type, void *param)
{
2007-04-14 08:46:25 +08:00
(void)type;
(void)param;
2005-01-16 06:15:51 +08:00
}
void null_debug_cleanup(void)
{
}
2002-05-15 06:38:55 +08:00
2002-05-01 04:53:55 +08:00
struct dfmt null_debug_form = {
"Null debug format",
"null",
null_debug_init,
null_debug_linenum,
null_debug_deflabel,
2002-05-01 04:53:55 +08:00
null_debug_routine,
null_debug_typevalue,
null_debug_output,
null_debug_cleanup
2002-05-01 04:53:55 +08:00
};
struct dfmt *null_debug_arr[2] = { &null_debug_form, NULL };