Guest User

Untitled

a guest
May 26th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 1.47 KB | None | 0 0
  1. let cfg_of_imp = fun imp_prog -> match imp_prog with
  2.     ImpProg (dec, com) ->
  3.       let rec cfg_of_imp' = fun com cont -> match com with
  4.               Cseq (com1, com2) -> let cfg = cfg_of_imp' com1  cont in
  5.                        let cont' = ultimo_cont cfg in
  6.                        let cfg' = cfg_of_imp' com2 cont' in
  7.                        (match com1 with
  8.                        While (exp, com) -> union_cfg cfg cfg'                  
  9.                      | _ -> union_cfg cfg (imposta_archi ([string_of_int cont', string_of_int (cont'+1)])
  10.                          (cfg_of_imp' com2 (cont'+1))))
  11.             | Skip -> ([(string_of_int cont, BSkip)], [])
  12.                 | AssignVar (ide, n) -> ([string_of_int cont, BAssignVar (ide, n)], [])
  13.         | AssignArray (ide, i, n) -> ([string_of_int cont, BAssignArray (ide, i, n)], [])
  14.         | If (exp, com1, com2) -> let cfg_com1 = cfg_of_imp' com1 (cont+1) in
  15.                       let cont' = ultimo_cont cfg_com1 in
  16.                       let cfg_com2 = cfg_of_imp' com2 cont' in
  17.                       union_cfg (imposta_archi ([string_of_int cont, string_of_int (cont')])
  18.                                 ([string_of_int cont, BGuard exp], [string_of_int cont, string_of_int (cont + 1)]))
  19.                                 (union_cfg cfg_com1 cfg_com2)
  20.         | While (exp, com) -> let cfg = cfg_of_imp' com (cont+1) in
  21.                       let cont' = ultimo_cont cfg in
  22.                       imposta_archi ([string_of_int cont', string_of_int cont; string_of_int cont, string_of_int (cont' + 1)]) (union_cfg ([string_of_int cont, BGuard exp], [string_of_int cont, string_of_int (cont+1)]) cfg)
  23.       in cfg_of_imp' com 0                 
  24. ;;
Add Comment
Please, Sign In to add comment