List Info

Thread: "ocaml_beginners"::[] maximal munch in instruction selection




"ocaml_beginners"::[] maximal munch in instruction selection
country flaguser name
United States
2007-06-06 23:15:27
I'm working on the tiger compiler project in tiger book
"Modern Compiler
Implementation  in ML"
Thanks! Got some questions on instruction selection: i'm
trying to translate
ir to machine code.

the example given in book is ML grammer, right? i didn't get
it.
what's the relation of emit's argument?
fun munchStm(
T.MOVE(T.MEM(T.BINOP(T.PLUS, e1, T.CONST(c))), e2)) =
emit(Assem.OPER{assem="STORE M['s0 + " ˆint(c) ˆ
"] = 's1n",
src=[munchExp(e1), munchExp(e2)],
dst=[],
jump=NONE})

And here is the definition of emit.
What's the meaning of "emit" function in the
following ML code? print
fun codegen(frame)(stm: Tree.stm):Assem.instr list =
let
val ilist = ref(nil: Assem.instr list)
fun emit(x) = ilist := x::!ilist
fun munchStm: Tree.stm -> unit
fun munchExp: Tree.exp -> Temp.temp
in
munchStm(stm);
rev(!ilist)
end


[Non-text portions of this message have been removed]



Archives up to November 11, 2006 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/

The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http:/
/groups.yahoo.com/group/ocaml_beginners/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    ht
tp://groups.yahoo.com/group/ocaml_beginners/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:ocaml_beginners-digest@yahoogroups.com 
    mailto:ocaml_beginners-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    ocaml_beginners-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 

Re: "ocaml_beginners"::[] maximal munch in instruction selection
country flaguser name
United States
2007-06-07 07:29:13
First of all, this is Standard ML code, not OCaml, so you
may be
getting confused by the syntactic differences between the
two
languages. You may find it worthwhile to read this:
http://www.dc
s.ed.ac.uk/home/stg/NOTES/

I can't make much sense of what you've written here,
probably in part
because of the (lack of) formatting. The use of emit seems
inconsistent: the definition just adds an instruction to an
instruction list, but the call in munchStmt is taking
arguments in a
form I don't recognize. It looks like the statement that is
getting
"munched" is of the form "*(e1 + c) :=
e2", i.e., an indirect
assignment through a pointer.

Regards,
Chris

On 6/7/07, LianYang <yangliangmail.com> wrote:
> I'm working on the tiger compiler project in tiger book
"Modern Compiler
> Implementation  in ML"
> Thanks! Got some questions on instruction selection:
i'm trying to translate
> ir to machine code.
>
> the example given in book is ML grammer, right? i
didn't get it.
> what's the relation of emit's argument?
> fun munchStm(
> T.MOVE(T.MEM(T.BINOP(T.PLUS, e1, T.CONST(c))), e2)) =
> emit(Assem.OPER{assem="STORE M['s0 + "
ˆint(c) ˆ "] = 's1n",
> src=[munchExp(e1), munchExp(e2)],
> dst=[],
> jump=NONE})
>
> And here is the definition of emit.
> What's the meaning of "emit" function in the
following ML code? print
> fun codegen(frame)(stm: Tree.stm):Assem.instr list =
> let
> val ilist = ref(nil: Assem.instr list)
> fun emit(x) = ilist := x::!ilist
> fun munchStm: Tree.stm -> unit
> fun munchExp: Tree.exp -> Temp.temp
> in
> munchStm(stm);
> rev(!ilist)
> end
>
>
> [Non-text portions of this message have been removed]
>
>
>
> Archives up to November 11, 2006 are also downloadable
at http://www.connettivo.net/cntprojects/ocaml_beginners/

> The archives of the very official ocaml list (the
seniors' one) can be found at http://caml.inria.fr
> Attachments are banned and you're asked to be polite,
avoid flames etc.
> Yahoo! Groups Links
>
>
>
>
>


Archives up to November 11, 2006 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/

The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http:/
/groups.yahoo.com/group/ocaml_beginners/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    ht
tp://groups.yahoo.com/group/ocaml_beginners/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:ocaml_beginners-digest@yahoogroups.com 
    mailto:ocaml_beginners-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    ocaml_beginners-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 

Re: "ocaml_beginners"::[] maximal munch in instruction selection
country flaguser name
United Kingdom
2007-06-07 15:44:46
On Thursday 07 June 2007 05:15:27 LianYang wrote:
> I'm working on the tiger compiler project in tiger book
"Modern Compiler
> Implementation  in ML"

Note that this is Standard ML and not OCaml.

> the example given in book is ML grammer, right? i
didn't get it.
> what's the relation of emit's argument?
> fun munchStm(
> T.MOVE(T.MEM(T.BINOP(T.PLUS, e1, T.CONST(c))), e2)) =
> emit(Assem.OPER{assem="STORE M['s0 + "
ˆint(c) ˆ "] = 's1n",
> src=[munchExp(e1), munchExp(e2)],
> dst=[],
> jump=NONE})

This is part of the definition of a function called
"munchStm". In OCaml, this 
is:

let munchStm = function
  | T.Move(T.Mem(T.BinOp(T.Plus, e1, T.Const c)), e2) ->
      emit(Assem.Oper{assem="STORE M['s0 +
"^string_of_int c^"] = 's1n",
                      src=[munchExp(e1), munchExp(e2)],
                      dst=[],
                      jump=NONE})
  | ...

> And here is the definition of emit.
> What's the meaning of "emit" function in the
following ML code? print
> fun codegen(frame)(stm: Tree.stm):Assem.instr list =
> let
> val ilist = ref(nil: Assem.instr list)
> fun emit(x) = ilist := x::!ilist
> fun munchStm: Tree.stm -> unit
> fun munchExp: Tree.exp -> Temp.temp
> in
> munchStm(stm);
> rev(!ilist)
> end

let codegen frame stm =
  let ilist = ref [] in
  let emit x =
    ilist := x :: !ilist in
  munchStm stm;
  List.rev !ilist

So emit just prepends a new instruction onto the mutable
list "ilist".

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_sci
entists/?e


Archives up to November 11, 2006 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/

The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http:/
/groups.yahoo.com/group/ocaml_beginners/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    ht
tp://groups.yahoo.com/group/ocaml_beginners/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:ocaml_beginners-digest@yahoogroups.com 
    mailto:ocaml_beginners-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    ocaml_beginners-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )