2 * Small utility functions for winebuild
4 * Copyright 2000 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 void *xmalloc (size_t size)
35 res = malloc (size ? size : 1);
38 fprintf (stderr, "Virtual memory exhausted.\n");
44 void *xrealloc (void *ptr, size_t size)
46 void *res = realloc (ptr, size);
49 fprintf (stderr, "Virtual memory exhausted.\n");
55 char *xstrdup( const char *str )
57 char *res = strdup( str );
60 fprintf (stderr, "Virtual memory exhausted.\n");
66 char *strupper(char *s)
69 for (p = s; *p; p++) *p = toupper(*p);
73 void fatal_error( const char *msg, ... )
76 va_start( valist, msg );
79 fprintf( stderr, "%s:", input_file_name );
81 fprintf( stderr, "%d:", current_line );
84 vfprintf( stderr, msg, valist );
89 void fatal_perror( const char *msg, ... )
92 va_start( valist, msg );
95 fprintf( stderr, "%s:", input_file_name );
97 fprintf( stderr, "%d:", current_line );
100 vfprintf( stderr, msg, valist );
106 void warning( const char *msg, ... )
110 if (!display_warnings) return;
111 va_start( valist, msg );
114 fprintf( stderr, "%s:", input_file_name );
116 fprintf( stderr, "%d:", current_line );
117 fputc( ' ', stderr );
119 fprintf( stderr, "warning: " );
120 vfprintf( stderr, msg, valist );
124 /* output a standard header for generated files */
125 void output_standard_file_header( FILE *outfile )
127 fprintf( outfile, "/* File generated automatically from %s; do not edit! */\n",
130 "/* This file can be copied, modified and distributed without restriction. */\n\n" );
133 /* dump a byte stream into the assembly code */
134 void dump_bytes( FILE *outfile, const unsigned char *data, int len,
135 const char *label, int constant )
139 fprintf( outfile, "\nstatic %sunsigned char %s[%d] = {",
140 constant ? "const " : "", label, len );
141 for (i = 0; i < len; i++)
143 if (!(i & 7)) fprintf( outfile, "\n " );
144 fprintf( outfile, "0x%02x", *data++ );
145 if (i < len - 1) fprintf( outfile, "," );
147 fprintf( outfile, "\n};\n" );
150 /*****************************************************************
151 * Function: get_alignment
154 * According to the info page for gas, the .align directive behaves
155 * differently on different systems. On some architectures, the
156 * argument of a .align directive is the number of bytes to pad to, so
157 * to align on an 8-byte boundary you'd say
159 * On other systems, the argument is "the number of low-order zero bits
160 * that the location counter must have after advancement." So to
161 * align on an 8-byte boundary you'd say
164 * The reason gas is written this way is that it's trying to mimick
165 * native assemblers for the various architectures it runs on. gas
166 * provides other directives that work consistantly across
167 * architectures, but of course we want to work on all arches with or
168 * without gas. Hence this function.
172 * alignBoundary -- the number of bytes to align to.
173 * If we're on an architecture where
174 * the assembler requires a 'number
175 * of low-order zero bits' as a
176 * .align argument, then this number
177 * must be a power of 2.
180 int get_alignment(int alignBoundary)
186 switch(alignBoundary)
237 fatal_error("Alignment to %d-byte boundary not supported on this architecture.\n",
242 #elif defined(__i386__) || defined(__sparc__)
244 return alignBoundary;
247 #error "How does the '.align' assembler directive work on your architecture?"