Loading ...
Sorry, an error occurred while loading the content.
 

Re: "ocaml_beginners"::[] example of code generation?

Expand Messages
  • Jon Harrop
    ... If you want to generate native-code at run-time then check out MetaOCaml. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. The F#.NET Journal
    Message 1 of 6 , May 2, 2007
      On Wednesday 02 May 2007 16:03, yanglian@... wrote:
      > is there any codes or related resources?
      > thanks.

      If you want to generate native-code at run-time then check out MetaOCaml.

      --
      Dr Jon D Harrop, Flying Frog Consultancy Ltd.
      The F#.NET Journal
      http://www.ffconsultancy.com/products/fsharp_journal/?e
    • yanglian@gmail.com
      try to write a compiler for tiger language. I m in instruction selection now. I read the tiger book but still don t know how to start it. so, wanna see some
      Message 2 of 6 , May 2, 2007
        try to write a compiler for tiger language.
        I'm in "instruction selection" now.
        I read the tiger book but still don't know how to start it. so, wanna see
        some examples

        On 5/2/07, William D. Neumann <wneumann@...> wrote:
        >
        > On Wed, 2 May 2007 yanglian@... <yanglian%40gmail.com> wrote:
        >
        > > is there any codes or related resources?
        > > thanks.
        >
        > I'd suppose that would depend on what you mean by code generation. Could
        > you be a bit more specific as to what you are interested in?
        >
        > William D. Neumann
        >
        > ---
        >
        > "There's just so many extra children, we could just feed the
        > children to these tigers. We don't need them, we're not doing
        > anything with them.
        >
        > Tigers are noble and sleek; children are loud and messy."
        >
        > -- Neko Case
        >
        > Life is unfair. Kill yourself or get over it.
        > -- Black Box Recorder
        >
        >


        [Non-text portions of this message have been removed]
      • William D. Neumann
        ... Oh. That kind of code generation. So are you targeting the OCaml VM? Or are you writing the compiler in OCaml and trying to target some notive platform,
        Message 3 of 6 , May 2, 2007
          On Wed, 2 May 2007 yanglian@... wrote:

          > try to write a compiler for tiger language.
          > I'm in "instruction selection" now.
          > I read the tiger book but still don't know how to start it. so, wanna see
          > some examples

          Oh. That kind of code generation.
          So are you targeting the OCaml VM? Or are you writing the compiler in
          OCaml and trying to target some notive platform, or some other IL?

          If it's the former, I don't believe there's too much out there --
          searching the main mailing list might turn up a paper or two from the guys
          at INRIA. Also a bit of searching turned up this thesis[1] which may or
          may not be of help.

          [1] http://www.brics.dk/DS/01/4/

          William D. Neumann

          ---

          "There's just so many extra children, we could just feed the
          children to these tigers. We don't need them, we're not doing
          anything with them.

          Tigers are noble and sleek; children are loud and messy."

          -- Neko Case

          Life is unfair. Kill yourself or get over it.
          -- Black Box Recorder
        • LianYang
          Thanks. where can i find the mapping among the ir tree, assem and bc? I looked at cogen exmple codes, there are asn, print, label. Here is what the current
          Message 4 of 6 , May 2, 2007
            Thanks.

            where can i find the mapping among the ir tree, assem and bc?
            I looked at cogen exmple codes, there are asn, print, label.

            Here is what the current codes look like.

            open Irgen

            type assem =
            Lit of int
            | OpRet
            | OpNeg
            | OpAdd
            | OpSub
            | OpMul
            | OpDiv
            | OpMod
            | OpEq
            | OpNeq
            | OpLt
            | OpGe
            | OpGt
            | OpLe
            | OpOr
            | OpAnd
            | OpNot
            | OpInc
            | OpDec
            | OpCp
            | CSPInt

            let hi n = n / 256
            let lo n = n mod 256

            let ir2assem irl =
            match irl with
            | (Asn a) ->
            (match a.irOp, a.irFst with
            | "Mov",(TInt n) -> [ Lit n ])
            | (Print i) ->
            (match i.irTarget with
            | TInt i -> [ Lit i; CSPInt])
            | (Label n) -> []

            let assem2bc assem =
            match assem with
            | Lit n -> [0;0;hi n; lo n]
            | OpRet -> [1;0]
            | OpNeg -> [1;1]
            | CSPInt -> [8;3]

            let cogen irl =
            let assem = List.flatten
            (List.map ir2assem irl) in
            let bc = List.flatten
            (List.map assem2bc assem) in
            begin
            print_string "let p = [";
            List.iter (fun i -> print_int i;
            print_string "; " ) bc;
            print_string "];;\n"
            end





            On 5/2/07, William D. Neumann <wneumann@...> wrote:
            >
            > On Wed, 2 May 2007 yanglian@... <yanglian%40gmail.com> wrote:
            >
            > > try to write a compiler for tiger language.
            > > I'm in "instruction selection" now.
            > > I read the tiger book but still don't know how to start it. so, wanna
            > see
            > > some examples
            >
            > Oh. That kind of code generation.
            > So are you targeting the OCaml VM? Or are you writing the compiler in
            > OCaml and trying to target some notive platform, or some other IL?
            >
            > If it's the former, I don't believe there's too much out there --
            > searching the main mailing list might turn up a paper or two from the guys
            >
            > at INRIA. Also a bit of searching turned up this thesis[1] which may or
            > may not be of help.
            >
            > [1] http://www.brics.dk/DS/01/4/
            >
            >
            > William D. Neumann
            >
            > ---
            >
            > "There's just so many extra children, we could just feed the
            > children to these tigers. We don't need them, we're not doing
            > anything with them.
            >
            > Tigers are noble and sleek; children are loud and messy."
            >
            > -- Neko Case
            >
            > Life is unfair. Kill yourself or get over it.
            > -- Black Box Recorder
            >
            >
            >


            [Non-text portions of this message have been removed]
          Your message has been successfully submitted and would be delivered to recipients shortly.