a few more warnings
[suif.git] / src / basesuif / printsuif / printsuif.cc
blob76d1f8cd6428b920698eafb523e0b592e5a8c850
1 /* Read and display a SUIF version 1.x file (or a set of SUIF version 1.x
2 files). */
4 /* Copyright (c) 1994 Stanford University
6 All rights reserved.
8 This software is provided under the terms described in
9 the "suif_copyright.h" include file. */
11 #include <suif_copyright.h>
13 #define RCS_BASE_FILE printsuif_cc
15 #include <suif1.h>
16 #include <string.h>
18 RCS_BASE(
19 "$Id: printsuif.cc,v 1.2 1999/08/25 03:27:38 brm Exp $")
21 INCLUDE_SUIF_COPYRIGHT
24 static void usage();
25 static boolean delete_dummy_srcs(instruction *, operand *r, void *);
28 int main(int argc, char *argv[])
30 boolean ftn_mode = FALSE;
31 boolean exp_trees = TRUE;
32 boolean mach = FALSE;
34 start_suif(argc, argv);
36 /* check for command-line arguments */
37 argv++; argc--;
38 while ((*argv != NULL) && (**argv == '-')) {
39 if (!strcmp(*argv, "-ftn")) {
40 ftn_mode = TRUE;
41 } else if (!strcmp(*argv, "-no-exprs")) {
42 exp_trees = FALSE;
43 } else if (!strcmp(*argv, "-raw")) {
44 /* set the library's raw_syms flag (if TRUE the symtab
45 lookup_sym_id and lookup_type_id methods will create dummy
46 sym_nodes/type_nodes for unknown ids) */
47 _suif_raw_syms = TRUE;
48 } else if (!strcmp(*argv, "-mach")) {
49 mach = TRUE;
50 } else if (!strcmp(*argv, "-print-flat")) {
51 _suif_flat_annotes = TRUE;
52 } else if (!strcmp(*argv, "-no-types")) {
53 _suif_no_types = TRUE;
54 } else if (!strcmp(*argv, "-no-symtabs")) {
55 _suif_no_symtabs = TRUE;
56 } else {
57 usage();
59 argv++; argc--;
61 if (argc < 1) usage();
63 while (*argv) {
65 if (!_suif_raw_syms) {
67 fileset->add_file(*argv, NULL);
69 } else {
71 in_stream *is = new in_stream(lexicon->enter(*argv)->sp);
72 is->open();
74 printf("******************** FILE %s ********************\n",
75 is->name());
77 global_symtab *syms = new global_symtab(is->name());
78 instruction *i;
80 /* read and print the file as a list of instructions */
81 while ((i = instruction::read(is, syms, NULL))) {
82 i->print(stdout, 3);
83 i->src_map(delete_dummy_srcs, NULL);
84 delete i;
87 delete syms;
90 argv++; argc--;
93 if (!_suif_raw_syms) {
95 if (mach) {
96 /* print the target machine parameters */
97 target.print(stdout, 2);
98 fputs("\n\n", stdout);
101 if (!_suif_no_symtabs) {
102 printf(" ****************** GLOBALS ******************\n");
103 fileset->globals()->print(stdout, 2);
104 fputs("\n\n", stdout);
107 fileset->reset_iter();
108 file_set_entry *fse;
109 while ((fse = fileset->next_file())) {
110 printf(" ****************** FILE %s ******************",
111 fse->name());
112 if (fse->are_annotations()) fse->print_annotes(stdout, 2);
113 if (!_suif_no_symtabs) {
114 fputs("\n", stdout);
115 fse->symtab()->print(stdout, 2);
116 } else {
117 fputs("\n", stdout);
120 proc_sym *psym;
121 fse->reset_proc_iter();
122 while ((psym = fse->next_proc())) {
123 fputs("\n\n", stdout);
124 psym->read_proc(exp_trees, ftn_mode);
125 psym->block()->print(stdout, 2);
126 psym->flush_proc();
129 fputs("\n\n", stdout);
133 exit_suif();
134 return 0;
138 void
139 usage ()
141 fprintf(stderr, "Usage: printsuif [flags] suif1_files\n");
142 fprintf(stderr, "Flags:\n");
143 fprintf(stderr, "\t-ftn\t\tFortran mode; use call-by-ref params\n");
144 fprintf(stderr, "\t-no-symtabs\tdon't print the symbol tables\n");
145 fprintf(stderr, "\t-no-types\tomit instruction result types\n");
146 fprintf(stderr, "\t-no-exprs\tuse flat instruction lists\n");
147 fprintf(stderr, "\t-print-flat\tprint annotations as flat immed lists\n");
148 fprintf(stderr, "\t-raw\t\tprint raw instruction list for debugging\n");
149 fprintf(stderr, "\t-mach\t\tshow the target machine parameters\n");
150 exit(-1);
154 boolean
155 delete_dummy_srcs (instruction *, operand *r, void *)
157 if (r->is_instr()) {
158 r->remove();
159 delete r->instr()->parent();
161 return FALSE;