]>
git.saurik.com Git - apple/libc.git/blob - ppc/gen/genassym.c
ca608b199f83785b6e9a8127f2584853e209da01
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
25 #import <ansi/string.h>
33 unsigned bit_num(char *reg_type
, char *field
, unsigned bits
)
38 for (bit
= 0, mask
= 0x1;
39 (mask
& bits
) == 0 && mask
;
44 fprintf(stderr
, "%s: Bad BIT_POS for %s.%s\n", progname
,
49 unsigned field_width(char *reg_type
, char *field
, unsigned bits
)
53 while (bits
&& (bits
& 0x1) == 0)
55 for (width
= 0; (bits
& 0x1) == 1; bits
>>= 1, width
+= 1)
57 if (bits
== 0 && width
)
59 fprintf(stderr
, "%s: Bad BIT_FIELD for %s.%s\n", progname
,
64 unsigned log2(unsigned val
, char *type
)
69 fprintf(stderr
, "log2: sizeof(%s) is zero!\n", type
);
72 while ((val
& 0x1) == 0) {
77 fprintf(stderr
, "log2: sizeof(%s) is not power of two!\n",
84 const char *skip_white(const char *cp
)
86 while (*cp
&& isspace(*cp
))
91 const char *strip_prefix(const char *cp
, const char *prefix
)
97 if (strncmp(cp
, prefix
, len
) == 0 && isspace(*(cp
+len
)))
103 print_define(const char *prefix
, const char *type_name
, const char *field
)
109 if (prefix
!= NULL
&& *prefix
!= '\0') {
110 printf("%s", prefix
);
111 col
+= strlen(prefix
);
113 if (type_name
!= NULL
&& *type_name
!= '\0') {
114 cp
= strip_prefix(type_name
, "struct");
115 cp
= strip_prefix(cp
, "enum");
117 if (*cp
!= '\0' && col
!= 0) {
121 for (; *cp
!= '\0'; cp
++) {
126 if (strncmp(cp
, "_t", 2) == 0 && !isalnum(cp
[2]))
128 putchar(isalpha(*cp
) ? toupper(*cp
) : *cp
);
133 if (field
!= NULL
&& *field
!= '\0') {
138 for (cp
= field
; *cp
!= 0; cp
++) {
145 else if (!isspace(*cp
))
146 putchar(isalpha(*cp
) ? toupper(*cp
) : *cp
);
151 fprintf(stderr
, "%s: Bad call to print_define\n", progname
);
157 } while (col
< NAME_LEN
);
160 void print_dec(int val
)
165 void print_hex(unsigned val
)
167 printf("%#010x\n", val
);
170 void print_str(const char *str
)
175 void comment(cmt_level_t level
, const char *cmt
)
181 printf(" * %s\n", cmt
);
186 printf("/* %s */\n", cmt
);
190 fprintf(stderr
, "%s: Bad comment level\n", progname
);
195 void main(int argc
, char **argv
)
199 printf("/* assym.h -- generated by genassym */\n");
200 printf("/* DON'T EDIT THIS -- change assymdefs.c */\n");