OSDN Git Service

Do not rewrite out of SSA scalar dependences crossing the limits of the scop.
[pf3gnuchains/gcc-fork.git] / gcc / java / jvgenmain.c
1 /* Program to generate "main" a Java(TM) class containing a main method.
2    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3    2007, 2008 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>. 
20
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.  */
24
25 /* Written by Per Bothner <bothner@cygnus.com> */
26
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "obstack.h"
31 #include "jcf.h"
32 #include "tree.h"
33 #include "java-tree.h"
34 #include "intl.h"
35 #include "tm.h"         /* FIXME: For gcc_obstack_init from defaults.h.  */
36
37 static char * do_mangle_classname (const char *string);
38
39 struct obstack  name_obstack;
40 struct obstack *mangle_obstack = &name_obstack;
41
42 static void usage (const char *) ATTRIBUTE_NORETURN;
43
44 static void
45 usage (const char *name)
46 {
47   fprintf (stderr, _("Usage: %s [OPTIONS]... CLASSNAMEmain [OUTFILE]\n"),
48            name);
49   exit (1);
50 }
51
52 int
53 main (int argc, char **argv)
54 {
55   char *classname, *p;
56   FILE *stream;
57   const char *mangled_classname;
58   int i, last_arg;
59   int indirect = 0;
60   char *prog_name = argv[0];
61
62   /* Unlock the stdio streams.  */
63   unlock_std_streams ();
64
65   gcc_init_libintl ();
66
67   if (argc > 1 && ! strcmp (argv[1], "-findirect-dispatch"))
68     {
69       indirect = 1;
70       ++argv;
71       --argc;
72     }
73
74   if (argc < 2)
75     usage (prog_name);
76
77   for (i = 1; i < argc; ++i)
78     {
79       if (! strncmp (argv[i], "-D", 2))
80         {
81           /* Handled later.  Check "-D XXX=YYY".  */
82           if (argv[i][2] == '\0')
83             i++;
84         }
85       else
86         break;
87     }
88
89   if (i < argc - 2 || i == argc)
90     usage (prog_name);
91   last_arg = i;
92
93   classname = argv[i];
94
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 (prog_name);
99   else
100     *p = '\0';
101
102   gcc_obstack_init (mangle_obstack);
103   mangled_classname = do_mangle_classname (classname);
104
105   if (i < argc - 1 && strcmp (argv[i + 1], "-") != 0)
106     {
107       const char *outfile = argv[i + 1];
108       stream = fopen (outfile, "w");
109       if (stream == NULL)
110         {
111           fprintf (stderr, _("%s: Cannot open output file: %s\n"),
112                    prog_name, outfile);
113           exit (1);
114         }
115     }
116   else
117     stream = stdout;
118
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)
124     {
125       const char *p;
126
127       if (strcmp (argv[i], "-D") == 0)
128         continue;
129
130       fprintf (stream, "  \"");
131       for (p = argv[i]; *p; ++p)
132         {
133           if (! ISPRINT (*p))
134             fprintf (stream, "\\%o", *p);
135           else if (*p == '\\' || *p == '"')
136             fprintf (stream, "\\%c", *p);
137           else
138             putc (*p, stream);
139         }
140       fprintf (stream, "\",\n");
141     }
142   fprintf (stream, "  0\n};\n\n");
143
144   fprintf (stream, "int main (int argc, const char **argv)\n");
145   fprintf (stream, "{\n");
146   fprintf (stream, "   _Jv_Compiler_Properties = props;\n");
147   if (indirect)
148     fprintf (stream, "   JvRunMainName (\"%s\", argc, argv);\n", classname);
149   else
150     {
151       fprintf (stream, "   extern char %s;\n", mangled_classname);
152       fprintf (stream, "   JvRunMain (&%s, argc, argv);\n", mangled_classname);
153     }
154   fprintf (stream, "}\n");
155   if (stream != stdout && fclose (stream) != 0)
156     {
157       fprintf (stderr, _("%s: Failed to close output file %s\n"),
158                prog_name, argv[2]);
159       exit (1);
160     }
161   return 0;
162 }
163
164
165 static char *
166 do_mangle_classname (const char *string)
167 {
168   const char *ptr;
169   int count = 0;
170
171   obstack_grow (&name_obstack, "_ZN", 3);
172
173   for (ptr = string; *ptr; ptr++ )
174     {
175       if (*ptr == '.')
176         {
177           append_gpp_mangled_name (ptr - count, count);
178           count = 0;
179         }
180       else
181         count++;
182     }
183   append_gpp_mangled_name (&ptr [-count], count);
184   obstack_grow (mangle_obstack, "6class$E", strlen ("6class$E"));
185   obstack_1grow (mangle_obstack, '\0');
186   return XOBFINISH (mangle_obstack, char *);
187 }