use of com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition in project sulong by graalvm.
the class MDUpgrade method visit.
@Override
public void visit(MDSubprogram md) {
final SymbolImpl valueSymbol = MDSymbolExtractor.getSymbol(md.getFunction());
if (valueSymbol instanceof FunctionDefinition) {
final FunctionDefinition function = (FunctionDefinition) valueSymbol;
attachSymbol(function, md);
}
if (currentCU != null && md.getCompileUnit() == MDVoidNode.INSTANCE) {
md.setCompileUnit(currentCU);
}
}
use of com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition in project sulong by graalvm.
the class Module method createFunction.
private void createFunction(long[] args) {
final int recordOffset = useStrTab() ? STRTAB_RECORD_OFFSET : 0;
Type type = types.get(args[FUNCTION_TYPE + recordOffset]);
if (type instanceof PointerType) {
type = ((PointerType) type).getPointeeType();
}
final FunctionType functionType = (FunctionType) type;
final boolean isPrototype = args[FUNCTION_ISPROTOTYPE + recordOffset] != 0;
final Linkage linkage = Linkage.decode(args[FUNCTION_LINKAGE + recordOffset]);
final AttributesCodeEntry paramAttr = paramAttributes.getCodeEntry(args[FUNCTION_PARAMATTR + recordOffset]);
if (isPrototype) {
final FunctionDeclaration function = new FunctionDeclaration(functionType, linkage, paramAttr);
module.addFunctionDeclaration(function);
scope.addSymbol(function, function.getType());
if (useStrTab()) {
readNameFromStrTab(args, function);
}
} else {
final FunctionDefinition function = new FunctionDefinition(functionType, linkage, paramAttr);
module.addFunctionDefinition(function);
scope.addSymbol(function, function.getType());
if (useStrTab()) {
readNameFromStrTab(args, function);
}
functionQueue.addLast(function);
}
}
use of com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition in project sulong by graalvm.
the class Module method skip.
@Override
public void skip(Block block, LLVMScanner.LazyScanner lazyScanner) {
if (block == Block.FUNCTION) {
if (functionQueue.isEmpty()) {
throw new RuntimeException("Missing Function Prototype in Bitcode File!");
}
final FunctionDefinition definition = functionQueue.removeFirst();
final Function parser = new Function(scope, types, definition, mode, paramAttributes);
module.addFunctionParser(definition, new LazyFunctionParser(lazyScanner, parser));
} else {
ParserListener.super.skip(block, lazyScanner);
}
}
use of com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition in project sulong by graalvm.
the class LLVMParserRuntime method registerFunctions.
private void registerFunctions(ModelModule model) {
for (FunctionDefinition function : model.getDefinedFunctions()) {
registerFunction(function, model);
}
for (Map.Entry<GlobalAlias, SymbolImpl> entry : aliases.entrySet()) {
GlobalAlias alias = entry.getKey();
SymbolImpl value = entry.getValue();
if (value instanceof FunctionDefinition) {
registerFunctionAlias(alias, (FunctionDefinition) value);
}
}
}
use of com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition in project sulong by graalvm.
the class FunctionStart method parseArguments.
static void parseArguments(IRScope scope, SymbolImpl callTarget, Instruction inst, SymbolImpl[] target, int[] src) {
if (src.length == 0) {
return;
}
final Type[] paramTypes;
if (callTarget instanceof FunctionDefinition) {
paramTypes = ((FunctionDefinition) (callTarget)).getType().getArgumentTypes();
} else if (callTarget instanceof FunctionDeclaration) {
paramTypes = ((FunctionDeclaration) (callTarget)).getType().getArgumentTypes();
} else {
paramTypes = Type.EMPTY_ARRAY;
}
final SymbolTable symbols = scope.getSymbols();
for (int i = Math.min(paramTypes.length, src.length) - 1; i >= 0; i--) {
if (paramTypes[i] == MetaType.METADATA) {
target[i] = MetadataSymbol.create(scope.getMetadata(), src[i]);
} else {
target[i] = symbols.getForwardReferenced(src[i], inst);
}
}
// parse varargs
for (int i = paramTypes.length; i < src.length; i++) {
target[i] = symbols.getForwardReferenced(src[i], inst);
}
}
Aggregations