caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Evgeny Roubinchtein <zhenya1007@gmail.com>
To: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] In-memory assembly
Date: Wed, 10 Jan 2018 17:42:52 +0200	[thread overview]
Message-ID: <CAGYXaSawpXujmGA4VhO3qGJMBD7RJUmc1reaTt0AZ_adFU7+sQ@mail.gmail.com> (raw)
In-Reply-To: <CAPFanBGuPStM5o10n5SAAJar9YHd_Q+p6X3EA=7PNxGUc9RUtA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3569 bytes --]

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. :-)

-- 
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=6704). 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öger
> <christoph.hoeger@celeraone.com> 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 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
> 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

[-- Attachment #2: Type: text/html, Size: 4913 bytes --]

  reply	other threads:[~2018-01-10 15:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-10 10:20 Christoph Höger
2018-01-10 10:41 ` Gabriel Scherer
2018-01-10 15:42   ` Evgeny Roubinchtein [this message]
2018-01-10 16:46 ` Basile Starynkevitch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGYXaSawpXujmGA4VhO3qGJMBD7RJUmc1reaTt0AZ_adFU7+sQ@mail.gmail.com \
    --to=zhenya1007@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).