]>
git.saurik.com Git - apple/libc.git/blob - ppc/gen/genassym.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 #import <ansi/string.h>
34 unsigned bit_num(char *reg_type
, char *field
, unsigned bits
)
39 for (bit
= 0, mask
= 0x1;
40 (mask
& bits
) == 0 && mask
;
45 fprintf(stderr
, "%s: Bad BIT_POS for %s.%s\n", progname
,
50 unsigned field_width(char *reg_type
, char *field
, unsigned bits
)
54 while (bits
&& (bits
& 0x1) == 0)
56 for (width
= 0; (bits
& 0x1) == 1; bits
>>= 1, width
+= 1)
58 if (bits
== 0 && width
)
60 fprintf(stderr
, "%s: Bad BIT_FIELD for %s.%s\n", progname
,
65 unsigned log2(unsigned val
, char *type
)
70 fprintf(stderr
, "log2: sizeof(%s) is zero!\n", type
);
73 while ((val
& 0x1) == 0) {
78 fprintf(stderr
, "log2: sizeof(%s) is not power of two!\n",
85 const char *skip_white(const char *cp
)
87 while (*cp
&& isspace(*cp
))
92 const char *strip_prefix(const char *cp
, const char *prefix
)
98 if (strncmp(cp
, prefix
, len
) == 0 && isspace(*(cp
+len
)))
104 print_define(const char *prefix
, const char *type_name
, const char *field
)
110 if (prefix
!= NULL
&& *prefix
!= '\0') {
111 printf("%s", prefix
);
112 col
+= strlen(prefix
);
114 if (type_name
!= NULL
&& *type_name
!= '\0') {
115 cp
= strip_prefix(type_name
, "struct");
116 cp
= strip_prefix(cp
, "enum");
118 if (*cp
!= '\0' && col
!= 0) {
122 for (; *cp
!= '\0'; cp
++) {
127 if (strncmp(cp
, "_t", 2) == 0 && !isalnum(cp
[2]))
129 putchar(isalpha(*cp
) ? toupper(*cp
) : *cp
);
134 if (field
!= NULL
&& *field
!= '\0') {
139 for (cp
= field
; *cp
!= 0; cp
++) {
146 else if (!isspace(*cp
))
147 putchar(isalpha(*cp
) ? toupper(*cp
) : *cp
);
152 fprintf(stderr
, "%s: Bad call to print_define\n", progname
);
158 } while (col
< NAME_LEN
);
161 void print_dec(int val
)
166 void print_hex(unsigned val
)
168 printf("%#010x\n", val
);
171 void print_str(const char *str
)
176 void comment(cmt_level_t level
, const char *cmt
)
182 printf(" * %s\n", cmt
);
187 printf("/* %s */\n", cmt
);
191 fprintf(stderr
, "%s: Bad comment level\n", progname
);
196 void main(int argc
, char **argv
)
200 printf("/* assym.h -- generated by genassym */\n");
201 printf("/* DON'T EDIT THIS -- change assymdefs.c */\n");