use of com.oracle.truffle.llvm.nodes.memory.LLVMAllocInstruction.LLVMAllocaConstInstruction in project sulong by graalvm.
the class BasicNodeFactory method createAlloca.
protected static LLVMExpressionNode createAlloca(LLVMParserRuntime runtime, Type type, int byteSize, int alignment) {
if (type instanceof StructureType) {
StructureType struct = (StructureType) type;
final int[] offsets = new int[struct.getNumberOfElements()];
final Type[] types = new Type[struct.getNumberOfElements()];
int currentOffset = 0;
for (int i = 0; i < struct.getNumberOfElements(); i++) {
final Type elemType = struct.getElementType(i);
if (!struct.isPacked()) {
currentOffset += runtime.getContext().getBytePadding(currentOffset, elemType);
}
offsets[i] = currentOffset;
types[i] = elemType;
currentOffset += runtime.getContext().getByteSize(elemType);
}
assert currentOffset <= byteSize : "currentOffset " + currentOffset + " vs. byteSize " + byteSize;
LLVMAllocaConstInstruction alloc = LLVMAllocaConstInstructionNodeGen.create(byteSize, alignment, type);
alloc.setTypes(types);
alloc.setOffsets(offsets);
return alloc;
}
return LLVMAllocaConstInstructionNodeGen.create(byteSize, alignment, type);
}
use of com.oracle.truffle.llvm.nodes.memory.LLVMAllocInstruction.LLVMAllocaConstInstruction in project sulong by graalvm.
the class BasicNodeFactory method createInlineAssemblerExpression.
@Override
public LLVMExpressionNode createInlineAssemblerExpression(LLVMParserRuntime runtime, String asmExpression, String asmFlags, LLVMExpressionNode[] args, Type[] argTypes, Type retType, LLVMSourceLocation sourceSection) {
Type[] retTypes = null;
int[] retOffsets = null;
if (retType instanceof StructureType) {
// multiple out values
assert args[1] instanceof LLVMAllocaConstInstruction;
LLVMAllocaConstInstruction alloca = (LLVMAllocaConstInstruction) args[1];
retTypes = alloca.getTypes();
retOffsets = alloca.getOffsets();
}
Parser asmParser = new Parser(runtime.getLanguage(), sourceSection, asmExpression, asmFlags, argTypes, retType, retTypes, retOffsets);
LLVMInlineAssemblyRootNode assemblyRoot = asmParser.Parse();
LLVMFunctionDescriptor asm = LLVMFunctionDescriptor.createDescriptor(runtime.getContext(), runtime.getLibrary(), "<asm>", new FunctionType(MetaType.UNKNOWN, new Type[0], false), -1);
asm.declareInSulong(Truffle.getRuntime().createCallTarget(assemblyRoot), false);
LLVMFunctionLiteralNode asmFunction = LLVMFunctionLiteralNodeGen.create(asm);
return new LLVMCallNode(new FunctionType(MetaType.UNKNOWN, argTypes, false), asmFunction, args, sourceSection);
}
Aggregations