Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jan 17th, 2012  |  syntax: OCaml  |  size: 1.44 KB  |  hits: 135  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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) ->
  5.                     let cfg = cfg_of_imp' com1 cont in
  6.                     let cont' = ultimo_cont cfg in
  7.                     let cfg' = cfg_of_imp' com2 (cont'+1) in
  8.                     (match com1 with
  9.                         While (_, _) -> union_cfg (imposta_archi ([string_of_int cont, string_of_int (cont'+1)]) cfg)  cfg'                                    
  10.                       | _ -> union_cfg cfg (imposta_archi ([string_of_int cont', string_of_int (cont'+1)])
  11.                                                  cfg'))
  12.                 | Skip -> ([(string_of_int cont, BSkip)], [])
  13.                 | AssignVar (ide, n) -> ([string_of_int cont, BAssignVar (ide, n)], [])
  14.                 | AssignArray (ide, i, n) -> ([string_of_int cont, BAssignArray (ide, i, n)], [])
  15.                 | If (exp, com1, com2) -> let cfg_com1 = cfg_of_imp' com1 (cont+1) in
  16.                                           let cont' = ultimo_cont cfg_com1 in
  17.                                           let cfg_com2 = cfg_of_imp' com2 cont' in
  18.                                           union_cfg (imposta_archi ([string_of_int cont, string_of_int (cont')])
  19.                                                     ([string_of_int cont, BGuard exp], [string_of_int cont, string_of_int (cont + 1)]))
  20.                                                     (union_cfg cfg_com1 cfg_com2)
  21.                 | While (exp, com) -> let cfg = cfg_of_imp' com (cont+1) in
  22.                                       let cont' = ultimo_cont cfg in
  23.                                       imposta_archi ([string_of_int cont', string_of_int cont]) (union_cfg ([string_of_int cont, BGuard exp], [string_of_int cont, string_of_int (cont+1)]) cfg)
  24.       in cfg_of_imp' com 0                                     
  25. ;;