summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/classes/com/sun/gluegen/CMethodBindingEmitter.java23
-rw-r--r--src/classes/com/sun/gluegen/DebugEmitter.java3
-rw-r--r--src/classes/com/sun/gluegen/FunctionEmitter.java26
-rw-r--r--src/classes/com/sun/gluegen/GlueEmitter.java21
-rw-r--r--src/classes/com/sun/gluegen/GlueGen.java16
-rw-r--r--src/classes/com/sun/gluegen/JavaEmitter.java345
-rw-r--r--src/classes/com/sun/gluegen/JavaMethodBindingEmitter.java23
-rw-r--r--src/classes/com/sun/gluegen/StructLayout.java37
-rw-r--r--src/classes/com/sun/gluegen/cgram/HeaderParser.g52
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/ArrayType.java4
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/CompoundType.java6
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/DoubleType.java2
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/EnumType.java12
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/Field.java23
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/FloatType.java2
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/FunctionType.java2
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/IntType.java4
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/PointerType.java6
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/PrimitiveType.java2
-rwxr-xr-xsrc/classes/com/sun/gluegen/cgram/types/SizeThunk.java171
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/Type.java18
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/VoidType.java2
-rwxr-xr-xsrc/classes/com/sun/gluegen/opengl/GLCMethodBindingEmitter.java1
-rwxr-xr-xsrc/classes/com/sun/gluegen/runtime/CPU.java75
-rw-r--r--src/classes/com/sun/opengl/impl/NativeLibLoader.java2
-rw-r--r--src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLDrawable.java4
-rw-r--r--src/classes/com/sun/opengl/impl/windows/WindowsGLDrawable.java2
-rw-r--r--src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLDrawable.java2
-rw-r--r--src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLDrawable.java2
-rw-r--r--src/classes/com/sun/opengl/impl/x11/X11GLDrawable.java4
-rw-r--r--src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java4
-rw-r--r--src/native/jogl/JAWT_DrawingSurfaceInfo.c10
32 files changed, 653 insertions, 253 deletions
diff --git a/src/classes/com/sun/gluegen/CMethodBindingEmitter.java b/src/classes/com/sun/gluegen/CMethodBindingEmitter.java
index 70877ff5e..a1cae8d51 100644
--- a/src/classes/com/sun/gluegen/CMethodBindingEmitter.java
+++ b/src/classes/com/sun/gluegen/CMethodBindingEmitter.java
@@ -120,6 +120,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
*/
public CMethodBindingEmitter(MethodBinding binding,
PrintWriter output,
+ MachineDescription defaultMachDesc,
String javaPackageName,
String javaClassName,
boolean isOverloadedBinding,
@@ -127,7 +128,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
boolean forImplementingMethodCall,
boolean forIndirectBufferAndArrayImplementation)
{
- super(output);
+ super(output, defaultMachDesc);
assert(binding != null);
assert(javaClassName != null);
@@ -381,7 +382,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
}
- protected void emitBody(PrintWriter writer)
+ protected void emitBody(PrintWriter writer, MachineDescription machDesc)
{
writer.println(" {");
emitBodyVariableDeclarations(writer);
@@ -392,7 +393,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
emitBodyUserVariableAssignments(writer);
emitBodyVariablePostCallCleanup(writer, true);
emitBodyVariablePostCallCleanup(writer, false);
- emitBodyReturnResult(writer);
+ emitBodyReturnResult(writer, machDesc);
writer.println("}");
writer.println();
}
@@ -965,7 +966,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
}
}
- protected void emitBodyReturnResult(PrintWriter writer)
+ protected void emitBodyReturnResult(PrintWriter writer, MachineDescription machDesc)
{
// WARNING: this code assumes that the return type has already been
// typedef-resolved.
@@ -996,11 +997,11 @@ public class CMethodBindingEmitter extends FunctionEmitter
writer.print(
returnValueCapacityExpression.format(argumentNames));
} else {
- int sz = 0;
+ SizeThunk sz = null;
if (cReturnType.isPointer() &&
cReturnType.asPointer().getTargetType().isCompound()) {
sz = cReturnType.asPointer().getTargetType().getSize();
- if (sz == -1) {
+ if (sz == null) {
throw new RuntimeException(
"Error emitting code for compound return type "+
"for function \"" + binding + "\": " +
@@ -1012,7 +1013,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
} else {
sz = cReturnType.getSize();
}
- writer.print(sz);
+ writer.print(sz.compute(machDesc));
System.err.println(
"WARNING: No capacity specified for java.nio.Buffer return " +
"value for function \"" + binding + "\";" +
@@ -1043,11 +1044,11 @@ public class CMethodBindingEmitter extends FunctionEmitter
} else {
baseType = retType.asArray().getElementType().asPointer().getTargetType();
}
- int sz = baseType.getSize();
- if (sz < 0)
- sz = 0;
+ SizeThunk sz = baseType.getSize();
+ if (sz == null)
+ sz = SizeThunk.constant(0);
writer.println(" (*env)->SetObjectArrayElement(env, " + arrayRes + ", " + arrayIdx +
- ", (*env)->NewDirectByteBuffer(env, _res[" + arrayIdx + "], " + sz + "));");
+ ", (*env)->NewDirectByteBuffer(env, _res[" + arrayIdx + "], " + sz.compute(machDesc) + "));");
writer.println(" }");
writer.println(" return " + arrayRes + ";");
} else if (javaReturnType.isArray()) {
diff --git a/src/classes/com/sun/gluegen/DebugEmitter.java b/src/classes/com/sun/gluegen/DebugEmitter.java
index bbcde0e0d..40d6c2dc0 100644
--- a/src/classes/com/sun/gluegen/DebugEmitter.java
+++ b/src/classes/com/sun/gluegen/DebugEmitter.java
@@ -48,7 +48,8 @@ import com.sun.gluegen.cgram.types.*;
public class DebugEmitter implements GlueEmitter {
public void readConfigurationFile(String filename) {}
- public void setMachineDescription(MachineDescription md) {}
+ public void setMachineDescription(MachineDescription md32,
+ MachineDescription md64) {}
public void beginEmission(GlueEmitterControls controls) {
System.out.println("----- BEGIN EMISSION OF GLUE CODE -----");
diff --git a/src/classes/com/sun/gluegen/FunctionEmitter.java b/src/classes/com/sun/gluegen/FunctionEmitter.java
index baf08b93a..2f52a9f36 100644
--- a/src/classes/com/sun/gluegen/FunctionEmitter.java
+++ b/src/classes/com/sun/gluegen/FunctionEmitter.java
@@ -41,6 +41,7 @@ package com.sun.gluegen;
import java.util.*;
import java.io.*;
+import com.sun.gluegen.cgram.types.MachineDescription;
public abstract class FunctionEmitter
{
@@ -49,14 +50,16 @@ public abstract class FunctionEmitter
private HashSet modifiers = new HashSet(4);
private CommentEmitter commentEmitter = null;
private PrintWriter defaultOutput;
+ private MachineDescription defaultMachDesc;
/**
* Constructs the FunctionEmitter with a CommentEmitter that emits nothing.
*/
- public FunctionEmitter(PrintWriter defaultOutput)
+ public FunctionEmitter(PrintWriter defaultOutput, MachineDescription defaultMachDesc)
{
assert(defaultOutput != null);
this.defaultOutput = defaultOutput;
+ this.defaultMachDesc = defaultMachDesc;
}
/**
@@ -66,9 +69,12 @@ public abstract class FunctionEmitter
modifiers = (HashSet) arg.modifiers.clone();
commentEmitter = arg.commentEmitter;
defaultOutput = arg.defaultOutput;
+ defaultMachDesc = arg.defaultMachDesc;
}
public PrintWriter getDefaultOutput() { return defaultOutput; }
+
+ public MachineDescription getDefaultMachineDescription() { return defaultMachDesc; }
public void addModifiers(Iterator/*<EmissionModifier>*/ mi)
{
@@ -93,29 +99,35 @@ public abstract class FunctionEmitter
* Emit the function to the specified output (instead of the default
* output).
*/
- public void emit(PrintWriter output)
+ public void emit(PrintWriter output, MachineDescription machDesc)
{
emitDocComment(output);
//output.println(" // Emitter: " + getClass().getName());
emitSignature(output);
- emitBody(output);
+ emitBody(output, machDesc);
}
/**
* Emit the function to the default output (the output that was passed to
* the constructor)
*/
- public final void emit()
+ public final void emit(MachineDescription machDesc)
{
- emit(getDefaultOutput());
+ emit(getDefaultOutput(), machDesc);
}
/** Returns, as a String, whatever {@link #emit} would output. */
public String toString()
{
+ return toString(getDefaultMachineDescription());
+ }
+
+ /** Returns, as a String, whatever {@link #emit} would output. */
+ public String toString(MachineDescription machDesc)
+ {
StringWriter sw = new StringWriter(500);
PrintWriter w = new PrintWriter(sw);
- emit(w);
+ emit(w, machDesc);
return sw.toString();
}
@@ -195,7 +207,7 @@ public abstract class FunctionEmitter
protected abstract void emitName(PrintWriter writer);
/** Returns the number of arguments emitted. */
protected abstract int emitArguments(PrintWriter writer);
- protected abstract void emitBody(PrintWriter writer);
+ protected abstract void emitBody(PrintWriter writer, MachineDescription machDesc);
public static class EmissionModifier
{
diff --git a/src/classes/com/sun/gluegen/GlueEmitter.java b/src/classes/com/sun/gluegen/GlueEmitter.java
index d6f5fede8..e21bc8764 100644
--- a/src/classes/com/sun/gluegen/GlueEmitter.java
+++ b/src/classes/com/sun/gluegen/GlueEmitter.java
@@ -50,8 +50,25 @@ public interface GlueEmitter {
public void readConfigurationFile(String filename) throws Exception;
- /** Set the description of the underlying hardware. */
- public void setMachineDescription(MachineDescription md);
+ /** Sets the description of the underlying hardware. "md32"
+ specifies the description of a 32-bit version of the underlying
+ CPU architecture. "md64" specifies the description of a 64-bit
+ version of the underlying CPU architecture. At least one must be
+ specified. When both are specified, the bulk of the glue code is
+ generated using the 32-bit machine description, but structs are
+ laid out twice and the base class delegates between the 32-bit
+ and 64-bit implementation at run time. This allows Java code
+ which can access both 32-bit and 64-bit versions of the data
+ structures to be included in the same jar file. <P>
+
+ It is up to the end user to provide the appropriate opaque
+ definitions to ensure that types of varying size (longs and
+ pointers in particular) are exposed to Java in such a way that
+ changing the machine description does not cause different shared
+ glue code to be generated for the 32- and 64-bit ports.
+ */
+ public void setMachineDescription(MachineDescription md32,
+ MachineDescription md64);
/**
* Begin the emission of glue code. This might include opening files,
diff --git a/src/classes/com/sun/gluegen/GlueGen.java b/src/classes/com/sun/gluegen/GlueGen.java
index c192ae8cd..a7c64a840 100644
--- a/src/classes/com/sun/gluegen/GlueGen.java
+++ b/src/classes/com/sun/gluegen/GlueGen.java
@@ -146,16 +146,6 @@ public class GlueGen implements GlueEmitterControls {
}
HeaderParser headerParser = new HeaderParser();
- MachineDescription machDesc;
- String os = System.getProperty("os.name").toLowerCase();
- String cpu = System.getProperty("os.arch").toLowerCase();
- if ((os.startsWith("linux") && cpu.equals("amd64")) ||
- (os.startsWith("linux") && cpu.equals("ia64"))) {
- machDesc = new MachineDescription64Bit();
- } else {
- machDesc = new MachineDescription32Bit();
- }
- headerParser.setMachineDescription(machDesc);
TypeDictionary td = new TypeDictionary();
headerParser.setTypedefDictionary(td);
TypeDictionary sd = new TypeDictionary();
@@ -190,8 +180,10 @@ public class GlueGen implements GlueEmitterControls {
emit.readConfigurationFile((String) iter.next());
}
- // provide MachineDescription to emitter if it needs it
- emit.setMachineDescription(machDesc);
+ // Provide MachineDescriptions to emitter
+ MachineDescription md32 = new MachineDescription32Bit();
+ MachineDescription md64 = new MachineDescription64Bit();
+ emit.setMachineDescription(md32, md64);
// begin emission of glue code
emit.beginEmission(this);
diff --git a/src/classes/com/sun/gluegen/JavaEmitter.java b/src/classes/com/sun/gluegen/JavaEmitter.java
index 24687d36f..85ba363a1 100644
--- a/src/classes/com/sun/gluegen/JavaEmitter.java
+++ b/src/classes/com/sun/gluegen/JavaEmitter.java
@@ -85,14 +85,27 @@ public class JavaEmitter implements GlueEmitter {
private PrintWriter javaImplWriter; // Only used in non-AllStatic modes for impl class
private PrintWriter cWriter;
private MachineDescription machDesc;
+ private MachineDescription machDesc32;
+ private MachineDescription machDesc64;
public void readConfigurationFile(String filename) throws Exception {
cfg = createConfig();
cfg.read(filename);
}
- public void setMachineDescription(MachineDescription md) {
- machDesc = md;
+ public void setMachineDescription(MachineDescription md32,
+ MachineDescription md64) {
+ if ((md32 == null) && (md64 == null)) {
+ throw new RuntimeException("Must specify at least one MachineDescription");
+ }
+
+ machDesc32 = md32;
+ machDesc64 = md64;
+ if (machDesc32 == null) {
+ machDesc = machDesc64;
+ } else {
+ machDesc = machDesc32;
+ }
}
public void beginEmission(GlueEmitterControls controls) throws IOException
@@ -280,7 +293,7 @@ public class JavaEmitter implements GlueEmitter {
for (int i = 0; i < methodBindingEmitters.size(); ++i) {
FunctionEmitter emitter = (FunctionEmitter)methodBindingEmitters.get(i);
try {
- emitter.emit();
+ emitter.emit(machDesc);
} catch (Exception e) {
throw new RuntimeException(
"Error while emitting binding for \"" + emitter.getName() + "\"", e);
@@ -341,6 +354,7 @@ public class JavaEmitter implements GlueEmitter {
JavaMethodBindingEmitter emitter =
new JavaMethodBindingEmitter(binding,
writer,
+ machDesc,
cfg.runtimeExceptionType(),
!signatureOnly && needsBody,
false,
@@ -403,6 +417,7 @@ public class JavaEmitter implements GlueEmitter {
JavaMethodBindingEmitter emitter =
new JavaMethodBindingEmitter(binding,
writer,
+ machDesc,
cfg.runtimeExceptionType(),
false,
true,
@@ -427,6 +442,7 @@ public class JavaEmitter implements GlueEmitter {
emitter =
new JavaMethodBindingEmitter(binding,
writer,
+ machDesc,
cfg.runtimeExceptionType(),
false,
true,
@@ -487,6 +503,7 @@ public class JavaEmitter implements GlueEmitter {
CMethodBindingEmitter cEmitter =
new CMethodBindingEmitter(binding,
cWriter(),
+ machDesc,
cfg.implPackageName(),
cfg.implClassName(),
true, /* NOTE: we always disambiguate with a suffix now, so this is optional */
@@ -511,6 +528,7 @@ public class JavaEmitter implements GlueEmitter {
cEmitter =
new CMethodBindingEmitter(binding,
cWriter(),
+ machDesc,
cfg.implPackageName(),
cfg.implClassName(),
true, /* NOTE: we always disambiguate with a suffix now, so this is optional */
@@ -642,6 +660,22 @@ public class JavaEmitter implements GlueEmitter {
}
public void emitStruct(CompoundType structType, String alternateName) throws Exception {
+ // Emit abstract base class delegating to 32-bit or 64-bit implementations
+ emitStructImpl(structType, alternateName, true, machDesc32, machDesc64);
+ // Emit concrete implementing class for each variant
+ if (machDesc32 != null) {
+ emitStructImpl(structType, alternateName, false, machDesc32, null);
+ }
+ if (machDesc64 != null) {
+ emitStructImpl(structType, alternateName, false, null, machDesc64);
+ }
+ }
+
+ public void emitStructImpl(CompoundType structType,
+ String alternateName,
+ boolean isAbstractBaseClass,
+ MachineDescription md32,
+ MachineDescription md64) throws Exception {
String name = structType.getName();
if (name == null && alternateName != null) {
name = alternateName;
@@ -656,18 +690,42 @@ public class JavaEmitter implements GlueEmitter {
return;
}
- Type containingCType = canonicalize(new PointerType(machDesc.pointerSizeInBytes(), structType, 0));
+ Type containingCType = canonicalize(new PointerType(SizeThunk.POINTER, structType, 0));
JavaType containingType = typeToJavaType(containingCType, false);
if (!containingType.isCompoundTypeWrapper()) {
return;
}
String containingTypeName = containingType.getName();
+ if ((md32 == null) && (md64 == null)) {
+ throw new RuntimeException("Must supply at least one MachineDescription to emitStructImpl");
+ }
+ String suffix = "";
+ MachineDescription curMachDesc = null;
+ if (!isAbstractBaseClass) {
+ if ((md32 != null) && (md64 != null)) {
+ throw new RuntimeException("Must supply at most one MachineDescription to emitStructImpl when emitting concrete classes");
+ }
+
+ if (md32 != null) {
+ suffix = "32";
+ curMachDesc = md32;
+ } else {
+ suffix = "64";
+ curMachDesc = md64;
+ }
+ }
+
boolean needsNativeCode = false;
- for (int i = 0; i < structType.getNumFields(); i++) {
- if (structType.getField(i).getType().isFunctionPointer()) {
- needsNativeCode = true;
- break;
+ // Native code for calls through function pointers gets emitted
+ // into the abstract base class; Java code which accesses fields
+ // gets emitted into the concrete classes
+ if (isAbstractBaseClass) {
+ for (int i = 0; i < structType.getNumFields(); i++) {
+ if (structType.getField(i).getType().isFunctionPointer()) {
+ needsNativeCode = true;
+ break;
+ }
}
}
@@ -679,7 +737,7 @@ public class JavaEmitter implements GlueEmitter {
writer = openFile(
cfg.javaOutputDir() + File.separator +
CodeGenUtils.packageAsPath(structClassPkg) +
- File.separator + containingTypeName + ".java");
+ File.separator + containingTypeName + suffix + ".java");
CodeGenUtils.emitAutogeneratedWarning(writer, this);
if (needsNativeCode) {
String nRoot = cfg.nativeOutputDir();
@@ -717,7 +775,10 @@ public class JavaEmitter implements GlueEmitter {
writer.println((String) iter.next());
}
writer.println();
- writer.print("public class " + containingTypeName + " ");
+ writer.print((isAbstractBaseClass ? "public " : "") + (isAbstractBaseClass ? "abstract " : "") + "class " + containingTypeName + suffix + " ");
+ if (!isAbstractBaseClass) {
+ writer.print("extends " + containingTypeName + " ");
+ }
boolean firstIteration = true;
List/*<String>*/ userSpecifiedInterfaces = cfg.implementedInterfaces(containingTypeName);
for (Iterator iter = userSpecifiedInterfaces.iterator(); iter.hasNext(); ) {
@@ -729,81 +790,127 @@ public class JavaEmitter implements GlueEmitter {
writer.print(" ");
}
writer.println("{");
- writer.println(" private StructAccessor accessor;");
- writer.println();
+ if (isAbstractBaseClass) {
+ writer.println(" StructAccessor accessor;");
+ writer.println();
+ }
writer.println(" public static int size() {");
- writer.println(" return " + structType.getSize() + ";");
- writer.println(" }");
- writer.println();
- writer.println(" public " + containingTypeName + "() {");
- writer.println(" this(BufferFactory.newDirectByteBuffer(size()));");
- writer.println(" }");
- writer.println();
- writer.println(" public " + containingTypeName + "(ByteBuffer buf) {");
- writer.println(" accessor = new StructAccessor(buf);");
+ if (isAbstractBaseClass) {
+ writer.println(" if (CPU.is32Bit()) {");
+ if (md32 == null) {
+ writer.println(" throw new " + cfg.runtimeExceptionType() + "(\"32-bit architectures not supported with this autogenerated code\");");
+ } else {
+ writer.println(" return " + containingTypeName + "32" + ".size();");
+ }
+ writer.println(" } else {");
+ if (md64 == null) {
+ writer.println(" throw new " + cfg.runtimeExceptionType() + "(\"64-bit architectures not supported with this autogenerated code\");");
+ } else {
+ writer.println(" return " + containingTypeName + "64" + ".size();");
+ }
+ writer.println(" }");
+ } else {
+ writer.println(" return " + structType.getSize(curMachDesc) + ";");
+ }
writer.println(" }");
writer.println();
- writer.println(" public ByteBuffer getBuffer() {");
- writer.println(" return accessor.getBuffer();");
- writer.println(" }");
+ if (isAbstractBaseClass) {
+ writer.println(" public static " + containingTypeName + " create() {");
+ writer.println(" return create(BufferFactory.newDirectByteBuffer(size()));");
+ writer.println(" }");
+ writer.println();
+ writer.println(" public static " + containingTypeName + " create(ByteBuffer buf) {");
+ writer.println(" if (CPU.is32Bit()) {");
+ if (md32 == null) {
+ writer.println(" throw new " + cfg.runtimeExceptionType() + "(\"32-bit architectures not supported with this autogenerated code\");");
+ } else {
+ writer.println(" return new " + containingTypeName + "32(buf);");
+ }
+ writer.println(" } else {");
+ if (md64 == null) {
+ writer.println(" throw new " + cfg.runtimeExceptionType() + "(\"64-bit architectures not supported with this autogenerated code\");");
+ } else {
+ writer.println(" return new " + containingTypeName + "64(buf);");
+ }
+ writer.println(" }");
+ writer.println(" }");
+ writer.println();
+ writer.println(" " + containingTypeName + "(ByteBuffer buf) {");
+ writer.println(" accessor = new StructAccessor(buf);");
+ writer.println(" }");
+ writer.println();
+ writer.println(" public ByteBuffer getBuffer() {");
+ writer.println(" return accessor.getBuffer();");
+ writer.println(" }");
+ } else {
+ writer.println(" " + containingTypeName + suffix + "(ByteBuffer buf) {");
+ writer.println(" super(buf);");
+ writer.println(" }");
+ writer.println();
+ }
for (int i = 0; i < structType.getNumFields(); i++) {
Field field = structType.getField(i);
Type fieldType = field.getType();
if (!cfg.shouldIgnore(name + " " + field.getName())) {
if (fieldType.isFunctionPointer()) {
- try {
- // Emit method call and associated native code
- FunctionType funcType = fieldType.asPointer().getTargetType().asFunction();
- FunctionSymbol funcSym = new FunctionSymbol(field.getName(), funcType);
- MethodBinding binding = bindFunction(funcSym, containingType, containingCType);
- binding.findThisPointer(); // FIXME: need to provide option to disable this on per-function basis
- writer.println();
-
- // Emit public Java entry point for calling this function pointer
- JavaMethodBindingEmitter emitter =
- new JavaMethodBindingEmitter(binding,
- writer,
- cfg.runtimeExceptionType(),
- true,
- false,
- true, // FIXME: should unify this with the general emission code
- false,
- false, // FIXME: should unify this with the general emission code
- false, // FIXME: should unify this with the general emission code
- false);
- emitter.addModifier(JavaMethodBindingEmitter.PUBLIC);
- emitter.emit();
-
- // Emit private native Java entry point for calling this function pointer
- emitter =
- new JavaMethodBindingEmitter(binding,
- writer,
- cfg.runtimeExceptionType(),
- false,
- true,
- true, // FIXME: should unify this with the general emission code
- true,
- true, // FIXME: should unify this with the general emission code
- false, // FIXME: should unify this with the general emission code
- false);
- emitter.addModifier(JavaMethodBindingEmitter.PRIVATE);
- emitter.addModifier(JavaMethodBindingEmitter.NATIVE);
- emitter.emit();
-
- // Emit (private) C entry point for calling this function pointer
- CMethodBindingEmitter cEmitter =
- new CMethodBindingEmitter(binding,
- cWriter,
- structClassPkg,
- containingTypeName,
- true, // FIXME: this is optional at this point
- false,
- true,
- false); // FIXME: should unify this with the general emission code
- cEmitter.emit();
- } catch (Exception e) {
- System.err.println("While processing field " + field + " of type " + name + ":");
- throw(e);
+ if (isAbstractBaseClass) {
+ try {
+ // Emit method call and associated native code
+ FunctionType funcType = fieldType.asPointer().getTargetType().asFunction();
+ FunctionSymbol funcSym = new FunctionSymbol(field.getName(), funcType);
+ MethodBinding binding = bindFunction(funcSym, containingType, containingCType);
+ binding.findThisPointer(); // FIXME: need to provide option to disable this on per-function basis
+ writer.println();
+
+ // Emit public Java entry point for calling this function pointer
+ JavaMethodBindingEmitter emitter =
+ new JavaMethodBindingEmitter(binding,
+ writer,
+ machDesc,
+ cfg.runtimeExceptionType(),
+ true,
+ false,
+ true, // FIXME: should unify this with the general emission code
+ false,
+ false, // FIXME: should unify this with the general emission code
+ false, // FIXME: should unify this with the general emission code
+ false);
+ emitter.addModifier(JavaMethodBindingEmitter.PUBLIC);
+ emitter.emit(machDesc);
+
+ // Emit private native Java entry point for calling this function pointer
+ emitter =
+ new JavaMethodBindingEmitter(binding,
+ writer,
+ machDesc,
+ cfg.runtimeExceptionType(),
+ false,
+ true,
+ true, // FIXME: should unify this with the general emission code
+ true,
+ true, // FIXME: should unify this with the general emission code
+ false, // FIXME: should unify this with the general emission code
+ false);
+ emitter.addModifier(JavaMethodBindingEmitter.PRIVATE);
+ emitter.addModifier(JavaMethodBindingEmitter.NATIVE);
+ emitter.emit(machDesc);
+
+ // Emit (private) C entry point for calling this function pointer
+ CMethodBindingEmitter cEmitter =
+ new CMethodBindingEmitter(binding,
+ cWriter,
+ machDesc,
+ structClassPkg,
+ containingTypeName,
+ true, // FIXME: this is optional at this point
+ false,
+ true,
+ false); // FIXME: should unify this with the general emission code
+ cEmitter.emit(machDesc);
+ } catch (Exception e) {
+ System.err.println("While processing field " + field + " of type " + name + ":");
+ throw(e);
+ }
}
} else if (fieldType.isCompound()) {
// FIXME: will need to support this at least in order to
@@ -815,15 +922,21 @@ public class JavaEmitter implements GlueEmitter {
}
writer.println();
- writer.println(" public " + fieldType.getName() + " " + field.getName() + "() {");
- writer.println(" return new " + fieldType.getName() + "(accessor.slice(" +
- field.getOffset() + ", " + fieldType.getSize() + "));");
- writer.println(" }");
-
+ writer.print(" public " + (isAbstractBaseClass ? "abstract " : "") + fieldType.getName() + " " + field.getName() + "()");
+ if (isAbstractBaseClass) {
+ writer.println(";");
+ } else {
+ writer.println(" {");
+ writer.println(" return " + fieldType.getName() + ".create(accessor.slice(" +
+ field.getOffset(machDesc) + ", " + fieldType.getSize(machDesc) + "));");
+ writer.println(" }");
+ }
// FIXME: add setter by autogenerating "copyTo" for all compound type wrappers
} else if (fieldType.isArray()) {
- System.err.println("WARNING: Array fields (field \"" + field + "\" of type \"" + name +
- "\") not implemented yet");
+ if (!isAbstractBaseClass) {
+ System.err.println("WARNING: Array fields (field \"" + field + "\" of type \"" + name +
+ "\") not implemented yet");
+ }
} else {
JavaType javaType = null;
try {
@@ -843,26 +956,36 @@ public class JavaEmitter implements GlueEmitter {
}
String capitalized =
"" + Character.toUpperCase(internalJavaTypeName.charAt(0)) + internalJavaTypeName.substring(1);
- int slot = slot(fieldType, (int) field.getOffset());
+ int slot = slot(fieldType, (int) field.getOffset(machDesc));
// Setter
writer.println();
- writer.println(" public " + containingTypeName + " " + field.getName() + "(" + externalJavaTypeName + " val) {");
- writer.print (" accessor.set" + capitalized + "At(" + slot + ", ");
- if (!externalJavaTypeName.equals(internalJavaTypeName)) {
- writer.print("(" + internalJavaTypeName + ") ");
+ writer.print(" public " + (isAbstractBaseClass ? "abstract " : "") + containingTypeName + " " + field.getName() + "(" + externalJavaTypeName + " val)");
+ if (isAbstractBaseClass) {
+ writer.println(";");
+ } else {
+ writer.println(" {");
+ writer.print (" accessor.set" + capitalized + "At(" + slot + ", ");
+ if (!externalJavaTypeName.equals(internalJavaTypeName)) {
+ writer.print("(" + internalJavaTypeName + ") ");
+ }
+ writer.println("val);");
+ writer.println(" return this;");
+ writer.println(" }");
}
- writer.println("val);");
- writer.println(" return this;");
- writer.println(" }");
- // Getter
writer.println();
- writer.println(" public " + externalJavaTypeName + " " + field.getName() + "() {");
- writer.print (" return ");
- if (!externalJavaTypeName.equals(internalJavaTypeName)) {
- writer.print("(" + externalJavaTypeName + ") ");
+ // Getter
+ writer.print(" public " + (isAbstractBaseClass ? "abstract " : "") + externalJavaTypeName + " " + field.getName() + "()");
+ if (isAbstractBaseClass) {
+ writer.println(";");
+ } else {
+ writer.println(" {");
+ writer.print (" return ");
+ if (!externalJavaTypeName.equals(internalJavaTypeName)) {
+ writer.print("(" + externalJavaTypeName + ") ");
+ }
+ writer.println("accessor.get" + capitalized + "At(" + slot + ");");
+ writer.println(" }");
}
- writer.println("accessor.get" + capitalized + "At(" + slot + ");");
- writer.println(" }");
} else {
// FIXME
System.err.println("WARNING: Complicated fields (field \"" + field + "\" of type \"" + name +
@@ -873,7 +996,9 @@ public class JavaEmitter implements GlueEmitter {
}
}
}
- emitCustomJavaCode(writer, containingTypeName);
+ if (isAbstractBaseClass) {
+ emitCustomJavaCode(writer, containingTypeName);
+ }
writer.println("}");
writer.flush();
writer.close();
@@ -904,13 +1029,13 @@ public class JavaEmitter implements GlueEmitter {
}
Type t = cType;
if (t.isInt() || t.isEnum()) {
- switch (t.getSize()) {
+ switch ((int) t.getSize(machDesc)) {
case 1: return javaType(Byte.TYPE);
case 2: return javaType(Short.TYPE);
case 4: return javaType(Integer.TYPE);
case 8: return javaType(Long.TYPE);
default: throw new RuntimeException("Unknown integer type of size " +
- t.getSize() + " and name " + t.getName());
+ t.getSize(machDesc) + " and name " + t.getName());
}
} else if (t.isFloat()) {
return javaType(Float.TYPE);
@@ -936,13 +1061,13 @@ public class JavaEmitter implements GlueEmitter {
if (targetType.isVoid()) {
return JavaType.createForVoidPointer();
} else if (targetType.isInt()) {
- switch (targetType.getSize()) {
+ switch ((int) targetType.getSize(machDesc)) {
case 1: return JavaType.createForCCharPointer();
case 2: return JavaType.createForCShortPointer();
case 4: return JavaType.createForCInt32Pointer();
case 8: return JavaType.createForCInt64Pointer();
default: throw new RuntimeException("Unknown integer array type of size " +
- t.getSize() + " and name " + t.getName());
+ t.getSize(machDesc) + " and name " + t.getName());
}
} else if (targetType.isFloat()) {
return JavaType.createForCFloatPointer();
@@ -990,13 +1115,13 @@ public class JavaEmitter implements GlueEmitter {
if (bottomType.isPrimitive()) {
if (bottomType.isInt()) {
- switch (bottomType.getSize()) {
+ switch ((int) bottomType.getSize(machDesc)) {
case 1: return javaType(ArrayTypes.byteBufferArrayClass);
case 2: return javaType(ArrayTypes.shortBufferArrayClass);
case 4: return javaType(ArrayTypes.intBufferArrayClass);
case 8: return javaType(ArrayTypes.longBufferArrayClass);
default: throw new RuntimeException("Unknown two-dimensional integer array type of element size " +
- bottomType.getSize() + " and name " + bottomType.getName());
+ bottomType.getSize(machDesc) + " and name " + bottomType.getName());
}
} else if (bottomType.isFloat()) {
return javaType(ArrayTypes.floatBufferArrayClass);
@@ -1047,11 +1172,11 @@ public class JavaEmitter implements GlueEmitter {
private int slot(Type t, int byteOffset) {
if (t.isInt()) {
- switch (t.getSize()) {
+ switch ((int) t.getSize(machDesc)) {
case 1:
case 2:
case 4:
- case 8: return byteOffset / t.getSize();
+ case 8: return byteOffset / (int) t.getSize(machDesc);
default: throw new RuntimeException("Illegal type");
}
} else if (t.isFloat()) {
@@ -1095,7 +1220,7 @@ public class JavaEmitter implements GlueEmitter {
// FIXME
throw new RuntimeException("Can't yet handle opaque definitions of structs' fields to non-integer types (byte, short, int, long, etc.)");
}
- switch (fieldType.getSize()) {
+ switch ((int) fieldType.getSize(machDesc)) {
case 1: return "byte";
case 2: return "short";
case 4: return "int";
@@ -1368,7 +1493,7 @@ public class JavaEmitter implements GlueEmitter {
PointerType prt = sym.getReturnType().asPointer();
if (prt == null ||
prt.getTargetType().asInt() == null ||
- prt.getTargetType().getSize() != 1) {
+ prt.getTargetType().getSize(machDesc) != 1) {
throw new RuntimeException(
"Cannot apply ReturnsString configuration directive to \"" + sym +
"\". ReturnsString requires native method to have return type \"char *\"");
diff --git a/src/classes/com/sun/gluegen/JavaMethodBindingEmitter.java b/src/classes/com/sun/gluegen/JavaMethodBindingEmitter.java
index 8dbb20d28..64d349ca9 100644
--- a/src/classes/com/sun/gluegen/JavaMethodBindingEmitter.java
+++ b/src/classes/com/sun/gluegen/JavaMethodBindingEmitter.java
@@ -89,6 +89,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
public JavaMethodBindingEmitter(MethodBinding binding,
PrintWriter output,
+ MachineDescription defaultMachDesc,
String runtimeExceptionType,
boolean emitBody,
boolean eraseBufferAndArrayTypes,
@@ -98,7 +99,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
boolean forIndirectBufferAndArrayImplementation,
boolean isUnimplemented)
{
- super(output);
+ super(output, defaultMachDesc);
this.binding = binding;
this.runtimeExceptionType = runtimeExceptionType;
this.emitBody = emitBody;
@@ -333,7 +334,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
return getArgumentName(i) + "_offset";
}
- protected void emitBody(PrintWriter writer)
+ protected void emitBody(PrintWriter writer, MachineDescription machDesc)
{
if (!emitBody) {
writer.println(';');
@@ -347,7 +348,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
emitPrologueOrEpilogue(prologue, writer);
emitPreCallSetup(binding, writer);
//emitReturnVariableSetup(binding, writer);
- emitReturnVariableSetupAndCall(binding, writer);
+ emitReturnVariableSetupAndCall(binding, writer, machDesc);
emitPrologueOrEpilogue(epilogue, writer);
}
writer.println(" }");
@@ -435,7 +436,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
}
- protected void emitReturnVariableSetupAndCall(MethodBinding binding, PrintWriter writer) {
+ protected void emitReturnVariableSetupAndCall(MethodBinding binding, PrintWriter writer, MachineDescription machDesc) {
writer.print(" ");
JavaType returnType = binding.getJavaReturnType();
boolean needsResultAssignment = false;
@@ -502,7 +503,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
writer.println();
}
if (needsResultAssignment) {
- emitCallResultReturn(binding, writer);
+ emitCallResultReturn(binding, writer, machDesc);
}
}
@@ -587,14 +588,14 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
return numArgsEmitted;
}
- protected void emitCallResultReturn(MethodBinding binding, PrintWriter writer) {
+ protected void emitCallResultReturn(MethodBinding binding, PrintWriter writer, MachineDescription machDesc) {
JavaType returnType = binding.getJavaReturnType();
if (returnType.isCompoundTypeWrapper()) {
String fmt = getReturnedArrayLengthExpression();
writer.println(" if (_res == null) return null;");
if (fmt == null) {
- writer.print(" return new " + returnType.getName() + "(_res.order(ByteOrder.nativeOrder()))");
+ writer.print(" return " + returnType.getName() + ".create(_res.order(ByteOrder.nativeOrder()))");
} else {
writer.println(" _res.order(ByteOrder.nativeOrder());");
String[] argumentNames = new String[binding.getNumArguments()];
@@ -616,13 +617,13 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
// Create temporary ByteBuffer slice
// FIXME: probably need Type.getAlignedSize() for arrays of
// compound types (rounding up to machine-dependent alignment)
- writer.println(" _res.position(_count * " + cReturnType.getSize() + ");");
- writer.println(" _res.limit ((1 + _count) * " + cReturnType.getSize() + ");");
+ writer.println(" _res.position(_count * " + cReturnType.getSize(machDesc) + ");");
+ writer.println(" _res.limit ((1 + _count) * " + cReturnType.getSize(machDesc) + ");");
writer.println(" ByteBuffer _tmp = _res.slice();");
writer.println(" _tmp.order(ByteOrder.nativeOrder());");
writer.println(" _res.position(0);");
writer.println(" _res.limit(_res.capacity());");
- writer.println(" _retarray[_count] = new " + getReturnTypeString(true) + "(_tmp);");
+ writer.println(" _retarray[_count] = " + getReturnTypeString(true) + ".create(_tmp);");
writer.println(" }");
writer.print (" return _retarray");
}
@@ -634,7 +635,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
writer.println(" if (_res == null) return null;");
writer.println(" " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[_res.length];");
writer.println(" for (int _count = 0; _count < _res.length; _count++) {");
- writer.println(" _retarray[_count] = new " + getReturnTypeString(true) + "(_res[_count]);");
+ writer.println(" _retarray[_count] = " + getReturnTypeString(true) + ".create(_res[_count]);");
writer.println(" }");
writer.println(" return _retarray;");
}
diff --git a/src/classes/com/sun/gluegen/StructLayout.java b/src/classes/com/sun/gluegen/StructLayout.java
index a7dbab61f..df47fd1f8 100644
--- a/src/classes/com/sun/gluegen/StructLayout.java
+++ b/src/classes/com/sun/gluegen/StructLayout.java
@@ -41,6 +41,13 @@ package com.sun.gluegen;
import com.sun.gluegen.cgram.types.*;
+/** Encapsulates algorithm for laying out data structures. Note that
+ this ends up embedding code in various places via SizeThunks. If
+ the 32-bit and 64-bit ports on a given platform differ
+ fundamentally in their handling of struct layout then this code
+ will need to be updated and, most likely, two versions of the
+ SizeThunks maintained in various places. */
+
public class StructLayout {
private int baseOffset;
private int structAlignment;
@@ -53,32 +60,28 @@ public class StructLayout {
public void layout(CompoundType t) {
int n = t.getNumFields();
- int curOffset = baseOffset;
- int maxSize = 0;
+ SizeThunk curOffset = SizeThunk.constant(baseOffset);
+ SizeThunk maxSize = SizeThunk.constant(0);
for (int i = 0; i < n; i++) {
Field f = t.getField(i);
Type ft = f.getType();
if (ft.isInt() || ft.isFloat() || ft.isDouble() || ft.isPointer()) {
- int sz = ft.getSize();
- if ((curOffset % sz) != 0) {
- curOffset += sz - (curOffset % sz);
- }
+ SizeThunk sz = ft.getSize();
+ curOffset = SizeThunk.roundUp(curOffset, sz);
f.setOffset(curOffset);
if (t.isUnion()) {
- maxSize = Math.max(maxSize, sz);
+ maxSize = SizeThunk.max(maxSize, sz);
} else {
- curOffset += sz;
+ curOffset = SizeThunk.add(curOffset, sz);
}
} else if (ft.isCompound()) {
new StructLayout(0, structAlignment).layout(ft.asCompound());
- if ((curOffset % structAlignment) != 0) {
- curOffset += structAlignment - (curOffset % structAlignment);
- }
+ curOffset = SizeThunk.roundUp(curOffset, SizeThunk.constant(structAlignment));
f.setOffset(curOffset);
if (t.isUnion()) {
- maxSize = Math.max(maxSize, ft.getSize());
+ maxSize = SizeThunk.max(maxSize, ft.getSize());
} else {
- curOffset += ft.getSize();
+ curOffset = SizeThunk.add(curOffset, ft.getSize());
}
} else if (ft.isArray()) {
ArrayType arrayType = ft.asArray();
@@ -88,11 +91,9 @@ public class StructLayout {
arrayType.recomputeSize();
}
// Note: not sure how this rounding is done
- if ((curOffset % structAlignment) != 0) {
- curOffset += structAlignment - (curOffset % structAlignment);
- }
+ curOffset = SizeThunk.roundUp(curOffset, SizeThunk.constant(structAlignment));
f.setOffset(curOffset);
- curOffset += ft.getSize();
+ curOffset = SizeThunk.add(curOffset, ft.getSize());
} else {
// FIXME
String name = t.getName();
@@ -119,6 +120,7 @@ public class StructLayout {
public static StructLayout createForCurrentPlatform() {
+ // Note: this code is replicated in CPU.java
String os = System.getProperty("os.name").toLowerCase();
String cpu = System.getProperty("os.arch").toLowerCase();
if ((os.startsWith("windows") && cpu.equals("x86")) ||
@@ -128,6 +130,7 @@ public class StructLayout {
(os.startsWith("linux") && cpu.equals("ia64")) ||
(os.startsWith("sunos") && cpu.equals("sparc")) ||
(os.startsWith("sunos") && cpu.equals("x86")) ||
+ (os.startsWith("sunos") && cpu.equals("amd64")) ||
(os.startsWith("mac os") && cpu.equals("ppc")) ||
(os.startsWith("freebsd") && cpu.equals("i386"))
) {
diff --git a/src/classes/com/sun/gluegen/cgram/HeaderParser.g b/src/classes/com/sun/gluegen/cgram/HeaderParser.g
index 212e56091..78ba5c54a 100644
--- a/src/classes/com/sun/gluegen/cgram/HeaderParser.g
+++ b/src/classes/com/sun/gluegen/cgram/HeaderParser.g
@@ -56,17 +56,6 @@ options {
/** Name assigned to a anonymous EnumType (e.g., "enum { ... }"). */
public static final String ANONYMOUS_ENUM_NAME = "<anonymous>";
- /** Set the machine description for this HeaderParser. Must be
- done before parsing. */
- public void setMachineDescription(MachineDescription machDesc) {
- this.machDesc = machDesc;
- }
-
- /** Returns the MachineDescription this HeaderParser uses. */
- public MachineDescription machineDescription() {
- return machDesc;
- }
-
/** Set the dictionary mapping typedef names to types for this
HeaderParser. Must be done before parsing. */
public void setTypedefDictionary(TypeDictionary dict) {
@@ -130,7 +119,7 @@ options {
int cvAttrs) {
CompoundType t = (CompoundType) structDictionary.get(typeName);
if (t == null) {
- t = new CompoundType(null, -1, kind, cvAttrs);
+ t = new CompoundType(null, null, kind, cvAttrs);
t.setStructName(typeName);
structDictionary.put(typeName, t);
}
@@ -207,7 +196,6 @@ options {
}
}
- private MachineDescription machDesc;
private boolean doDeclaration; // Used to only process function typedefs
private String declId;
private List parameters;
@@ -242,7 +230,7 @@ options {
private void processDeclaration(Type returnType) {
if (doDeclaration) {
- FunctionSymbol sym = new FunctionSymbol(declId, new FunctionType(null, -1, returnType, 0));
+ FunctionSymbol sym = new FunctionSymbol(declId, new FunctionType(null, null, returnType, 0));
if (parameters != null) { // handle funcs w/ empty parameter lists (e.g., "foo()")
for (Iterator iter = parameters.iterator(); iter.hasNext(); ) {
ParameterDeclaration pd = (ParameterDeclaration) iter.next();
@@ -272,13 +260,13 @@ options {
// FIXME: this doesn't take into account struct alignment, which may be necessary
// See also FIXMEs in ArrayType.java
int len = parseIntConstExpr(t);
- tb.setType(canonicalize(new ArrayType(tb.type(), len * tb.type().getSize(), len, 0)));
+ tb.setType(canonicalize(new ArrayType(tb.type(), SizeThunk.mul(SizeThunk.constant(len), tb.type().getSize()), len, 0)));
return;
} catch (RecognitionException e) {
// Fall through
}
}
- tb.setType(canonicalize(new PointerType(machDesc.pointerSizeInBytes(),
+ tb.setType(canonicalize(new PointerType(SizeThunk.POINTER,
tb.type(),
0)));
}
@@ -301,7 +289,7 @@ options {
}
if (enumType == null) {
- enumType = new EnumType(enumTypeName, machDesc.longSizeInBytes());
+ enumType = new EnumType(enumTypeName, SizeThunk.LONG);
}
return enumType;
@@ -348,7 +336,7 @@ declarator[TypeBox tb] returns [String s] {
doDeclaration();
} else if ( funcPointerName != null ) {
/* TypeBox becomes function pointer in this case */
- FunctionType ft = new FunctionType(null, -1, tb.type(), 0);
+ FunctionType ft = new FunctionType(null, null, tb.type(), 0);
if (params == null) {
// If the function pointer has no declared parameters, it's a
// void function. I'm not sure if the parameter name is
@@ -362,7 +350,7 @@ declarator[TypeBox tb] returns [String s] {
ft.addArgument(pd.type(), pd.id());
}
}
- tb.setType(canonicalize(new PointerType(machDesc.pointerSizeInBytes(),
+ tb.setType(canonicalize(new PointerType(SizeThunk.POINTER,
ft,
0)));
s = funcPointerName;
@@ -431,7 +419,7 @@ declSpecifiers returns [TypeBox tb] {
{
if (t == null &&
(x & (SIGNED | UNSIGNED)) != 0) {
- t = new IntType("int", machDesc.intSizeInBytes(), ((x & UNSIGNED) != 0), attrs2CVAttrs(x));
+ t = new IntType("int", SizeThunk.INT, ((x & UNSIGNED) != 0), attrs2CVAttrs(x));
}
tb = new TypeBox(t, ((x & TYPEDEF) != 0));
}
@@ -465,13 +453,13 @@ typeSpecifier[int attributes] returns [Type t] {
boolean unsigned = ((attributes & UNSIGNED) != 0);
}
: "void" { t = new VoidType(cvAttrs); }
- | "char" { t = new IntType("char" , machDesc.charSizeInBytes(), unsigned, cvAttrs); }
- | "short" { t = new IntType("short", machDesc.shortSizeInBytes(), unsigned, cvAttrs); }
- | "int" { t = new IntType("int" , machDesc.intSizeInBytes(), unsigned, cvAttrs); }
- | "long" { t = new IntType("long" , machDesc.longSizeInBytes(), unsigned, cvAttrs); }
- | "__int64" { t = new IntType("__int64", machDesc.int64SizeInBytes(), unsigned, cvAttrs); }
- | "float" { t = new FloatType("float", machDesc.floatSizeInBytes(), cvAttrs); }
- | "double" { t = new DoubleType("double", machDesc.doubleSizeInBytes(), cvAttrs); }
+ | "char" { t = new IntType("char" , SizeThunk.CHAR, unsigned, cvAttrs); }
+ | "short" { t = new IntType("short", SizeThunk.SHORT, unsigned, cvAttrs); }
+ | "int" { t = new IntType("int" , SizeThunk.INT, unsigned, cvAttrs); }
+ | "long" { t = new IntType("long" , SizeThunk.LONG, unsigned, cvAttrs); }
+ | "__int64" { t = new IntType("__int64", SizeThunk.INT64, unsigned, cvAttrs); }
+ | "float" { t = new FloatType("float", SizeThunk.FLOAT, cvAttrs); }
+ | "double" { t = new DoubleType("double", SizeThunk.DOUBLE, cvAttrs); }
| t = structSpecifier[cvAttrs] ( attributeDecl )*
| t = unionSpecifier [cvAttrs] ( attributeDecl )*
| t = enumSpecifier [cvAttrs]
@@ -507,7 +495,7 @@ structOrUnionBody[CompoundTypeKind kind, int cvAttrs] returns [CompoundType t] {
t = (CompoundType) canonicalize(lookupInStructDictionary(id.getText(), kind, cvAttrs));
} ( structDeclarationList[t] )?
RCURLY { t.setBodyParsed(); }
- | LCURLY { t = new CompoundType(null, -1, kind, cvAttrs); }
+ | LCURLY { t = new CompoundType(null, null, kind, cvAttrs); }
( structDeclarationList[t] )?
RCURLY { t.setBodyParsed(); }
| id2:ID { t = (CompoundType) canonicalize(lookupInStructDictionary(id2.getText(), kind, cvAttrs)); }
@@ -528,7 +516,7 @@ structDeclaration[CompoundType containingType] {
CompoundType ct = t.asCompound();
if (ct.isUnion()) {
// Anonymous union
- containingType.addField(new Field(null, t, -1));
+ containingType.addField(new Field(null, t, null));
}
}
}
@@ -544,7 +532,7 @@ specifierQualifierList returns [Type t] {
)+ {
if (t == null &&
(x & (SIGNED | UNSIGNED)) != 0) {
- t = new IntType("int", machDesc.intSizeInBytes(), ((x & UNSIGNED) != 0), attrs2CVAttrs(x));
+ t = new IntType("int", SizeThunk.INT, ((x & UNSIGNED) != 0), attrs2CVAttrs(x));
}
}
;
@@ -563,7 +551,7 @@ structDeclarator[CompoundType containingType, Type t] returns [boolean addedAny]
}
:
#( NStructDeclarator
- ( s = declarator[tb] { containingType.addField(new Field(s, tb.type(), -1)); addedAny = true; } )?
+ ( s = declarator[tb] { containingType.addField(new Field(s, tb.type(), null)); addedAny = true; } )?
( COLON expr { /* FIXME: bit types not handled yet */ } ) ?
( attributeDecl )*
)
@@ -659,7 +647,7 @@ pointerGroup[TypeBox tb] { int x = 0; int y = 0; }
{
//System.err.println("IN PTR GROUP: TB=" + tb);
if (tb != null) {
- tb.setType(canonicalize(new PointerType(machDesc.pointerSizeInBytes(),
+ tb.setType(canonicalize(new PointerType(SizeThunk.POINTER,
tb.type(),
attrs2CVAttrs(x))));
}
diff --git a/src/classes/com/sun/gluegen/cgram/types/ArrayType.java b/src/classes/com/sun/gluegen/cgram/types/ArrayType.java
index c61e6457f..0e23d356d 100644
--- a/src/classes/com/sun/gluegen/cgram/types/ArrayType.java
+++ b/src/classes/com/sun/gluegen/cgram/types/ArrayType.java
@@ -49,7 +49,7 @@ public class ArrayType extends Type {
private int length;
private String computedName;
- public ArrayType(Type elementType, int sizeInBytes, int length, int cvAttributes) {
+ public ArrayType(Type elementType, SizeThunk sizeInBytes, int length, int cvAttributes) {
super(elementType.getName() + " *", sizeInBytes, cvAttributes);
this.elementType = elementType;
this.length = length;
@@ -100,7 +100,7 @@ public class ArrayType extends Type {
}
// FIXME: this doesn't take into account struct alignment, which may be necessary
// See also FIXME below and in HeaderParser.g
- super.setSize(getLength() * elementType.getSize());
+ super.setSize(SizeThunk.mul(SizeThunk.constant(getLength()), elementType.getSize()));
}
public String toString() {
diff --git a/src/classes/com/sun/gluegen/cgram/types/CompoundType.java b/src/classes/com/sun/gluegen/cgram/types/CompoundType.java
index 6ad7580e0..28d7b7664 100644
--- a/src/classes/com/sun/gluegen/cgram/types/CompoundType.java
+++ b/src/classes/com/sun/gluegen/cgram/types/CompoundType.java
@@ -55,11 +55,11 @@ public class CompoundType extends Type {
private boolean computedHashcode;
private int hashcode;
- public CompoundType(String name, int size, CompoundTypeKind kind, int cvAttributes) {
+ public CompoundType(String name, SizeThunk size, CompoundTypeKind kind, int cvAttributes) {
this(name, size, kind, cvAttributes, null);
}
- private CompoundType(String name, int size, CompoundTypeKind kind, int cvAttributes, String structName) {
+ private CompoundType(String name, SizeThunk size, CompoundTypeKind kind, int cvAttributes, String structName) {
super(name, size, cvAttributes);
assert kind != null;
this.kind = kind;
@@ -107,7 +107,7 @@ public class CompoundType extends Type {
this.structName = structName;
}
- public void setSize(int size) {
+ public void setSize(SizeThunk size) {
super.setSize(size);
}
diff --git a/src/classes/com/sun/gluegen/cgram/types/DoubleType.java b/src/classes/com/sun/gluegen/cgram/types/DoubleType.java
index e2be470fb..6d6e62c98 100644
--- a/src/classes/com/sun/gluegen/cgram/types/DoubleType.java
+++ b/src/classes/com/sun/gluegen/cgram/types/DoubleType.java
@@ -42,7 +42,7 @@ package com.sun.gluegen.cgram.types;
/** Represents a double-word floating-point type (C type "double".) */
public class DoubleType extends PrimitiveType {
- public DoubleType(String name, int size, int cvAttributes) {
+ public DoubleType(String name, SizeThunk size, int cvAttributes) {
super(name, size, cvAttributes);
}
diff --git a/src/classes/com/sun/gluegen/cgram/types/EnumType.java b/src/classes/com/sun/gluegen/cgram/types/EnumType.java
index 7f4b9e559..717d3892c 100644
--- a/src/classes/com/sun/gluegen/cgram/types/EnumType.java
+++ b/src/classes/com/sun/gluegen/cgram/types/EnumType.java
@@ -60,16 +60,14 @@ public class EnumType extends IntType {
}
private List/*<Enum>*/ enums;
- private static final int longSizeBytes = 8;
-
public EnumType(String name) {
- super(name, longSizeBytes, false, CVAttributes.CONST );
- this.underlyingType = new IntType(name, longSizeBytes, false, CVAttributes.CONST);
+ super(name, SizeThunk.LONG, false, CVAttributes.CONST );
+ this.underlyingType = new IntType(name, SizeThunk.LONG, false, CVAttributes.CONST);
}
- public EnumType(String name, int enumSizeBytes) {
- super(name, enumSizeBytes, false, CVAttributes.CONST );
- this.underlyingType = new IntType(name, enumSizeBytes, false, CVAttributes.CONST);
+ public EnumType(String name, SizeThunk enumSizeInBytes) {
+ super(name, enumSizeInBytes, false, CVAttributes.CONST );
+ this.underlyingType = new IntType(name, enumSizeInBytes, false, CVAttributes.CONST);
}
protected EnumType(String name, IntType underlyingType, int cvAttributes) {
diff --git a/src/classes/com/sun/gluegen/cgram/types/Field.java b/src/classes/com/sun/gluegen/cgram/types/Field.java
index 3514c8f7e..e16ffbc5b 100644
--- a/src/classes/com/sun/gluegen/cgram/types/Field.java
+++ b/src/classes/com/sun/gluegen/cgram/types/Field.java
@@ -42,11 +42,11 @@ package com.sun.gluegen.cgram.types;
/** Represents a field in a struct or union. */
public class Field {
- private String name;
- private Type type;
- private long offset;
+ private String name;
+ private Type type;
+ private SizeThunk offset;
- public Field(String name, Type type, long offset) {
+ public Field(String name, Type type, SizeThunk offset) {
this.name = name;
this.type = type;
this.offset = offset;
@@ -62,10 +62,11 @@ public class Field {
}
Field f = (Field) arg;
+ // Note: don't know how to examine offset any more since it's
+ // implemented in terms of code and they're not canonicalized
return (((name != null && name.equals(f.name)) ||
(name == null && f.name == null)) &&
- type.equals(f.type) &&
- offset == f.offset);
+ type.equals(f.type));
}
/** Name of this field in the containing data structure. */
@@ -74,11 +75,15 @@ public class Field {
/** Type of this field. */
public Type getType() { return type; }
- /** Offset, in bytes, of this field in the containing data structure. */
- public long getOffset() { return offset; }
+ /** SizeThunk computing offset, in bytes, of this field in the containing data structure. */
+ public SizeThunk getOffset() { return offset; }
+
+ /** Offset, in bytes, of this field in the containing data structure
+ given the specified MachineDescription. */
+ public long getOffset(MachineDescription machDesc) { return offset.compute(machDesc); }
/** Sets the offset of this field in the containing data structure. */
- public void setOffset(long offset) { this.offset = offset; }
+ public void setOffset(SizeThunk offset) { this.offset = offset; }
public String toString() {
if (!getType().isFunctionPointer()) {
diff --git a/src/classes/com/sun/gluegen/cgram/types/FloatType.java b/src/classes/com/sun/gluegen/cgram/types/FloatType.java
index 9f59b3564..7a6fa4d64 100644
--- a/src/classes/com/sun/gluegen/cgram/types/FloatType.java
+++ b/src/classes/com/sun/gluegen/cgram/types/FloatType.java
@@ -42,7 +42,7 @@ package com.sun.gluegen.cgram.types;
/** Represents a single-word floating-point type (C type "float".) */
public class FloatType extends PrimitiveType {
- public FloatType(String name, int size, int cvAttributes) {
+ public FloatType(String name, SizeThunk size, int cvAttributes) {
super(name, size, cvAttributes);
}
diff --git a/src/classes/com/sun/gluegen/cgram/types/FunctionType.java b/src/classes/com/sun/gluegen/cgram/types/FunctionType.java
index 9c94daea2..5e22e47d7 100644
--- a/src/classes/com/sun/gluegen/cgram/types/FunctionType.java
+++ b/src/classes/com/sun/gluegen/cgram/types/FunctionType.java
@@ -49,7 +49,7 @@ public class FunctionType extends Type {
private ArrayList argumentTypes;
private ArrayList argumentNames;
- public FunctionType(String name, int size, Type returnType, int cvAttributes) {
+ public FunctionType(String name, SizeThunk size, Type returnType, int cvAttributes) {
super(name, size, cvAttributes);
this.returnType = returnType;
}
diff --git a/src/classes/com/sun/gluegen/cgram/types/IntType.java b/src/classes/com/sun/gluegen/cgram/types/IntType.java
index 2816c561c..acd6a3d2b 100644
--- a/src/classes/com/sun/gluegen/cgram/types/IntType.java
+++ b/src/classes/com/sun/gluegen/cgram/types/IntType.java
@@ -43,11 +43,11 @@ public class IntType extends PrimitiveType {
private boolean unsigned;
private boolean typedefedUnsigned;
- public IntType(String name, int size, boolean unsigned, int cvAttributes) {
+ public IntType(String name, SizeThunk size, boolean unsigned, int cvAttributes) {
this(name, size, unsigned, cvAttributes, false);
}
- private IntType(String name, int size, boolean unsigned, int cvAttributes, boolean typedefedUnsigned) {
+ private IntType(String name, SizeThunk size, boolean unsigned, int cvAttributes, boolean typedefedUnsigned) {
super(name, size, cvAttributes);
this.unsigned = unsigned;
this.typedefedUnsigned = typedefedUnsigned;
diff --git a/src/classes/com/sun/gluegen/cgram/types/PointerType.java b/src/classes/com/sun/gluegen/cgram/types/PointerType.java
index 142a2f12d..3fe69a164 100644
--- a/src/classes/com/sun/gluegen/cgram/types/PointerType.java
+++ b/src/classes/com/sun/gluegen/cgram/types/PointerType.java
@@ -44,13 +44,13 @@ public class PointerType extends Type {
private String computedName;
private boolean hasTypedefedName;
- public PointerType(int size, Type targetType, int cvAttributes) {
+ public PointerType(SizeThunk size, Type targetType, int cvAttributes) {
// can pass null for the final name parameter because the PointerType's getName()
// completely replaces superclass behavior
- this(size, targetType, cvAttributes, false, null);
+ this(size, targetType, cvAttributes, false, null);
}
- private PointerType(int size, Type targetType, int cvAttributes, boolean hasTypedefedName, String typedefedName) {
+ private PointerType(SizeThunk size, Type targetType, int cvAttributes, boolean hasTypedefedName, String typedefedName) {
super(targetType.getName() + " *", size, cvAttributes);
this.hasTypedefedName = false;
this.targetType = targetType;
diff --git a/src/classes/com/sun/gluegen/cgram/types/PrimitiveType.java b/src/classes/com/sun/gluegen/cgram/types/PrimitiveType.java
index 8807e2615..80dab9aef 100644
--- a/src/classes/com/sun/gluegen/cgram/types/PrimitiveType.java
+++ b/src/classes/com/sun/gluegen/cgram/types/PrimitiveType.java
@@ -40,7 +40,7 @@
package com.sun.gluegen.cgram.types;
public abstract class PrimitiveType extends Type {
- protected PrimitiveType(String name, int size, int cvAttributes) {
+ protected PrimitiveType(String name, SizeThunk size, int cvAttributes) {
super(name, size, cvAttributes);
}
diff --git a/src/classes/com/sun/gluegen/cgram/types/SizeThunk.java b/src/classes/com/sun/gluegen/cgram/types/SizeThunk.java
new file mode 100755
index 000000000..74feef950
--- /dev/null
+++ b/src/classes/com/sun/gluegen/cgram/types/SizeThunk.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.sun.gluegen.cgram.types;
+
+/** Provides a level of indirection between the definition of a type's
+ size and the absolute value of this size. Necessary when
+ generating glue code for two different CPU architectures (e.g.,
+ 32-bit and 64-bit) from the same internal representation of the
+ various types involved. */
+
+public abstract class SizeThunk {
+ // Private constructor because there are only a few of these
+ private SizeThunk() {}
+
+ public abstract long compute(MachineDescription machDesc);
+
+ public static final SizeThunk CHAR = new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return machDesc.charSizeInBytes();
+ }
+ };
+
+ public static final SizeThunk SHORT = new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return machDesc.shortSizeInBytes();
+ }
+ };
+
+ public static final SizeThunk INT = new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return machDesc.intSizeInBytes();
+ }
+ };
+
+ public static final SizeThunk LONG = new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return machDesc.longSizeInBytes();
+ }
+ };
+
+ public static final SizeThunk INT64 = new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return machDesc.int64SizeInBytes();
+ }
+ };
+
+ public static final SizeThunk FLOAT = new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return machDesc.floatSizeInBytes();
+ }
+ };
+
+ public static final SizeThunk DOUBLE = new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return machDesc.doubleSizeInBytes();
+ }
+ };
+
+ public static final SizeThunk POINTER = new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return machDesc.pointerSizeInBytes();
+ }
+ };
+
+ // Factory methods for performing certain limited kinds of
+ // arithmetic on these values
+ public static SizeThunk add(final SizeThunk thunk1,
+ final SizeThunk thunk2) {
+ return new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return thunk1.compute(machDesc) + thunk2.compute(machDesc);
+ }
+ };
+ }
+
+ public static SizeThunk sub(final SizeThunk thunk1,
+ final SizeThunk thunk2) {
+ return new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return thunk1.compute(machDesc) - thunk2.compute(machDesc);
+ }
+ };
+ }
+
+ public static SizeThunk mul(final SizeThunk thunk1,
+ final SizeThunk thunk2) {
+ return new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return thunk1.compute(machDesc) * thunk2.compute(machDesc);
+ }
+ };
+ }
+
+ public static SizeThunk mod(final SizeThunk thunk1,
+ final SizeThunk thunk2) {
+ return new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return thunk1.compute(machDesc) % thunk2.compute(machDesc);
+ }
+ };
+ }
+
+ public static SizeThunk roundUp(final SizeThunk thunk1,
+ final SizeThunk thunk2) {
+ return new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ long sz1 = thunk1.compute(machDesc);
+ long sz2 = thunk2.compute(machDesc);
+ long rem = (sz1 % sz2);
+ if (rem == 0) {
+ return sz1;
+ }
+ return sz1 + (sz2 - rem);
+ }
+ };
+ }
+
+ public static SizeThunk max(final SizeThunk thunk1,
+ final SizeThunk thunk2) {
+ return new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return Math.max(thunk1.compute(machDesc), thunk2.compute(machDesc));
+ }
+ };
+ }
+
+ public static SizeThunk constant(final int constant) {
+ return new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return constant;
+ }
+ };
+ }
+}
diff --git a/src/classes/com/sun/gluegen/cgram/types/Type.java b/src/classes/com/sun/gluegen/cgram/types/Type.java
index 2ac492d3f..0dcaabcef 100644
--- a/src/classes/com/sun/gluegen/cgram/types/Type.java
+++ b/src/classes/com/sun/gluegen/cgram/types/Type.java
@@ -48,12 +48,12 @@ import java.util.List;
public abstract class Type {
private String name;
- private int size;
+ private SizeThunk size;
private int cvAttributes;
private int typedefedCVAttributes;
private boolean hasTypedefName;
- protected Type(String name, int size, int cvAttributes) {
+ protected Type(String name, SizeThunk size, int cvAttributes) {
setName(name);
this.size = size;
this.cvAttributes = cvAttributes;
@@ -88,10 +88,18 @@ public abstract class Type {
hasTypedefName = true;
}
- /** Size of this type in bytes. */
- public int getSize() { return size; }
+ /** SizeThunk which computes size of this type in bytes. */
+ public SizeThunk getSize() { return size; }
+ /** Size of this type in bytes according to the given MachineDescription. */
+ public long getSize(MachineDescription machDesc) {
+ SizeThunk thunk = getSize();
+ if (thunk == null) {
+ throw new RuntimeException("No size set for type \"" + getName() + "\"");
+ }
+ return thunk.compute(machDesc);
+ }
/** Set the size of this type; only available for CompoundTypes. */
- void setSize(int size) { this.size = size; }
+ void setSize(SizeThunk size) { this.size = size; }
/** Casts this to a BitType or returns null if not a BitType. */
public BitType asBit() { return null; }
diff --git a/src/classes/com/sun/gluegen/cgram/types/VoidType.java b/src/classes/com/sun/gluegen/cgram/types/VoidType.java
index db4c43f81..3a2f1b93f 100644
--- a/src/classes/com/sun/gluegen/cgram/types/VoidType.java
+++ b/src/classes/com/sun/gluegen/cgram/types/VoidType.java
@@ -45,7 +45,7 @@ public class VoidType extends Type {
}
private VoidType(String name, int cvAttributes) {
- super(name, 0, cvAttributes);
+ super(name, null, cvAttributes);
}
public VoidType asVoid() { return this; }
diff --git a/src/classes/com/sun/gluegen/opengl/GLCMethodBindingEmitter.java b/src/classes/com/sun/gluegen/opengl/GLCMethodBindingEmitter.java
index 653a8cd3d..43053410e 100755
--- a/src/classes/com/sun/gluegen/opengl/GLCMethodBindingEmitter.java
+++ b/src/classes/com/sun/gluegen/opengl/GLCMethodBindingEmitter.java
@@ -74,6 +74,7 @@ public class GLCMethodBindingEmitter extends CMethodBindingEmitter {
}
},
methodToWrap.getDefaultOutput(),
+ methodToWrap.getDefaultMachineDescription(),
methodToWrap.getJavaPackageName(),
methodToWrap.getJavaClassName(),
methodToWrap.getIsOverloadedBinding(),
diff --git a/src/classes/com/sun/gluegen/runtime/CPU.java b/src/classes/com/sun/gluegen/runtime/CPU.java
new file mode 100755
index 000000000..228ea0f03
--- /dev/null
+++ b/src/classes/com/sun/gluegen/runtime/CPU.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.sun.gluegen.runtime;
+
+/** Provides information to autogenerated struct accessors about what
+ kind of architecture (32- or 64-bit) we are currently running
+ on. */
+
+public class CPU {
+ private static boolean is32Bit;
+
+ static {
+ // We don't seem to need an AccessController.doPrivileged() block
+ // here as these system properties are visible even to unsigned
+ // applets
+ // Note: this code is replicated in StructLayout.java
+ String os = System.getProperty("os.name").toLowerCase();
+ String cpu = System.getProperty("os.arch").toLowerCase();
+ if ((os.startsWith("windows") && cpu.equals("x86")) ||
+ (os.startsWith("linux") && cpu.equals("i386")) ||
+ (os.startsWith("mac os") && cpu.equals("ppc")) ||
+ (os.startsWith("sunos") && cpu.equals("sparc")) ||
+ (os.startsWith("sunos") && cpu.equals("x86")) ||
+ (os.startsWith("freebsd") && cpu.equals("i386"))) {
+ is32Bit = true;
+ } else if ((os.startsWith("linux") && cpu.equals("amd64")) ||
+ (os.startsWith("linux") && cpu.equals("x86_64")) ||
+ (os.startsWith("linux") && cpu.equals("ia64")) ||
+ (os.startsWith("sunos") && cpu.equals("amd64"))) {
+ } else {
+ throw new RuntimeException("Please port CPU detection (32/64 bit) to your platform (" + os + "/" + cpu + ")");
+ }
+ }
+
+ public static boolean is32Bit() {
+ return is32Bit;
+ }
+}
diff --git a/src/classes/com/sun/opengl/impl/NativeLibLoader.java b/src/classes/com/sun/opengl/impl/NativeLibLoader.java
index fa535c7d5..6d4815cd7 100644
--- a/src/classes/com/sun/opengl/impl/NativeLibLoader.java
+++ b/src/classes/com/sun/opengl/impl/NativeLibLoader.java
@@ -79,7 +79,7 @@ public class NativeLibLoader {
// Workaround for 4845371.
// Make sure the first reference to the JNI GetDirectBufferAddress is done
// from a privileged context so the VM's internal class lookups will succeed.
- JAWT jawt = new JAWT();
+ JAWT jawt = JAWT.create();
JAWTFactory.JAWT_GetAWT(jawt);
return null;
diff --git a/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLDrawable.java b/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLDrawable.java
index e7f6537b9..4d0f16623 100644
--- a/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLDrawable.java
+++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLDrawable.java
@@ -215,7 +215,7 @@ public class MacOSXOnscreenGLDrawable extends MacOSXGLDrawable {
{
if (jawt == null)
{
- JAWT j = new JAWT();
+ JAWT j = JAWT.create();
j.version(JAWTFactory.JAWT_VERSION_1_4);
if (!JAWTFactory.JAWT_GetAWT(j))
{
@@ -225,4 +225,4 @@ public class MacOSXOnscreenGLDrawable extends MacOSXGLDrawable {
}
return jawt;
}
-} \ No newline at end of file
+}
diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawable.java
index ae95f5505..abbc9a511 100644
--- a/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawable.java
+++ b/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawable.java
@@ -379,7 +379,7 @@ public abstract class WindowsGLDrawable extends GLDrawableImpl {
}
static PIXELFORMATDESCRIPTOR newPixelFormatDescriptor() {
- PIXELFORMATDESCRIPTOR pfd = new PIXELFORMATDESCRIPTOR();
+ PIXELFORMATDESCRIPTOR pfd = PIXELFORMATDESCRIPTOR.create();
pfd.nSize((short) pfd.size());
pfd.nVersion((short) 1);
return pfd;
diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLDrawable.java
index 7dd6d2361..a128ea1a4 100644
--- a/src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLDrawable.java
+++ b/src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLDrawable.java
@@ -76,7 +76,7 @@ public class WindowsOffscreenGLDrawable extends WindowsGLDrawable {
}
private void create() {
- BITMAPINFO info = new BITMAPINFO();
+ BITMAPINFO info = BITMAPINFO.create();
BITMAPINFOHEADER header = info.bmiHeader();
int bitsPerPixel = (capabilities.getRedBits() +
capabilities.getGreenBits() +
diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLDrawable.java
index b1f2d57a1..fa3766a80 100644
--- a/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLDrawable.java
+++ b/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLDrawable.java
@@ -186,7 +186,7 @@ public class WindowsOnscreenGLDrawable extends WindowsGLDrawable {
private JAWT getJAWT() {
if (jawt == null) {
- JAWT j = new JAWT();
+ JAWT j = JAWT.create();
j.version(JAWTFactory.JAWT_VERSION_1_4);
if (!JAWTFactory.JAWT_GetAWT(j)) {
throw new RuntimeException("Unable to initialize JAWT");
diff --git a/src/classes/com/sun/opengl/impl/x11/X11GLDrawable.java b/src/classes/com/sun/opengl/impl/x11/X11GLDrawable.java
index 1d4f5389b..343931965 100644
--- a/src/classes/com/sun/opengl/impl/x11/X11GLDrawable.java
+++ b/src/classes/com/sun/opengl/impl/x11/X11GLDrawable.java
@@ -100,7 +100,7 @@ public abstract class X11GLDrawable extends GLDrawableImpl {
// use XGetVisualInfo with a VisualIDMask to get the
// corresponding XVisualInfo to pass into glXChooseVisual.
int[] count = new int[1];
- XVisualInfo template = new XVisualInfo();
+ XVisualInfo template = XVisualInfo.create();
// FIXME: probably not 64-bit clean
template.visualid((int) visualID);
lockAWT();
@@ -122,7 +122,7 @@ public abstract class X11GLDrawable extends GLDrawableImpl {
int screen = 0; // FIXME: provide way to specify this?
XVisualInfo vis = null;
int[] count = new int[1];
- XVisualInfo template = new XVisualInfo();
+ XVisualInfo template = XVisualInfo.create();
template.screen(screen);
XVisualInfo[] infos = null;
GLCapabilities[] caps = null;
diff --git a/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java b/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java
index f4523c95e..38d63f04d 100644
--- a/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java
+++ b/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java
@@ -105,7 +105,7 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl {
long display = getDisplayConnection();
XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs, 0);
int[] count = new int[1];
- XVisualInfo template = new XVisualInfo();
+ XVisualInfo template = XVisualInfo.create();
template.screen(screen);
infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count, 0);
if (infos == null) {
@@ -347,7 +347,7 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl {
private static JAWT jawt;
public static JAWT getJAWT() {
if (jawt == null) {
- JAWT j = new JAWT();
+ JAWT j = JAWT.create();
j.version(JAWTFactory.JAWT_VERSION_1_4);
if (!JAWTFactory.JAWT_GetAWT(j)) {
throw new RuntimeException("Unable to initialize JAWT");
diff --git a/src/native/jogl/JAWT_DrawingSurfaceInfo.c b/src/native/jogl/JAWT_DrawingSurfaceInfo.c
index 2b64ec858..6eeaf053b 100644
--- a/src/native/jogl/JAWT_DrawingSurfaceInfo.c
+++ b/src/native/jogl/JAWT_DrawingSurfaceInfo.c
@@ -53,13 +53,14 @@
#endif
static jclass platformDSIClass = NULL;
-static jmethodID constructor = NULL;
+static jmethodID factoryMethod = NULL;
JNIEXPORT jobject JNICALL
Java_com_sun_opengl_impl_JAWT_1DrawingSurfaceInfo_platformInfo0(JNIEnv* env, jobject unused, jobject jthis0) {
JAWT_DrawingSurfaceInfo* dsi;
jobject dirbuf;
jclass clazz;
+ char sig[512];
dsi = (*env)->GetDirectBufferAddress(env, jthis0);
if (dsi == NULL) {
(*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/RuntimeException"),
@@ -81,14 +82,15 @@ Java_com_sun_opengl_impl_JAWT_1DrawingSurfaceInfo_platformInfo0(JNIEnv* env, job
return NULL;
}
clazz = (jclass) (*env)->NewGlobalRef(env, clazz);
- constructor = (*env)->GetMethodID(env, clazz, "<init>", "(Ljava/nio/ByteBuffer;)V");
- if (constructor == NULL) {
+ sprintf(sig, "(Ljava/nio/ByteBuffer;)L%s;", platformDSIClassName);
+ factoryMethod = (*env)->GetStaticMethodID(env, clazz, "create", sig);
+ if (factoryMethod == NULL) {
(*env)->DeleteGlobalRef(env, clazz);
return NULL;
}
platformDSIClass = clazz;
}
- return (*env)->NewObject(env, platformDSIClass, constructor, dirbuf);
+ return (*env)->CallStaticObjectMethod(env, platformDSIClass, factoryMethod, dirbuf);
}
#ifdef __sun