use of com.oracle.truffle.llvm.runtime.types.PrimitiveType in project sulong by graalvm.
the class LLVMGlobalRootNode method getMainFunctionType.
/**
* Identify the signature of the main method so that crt0.c:_start can invoke the main method
* with the correct signature. This is necessary because languages like Rust use non-standard C
* main functions.
*/
private static int getMainFunctionType(LLVMFunctionDescriptor mainFunctionDescriptor) {
Type returnType = mainFunctionDescriptor.getType().getReturnType();
Type[] argumentTypes = mainFunctionDescriptor.getType().getArgumentTypes();
if (argumentTypes.length > 0 && argumentTypes[0] instanceof PrimitiveType) {
if (((PrimitiveType) argumentTypes[0]).getPrimitiveKind() == PrimitiveKind.I64) {
return 1;
}
}
if (returnType instanceof VoidType) {
return 2;
} else if (returnType instanceof PrimitiveType) {
switch(((PrimitiveType) returnType).getPrimitiveKind()) {
case I8:
return 3;
case I16:
return 4;
case I32:
return 0;
case I64:
return 5;
}
}
throw new AssertionError("Unexpected main method signature");
}
use of com.oracle.truffle.llvm.runtime.types.PrimitiveType 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.llvm.runtime.types.PrimitiveType 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.llvm.runtime.types.PrimitiveType 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;
}
use of com.oracle.truffle.llvm.runtime.types.PrimitiveType in project sulong by graalvm.
the class BasicNodeFactory method createVectorLiteralNode.
@Override
public LLVMExpressionNode createVectorLiteralNode(LLVMParserRuntime runtime, List<LLVMExpressionNode> listValues, Type type) {
LLVMExpressionNode[] vals = listValues.toArray(new LLVMExpressionNode[listValues.size()]);
Type llvmType = ((VectorType) type).getElementType();
if (llvmType instanceof PrimitiveType) {
switch(((PrimitiveType) llvmType).getPrimitiveKind()) {
case I1:
return LLVMVectorI1LiteralNodeGen.create(vals);
case I8:
return LLVMVectorI8LiteralNodeGen.create(vals);
case I16:
return LLVMVectorI16LiteralNodeGen.create(vals);
case I32:
return LLVMVectorI32LiteralNodeGen.create(vals);
case I64:
return LLVMVectorI64LiteralNodeGen.create(vals);
case FLOAT:
return LLVMVectorFloatLiteralNodeGen.create(vals);
case DOUBLE:
return LLVMVectorDoubleLiteralNodeGen.create(vals);
default:
throw new AssertionError();
}
} else if (llvmType instanceof PointerType) {
if (((PointerType) llvmType).getPointeeType() instanceof FunctionType) {
return LLVMVectorFunctionLiteralNodeGen.create(vals);
} else {
return LLVMVectorAddressLiteralNodeGen.create(vals);
}
} else {
throw new AssertionError(llvmType + " not yet supported");
}
}
Aggregations