OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [gij.cc] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 753 jeremybenn
/* Copyright (C) 1999-2007  Free Software Foundation
2
 
3
   This file is part of libgcj.
4
 
5
   This software is copyrighted work licensed under the terms of the
6
   Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7
   details. */
8
 
9
#include <config.h>
10
 
11
#include <jvm.h>
12
#include <gcj/cni.h>
13
 
14
#include <stdio.h>
15
#include <string.h>
16
#include <stdlib.h>
17
 
18
static void
19
help ()
20
{
21
  printf ("Usage: gij [OPTION] ... CLASS [ARGS] ...\n");
22
  printf ("          to interpret Java bytecodes, or\n");
23
  printf ("       gij -jar [OPTION] ... JARFILE [ARGS] ...\n");
24
  printf ("          to execute a jar file\n\n");
25
  printf ("  --cp LIST         set class path\n");
26
  printf ("  --classpath LIST  set class path\n");
27
  printf ("  -DVAR=VAL         define property VAR with value VAL\n");
28
  printf ("  -?, --help        print this help, then exit\n");
29
  printf ("  -X                print help on supported -X options, then exit\n");
30
  printf ("  --ms=NUMBER       set initial heap size\n");
31
  printf ("  --mx=NUMBER       set maximum heap size\n");
32
  printf ("  --verbose[:class] print information about class loading\n");
33
  printf ("  --showversion     print version number, then keep going\n");
34
  printf ("  --version         print version number, then exit\n");
35
  printf ("\nOptions can be specified with `-' or `--'.\n");
36
  printf ("\nSee http://gcc.gnu.org/java/ for information on reporting bugs\n");
37
  exit (0);
38
}
39
 
