use of com.oracle.truffle.llvm.runtime.LLVMFunction in project graal by oracle.
the class LoadModulesNode method findMainFunction.
/**
* Retrieves the function for the main method.
*/
private LLVMFunction findMainFunction() {
// check if the freshly parsed code exports a main method
LLVMScope fileScope = parserRuntime.getFileScope();
LLVMSymbol mainSymbol = fileScope.get(MAIN_METHOD_NAME);
if (mainSymbol != null && mainSymbol.isFunction()) {
/*
* The `isLLVMIRFunction` check makes sure the `main` function is really defined in
* bitcode. This prevents us from finding a native `main` function (e.g. the `main` of
* the VM we're running in).
*/
LLVMFunction mainFunction = mainSymbol.asFunction();
if (mainFunction.getFunction() instanceof LLVMFunctionCode.LLVMIRFunction || mainFunction.getFunction() instanceof LLVMFunctionCode.LazyLLVMIRFunction) {
return mainFunction;
}
}
return null;
}
use of com.oracle.truffle.llvm.runtime.LLVMFunction in project graal by oracle.
the class InitializeExternalNode method execute.
/*
* (PLi): Need to be careful of native functions/globals that are not in the nfi context (i.e.
* __xstat). Ideally they will be added to the symbol table as unresolved/undefined
* functions/globals.
*/
public void execute(LLVMContext context, LLVMScopeChain localScope, LLVMDLOpen.RTLDFlags rtldFlags) {
LLVMScopeChain globalScope = context.getGlobalScopeChain();
LLVMIntrinsicProvider intrinsicProvider = getLanguage().getCapability(LLVMIntrinsicProvider.class);
NativeContextExtension nativeContextExtension = getNativeContextExtension(context);
for (int i = 0; i < globals.length; i++) {
LLVMGlobal global = globals[i];
LLVMPointer pointer = allocExternalSymbol.execute(localScope, globalScope, intrinsicProvider, nativeContextExtension, context, rtldFlags, global);
if (pointer == null) {
continue;
}
context.initializeSymbol(globals[i], pointer);
}
for (int i = 0; i < functions.length; i++) {
LLVMFunction function = functions[i];
LLVMPointer pointer = allocExternalSymbol.execute(localScope, globalScope, intrinsicProvider, nativeContextExtension, context, rtldFlags, function);
if (pointer == null) {
continue;
}
context.initializeSymbol(functions[i], pointer);
}
}
use of com.oracle.truffle.llvm.runtime.LLVMFunction in project graal by oracle.
the class InitializeOverwriteNode method execute.
public void execute(LLVMContext context, LLVMScopeChain localScope, RTLDFlags rtldFlags) {
LLVMScopeChain globalScope = context.getGlobalScopeChain();
for (LLVMFunction function : functions) {
LLVMPointer pointer = allocExternalSymbol.execute(localScope, globalScope, null, null, context, rtldFlags, function);
// skip allocating fallbacks
if (pointer == null) {
continue;
}
context.initializeSymbol(function, pointer);
}
for (LLVMGlobal global : globals) {
LLVMPointer pointer = allocExternalSymbol.execute(localScope, globalScope, null, null, context, rtldFlags, global);
// skip allocating fallbacks
if (pointer == null) {
continue;
}
context.initializeSymbol(global, pointer);
}
}
use of com.oracle.truffle.llvm.runtime.LLVMFunction in project graal by oracle.
the class LLVMParser method defineFunction.
private void defineFunction(FunctionSymbol functionSymbol, ModelModule model, DataLayout dataLayout) {
assert !functionSymbol.isExternal();
// handle the file scope
FunctionDefinition functionDefinition = (FunctionDefinition) functionSymbol;
LazyToTruffleConverterImpl lazyConverter = new LazyToTruffleConverterImpl(runtime, functionDefinition, source, model.getFunctionParser(functionDefinition), model.getFunctionProcessor(), dataLayout);
Function function = new LazyLLVMIRFunction(lazyConverter);
LLVMFunction llvmFunction = LLVMFunction.create(functionSymbol.getName(), function, functionSymbol.getType(), runtime.getBitcodeID(), functionSymbol.getIndex(), functionDefinition.isExported(), runtime.getFile().getPath(), functionDefinition.isExternalWeak());
lazyConverter.setRootFunction(llvmFunction);
runtime.getFileScope().register(llvmFunction);
registerInPublicFileScope(llvmFunction);
final boolean cxxInterop = LLVMLanguage.getContext().getEnv().getOptions().get(SulongEngineOption.CXX_INTEROP);
if (cxxInterop) {
model.getFunctionParser(functionDefinition).parseLinkageName(runtime);
}
}
Aggregations