From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL,HTML_MESSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 23DEABC6B for ; Fri, 12 Oct 2007 14:45:24 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAPAGD0fAXQImh2dsb2JhbACCcotcAgEICik X-IronPort-AV: E=Sophos;i="4.21,266,1188770400"; d="scan'208,217";a="17908144" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 12 Oct 2007 14:45:23 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l9CCjM8N001096 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 12 Oct 2007 14:45:23 +0200 X-IronPort-AV: E=Sophos;i="4.21,266,1188770400"; d="scan'208,217";a="2930914" Received: from smtpoutm.mac.com ([17.148.16.76]) by mail2-smtp-roc.national.inria.fr with ESMTP; 12 Oct 2007 14:45:22 +0200 Received: from mac.com (smtpin02-en2 [10.13.10.147]) by smtpoutm.mac.com (Xserve/smtpout013/MantshX 4.0) with ESMTP id l9CCj76G023090; Fri, 12 Oct 2007 05:45:07 -0700 (PDT) Received: from [192.168.8.101] (c-24-218-151-219.hsd1.ma.comcast.net [24.218.151.219]) (authenticated bits=0) by mac.com (Xserve/smtpin02/MantshX 4.0) with ESMTP id l9CCj3DC019275 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Fri, 12 Oct 2007 05:45:05 -0700 (PDT) In-Reply-To: <20071012131730.GG12540@harlekin> References: <20071012131730.GG12540@harlekin> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: multipart/alternative; boundary=Apple-Mail-12--862455957 Message-Id: Cc: caml-list@inria.fr From: Gordon Henriksen Subject: Re: [Caml-list] Adding new architecture to ocamlopt Date: Fri, 12 Oct 2007 08:45:08 -0400 To: Christoph Sieghart X-Mailer: Apple Mail (2.752.2) X-j-chkmail-Score: MSGID : 470F6C63.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 470F6C63.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocamlopt:01 ocamlopt:01 pointers:01 asmcomp:01 asmcomp:01 symlinks:01 foo:01 foo:01 ocamlc:01 pointers:01 ocamlc:01 lambda:01 bytecomp:01 lambda:01 mli:01 --Apple-Mail-12--862455957 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=WINDOWS-1252; delsp=yes; format=flowed On Oct 12, 2007, at 09:17, Christoph Sieghart wrote: > Is there any documentation for adding a new architecture to =20 > ocamlopt? I would like to do a crosscompiler from one of the =20 > existing architectures to an embedded microcontroller. > > I have searched the mailinglist archives and the documenation, but =20 > have not found anything. Any pointers are welcome? Is my assumption =20= > that the major codegeneration work is done by the code in $caml/=20 > asmcomp? Christoph, Yes, asmcomp contains both the middle-end and the back-end code =20 generators. Note that the architecture-specific features are injected =20= by configure creating various symlinks of the form asmcomp/.ml -=20 > asmcomp//.ml. On one hand, this means you should be =20 able to clone the contents of one of the asmcomp/ =20 subdirectories and get your project off to a start pretty quickly. On =20= the other, ocamlopt is not a cross-compiler, so you may have a bit of =20= a challenge just getting the paths to the cross tools into the right =20 places without breaking ocamlc. I'm sure you'll get more detailed pointers, but here's a quick =20 overview... ocamlc and ocamlopt share code through the "Lambda" representation =20 (bytecomp/lambda.mli). After this point, ocamlopt transfers control =20 into asmcomp/asmgen.ml, which has a fairly straightforward pass =20 pipeline in Asmgen.compile_implementation. The Lambda representation is first translated into Closed Lambda =20 (asmcomp/clambda.mli), which is similar except that closures are =20 explicit. Next, ocamlopt transforms Clambda into its middle-end representation, =20= C--. This form is somewhat well documented at http://cminusminus.org/ =20= and in various academic papers. The C-- representation is =20 architecture-neutral in form, but not content. Target dependencies =20 are injected through the Arch module, which specifies address sizes, =20 endianness, etc. This is the point where displacement calculations =20 are performed, etc. The C-- representation is the input to the architecture-specific back-=20= end code generators, which are driven by the architecture-neutral =20 Asmgen.compile_phrase and Asmgen.compile_fundecl. In particular, this =20= pipeline is pleasantly self-documenting: let (++) x f =3D f x let compile_fundecl (ppf : formatter) fd_cmm =3D Reg.reset(); fd_cmm (* <-- The C-- representation for the function *) ++ Selection.fundecl ++ pass_dump_if ppf dump_selection "After instruction selection" ++ Comballoc.fundecl ++ pass_dump_if ppf dump_combine "After allocation combining" ++ liveness ppf ++ pass_dump_if ppf dump_live "Liveness analysis" ++ Spill.fundecl ++ liveness ppf ++ pass_dump_if ppf dump_spill "After spilling" ++ Split.fundecl ++ pass_dump_if ppf dump_split "After live range splitting" ++ liveness ppf ++ regalloc ppf 1 ++ Linearize.fundecl ++ pass_dump_linear_if ppf dump_linear "Linearized code" ++ Scheduling.fundecl ++ pass_dump_linear_if ppf dump_scheduling "After instruction =20 scheduling" ++ Emit.fundecl You can identify the target-dependent phases by correlating the =20 passes with the contents of a target subdirectory. Have fun! =97 Gordon --Apple-Mail-12--862455957 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=WINDOWS-1252
On Oct 12, 2007, at = 09:17, Christoph Sieghart wrote:

