use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer in project graal by oracle.
the class LLVMVaListStorage method invokeMember.
@ExportMessage
public Object invokeMember(String member, Object[] arguments, @Cached.Shared("escapeNode") @Cached LLVMPointerDataEscapeNode pointerEscapeNode) throws ArityException, UnknownIdentifierException, UnsupportedTypeException {
if (GET_MEMBER.equals(member)) {
if (arguments.length == 2) {
if (!(arguments[0] instanceof Integer)) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw UnsupportedTypeException.create(new Object[] { arguments[0] }, "Index argument must be an integer");
}
int i = (Integer) arguments[0];
if (i >= realArguments.length - numberOfExplicitArguments) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new ArrayIndexOutOfBoundsException(i);
}
Object arg = realArguments[numberOfExplicitArguments + i];
if (!(arguments[1] instanceof LLVMInteropType.Structured)) {
return arg;
}
LLVMInteropType.Structured type = (LLVMInteropType.Structured) arguments[1];
if (!LLVMPointer.isInstance(arg)) {
// arg's types
return arg;
}
LLVMPointer ptrArg = LLVMPointer.cast(arg);
return pointerEscapeNode.executeWithType(ptrArg, type);
} else {
throw ArityException.create(2, 2, arguments.length);
}
}
throw UnknownIdentifierException.create(member);
}
use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer in project graal by oracle.
the class LLDBMemoryValue method loadValue.
private Object loadValue(Type loadtype, int byteOffset) {
final LLVMPointer offsetPointer = pointer.increment(byteOffset);
CallTarget loadFunction = LLVMLanguage.getLLDBSupport().getLoadFunction(loadtype);
return loadFunction.call(offsetPointer);
}
use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer in project graal by oracle.
the class LLVMArrayLiteralNode method foreignWrite.
@Specialization
@ExplodeLoop
protected LLVMPointer foreignWrite(VirtualFrame frame, LLVMPointer addr) {
LLVMPointer currentPtr = addr;
for (int i = 0; i < values.length; i++) {
write.executeWithTarget(currentPtr, values[i].executeGeneric(frame));
currentPtr = currentPtr.increment(stride);
}
return addr;
}
use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer in project graal by oracle.
the class LLVMX86_64VaListStorage method shift.
/**
* This is the implementation of the {@code va_arg} instruction.
*/
@SuppressWarnings("static-method")
@ExportMessage
Object shift(Type type, @SuppressWarnings("unused") Frame frame, @CachedLibrary(limit = "1") LLVMManagedReadLibrary readLib, @CachedLibrary(limit = "1") LLVMManagedWriteLibrary writeLib, @Cached BranchProfile regAreaProfile, @Cached("createBinaryProfile()") ConditionProfile isNativizedProfile) {
int regSaveOffs = 0;
int regSaveStep = 0;
int regSaveLimit = 0;
boolean lookIntoRegSaveArea = true;
VarArgArea varArgArea = getVarArgArea(type);
switch(varArgArea) {
case GP_AREA:
regSaveOffs = X86_64BitVarArgs.GP_OFFSET;
regSaveStep = X86_64BitVarArgs.GP_STEP;
regSaveLimit = X86_64BitVarArgs.GP_LIMIT;
break;
case FP_AREA:
regSaveOffs = X86_64BitVarArgs.FP_OFFSET;
regSaveStep = X86_64BitVarArgs.FP_STEP;
regSaveLimit = X86_64BitVarArgs.FP_LIMIT;
break;
case OVERFLOW_AREA:
lookIntoRegSaveArea = false;
break;
}
if (lookIntoRegSaveArea) {
regAreaProfile.enter();
int offs = readLib.readI32(this, regSaveOffs);
if (offs < regSaveLimit) {
writeLib.writeI32(this, regSaveOffs, offs + regSaveStep);
long n = this.regSaveArea.offsetToIndex(offs);
int i = (int) ((n << 32) >> 32);
return this.regSaveArea.args[i];
}
}
// overflow area
if (isNativizedProfile.profile(isNativized())) {
// Synchronize the managed current argument pointer from the native overflow area
this.overflowArgArea.setOffset(getArgPtrFromNativePtr(this, readLib));
Object currentArg = this.overflowArgArea.getCurrentArg();
// Shift the managed current argument pointer
this.overflowArgArea.shift(1);
// Update the new native current argument pointer from the managed one
long shiftOffs = this.overflowArgArea.getOffset();
LLVMPointer shiftedOverflowAreaPtr = overflowArgAreaBaseNativePtr.increment(shiftOffs);
writeLib.writePointer(this, X86_64BitVarArgs.OVERFLOW_ARG_AREA, shiftedOverflowAreaPtr);
return currentArg;
} else {
Object currentArg = this.overflowArgArea.getCurrentArg();
this.overflowArgArea.shift(1);
return currentArg;
}
}
use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer in project graal by oracle.
the class LLVMComplex80BitFloatMul method doMul.
@Specialization
public Object doMul(VirtualFrame frame, @Cached("getSizeInBytes()") int sizeInBytes) {
try {
LLVM80BitFloat longDoubleA = (LLVM80BitFloat) aNode.executeGeneric(frame);
LLVM80BitFloat longDoubleB = (LLVM80BitFloat) bNode.executeGeneric(frame);
LLVM80BitFloat longDoubleC = (LLVM80BitFloat) cNode.executeGeneric(frame);
LLVM80BitFloat longDoubleD = (LLVM80BitFloat) dNode.executeGeneric(frame);
double a = longDoubleA.getDoubleValue();
double b = longDoubleB.getDoubleValue();
double c = longDoubleC.getDoubleValue();
double d = longDoubleD.getDoubleValue();
double ac = a * c;
double bd = b * d;
double ad = a * d;
double bc = b * c;
double zReal = ac - bd;
double zImag = ad + bc;
LLVMPointer allocatedMemory = alloc.executeLLVMPointer(frame);
store.executeWithTarget(allocatedMemory, LLVM80BitFloat.fromDouble(zReal));
store.executeWithTarget(allocatedMemory.increment(sizeInBytes), LLVM80BitFloat.fromDouble(zImag));
return allocatedMemory;
} catch (UnexpectedResultException | ClassCastException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
}
Aggregations