use of com.oracle.truffle.llvm.parser.model.functions.FunctionSymbol in project graal by oracle.
the class ParserDriver method resolveRenamedSymbols.
protected void resolveRenamedSymbols(LLVMParserResult parserResult) {
for (GlobalVariable external : parserResult.getExternalGlobals()) {
String name = external.getName();
if (name.startsWith(SULONG_RENAME_MARKER)) {
registerRenamed(name, external, (scope, originalName, lib) -> createNewGlobal(scope, originalName, parserResult, external, lib, name));
}
}
ListIterator<FunctionSymbol> it = parserResult.getExternalFunctions().listIterator();
while (it.hasNext()) {
FunctionSymbol external = it.next();
String name = external.getName();
if (name.startsWith(SULONG_RENAME_MARKER)) {
registerRenamed(name, external, (scope, originalName, lib) -> createNewFunction(scope, originalName, parserResult, external, lib, name, it));
} else if (CXXDemangler.isRenamedNamespaceSymbol(name)) {
LLVMScope scope;
ArrayList<String> namespaces = CXXDemangler.decodeNamespace(name);
String lib = CXXDemangler.getAndRemoveLibraryName(namespaces);
scope = language.getInternalFileScopes(getSimpleLibraryName(lib));
if (scope == null) {
try {
// If the library that contains the function has not been parsed,
// then the library will be lazily parse now.
String libName = lib + "." + language.getCapability(PlatformCapability.class).getLibrarySuffix();
TruffleFile file = createTruffleFile(libName, null, InternalLibraryLocator.INSTANCE, "<default bitcode library>");
context.getEnv().parseInternal(Source.newBuilder("llvm", file).internal(context.isInternalLibraryFile(file)).build());
scope = language.getInternalFileScopes(getSimpleLibraryName(lib));
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
if (scope == null) {
// initialised.
throw new LLVMLinkerException(String.format("The symbol %s could not be imported because library %s was not found during symbol renaming", external.getName(), lib));
}
String originalName = CXXDemangler.encodeNamespace(namespaces);
createNewFunction(scope, originalName, parserResult, external, lib, name, it);
}
}
}
use of com.oracle.truffle.llvm.parser.model.functions.FunctionSymbol in project graal by oracle.
the class LLVMParser method defineAlias.
private void defineAlias(String aliasName, boolean isAliasExported, SymbolImpl value, DataLayout targetDataLayout) {
if (value instanceof FunctionSymbol) {
FunctionSymbol function = (FunctionSymbol) value;
defineAlias(function.getName(), aliasName, isAliasExported);
} else if (value instanceof GlobalVariable) {
GlobalVariable global = (GlobalVariable) value;
defineAlias(global.getName(), aliasName, isAliasExported);
} else if (value instanceof GlobalAlias) {
GlobalAlias target = (GlobalAlias) value;
defineAlias(target, targetDataLayout);
defineAlias(target.getName(), aliasName, isAliasExported);
} else if (value instanceof CastConstant) {
// TODO (chaeubl): this is not perfectly accurate as we are loosing the type cast
CastConstant cast = (CastConstant) value;
defineAlias(aliasName, isAliasExported, cast.getValue(), targetDataLayout);
} else if (value instanceof GetElementPointerConstant) {
GetElementPointerConstant elementPointerConstant = (GetElementPointerConstant) value;
defineExpressionSymbol(aliasName, isAliasExported, elementPointerConstant, targetDataLayout);
} else {
throw new LLVMLinkerException("Unknown alias type: " + value.getClass());
}
}
Aggregations