use of com.oracle.truffle.llvm.runtime.LLVMFunction in project graal by oracle.
the class LLVMTruffleDecorateFunction method registerRoot.
private static Object registerRoot(String path, FunctionType newFunctionType, DecoratedRoot decoratedRoot) {
LLVMIRFunction function = new LLVMIRFunction(decoratedRoot.getCallTarget(), null);
LLVMFunction functionDetail = LLVMFunction.create("<wrapper>", function, newFunctionType, IDGenerater.INVALID_ID, LLVMSymbol.INVALID_INDEX, false, path, false);
LLVMFunctionDescriptor wrappedFunction = new LLVMFunctionDescriptor(functionDetail, new LLVMFunctionCode(functionDetail));
return LLVMManagedPointer.create(wrappedFunction);
}
use of com.oracle.truffle.llvm.runtime.LLVMFunction in project graal by oracle.
the class LLVMInteropNonvirtualCallNode method doResolve.
/**
* @param receiver
* @param method
*/
@Specialization
@GenerateAOT.Exclude
Object doResolve(LLVMPointer receiver, LLVMInteropType.Clazz type, String methodName, Method method, Object[] arguments, @Cached LLVMDynAccessSymbolNode dynAccessSymbolNode, @CachedLibrary(limit = "5") InteropLibrary interop, @Cached BranchProfile notFound) throws UnsupportedTypeException, ArityException, UnsupportedMessageException {
Method newMethod = type.findMethodByArgumentsWithSelf(methodName, arguments);
LLVMFunction newLLVMFunction = getLLVMFunction(newMethod, type, notFound);
Object newReceiver = dynAccessSymbolNode.execute(newLLVMFunction);
return interop.execute(newReceiver, arguments);
}
use of com.oracle.truffle.llvm.runtime.LLVMFunction in project graal by oracle.
the class ParserDriver method createNewFunction.
private static void createNewFunction(LLVMScope scope, String originalName, LLVMParserResult parserResult, FunctionSymbol external, String lib, String name, ListIterator<FunctionSymbol> it) {
LLVMFunction originalSymbol = scope.getFunction(originalName);
if (originalSymbol == null) {
throw new LLVMLinkerException(String.format("The symbol %s could not be imported because the symbol %s was not found in library %s", external.getName(), originalName, lib));
}
LLVMFunction newFunction = LLVMFunction.create(name, originalSymbol.getFunction(), originalSymbol.getType(), parserResult.getRuntime().getBitcodeID(), external.getIndex(), external.isExported(), parserResult.getRuntime().getFile().getPath(), external.isExternalWeak());
parserResult.getRuntime().getFileScope().register(newFunction);
if (external.isExported()) {
parserResult.getRuntime().getPublicFileScope().register(newFunction);
}
it.remove();
parserResult.getDefinedFunctions().add(external);
}
use of com.oracle.truffle.llvm.runtime.LLVMFunction in project graal by oracle.
the class LoadModulesNode method execute.
@Override
public Object execute(VirtualFrame frame) {
LLVMContext context = getContext();
synchronized (context) {
if (!hasInitialised) {
CompilerDirectives.transferToInterpreterAndInvalidate();
LLVMFunction mainFunction = findMainFunction();
if (mainFunction != null) {
main = new CachedMainFunction(mainFunction);
} else {
main = null;
}
initContext = this.insert(language.createInitializeContextNode());
hasInitialised = true;
}
LLVMScopeChain firstScopeChain = loadModule(frame, context);
context.addSourceForCache(bitcodeID, source);
context.addCalltargetForCache(libraryName, this.getCallTarget());
// Only the root library (not a dependency) will have a non-null scope.
if (firstScopeChain != null) {
SulongLibrary library = new SulongLibrary(this.libraryName, firstScopeChain, main, context, parserRuntime.getLocator(), parserRuntime.getBitcodeID());
if (main != null) {
context.setMainLibrary(library);
}
return library;
}
}
return null;
}
use of com.oracle.truffle.llvm.runtime.LLVMFunction in project graal by oracle.
the class BasicNodeFactory method createInlineAssemblerExpression.
@Override
public LLVMExpressionNode createInlineAssemblerExpression(String asmExpression, String asmFlags, LLVMExpressionNode[] args, Type.TypeArrayBuilder argTypes, Type retType) {
Type[] retTypes = null;
long[] retOffsets = null;
if (retType instanceof StructureType) {
// multiple out values
StructureType struct = (StructureType) retType;
retOffsets = new long[struct.getNumberOfElementsInt()];
retTypes = new Type[struct.getNumberOfElementsInt()];
long currentOffset = 0;
try {
for (int i = 0; i < struct.getNumberOfElements(); i++) {
Type elemType = struct.getElementType(i);
if (!struct.isPacked()) {
currentOffset = Type.addUnsignedExact(currentOffset, getBytePadding(currentOffset, elemType));
}
retOffsets[i] = currentOffset;
retTypes[i] = elemType;
currentOffset = Type.addUnsignedExact(currentOffset, getByteSize(elemType));
}
assert currentOffset <= getByteSize(retType) : "currentOffset " + currentOffset + " vs. byteSize " + getByteSize(retType);
} catch (TypeOverflowException e) {
return Type.handleOverflowExpression(e);
}
}
LLVMInlineAssemblyRootNode assemblyRoot;
try {
assemblyRoot = InlineAssemblyParser.parseInlineAssembly(asmExpression, new AsmFactory(language, argTypes, asmFlags, retType, retTypes, retOffsets, this));
} catch (AsmParseException e) {
assemblyRoot = getLazyUnsupportedInlineRootNode(asmExpression, e);
}
LLVMIRFunction function = new LLVMIRFunction(assemblyRoot.getCallTarget(), null);
LLVMFunction functionDetail = LLVMFunction.create("<asm>", function, new FunctionType(MetaType.UNKNOWN, 0, false), IDGenerater.INVALID_ID, LLVMSymbol.INVALID_INDEX, false, assemblyRoot.getName(), false);
// The function descriptor for the inline assembly does not require a language.
LLVMFunctionDescriptor asm = new LLVMFunctionDescriptor(functionDetail, new LLVMFunctionCode(functionDetail));
LLVMManagedPointerLiteralNode asmFunction = LLVMManagedPointerLiteralNodeGen.create(LLVMManagedPointer.create(asm));
return LLVMCallNode.create(new FunctionType(MetaType.UNKNOWN, argTypes, false), asmFunction, args, false);
}
Aggregations