use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project sulong by graalvm.
the class LLVMRunDestructorFunctions method runDestructorFunctions.
@TruffleBoundary
private void runDestructorFunctions() {
// is only executed once per context so it will be executed in the interpreter only
LLVMContext context = getContextReference().get();
RootCallTarget[] targets = context.getDestructorFunctions().toArray(new RootCallTarget[0]);
for (RootCallTarget target : targets) {
try (StackPointer stackPointer = context.getThreadingStack().getStack().newFrame()) {
callNode.call(target, new Object[] { stackPointer });
}
}
}
use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project sulong by graalvm.
the class LLVMSourceScope method getVariables.
@TruffleBoundary
protected Object getVariables(Frame frame) {
final Map<String, LLVMDebugObject> vars = new HashMap<>();
if (frame != null && !symbols.isEmpty()) {
for (FrameSlot slot : frame.getFrameDescriptor().getSlots()) {
if (slot.getIdentifier() instanceof LLVMSourceSymbol && frame.getValue(slot) instanceof LLVMDebugValue) {
final LLVMSourceSymbol symbol = (LLVMSourceSymbol) slot.getIdentifier();
final LLVMDebugObject value = ((LLVMDebugValue) frame.getValue(slot)).getValue(symbol);
if (symbols.contains(symbol)) {
vars.put(symbol.getName(), value);
}
}
}
}
for (LLVMSourceSymbol symbol : symbols) {
if (!vars.containsKey(symbol.getName())) {
LLVMDebugValue dbgVal = context.getStatic(symbol);
if (dbgVal == null) {
final LLVMFrameValueAccess allocation = context.getFrameValue(symbol);
if (allocation != null && frame != null) {
dbgVal = allocation.getValue(frame);
}
}
if (dbgVal == null) {
dbgVal = LLVMDebugValue.UNAVAILABLE;
}
vars.put(symbol.getName(), dbgVal.getValue(symbol));
}
}
return new LLVMSourceScopeVariables(vars);
}
use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project sulong by graalvm.
the class LLVMIVarBit method logicalRightShift.
@TruffleBoundary
public LLVMIVarBit logicalRightShift(LLVMIVarBit right) {
int shiftAmount = right.getIntValue();
BigInteger mask = BigInteger.valueOf(-1).shiftLeft(bits - shiftAmount).not();
BigInteger result = new BigInteger(arr).shiftRight(shiftAmount).and(mask);
return asIVar(result);
}
use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project sulong by graalvm.
the class LLVMIVarBit method getByteBuffer.
@TruffleBoundary
private ByteBuffer getByteBuffer(int minSizeBytes, boolean signExtend) {
int allocationSize = Math.max(minSizeBytes, getByteSize());
ByteBuffer bb = ByteBuffer.allocate(allocationSize).order(ByteOrder.BIG_ENDIAN);
boolean truncation = bits > minSizeBytes * Byte.SIZE;
boolean shouldAddLeadingOnes = signExtend && mostSignificantBit();
if (!truncation) {
int bytesToFillUp = minSizeBytes - getByteSize();
if (shouldAddLeadingOnes) {
for (int i = 0; i < bytesToFillUp; i++) {
bb.put((byte) -1);
}
} else {
for (int i = 0; i < bytesToFillUp; i++) {
bb.put((byte) 0);
}
}
}
if (bits % Byte.SIZE == 0) {
bb.put(arr, 0, getByteSize());
} else {
BitSet bitSet = new BitSet(Byte.SIZE);
int bitsToSet = bits % Byte.SIZE;
for (int i = 0; i < bitsToSet; i++) {
boolean isBitSet = ((arr[0] >> i) & 1) == 1;
if (isBitSet) {
bitSet.set(i);
}
}
if (shouldAddLeadingOnes) {
for (int i = bitsToSet; i < Byte.SIZE; i++) {
bitSet.set(i);
}
}
byte firstByteResult;
if (bitSet.isEmpty()) {
firstByteResult = 0;
} else {
firstByteResult = bitSet.toByteArray()[0];
}
// FIXME actually need to truncate or sign extend individual bits
bb.put(firstByteResult);
for (int i = 1; i < arr.length; i++) {
bb.put(arr[i]);
}
}
bb.position(Math.max(0, getByteSize() - minSizeBytes));
return bb;
}
use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project sulong by graalvm.
the class NFIContextExtension method createNativeWrapper.
@TruffleBoundary
public TruffleObject createNativeWrapper(LLVMFunctionDescriptor descriptor) {
TruffleObject wrapper = null;
try {
String signature = getNativeSignature(descriptor.getType(), 0);
TruffleObject createNativeWrapper = getNativeFunction(descriptor.getContext(), "@createNativeWrapper", String.format("(env, %s):object", signature));
try {
wrapper = (TruffleObject) ForeignAccess.sendExecute(Message.createExecute(1).createNode(), createNativeWrapper, descriptor);
} catch (InteropException ex) {
throw new AssertionError(ex);
}
} catch (UnsupportedNativeTypeException ex) {
// ignore, fall back to tagged id
}
return wrapper;
}
Aggregations