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 DD72A82355 for ; Wed, 10 Jan 2018 16:42:55 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=zhenya1007@gmail.com; spf=Pass smtp.mailfrom=zhenya1007@gmail.com; spf=None smtp.helo=postmaster@mail-yw0-f181.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of zhenya1007@gmail.com) identity=pra; client-ip=209.85.161.181; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="zhenya1007@gmail.com"; x-sender="zhenya1007@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of zhenya1007@gmail.com designates 209.85.161.181 as permitted sender) identity=mailfrom; client-ip=209.85.161.181; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="zhenya1007@gmail.com"; x-sender="zhenya1007@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-yw0-f181.google.com) identity=helo; client-ip=209.85.161.181; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="zhenya1007@gmail.com"; x-sender="postmaster@mail-yw0-f181.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AGg3fMB8xfKAQZf9uRHKM819IXTAuvvDOBiVQ1KB2?= =?us-ascii?q?0uIcTK2v8tzYMVDF4r011RmVBdyds6oMotGVmpioYXYH75eFvSJKW713fDhBt/?= =?us-ascii?q?8rmRc9CtWOE0zxIa2iRSU7GMNfSA0tpCnjYgBaF8nkelLdvGC54yIMFRXjLwp1?= =?us-ascii?q?Ifn+FpLPg8it2O2+54Dfbx9UiDahfLh/MAi4oQLNu8cMnIBsMLwxyhzHontJf+?= =?us-ascii?q?RZ22ZlLk+Nkhj/+8m94odt/zxftPw9+cFAV776f7kjQrxDEDsmKWE169b1uhTF?= =?us-ascii?q?UACC+2ETUmQSkhpPHgjF8BT3VYr/vyfmquZw3jSRMNboRr4oRzut86ZrSAfpiC?= =?us-ascii?q?gZMT457HrXgdF0gK5CvR6tuwBzz4vSbY6SKfR+Y7jdfcsESmVdQsZfWStBAoam?= =?us-ascii?q?YIsOCeoKIOJUoob5qlcLqxa1GAuiC/71yjJQhHD206003eoiHw/bwgIvA8kDv2?= =?us-ascii?q?7IoNjvLqoeTfy5wavOwD7eb/1WwzD96I3Qfx4uv/GMUqx/cczRyEIyCw3FiUiQ?= =?us-ascii?q?ppfkPzOTyusNs3Sb4PRhVeKplmUqrABwojixyccqiojGnJ8ZxkzY+Sh724s1Kt?= =?us-ascii?q?i4R1R6Yd6gCpdfqyaaN45vT84kXmpmtiE6yrgctp66eigH0I4oxwTQavyGbYiE?= =?us-ascii?q?+BXjVPyeITtghXJlfqi/hxeo/kS6xO38TNG40FlLripZktnMq2sC2wbP5ciAT/?= =?us-ascii?q?tx5keg1iyP1wDU7eFIO1w7la3eK5Mn37U+lYITvFzdEiPqnEj6lqybe0U+9uS1?= =?us-ascii?q?6unrf6/qqoKfOoNpjAz1L74gldalAesiNwgDR2ib9vq41L3k5UD5Ra9Fjvwykq?= =?us-ascii?q?XAsJHbK9gXqre3AwNI0Ysv9gyzDzih0NQfknkHKExKdAibgIjuPlHCOPH4DfGh?= =?us-ascii?q?jFSwiDpn2ezKM7n7DpjOLnXPiqrtcLdg50JG1QY+zs1T64pRCr4bIfLzXkHxtM?= =?us-ascii?q?bfDh88KwG1wubnB8t71oIeQ22DH7OVPL/QvFKT6eIvJvODZI4RuDrnN/cl4Pvu?= =?us-ascii?q?gWcjmVABZampwYcXaHegE/t6OUqZZH7sjs4FEWcLpQo+UPfniEaCUD5Wf3a9Rb?= =?us-ascii?q?gw5jA9CIK8DIfMXJqhgLKb3HTzIpoDQUtPD1TENH7pc4SCVL8oaTmOaptqmzkA?= =?us-ascii?q?ELygUJMJ1Be0tQa8xaAxfcTO/ShNmIzs2d5kr9fUiBsz8zd0E8mc1SnZXWF5mH?= =?us-ascii?q?IBHmdug4hwpEV8zhGI1q0u0K8QLsBa+/4cClRyDpXb1eEvTo2rA1OTTpKyUF+j?= =?us-ascii?q?B+6eL3Q0R9M1zcUJZh8kSdqnhxHHmSGtBu1MzuDZNNkP6qvZmkPJCYNl0X+fjf?= =?us-ascii?q?suilAnRo1EMmj03vcipTiWPJbAlgCir4jvdakY23STpmKKzG7LrV4AFQApAfyD?= =?us-ascii?q?UncYaU/b69/+4xGaQg=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CnBQBdM1ZahrWhVdFEGhwBAQEEAQEKA?= =?us-ascii?q?QGDaD90JweEAIE5l0dGAQEGgTQCgmaGG4VUiGyCAgojhRgChD0HQhUBAQEBAQE?= =?us-ascii?q?BAQEBEgEBAQgLCwgoL4I4JIJIAQIBAiMEGQEbEgwDDAYFCw0NHQICIQEBEQEFA?= =?us-ascii?q?QoSBhMSAgeJfwEDCA0QNKIaQIwRgW0YBQEcgwsFg2AKGScDClmCFwELAR0CBhK?= =?us-ascii?q?EDoIVgQ+CMYIggQ6Cay0MCwIBARmBGgRlgmqCZQWBLQEBAYc0DJo3MwgBAYFnC?= =?us-ascii?q?oYaiDmFAYJ/kQ+NO0CJEhQFIIEXDyaBc29SMlKBJgmCEioPEAyBaT83AYtfAQE?= =?us-ascii?q?B?= X-IPAS-Result: =?us-ascii?q?A0CnBQBdM1ZahrWhVdFEGhwBAQEEAQEKAQGDaD90JweEAIE?= =?us-ascii?q?5l0dGAQEGgTQCgmaGG4VUiGyCAgojhRgChD0HQhUBAQEBAQEBAQEBEgEBAQgLC?= =?us-ascii?q?wgoL4I4JIJIAQIBAiMEGQEbEgwDDAYFCw0NHQICIQEBEQEFAQoSBhMSAgeJfwE?= =?us-ascii?q?DCA0QNKIaQIwRgW0YBQEcgwsFg2AKGScDClmCFwELAR0CBhKEDoIVgQ+CMYIgg?= =?us-ascii?q?Q6Cay0MCwIBARmBGgRlgmqCZQWBLQEBAYc0DJo3MwgBAYFnCoYaiDmFAYJ/kQ+?= =?us-ascii?q?NO0CJEhQFIIEXDyaBc29SMlKBJgmCEioPEAyBaT83AYtfAQEB?= X-IronPort-AV: E=Sophos;i="5.46,340,1511823600"; d="scan'208,217";a="308472487" Received: from mail-yw0-f181.google.com ([209.85.161.181]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 10 Jan 2018 16:42:54 +0100 Received: by mail-yw0-f181.google.com with SMTP id m19so725702ywh.12 for ; Wed, 10 Jan 2018 07:42:54 -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; bh=1hbi/vHgNfazZKuG1wiwQXkX3/2gdJT+DaRdBI4Lcd8=; b=MopAXCGSiGz5fbXmXETfov4wz22fDEjpmpk4Ebh91XYfuuth/KsXwfS/uOAtQN3sQ4 OxA1oLsrTpif5QGXqxfAUUAGjK74Pg0rNUR0zaxvf07nC8Q7tOpxV0ngVxtPTVAnWFyE LVaOL9GW74nMxmdBGHObrq7Fk8n9IlLxoAcW8zjqYAXl/Zj11FMBTySYoj/xekjom5US rFtH++wmtPXYpOOnDNfpkjBOaN2VNwu/b4YqclsgrhSLD+dPu65TL9dVBECC5chO6ghk HzyslhmLs55pCIPf2XKI4vdmjVQ3IECznbHDxYtAf/j+bP3C/0dEtEtQEBfbpYLRr/I3 9eGQ== 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; bh=1hbi/vHgNfazZKuG1wiwQXkX3/2gdJT+DaRdBI4Lcd8=; b=szgodGauhWUp9JWlwP1GFdV/5g3QfJ8DGUOIWyVVw4OQQF/d8J7lxGOcQF7VEVS1Wl MAOMlvc7p/7FvJeF7k9OFb25nwzb5GhTfQKAUdGbm6NuRaJYlB5EMx1NhJkZ/QlttdJa UGBSGGrcthMm8/KHlp/CJsnS8jsKnNWVoV4cxtPd7fpiX4egTtC+4wwkSRVIw0+s8yE1 raxqESPxx6ITMVCTPG7r/Uwi4iBlaMVxBNyPDXN5OCFfMLMElvT6LW3JhFdYIlx13OsB kMSYdAEcvlj1X+2h7x+h2cKTeAfqClzfqieTb9pCqzfrWdagNoWcHifMCbdYMiA1N9A4 M49Q== X-Gm-Message-State: AKGB3mKl/Mt2esHpjW8JwHJZjLpfJp4CWiSqOzOdhaIscOPAz/+dBIWa HCnwYJxW1Ytb8r9HQmvYmKXLpRTHYEk5O2dx05zQFQ== X-Google-Smtp-Source: ACJfBosu8e7UEGwJTzVwvXrybyX6ZpYKJX6qf2XuvKqnOorTRco28BSre3j+rYdMVGHHXIxPaZzISxI7oIMEYzJ+SS8= X-Received: by 10.13.248.70 with SMTP id i67mr17225874ywf.376.1515598972728; Wed, 10 Jan 2018 07:42:52 -0800 (PST) MIME-Version: 1.0 Received: by 10.37.186.206 with HTTP; Wed, 10 Jan 2018 07:42:52 -0800 (PST) In-Reply-To: References: From: Evgeny Roubinchtein Date: Wed, 10 Jan 2018 17:42:52 +0200 Message-ID: To: OCaml Mailing List Content-Type: multipart/alternative; boundary="94eb2c07fa50643ae405626de2db" Subject: Re: [Caml-list] In-memory assembly --94eb2c07fa50643ae405626de2db Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable With respect to compiler calling the assembler, there _was_ work done to allow the compiler to generate object code directly, see: https://github.com/bmeurer/ocamljit2, as well as https://arxiv.org/pdf/1110.1029.pdf and https://arxiv.org/pdf/1011.6223.pdf. Unfortunately, it looks like that effort stopped tracking the OCaml mainline as of version 3.12. I don't have a good idea of how much effort it would be to resurrect that work for version 4.0.x of the OCaml compiler. IIRC, Benedikt Meurer reads this list, so perhaps he can comment. :-) --=20 Best, Evgeny On Wed, Jan 10, 2018 at 12:41 PM, Gabriel Scherer wrote: > # 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++ > application > > 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 wi= th > > 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 > with > > 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. > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs --94eb2c07fa50643ae405626de2db Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
With respect to compiler calling the assembler, = there _was_ work done to allow the compiler to generate object code directl= y, see: https://github.com= /bmeurer/ocamljit2, as well as https://arxiv.org/pdf/1110.1029.pdf and https://arxiv.org/pdf/1011.6223.pdf.=C2=A0 Unf= ortunately, it looks like that effort stopped tracking the OCaml mainline a= s of version 3.12.=C2=A0 I don't have a good idea of how much effort it= would be to resurrect that work for version 4.0.x of the OCaml compiler.= =C2=A0 IIRC, Benedikt Meurer reads this list, so perhaps he can comment. :-= )

--
Best,
Evgeny

On Wed, Jan 10, 2018 = at 12:41 PM, Gabriel Scherer <gabriel.scherer@gmail.com> wrote:
# 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<= /a>). 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

=C2=A0 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
<
christoph.hoeger@cele= raone.com> wrote:
> Dear all,
>
> I want to trigger OCaml compilation programmatically from a C++ applic= ation
> 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
>
>=C2=A0 =C2=A0utop # #require "compiler-libs.optcomp";;
>=C2=A0 =C2=A0Error: Reference to undefined global `Location'
>
>=C2=A0 =C2=A0X86_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 w= ith
> some simple modifications)
>
> b) Is there a way to create an out_channel=C2=A0 from a memory buffer?=
>
> thanks,
>
> Christoph
>
> ps: If the answer to both questions is "no", I would be will= ing to work with
> the community and enhance the compiler if I could get some advice on h= ow to
> do it best and if such a modification is wanted.

--
Caml-list mailing list.=C2=A0 Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

--94eb2c07fa50643ae405626de2db--