From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 973F4BB84 for ; Sun, 13 Jul 2008 14:20:44 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmMIAM+PeUjUnw6DZWdsb2JhbACCOI91EgIeA5Rw X-IronPort-AV: E=Sophos;i="4.30,353,1212357600"; d="scan'208";a="15055332" Received: from pih-relay04.plus.net ([212.159.14.131]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/AES256-SHA; 13 Jul 2008 14:20:43 +0200 Received: from [90.192.139.241] (helo=beast.local) by pih-relay04.plus.net with esmtpa (Exim) id 1KI0ZG-0001yy-V9 for caml-list@yquem.inria.fr; Sun, 13 Jul 2008 13:20:43 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Run-time FFI generation using LLVM Date: Sun, 13 Jul 2008 13:19:33 +0100 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200807131319.33126.jon@ffconsultancy.com> X-Plusnet-Relay: 5fab391907dd63a23c98a199ae5c8e63 X-Spam: no; 0.00; run-time:01 ffi:01 ocaml:01 ffi:01 run-time:01 ocaml:01 stubs:01 statically:01 bindings:01 amortized:01 wosize:01 val:01 compiler:01 ocaml's:01 bytecode:01 The latest OCaml Journal article describes how LLVM can be used to generate FFI code at run-time, allowing OCaml programs to dynamically load C libraries and call their functions without having to write any C stubs or statically link any custom libraries. This technique has the obvious advantage that its potential for reuse is much better because the bindings are written in OCaml rather than C. However, there are two disadvantages: . A significant amount of boilerplate is currently required (that could easily be amortized into an OCaml library) . The LLVM execution engine is currently very slow to invoke from OCaml (taking around 0.5ms for a single function call). Perhaps the most obvious steps forward are to expose the OCaml macros (e.g. Field, Wosize_val) as ordinary C functions so they can be called from LLVM-generated code, and then design and implement a DSL and compiler to ease the burden of generating FFI code. As an aside, I think it would also be very interesting to convert OCaml's bytecode interpreter from C into a JIT using LLVM by partially specializing the existing C code over a given bytecode. Anyway, LLVM is certainly a very exciting project for the OCaml community! -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e