use of com.oracle.truffle.llvm.nodes.vars.LLVMWriteNode.LLVMWriteAddressNode in project sulong by graalvm.
the class AsmFactory method getArguments.
private void getArguments() {
LLVMStoreNode[] writeNodes = null;
LLVMExpressionNode[] valueNodes = null;
if (retType instanceof StructureType) {
writeNodes = new LLVMStoreNode[retTypes.length];
valueNodes = new LLVMExpressionNode[retTypes.length];
}
Set<String> todoRegisters = new HashSet<>(registers);
for (Argument arg : argInfo) {
// output register
if (arg.isOutput()) {
FrameSlot slot = null;
if (arg.isRegister()) {
slot = getRegisterSlot(arg.getRegister());
LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(slot);
if (retType instanceof StructureType) {
assert retTypes[arg.getOutIndex()] == arg.getType();
if (arg.getType() instanceof PointerType) {
valueNodes[arg.getOutIndex()] = LLVMToAddressNodeGen.create(register);
writeNodes[arg.getOutIndex()] = LLVMAddressStoreNodeGen.create(null, null);
} else {
PrimitiveKind primitiveKind = getPrimitiveKind(arg);
switch(primitiveKind) {
case I8:
valueNodes[arg.getOutIndex()] = LLVMToI8NoZeroExtNodeGen.create(register);
writeNodes[arg.getOutIndex()] = LLVMI8StoreNodeGen.create(null, null);
break;
case I16:
valueNodes[arg.getOutIndex()] = LLVMToI16NoZeroExtNodeGen.create(register);
writeNodes[arg.getOutIndex()] = LLVMI16StoreNodeGen.create(null, null);
break;
case I32:
valueNodes[arg.getOutIndex()] = LLVMToI32NoZeroExtNodeGen.create(register);
writeNodes[arg.getOutIndex()] = LLVMI32StoreNodeGen.create(null, null);
break;
case I64:
valueNodes[arg.getOutIndex()] = register;
writeNodes[arg.getOutIndex()] = LLVMI64StoreNodeGen.create(null, null);
break;
default:
throw new AsmParseException("invalid operand size: " + arg.getType());
}
}
} else {
result = castResult(register);
}
} else {
assert arg.isMemory();
slot = getArgumentSlot(arg.getIndex(), argTypes[arg.getOutIndex()]);
LLVMExpressionNode argnode = LLVMArgNodeGen.create(arg.getOutIndex());
arguments.add(LLVMWriteAddressNodeGen.create(argnode, slot, sourceLocation));
}
}
// input register
if (arg.isInput()) {
FrameSlot slot = null;
if (arg.isRegister()) {
String reg = arg.isAnonymous() ? arg.getRegister() : AsmRegisterOperand.getBaseRegister(arg.getRegister());
slot = getRegisterSlot(reg);
todoRegisters.remove(reg);
LLVMExpressionNode argnode = LLVMArgNodeGen.create(arg.getInIndex());
if (argTypes[arg.getInIndex()] instanceof PointerType) {
arguments.add(LLVMWriteAddressNodeGen.create(argnode, slot, null));
} else {
LLVMExpressionNode node = LLVMToI64NoZeroExtNodeGen.create(argnode);
arguments.add(LLVMWriteI64NodeGen.create(node, slot, null));
}
}
slot = getArgumentSlot(arg.getIndex(), argTypes[arg.getInIndex()]);
LLVMExpressionNode argnode = LLVMArgNodeGen.create(arg.getInIndex());
if (arg.getType() instanceof PrimitiveType) {
LLVMExpressionNode node = LLVMToI64NoZeroExtNodeGen.create(argnode);
arguments.add(LLVMWriteI64NodeGen.create(node, slot, null));
} else if (arg.getType() instanceof PointerType) {
arguments.add(LLVMWriteAddressNodeGen.create(argnode, slot, null));
} else {
throw new AsmParseException("invalid operand size: " + arg.getType());
}
}
}
if (retType instanceof StructureType) {
LLVMExpressionNode addrArg = LLVMArgNodeGen.create(1);
FrameSlot slot = frameDescriptor.addFrameSlot("returnValue", null, FrameSlotKind.Object);
LLVMWriteAddressNode writeAddr = LLVMWriteAddressNodeGen.create(addrArg, slot, null);
statements.add(writeAddr);
LLVMExpressionNode addr = LLVMAddressReadNodeGen.create(slot);
this.result = StructLiteralNodeGen.create(retOffsets, writeNodes, valueNodes, addr);
}
// rsp is initialized to stack pointer; ignore it here
todoRegisters.remove("rsp");
// initialize registers
for (String register : todoRegisters) {
if (register.startsWith("$")) {
continue;
}
LLVMExpressionNode node = LLVMAMD64I64NodeGen.create(0);
FrameSlot slot = getRegisterSlot(register);
arguments.add(LLVMWriteI64NodeGen.create(node, slot, null));
}
// initialize flags
LLVMExpressionNode zero = LLVMAMD64I1NodeGen.create(false);
arguments.add(LLVMWriteI1NodeGen.create(zero, getFlagSlot(LLVMAMD64Flags.CF), sourceLocation));
arguments.add(LLVMWriteI1NodeGen.create(zero, getFlagSlot(LLVMAMD64Flags.PF), sourceLocation));
arguments.add(LLVMWriteI1NodeGen.create(zero, getFlagSlot(LLVMAMD64Flags.AF), sourceLocation));
arguments.add(LLVMWriteI1NodeGen.create(zero, getFlagSlot(LLVMAMD64Flags.ZF), sourceLocation));
arguments.add(LLVMWriteI1NodeGen.create(zero, getFlagSlot(LLVMAMD64Flags.SF), sourceLocation));
arguments.add(LLVMWriteI1NodeGen.create(zero, getFlagSlot(LLVMAMD64Flags.OF), sourceLocation));
// copy stack pointer
LLVMExpressionNode stackPointer = LLVMArgNodeGen.create(0);
FrameSlot stackSlot = frameDescriptor.addFrameSlot(LLVMStack.FRAME_ID);
stackSlot.setKind(FrameSlotKind.Object);
arguments.add(LLVMWriteAddressNodeGen.create(stackPointer, frameDescriptor.findFrameSlot(LLVMStack.FRAME_ID), sourceLocation));
arguments.add(LLVMWriteAddressNodeGen.create(stackPointer, getRegisterSlot("rsp"), null));
assert retType instanceof VoidType || retType != null;
}
Aggregations