use of com.oracle.truffle.llvm.runtime.LLVMFunctionCode 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.LLVMFunctionCode 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);
}
use of com.oracle.truffle.llvm.runtime.LLVMFunctionCode in project graal by oracle.
the class AllocExternalSymbolNode method execute.
public LLVMPointer execute(LLVMScopeChain localScope, LLVMScopeChain globalScope, LLVMIntrinsicProvider intrinsicProvider, NativeContextExtension nativeContextExtension, LLVMContext context, LLVMDLOpen.RTLDFlags rtldFlags, LLVMSymbol symbol) {
LLVMPointer pointerFromLocal = lookupFromScope(localScope, symbol, context);
// The default case for active default flag is to search the local scope first.
if (pointerFromLocal != null && isDefaultFlagActive(rtldFlags)) {
return pointerFromLocal;
}
LLVMPointer pointerFromGlobal = lookupFromScope(globalScope, symbol, context);
// the default flag, global scope takes priority if the default flag is not active.)
if (pointerFromGlobal != null) {
return pointerFromGlobal;
}
// flag is not active).
if (pointerFromLocal != null) {
return pointerFromLocal;
}
// Allocating a native global symbol to the symbol table as provided by the nfi context.
if (symbol.isGlobalVariable()) {
if (symbol.isExternalWeak()) {
return LLVMNativePointer.createNull();
} else if (nativeContextExtension != null) {
NativeContextExtension.NativePointerIntoLibrary pointer = getNativePointer(nativeContextExtension, symbol);
if (pointer != null) {
return LLVMNativePointer.create(pointer.getAddress());
}
return null;
}
}
// native function and intrinsic function.
if (symbol.isFunction()) {
if (symbol.isExternalWeak()) {
return LLVMNativePointer.createNull();
} else if (intrinsicProvider != null && intrinsicProvider.isIntrinsified(symbol.getName())) {
LLVMFunctionCode functionCode = new LLVMFunctionCode(symbol.asFunction());
LLVMFunctionDescriptor functionDescriptor = context.createFunctionDescriptor(symbol.asFunction(), functionCode);
functionDescriptor.getFunctionCode().define(intrinsicProvider, nodeFactory);
return LLVMManagedPointer.create(functionDescriptor);
} else if (intrinsicProvider != null && !intrinsicProvider.isIntrinsified(symbol.getName()) && nativeContextExtension != null) {
/*
* Currently native functions/globals that are not in the nfi context are not
* written into the symbol table. For function, another lookup will happen when
* something tries to call the function. (see {@link
* LLVMDispatchNode#doCachedNative}) The function will be taken from the filescope
* directly. Ideally the filescope and symbol table is in sync, and any lazy look up
* will resolve from the function code in the symbol table.
*/
NativeLookupResult nativeFunction = getNativeFunction(nativeContextExtension, symbol);
if (nativeFunction != null) {
LLVMFunctionDescriptor functionDescriptor = context.createFunctionDescriptor(symbol.asFunction(), new LLVMFunctionCode(symbol.asFunction()));
functionDescriptor.getFunctionCode().define(new LLVMFunctionCode.NativeFunction(nativeFunction.getObject()));
symbol.asFunction().setNFISymbol(nativeFunction.getObject());
return LLVMManagedPointer.create(functionDescriptor);
}
return null;
}
}
/*
* Fallback for when the same symbol is being overwritten. There exists code where the
* symbol is not there.
*/
return null;
}
Aggregations