40
static void
41
version ()
42
{
43
  printf ("java version \"" JV_VERSION "\"\n");
44
  printf ("gij (GNU libgcj) version %s\n\n", __VERSION__);
45
  printf ("Copyright (C) 2007 Free Software Foundation, Inc.\n");
46
  printf ("This is free software; see the source for copying conditions.  There is NO\n");
47
  printf ("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
48
}
49
 
50
static void
51
nonstandard_opts_help ()
52
{
53
  printf ("  -Xms<size>         set initial heap size\n");
54
  printf ("  -Xmx<size>         set maximum heap size\n");
55
  printf ("  -Xss<size>         set thread stack size\n");
56
  exit (0);
57
}
58
 
59
static void
60
add_option (JvVMInitArgs& vm_args, char const* option, void const* extra)
61
{
62
  vm_args.options =
63
    (JvVMOption*) JvRealloc (vm_args.options,
64
                             (vm_args.nOptions + 1) * sizeof (JvVMOption));
65
 
66
  vm_args.options[vm_args.nOptions].optionString = const_cast<char*> (option);
67
  vm_args.options[vm_args.nOptions].extraInfo = const_cast<void*> (extra);
68
  ++vm_args.nOptions;
69
}
70
 
71
int
72
main (int argc, char const** argv)
73
{
74
  JvVMInitArgs vm_args;
75
  bool jar_mode = false;
76
 
77
  vm_args.options = NULL;
78
  vm_args.nOptions = 0;
79
  vm_args.ignoreUnrecognized = true;
80
 
81
  // Command-line options always override the CLASSPATH environment
82
  // variable.
83
  char *classpath = getenv("CLASSPATH");
84
 
85
  if (classpath)
86
    {
87
      char* darg = (char*) JvMalloc (strlen (classpath)
88
                                     + sizeof ("-Djava.class.path="));
89
      sprintf (darg, "-Djava.class.path=%s", classpath);
90
      add_option (vm_args, darg, NULL);
91
    }
92
 
93
  // Handle arguments to the java command.  Store in vm_args arguments
94
  // handled by the invocation API.
95
  int i;
96
  for (i = 1; i < argc; ++i)
97
    {
98
      char* arg = const_cast<char*> (argv[i]);
99
 
100
      // A non-option stops processing.
101
      if (arg[0] != '-')
102
        break;
103
 
104
      // A "--" stops processing.
105
      if (! strcmp (arg, "--"))
106
        {
107
          ++i;
108
          break;
109
        }
110
 
111
      // Allow both single or double hyphen for all options.
112
      if (arg[1] == '-')
113
        ++arg;
114
 
115
      // Ignore JIT options
116
      if (! strcmp (arg, "-client"))
117
        continue;
118
      else if (! strcmp (arg, "-server"))
119
        continue;
120
      else if (! strcmp (arg, "-hotspot"))
121
        continue;
122
      else if (! strcmp (arg, "-jrockit"))
123
        continue;
124
      // JVM Tool Interface options.
125
      else if (! strncmp (arg, "-agentlib:", sizeof ("-agentlib:") - 1))
126
        add_option (vm_args, arg, NULL);
127
      else if (! strncmp (arg, "-agentpath:", sizeof ("-agentpath:") - 1))
128
        add_option (vm_args, arg, NULL);
129
      else if (! strcmp (arg, "-classpath") || ! strcmp (arg, "-cp"))
130
        {
131
          if (i >= argc - 1)
132
            {
133
            no_arg:
134
              fprintf (stderr, "gij: option requires an argument -- `%s'\n",
135
                       argv[i]);
136
              fprintf (stderr, "Try `gij --help' for more information.\n");
137
              exit (1);
138
            }
139
 
140
          // Sun seems to translate the -classpath option into
141
          // -Djava.class.path because if both -classpath and
142
          // -Djava.class.path are specified on the java command line,
143
          // the last one always wins.
144
          char* darg = (char*) JvMalloc (strlen (argv[++i])
145
                                         + sizeof ("-Djava.class.path="));
146
          sprintf (darg, "-Djava.class.path=%s", argv[i]);
147
          add_option (vm_args, darg, NULL);
148
        }
149
      else if (! strcmp (arg, "-debug"))
150
        {
151
          char* xarg = strdup ("-Xdebug");
152
          add_option (vm_args, xarg, NULL);
153
        }
154
      else if (! strncmp (arg, "-D", sizeof ("-D") - 1))
155
        add_option (vm_args, arg, NULL);
156
      // Ignore 32/64-bit JIT options
157
      else if (! strcmp (arg, "-d32") || ! strcmp (arg, "-d64"))
158
        continue;
159
      else if (! strncmp (arg, "-enableassertions", sizeof ("-enableassertions") - 1)
160
               || ! strncmp (arg, "-ea", sizeof ("-ea") - 1))
161
        {
162
          // FIXME: hook up assertion support
163
          continue;
164
        }
165
      else if (! strncmp (arg, "-disableassertions", sizeof ("-disableassertions") - 1)
166
               || ! strncmp (arg, "-da", sizeof ("-da") - 1))
167
        {
168
          // FIXME: hook up assertion support
169
          continue;
170
        }
171
      else if (! strcmp (arg, "-enablesystemassertions")
172
               || ! strcmp (arg, "-esa"))
173
        {
174
          // FIXME: hook up system assertion support
175
          continue;
176
        }
177
      else if (! strcmp (arg, "-disablesystemassertions")
178
               || ! strcmp (arg, "-dsa"))
179
        {
180
          // FIXME
181
          continue;
182
        }
183
      else if (! strcmp (arg, "-jar"))
184
        {
185
          jar_mode = true;
186
          continue;
187
        }
188
      // Ignore java.lang.instrument option
189
      else if (! strncmp (arg, "-javaagent:", sizeof ("-javaagent:") - 1))
190
        continue;
191
      else if (! strcmp (arg, "-noclassgc"))
192
        {
193
          char* xarg = strdup ("-Xnoclassgc");
194
          add_option (vm_args, xarg, NULL);
195
        }
196
      // -ms=n
197
      else if (! strncmp (arg, "-ms=", sizeof ("-ms=") - 1))
198
        {
199
          arg[1] = 'X';
200
          arg[2] = 'm';
201
          arg[3] = 's';
202
          add_option (vm_args, arg, NULL);
203
        }
204
      // -ms n
205
      else if (! strcmp (arg, "-ms"))
206
        {
207
          if (i >= argc - 1)
208
            goto no_arg;
209
 
210
          char* xarg = (char*) JvMalloc (strlen (argv[++i])
211
                                         + sizeof ("-Xms"));
212
          sprintf (xarg, "-Xms%s", argv[i]);
213
          add_option (vm_args, xarg, NULL);
214
        }
215
      // -msn
216
      else if (! strncmp (arg, "-ms", sizeof ("-ms") - 1))
217
        {
218
          char* xarg = (char*) JvMalloc (strlen (arg) + sizeof ("X"));
219
          sprintf (xarg, "-Xms%s", arg + sizeof ("-Xms") - 1);
220
          add_option (vm_args, xarg, NULL);
221
        }
222
      // -mx=n
223
      else if (! strncmp (arg, "-mx=", sizeof ("-mx=") - 1))
224
        {
225
          arg[1] = 'X';
226
          arg[2] = 'm';
227
          arg[3] = 'x';
228
          add_option (vm_args, arg, NULL);
229
        }
230
      // -mx n
231
      else if (! strcmp (arg, "-mx"))
232
        {
233
          if (i >= argc - 1)
234
            goto no_arg;
235
 
236
          char* xarg = (char*) JvMalloc (strlen (argv[++i])
237
                                         + sizeof ("-Xmx"));
238
          sprintf (xarg, "-Xmx%s", argv[i]);
239
          add_option (vm_args, xarg, NULL);
240
        }
241
      // -mxn
242
      else if (! strncmp (arg, "-mx", sizeof ("-mx") - 1))
243
        {
244
          char* xarg = (char*) JvMalloc (strlen (arg) + sizeof ("X"));
245
          sprintf (xarg, "-Xmx%s", arg + sizeof ("-Xmx") - 1);
246
          add_option (vm_args, xarg, NULL);
247
        }
248
      // -ss=n
249
      else if (! strncmp (arg, "-ss=", sizeof ("-ss=") - 1))
250
        {
251
          arg[1] = 'X';
252
          arg[2] = 's';
253
          arg[3] = 's';
254
          add_option (vm_args, arg, NULL);
255
        }
256
      // -ss n
257
      else if (! strcmp (arg, "-ss"))
258
        {
259
          if (i >= argc - 1)
260
            goto no_arg;
261
 
262
          char* xarg = (char*) JvMalloc (strlen (argv[++i])
263
                                         + sizeof ("-Xss"));
264
          sprintf (xarg, "-Xss%s", argv[i]);
265
          add_option (vm_args, xarg, NULL);
266
        }
267
      // -ssn
268
      else if (! strncmp (arg, "-ss", sizeof ("-ss") - 1))
269
        {
270
          char* xarg = (char*) JvMalloc (strlen (arg) + sizeof ("X"));
271
          sprintf (xarg, "-Xss%s", arg + sizeof ("-Xss") - 1);
272
          add_option (vm_args, xarg, NULL);
273
        }
274
      // This handles all the option variants that begin with
275
      // -verbose.
276
      else if (! strncmp (arg, "-verbose", 8))
277
        add_option (vm_args, arg, NULL);
278
      else if (! strcmp (arg, "-version"))
279
        {
280
          version ();
281
          exit (0);
282
        }
283
      else if (! strcmp (arg, "-fullversion"))
284
        {
285
          printf ("java full version \"gcj-" JV_VERSION "\"\n");
286
          exit (0);
287
        }
288
      else if (! strcmp (arg, "-showversion"))
289
        version ();
290
      else if (! strcmp (arg, "-help") || ! strcmp (arg, "-?"))
291
        help ();
292
      else if (! strcmp (arg, "-X"))
293
        nonstandard_opts_help ();
294
      else if (! strncmp (arg, "-X", 2))
295
        add_option (vm_args, arg, NULL);
296
      // Obsolete options recognized for backwards-compatibility.
297
      else if (! strcmp (arg, "-verify")
298
               || ! strcmp (arg, "-verifyremote"))
299
        continue;
300
      else if (! strcmp (arg, "-noverify"))
301
        {
302
          gcj::verifyClasses = false;
303
        }
304
      else
305
        {
306
          fprintf (stderr, "gij: unrecognized option -- `%s'\n", argv[i]);
307
          fprintf (stderr, "Try `gij --help' for more information.\n");
308
          exit (1);
309
        }
310
    }
311
 
312
  if (argc - i < 1)
313
    {
314
      fprintf (stderr, "Usage: gij [OPTION] ... CLASS [ARGS] ...\n");
315
      fprintf (stderr, "          to invoke CLASS.main, or\n");
316
      fprintf (stderr, "       gij -jar [OPTION] ... JARFILE [ARGS] ...\n");
317
      fprintf (stderr, "          to execute a jar file\n");
318
      fprintf (stderr, "Try `gij --help' for more information.\n");
319
      exit (1);
320
    }
321
 
322
  // -jar mode overrides all other modes of specifying class path:
323
  // CLASSPATH, -Djava.class.path, -classpath and -cp.
324
  if (jar_mode)
325
    {
326
      char* darg = (char*) JvMalloc (strlen (argv[i])
327
                                      + sizeof ("-Djava.class.path="));
328
      sprintf (darg, "-Djava.class.path=%s", argv[i]);
329
      add_option (vm_args, darg, NULL);
330
    }
331
 
332
  _Jv_RunMain (&vm_args, NULL, argv[i], argc - i,
333
               (char const**) (argv + i), jar_mode);
334
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.