use of com.oracle.truffle.llvm.runtime.types.FunctionType in project sulong by graalvm.
the class LLVMLangStart method getLookupDispatchNode.
protected LLVMLookupDispatchNode getLookupDispatchNode(LLVMAddress main) {
CompilerAsserts.neverPartOfCompilation();
FunctionType functionType = getContextReference().get().getFunctionDescriptor(main).getType();
return LLVMLookupDispatchNodeGen.create(functionType);
}
use of com.oracle.truffle.llvm.runtime.types.FunctionType in project sulong by graalvm.
the class NFIIntrinsicsProvider method registerTruffleIntrinsics.
protected void registerTruffleIntrinsics(NodeFactory nodeFactory) {
LLVMNativeIntrinsicFactory polyglotImport = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_import", LLVMPolyglotImportNodeGen.create(LLVMArgNodeGen.create(1)));
}
};
factories.put("@polyglot_import", polyglotImport);
factories.put("@truffle_import", polyglotImport);
factories.put("@truffle_import_cached", polyglotImport);
factories.put("@polyglot_export", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_export", LLVMPolyglotExportNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@polyglot_eval", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_eval", LLVMPolyglotEval.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
//
factories.put("@polyglot_is_value", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_is_value", LLVMPolyglotIsValueNodeGen.create(LLVMArgNodeGen.create(1)));
}
});
factories.put("@polyglot_is_number", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_is_number", LLVMPolyglotBoxedPredicateNodeGen.create(new IsNumber(), LLVMArgNodeGen.create(1)));
}
});
factories.put("@polyglot_is_boolean", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_is_boolean", LLVMPolyglotBoxedPredicateNodeGen.create(new IsBoolean(), LLVMArgNodeGen.create(1)));
}
});
factories.put("@polyglot_is_string", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_is_string", LLVMPolyglotBoxedPredicateNodeGen.create(new IsString(), LLVMArgNodeGen.create(1)));
}
});
factories.put("@polyglot_fits_in_i8", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_fits_in_i8", LLVMPolyglotBoxedPredicateNodeGen.create(FitsInI8NodeGen.create(), LLVMArgNodeGen.create(1)));
}
});
factories.put("@polyglot_fits_in_i16", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_fits_in_i16", LLVMPolyglotBoxedPredicateNodeGen.create(FitsInI16NodeGen.create(), LLVMArgNodeGen.create(1)));
}
});
factories.put("@polyglot_fits_in_i32", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_fits_in_i32", LLVMPolyglotBoxedPredicateNodeGen.create(FitsInI32NodeGen.create(), LLVMArgNodeGen.create(1)));
}
});
factories.put("@polyglot_fits_in_i64", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_fits_in_i64", LLVMPolyglotBoxedPredicateNodeGen.create(FitsInI64NodeGen.create(), LLVMArgNodeGen.create(1)));
}
});
factories.put("@polyglot_fits_in_float", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_fits_in_float", LLVMPolyglotBoxedPredicateNodeGen.create(FitsInFloatNodeGen.create(), LLVMArgNodeGen.create(1)));
}
});
factories.put("@polyglot_fits_in_double", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_fits_in_double", LLVMPolyglotBoxedPredicateNodeGen.create(FitsInDoubleNodeGen.create(), LLVMArgNodeGen.create(1)));
}
});
LLVMNativeIntrinsicFactory polyglotPutMember = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_put_member", LLVMTruffleWriteToNameNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
};
factories.put("@polyglot_put_member", polyglotPutMember);
factories.put("@truffle_write", polyglotPutMember);
factories.put("@truffle_write_i", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_write_i", LLVMTruffleWriteToNameNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
});
factories.put("@truffle_write_l", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_write_l", LLVMTruffleWriteToNameNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
});
factories.put("@truffle_write_c", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_write_c", LLVMTruffleWriteToNameNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
});
factories.put("@truffle_write_f", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_write_f", LLVMTruffleWriteToNameNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
});
factories.put("@truffle_write_d", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("truffle_write_d", LLVMTruffleWriteToNameNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
});
factories.put("@truffle_write_b", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_write_b", LLVMTruffleWriteToNameNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
});
LLVMNativeIntrinsicFactory polyglotSetArrayElement = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_set_array_element", LLVMTruffleWriteToIndexNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
};
factories.put("@polyglot_set_array_element", polyglotSetArrayElement);
factories.put("@truffle_write_idx", polyglotSetArrayElement);
factories.put("@truffle_write_idx_i", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_write_idx_i", LLVMTruffleWriteToIndexNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
});
factories.put("@truffle_write_idx_l", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_write_idx_l", LLVMTruffleWriteToIndexNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
});
factories.put("@truffle_write_idx_c", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_write_idx_c", LLVMTruffleWriteToIndexNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
});
factories.put("@truffle_write_idx_f", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_write_idx_f", LLVMTruffleWriteToIndexNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
});
factories.put("@truffle_write_idx_d", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_write_idx_d", LLVMTruffleWriteToIndexNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
});
factories.put("@truffle_write_idx_b", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_write_idx_b", LLVMTruffleWriteToIndexNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
});
LLVMNativeIntrinsicFactory polyglotGetMember = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_get_member", LLVMTruffleReadFromNameNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.POINTER), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
};
factories.put("@polyglot_get_member", polyglotGetMember);
factories.put("@truffle_read", polyglotGetMember);
factories.put("@truffle_read_i", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_i", LLVMTruffleReadFromNameNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I32), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_read_l", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_l", LLVMTruffleReadFromNameNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I64), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_read_c", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_c", LLVMTruffleReadFromNameNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I8), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_read_f", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_f", LLVMTruffleReadFromNameNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.FLOAT), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_read_d", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_d", LLVMTruffleReadFromNameNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.DOUBLE), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_read_b", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_b", LLVMTruffleReadFromNameNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I1), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
LLVMNativeIntrinsicFactory polyglotGetArrayElement = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_get_array_element", LLVMTruffleReadFromIndexNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.POINTER), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
};
factories.put("@polyglot_get_array_element", polyglotGetArrayElement);
factories.put("@truffle_read_idx", polyglotGetArrayElement);
factories.put("@truffle_read_idx_i", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_idx_i", LLVMTruffleReadFromIndexNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I32), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_read_idx_l", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_idx_l", LLVMTruffleReadFromIndexNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I64), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_read_idx_c", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_idx_c", LLVMTruffleReadFromIndexNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I8), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_read_idx_f", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_idx_f", LLVMTruffleReadFromIndexNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.FLOAT), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_read_idx_d", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_idx_d", LLVMTruffleReadFromIndexNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.DOUBLE), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_read_idx_b", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_idx_b", LLVMTruffleReadFromIndexNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I1), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
LLVMNativeIntrinsicFactory polyglotAsI8 = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_as_i8", LLVMTruffleUnboxNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I8), LLVMArgNodeGen.create(1)));
}
};
factories.put("@polyglot_as_i8", polyglotAsI8);
factories.put("@truffle_unbox_c", polyglotAsI8);
LLVMNativeIntrinsicFactory polyglotAsI16 = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_as_i16", LLVMTruffleUnboxNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I16), LLVMArgNodeGen.create(1)));
}
};
factories.put("@polyglot_as_i16", polyglotAsI16);
LLVMNativeIntrinsicFactory polyglotAsI32 = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_as_i32", LLVMTruffleUnboxNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I32), LLVMArgNodeGen.create(1)));
}
};
factories.put("@polyglot_as_i32", polyglotAsI32);
factories.put("@truffle_unbox_i", polyglotAsI32);
LLVMNativeIntrinsicFactory polyglotAsI64 = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_as_i64", LLVMTruffleUnboxNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I64), LLVMArgNodeGen.create(1)));
}
};
factories.put("@polyglot_as_i64", polyglotAsI64);
factories.put("@truffle_unbox_l", polyglotAsI64);
LLVMNativeIntrinsicFactory polyglotAsFloat = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_as_float", LLVMTruffleUnboxNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.FLOAT), LLVMArgNodeGen.create(1)));
}
};
factories.put("@polyglot_as_float", polyglotAsFloat);
factories.put("@truffle_unbox_f", polyglotAsFloat);
LLVMNativeIntrinsicFactory polyglotAsDouble = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_as_double", LLVMTruffleUnboxNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.DOUBLE), LLVMArgNodeGen.create(1)));
}
};
factories.put("@polyglot_as_double", polyglotAsDouble);
factories.put("@truffle_unbox_d", polyglotAsDouble);
LLVMNativeIntrinsicFactory polyglotAsBoolean = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_as_boolean", LLVMTruffleUnboxNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I1), LLVMArgNodeGen.create(1)));
}
};
factories.put("@polyglot_as_boolean", polyglotAsBoolean);
factories.put("@truffle_unbox_b", polyglotAsBoolean);
//
LLVMNativeIntrinsicFactory polyglotInvoke = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_invoke", LLVMTruffleInvokeNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.POINTER), argumentsArray(3, type.getArgumentTypes().length - 3), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
};
factories.put("@polyglot_invoke", polyglotInvoke);
factories.put("@truffle_invoke", polyglotInvoke);
factories.put("@truffle_invoke_i", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_invoke_i", LLVMTruffleInvokeNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I32), argumentsArray(3, type.getArgumentTypes().length - 3), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_invoke_l", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_invoke_l", LLVMTruffleInvokeNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I64), argumentsArray(3, type.getArgumentTypes().length - 3), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_invoke_c", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_invoke_c", LLVMTruffleInvokeNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I8), argumentsArray(3, type.getArgumentTypes().length - 3), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_invoke_f", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_invoke_f", LLVMTruffleInvokeNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.FLOAT), argumentsArray(3, type.getArgumentTypes().length - 3), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_invoke_d", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_invoke_d", LLVMTruffleInvokeNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.DOUBLE), argumentsArray(3, type.getArgumentTypes().length - 3), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_invoke_b", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_invoke_b", LLVMTruffleInvokeNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I1), argumentsArray(3, type.getArgumentTypes().length - 3), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
//
factories.put("@truffle_execute", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_execute", LLVMTruffleExecuteNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.POINTER), argumentsArray(2, type.getArgumentTypes().length - 2), LLVMArgNodeGen.create(1)));
}
});
factories.put("@truffle_execute_i", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_execute_i", LLVMTruffleExecuteNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I32), argumentsArray(2, type.getArgumentTypes().length - 2), LLVMArgNodeGen.create(1)));
}
});
factories.put("@truffle_execute_l", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_execute_l", LLVMTruffleExecuteNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I64), argumentsArray(2, type.getArgumentTypes().length - 2), LLVMArgNodeGen.create(1)));
}
});
factories.put("@truffle_execute_c", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_execute_c", LLVMTruffleExecuteNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I8), argumentsArray(2, type.getArgumentTypes().length - 2), LLVMArgNodeGen.create(1)));
}
});
factories.put("@truffle_execute_f", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_execute_f", LLVMTruffleExecuteNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.FLOAT), argumentsArray(2, type.getArgumentTypes().length - 2), LLVMArgNodeGen.create(1)));
}
});
factories.put("@truffle_execute_d", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_execute_d", LLVMTruffleExecuteNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.DOUBLE), argumentsArray(2, type.getArgumentTypes().length - 2), LLVMArgNodeGen.create(1)));
}
});
factories.put("@truffle_execute_b", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_execute_b", LLVMTruffleExecuteNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I1), argumentsArray(2, type.getArgumentTypes().length - 2), LLVMArgNodeGen.create(1)));
}
});
//
factories.put("@truffle_address_to_function", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_address_to_function", LLVMTruffleAddressToFunctionNodeGen.create(LLVMArgNodeGen.create(1)));
}
});
LLVMNativeIntrinsicFactory polyglotCanExecute = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_can_execute", LLVMTruffleIsExecutableNodeGen.create(LLVMArgNodeGen.create(1)));
}
};
factories.put("@polyglot_can_execute", polyglotCanExecute);
factories.put("@truffle_is_executable", polyglotCanExecute);
LLVMNativeIntrinsicFactory polyglotIsNull = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_is_null", LLVMTruffleIsNullNodeGen.create(LLVMArgNodeGen.create(1)));
}
};
factories.put("@polyglot_is_null", polyglotIsNull);
factories.put("@truffle_is_null", polyglotIsNull);
LLVMNativeIntrinsicFactory polyglotHasArrayElements = new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_has_array_elements", LLVMTruffleHasSizeNodeGen.create(LLVMArgNodeGen.create(1)));
}
};
factories.put("@polyglot_has_array_elements", polyglotHasArrayElements);
factories.put("@truffle_has_size", polyglotHasArrayElements);
factories.put("@polyglot_has_members", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_has_members", LLVMTruffleHasKeysNodeGen.create(LLVMArgNodeGen.create(1)));
}
});
factories.put("@truffle_is_boxed", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_is_boxed", LLVMTruffleIsBoxedNodeGen.create(LLVMArgNodeGen.create(1)));
}
});
factories.put("@polyglot_get_array_size", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_get_array_size", LLVMTruffleGetSizeNodeGen.create(ForeignToLLVMType.I64, LLVMArgNodeGen.create(1)));
}
});
factories.put("@truffle_get_size", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_get_size", LLVMTruffleGetSizeNodeGen.create(ForeignToLLVMType.I32, LLVMArgNodeGen.create(1)));
}
});
//
factories.put("@polyglot_get_string_size", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_get_string_size", LLVMPolyglotGetStringSizeNodeGen.create(LLVMArgNodeGen.create(1)));
}
});
factories.put("@polyglot_as_string", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_as_string", LLVMPolyglotAsString.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3), LLVMArgNodeGen.create(4)));
}
});
factories.put("@polyglot_from_string", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_from_string", LLVMPolyglotFromString.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@polyglot_from_string_n", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@polyglot_from_string", LLVMPolyglotFromString.createN(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
});
//
factories.put("@truffle_read_string", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_string", LLVMTruffleReadStringNodeGen.create(LLVMArgNodeGen.create(1)));
}
});
factories.put("@truffle_read_n_string", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_n_string", LLVMTruffleReadNStringNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_read_bytes", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_bytes", LLVMTruffleReadBytesNodeGen.create(LLVMArgNodeGen.create(1)));
}
});
factories.put("@truffle_read_n_bytes", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_read_n_bytes", LLVMTruffleReadNBytesNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_string_to_cstr", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_string_to_cstr", LLVMTruffleStringAsCStringNodeGen.create(nodeFactory.createAllocateString(), LLVMArgNodeGen.create(1)));
}
});
factories.put("@truffle_free_cstr", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_free_cstr", LLVMTruffleFreeCStringNodeGen.create(LLVMArgNodeGen.create(1)));
}
});
factories.put("@truffle_is_truffle_object", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_is_truffle_object", LLVMTruffleIsTruffleObjectNodeGen.create(LLVMArgNodeGen.create(1)));
}
});
factories.put("@truffle_sulong_function_to_native_pointer", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_sulong_function_to_native_pointer", LLVMSulongFunctionToNativePointerNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@truffle_load_library", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_load_library", LLVMLoadLibraryNodeGen.create(LLVMArgNodeGen.create(1)));
}
});
factories.put("@truffle_polyglot_eval", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@truffle_polyglot_eval", LLVMPolyglotEval.createLegacy(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
//
factories.put("@__polyglot_as_typed", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@__polyglot_as_typed", LLVMPolyglotAsTyped.createStruct(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@__polyglot_as_typed_array", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@__polyglot_as_typed_array", LLVMPolyglotAsTyped.createArray(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@__polyglot_from_typed", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@__polyglot_from_typed", LLVMPolyglotFromTyped.createStruct(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
}
});
factories.put("@__polyglot_from_typed_array", new LLVMNativeIntrinsicFactory(true, true) {
@Override
protected RootCallTarget generate(FunctionType type) {
return wrap("@__polyglot_from_typed_array", LLVMPolyglotFromTyped.createArray(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
}
});
}
use of com.oracle.truffle.llvm.runtime.types.FunctionType in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(InvokeInstruction call) {
final Type targetType = call.getType();
int argumentCount = getArgumentCount(call.getArgumentCount(), targetType);
final LLVMExpressionNode[] argNodes = new LLVMExpressionNode[argumentCount];
final Type[] argTypes = new Type[argumentCount];
int argIndex = 0;
argNodes[argIndex] = nodeFactory.createFrameRead(runtime, PointerType.VOID, getStackSlot());
argTypes[argIndex] = new PointerType(null);
argIndex++;
if (targetType instanceof StructureType) {
argTypes[argIndex] = new PointerType(targetType);
argNodes[argIndex] = nodeFactory.createAlloca(runtime, targetType);
argIndex++;
}
for (int i = 0; argIndex < argumentCount; i++, argIndex++) {
argNodes[argIndex] = symbols.resolve(call.getArgument(i));
argTypes[argIndex] = call.getArgument(i).getType();
final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
if (isByValue(paramAttr)) {
argNodes[argIndex] = capsuleAddressByValue(argNodes[argIndex], argTypes[argIndex], paramAttr);
}
}
final SymbolImpl target = call.getCallTarget();
int regularIndex = call.normalSuccessor().getBlockIndex();
int unwindIndex = call.unwindSuccessor().getBlockIndex();
List<FrameSlot> normalTo = new ArrayList<>();
List<FrameSlot> unwindTo = new ArrayList<>();
List<Type> normalType = new ArrayList<>();
List<Type> unwindType = new ArrayList<>();
List<LLVMExpressionNode> normalValue = new ArrayList<>();
List<LLVMExpressionNode> unwindValue = new ArrayList<>();
if (blockPhis != null) {
for (Phi phi : blockPhis) {
FrameSlot slot = getSlot(phi.getPhiValue().getName());
LLVMExpressionNode value = symbols.resolve(phi.getValue());
if (call.normalSuccessor() == phi.getBlock()) {
normalTo.add(slot);
normalType.add(phi.getValue().getType());
normalValue.add(value);
} else {
unwindTo.add(slot);
unwindType.add(phi.getValue().getType());
unwindValue.add(value);
}
}
}
LLVMExpressionNode normalPhi = nodeFactory.createPhi(runtime, normalValue.toArray(new LLVMExpressionNode[normalValue.size()]), normalTo.toArray(new FrameSlot[normalTo.size()]), normalType.toArray(Type.EMPTY_ARRAY));
LLVMExpressionNode unwindPhi = nodeFactory.createPhi(runtime, unwindValue.toArray(new LLVMExpressionNode[unwindValue.size()]), unwindTo.toArray(new FrameSlot[unwindTo.size()]), unwindType.toArray(Type.EMPTY_ARRAY));
final LLVMSourceLocation source = sourceFunction.getSourceLocation(call);
LLVMExpressionNode function = nodeFactory.createLLVMBuiltin(runtime, target, argNodes, argCount, null);
if (function == null) {
function = symbols.resolve(target);
}
LLVMControlFlowNode result = nodeFactory.createFunctionInvoke(runtime, getSlot(call.getName()), function, argNodes, new FunctionType(targetType, argTypes, false), regularIndex, unwindIndex, normalPhi, unwindPhi, source);
setControlFlowNode(result);
}
use of com.oracle.truffle.llvm.runtime.types.FunctionType in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(VoidCallInstruction call) {
// stackpointer
final int argumentCount = call.getArgumentCount() + 1;
final LLVMExpressionNode[] args = new LLVMExpressionNode[argumentCount];
final Type[] argsType = new Type[argumentCount];
int argIndex = 0;
args[argIndex] = nodeFactory.createFrameRead(runtime, PointerType.VOID, getStackSlot());
argsType[argIndex] = new PointerType(null);
argIndex++;
for (int i = 0; i < call.getArgumentCount(); i++) {
args[argIndex] = symbols.resolve(call.getArgument(i));
argsType[argIndex] = call.getArgument(i).getType();
final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
if (isByValue(paramAttr)) {
args[argIndex] = capsuleAddressByValue(args[argIndex], argsType[argIndex], paramAttr);
}
argIndex++;
}
final LLVMSourceLocation source = sourceFunction.getSourceLocation(call);
final SymbolImpl target = call.getCallTarget();
LLVMExpressionNode node = nodeFactory.createLLVMBuiltin(runtime, target, args, argCount, source);
if (node == null) {
if (target instanceof InlineAsmConstant) {
final InlineAsmConstant inlineAsmConstant = (InlineAsmConstant) target;
node = createInlineAssemblerNode(inlineAsmConstant, args, argsType, call.getType(), source);
} else {
final LLVMExpressionNode function = symbols.resolve(target);
final FunctionType functionType = new FunctionType(call.getType(), argsType, false);
node = nodeFactory.createFunctionCall(runtime, function, args, functionType, source);
}
}
addInstruction(node);
}
use of com.oracle.truffle.llvm.runtime.types.FunctionType in project sulong by graalvm.
the class Function method createInvoke.
private void createInvoke(long[] args) {
int i = 0;
final AttributesCodeEntry paramAttr = paramAttributes.getCodeEntry(args[i++]);
final long ccInfo = args[i++];
final InstructionBlock normalSuccessor = function.getBlock(args[i++]);
final InstructionBlock unwindSuccessor = function.getBlock(args[i++]);
FunctionType functionType = null;
if (((ccInfo >> INVOKE_HASEXPLICITFUNCTIONTYPE_SHIFT) & 1) != 0) {
functionType = (FunctionType) types.get(args[i++]);
}
final int target = getIndex(args[i++]);
final Type calleeType;
if (scope.isValueForwardRef(target)) {
calleeType = types.get(args[i++]);
} else {
calleeType = scope.getValueType(target);
}
if (functionType == null) {
if (calleeType instanceof PointerType) {
functionType = (FunctionType) ((PointerType) calleeType).getPointeeType();
} else if (calleeType instanceof FunctionType) {
functionType = (FunctionType) calleeType;
} else {
throw new AssertionError("Cannot find Type of invoked function: " + calleeType.toString());
}
}
int[] arguments = new int[args.length - i];
int skipped = 0;
int j = 0;
while (j < functionType.getArgumentTypes().length && i < args.length) {
arguments[j++] = getIndex(args[i++]);
}
while (i < args.length) {
int index = getIndex(args[i++]);
arguments[j++] = index;
if (scope.isValueForwardRef(index)) {
i++;
skipped++;
}
}
if (skipped > 0) {
arguments = Arrays.copyOf(arguments, arguments.length - skipped);
}
final Type returnType = functionType.getReturnType();
if (returnType == VoidType.INSTANCE) {
emit(VoidInvokeInstruction.fromSymbols(scope, target, arguments, normalSuccessor, unwindSuccessor, paramAttr));
} else {
emit(InvokeInstruction.fromSymbols(scope, returnType, target, arguments, normalSuccessor, unwindSuccessor, paramAttr));
}
isLastBlockTerminated = true;
}
Aggregations