use of com.oracle.truffle.api.dsl.Specialization in project sulong by graalvm.
the class LLVMNativeDispatchNode method doGeneric.
@Specialization
protected Object doGeneric(LLVMAddress function, Object[] arguments, @Cached("getContextReference()") ContextReference<LLVMContext> context, @Cached("identityFunction()") TruffleObject identity, @Cached("createToNativeNodes()") LLVMNativeConvertNode[] toNative, @Cached("createFromNativeNode()") LLVMNativeConvertNode fromNative, @Cached("nativeCallStatisticsEnabled(context)") boolean statistics) {
Object[] nativeArgs = prepareNativeArguments(arguments, toNative);
Object returnValue;
try (StackPointer save = ((StackPointer) arguments[0]).newFrame()) {
returnValue = LLVMNativeCallUtils.callNativeFunction(statistics, context, nativeCallNode, dispatchIdentity(identity, function.getVal()), nativeArgs, null);
}
return fromNative.executeConvert(returnValue);
}
use of com.oracle.truffle.api.dsl.Specialization in project sulong by graalvm.
the class LLVMX86_64VAStart method vaStart.
@Specialization
protected Object vaStart(VirtualFrame frame, Object targetAddress) {
final Object[] arguments = getArgumentsArray(frame);
final int vaLength = arguments.length - numberOfExplicitArguments;
Object regSaveArea = stackAllocationNode.executeWithTarget(frame, X86_64BitVarArgs.FP_LIMIT);
int overflowArgAreaSize = computeOverflowArgAreaSize(arguments);
Object overflowArgArea = stackAllocationNode.executeWithTarget(frame, overflowArgAreaSize);
int gpOffset = calculateUsedGpArea(arguments);
int fpOffset = X86_64BitVarArgs.GP_LIMIT + calculateUsedFpArea(arguments);
initializeVaList(targetAddress, gpOffset, fpOffset, overflowArgArea, regSaveArea);
// reconstruct register_save_area and overflow_arg_area according to AMD64 ABI
if (vaLength > 0) {
int overflowOffset = 0;
for (int i = 0; i < vaLength; i++) {
final Object object = arguments[numberOfExplicitArguments + i];
final VarArgArea area = getVarArgArea(object);
if (area == VarArgArea.GP_AREA && gpOffset < X86_64BitVarArgs.GP_LIMIT) {
storeArgument(regSaveArea, gpOffset, memmove, pointerArithmeticRegSaveArea, i64RegSaveAreaStore, i32RegSaveAreaStore, fp80bitRegSaveAreaStore, object);
gpOffset += X86_64BitVarArgs.GP_STEP;
} else if (area == VarArgArea.FP_AREA && fpOffset < X86_64BitVarArgs.FP_LIMIT) {
storeArgument(regSaveArea, fpOffset, memmove, pointerArithmeticRegSaveArea, i64RegSaveAreaStore, i32RegSaveAreaStore, fp80bitRegSaveAreaStore, object);
fpOffset += X86_64BitVarArgs.FP_STEP;
} else {
assert overflowArgAreaSize >= overflowOffset;
overflowOffset += storeArgument(overflowArgArea, overflowOffset, memmove, pointerArithmeticOverflowArea, i64OverflowArgAreaStore, i32OverflowArgAreaStore, fp80bitOverflowArgAreaStore, object);
}
}
}
return null;
}
use of com.oracle.truffle.api.dsl.Specialization in project sulong by graalvm.
the class LLVMPanic method doOp.
@Specialization
protected Object doOp(LLVMGlobal panicLocVar, @Cached("createToNativeWithTarget()") LLVMToNativeNode globalAccess, @Cached("createPanicLocation()") PanicLocType panicLoc, @Cached("getLLVMMemory()") LLVMMemory memory) {
LLVMAddress addr = globalAccess.executeWithTarget(panicLocVar);
CompilerDirectives.transferToInterpreter();
throw panicLoc.read(memory, addr.getVal());
}
use of com.oracle.truffle.api.dsl.Specialization in project sulong by graalvm.
the class LLVMTruffleHandleToManaged method doIntrinsic.
@Specialization
protected LLVMTruffleObject doIntrinsic(Object rawHandle, @Cached("getContextReference()") ContextReference<LLVMContext> context, @Cached("createToNativeWithTarget()") LLVMToNativeNode forceAddressNode) {
LLVMAddress handle = forceAddressNode.executeWithTarget(rawHandle);
TruffleObject object = context.get().getManagedObjectForHandle(handle);
return new LLVMTruffleObject(object);
}
use of com.oracle.truffle.api.dsl.Specialization in project sulong by graalvm.
the class LLVMTruffleReadNBytes method doIntrinsic.
@Specialization
protected Object doIntrinsic(LLVMAddress value, int n, @Cached("getLLVMMemory()") LLVMMemory memory, @Cached("getContextReference()") ContextReference<LLVMContext> ctxRef) {
int count = n < 0 ? 0 : n;
byte[] bytes = new byte[count];
long ptr = value.getVal();
for (int i = 0; i < count; i++) {
bytes[i] = memory.getI8(ptr);
ptr += Byte.BYTES;
}
TruffleObject ret = (TruffleObject) ctxRef.get().getEnv().asGuestValue(bytes);
return new LLVMTruffleObject(LLVMTypedForeignObject.createUnknown(ret));
}
Aggregations