Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / hypervisor / src / support / mdgen / output_dot.c
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* Hypervisor Software File: output_dot.c
5*
6* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
7*
8* - Do no alter or remove copyright notices
9*
10* - Redistribution and use of this software in source and binary forms, with
11* or without modification, are permitted provided that the following
12* conditions are met:
13*
14* - Redistribution of source code must retain the above copyright notice,
15* this list of conditions and the following disclaimer.
16*
17* - Redistribution in binary form must reproduce the above copyright notice,
18* this list of conditions and the following disclaimer in the
19* documentation and/or other materials provided with the distribution.
20*
21* Neither the name of Sun Microsystems, Inc. or the names of contributors
22* may be used to endorse or promote products derived from this software
23* without specific prior written permission.
24*
25* This software is provided "AS IS," without a warranty of any kind.
26* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
27* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
28* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
29* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
30* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
31* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
32* OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
33* FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
34* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
35* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
36* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
37*
38* You acknowledge that this software is not designed, licensed or
39* intended for use in the design, construction, operation or maintenance of
40* any nuclear facility.
41*
42* ========== Copyright Header End ============================================
43*/
44/*
45 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
46 * Use is subject to license terms.
47 */
48
49#pragma ident "@(#)output_dot.c 1.2 07/06/07 SMI"
50
51#include <stdio.h>
52#include <stdlib.h>
53#include <unistd.h>
54#include <sys/types.h>
55#include <strings.h>
56#include <ctype.h>
57
58#include <assert.h>
59
60#include "basics.h"
61#include "allocate.h"
62#include "fatal.h"
63#include "lexer.h"
64
65#include "dagtypes.h"
66#include "outputtypes.h"
67
68#define ASSERT(_s) assert(_s)
69
70
71
72 /*
73 * Output for DOT utility
74 */
75
76
77
78
79
80
81static char *
82sanity_name(char *p)
83{
84 static char buf[2048];
85 int i, ch;
86
87 for (i = 0; (ch = p[i]) != '\0'; i++) {
88 if (isalnum(ch) || ch == '_') {
89 buf[i] = ch;
90 } else {
91 buf[i] = '_';
92 }
93 }
94 buf[i] = '\0';
95
96 return (buf);
97}
98
99
100
101extern char *output_dot_dagp;
102extern bool_t output_dot_flag_none;
103
104
105
106
107void
108output_dot(FILE *fp)
109{
110 dag_node_t *dnp;
111
112 fprintf(fp, "digraph machine_description {\n");
113 fprintf(fp, "rankdir = LR ;\n");
114 fprintf(fp, "ordering=in ;\n");
115/* CSTYLED */
116 fprintf(fp, "size=\"8.5,10\" ;\n");
117 fprintf(fp, "nslimit=\"100.0\" ;\n");
118 fprintf(fp, "mclimit=\"100.0\" ;\n");
119#if 0 /* { */
120 fprintf(fp, "node [ fontfamily=Helvetica , fontsize=6 ] ;\n");
121#endif /* } */
122 fprintf(fp, "node [ fontfamily=Helvetica ] ;\n");
123
124 /* Now output the nodes ... and their connections */
125 for (dnp = dag_listp; NULL != dnp; dnp = dnp->nextp) {
126 int i;
127 pair_entry_t *pep;
128
129 fprintf(fp, "%s [ label=\"%s\\n", sanity_name(dnp->namep),
130 dnp->typep);
131
132 if (!output_dot_flag_none) {
133 pep = dnp->properties.listp;
134 for (i = 0; i < dnp->properties.num; i++) {
135 switch (pep->utype) {
136 case PE_none:
137 break;
138 case PE_string:
139 fprintf(fp, "%s =",
140 sanity_name(pep->namep));
141 fprintf(fp, " %s\\n",
142 sanity_name(pep->u.strp));
143 break;
144 case PE_int:
145 fprintf(fp, "%s = 0x%llx\\n",
146 pep->namep, pep->u.val);
147 break;
148 case PE_arc:
149 break;
150 case PE_noderef:
151 fatal("Internal error noderefs should \
152all be resolved");
153 break;
154 }
155 pep ++;
156 }
157 }
158/* CSTYLED */
159 fprintf(fp, "\" ] ;\n");
160
161 /* Now connect the arcs */
162 pep = dnp->properties.listp;
163 for (i = 0; i < dnp->properties.num; i++) {
164 switch (pep->utype) {
165 case PE_none:
166 break;
167 case PE_string:
168 break;
169 case PE_int:
170 break;
171 case PE_arc:
172 if (strcmp(output_dot_dagp, pep->namep) == 0) {
173 fprintf(fp, "%s ->\n",
174 sanity_name(dnp->namep));
175 fprintf(fp, "%s\n",
176 sanity_name(pep->u.dnp->namep));
177 }
178 break;
179 case PE_noderef:
180 fatal("Internal error noderefs should all \
181be resolved");
182 break;
183 }
184 pep ++;
185 }
186 }
187
188 fprintf(fp, "}\n");
189 fflush(fp);
190}