use of com.oracle.truffle.api.frame.FrameSlot in project sulong by graalvm.
the class AsmFactory method getOperandStore.
private LLVMExpressionNode getOperandStore(Type type, AsmOperand operand, LLVMExpressionNode from) {
if (operand instanceof AsmRegisterOperand) {
AsmRegisterOperand op = (AsmRegisterOperand) operand;
FrameSlot frame = getRegisterSlot(op.getBaseRegister());
LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
int shift = op.getShift();
LLVMExpressionNode out = null;
assert (type instanceof PointerType && op.getType() == PrimitiveType.I64) || (op.getType() instanceof PointerType && type == PrimitiveType.I64) || (type == op.getType());
switch(((PrimitiveType) op.getType()).getPrimitiveKind()) {
case I8:
out = LLVMI8ToR64NodeGen.create(shift, register, from);
break;
case I16:
out = LLVMI16ToR64NodeGen.create(register, from);
break;
case I32:
out = LLVMI32ToR64NodeGen.create(from);
break;
case I64:
out = from;
break;
default:
throw new AsmParseException("unsupported operand type: " + op.getType());
}
return LLVMWriteI64NodeGen.create(out, frame, null);
} else if (operand instanceof AsmArgumentOperand) {
AsmArgumentOperand op = (AsmArgumentOperand) operand;
Argument info = argInfo.get(op.getIndex());
if (info.isMemory()) {
LLVMExpressionNode address = info.getAddress();
switch(((PrimitiveType) type).getPrimitiveKind()) {
case I8:
return LLVMI8StoreNodeGen.create(address, from);
case I16:
return LLVMI16StoreNodeGen.create(address, from);
case I32:
return LLVMI32StoreNodeGen.create(address, from);
case I64:
return LLVMI64StoreNodeGen.create(address, from);
default:
throw new AsmParseException("unsupported operand type: " + type);
}
} else if (info.isRegister()) {
FrameSlot frame = getRegisterSlot(info.getRegister());
LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
LLVMExpressionNode out = null;
if (type instanceof PointerType || info.getType() instanceof PointerType) {
return LLVMAMD64WriteAddressRegisterNodeGen.create(sourceLocation, from, frame);
}
switch(((PrimitiveType) type).getPrimitiveKind()) {
case I8:
out = LLVMI8ToR64NodeGen.create(0, register, from);
break;
case I16:
out = LLVMI16ToR64NodeGen.create(register, from);
break;
case I32:
out = LLVMI32ToR64NodeGen.create(from);
break;
case I64:
out = from;
break;
default:
throw new AsmParseException("unsupported operand type: " + type);
}
return LLVMWriteI64NodeGen.create(out, frame, null);
} else {
throw new AssertionError("this should not happen; " + info);
}
} else if (operand instanceof AsmMemoryOperand) {
LLVMExpressionNode address = getOperandAddress(operand);
switch(((PrimitiveType) type).getPrimitiveKind()) {
case I8:
return LLVMI8StoreNodeGen.create(null, address, from);
case I16:
return LLVMI16StoreNodeGen.create(null, address, from);
case I32:
return LLVMI32StoreNodeGen.create(null, address, from);
case I64:
return LLVMI64StoreNodeGen.create(null, address, from);
default:
throw new AsmParseException("unsupported operand type: " + type);
}
}
throw new AsmParseException("unsupported operand type: " + operand);
}
use of com.oracle.truffle.api.frame.FrameSlot in project sulong by graalvm.
the class AsmFactory method getRegisterSlot.
private FrameSlot getRegisterSlot(String name) {
if (name.startsWith(TEMP_REGISTER_PREFIX)) {
addFrameSlot(name, PrimitiveType.I64);
return frameDescriptor.findFrameSlot(name);
}
AsmRegisterOperand op = new AsmRegisterOperand(name);
String baseRegister = op.getBaseRegister();
addFrameSlot(baseRegister, PrimitiveType.I64);
FrameSlot frame = frameDescriptor.findFrameSlot(baseRegister);
return frame;
}
use of com.oracle.truffle.api.frame.FrameSlot in project sulong by graalvm.
the class AsmFactory method getOperandLoad.
private LLVMExpressionNode getOperandLoad(Type typeHint, AsmOperand operand) {
Type type = typeHint == null ? operand.getType() : typeHint;
if (operand instanceof AsmRegisterOperand) {
AsmRegisterOperand op = (AsmRegisterOperand) operand;
FrameSlot frame = getRegisterSlot(op.getBaseRegister());
LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
int shift = op.getShift();
assert type instanceof PointerType || type == op.getType();
if (type instanceof PointerType) {
switch(((PrimitiveType) op.getType()).getPrimitiveKind()) {
case I8:
return LLVMToI8NoZeroExtNodeGen.create(register);
case I16:
return LLVMToI16NoZeroExtNodeGen.create(register);
case I32:
return LLVMToI32NoZeroExtNodeGen.create(register);
case I64:
return LLVMAMD64ReadAddressNodeGen.create(frame);
default:
throw new AsmParseException("unsupported operand type: " + type);
}
}
switch(((PrimitiveType) op.getType()).getPrimitiveKind()) {
case I8:
return LLVMAMD64I64ToI8NodeGen.create(shift, register);
case I16:
return LLVMToI16NoZeroExtNodeGen.create(register);
case I32:
return LLVMToI32NoZeroExtNodeGen.create(register);
case I64:
return register;
default:
throw new AsmParseException("unsupported operand type: " + type);
}
} else if (operand instanceof AsmImmediateOperand) {
AsmImmediateOperand op = (AsmImmediateOperand) operand;
if (op.isLabel()) {
throw new AsmParseException("labels not supported");
} else {
switch(((PrimitiveType) type).getPrimitiveKind()) {
case I8:
return LLVMAMD64I8NodeGen.create((byte) op.getValue());
case I16:
return LLVMAMD64I16NodeGen.create((short) op.getValue());
case I32:
return LLVMAMD64I32NodeGen.create((int) op.getValue());
case I64:
return LLVMAMD64I64NodeGen.create(op.getValue());
default:
throw new AsmParseException("unsupported operand type: " + type);
}
}
} else if (operand instanceof AsmArgumentOperand) {
AsmArgumentOperand op = (AsmArgumentOperand) operand;
Argument info = argInfo.get(op.getIndex());
FrameSlot frame = getArgumentSlot(op.getIndex(), type);
if (info.isMemory()) {
if (type instanceof PointerType) {
return LLVMAddressDirectLoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
}
switch(((PrimitiveType) type).getPrimitiveKind()) {
case I8:
return LLVMI8LoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
case I16:
return LLVMI16LoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
case I32:
return LLVMI32LoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
case I64:
return LLVMI64LoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
default:
throw new AsmParseException("unsupported operand type: " + type);
}
} else if (info.isRegister()) {
frame = getRegisterSlot(info.getRegister());
if (type instanceof PointerType) {
return LLVMAMD64ReadAddressNodeGen.create(frame);
}
LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
switch(((PrimitiveType) type).getPrimitiveKind()) {
case I8:
return LLVMToI8NoZeroExtNodeGen.create(register);
case I16:
return LLVMToI16NoZeroExtNodeGen.create(register);
case I32:
return LLVMToI32NoZeroExtNodeGen.create(register);
case I64:
return LLVMToI64NoZeroExtNodeGen.create(register);
default:
throw new AsmParseException("unsupported operand type: " + type);
}
} else {
// constraint "0"-"9"
if (type instanceof PointerType) {
return LLVMAMD64ReadAddressNodeGen.create(frame);
}
LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
switch(((PrimitiveType) type).getPrimitiveKind()) {
case I8:
return LLVMToI8NoZeroExtNodeGen.create(register);
case I16:
return LLVMToI16NoZeroExtNodeGen.create(register);
case I32:
return LLVMToI32NoZeroExtNodeGen.create(register);
case I64:
return LLVMToI64NoZeroExtNodeGen.create(register);
default:
throw new AsmParseException("unsupported operand type: " + type);
}
}
} else if (operand instanceof AsmMemoryOperand) {
LLVMExpressionNode address = getOperandAddress(operand);
LLVMExpressionNode addr = LLVMToAddressNodeGen.create(address);
if (type instanceof PrimitiveType) {
switch(((PrimitiveType) type).getPrimitiveKind()) {
case I8:
return LLVMI8LoadNodeGen.create(addr);
case I16:
return LLVMI16LoadNodeGen.create(addr);
case I32:
return LLVMI32LoadNodeGen.create(addr);
case I64:
return LLVMI64LoadNodeGen.create(addr);
default:
throw new AsmParseException("unsupported operand type: " + type);
}
} else if (type instanceof PointerType) {
return LLVMAddressDirectLoadNodeGen.create(addr);
} else {
throw new AsmParseException("unsupported operand type: " + type);
}
}
throw new AsmParseException("unsupported operand: " + operand);
}
use of com.oracle.truffle.api.frame.FrameSlot 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.frame.FrameSlot in project sulong by graalvm.
the class LLVMContext method getGlobalFrameSlot.
public FrameSlot getGlobalFrameSlot(Object symbol, Type type) {
FrameSlotKind kind;
if (type instanceof PrimitiveType) {
switch(((PrimitiveType) type).getPrimitiveKind()) {
case DOUBLE:
kind = FrameSlotKind.Double;
break;
case FLOAT:
kind = FrameSlotKind.Float;
break;
case HALF:
case I16:
case I32:
kind = FrameSlotKind.Int;
break;
case I1:
kind = FrameSlotKind.Boolean;
break;
case I64:
kind = FrameSlotKind.Long;
break;
case I8:
kind = FrameSlotKind.Byte;
break;
default:
kind = FrameSlotKind.Object;
break;
}
} else {
kind = FrameSlotKind.Object;
}
FrameSlot frameSlot = globalFrameDescriptor.findOrAddFrameSlot(symbol, type, kind);
return frameSlot;
}
Aggregations