Ignore:
Timestamp:
Jun 15, 2011, 4:15:57 PM (9 years ago)
Author:
campbell
Message:

Update Cminor pretty printer and some examples.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Cminor/cminorMatitaPrinter.ml

    r898 r966  
    2121let print_data = function
    2222  (*| Data_reserve n -> Printf.sprintf "Init_space %d" n*)
    23   | Data_int8 i -> Printf.sprintf "Init_int8 (repr %d)" i
    24   | Data_int16 i -> Printf.sprintf "Init_int16 (repr %d)" i
    25   | Data_int32 i -> Printf.sprintf "Init_int32 (repr %d)" i
     23  | Data_int8 i -> Printf.sprintf "Init_int8 (repr I8 %d)" i
     24  | Data_int16 i -> Printf.sprintf "Init_int16 (repr I16 %d)" i
     25  | Data_int32 i -> Printf.sprintf "Init_int32 (repr I32 %d)" i
    2626  | Data_float32 f -> Printf.sprintf "Init_float32 %f" f
    2727  | Data_float64 f -> Printf.sprintf "Init_float64 %f" f
     
    4545  | AST.Cmp_le -> "Cle"
    4646
    47 let print_constant = function
    48   | AST.Cst_int i -> Printf.sprintf "Ointconst (repr %d)" i
     47let print_constant ty = function
     48  | AST.Cst_int i ->
     49      Printf.sprintf "Ointconst I%d (repr ? %d)"
     50        (match ty with Sig_int (sz, _) -> 8*sz | _ -> 32)
     51        i
    4952  | AST.Cst_float f -> Printf.sprintf "Ofloatconst %f" f
    50   | AST.Cst_addrsymbol id -> Printf.sprintf "Oaddrsymbol id_%s (repr 0)" id
     53  | AST.Cst_addrsymbol id -> Printf.sprintf "Oaddrsymbol id_%s 0" id
    5154  (*| AST.Cst_stackoffset off -> Printf.sprintf "Oaddrstack (repr %d)" off*)
    52   | AST.Cst_stack -> Printf.sprintf "Oaddrstack (repr 0)"
    53   | AST.Cst_offset off -> Printf.sprintf "Ointconst (repr %d)" (Driver.CminorMemory.concrete_offset off)
    54   | AST.Cst_sizeof sz -> Printf.sprintf "Ointconst (repr %d)" (Driver.CminorMemory.concrete_size sz)
     55  | AST.Cst_stack -> Printf.sprintf "Oaddrstack 0"
     56  | AST.Cst_offset off ->
     57      Printf.sprintf "Ointconst I%d (repr ? %d)"
     58        (match ty with Sig_int (sz, _) -> 8*sz | _ -> 32)
     59        (Driver.CminorMemory.concrete_offset off)
     60  | AST.Cst_sizeof sz ->
     61      Printf.sprintf "Ointconst I%d (repr ? %d)"
     62        (match ty with Sig_int (sz, _) -> 8*sz | _ -> 32)
     63        (Driver.CminorMemory.concrete_size sz)
    5564
    5665let print_op1 = function
    57   | AST.Op_cast((1,Unsigned),_) -> "Ocast8unsigned"
    58   | AST.Op_cast((1,Signed),_) -> "Ocast8signed"
    59   | AST.Op_cast((2,Unsigned),_) -> "Ocast16unsigned"
    60   | AST.Op_cast((2,Signed),_) -> "Ocast16signed"
    61   | AST.Op_cast((4,_),_) -> "Oid"
     66  | AST.Op_cast((_,sg),sz) -> Printf.sprintf "(Ocastint %s I%d)" (print_signedness sg) (8*sz)
    6267  | AST.Op_negint -> "Onegint"
    6368  | AST.Op_notbool -> "Onotbool"
     
    6570  | AST.Op_id -> "Oid"
    6671  | AST.Op_ptrofint -> "(Optrofint Any)"
    67   | AST.Op_intofptr -> "Ointofptr"
    68 
    69 let print_op2 = function
     72  | AST.Op_intofptr -> "(Ointofptr ?)"
     73
     74let print_op2 ty = function
    7075  | AST.Op_add -> "Oadd"
    7176  | AST.Op_sub -> "Osub"
     
    8590  | AST.Op_addp -> "Oaddp"
    8691  | AST.Op_subp -> "Osubpi"
    87   | AST.Op_subpp -> "Osubpp"
     92  | AST.Op_subpp ->
     93      Printf.sprintf "(Osubpp I%d)"
     94        (match ty with Sig_int (sz, _) -> 8*sz | _ -> 32)
    8895  | AST.Op_cmpp cmp -> "(Ocmpp " ^ (print_cmp cmp) ^ ")"
    8996
     
    112119| Cminor.Expr (e,ty) -> match e with
    113120  | Cminor.Id id -> Printf.sprintf "Id (%s) %s" (print_type ty) (p_id id)
    114   | Cminor.Cst cst -> Printf.sprintf "Cst (%s) (%s)" (print_type ty) (print_constant cst)
     121  | Cminor.Cst cst -> Printf.sprintf "Cst (%s) (%s)" (print_type ty) (print_constant ty cst)
    115122  | Cminor.Op1 (op1, e) ->
    116123      Printf.sprintf "Op1 (%s) (%s) %s (%s)"
     
    120127      Printf.sprintf "Op2 (%s) (%s) (%s) %s (%s) (%s)"
    121128        (print_type (typeof e1)) (print_type (typeof e2)) (print_type ty)
    122         (print_op2 op2)
     129        (print_op2 ty op2)
    123130        (print_expression p_id e1)
    124131        (print_expression p_id e2)
     
    156163let print_table n =
    157164  let f (case, exit) =
    158     Printf.sprintf "(pair ?? (repr %d) %d)" case exit
     165    Printf.sprintf "(pair ?? (repr ? %d) %d)" case exit
    159166  in
    160167  MiscPottier.string_of_list (";\n" ^ n_spaces n) f
     
    194201(* XXX cheat horribly *)
    195202  | Cminor.St_call (None, Cminor.Expr (Cminor.Cst (AST.Cst_addrsymbol f),_), args, sg) ->
    196       Printf.sprintf "%sSt_call (None ?) (Cst ? (Oaddrsymbol id_%s (repr 0))) [%s]\n"
     203      Printf.sprintf "%sSt_call (None ?) (Cst ? (Oaddrsymbol id_%s 0)) [%s]\n"
    197204        (n_spaces n)
    198205        f
    199206        (print_args p_id args)
    200207  | Cminor.St_call (Some id, Cminor.Expr (Cminor.Cst (AST.Cst_addrsymbol f),_), args, sg) ->
    201       Printf.sprintf "%sSt_call (Some ? %s) (Cst ? (Oaddrsymbol id_%s (repr 0))) [%s]\n"
     208      Printf.sprintf "%sSt_call (Some ? %s) (Cst ? (Oaddrsymbol id_%s 0)) [%s]\n"
    202209        (n_spaces n)
    203210        (p_id id)
     
    205212        (print_args p_id args)
    206213  | Cminor.St_tailcall (Cminor.Expr (Cminor.Cst (AST.Cst_addrsymbol f),_), args, sg) ->
    207       Printf.sprintf "%sSt_tailcall (Cst ? (Oaddrsymbol id_%s (repr 0))) [%s]\n"
     214      Printf.sprintf "%sSt_tailcall (Cst ? (Oaddrsymbol id_%s 0)) [%s]\n"
    208215        (n_spaces n)
    209216        f
Note: See TracChangeset for help on using the changeset viewer.