1 /* small utility functions for winebuild */
12 void *xmalloc (size_t size
)
16 res
= malloc (size
? size
: 1);
19 fprintf (stderr
, "Virtual memory exhausted.\n");
25 void *xrealloc (void *ptr
, size_t size
)
27 void *res
= realloc (ptr
, size
);
30 fprintf (stderr
, "Virtual memory exhausted.\n");
36 char *xstrdup( const char *str
)
38 char *res
= strdup( str
);
41 fprintf (stderr
, "Virtual memory exhausted.\n");
47 char *strupper(char *s
)
50 for (p
= s
; *p
; p
++) *p
= toupper(*p
);
54 void fatal_error( const char *msg
, ... )
57 va_start( valist
, msg
);
60 fprintf( stderr
, "%s:", input_file_name
);
62 fprintf( stderr
, "%d:", current_line
);
65 vfprintf( stderr
, msg
, valist
);
70 void fatal_perror( const char *msg
, ... )
73 va_start( valist
, msg
);
76 fprintf( stderr
, "%s:", input_file_name
);
78 fprintf( stderr
, "%d:", current_line
);
81 vfprintf( stderr
, msg
, valist
);
87 void warning( const char *msg
, ... )
90 va_start( valist
, msg
);
93 fprintf( stderr
, "%s:", input_file_name
);
95 fprintf( stderr
, "%d:", current_line
);
98 fprintf( stderr
, "warning: " );
99 vfprintf( stderr
, msg
, valist
);
103 /* dump a byte stream into the assembly code */
104 void dump_bytes( FILE *outfile
, const unsigned char *data
, int len
,
105 const char *label
, int constant
)
109 fprintf( outfile
, "\nstatic %sunsigned char %s[%d] = {",
110 constant
? "const " : "", label
, len
);
111 for (i
= 0; i
< len
; i
++)
113 if (!(i
& 7)) fprintf( outfile
, "\n " );
114 fprintf( outfile
, "0x%02x", *data
++ );
115 if (i
< len
- 1) fprintf( outfile
, "," );
117 fprintf( outfile
, "\n};\n" );
120 /*****************************************************************
121 * Function: get_alignment
124 * According to the info page for gas, the .align directive behaves
125 * differently on different systems. On some architectures, the
126 * argument of a .align directive is the number of bytes to pad to, so
127 * to align on an 8-byte boundary you'd say
129 * On other systems, the argument is "the number of low-order zero bits
130 * that the location counter must have after advancement." So to
131 * align on an 8-byte boundary you'd say
134 * The reason gas is written this way is that it's trying to mimick
135 * native assemblers for the various architectures it runs on. gas
136 * provides other directives that work consistantly across
137 * architectures, but of course we want to work on all arches with or
138 * without gas. Hence this function.
142 * alignBoundary -- the number of bytes to align to.
143 * If we're on an architecture where
144 * the assembler requires a 'number
145 * of low-order zero bits' as a
146 * .align argument, then this number
147 * must be a power of 2.
150 int get_alignment(int alignBoundary
)
156 switch(alignBoundary
)
207 fatal_error("Alignment to %d-byte boundary not supported on this architecture.\n",
212 #elif defined(__i386__) || defined(__sparc__)
214 return alignBoundary
;
217 #error "How does the '.align' assembler directive work on your architecture?"