aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/com/sun/gluegen
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2006-01-01 22:51:07 +0000
committerKenneth Russel <[email protected]>2006-01-01 22:51:07 +0000
commit875a3de8f54704604d006badf0f0747347319025 (patch)
tree904c468f43c9c818c57bb0f7f17608066172cf29 /src/classes/com/sun/gluegen
parent0747964f0b88d0c9da9c38bf9eff96eb6561f0c1 (diff)
Fixed more problems related to recent restructuring of glue code
generation to support simultaneous 32- and 64-bit ports. Now uses size() (on Java side) and sizeof (on C side) when creating direct Buffers for struct accessors rather than passing MachineDescription down to JavaMethodBindingEmitter and CMethodBindingEmitter. Now uses 64-bit MachineDescription when sizing outgoing arguments and return types for bound methods. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@506 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/gluegen')
-rw-r--r--src/classes/com/sun/gluegen/CMethodBindingEmitter.java24
-rw-r--r--src/classes/com/sun/gluegen/FunctionEmitter.java25
-rw-r--r--src/classes/com/sun/gluegen/JavaEmitter.java37
-rw-r--r--src/classes/com/sun/gluegen/JavaMethodBindingEmitter.java17
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/MachineDescription.java6
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/MachineDescription32Bit.java2
-rw-r--r--src/classes/com/sun/gluegen/cgram/types/MachineDescription64Bit.java2
-rwxr-xr-xsrc/classes/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java1
8 files changed, 42 insertions, 72 deletions
diff --git a/src/classes/com/sun/gluegen/CMethodBindingEmitter.java b/src/classes/com/sun/gluegen/CMethodBindingEmitter.java
index a1cae8d51..550d8d739 100644
--- a/src/classes/com/sun/gluegen/CMethodBindingEmitter.java
+++ b/src/classes/com/sun/gluegen/CMethodBindingEmitter.java
@@ -120,7 +120,6 @@ public class CMethodBindingEmitter extends FunctionEmitter
*/
public CMethodBindingEmitter(MethodBinding binding,
PrintWriter output,
- MachineDescription defaultMachDesc,
String javaPackageName,
String javaClassName,
boolean isOverloadedBinding,
@@ -128,7 +127,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
boolean forImplementingMethodCall,
boolean forIndirectBufferAndArrayImplementation)
{
- super(output, defaultMachDesc);
+ super(output);
assert(binding != null);
assert(javaClassName != null);
@@ -382,7 +381,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
}
- protected void emitBody(PrintWriter writer, MachineDescription machDesc)
+ protected void emitBody(PrintWriter writer)
{
writer.println(" {");
emitBodyVariableDeclarations(writer);
@@ -393,7 +392,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
emitBodyUserVariableAssignments(writer);
emitBodyVariablePostCallCleanup(writer, true);
emitBodyVariablePostCallCleanup(writer, false);
- emitBodyReturnResult(writer, machDesc);
+ emitBodyReturnResult(writer);
writer.println("}");
writer.println();
}
@@ -966,7 +965,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
}
}
- protected void emitBodyReturnResult(PrintWriter writer, MachineDescription machDesc)
+ protected void emitBodyReturnResult(PrintWriter writer)
{
// WARNING: this code assumes that the return type has already been
// typedef-resolved.
@@ -997,11 +996,9 @@ public class CMethodBindingEmitter extends FunctionEmitter
writer.print(
returnValueCapacityExpression.format(argumentNames));
} else {
- SizeThunk sz = null;
if (cReturnType.isPointer() &&
cReturnType.asPointer().getTargetType().isCompound()) {
- sz = cReturnType.asPointer().getTargetType().getSize();
- if (sz == null) {
+ if (cReturnType.asPointer().getTargetType().getSize() == null) {
throw new RuntimeException(
"Error emitting code for compound return type "+
"for function \"" + binding + "\": " +
@@ -1010,14 +1007,12 @@ public class CMethodBindingEmitter extends FunctionEmitter
cReturnType.asPointer().getTargetType() + " was not)"
);
}
- } else {
- sz = cReturnType.getSize();
}
- writer.print(sz.compute(machDesc));
+ writer.print("sizeof(" + cReturnType.getName() + ")");
System.err.println(
"WARNING: No capacity specified for java.nio.Buffer return " +
"value for function \"" + binding + "\";" +
- " assuming size of equivalent C return type (" + sz + " bytes): " + binding);
+ " assuming size of equivalent C return type (sizeof(" + cReturnType.getName() + ")): " + binding);
}
writer.println(");");
} else if (javaReturnType.isString()) {
@@ -1044,11 +1039,8 @@ public class CMethodBindingEmitter extends FunctionEmitter
} else {
baseType = retType.asArray().getElementType().asPointer().getTargetType();
}
- SizeThunk sz = baseType.getSize();
- if (sz == null)
- sz = SizeThunk.constant(0);
writer.println(" (*env)->SetObjectArrayElement(env, " + arrayRes + ", " + arrayIdx +
- ", (*env)->NewDirectByteBuffer(env, _res[" + arrayIdx + "], " + sz.compute(machDesc) + "));");
+ ", (*env)->NewDirectByteBuffer(env, _res[" + arrayIdx + "], sizeof(" + baseType.getName() + ")));");
writer.println(" }");
writer.println(" return " + arrayRes + ";");
} else if (javaReturnType.isArray()) {
diff --git a/src/classes/com/sun/gluegen/FunctionEmitter.java b/src/classes/com/sun/gluegen/FunctionEmitter.java
index 2f52a9f36..3fa6f0341 100644
--- a/src/classes/com/sun/gluegen/FunctionEmitter.java
+++ b/src/classes/com/sun/gluegen/FunctionEmitter.java
@@ -50,16 +50,14 @@ 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, MachineDescription defaultMachDesc)
+ public FunctionEmitter(PrintWriter defaultOutput)
{
assert(defaultOutput != null);
this.defaultOutput = defaultOutput;
- this.defaultMachDesc = defaultMachDesc;
}
/**
@@ -69,13 +67,10 @@ 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)
{
while (mi.hasNext())
@@ -99,35 +94,29 @@ public abstract class FunctionEmitter
* Emit the function to the specified output (instead of the default
* output).
*/
- public void emit(PrintWriter output, MachineDescription machDesc)
+ public void emit(PrintWriter output)
{
emitDocComment(output);
//output.println(" // Emitter: " + getClass().getName());
emitSignature(output);
- emitBody(output, machDesc);
+ emitBody(output);
}
/**
* Emit the function to the default output (the output that was passed to
* the constructor)
*/
- public final void emit(MachineDescription machDesc)
+ public final void emit()
{
- emit(getDefaultOutput(), machDesc);
+ emit(getDefaultOutput());
}
/** 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, machDesc);
+ emit(w);
return sw.toString();
}
@@ -207,7 +196,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, MachineDescription machDesc);
+ protected abstract void emitBody(PrintWriter writer);
public static class EmissionModifier
{
diff --git a/src/classes/com/sun/gluegen/JavaEmitter.java b/src/classes/com/sun/gluegen/JavaEmitter.java
index 949dc6a51..d4bafb7a8 100644
--- a/src/classes/com/sun/gluegen/JavaEmitter.java
+++ b/src/classes/com/sun/gluegen/JavaEmitter.java
@@ -84,7 +84,6 @@ public class JavaEmitter implements GlueEmitter {
private PrintWriter javaWriter; // Emits either interface or, in AllStatic mode, everything
private PrintWriter javaImplWriter; // Only used in non-AllStatic modes for impl class
private PrintWriter cWriter;
- private MachineDescription machDesc;
private MachineDescription machDesc32;
private MachineDescription machDesc64;
@@ -101,11 +100,6 @@ public class JavaEmitter implements GlueEmitter {
machDesc32 = md32;
machDesc64 = md64;
- if (machDesc32 == null) {
- machDesc = machDesc64;
- } else {
- machDesc = machDesc32;
- }
}
public void beginEmission(GlueEmitterControls controls) throws IOException
@@ -293,7 +287,7 @@ public class JavaEmitter implements GlueEmitter {
for (int i = 0; i < methodBindingEmitters.size(); ++i) {
FunctionEmitter emitter = (FunctionEmitter)methodBindingEmitters.get(i);
try {
- emitter.emit(machDesc);
+ emitter.emit();
} catch (Exception e) {
throw new RuntimeException(
"Error while emitting binding for \"" + emitter.getName() + "\"", e);
@@ -360,7 +354,6 @@ public class JavaEmitter implements GlueEmitter {
JavaMethodBindingEmitter emitter =
new JavaMethodBindingEmitter(binding,
writer,
- machDesc,
cfg.runtimeExceptionType(),
!signatureOnly && needsBody,
false,
@@ -423,7 +416,6 @@ public class JavaEmitter implements GlueEmitter {
JavaMethodBindingEmitter emitter =
new JavaMethodBindingEmitter(binding,
writer,
- machDesc,
cfg.runtimeExceptionType(),
false,
true,
@@ -448,7 +440,6 @@ public class JavaEmitter implements GlueEmitter {
emitter =
new JavaMethodBindingEmitter(binding,
writer,
- machDesc,
cfg.runtimeExceptionType(),
false,
true,
@@ -509,7 +500,6 @@ 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 */
@@ -534,7 +524,6 @@ 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 */
@@ -564,7 +553,7 @@ public class JavaEmitter implements GlueEmitter {
try {
// Get Java binding for the function
- MethodBinding mb = bindFunction(sym, null, null);
+ MethodBinding mb = bindFunction(sym, null, null, machDesc64);
// JavaTypes representing C pointers in the initial
// MethodBinding have not been lowered yet to concrete types
@@ -694,7 +683,7 @@ public class JavaEmitter implements GlueEmitter {
}
Type containingCType = canonicalize(new PointerType(SizeThunk.POINTER, structType, 0));
- JavaType containingType = typeToJavaType(containingCType, false, machDesc);
+ JavaType containingType = typeToJavaType(containingCType, false, null);
if (!containingType.isCompoundTypeWrapper()) {
return;
}
@@ -860,7 +849,7 @@ public class JavaEmitter implements GlueEmitter {
// 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);
+ MethodBinding binding = bindFunction(funcSym, containingType, containingCType, machDesc64);
binding.findThisPointer(); // FIXME: need to provide option to disable this on per-function basis
writer.println();
@@ -868,7 +857,6 @@ public class JavaEmitter implements GlueEmitter {
JavaMethodBindingEmitter emitter =
new JavaMethodBindingEmitter(binding,
writer,
- machDesc,
cfg.runtimeExceptionType(),
true,
false,
@@ -878,13 +866,12 @@ public class JavaEmitter implements GlueEmitter {
false, // FIXME: should unify this with the general emission code
false);
emitter.addModifier(JavaMethodBindingEmitter.PUBLIC);
- emitter.emit(machDesc);
+ emitter.emit();
// Emit private native Java entry point for calling this function pointer
emitter =
new JavaMethodBindingEmitter(binding,
writer,
- machDesc,
cfg.runtimeExceptionType(),
false,
true,
@@ -895,20 +882,19 @@ public class JavaEmitter implements GlueEmitter {
false);
emitter.addModifier(JavaMethodBindingEmitter.PRIVATE);
emitter.addModifier(JavaMethodBindingEmitter.NATIVE);
- emitter.emit(machDesc);
+ emitter.emit();
// 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);
+ cEmitter.emit();
} catch (Exception e) {
System.err.println("While processing field " + field + " of type " + name + ":");
throw(e);
@@ -1504,7 +1490,8 @@ public class JavaEmitter implements GlueEmitter {
emitters for them. */
private MethodBinding bindFunction(FunctionSymbol sym,
JavaType containingType,
- Type containingCType) {
+ Type containingCType,
+ MachineDescription curMachDesc) {
MethodBinding binding = new MethodBinding(sym, containingType, containingCType);
@@ -1514,14 +1501,14 @@ public class JavaEmitter implements GlueEmitter {
PointerType prt = sym.getReturnType().asPointer();
if (prt == null ||
prt.getTargetType().asInt() == null ||
- prt.getTargetType().getSize(machDesc) != 1) {
+ prt.getTargetType().getSize(curMachDesc) != 1) {
throw new RuntimeException(
"Cannot apply ReturnsString configuration directive to \"" + sym +
"\". ReturnsString requires native method to have return type \"char *\"");
}
binding.setJavaReturnType(javaType(java.lang.String.class));
} else {
- binding.setJavaReturnType(typeToJavaType(sym.getReturnType(), false, machDesc));
+ binding.setJavaReturnType(typeToJavaType(sym.getReturnType(), false, curMachDesc));
}
// List of the indices of the arguments in this function that should be
@@ -1530,7 +1517,7 @@ public class JavaEmitter implements GlueEmitter {
for (int i = 0; i < sym.getNumArguments(); i++) {
Type cArgType = sym.getArgumentType(i);
- JavaType mappedType = typeToJavaType(cArgType, true, machDesc);
+ JavaType mappedType = typeToJavaType(cArgType, true, curMachDesc);
//System.out.println("C arg type -> \"" + cArgType + "\"" );
//System.out.println(" Java -> \"" + mappedType + "\"" );
diff --git a/src/classes/com/sun/gluegen/JavaMethodBindingEmitter.java b/src/classes/com/sun/gluegen/JavaMethodBindingEmitter.java
index 031a994e0..5a7e065f7 100644
--- a/src/classes/com/sun/gluegen/JavaMethodBindingEmitter.java
+++ b/src/classes/com/sun/gluegen/JavaMethodBindingEmitter.java
@@ -89,7 +89,6 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
public JavaMethodBindingEmitter(MethodBinding binding,
PrintWriter output,
- MachineDescription defaultMachDesc,
String runtimeExceptionType,
boolean emitBody,
boolean eraseBufferAndArrayTypes,
@@ -99,7 +98,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
boolean forIndirectBufferAndArrayImplementation,
boolean isUnimplemented)
{
- super(output, defaultMachDesc);
+ super(output);
this.binding = binding;
this.runtimeExceptionType = runtimeExceptionType;
this.emitBody = emitBody;
@@ -334,7 +333,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
return getArgumentName(i) + "_offset";
}
- protected void emitBody(PrintWriter writer, MachineDescription machDesc)
+ protected void emitBody(PrintWriter writer)
{
if (!emitBody) {
writer.println(';');
@@ -348,7 +347,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
emitPrologueOrEpilogue(prologue, writer);
emitPreCallSetup(binding, writer);
//emitReturnVariableSetup(binding, writer);
- emitReturnVariableSetupAndCall(binding, writer, machDesc);
+ emitReturnVariableSetupAndCall(binding, writer);
}
writer.println(" }");
}
@@ -435,7 +434,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
}
- protected void emitReturnVariableSetupAndCall(MethodBinding binding, PrintWriter writer, MachineDescription machDesc) {
+ protected void emitReturnVariableSetupAndCall(MethodBinding binding, PrintWriter writer) {
writer.print(" ");
JavaType returnType = binding.getJavaReturnType();
boolean needsResultAssignment = false;
@@ -507,7 +506,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
}
emitPrologueOrEpilogue(epilogue, writer);
if (needsResultAssignment) {
- emitCallResultReturn(binding, writer, machDesc);
+ emitCallResultReturn(binding, writer);
}
}
@@ -592,7 +591,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
return numArgsEmitted;
}
- protected void emitCallResultReturn(MethodBinding binding, PrintWriter writer, MachineDescription machDesc) {
+ protected void emitCallResultReturn(MethodBinding binding, PrintWriter writer) {
JavaType returnType = binding.getJavaReturnType();
if (returnType.isCompoundTypeWrapper()) {
@@ -621,8 +620,8 @@ 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(machDesc) + ");");
- writer.println(" _res.limit ((1 + _count) * " + cReturnType.getSize(machDesc) + ");");
+ writer.println(" _res.position(_count * " + getReturnTypeString(true) + ".size());");
+ writer.println(" _res.limit ((1 + _count) * " + getReturnTypeString(true) + ".size());");
writer.println(" ByteBuffer _tmp = _res.slice();");
writer.println(" _tmp.order(ByteOrder.nativeOrder());");
writer.println(" _res.position(0);");
diff --git a/src/classes/com/sun/gluegen/cgram/types/MachineDescription.java b/src/classes/com/sun/gluegen/cgram/types/MachineDescription.java
index 41923979b..b3aaf53aa 100644
--- a/src/classes/com/sun/gluegen/cgram/types/MachineDescription.java
+++ b/src/classes/com/sun/gluegen/cgram/types/MachineDescription.java
@@ -48,6 +48,7 @@ public class MachineDescription {
private int floatSizeInBytes;
private int doubleSizeInBytes;
private int pointerSizeInBytes;
+ private int structAlignmentInBytes;
public MachineDescription(int charSizeInBytes,
int shortSizeInBytes,
@@ -56,7 +57,8 @@ public class MachineDescription {
int int64SizeInBytes,
int floatSizeInBytes,
int doubleSizeInBytes,
- int pointerSizeInBytes) {
+ int pointerSizeInBytes,
+ int structAlignmentInBytes) {
this.charSizeInBytes = charSizeInBytes;
this.shortSizeInBytes = shortSizeInBytes;
this.intSizeInBytes = intSizeInBytes;
@@ -65,6 +67,7 @@ public class MachineDescription {
this.floatSizeInBytes = floatSizeInBytes;
this.doubleSizeInBytes = doubleSizeInBytes;
this.pointerSizeInBytes = pointerSizeInBytes;
+ this.structAlignmentInBytes = structAlignmentInBytes;
}
public int charSizeInBytes() { return charSizeInBytes; }
@@ -75,4 +78,5 @@ public class MachineDescription {
public int floatSizeInBytes() { return floatSizeInBytes; }
public int doubleSizeInBytes() { return doubleSizeInBytes; }
public int pointerSizeInBytes() { return pointerSizeInBytes; }
+ public int structAlignmentInBytes() { return structAlignmentInBytes; }
}
diff --git a/src/classes/com/sun/gluegen/cgram/types/MachineDescription32Bit.java b/src/classes/com/sun/gluegen/cgram/types/MachineDescription32Bit.java
index 1dbbb700c..7b8f12d92 100644
--- a/src/classes/com/sun/gluegen/cgram/types/MachineDescription32Bit.java
+++ b/src/classes/com/sun/gluegen/cgram/types/MachineDescription32Bit.java
@@ -41,6 +41,6 @@ package com.sun.gluegen.cgram.types;
public class MachineDescription32Bit extends MachineDescription {
public MachineDescription32Bit() {
- super(1, 2, 4, 4, 8, 4, 8, 4);
+ super(1, 2, 4, 4, 8, 4, 8, 4, 8);
}
}
diff --git a/src/classes/com/sun/gluegen/cgram/types/MachineDescription64Bit.java b/src/classes/com/sun/gluegen/cgram/types/MachineDescription64Bit.java
index 00d581266..10363998f 100644
--- a/src/classes/com/sun/gluegen/cgram/types/MachineDescription64Bit.java
+++ b/src/classes/com/sun/gluegen/cgram/types/MachineDescription64Bit.java
@@ -41,6 +41,6 @@ package com.sun.gluegen.cgram.types;
public class MachineDescription64Bit extends MachineDescription {
public MachineDescription64Bit() {
- super(1, 2, 4, 8, 8, 4, 8, 8);
+ super(1, 2, 4, 8, 8, 4, 8, 8, 16);
}
}
diff --git a/src/classes/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java b/src/classes/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java
index cc363178d..423f009e2 100755
--- a/src/classes/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java
+++ b/src/classes/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java
@@ -72,7 +72,6 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter {
}
},
methodToWrap.getDefaultOutput(),
- methodToWrap.getDefaultMachineDescription(),
methodToWrap.getJavaPackageName(),
methodToWrap.getJavaClassName(),
methodToWrap.getIsOverloadedBinding(),