Ignore:
Timestamp:
Oct 28, 2011, 4:45:12 PM (9 years ago)
Author:
tranquil
Message:
  • implemented partial redundancy elimination
  • added some tools for RTLabs, with a depth-first fold
  • prettier printing of RTLabs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.2/8051-indexed-labels-branch/src/RTLabs/RTLabsPrinter.ml

    r1340 r1473  
    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_op2 op r s = Printf.sprintf "%s %s %s"
     98  (print_reg r)
     99  (match op with
     100  | AST.Op_add -> "+"
     101  | AST.Op_sub -> "-"
     102  | AST.Op_mul -> "*"
     103  | AST.Op_div -> "/"
    100104  | AST.Op_divu -> "/u"
    101105  | AST.Op_mod -> "mod"
     
    104108  | AST.Op_or -> "or"
    105109  | AST.Op_xor -> "xor"
    106   | AST.Op_shl -> "shl"
    107   | AST.Op_shr -> "shr"
    108   | AST.Op_shru -> "shru"
     110  | AST.Op_shl -> "<<"
     111  | AST.Op_shr -> ">>"
     112  | AST.Op_shru -> ">>u"
    109113  | AST.Op_cmp cmp -> print_cmp cmp
    110   | AST.Op_addp -> "addp"
    111   | AST.Op_subp -> "subp"
    112   | AST.Op_subpp -> "subpp"
     114  | AST.Op_addp -> "+p"
     115  | AST.Op_subp -> "-p"
     116  | AST.Op_subpp -> "-pp"
    113117  | AST.Op_cmpp cmp -> (print_cmp cmp) ^ "p"
    114   | AST.Op_cmpu cmp -> (print_cmp cmp) ^ "u"
     118  | AST.Op_cmpu cmp -> (print_cmp cmp) ^ "u")
     119        (print_reg s)
    115120
    116121
     
    143148    Printf.sprintf "increment %d --> %s" i lbl
    144149  | RTLabs.St_cst (destr, cst, lbl) ->
    145       Printf.sprintf "imm %s, %s --> %s"
     150      Printf.sprintf "%s := %s --> %s"
    146151        (print_reg destr)
    147152        (print_cst cst)
    148153        lbl
    149154  | RTLabs.St_op1 (op1, destr, srcr, lbl) ->
    150       Printf.sprintf "%s %s, %s --> %s"
    151         (print_op1 op1)
     155      Printf.sprintf "%s := %s --> %s"
    152156        (print_reg destr)
    153         (print_reg srcr)
     157  (print_op1 op1 srcr)
    154158        lbl
    155159  | RTLabs.St_op2 (op2, destr, srcr1, srcr2, lbl) ->
    156       Printf.sprintf "%s %s, %s, %s --> %s"
    157         (print_op2 op2)
     160      Printf.sprintf "%s := %s --> %s"
    158161        (print_reg destr)
    159         (print_reg srcr1)
    160         (print_reg srcr2)
     162  (print_op2 op2 srcr1 srcr2)
    161163        lbl
    162164  | RTLabs.St_load (q, addr, destr, lbl) ->
    163       Printf.sprintf "load %s, %s, %s --> %s"
     165      Printf.sprintf "%s := *(%s) %s --> %s"
     166  (print_reg destr)
    164167        (Memory.string_of_quantity q)
    165168        (print_reg addr)
    166         (print_reg destr)
    167169        lbl
    168170  | RTLabs.St_store (q, addr, srcr, lbl) ->
    169       Printf.sprintf "store %s, %s, %s --> %s"
    170         (Memory.string_of_quantity q)
     171      Printf.sprintf "*(%s)%s := %s --> %s"
     172  (Memory.string_of_quantity q)
    171173        (print_reg addr)
    172174        (print_reg srcr)
    173175        lbl
    174   | RTLabs.St_call_id (f, args, res, sg, lbl) ->
    175       Printf.sprintf "call \"%s\", %s, %s: %s --> %s"
    176         f
     176  | RTLabs.St_call_id (f, args, Some r, sg, lbl) ->
     177      Printf.sprintf "%s := \"%s\"(%s) : %s --> %s"
     178  (print_reg r)
     179  f
    177180        (print_args args)
    178         (print_oreg res)
    179181        (Primitive.print_sig sg)
    180182        lbl
    181   | RTLabs.St_call_ptr (f, args, res, sg, lbl) ->
    182       Printf.sprintf "call_ptr %s, %s, %s: %s --> %s"
    183         (print_reg f)
    184         (print_args args)
    185         (print_oreg res)
    186         (Primitive.print_sig sg)
    187         lbl
     183  | RTLabs.St_call_id (f, args, None, sg, lbl) ->
     184    Printf.sprintf "\"%s\"(%s) : %s --> %s"
     185    f
     186    (print_args args)
     187    (Primitive.print_sig sg)
     188    lbl
     189  | RTLabs.St_call_ptr (f, args, Some r, sg, lbl) ->
     190      Printf.sprintf "%s := *%s (%s) : %s --> %s"
     191  (print_reg r)
     192    (print_reg f)
     193    (print_args args)
     194    (Primitive.print_sig sg)
     195    lbl
     196  | RTLabs.St_call_ptr (f, args, None, sg, lbl) ->
     197    Printf.sprintf "*%s (%s) : %s --> %s"
     198    (print_reg f)
     199    (print_args args)
     200    (Primitive.print_sig sg)
     201    lbl
    188202  | RTLabs.St_tailcall_id (f, args, sg) ->
    189       Printf.sprintf "tailcall \"%s\", %s: %s"
     203      Printf.sprintf "tailcall \"%s\" (%s) : %s"
    190204        f
    191205        (print_args args)
    192206        (Primitive.print_sig sg)
    193207  | RTLabs.St_tailcall_ptr (f, args, sg) ->
    194       Printf.sprintf "tailcall_ptr \"%s\", %s: %s"
     208      Printf.sprintf "tailcall *%s (%s) : %s"
    195209        (print_reg f)
    196210        (print_args args)
     
    230244
    231245
    232 let print_graph n c =
     246let print_graph n c entry =
    233247  let f lbl stmt s =
    234248    Printf.sprintf "%s%s: %s\n%s"
     
    237251      (print_statement stmt)
    238252      s in
    239   Label.Map.fold f c ""
    240 
    241 
     253        let f' lbl stmt (reach, s) =
     254    (Label.Set.add lbl reach, f lbl stmt s) in
     255        let (reachable, str) =
     256                RTLabsUtilities.dfs_fold f' c entry (Label.Set.empty, "") in
     257        let filter lbl _ = not (Label.Set.mem lbl reachable) in
     258        let c_rest = Label.Map.filter filter c in
     259        if Label.Map.is_empty c_rest then str else
     260        let str' = Label.Map.fold f c_rest "" in
     261        str ^ "DEAD NODES:\n" ^ str'
     262       
    242263let print_internal_decl n f def =
    243264
     
    257278    (n_spaces (n+2))
    258279    def.RTLabs.f_exit
    259     (print_graph (n+2) def.RTLabs.f_graph)
     280    (print_graph (n+2) def.RTLabs.f_graph def.RTLabs.f_entry)
    260281
    261282
Note: See TracChangeset for help on using the changeset viewer.