Use 'a' operand code for prefetch instruction.
[official-gcc.git] / gcc / java / jvgenmain.c
blob9a425715066180edad4b8d8578f8ede0175302ad
1 /* Program to generate "main" a Java(TM) class containing a main method.
2 Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 Java and all Java-based marks are trademarks or registered trademarks
22 of Sun Microsystems, Inc. in the United States and other countries.
23 The Free Software Foundation is independent of Sun Microsystems, Inc. */
25 /* Written by Per Bothner <bothner@cygnus.com> */
27 #include "config.h"
28 #include "system.h"
29 #include "obstack.h"
30 #include "jcf.h"
31 #include "tree.h"
32 #include "java-tree.h"
34 static char * do_mangle_classname PARAMS ((const char *string));
36 struct obstack name_obstack;
37 struct obstack *mangle_obstack = &name_obstack;
39 void
40 gcc_obstack_init (obstack)
41 struct obstack *obstack;
43 /* Let particular systems override the size of a chunk. */
44 #ifndef OBSTACK_CHUNK_SIZE
45 #define OBSTACK_CHUNK_SIZE 0
46 #endif
47 /* Let them override the alloc and free routines too. */
48 #ifndef OBSTACK_CHUNK_ALLOC
49 #define OBSTACK_CHUNK_ALLOC xmalloc
50 #endif
51 #ifndef OBSTACK_CHUNK_FREE
52 #define OBSTACK_CHUNK_FREE free
53 #endif
54 _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
55 (void *(*) PARAMS ((long))) OBSTACK_CHUNK_ALLOC,
56 (void (*) PARAMS ((void *))) OBSTACK_CHUNK_FREE);
59 static void usage (const char *) ATTRIBUTE_NORETURN;
61 static void
62 usage (const char *name)
64 fprintf (stderr, "Usage: %s [OPTIONS]... CLASSNAMEmain [OUTFILE]\n", name);
65 exit (1);
68 int
69 main (int argc, char **argv)
71 char *classname, *p;
72 FILE *stream;
73 const char *mangled_classname;
74 int i, last_arg;
76 if (argc < 2)
77 usage (argv[0]);
79 for (i = 1; i < argc; ++i)
81 if (! strncmp (argv[i], "-D", 2))
83 /* Handled later. */
85 else
86 break;
89 if (i < argc - 2 || i == argc)
90 usage (argv[0]);
91 last_arg = i;
93 classname = argv[i];
95 /* gcj always appends `main' to classname. We need to strip this here. */
96 p = strrchr (classname, 'm');
97 if (p == NULL || p == classname || strcmp (p, "main") != 0)
98 usage (argv[0]);
99 else
100 *p = '\0';
102 gcc_obstack_init (mangle_obstack);
103 mangled_classname = do_mangle_classname (classname);
105 if (i < argc - 1 && strcmp (argv[i + 1], "-") != 0)
107 const char *outfile = argv[i + 1];
108 stream = fopen (outfile, "w");
109 if (stream == NULL)
111 fprintf (stderr, "%s: Cannot open output file: %s\n",
112 argv[0], outfile);
113 exit (1);
116 else
117 stream = stdout;
119 /* At this point every element of ARGV from 1 to LAST_ARG is a `-D'
120 option. Process them appropriately. */
121 fprintf (stream, "extern const char **_Jv_Compiler_Properties;\n");
122 fprintf (stream, "static const char *props[] =\n{\n");
123 for (i = 1; i < last_arg; ++i)
125 const char *p;
126 fprintf (stream, " \"");
127 for (p = &argv[i][2]; *p; ++p)
129 if (! ISPRINT (*p))
130 fprintf (stream, "\\%o", *p);
131 else if (*p == '\\' || *p == '"')
132 fprintf (stream, "\\%c", *p);
133 else
134 putc (*p, stream);
136 fprintf (stream, "\",\n");
138 fprintf (stream, " 0\n};\n\n");
140 fprintf (stream, "extern int %s;\n", mangled_classname);
141 fprintf (stream, "int main (int argc, const char **argv)\n");
142 fprintf (stream, "{\n");
143 fprintf (stream, " _Jv_Compiler_Properties = props;\n");
144 fprintf (stream, " JvRunMain (&%s, argc, argv);\n", mangled_classname);
145 fprintf (stream, "}\n");
146 if (stream != stdout && fclose (stream) != 0)
148 fprintf (stderr, "%s: Failed to close output file %s\n",
149 argv[0], argv[2]);
150 exit (1);
152 return 0;
156 static char *
157 do_mangle_classname (string)
158 const char *string;
160 const char *ptr;
161 int count = 0;
163 obstack_grow (&name_obstack, "_ZN", 3);
165 for (ptr = string; *ptr; ptr++ )
167 if (ptr[0] == '.')
169 append_gpp_mangled_name (&ptr [-count], count);
170 count = 0;
172 else
173 count++;
175 append_gpp_mangled_name (&ptr [-count], count);
176 obstack_grow (mangle_obstack, "6class$E", 8);
177 obstack_1grow (mangle_obstack, '\0');
178 return obstack_finish (mangle_obstack);