use of com.oracle.truffle.llvm.nodes.asm.support.LLVMAMD64GetTlsNode in project sulong by graalvm.
the class AsmFactory method getOperandAddress.
private LLVMExpressionNode getOperandAddress(Type type, AsmOperand operand) {
if (operand instanceof AsmRegisterOperand) {
AsmRegisterOperand op = (AsmRegisterOperand) operand;
FrameSlot frame = getRegisterSlot(op.getBaseRegister());
if (type instanceof PointerType) {
return LLVMAddressReadNodeGen.create(frame);
} else {
throw new AsmParseException("not a pointer");
}
} else if (operand instanceof AsmArgumentOperand) {
AsmArgumentOperand op = (AsmArgumentOperand) operand;
Argument info = argInfo.get(op.getIndex());
FrameSlot frame = getArgumentSlot(op.getIndex(), type);
if (info.isMemory()) {
return LLVMAddressReadNodeGen.create(frame);
} else {
throw new AsmParseException("not a pointer");
}
} else if (operand instanceof AsmMemoryOperand) {
AsmMemoryOperand op = (AsmMemoryOperand) operand;
int displacement = op.getDisplacement();
AsmOperand base = op.getBase();
AsmOperand offset = op.getOffset();
int shift = op.getShift();
LLVMExpressionNode baseAddress;
assert op.getSegment() == null || op.getSegment().equals("%fs");
LLVMExpressionNode segment = null;
if (op.getSegment() != null) {
segment = new LLVMAMD64GetTlsNode();
}
if (base != null) {
baseAddress = getOperandLoad(new PointerType(type), base);
} else if (offset != null) {
LLVMExpressionNode offsetNode = getOperandLoad(null, offset);
if (op.getSegment() != null) {
return LLVMAMD64AddressOffsetComputationNodeGen.create(displacement, shift, segment, offsetNode);
} else {
return LLVMAMD64AddressNoBaseOffsetComputationNodeGen.create(displacement, shift, offsetNode);
}
} else if (op.getSegment() != null) {
return LLVMAMD64AddressDisplacementComputationNodeGen.create(displacement, segment);
} else {
if (type instanceof PrimitiveType) {
switch(((PrimitiveType) type).getPrimitiveKind()) {
case I16:
return LLVMAMD64I16NodeGen.create((short) displacement);
case I32:
return LLVMAMD64I32NodeGen.create(displacement);
case I64:
return LLVMAMD64I64NodeGen.create(displacement);
default:
throw new AsmParseException("unknown type: " + type);
}
} else if (type instanceof PointerType) {
return LLVMAMD64I64NodeGen.create(displacement);
} else {
throw new AsmParseException("invalid type: " + type);
}
}
LLVMExpressionNode address;
if (offset == null) {
address = LLVMAMD64AddressDisplacementComputationNodeGen.create(displacement, baseAddress);
} else {
LLVMExpressionNode offsetNode = getOperandLoad(null, offset);
address = LLVMAMD64AddressOffsetComputationNodeGen.create(displacement, shift, baseAddress, offsetNode);
}
if (op.getSegment() != null) {
address = LLVMAMD64AddressSegmentComputationNodeGen.create(address, segment);
}
return address;
} else {
throw new AsmParseException("unsupported operand: " + operand);
}
}
Aggregations