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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [tools/] [com/] [sun/] [tools/] [javac/] [Main.java] - Blame information for rev 779

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 779 jeremybenn
/* Main.java -- implement com.sun.tools.javac.Main
2
   Copyright (C) 2007 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath 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.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package com.sun.tools.javac;
40
 
41
import gnu.classpath.Configuration;
42
import java.io.File;
43
import java.io.PrintWriter;
44
import java.lang.reflect.Constructor;
45
import java.lang.reflect.Method;
46
import java.net.MalformedURLException;
47
import java.net.URL;
48
import java.net.URLClassLoader;
49
import java.text.MessageFormat;
50
 
51
public class Main
52
{
53
  static Constructor ecjConstructor = null;
54
  static Method ecjMethod = null;
55
 
56
  static
57
  {
58
    String classname = "org.eclipse.jdt.internal.compiler.batch.Main";
59
    Class klass = null;
60
    try
61
      {
62
        klass = Class.forName(classname);
63
      }
64
    catch (ClassNotFoundException e)
65
      {
66
        File jar = new File(Configuration.ECJ_JAR);
67
        if (!jar.exists() || !jar.canRead())
68
          {
69
            String message
70
              = MessageFormat.format(Messages.getString("Main.FailedToRead"),
71
                                     new Object[] { Configuration.ECJ_JAR });
72
            System.err.println(message);
73
          }
74
 
75
        ClassLoader loader = null;
76
        try
77
          {
78
            loader = new URLClassLoader(new URL[] {jar.toURL()});
79
          }
80
        catch (MalformedURLException f)
81
          {
82
            String message
83
              = MessageFormat.format(Messages.getString("Main.MalformedURL"),
84
                                     new Object[] { Configuration.ECJ_JAR });
85
            System.err.println(message);
86
            f.printStackTrace();
87
          }
88
 
89
        try
90
          {
91
            klass = loader.loadClass(classname);
92
          }
93
        catch (ClassNotFoundException g)
94
          {
95
            String message
96
              = MessageFormat.format(Messages.getString("Main.FailedToLoad"),
97
                                     new Object[] { classname,
98
                                                    Configuration.ECJ_JAR });
99
            System.err.println(message);
100
            g.printStackTrace();
101
          }
102
      }
103
 
104
    try
105
      {
106
        ecjConstructor = klass.getConstructor(new Class[] {
107
                                                PrintWriter.class,
108
                                                PrintWriter.class,
109
                                                Boolean.TYPE});
110
      }
111
    catch (NoSuchMethodException h)
112
      {
113
        System.err.println(Messages.getString("Main.FailedConstructor"));
114
        h.printStackTrace();
115
      }
116
 
117
    try
118
      {
119
        ecjMethod = klass.getMethod("compile", new Class[] {String[].class});
120
      }
121
    catch (NoSuchMethodException i)
122
      {
123
        System.err.println(Messages.getString("Main.FailedCompile"));
124
        i.printStackTrace();
125
      }
126
  }
127
 
128
  public static int compile(String[] args, PrintWriter p) throws Exception
129
  {
130
    /*
131
     * This code depends on the patch in Comment #10 in this bug
132
     * report:
133
     *
134
     * https://bugs.eclipse.org/bugs/show_bug.cgi?id=88364
135
     */
136
    Object ecjInstance = ecjConstructor.newInstance(new Object[]
137
        {
138
          p,
139
          new PrintWriter(System.err),
140
          Boolean.FALSE
141
        });
142
    String[] runArgs = new String[args.length + 1];
143
    runArgs[0] = "-1.5";
144
    System.arraycopy(args, 0, runArgs, 1, args.length);
145
    return ((Boolean) ecjMethod.invoke(ecjInstance, new Object[]
146
        { runArgs })).booleanValue() ? 0 : -1;
147
  }
148
 
149
  public static int compile(String[] args) throws Exception
150
  {
151
    return compile(args, new PrintWriter(System.out));
152
  }
153
 
154
  public static void main(String[] args) throws Exception
155
  {
156
    Runtime.getRuntime().exit(Main.compile(args));
157
  }
158
}

powered by: WebSVN 2.1.0

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