]>
Commit | Line | Data |
---|---|---|
14c7c974 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
4f6e3300 A |
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 | |
12 | * this file. | |
14c7c974 A |
13 | * |
14 | * The Original Code and all software distributed under the License are | |
4f6e3300 | 15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
14c7c974 A |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
4f6e3300 A |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the |
19 | * License for the specific language governing rights and limitations | |
20 | * under the License. | |
14c7c974 A |
21 | * |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | /* nasmlib.c header file for nasmlib.h | |
25 | * | |
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. | |
30 | */ | |
31 | ||
32 | #ifndef NASM_NASMLIB_H | |
33 | #define NASM_NASMLIB_H | |
34 | ||
35 | /* | |
36 | * If this is defined, the wrappers around malloc et al will | |
37 | * transform into logging variants, which will cause NASM to create | |
38 | * a file called `malloc.log' when run, and spew details of all its | |
39 | * memory management into that. That can then be analysed to detect | |
40 | * memory leaks and potentially other problems too. | |
41 | */ | |
42 | /* #define LOGALLOC */ | |
43 | ||
44 | /* | |
45 | * Wrappers around malloc, realloc and free. nasm_malloc will | |
46 | * fatal-error and die rather than return NULL; nasm_realloc will | |
47 | * do likewise, and will also guarantee to work right on being | |
48 | * passed a NULL pointer; nasm_free will do nothing if it is passed | |
49 | * a NULL pointer. | |
50 | */ | |
51 | #ifdef NASM_NASM_H /* need efunc defined for this */ | |
52 | void nasm_set_malloc_error (efunc); | |
53 | #ifndef LOGALLOC | |
54 | void *nasm_malloc (size_t); | |
55 | void *nasm_realloc (void *, size_t); | |
56 | void nasm_free (void *); | |
57 | char *nasm_strdup (char *); | |
58 | char *nasm_strndup (char *, size_t); | |
59 | #else | |
60 | void *nasm_malloc_log (char *, int, size_t); | |
61 | void *nasm_realloc_log (char *, int, void *, size_t); | |
62 | void nasm_free_log (char *, int, void *); | |
63 | char *nasm_strdup_log (char *, int, char *); | |
64 | char *nasm_strndup_log (char *, int, char *, size_t); | |
65 | #define nasm_malloc(x) nasm_malloc_log(__FILE__,__LINE__,x) | |
66 | #define nasm_realloc(x,y) nasm_realloc_log(__FILE__,__LINE__,x,y) | |
67 | #define nasm_free(x) nasm_free_log(__FILE__,__LINE__,x) | |
68 | #define nasm_strdup(x) nasm_strdup_log(__FILE__,__LINE__,x) | |
69 | #define nasm_strndup(x,y) nasm_strndup_log(__FILE__,__LINE__,x,y) | |
70 | #endif | |
71 | #endif | |
72 | ||
73 | /* | |
74 | * ANSI doesn't guarantee the presence of `stricmp' or | |
75 | * `strcasecmp'. | |
76 | */ | |
77 | int nasm_stricmp (char *, char *); | |
78 | int nasm_strnicmp (char *, char *, int); | |
79 | ||
80 | /* | |
81 | * Convert a string into a number, using NASM number rules. Sets | |
82 | * `*error' to TRUE if an error occurs, and FALSE otherwise. | |
83 | */ | |
84 | long readnum(char *str, int *error); | |
85 | ||
86 | /* | |
87 | * seg_init: Initialise the segment-number allocator. | |
88 | * seg_alloc: allocate a hitherto unused segment number. | |
89 | */ | |
90 | void seg_init(void); | |
91 | long seg_alloc(void); | |
92 | ||
93 | /* | |
94 | * many output formats will be able to make use of this: a standard | |
95 | * function to add an extension to the name of the input file | |
96 | */ | |
97 | #ifdef NASM_NASM_H | |
98 | void standard_extension (char *inname, char *outname, char *extension, | |
99 | efunc error); | |
100 | #endif | |
101 | ||
102 | /* | |
103 | * some handy macros that will probably be of use in more than one | |
104 | * output format: convert integers into little-endian byte packed | |
105 | * format in memory | |
106 | */ | |
107 | ||
108 | #define WRITELONG(p,v) \ | |
109 | do { \ | |
110 | *(p)++ = (v) & 0xFF; \ | |
111 | *(p)++ = ((v) >> 8) & 0xFF; \ | |
112 | *(p)++ = ((v) >> 16) & 0xFF; \ | |
113 | *(p)++ = ((v) >> 24) & 0xFF; \ | |
114 | } while (0) | |
115 | ||
116 | #define WRITESHORT(p,v) \ | |
117 | do { \ | |
118 | *(p)++ = (v) & 0xFF; \ | |
119 | *(p)++ = ((v) >> 8) & 0xFF; \ | |
120 | } while (0) | |
121 | ||
122 | /* | |
123 | * and routines to do the same thing to a file | |
124 | */ | |
125 | void fwriteshort (int data, FILE *fp); | |
126 | void fwritelong (long data, FILE *fp); | |
127 | ||
128 | /* | |
129 | * Routines to manage a dynamic random access array of longs which | |
130 | * may grow in size to be more than the largest single malloc'able | |
131 | * chunk. | |
132 | */ | |
133 | ||
134 | struct RAA; | |
135 | ||
136 | struct RAA *raa_init (void); | |
137 | void raa_free (struct RAA *); | |
138 | long raa_read (struct RAA *, long); | |
139 | struct RAA *raa_write (struct RAA *r, long posn, long value); | |
140 | ||
141 | /* | |
142 | * Routines to manage a dynamic sequential-access array, under the | |
143 | * same restriction on maximum mallocable block. This array may be | |
144 | * written to in two ways: a contiguous chunk can be reserved of a | |
145 | * given size, and a pointer returned, or single-byte data may be | |
146 | * written. The array can also be read back in the same two ways: | |
147 | * as a series of big byte-data blocks or as a list of structures | |
148 | * of a given size. | |
149 | */ | |
150 | ||
151 | struct SAA; | |
152 | ||
153 | struct SAA *saa_init (long elem_len); /* 1 == byte */ | |
154 | void saa_free (struct SAA *); | |
155 | void *saa_wstruct (struct SAA *); /* return a structure of elem_len */ | |
156 | void saa_wbytes (struct SAA *, void *, long); /* write arbitrary bytes */ | |
157 | void saa_rewind (struct SAA *); /* for reading from beginning */ | |
158 | void *saa_rstruct (struct SAA *); /* return NULL on EOA */ | |
159 | void *saa_rbytes (struct SAA *, long *); /* return 0 on EOA */ | |
160 | void saa_rnbytes (struct SAA *, void *, long); /* read a given no. of bytes */ | |
161 | void saa_fread (struct SAA *s, long posn, void *p, long len); /* fixup */ | |
162 | void saa_fwrite (struct SAA *s, long posn, void *p, long len); /* fixup */ | |
163 | void saa_fpwrite (struct SAA *, FILE *); | |
164 | ||
165 | #ifdef NASM_NASM_H | |
166 | /* | |
167 | * Standard scanner. | |
168 | */ | |
169 | extern char *stdscan_bufptr; | |
170 | void stdscan_reset(void); | |
171 | int stdscan (void *private_data, struct tokenval *tv); | |
172 | #endif | |
173 | ||
174 | #ifdef NASM_NASM_H | |
175 | /* | |
176 | * Library routines to manipulate expression data types. | |
177 | */ | |
178 | int is_reloc(expr *); | |
179 | int is_simple(expr *); | |
180 | int is_really_simple (expr *); | |
181 | int is_unknown(expr *); | |
182 | int is_just_unknown(expr *); | |
183 | long reloc_value(expr *); | |
184 | long reloc_seg(expr *); | |
185 | long reloc_wrt(expr *); | |
186 | #endif | |
187 | ||
188 | /* | |
189 | * Binary search routine. Returns index into `array' of an entry | |
190 | * matching `string', or <0 if no match. `array' is taken to | |
191 | * contain `size' elements. | |
192 | */ | |
193 | int bsi (char *string, char **array, int size); | |
194 | ||
195 | #endif |