Is there any documentation for = adding a new architecture to ocamlopt? I would=A0like to do a = crosscompiler from one of the existing architectures to an=A0embedded = microcontroller.

I have searched the mailinglist = archives and the documenation, but have not=A0
Yes, asmcomp = contains both the middle-end and the back-end code generators. Note that = the architecture-specific features are injected by configure creating = various symlinks of the form asmcomp/<foo>.ml -> = asmcomp/<arch>/<foo>.ml. On one hand,=A0this means you = should be able to clone the contents of one of the asmcomp/<arch> = subdirectories and get your project off to a start pretty quickly. On = the other,=A0ocamlopt is not a cross-compiler, so you may have a bit of = a challenge just getting the paths to the cross tools into the right = places without breaking ocamlc.

I'm sure you'll get = more detailed pointers, but here's a quick = overview...

ocamlc and ocamlopt share = code through the "Lambda" representation (bytecomp/lambda.mli). After = this point, ocamlopt transfers control into asmcomp/asmgen.ml, which has = a fairly straightforward pass pipeline in = Asmgen.compile_implementation.

The Lambda representation = is first translated into Closed Lambda (asmcomp/clambda.mli), which is = similar except that closures are explicit.

Next, ocamlopt transforms = Clambda into its middle-end representation, C--. This form=A0is somewhat = well documented at http://cminusminus.org/ and in = various academic papers. The C-- representation is=A0architecture-neutral = in form, but not content. Target dependencies are injected through the = Arch module, which specifies address sizes, endianness, etc. This is the = point where displacement calculations are performed, etc.

The C-- representation is = the input to the=A0architecture-specific back-end code generators, which = are driven by the=A0architecture-neutral Asmgen.compile_phrase and = Asmgen.compile_fundecl. In particular, this pipeline is pleasantly = self-documenting:

let (++) x f =3D f = x

let = compile_fundecl (ppf : formatter) fd_cmm = =3D
=A0=A0Reg.reset();
=A0=A0fd_cmm (* <-- The = C-- representation for the function *)
=A0=A0++ = Selection.fundecl
=A0=A0++ pass_dump_if ppf dump_selection = "After instruction selection"
=A0=A0++ = Comballoc.fundecl
=A0=A0++ pass_dump_if ppf dump_combine = "After allocation combining"
=A0=A0++ liveness = ppf
=A0=A0++ pass_dump_if ppf dump_live "Liveness = analysis"
=A0=A0++ Spill.fundecl
=A0=A0++ liveness = ppf
=A0=A0++ pass_dump_if ppf dump_spill "After = spilling"
=A0=A0++ Split.fundecl
=A0=A0++ = pass_dump_if ppf dump_split "After live range splitting"
=A0=A0+= + liveness ppf
=A0=A0++ regalloc ppf 1
=A0=A0++ = Linearize.fundecl
=A0=A0++ pass_dump_linear_if ppf dump_linear = "Linearized code"
=A0=A0++ Scheduling.fundecl
=A0=A0++= pass_dump_linear_if ppf dump_scheduling "After instruction = scheduling"
=A0=A0++ Emit.fundecl

You can identify the = target-dependent phases by correlating the passes with the contents of a = target subdirectory. =A0Have fun!

=97 Gordon
=

= --Apple-Mail-12--862455957--