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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [tools/] [gnu/] [classpath/] [tools/] [javah/] [JniIncludePrinter.java] - Blame information for rev 779

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 779 jeremybenn
/* JniIncludePrinter.java - Generate a JNI header file
2
 Copyright (C) 2006, 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 gnu.classpath.tools.javah;
40
 
41
import java.io.File;
42
import java.io.FileOutputStream;
43
import java.io.IOException;
44
import java.io.PrintStream;
45
import java.lang.reflect.Modifier;
46
import java.util.Iterator;
47
 
48
import org.objectweb.asm.Type;
49
import org.objectweb.asm.tree.FieldNode;
50
import org.objectweb.asm.tree.MethodNode;
51
 
52
public class JniIncludePrinter
53
    extends Printer
54
{
55
  protected JniIncludePrinter(Main classpath, File outFile, boolean isDir,
56
                              boolean force)
57
  {
58
    super(classpath, outFile, isDir, force);
59
  }
60
 
61
  private void writeFields(ClassWrapper klass, JniPrintStream out)
62
    throws IOException
63
  {
64
    klass.linkSupers();
65
    boolean wroteAny = false;
66
    for (; klass != null; klass = klass.superClass)
67
      {
68
        Iterator<?> i = klass.fields.iterator();
69
        while (i.hasNext())
70
          {
71
            FieldNode field = (FieldNode) i.next();
72
            if (! Modifier.isStatic(field.access)
73
                || ! Modifier.isFinal(field.access))
74
              continue;
75
            if (! (field.value instanceof Integer)
76
                && ! (field.value instanceof Long))
77
              continue;
78
 
79
            // Note that we don't want to mangle the field name.
80
            String name = (JniHelper.mangle(klass.name) + "_" + field.name);
81
            out.print("#undef ");
82
            out.println(name);
83
            out.print("#define ");
84
            out.print(name);
85
            out.print(" ");
86
            out.print(field.value);
87
            if (field.value instanceof Integer)
88
              out.print("L");
89
            else if (field.value instanceof Long)
90
              out.print("LL");
91
            out.println();
92
            wroteAny = true;
93
          }
94
      }
95
    if (wroteAny)
96
      out.println();
97
  }
98
 
99
  protected void writePreambleImpl(PrintStream out)
100
  {
101
    out.println("/* DO NOT EDIT THIS FILE - it is machine generated */");
102
    out.println();
103
    out.println("#include <jni.h>");
104
  }
105
 
106
  protected PrintStream getPrintStreamImpl(FileOutputStream fos,
107
                                           ClassWrapper klass)
108
  {
109
    return new JniPrintStream(classpath, fos, klass);
110
  }
111
 
112
  public void printClass(File file, ClassWrapper klass) throws IOException
113
  {
114
    // Note that we ignore the filename here.
115
    String xname = JniHelper.mangle(klass.name);
116
 
117
    // mangle the filename a bit
118
    String filename = klass.name;
119
 
120
    filename = filename.replace('/', '_');
121
    filename = filename.replace('$', '_');
122
    filename = filename + ".h";
123
 
124
    JniPrintStream out = (JniPrintStream) getPrintStream(filename, klass);
125
 
126
    if (out == null)
127
      return;
128
 
129
    out.println();
130
    out.print("#ifndef __");
131
    out.print(xname);
132
    out.println("__");
133
    out.print("#define __");
134
    out.print(xname);
135
    out.println("__");
136
    out.println();
137
    out.println("#ifdef __cplusplus");
138
    out.println("extern \"C\"");
139
    out.println("{");
140
    out.println("#endif");
141
    out.println();
142
 
143
    Iterator<?> i = klass.methods.iterator();
144
    while (i.hasNext())
145
      {
146
        MethodNode method = (MethodNode) i.next();
147
        if (! Modifier.isNative(method.access))
148
          continue;
149
        out.print("JNIEXPORT ");
150
        out.print(Type.getReturnType(method.desc));
151
        out.print(" JNICALL ");
152
        out.print(method, xname);
153
        out.println(";");
154
      }
155
 
156
    out.println();
157
 
158
    writeFields(klass, out);
159
 
160
    out.println("#ifdef __cplusplus");
161
    out.println("}");
162
    out.println("#endif");
163
    out.println();
164
    out.print("#endif /* __");
165
    out.print(xname);
166
    out.println("__ */");
167
    out.close();
168
  }
169
}

powered by: WebSVN 2.1.0

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