From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id DFD4282355 for ; Wed, 10 Jan 2018 11:41:44 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-qt0-f182.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.216.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.216.182 as permitted sender) identity=mailfrom; client-ip=209.85.216.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qt0-f182.google.com) identity=helo; client-ip=209.85.216.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-qt0-f182.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3Ars+m9xyA11MiqWXXCy+O+j09IxM/srCxBDY+r6Qd?= =?us-ascii?q?2+4XIJqq85mqBkHD//Il1AaPAd2Craocw8Pt8InYEVQa5piAtH1QOLdtbDQizf?= =?us-ascii?q?ssogo7HcSeAlf6JvO5JwYzHcBFSUM3tyrjaRsdF8nxfUDdrWOv5jAOBBr/KRB1?= =?us-ascii?q?JuPoEYLOksi7ze+/94HObwlSmDaxfa55IQmrownWqsQYm5ZpJLwryhvOrHtIeu?= =?us-ascii?q?BWyn1tKFmOgRvy5dq+8YB6/ShItP0v68BPUaPhf6QlVrNYFygpM3o05MLwqxbO?= =?us-ascii?q?SxaE62YGXWUXlhpIBBXF7A3/U5zsvCb2qvZx1S+HNsDtU7s6RSqt4LtqSB/wiS?= =?us-ascii?q?cIKTg58H3MisdtiK5XuQ+tqwBjz4LRZoyeKfhwcb7Hfd4CR2VBUMZfWSJCDI2h?= =?us-ascii?q?cYUAE+UPMP1Er4nkvVYCsQeyCRWuCe7p1zRGhmX23ao/0+k5EA/JxhcvH8gPsH?= =?us-ascii?q?vKqNX+KbocXvy1zKbW1zXMcelW0ir65YjHaB8uuuuMXbNufsrV00UvDB/KjlWO?= =?us-ascii?q?poz/ITyVzP8As2ee7+V6VOKvj3QrpB12ojiq38ohjJTCiIwSylDB7yp5wYA1KM?= =?us-ascii?q?W5SE59e96kEYFfuzuUN4tsRM4pXmJmuD4ix7EYpZK2eDIGxZcnyhLFdfCLbomF?= =?us-ascii?q?7gj+WOuSPzt1gm9udqiliBao60egz/XxVsmq31ZOqSpIitzMuWoM1xzX88SHU+?= =?us-ascii?q?d98lu41TaBygze6f9ILVo7larcLJ4hzbowmYQJvUvfGS/2nV36jK6Qdko65uil?= =?us-ascii?q?8/rrbqniq5OGNIJ5ihvyProzlsG+G+g0LwsDU3aD9eS5zrLj/En5QLtQjv0xl6?= =?us-ascii?q?nUqJ/aKt4Aqa6jAg9azIIj5wykDzi60NQXg2MHI0xfeB+cgIjpPkvBIPH8Dful?= =?us-ascii?q?n1uslzJry+jcPrL9GpXNMmTDkLD5cLlh8UFczQ4zwclb55JVEbEBPOn+WlTxtd?= =?us-ascii?q?zdFh82KRa4w+fhCNVn14MRQ3iDAqGDMPCajVjdzeI1IvKQY5cVjxZjJPU/r6rl?= =?us-ascii?q?jWU4gkMaZanv3ZwaZ32iNv9rJ0iDaH3qj5EKFmJc7SQkS+m/p1SISz9eYz6JVK?= =?us-ascii?q?Ix/DwhQNapBI3ZR42pxqeK3CqhE4d+aWVPC1TKGnDtIdbXE8wQYT6fd5cy2gcP?= =?us-ascii?q?UqKsHsp4jUn35V3KjoF/J++RwRU28Jfq1dx7/erWzEhg+jl9DsDb2GaIHTgtwj?= =?us-ascii?q?E4AgQu1aU6mnRTj0+Z2PEh0fNdHN1XofhOV1VibMOO/6lBE9n3Hzn5UJKJRVKh?= =?us-ascii?q?GIv0BDgwSpco34dLbR8tQZOtiRfM2yfsCLgQxeSG?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0BIAgDX7FVahrbYVdFDGhwBAQEEAQEKA?= =?us-ascii?q?QGEJ3QnB4QAmQKCAol/jS8UggIKI4UYAoQ2B0AXAQEBAQEBAQEBARIBAQEICws?= =?us-ascii?q?IKC+COCQBgkcBAgMjBBkBGx0BAwwGBQsNAgImAgIiAREBBQEcBhMUB4l/AQMVE?= =?us-ascii?q?DSiAUCMEYFtGAUBHIMLBYNgChknDVmCFwEBAQEGAQEBAQEbAgEFEn2DEYIVgVe?= =?us-ascii?q?ECYEOgy8EGYEaBDiDF4JlBaNkgkCFS406lA6NO4lSFAUggRchA4IEMhojUjKBe?= =?us-ascii?q?IJFDxAMgWhANwGLXwEBAQ?= X-IPAS-Result: =?us-ascii?q?A0BIAgDX7FVahrbYVdFDGhwBAQEEAQEKAQGEJ3QnB4QAmQK?= =?us-ascii?q?CAol/jS8UggIKI4UYAoQ2B0AXAQEBAQEBAQEBARIBAQEICwsIKC+COCQBgkcBA?= =?us-ascii?q?gMjBBkBGx0BAwwGBQsNAgImAgIiAREBBQEcBhMUB4l/AQMVEDSiAUCMEYFtGAU?= =?us-ascii?q?BHIMLBYNgChknDVmCFwEBAQEGAQEBAQEbAgEFEn2DEYIVgVeECYEOgy8EGYEaB?= =?us-ascii?q?DiDF4JlBaNkgkCFS406lA6NO4lSFAUggRchA4IEMhojUjKBeIJFDxAMgWhANwG?= =?us-ascii?q?LXwEBAQ?= X-IronPort-AV: E=Sophos;i="5.46,339,1511823600"; d="scan'208";a="308419871" Received: from mail-qt0-f182.google.com ([209.85.216.182]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 10 Jan 2018 11:41:43 +0100 Received: by mail-qt0-f182.google.com with SMTP id m59so21446759qte.11 for ; Wed, 10 Jan 2018 02:41:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=RC5oe/zpDQVs5JKnr1R3rl1gwdsAxnBvQIfuNipqgZM=; b=oYNsY1R3K7A0nEw4lzMlPllzX3RMtSMb69kZuK7oJW1E/7VSqT5RnvfUXeW6PLkzSP 6b2KC5bf2Knq/f7hOM0rYU8jHKCZIwzZ5qeaeBvuryAfBCxGRyAEoojQE/5TP5HwyY3w +9MfVS78/BCzKijtxMY5IesSJMgH6yk6PX17Fgutd0uDYk/znC6h8SWNuL6JMtG6P35w 70Wwz/5fj1g6xM9l/8pswGC0f07y0G7H5FjdbPqrNo/+F8exuoFSwUTKEe7v7ff8ztr1 FUrDakwaXupjG4XzfiNv1uEtITWh5WMSHYV+RYLINatSH7rZvWcIAF71GtdcZz/ZZRcM 55GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=RC5oe/zpDQVs5JKnr1R3rl1gwdsAxnBvQIfuNipqgZM=; b=i8BLHlHQNYnJKd4cJgJGmOMFa6K0aNHPH1jZ9kFR4CxJ6ckM3P5I6V1tfG+S1QHWEz dPGWP2udpHVQYjXOy38auSi39P/RmQ66L1w4iEXsQ1blHx2q4dQKufJW9OzKQr3jZseN mb1CmGZF/WsP2e9eUULLW1SWE9R+8nb+PiN5vHDo7xbZavm1T1DHk9ftuliAY/d1MgA7 +h98wzGogHPlMGqLo5gcUSSF6VGl1tggX2vo0nnluDwInMuAP6QjyXAUz0lYwYUFMzoK x1MhWIkYdSxc1sxzq0j0WCBWL74YbBgLzRgTugDx+Y+Cb0xwy9aSgLMjqNDTOa71V+FJ b3ag== X-Gm-Message-State: AKwxyteECUxcO2wTfr1s49g5m7ooPqOVc6SnnCJcgVzd3wXJFAeMR+GV isvxCaw9VWcOB9xRmXLiuPxT4O1mNkPPNvY0bMw= X-Google-Smtp-Source: ACJfBosUQ8UZ0cNSAtlPg4TLjIqe0SjM7YnRmaxm/zS3gS2HIn5cTHDNNrZqIOE7R9wkHIXEF3E1/1tlRhgkhxgW+i8= X-Received: by 10.200.50.176 with SMTP id z45mr399880qta.140.1515580902740; Wed, 10 Jan 2018 02:41:42 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.194.140 with HTTP; Wed, 10 Jan 2018 02:41:02 -0800 (PST) In-Reply-To: References: From: Gabriel Scherer Date: Wed, 10 Jan 2018 11:41:02 +0100 Message-ID: To: =?UTF-8?Q?Christoph_H=C3=B6ger?= Cc: OCaml Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] In-memory assembly # 1 Loading compiler-libs module from the toplevel requires some black magic because the toplevel is already built by linking the same libraries. (see MPR#6704, https://caml.inria.fr/mantis/view.php?id=3D6704). The "ocaml" toplevel does more black magic than "utop" and it works better there, but in general I would recommend experimenting with non-toplevel programs for this specific purpose. # 2 The various x86_* modules seem to internally define a print_line : Buffer.t -> X86_ast.asm_line -> unit which does not involve filesystem i/o. I think that the simplest solution to your question would be to expose this function in addition to the global one. (If I were you I would feel free to send a Pull Request performing this change for all x86 printer implementations, although I don't know whether the maintainers of this part of the codebase would find it desirable.) That said, what you would get is an in-memory representation of the assembler *text*; the compiler calls an assembler and linker as external programs. If for some reason you wanted to avoid this, you would have to link to an assembler as a library, and then it would possibly be easier to directly feed the (X86_ast.asm_line list) abstract representation -- with some conversion into the format this assembler library expects. For this you don't need to modify the interface of the printer modules. On Wed, Jan 10, 2018 at 11:20 AM, Christoph H=C3=B6ger wrote: > Dear all, > > I want to trigger OCaml compilation programmatically from a C++ applicati= on > and avoid the usage of subprocesses. It is fairly straightforward to > generate an OCaml AST, but I cannot compile it. > > 1. The relevant modules/libraries do not load > > utop # #require "compiler-libs.optcomp";; > Error: Reference to undefined global `Location' > > X86_masm.generate_asm stdout [] ;; > > > 2. The relevant modules seem to insist on file i/o for communication (i.e= ., > they use out_channel objects) > > > Does anyone know a simple way around these issues? > > a) Can I load the optcomp library without modifying the compiler (or with > some simple modifications) > > b) Is there a way to create an out_channel from a memory buffer? > > thanks, > > Christoph > > ps: If the answer to both questions is "no", I would be willing to work w= ith > the community and enhance the compiler if I could get some advice on how = to > do it best and if such a modification is wanted.