Search in sources :

Example 1 with FunctionDeclaration

use of com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration 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 2 with FunctionDeclaration

use of com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration 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)

Example 3 with FunctionDeclaration

use of com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration in project sulong by graalvm.

the class LLVMLivenessAnalysis method resolve.

private static int resolve(FrameDescriptor frame, SymbolImpl symbol) {
    if (symbol instanceof ValueSymbol && !(symbol instanceof GlobalValueSymbol || symbol instanceof FunctionDefinition || symbol instanceof FunctionDeclaration)) {
        String name = ((ValueSymbol) symbol).getName();
        assert name != null;
        FrameSlot frameSlot = frame.findFrameSlot(name);
        assert frameSlot != null : "No Frameslot for ValueSymbol: " + symbol;
        return frameSlot.getIndex();
    }
    return -1;
}
Also used : FunctionDeclaration(com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol) ValueSymbol(com.oracle.truffle.llvm.parser.model.ValueSymbol) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol)

Aggregations

FunctionDeclaration (com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration)3 FunctionDefinition (com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)3 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 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