use of com.oracle.truffle.llvm.runtime.LLVMTruffleObject in project sulong by graalvm.
the class LLVMGlobalRootNode method execute.
@Override
@ExplodeLoop
public Object execute(VirtualFrame frame) {
try (StackPointer basePointer = getContext().getThreadingStack().getStack().newFrame()) {
try {
TruffleObject appPath = (TruffleObject) ctxRef.get().getEnv().asGuestValue(applicationPath.getBytes());
LLVMTruffleObject applicationPathObj = new LLVMTruffleObject(LLVMTypedForeignObject.createUnknown(appPath));
Object[] realArgs = new Object[] { basePointer, mainFunctionType, applicationPathObj };
Object result = startFunction.call(realArgs);
getContext().awaitThreadTermination();
return result;
} catch (LLVMExitException e) {
LLVMContext context = getContext();
// if any variant of exit or abort was called, we know that all the necessary
// cleanup was already done
context.setCleanupNecessary(false);
context.awaitThreadTermination();
return e.getReturnCode();
} catch (SulongRuntimeException e) {
CompilerDirectives.transferToInterpreter();
throw e;
} catch (GuestLanguageRuntimeException e) {
CompilerDirectives.transferToInterpreter();
return e.handleExit();
} finally {
// if not done already, we want at least call a shutdown command
getContext().shutdownThreads();
}
}
}
use of com.oracle.truffle.llvm.runtime.LLVMTruffleObject in project sulong by graalvm.
the class LLVMToFunctionNode method doTruffleObject.
@Specialization
protected Object doTruffleObject(LLVMTruffleObject from, @Cached("create()") LLVMAsForeignNode asForeign) {
TruffleObject foreign = asForeign.execute(from);
if (ForeignAccess.sendIsNull(isNull, foreign)) {
return LLVMAddress.fromLong(0);
} else if (ForeignAccess.sendIsExecutable(isExecutable, foreign)) {
return from;
}
CompilerDirectives.transferToInterpreter();
throw new IllegalStateException("Not a function");
}
use of com.oracle.truffle.llvm.runtime.LLVMTruffleObject 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.llvm.runtime.LLVMTruffleObject 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));
}
use of com.oracle.truffle.llvm.runtime.LLVMTruffleObject in project sulong by graalvm.
the class LLVMTruffleReadNString method interop.
@Specialization
protected Object interop(LLVMTruffleObject objectWithOffset, int n, @Cached("createForeignReadNode()") Node foreignRead, @Cached("createToByteNode()") ForeignToLLVM toLLVM) {
long offset = objectWithOffset.getOffset();
TruffleObject object = objectWithOffset.getObject();
char[] chars = new char[n];
for (int i = 0; i < n; i++) {
Object rawValue;
try {
rawValue = ForeignAccess.sendRead(foreignRead, object, offset + i);
} catch (UnknownIdentifierException | UnsupportedMessageException e) {
CompilerDirectives.transferToInterpreter();
throw new IllegalStateException(e);
}
byte byteValue = (byte) toLLVM.executeWithTarget(rawValue);
chars[i] = (char) Byte.toUnsignedInt(byteValue);
}
return new String(chars);
}
Aggregations