use of com.oracle.truffle.api.dsl.Specialization 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);
}
use of com.oracle.truffle.api.dsl.Specialization in project sulong by graalvm.
the class LLVMPolyglotExport method doExport.
@Specialization
protected Object doExport(Object name, Object value, @Cached("getContextReference()") ContextReference<LLVMContext> ctxRef) {
String symbolName = readString.executeWithTarget(name);
LLVMContext ctx = ctxRef.get();
Object escaped = escape.executeWithTarget(value);
try {
ForeignAccess.sendWrite(write, (TruffleObject) ctx.getEnv().getPolyglotBindings(), symbolName, escaped);
} catch (InteropException ex) {
throw ex.raise();
}
return null;
}
use of com.oracle.truffle.api.dsl.Specialization in project sulong by graalvm.
the class LLVMPrintStackTrace method doOp.
@TruffleBoundary
@Specialization
protected Object doOp() {
SulongStackTrace trace = getStackTrace("__sulong_print_stacktrace");
printCStackTrace(trace);
return null;
}
use of com.oracle.truffle.api.dsl.Specialization in project sulong by graalvm.
the class LLVMStackRestore method doVoid.
@Specialization
protected Object doVoid(VirtualFrame frame, LLVMAddress addr) {
StackPointer pointer = (StackPointer) FrameUtil.getObjectSafe(frame, getStackPointerSlot());
pointer.set(addr.getVal());
return null;
}
use of com.oracle.truffle.api.dsl.Specialization in project sulong by graalvm.
the class LLVMForeignCallNode method callIndirect.
@Specialization(replaces = "callDirectCached")
protected Object callIndirect(LLVMFunctionDescriptor function, Object[] arguments, @Cached("create()") IndirectCallNode callNode, @Cached("createSlowPackArguments()") SlowPackForeignArgumentsNode slowPack, @Cached("create()") LLVMGetStackNode getStack, @Cached("getLLVMMemory()") LLVMMemory memory) {
assert !(function.getType().getReturnType() instanceof StructureType);
LLVMStack stack = getStack.executeWithTarget(function.getContext().getThreadingStack(), Thread.currentThread());
Object result;
try (StackPointer stackPointer = stack.newFrame()) {
result = callNode.call(getCallTarget(function), slowPack.pack(function, memory, arguments, stackPointer));
}
return prepareValueForEscape.executeWithTarget(result);
}
Aggregations