]>
git.saurik.com Git - apple/libc.git/blob - ppc/sys/genassym.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
28 #import <ansi/string.h>
36 unsigned bit_num(char *reg_type
, char *field
, unsigned bits
)
41 for (bit
= 0, mask
= 0x1;
42 (mask
& bits
) == 0 && mask
;
47 fprintf(stderr
, "%s: Bad BIT_POS for %s.%s\n", progname
,
52 unsigned field_width(char *reg_type
, char *field
, unsigned bits
)
56 while (bits
&& (bits
& 0x1) == 0)
58 for (width
= 0; (bits
& 0x1) == 1; bits
>>= 1, width
+= 1)
60 if (bits
== 0 && width
)
62 fprintf(stderr
, "%s: Bad BIT_FIELD for %s.%s\n", progname
,
67 unsigned log2(unsigned val
, char *type
)
72 fprintf(stderr
, "log2: sizeof(%s) is zero!\n", type
);
75 while ((val
& 0x1) == 0) {
80 fprintf(stderr
, "log2: sizeof(%s) is not power of two!\n",
87 const char *skip_white(const char *cp
)
89 while (*cp
&& isspace(*cp
))
94 const char *strip_prefix(const char *cp
, const char *prefix
)
100 if (strncmp(cp
, prefix
, len
) == 0 && isspace(*(cp
+len
)))
106 print_define(const char *prefix
, const char *type_name
, const char *field
)
112 if (prefix
!= NULL
&& *prefix
!= '\0') {
113 printf("%s", prefix
);
114 col
+= strlen(prefix
);
116 if (type_name
!= NULL
&& *type_name
!= '\0') {
117 cp
= strip_prefix(type_name
, "struct");
118 cp
= strip_prefix(cp
, "enum");
120 if (*cp
!= '\0' && col
!= 0) {
124 for (; *cp
!= '\0'; cp
++) {
129 if (strncmp(cp
, "_t", 2) == 0 && !isalnum(cp
[2]))
131 putchar(isalpha(*cp
) ? toupper(*cp
) : *cp
);
136 if (field
!= NULL
&& *field
!= '\0') {
141 for (cp
= field
; *cp
!= 0; cp
++) {
148 else if (!isspace(*cp
))
149 putchar(isalpha(*cp
) ? toupper(*cp
) : *cp
);
154 fprintf(stderr
, "%s: Bad call to print_define\n", progname
);
160 } while (col
< NAME_LEN
);
163 void print_dec(int val
)
168 void print_hex(unsigned val
)
170 printf("%#010x\n", val
);
173 void print_str(const char *str
)
178 void comment(cmt_level_t level
, const char *cmt
)
184 printf(" * %s\n", cmt
);
189 printf("/* %s */\n", cmt
);
193 fprintf(stderr
, "%s: Bad comment level\n", progname
);
198 void main(int argc
, char **argv
)
202 printf("/* assym.h -- generated by genassym */\n");
203 printf("/* DON'T EDIT THIS -- change assymdefs.c */\n");