* ========== Copyright Header Begin ==========================================
* Hypervisor Software File: main.c
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* - Do no alter or remove copyright notices
* - Redistribution and use of this software in source and binary forms, with
* or without modification, are permitted provided that the following
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of Sun Microsystems, Inc. or the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
* OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
* FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or maintenance of
* ========== Copyright Header End ============================================
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
#pragma ident "@(#)main.c 1.2 07/06/07 SMI"
boolean_t error
= B_FALSE
;
extern void forth_do_sou(struct tdesc
*, struct node
*);
extern void forth_do_enum(struct tdesc
*, struct node
*);
extern void forth_do_intrinsic(struct tdesc
*, struct node
*);
extern void genassym_do_sou(struct tdesc
*, struct node
*);
extern void genassym_do_enum(struct tdesc
*, struct node
*);
extern void genassym_do_intrinsic(struct tdesc
*, struct node
*);
extern void squander_do_sou(struct tdesc
*, struct node
*);
extern void squander_do_enum(struct tdesc
*, struct node
*);
extern void squander_do_intrinsic(struct tdesc
*, struct node
*);
extern void asmcheck_do_sou(struct tdesc
*, struct node
*);
extern void asmcheck_do_enum(struct tdesc
*, struct node
*);
extern void asmcheck_do_intrinsic(struct tdesc
*, struct node
*);
struct model_info models
[] = {
{ "ilp32", 4, 1, 2, 4, 4 },
{ "lp64", 8, 1, 2, 4, 8 },
void (*do_sou
)(struct tdesc
*, struct node
*);
void (*do_enum
)(struct tdesc
*, struct node
*);
void (*do_intrinsic
)(struct tdesc
*, struct node
*);
forth_do_sou
, forth_do_enum
, forth_do_intrinsic
},
genassym_do_sou
, genassym_do_enum
, genassym_do_intrinsic
},
squander_do_sou
, squander_do_enum
, squander_do_intrinsic
},
asmcheck_do_sou
, asmcheck_do_enum
, asmcheck_do_intrinsic
},
static void get_dbgs(int argc
, char **argv
);
static void parse_dbg(FILE *sp
);
static void printnode(struct node
*np
);
static struct tdesc
*find_member(struct tdesc
*tdp
, char *name
);
static char *namex(char *cp
, char **w
);
static void addchild(char *cp
, struct node
*np
);
static struct node
*getnode(char *cp
);
struct model_info
*model
;
main(int argc
, char **argv
)
char *output_type
= NULL
;
program
= strrchr(argv
[0], '/');
while (!error
&& ((c
= getopt(argc
, argv
, "dt:m:")) != EOF
)) {
* Find ops for the specified output type
for (ops
= ops_table
; ops
->type
!= NULL
; ops
++) {
if (strcmp(ops
->type
, output_type
) == 0)
* Find model characteristics
for (model
= models
; model
->name
!= NULL
; model
++) {
if (strcmp(model
->name
, model_name
) == 0)
/* skip over previously processed arguments */
fprintf(stderr
, "Usage: %s [-d] {-m datamodel} "
"{-t output_type} files\n", program
);
fprintf(stderr
, "\tSupported data models:\n");
for (model
= models
; model
->name
!= NULL
; model
++)
fprintf(stderr
, "\t\t%s\n", model
->name
);
fprintf(stderr
, "\tSupported output types:\n");
for (ops
= ops_table
; ops
->type
!= NULL
; ops
++)
fprintf(stderr
, "\t\t%s\n", ops
->type
);
* This routine will read the .dbg files and build a list of the structures
* and fields that user is interested in. Any struct specified will get all
* its fields included. If nested struct needs to be printed - then the
* field name and name of struct type needs to be included in the next line.
get_dbgs(int argc
, char **argv
)
for (; argc
!= 0; argc
--, argv
++) {
if ((fp
= fopen(*argv
, "r")) == NULL
) {
fprintf(stderr
, "Cannot open %s\n", *argv
);
/* add all types in this file to our table */
namex(char *cp
, char **w
)
for (c
= *cp
++; isspace(c
); c
= *cp
++)
if (isalpha(c
) || ispunct(c
)) {
for (c
= *cp
++; isalnum(c
) || ispunct(c
); c
= *cp
++)
new = (char *)malloc(len
);
fprintf(stderr
, "line %d has bad character %c\n", line
, c
);
* checks to see if this field in the struct was requested for by user
find_child(struct node
*np
, char *w
)
for (chp
= np
->child
; chp
!= NULL
; chp
= chp
->next
) {
if (strcmp(chp
->name
, w
) == 0)
find_member(struct tdesc
*tdp
, char *name
)
while (tdp
->type
== TYPEOF
)
if (tdp
->type
!= STRUCT
&& tdp
->type
!= UNION
)
for (mlp
= tdp
->data
.members
.forw
; mlp
!= NULL
; mlp
= mlp
->next
)
if (strcmp(mlp
->name
, name
) == 0)
* add this field to our table of structs/fields that the user has
* requested in the .dbg files
addchild(char *cp
, struct node
*np
)
chp
= malloc(sizeof (*chp
));
fprintf(stderr
, "NULL child name\n");
/* XXX - always convert to upper-case? */
chp
->format
= uc(chp
->name
);
* add this struct to our table of structs/fields that the user has
* requested in the .dbg files
np
= malloc(sizeof (*np
));
* XXX - These positional parameters are a hack
* We have two right now for genassym. The back-ends
* can use format and format2 any way they'd like.
* Format for .dbg files should be
* if you wanted the contents of "s_as" (a pointer) to be printed in
static char linebuf
[MAXLINE
];
/* grab each line and add them to our table */
for (line
= 1; (cp
= fgets(linebuf
, MAXLINE
, sp
)) != NULL
; line
++) {
if (strcmp(cp
, "model_end\n") == 0) {
c
= strlen("model_start ");
if (strncmp(cp
, "model_start ", c
) == 0) {
if (strncmp(cp
+ c
, model
->name
, strlen(model
->name
))
== 0 && *(cp
+ c
+ strlen(model
->name
)) == '\n')
if ((strcmp(cp
, "verbatim_begin\n") == 0) ||
(strcmp(cp
, "forth_start\n") == 0)) {
if ((strcmp(cp
, "verbatim_end\n") == 0) ||
(strcmp(cp
, "forth_end\n") == 0)) {
for (line
++; ((cp
= fgets(linebuf
, MAXLINE
, sp
)) != NULL
) &&
/* members of struct, union or enum */
printnode(struct node
*np
)
tdp
= lookupname(np
->name
);
if ((member
= strchr(np
->name
, '.')) != NULL
) {
ptdp
= lookupname(np
->name
);
tdp
= find_member(ptdp
, member
+ 1);
fprintf(stderr
, "Can't find %s\n", np
->name
);
ops
->do_intrinsic(tdp
, np
);
fprintf(stderr
, "%s isn't aggregate\n", np
->name
);
convert_format(char *format
, char *dfault
)
static char dot
[3] = ".";
else if (strlen(format
) == 1) {
for (i
= 0; i
< strlen(buf
); i
++)
buf
[i
] = toupper(buf
[i
]);