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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [java/] [jvgenmain.c] - Blame information for rev 744

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

Line No. Rev Author Line
1 715 jeremybenn
/* 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, 2010, 2011 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 "diagnostic.h"
36
#include "tm.h"         /* FIXME: For gcc_obstack_init from defaults.h.  */
37
 
38
static char * do_mangle_classname (const char *string);
39
 
40
struct obstack  name_obstack;
41
struct obstack *mangle_obstack = &name_obstack;
42
 
43
static void usage (const char *) ATTRIBUTE_NORETURN;
44
 
45
static void
46
usage (const char *name)
47
{
48
  fprintf (stderr, _("Usage: %s [OPTIONS]... CLASSNAMEmain [OUTFILE]\n"),
49
           name);
50
  exit (1);
51
}
52
 
53
int
54
main (int argc, char **argv)
55
{
56
  char *classname, *p;
57
  FILE *stream;
58
  const char *mangled_classname;
59
  int i, last_arg;
60
  int indirect = 0;
61
  char *prog_name = argv[0];
62
 
63
  p = argv[0] + strlen (argv[0]);
64
  while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1]))
65
    --p;
66
  progname = p;
67
 
68
  xmalloc_set_program_name (progname);
69
 
70
  /* Unlock the stdio streams.  */
71
  unlock_std_streams ();
72
 
73
  gcc_init_libintl ();
74
 
75
  diagnostic_initialize (global_dc, 0);
76
 
77
  if (argc > 1 && ! strcmp (argv[1], "-findirect-dispatch"))
78
    {
79
      indirect = 1;
80
      ++argv;
81
      --argc;
82
    }
83
 
84
  if (argc < 2)
85
    usage (prog_name);
86
 
87
  for (i = 1; i < argc; ++i)
88
    {
89
      if (! strncmp (argv[i], "-D", 2))
90
        {
91
          /* Handled later.  Check "-D XXX=YYY".  */
92
          if (argv[i][2] == '\0')
93
            i++;
94
        }
95
      else
96
        break;
97
    }
98
 
99
  if (i < argc - 2 || i == argc)
100
    usage (prog_name);
101
  last_arg = i;
102
 
103
  classname = argv[i];
104
 
105
  /* gcj always appends `main' to classname.  We need to strip this here.  */
106
  p = strrchr (classname, 'm');
107
  if (p == NULL || p == classname || strcmp (p, "main") != 0)
108
    usage (prog_name);
109
  else
110
    *p = '\0';
111
 
112
  gcc_obstack_init (mangle_obstack);
113
  mangled_classname = do_mangle_classname (classname);
114
 
115
  if (i < argc - 1 && strcmp (argv[i + 1], "-") != 0)
116
    {
117
      const char *outfile = argv[i + 1];
118
      stream = fopen (outfile, "w");
119
      if (stream == NULL)
120
        {
121
          fprintf (stderr, _("%s: Cannot open output file: %s\n"),
122
                   prog_name, outfile);
123
          exit (1);
124
        }
125
    }
126
  else
127
    stream = stdout;
128
 
129
  /* At this point every element of ARGV from 1 to LAST_ARG is a `-D'
130
     option.  Process them appropriately.  */
131
  fprintf (stream, "extern const char **_Jv_Compiler_Properties;\n");
132
  fprintf (stream, "static const char *props[] =\n{\n");
133
  for (i = 1; i < last_arg; ++i)
134
    {
135
      const char *p;
136
 
137
      if (strcmp (argv[i], "-D") == 0)
138
        continue;
139
 
140
      fprintf (stream, "  \"");
141
      for (p = argv[i]; *p; ++p)
142
        {
143
          if (! ISPRINT (*p))
144
            fprintf (stream, "\\%o", *p);
145
          else if (*p == '\\' || *p == '"')
146
            fprintf (stream, "\\%c", *p);
147
          else
148
            putc (*p, stream);
149
        }
150
      fprintf (stream, "\",\n");
151
    }
152
  fprintf (stream, "  0\n};\n\n");
153
 
154
  fprintf (stream, "int main (int argc, const char **argv)\n");
155
  fprintf (stream, "{\n");
156
  fprintf (stream, "   _Jv_Compiler_Properties = props;\n");
157
  if (indirect)
158
    fprintf (stream, "   JvRunMainName (\"%s\", argc, argv);\n", classname);
159
  else
160
    {
161
      fprintf (stream, "   extern char %s;\n", mangled_classname);
162
      fprintf (stream, "   JvRunMain (&%s, argc, argv);\n", mangled_classname);
163
    }
164
  fprintf (stream, "}\n");
165
  if (stream != stdout && fclose (stream) != 0)
166
    {
167
      fprintf (stderr, _("%s: Failed to close output file %s\n"),
168
               prog_name, argv[2]);
169
      exit (1);
170
    }
171
  return 0;
172
}
173
 
174
 
175
static char *
176
do_mangle_classname (const char *string)
177
{
178
  const char *ptr;
179
  int count = 0;
180
 
181
  obstack_grow (&name_obstack, "_ZN", 3);
182
 
183
  for (ptr = string; *ptr; ptr++ )
184
    {
185
      if (*ptr == '.')
186
        {
187
          append_gpp_mangled_name (ptr - count, count);
188
          count = 0;
189
        }
190
      else
191
        count++;
192
    }
193
  append_gpp_mangled_name (&ptr [-count], count);
194
  obstack_grow (mangle_obstack, "6class$E", strlen ("6class$E"));
195
  obstack_1grow (mangle_obstack, '\0');
196
  return XOBFINISH (mangle_obstack, char *);
197
}

powered by: WebSVN 2.1.0

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