1 /* small utility functions for winebuild */
14 void *xmalloc (size_t size)
18 res = malloc (size ? size : 1);
21 fprintf (stderr, "Virtual memory exhausted.\n");
27 void *xrealloc (void *ptr, size_t size)
29 void *res = realloc (ptr, size);
32 fprintf (stderr, "Virtual memory exhausted.\n");
38 char *xstrdup( const char *str )
40 char *res = strdup( str );
43 fprintf (stderr, "Virtual memory exhausted.\n");
49 char *strupper(char *s)
52 for (p = s; *p; p++) *p = toupper(*p);
56 void fatal_error( const char *msg, ... )
59 va_start( valist, msg );
62 fprintf( stderr, "%s:", input_file_name );
64 fprintf( stderr, "%d:", current_line );
67 vfprintf( stderr, msg, valist );
72 void fatal_perror( const char *msg, ... )
75 va_start( valist, msg );
78 fprintf( stderr, "%s:", input_file_name );
80 fprintf( stderr, "%d:", current_line );
83 vfprintf( stderr, msg, valist );
89 void warning( const char *msg, ... )
92 va_start( valist, msg );
95 fprintf( stderr, "%s:", input_file_name );
97 fprintf( stderr, "%d:", current_line );
100 fprintf( stderr, "warning: " );
101 vfprintf( stderr, msg, valist );
105 /* dump a byte stream into the assembly code */
106 void dump_bytes( FILE *outfile, const unsigned char *data, int len,
107 const char *label, int constant )
111 fprintf( outfile, "\nstatic %sunsigned char %s[%d] = {",
112 constant ? "const " : "", label, len );
113 for (i = 0; i < len; i++)
115 if (!(i & 7)) fprintf( outfile, "\n " );
116 fprintf( outfile, "0x%02x", *data++ );
117 if (i < len - 1) fprintf( outfile, "," );
119 fprintf( outfile, "\n};\n" );
122 /*****************************************************************
123 * Function: get_alignment
126 * According to the info page for gas, the .align directive behaves
127 * differently on different systems. On some architectures, the
128 * argument of a .align directive is the number of bytes to pad to, so
129 * to align on an 8-byte boundary you'd say
131 * On other systems, the argument is "the number of low-order zero bits
132 * that the location counter must have after advancement." So to
133 * align on an 8-byte boundary you'd say
136 * The reason gas is written this way is that it's trying to mimick
137 * native assemblers for the various architectures it runs on. gas
138 * provides other directives that work consistantly across
139 * architectures, but of course we want to work on all arches with or
140 * without gas. Hence this function.
144 * alignBoundary -- the number of bytes to align to.
145 * If we're on an architecture where
146 * the assembler requires a 'number
147 * of low-order zero bits' as a
148 * .align argument, then this number
149 * must be a power of 2.
152 int get_alignment(int alignBoundary)
158 switch(alignBoundary)
209 fatal_error("Alignment to %d-byte boundary not supported on this architecture.\n",
214 #elif defined(__i386__) || defined(__sparc__)
216 return alignBoundary;
219 #error "How does the '.align' assembler directive work on your architecture?"