]>
git.saurik.com Git - apple/boot.git/blob - i386/nasm/nasmlib.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
24 /* nasmlib.c library routines for the Netwide Assembler
26 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
27 * Julian Hall. All rights reserved. The software is
28 * redistributable under the licence given in the file "Licence"
29 * distributed in the NASM archive.
40 static efunc nasm_malloc_error
;
46 void nasm_set_malloc_error (efunc error
) {
47 nasm_malloc_error
= error
;
49 logfp
= fopen ("malloc.log", "w");
50 setvbuf (logfp
, NULL
, _IOLBF
, BUFSIZ
);
51 fprintf (logfp
, "null pointer is %p\n", NULL
);
56 void *nasm_malloc_log (char *file
, int line
, size_t size
)
58 void *nasm_malloc (size_t size
)
61 void *p
= malloc(size
);
63 nasm_malloc_error (ERR_FATAL
| ERR_NOFILE
, "out of memory");
66 fprintf(logfp
, "%s %d malloc(%ld) returns %p\n",
67 file
, line
, (long)size
, p
);
73 void *nasm_realloc_log (char *file
, int line
, void *q
, size_t size
)
75 void *nasm_realloc (void *q
, size_t size
)
78 void *p
= q
? realloc(q
, size
) : malloc(size
);
80 nasm_malloc_error (ERR_FATAL
| ERR_NOFILE
, "out of memory");
83 fprintf(logfp
, "%s %d realloc(%p,%ld) returns %p\n",
84 file
, line
, q
, (long)size
, p
);
86 fprintf(logfp
, "%s %d malloc(%ld) returns %p\n",
87 file
, line
, (long)size
, p
);
93 void nasm_free_log (char *file
, int line
, void *q
)
95 void nasm_free (void *q
)
101 fprintf(logfp
, "%s %d free(%p)\n",
108 char *nasm_strdup_log (char *file
, int line
, char *s
)
110 char *nasm_strdup (char *s
)
114 int size
= strlen(s
)+1;
118 nasm_malloc_error (ERR_FATAL
| ERR_NOFILE
, "out of memory");
121 fprintf(logfp
, "%s %d strdup(%ld) returns %p\n",
122 file
, line
, (long)size
, p
);
129 char *nasm_strndup_log (char *file
, int line
, char *s
, size_t len
)
131 char *nasm_strndup (char *s
, size_t len
)
139 nasm_malloc_error (ERR_FATAL
| ERR_NOFILE
, "out of memory");
142 fprintf(logfp
, "%s %d strndup(%ld) returns %p\n",
143 file
, line
, (long)size
, p
);
150 int nasm_stricmp (char *s1
, char *s2
) {
151 while (*s1
&& toupper(*s1
) == toupper(*s2
))
155 else if (toupper(*s1
) < toupper(*s2
))
161 int nasm_strnicmp (char *s1
, char *s2
, int n
) {
162 while (n
> 0 && *s1
&& toupper(*s1
) == toupper(*s2
))
164 if ((!*s1
&& !*s2
) || n
==0)
166 else if (toupper(*s1
) < toupper(*s2
))
172 #define lib_isnumchar(c) ( isalnum(c) || (c) == '$')
173 #define numvalue(c) ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0')
175 long readnum (char *str
, int *error
) {
178 unsigned long result
, checklimit
;
183 while (isspace(*r
)) r
++; /* find start of number */
186 while (lib_isnumchar(*q
)) q
++; /* find end of number */
189 * If it begins 0x, 0X or $, or ends in H, it's in hex. if it
190 * ends in Q, it's octal. if it ends in B, it's binary.
191 * Otherwise, it's ordinary decimal.
193 if (*r
=='0' && (r
[1]=='x' || r
[1]=='X'))
197 else if (q
[-1]=='H' || q
[-1]=='h')
199 else if (q
[-1]=='Q' || q
[-1]=='q')
201 else if (q
[-1]=='B' || q
[-1]=='b')
207 * If this number has been found for us by something other than
208 * the ordinary scanners, then it might be malformed by having
209 * nothing between the prefix and the suffix. Check this case
218 * `checklimit' must be 2**32 / radix. We can't do that in
219 * 32-bit arithmetic, which we're (probably) using, so we
220 * cheat: since we know that all radices we use are even, we
221 * can divide 2**31 by radix/2 instead.
223 checklimit
= 0x80000000UL
/ (radix
>>1);
226 while (*r
&& r
< q
) {
227 if (*r
<'0' || (*r
>'9' && *r
<'A') || numvalue(*r
)>=radix
) {
231 if (result
>= checklimit
)
233 result
= radix
* result
+ numvalue(*r
);
238 nasm_malloc_error (ERR_WARNING
| ERR_PASS1
| ERR_WARN_NOV
,
239 "numeric constant %s does not fit in 32 bits",
245 static long next_seg
;
247 void seg_init(void) {
251 long seg_alloc(void) {
252 return (next_seg
+= 2) - 2;
255 void fwriteshort (int data
, FILE *fp
) {
256 fputc ((int) (data
& 255), fp
);
257 fputc ((int) ((data
>> 8) & 255), fp
);
260 void fwritelong (long data
, FILE *fp
) {
261 fputc ((int) (data
& 255), fp
);
262 fputc ((int) ((data
>> 8) & 255), fp
);
263 fputc ((int) ((data
>> 16) & 255), fp
);
264 fputc ((int) ((data
>> 24) & 255), fp
);
267 void standard_extension (char *inname
, char *outname
, char *extension
,
271 if (*outname
) /* file name already exists, */
272 return; /* so do nothing */
275 while (*q
) *p
++ = *q
++; /* copy, and find end of string */
276 *p
= '\0'; /* terminate it */
277 while (p
> outname
&& *--p
!= '.');/* find final period (or whatever) */
278 if (*p
!= '.') while (*p
) p
++; /* go back to end if none found */
279 if (!strcmp(p
, extension
)) { /* is the extension already there? */
281 error(ERR_WARNING
| ERR_NOFILE
,
282 "file name already ends in `%s': "
283 "output will be in `nasm.out'",
286 error(ERR_WARNING
| ERR_NOFILE
,
287 "file name already has no extension: "
288 "output will be in `nasm.out'");
289 strcpy(outname
, "nasm.out");
291 strcpy(p
, extension
);
294 #define RAA_BLKSIZE 4096 /* this many longs allocated at once */
295 #define RAA_LAYERSIZE 1024 /* this many _pointers_ allocated */
297 typedef struct RAA RAA
;
298 typedef union RAA_UNION RAA_UNION
;
299 typedef struct RAA_LEAF RAA_LEAF
;
300 typedef struct RAA_BRANCH RAA_BRANCH
;
304 * Number of layers below this one to get to the real data. 0
305 * means this structure is a leaf, holding RAA_BLKSIZE real
306 * data items; 1 and above mean it's a branch, holding
307 * RAA_LAYERSIZE pointers to the next level branch or leaf
312 * Number of real data items spanned by one position in the
313 * `data' array at this level. This number is 1, trivially, for
314 * a leaf (level 0): for a level 1 branch it should be
315 * RAA_BLKSIZE, and for a level 2 branch it's
316 * RAA_LAYERSIZE*RAA_BLKSIZE.
321 long data
[RAA_BLKSIZE
];
324 struct RAA
*data
[RAA_LAYERSIZE
];
329 #define LEAFSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_LEAF))
330 #define BRANCHSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_BRANCH))
332 #define LAYERSIZ(r) ( (r)->layers==0 ? RAA_BLKSIZE : RAA_LAYERSIZE )
334 static struct RAA
*real_raa_init (int layers
) {
338 r
= nasm_malloc (LEAFSIZ
);
339 memset (r
->u
.l
.data
, 0, sizeof(r
->u
.l
.data
));
343 r
= nasm_malloc (BRANCHSIZ
);
344 memset (r
->u
.b
.data
, 0, sizeof(r
->u
.b
.data
));
346 r
->stepsize
= RAA_BLKSIZE
;
348 r
->stepsize
*= RAA_LAYERSIZE
;
353 struct RAA
*raa_init (void) {
354 return real_raa_init (0);
357 void raa_free (struct RAA
*r
) {
362 for (p
= r
->u
.b
.data
; p
- r
->u
.b
.data
< RAA_LAYERSIZE
; p
++)
368 long raa_read (struct RAA
*r
, long posn
) {
369 if (posn
> r
->stepsize
* LAYERSIZ(r
))
371 while (r
->layers
> 0) {
373 l
= ldiv (posn
, r
->stepsize
);
374 r
= r
->u
.b
.data
[l
.quot
];
376 if (!r
) /* better check this */
379 return r
->u
.l
.data
[posn
];
382 struct RAA
*raa_write (struct RAA
*r
, long posn
, long value
) {
386 nasm_malloc_error (ERR_PANIC
, "negative position in raa_write");
388 while (r
->stepsize
* LAYERSIZ(r
) < posn
) {
390 * Must go up a layer.
394 s
= nasm_malloc (BRANCHSIZ
);
395 memset (s
->u
.b
.data
, 0, sizeof(r
->u
.b
.data
));
396 s
->layers
= r
->layers
+ 1;
397 s
->stepsize
= RAA_LAYERSIZE
* r
->stepsize
;
404 while (r
->layers
> 0) {
407 l
= ldiv (posn
, r
->stepsize
);
408 s
= &r
->u
.b
.data
[l
.quot
];
410 *s
= real_raa_init (r
->layers
- 1);
415 r
->u
.l
.data
[posn
] = value
;
420 #define SAA_MAXLEN 8192
424 * members `end' and `elem_len' are only valid in first link in
425 * list; `rptr' and `rpos' are used for reading
427 struct SAA
*next
, *end
, *rptr
;
428 long elem_len
, length
, posn
, start
, rpos
;
432 struct SAA
*saa_init (long elem_len
) {
435 if (elem_len
> SAA_MAXLEN
)
436 nasm_malloc_error (ERR_PANIC
| ERR_NOFILE
, "SAA with huge elements");
438 s
= nasm_malloc (sizeof(struct SAA
));
439 s
->posn
= s
->start
= 0L;
440 s
->elem_len
= elem_len
;
441 s
->length
= SAA_MAXLEN
- (SAA_MAXLEN
% elem_len
);
442 s
->data
= nasm_malloc (s
->length
);
449 void saa_free (struct SAA
*s
) {
460 void *saa_wstruct (struct SAA
*s
) {
463 if (s
->end
->length
- s
->end
->posn
< s
->elem_len
) {
464 s
->end
->next
= nasm_malloc (sizeof(struct SAA
));
465 s
->end
->next
->start
= s
->end
->start
+ s
->end
->posn
;
466 s
->end
= s
->end
->next
;
467 s
->end
->length
= s
->length
;
470 s
->end
->data
= nasm_malloc (s
->length
);
473 p
= s
->end
->data
+ s
->end
->posn
;
474 s
->end
->posn
+= s
->elem_len
;
478 void saa_wbytes (struct SAA
*s
, void *data
, long len
) {
482 long l
= s
->end
->length
- s
->end
->posn
;
487 memcpy (s
->end
->data
+ s
->end
->posn
, d
, l
);
490 memset (s
->end
->data
+ s
->end
->posn
, 0, l
);
495 s
->end
->next
= nasm_malloc (sizeof(struct SAA
));
496 s
->end
->next
->start
= s
->end
->start
+ s
->end
->posn
;
497 s
->end
= s
->end
->next
;
498 s
->end
->length
= s
->length
;
501 s
->end
->data
= nasm_malloc (s
->length
);
506 void saa_rewind (struct SAA
*s
) {
511 void *saa_rstruct (struct SAA
*s
) {
517 if (s
->rptr
->posn
- s
->rpos
< s
->elem_len
) {
518 s
->rptr
= s
->rptr
->next
;
520 return NULL
; /* end of array */
524 p
= s
->rptr
->data
+ s
->rpos
;
525 s
->rpos
+= s
->elem_len
;
529 void *saa_rbytes (struct SAA
*s
, long *len
) {
535 p
= s
->rptr
->data
+ s
->rpos
;
536 *len
= s
->rptr
->posn
- s
->rpos
;
537 s
->rptr
= s
->rptr
->next
;
542 void saa_rnbytes (struct SAA
*s
, void *data
, long len
) {
551 l
= s
->rptr
->posn
- s
->rpos
;
555 memcpy (d
, s
->rptr
->data
+ s
->rpos
, l
);
561 s
->rptr
= s
->rptr
->next
;
567 void saa_fread (struct SAA
*s
, long posn
, void *data
, long len
) {
572 if (!s
->rptr
|| posn
> s
->rptr
->start
+ s
->rpos
)
574 while (posn
>= s
->rptr
->start
+ s
->rptr
->posn
) {
575 s
->rptr
= s
->rptr
->next
;
577 return; /* what else can we do?! */
581 pos
= posn
- s
->rptr
->start
;
583 long l
= s
->rptr
->posn
- pos
;
586 memcpy (cdata
, s
->rptr
->data
+pos
, l
);
596 void saa_fwrite (struct SAA
*s
, long posn
, void *data
, long len
) {
601 if (!s
->rptr
|| posn
> s
->rptr
->start
+ s
->rpos
)
603 while (posn
>= s
->rptr
->start
+ s
->rptr
->posn
) {
604 s
->rptr
= s
->rptr
->next
;
606 return; /* what else can we do?! */
610 pos
= posn
- s
->rptr
->start
;
612 long l
= s
->rptr
->posn
- pos
;
615 memcpy (s
->rptr
->data
+pos
, cdata
, l
);
625 void saa_fpwrite (struct SAA
*s
, FILE *fp
) {
630 while ( (data
= saa_rbytes (s
, &len
)) )
631 fwrite (data
, 1, len
, fp
);
635 * Register, instruction, condition-code and prefix keywords used
639 static char *special_names
[] = {
640 "byte", "dword", "far", "long", "near", "nosplit", "qword",
641 "short", "to", "tword", "word"
643 static char *prefix_names
[] = {
644 "a16", "a32", "lock", "o16", "o32", "rep", "repe", "repne",
645 "repnz", "repz", "times"
650 * Standard scanner routine used by parser.c and some output
651 * formats. It keeps a succession of temporary-storage strings in
652 * stdscan_tempstorage, which can be cleared using stdscan_reset.
654 static char **stdscan_tempstorage
= NULL
;
655 static int stdscan_tempsize
= 0, stdscan_templen
= 0;
656 #define STDSCAN_TEMP_DELTA 256
658 static void stdscan_pop(void) {
659 nasm_free (stdscan_tempstorage
[--stdscan_templen
]);
662 void stdscan_reset(void) {
663 while (stdscan_templen
> 0)
667 static char *stdscan_copy(char *p
, int len
) {
670 text
= nasm_malloc(len
+1);
671 strncpy (text
, p
, len
);
674 if (stdscan_templen
>= stdscan_tempsize
) {
675 stdscan_tempsize
+= STDSCAN_TEMP_DELTA
;
676 stdscan_tempstorage
= nasm_realloc(stdscan_tempstorage
,
677 stdscan_tempsize
*sizeof(char *));
679 stdscan_tempstorage
[stdscan_templen
++] = text
;
684 char *stdscan_bufptr
= NULL
;
685 int stdscan (void *private_data
, struct tokenval
*tv
) {
686 char ourcopy
[256], *r
, *s
;
688 while (isspace(*stdscan_bufptr
)) stdscan_bufptr
++;
689 if (!*stdscan_bufptr
)
690 return tv
->t_type
= 0;
692 /* we have a token; either an id, a number or a char */
693 if (isidstart(*stdscan_bufptr
) ||
694 (*stdscan_bufptr
== '$' && isidstart(stdscan_bufptr
[1]))) {
695 /* now we've got an identifier */
699 if (*stdscan_bufptr
== '$') {
704 r
= stdscan_bufptr
++;
705 while (isidchar(*stdscan_bufptr
)) stdscan_bufptr
++;
706 tv
->t_charptr
= stdscan_copy(r
, stdscan_bufptr
- r
);
708 for (s
=tv
->t_charptr
, r
=ourcopy
; *s
; s
++)
712 return tv
->t_type
= TOKEN_ID
;/* bypass all other checks */
713 /* right, so we have an identifier sitting in temp storage. now,
714 * is it actually a register or instruction name, or what? */
715 if ((tv
->t_integer
=bsi(ourcopy
, reg_names
,
716 elements(reg_names
)))>=0) {
717 tv
->t_integer
+= EXPR_REG_START
;
718 return tv
->t_type
= TOKEN_REG
;
719 } else if ((tv
->t_integer
=bsi(ourcopy
, insn_names
,
720 elements(insn_names
)))>=0) {
721 return tv
->t_type
= TOKEN_INSN
;
723 for (i
=0; i
<elements(icn
); i
++)
724 if (!strncmp(ourcopy
, icn
[i
], strlen(icn
[i
]))) {
725 char *p
= ourcopy
+ strlen(icn
[i
]);
726 tv
->t_integer
= ico
[i
];
727 if ((tv
->t_inttwo
=bsi(p
, conditions
,
728 elements(conditions
)))>=0)
729 return tv
->t_type
= TOKEN_INSN
;
731 if ((tv
->t_integer
=bsi(ourcopy
, prefix_names
,
732 elements(prefix_names
)))>=0) {
733 tv
->t_integer
+= PREFIX_ENUM_START
;
734 return tv
->t_type
= TOKEN_PREFIX
;
736 if ((tv
->t_integer
=bsi(ourcopy
, special_names
,
737 elements(special_names
)))>=0)
738 return tv
->t_type
= TOKEN_SPECIAL
;
739 if (!strcmp(ourcopy
, "seg"))
740 return tv
->t_type
= TOKEN_SEG
;
741 if (!strcmp(ourcopy
, "wrt"))
742 return tv
->t_type
= TOKEN_WRT
;
743 return tv
->t_type
= TOKEN_ID
;
744 } else if (*stdscan_bufptr
== '$' && !isnumchar(stdscan_bufptr
[1])) {
746 * It's a $ sign with no following hex number; this must
747 * mean it's a Here token ($), evaluating to the current
748 * assembly location, or a Base token ($$), evaluating to
749 * the base of the current segment.
752 if (*stdscan_bufptr
== '$') {
754 return tv
->t_type
= TOKEN_BASE
;
756 return tv
->t_type
= TOKEN_HERE
;
757 } else if (isnumstart(*stdscan_bufptr
)) { /* now we've got a number */
760 r
= stdscan_bufptr
++;
761 while (isnumchar(*stdscan_bufptr
))
764 if (*stdscan_bufptr
== '.') {
766 * a floating point constant
769 while (isnumchar(*stdscan_bufptr
)) {
772 tv
->t_charptr
= stdscan_copy(r
, stdscan_bufptr
- r
);
773 return tv
->t_type
= TOKEN_FLOAT
;
775 r
= stdscan_copy(r
, stdscan_bufptr
- r
);
776 tv
->t_integer
= readnum(r
, &rn_error
);
779 return tv
->t_type
= TOKEN_ERRNUM
;/* some malformation occurred */
780 tv
->t_charptr
= NULL
;
781 return tv
->t_type
= TOKEN_NUM
;
782 } else if (*stdscan_bufptr
== '\'' ||
783 *stdscan_bufptr
== '"') {/* a char constant */
784 char quote
= *stdscan_bufptr
++, *r
;
785 r
= tv
->t_charptr
= stdscan_bufptr
;
786 while (*stdscan_bufptr
&& *stdscan_bufptr
!= quote
) stdscan_bufptr
++;
787 tv
->t_inttwo
= stdscan_bufptr
- r
; /* store full version */
788 if (!*stdscan_bufptr
)
789 return tv
->t_type
= TOKEN_ERRNUM
; /* unmatched quotes */
791 r
= stdscan_bufptr
++; /* skip over final quote */
792 while (quote
!= *--r
) {
793 tv
->t_integer
= (tv
->t_integer
<<8) + (unsigned char) *r
;
795 return tv
->t_type
= TOKEN_NUM
;
796 } else if (*stdscan_bufptr
== ';') { /* a comment has happened - stay */
797 return tv
->t_type
= 0;
798 } else if (stdscan_bufptr
[0] == '>' && stdscan_bufptr
[1] == '>') {
800 return tv
->t_type
= TOKEN_SHR
;
801 } else if (stdscan_bufptr
[0] == '<' && stdscan_bufptr
[1] == '<') {
803 return tv
->t_type
= TOKEN_SHL
;
804 } else if (stdscan_bufptr
[0] == '/' && stdscan_bufptr
[1] == '/') {
806 return tv
->t_type
= TOKEN_SDIV
;
807 } else if (stdscan_bufptr
[0] == '%' && stdscan_bufptr
[1] == '%') {
809 return tv
->t_type
= TOKEN_SMOD
;
810 } else if (stdscan_bufptr
[0] == '=' && stdscan_bufptr
[1] == '=') {
812 return tv
->t_type
= TOKEN_EQ
;
813 } else if (stdscan_bufptr
[0] == '<' && stdscan_bufptr
[1] == '>') {
815 return tv
->t_type
= TOKEN_NE
;
816 } else if (stdscan_bufptr
[0] == '!' && stdscan_bufptr
[1] == '=') {
818 return tv
->t_type
= TOKEN_NE
;
819 } else if (stdscan_bufptr
[0] == '<' && stdscan_bufptr
[1] == '=') {
821 return tv
->t_type
= TOKEN_LE
;
822 } else if (stdscan_bufptr
[0] == '>' && stdscan_bufptr
[1] == '=') {
824 return tv
->t_type
= TOKEN_GE
;
825 } else if (stdscan_bufptr
[0] == '&' && stdscan_bufptr
[1] == '&') {
827 return tv
->t_type
= TOKEN_DBL_AND
;
828 } else if (stdscan_bufptr
[0] == '^' && stdscan_bufptr
[1] == '^') {
830 return tv
->t_type
= TOKEN_DBL_XOR
;
831 } else if (stdscan_bufptr
[0] == '|' && stdscan_bufptr
[1] == '|') {
833 return tv
->t_type
= TOKEN_DBL_OR
;
834 } else /* just an ordinary char */
835 return tv
->t_type
= (unsigned char) (*stdscan_bufptr
++);
839 * Return TRUE if the argument is a simple scalar. (Or a far-
840 * absolute, which counts.)
842 int is_simple (expr
*vect
) {
843 while (vect
->type
&& !vect
->value
)
847 if (vect
->type
!= EXPR_SIMPLE
)
851 } while (vect
->type
&& !vect
->value
);
852 if (vect
->type
&& vect
->type
< EXPR_SEGBASE
+SEG_ABS
) return 0;
857 * Return TRUE if the argument is a simple scalar, _NOT_ a far-
860 int is_really_simple (expr
*vect
) {
861 while (vect
->type
&& !vect
->value
)
865 if (vect
->type
!= EXPR_SIMPLE
)
869 } while (vect
->type
&& !vect
->value
);
870 if (vect
->type
) return 0;
875 * Return TRUE if the argument is relocatable (i.e. a simple
876 * scalar, plus at most one segment-base, plus possibly a WRT).
878 int is_reloc (expr
*vect
) {
879 while (vect
->type
&& !vect
->value
) /* skip initial value-0 terms */
881 if (!vect
->type
) /* trivially return TRUE if nothing */
882 return 1; /* is present apart from value-0s */
883 if (vect
->type
< EXPR_SIMPLE
) /* FALSE if a register is present */
885 if (vect
->type
== EXPR_SIMPLE
) { /* skip over a pure number term... */
888 } while (vect
->type
&& !vect
->value
);
889 if (!vect
->type
) /* ...returning TRUE if that's all */
892 if (vect
->type
== EXPR_WRT
) { /* skip over a WRT term... */
895 } while (vect
->type
&& !vect
->value
);
896 if (!vect
->type
) /* ...returning TRUE if that's all */
899 if (vect
->value
!= 0 && vect
->value
!= 1)
900 return 0; /* segment base multiplier non-unity */
901 do { /* skip over _one_ seg-base term... */
903 } while (vect
->type
&& !vect
->value
);
904 if (!vect
->type
) /* ...returning TRUE if that's all */
906 return 0; /* And return FALSE if there's more */
910 * Return TRUE if the argument contains an `unknown' part.
912 int is_unknown(expr
*vect
) {
913 while (vect
->type
&& vect
->type
< EXPR_UNKNOWN
)
915 return (vect
->type
== EXPR_UNKNOWN
);
919 * Return TRUE if the argument contains nothing but an `unknown'
922 int is_just_unknown(expr
*vect
) {
923 while (vect
->type
&& !vect
->value
)
925 return (vect
->type
== EXPR_UNKNOWN
);
929 * Return the scalar part of a relocatable vector. (Including
930 * simple scalar vectors - those qualify as relocatable.)
932 long reloc_value (expr
*vect
) {
933 while (vect
->type
&& !vect
->value
)
935 if (!vect
->type
) return 0;
936 if (vect
->type
== EXPR_SIMPLE
)
943 * Return the segment number of a relocatable vector, or NO_SEG for
946 long reloc_seg (expr
*vect
) {
947 while (vect
->type
&& (vect
->type
== EXPR_WRT
|| !vect
->value
))
949 if (vect
->type
== EXPR_SIMPLE
) {
952 } while (vect
->type
&& (vect
->type
== EXPR_WRT
|| !vect
->value
));
957 return vect
->type
- EXPR_SEGBASE
;
961 * Return the WRT segment number of a relocatable vector, or NO_SEG
962 * if no WRT part is present.
964 long reloc_wrt (expr
*vect
) {
965 while (vect
->type
&& vect
->type
< EXPR_WRT
)
967 if (vect
->type
== EXPR_WRT
) {
976 int bsi (char *string
, char **array
, int size
) {
977 int i
= -1, j
= size
; /* always, i < index < j */
980 int l
= strcmp(string
, array
[k
]);
981 if (l
<0) /* it's in the first half */
983 else if (l
>0) /* it's in the second half */
985 else /* we've got it :) */
988 return -1; /* we haven't got it :( */