use of com.oracle.truffle.api.interop.UnknownIdentifierException in project sulong by graalvm.
the class LLVMTruffleReadNBytes method interop.
@Specialization
protected Object interop(LLVMTruffleObject objectWithOffset, int n, @Cached("createForeignReadNode()") Node foreignRead, @Cached("createToByteNode()") ForeignToLLVM toLLVM, @Cached("getContextReference()") ContextReference<LLVMContext> ctxRef) {
long offset = objectWithOffset.getOffset();
TruffleObject object = objectWithOffset.getObject();
byte[] chars = new byte[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);
}
chars[i] = (byte) toLLVM.executeWithTarget(rawValue);
}
TruffleObject ret = (TruffleObject) ctxRef.get().getEnv().asGuestValue(chars);
return new LLVMTruffleObject(LLVMTypedForeignObject.createUnknown(ret));
}
Aggregations