Ignore:
Timestamp:
Nov 23, 2011, 5:43:24 PM (9 years ago)
Author:
tranquil
Message:

merge of indexed labels branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.2/8051/src/RTLabs/RTLabsPrinter.ml

    r818 r1542  
    4545
    4646let print_cmp = function
    47   | AST.Cmp_eq -> "eq"
    48   | AST.Cmp_ne -> "ne"
    49   | AST.Cmp_gt -> "gt"
    50   | AST.Cmp_ge -> "ge"
    51   | AST.Cmp_lt -> "lt"
    52   | AST.Cmp_le -> "le"
     47  | AST.Cmp_eq -> "="
     48  | AST.Cmp_ne -> "!="
     49  | AST.Cmp_gt -> ">"
     50  | AST.Cmp_ge -> ">="
     51  | AST.Cmp_lt -> "<"
     52  | AST.Cmp_le -> "<="
    5353
    5454let rec print_size = function
     
    8383  Printf.sprintf "%d%s" size (string_of_signedness sign)
    8484
    85 let print_op1 = function
     85let print_op1 op r = Printf.sprintf "%s %s"
     86  (match op with
    8687  | AST.Op_cast (int_type, dest_size) ->
    8788    Printf.sprintf "int%sto%d" (string_of_int_type int_type) dest_size
    88   | AST.Op_negint -> "negint"
    89   | AST.Op_notbool -> "notbool"
    90   | AST.Op_notint -> "notint"
    91   | AST.Op_id -> "id"
     89  | AST.Op_negint -> "-"
     90  | AST.Op_notbool -> "!"
     91  | AST.Op_notint -> "!i"
     92  | AST.Op_id -> ""
    9293  | AST.Op_ptrofint -> "ptrofint"
    93   | AST.Op_intofptr -> "intofptr"
    94 
    95 let print_op2 = function
    96   | AST.Op_add -> "add"
    97   | AST.Op_sub -> "sub"
    98   | AST.Op_mul -> "mul"
    99   | AST.Op_div -> "div"
     94  | AST.Op_intofptr -> "intofptr")
     95        (print_reg r)
     96
     97let print_arg = function
     98  | RTLabs.Reg r -> print_reg r
     99  | RTLabs.Imm (c, t) ->
     100    Printf.sprintf "(%s)%s" (Primitive.print_type t) (print_cst c)
     101
     102let print_op2 op r s = Printf.sprintf "%s %s %s"
     103  (print_arg r)
     104  (match op with
     105  | AST.Op_add -> "+"
     106  | AST.Op_sub -> "-"
     107  | AST.Op_mul -> "*"
     108  | AST.Op_div -> "/"
    100109  | AST.Op_divu -> "/u"
    101110  | AST.Op_mod -> "mod"
     
    104113  | AST.Op_or -> "or"
    105114  | AST.Op_xor -> "xor"
    106   | AST.Op_shl -> "shl"
    107   | AST.Op_shr -> "shr"
    108   | AST.Op_shru -> "shru"
     115  | AST.Op_shl -> "<<"
     116  | AST.Op_shr -> ">>"
     117  | AST.Op_shru -> ">>u"
    109118  | AST.Op_cmp cmp -> print_cmp cmp
    110   | AST.Op_addp -> "addp"
    111   | AST.Op_subp -> "subp"
    112   | AST.Op_subpp -> "subpp"
     119  | AST.Op_addp -> "+p"
     120  | AST.Op_subp -> "-p"
     121  | AST.Op_subpp -> "-pp"
    113122  | AST.Op_cmpp cmp -> (print_cmp cmp) ^ "p"
    114   | AST.Op_cmpu cmp -> (print_cmp cmp) ^ "u"
     123  | AST.Op_cmpu cmp -> (print_cmp cmp) ^ "u")
     124  (print_arg s)
    115125
    116126
     
    136146  | RTLabs.St_skip lbl -> "--> " ^ lbl
    137147  | RTLabs.St_cost (cost_lbl, lbl) ->
    138       Printf.sprintf "emit %s --> %s" cost_lbl lbl
     148    let cost_lbl = CostLabel.string_of_cost_label ~pretty:true cost_lbl in
     149    Printf.sprintf "emit %s --> %s" cost_lbl lbl
     150  | RTLabs.St_ind_0 (i, lbl) ->
     151    Printf.sprintf "index %d --> %s" i lbl
     152  | RTLabs.St_ind_inc (i, lbl) ->
     153    Printf.sprintf "increment %d --> %s" i lbl
    139154  | RTLabs.St_cst (destr, cst, lbl) ->
    140       Printf.sprintf "imm %s, %s --> %s"
     155      Printf.sprintf "%s := %s --> %s"
    141156        (print_reg destr)
    142157        (print_cst cst)
    143158        lbl
    144159  | RTLabs.St_op1 (op1, destr, srcr, lbl) ->
    145       Printf.sprintf "%s %s, %s --> %s"
    146         (print_op1 op1)
     160      Printf.sprintf "%s := %s --> %s"
    147161        (print_reg destr)
    148         (print_reg srcr)
     162  (print_op1 op1 srcr)
    149163        lbl
    150164  | RTLabs.St_op2 (op2, destr, srcr1, srcr2, lbl) ->
    151       Printf.sprintf "%s %s, %s, %s --> %s"
    152         (print_op2 op2)
     165      Printf.sprintf "%s := %s --> %s"
    153166        (print_reg destr)
    154         (print_reg srcr1)
    155         (print_reg srcr2)
     167  (print_op2 op2 srcr1 srcr2)
    156168        lbl
    157169  | RTLabs.St_load (q, addr, destr, lbl) ->
    158       Printf.sprintf "load %s, %s, %s --> %s"
     170      Printf.sprintf "%s := *(%s) %s --> %s"
     171        (print_reg destr)
    159172        (Memory.string_of_quantity q)
    160         (print_reg addr)
    161         (print_reg destr)
     173        (print_arg addr)
    162174        lbl
    163175  | RTLabs.St_store (q, addr, srcr, lbl) ->
    164       Printf.sprintf "store %s, %s, %s --> %s"
    165         (Memory.string_of_quantity q)
    166         (print_reg addr)
    167         (print_reg srcr)
    168         lbl
    169   | RTLabs.St_call_id (f, args, res, sg, lbl) ->
    170       Printf.sprintf "call \"%s\", %s, %s: %s --> %s"
     176      Printf.sprintf "*(%s)%s := %s --> %s"
     177        (Memory.string_of_quantity q)
     178        (print_arg addr)
     179        (print_arg srcr)
     180        lbl
     181  | RTLabs.St_call_id (f, args, Some r, sg, lbl) ->
     182      Printf.sprintf "%s := \"%s\"(%s) : %s --> %s"
     183        (print_reg r)
    171184        f
    172185        (print_args args)
    173         (print_oreg res)
    174         (Primitive.print_sig sg)
    175         lbl
    176   | RTLabs.St_call_ptr (f, args, res, sg, lbl) ->
    177       Printf.sprintf "call_ptr %s, %s, %s: %s --> %s"
     186        (Primitive.print_sig sg)
     187        lbl
     188  | RTLabs.St_call_id (f, args, None, sg, lbl) ->
     189      Printf.sprintf "\"%s\"(%s) : %s --> %s"
     190        f
     191        (print_args args)
     192        (Primitive.print_sig sg)
     193        lbl
     194  | RTLabs.St_call_ptr (f, args, Some r, sg, lbl) ->
     195      Printf.sprintf "%s := *%s (%s) : %s --> %s"
     196        (print_reg r)
    178197        (print_reg f)
    179198        (print_args args)
    180         (print_oreg res)
     199        (Primitive.print_sig sg)
     200        lbl
     201  | RTLabs.St_call_ptr (f, args, None, sg, lbl) ->
     202      Printf.sprintf "*%s (%s) : %s --> %s"
     203        (print_reg f)
     204        (print_args args)
    181205        (Primitive.print_sig sg)
    182206        lbl
    183207  | RTLabs.St_tailcall_id (f, args, sg) ->
    184       Printf.sprintf "tailcall \"%s\", %s: %s"
     208      Printf.sprintf "tailcall \"%s\" (%s) : %s"
    185209        f
    186210        (print_args args)
    187211        (Primitive.print_sig sg)
    188212  | RTLabs.St_tailcall_ptr (f, args, sg) ->
    189       Printf.sprintf "tailcall_ptr \"%s\", %s: %s"
     213      Printf.sprintf "tailcall *%s (%s) : %s"
    190214        (print_reg f)
    191215        (print_args args)
     
    225249
    226250
    227 let print_graph n c =
     251let print_graph n c entry =
    228252  let f lbl stmt s =
    229253    Printf.sprintf "%s%s: %s\n%s"
     
    232256      (print_statement stmt)
    233257      s in
    234   Label.Map.fold f c ""
    235 
    236 
     258  let f' lbl stmt (reach, s) =
     259    (Label.Set.add lbl reach, f lbl stmt s) in
     260  let (reachable, str) =
     261    RTLabsUtilities.dfs_fold f' c entry (Label.Set.empty, "") in
     262  let filter lbl _ = not (Label.Set.mem lbl reachable) in
     263  let c_rest = Label.Map.filter filter c in
     264  if Label.Map.is_empty c_rest then str else
     265    let str' = Label.Map.fold f c_rest "" in
     266    str ^ "DEAD NODES:\n" ^ str'
     267       
    237268let print_internal_decl n f def =
    238269
     
    252283    (n_spaces (n+2))
    253284    def.RTLabs.f_exit
    254     (print_graph (n+2) def.RTLabs.f_graph)
     285    (print_graph (n+2) def.RTLabs.f_graph def.RTLabs.f_entry)
    255286
    256287
Note: See TracChangeset for help on using the changeset viewer.