Search in sources :

Example 1 with FunctionDefinition

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);
    }
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)

Example 2 with FunctionDefinition

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);
    }
}
Also used : FunctionDeclaration(com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) Type(com.oracle.truffle.llvm.runtime.types.Type) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) Linkage(com.oracle.truffle.llvm.parser.model.enums.Linkage) AttributesCodeEntry(com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)

Example 3 with FunctionDefinition

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);
    }
}
Also used : LazyFunctionParser(com.oracle.truffle.llvm.parser.model.functions.LazyFunctionParser) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)

Example 4 with FunctionDefinition

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);
        }
    }
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition) GlobalAlias(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias) Map(java.util.Map)

Example 5 with FunctionDefinition

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);
    }
}
Also used : FunctionDeclaration(com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration) Type(com.oracle.truffle.llvm.runtime.types.Type) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) SymbolTable(com.oracle.truffle.llvm.parser.model.SymbolTable) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)

Aggregations

FunctionDefinition (com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)6 FunctionDeclaration (com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration)3 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)2 Type (com.oracle.truffle.llvm.runtime.types.Type)2 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)1 SymbolTable (com.oracle.truffle.llvm.parser.model.SymbolTable)1 ValueSymbol (com.oracle.truffle.llvm.parser.model.ValueSymbol)1 AttributesCodeEntry (com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry)1 Linkage (com.oracle.truffle.llvm.parser.model.enums.Linkage)1 LazyFunctionParser (com.oracle.truffle.llvm.parser.model.functions.LazyFunctionParser)1 GlobalAlias (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias)1 GlobalValueSymbol (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol)1 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)1 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)1 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)1 Map (java.util.Map)1