Ignore:
Timestamp:
Oct 17, 2011, 2:08:27 PM (8 years ago)
Author:
tranquil
Message:

fiddling with Cminor: elimination of loops, blocks and exits

File:
1 edited

Legend:

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

    r1357 r1392  
    2828    Ct_stop
    2929  | Ct_cont of statement*continuation
    30         | Ct_ind_inc of CostLabel.index*continuation
    31   | Ct_endblock of continuation
     30(*  | Ct_endblock of continuation *)
    3231  | Ct_returnto of
    3332      ident option*internal_function*Val.address*local_env*continuation
     
    6261  | St_seq _ -> "sequence"
    6362  | St_ifthenelse (e, _, _) -> "if (" ^ (string_of_expr e) ^ ")"
    64   | St_loop _ -> "loop"
     63(*  | St_loop _ -> "loop"
    6564  | St_block _ -> "block"
    66   | St_exit n -> "exit " ^ (string_of_int n)
     65  | St_exit n -> "exit " ^ (string_of_int n) *)
    6766  | St_switch (e, _, _) -> "switch (" ^ (string_of_expr e) ^ ")"
    6867  | St_return None -> "return"
     
    7473                "cost " ^ lbl
    7574        | St_ind_0 (i, _) -> "reset " ^ string_of_int i ^ " to 0"
    76         | St_ind_inc (_, i) -> "post-increment " ^ string_of_int i
     75        | St_ind_inc (i, _) -> "post-increment " ^ string_of_int i
    7776
    7877let print_state = function
     
    233232
    234233let rec callcont = function
    235   | Ct_cont(_,k) | Ct_endblock k | Ct_ind_inc(_,k) -> callcont k
     234  | Ct_cont(_,k) (*| Ct_endblock k *) -> callcont k
    236235        | (Ct_stop | Ct_returnto _) as k -> k
    237236
     
    245244  | St_seq(s1,s2)               ->
    246245      (match fdlbl (Ct_cont(s2,k)) s1 with
    247            None -> fdlbl k s2
    248         | Some(v) -> Some(v)
     246       None -> fdlbl k s2
     247    | Some(v) -> Some(v)
    249248      )
    250249  | St_ifthenelse(_,s1,s2)      ->
    251250      (match fdlbl k s1 with
    252            None -> fdlbl k s2
    253         | Some(v) -> Some(v)
     251       None -> fdlbl k s2
     252    | Some(v) -> Some(v)
    254253      )
    255   | St_loop(s)                  -> fdlbl (Ct_cont(St_loop(s),k)) s
     254(*  | St_loop(s)                  -> fdlbl (Ct_cont(St_loop(s),k)) s
    256255  | St_block(s)                 -> fdlbl (Ct_endblock(k)) s
    257   | St_exit(_)                  -> None
     256  | St_exit(_)                  -> None *)
    258257  | St_switch(_,_,_)            -> None
    259258  | St_return(_)                -> None
    260   | St_label(l,s)               -> if l=lbl then Some((s,k)) else None
     259  | St_label(l,s) when l = lbl  -> Some((s,k))
    261260  | St_goto(_)                  -> None
    262   | St_cost (_,s) | St_ind_0(_,s) | St_ind_inc(s,_) -> fdlbl k s
     261  | St_cost(_,s)  | St_label(_,s)
     262        | St_ind_0(_,s) | St_ind_inc(_,s) -> fdlbl k s
    263263  in match fdlbl k st with
    264264      None -> assert false (*Wrong label*)
     
    274274let eval_stmt f k sigma e m i s = match s, k with
    275275  | St_skip,Ct_cont(s,k) -> (State_regular(f, s, k, sigma, e, m, i),[])
    276   | St_skip,Ct_endblock(k) -> (State_regular(f, St_skip, k, sigma, e, m, i),[])
     276(*  | St_skip,Ct_endblock(k) -> (State_regular(f, St_skip, k, sigma, e, m, i),[]) *)
    277277  | St_skip, (Ct_returnto _ as k) ->
    278278    (State_return (Val.undef,k,Mem.free m sigma,i),[])
    279   | St_skip,Ct_ind_inc(ind,k) ->
    280                 CostLabel.continue_loop i ind;
    281                 (State_regular(f, s, k, sigma, e, m, i),[])
    282279  | St_skip,Ct_stop ->
    283280    (State_return (Val.undef,Ct_stop,Mem.free m sigma,i),[])
     
    304301        else error "undefined conditional value." in
    305302      (State_regular(f,next_stmt,k,sigma,e,m,i),l)
    306   | St_loop(s),_ -> (State_regular(f,s,Ct_cont((St_loop s),k),sigma,e,m,i),[])
     303(*  | St_loop(s),_ -> (State_regular(f,s,Ct_cont((St_loop s),k),sigma,e,m,i),[])
    307304  | St_block(s),_ -> (State_regular(f,s,(Ct_endblock k),sigma,e,m,i),[])
    308305  | St_exit(n),Ct_cont(s,k) -> (State_regular(f,(St_exit n),k,sigma,e,m,i),[])
    309306  | St_exit(0),Ct_endblock(k) -> (State_regular(f,St_skip,k,sigma,e,m,i),[])
    310307  | St_exit(n),Ct_endblock(k) ->
    311     (State_regular(f,(St_exit (n-1)),k,sigma,e,m,i),[])
     308    (State_regular(f,(St_exit (n-1)),k,sigma,e,m,i),[]) *)
    312309  | St_label(_,s),_ -> (State_regular(f,s,k,sigma,e,m,i),[])
    313   | St_goto(lbl),_ -> 
     310  | St_goto(lbl),_ ->
    314311    let (s2,k2) = findlabel lbl f.f_body (callcont k) in
    315312    (State_regular(f,s2,k2,sigma,e,m,i),[])
     
    318315    if Val.is_int v then
    319316      try
    320         let v = Val.to_int v in
    321         let nb_exit =
    322           if List.mem_assoc v lst then List.assoc v lst
    323           else def in
    324         (State_regular(f, St_exit nb_exit,k, sigma, e, m, i),l)
     317                                let v = Val.to_int v in
     318                                let lbl =
     319                                        try
     320                                                List.assoc v lst
     321                                        with
     322                                                | Not_found -> def in
     323        let (s',k') = findlabel lbl f.f_body (callcont k) in
     324              (State_regular(f, s', k', sigma, e, m, i),l)
    325325      with _ -> error "int value too big."
    326326    else error "undefined switch value."
     
    337337                CostLabel.enter_loop i ind;
    338338                (State_regular(f,s,k,sigma,e,m,i), [])
    339         | St_ind_inc(s,ind),_ ->
    340     (State_regular(f,s,Ct_ind_inc(ind,k),sigma,e,m,i), [])
    341   | _ -> error "state malformation."
     339        | St_ind_inc(ind,s),_ ->
     340                CostLabel.continue_loop i ind;
     341    (State_regular(f,s,k,sigma,e,m,i), [])
     342(*  | _ -> error "state malformation." *)
    342343
    343344
Note: See TracChangeset for help on using the changeset viewer.