use of com.oracle.truffle.llvm.runtime.LLVMSymbol in project graal by oracle.
the class InitializeSymbolsNode method allocFunctions.
private void allocFunctions(LLVMContext context) {
for (int i = 0; i < allocFuncs.length; i++) {
AllocSymbolNode allocSymbol = allocFuncs[i];
LLVMPointer pointer = allocSymbol.allocate(context);
context.initializeSymbol(functions[i], pointer);
List<LLVMSymbol> list = new ArrayList<>(1);
list.add(allocSymbol.symbol);
context.registerSymbolReverseMap(list, pointer);
}
}
use of com.oracle.truffle.llvm.runtime.LLVMSymbol 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.LLVMSymbol in project graal by oracle.
the class LLVMParser method defineAlias.
private void defineAlias(GlobalAlias alias, DataLayout targetDataLayout) {
LLVMSymbol alreadyRegisteredSymbol = runtime.getFileScope().get(alias.getName());
if (alreadyRegisteredSymbol != null) {
// this alias was already registered by a recursive call
assert alreadyRegisteredSymbol instanceof LLVMAlias;
return;
}
defineAlias(alias.getName(), alias.isExported(), alias.getValue(), targetDataLayout);
}
use of com.oracle.truffle.llvm.runtime.LLVMSymbol in project graal by oracle.
the class LLVMParser method defineExpressionSymbol.
private void defineExpressionSymbol(String aliasName, boolean isAliasExported, GetElementPointerConstant elementPointerConstant, DataLayout targetDataLayout) {
LLVMSymbol baseSymbol = runtime.getFileScope().get(elementPointerConstant.getBasePointer().toString());
Supplier<LLVMExpressionNode> createElemPtrNode = () -> elementPointerConstant.createNode(runtime, targetDataLayout, GetStackSpaceFactory.createAllocaFactory());
LLVMElemPtrSymbol expressionSymbol = new LLVMElemPtrSymbol(aliasName, runtime.getBitcodeID(), -1, isAliasExported, elementPointerConstant.getType(), baseSymbol, createElemPtrNode);
runtime.getFileScope().register(expressionSymbol);
}
use of com.oracle.truffle.llvm.runtime.LLVMSymbol in project graal by oracle.
the class LLVMTruffleWriteManagedToSymbol method write.
@TruffleBoundary
@Specialization
protected Object write(LLVMPointer address, Object value) {
/*
* The list of symbols should be all global symbols or all function symbols more over, the
* list of symbols should all be pointing to the same value or function code, and they
* should all have the same name.
*/
List<LLVMSymbol> symbols = getContext().removeSymbolReverseMap(address);
if (symbols == null) {
throw new LLVMPolyglotException(this, "First argument to truffle_assign_managed must be a pointer to a symbol.");
}
Object newValue = value;
boolean allGlobals = symbols.get(0).isGlobalVariable();
LLVMContext ctx = LLVMContext.get(this);
/*
* The interop type of the global symbol has to be attached to the new object that's
* replacing the global. This is done by creating a LLVMTypedForeignObject wrapping it
* around the new object with the global's interop type.
*/
if (allGlobals) {
newValue = attachType.execute(value, symbols.get(0).asGlobalVariable().getInteropType(ctx));
}
/*
* Every symbol in the symbol list should point to the same value even if they are stored in
* different locations in the symbol table.
*/
for (LLVMSymbol symbol : symbols) {
assert allGlobals ? symbol.isGlobalVariable() : symbol.isFunction();
ctx.setSymbol(symbol, LLVMPointer.cast(newValue));
}
ctx.registerSymbolReverseMap(symbols, LLVMPointer.cast(value));
return newValue;
}
Aggregations