Ignore:
Timestamp:
May 19, 2011, 4:03:04 PM (9 years ago)
Author:
ayache
Message:

32 and 16 bits operations support in D2.2/8051

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.2/8051/src/RTL/RTLInterpret.ml

    r740 r818  
    144144          [get_local_value lenv srcr]
    145145
    146       | RTL.St_opaccs (opaccs, destr, srcr1, srcr2, lbl) ->
    147         let v =
     146      | RTL.St_opaccs (opaccs, destr1, destr2, srcr1, srcr2, lbl) ->
     147        let (v1, v2) =
    148148          Eval.opaccs opaccs
    149149            (get_local_value lenv srcr1)
    150150            (get_local_value lenv srcr2) in
    151         assign_state sfrs graph lbl sp lenv carry mem trace [destr] [v]
     151        assign_state sfrs graph lbl sp lenv carry mem trace
     152          [destr1 ; destr2] [v1 ; v2]
    152153
    153154      | RTL.St_op1 (op1, destr, srcr, lbl) ->
     
    164165      | RTL.St_clear_carry lbl ->
    165166        State (sfrs, graph, lbl, sp, lenv, Val.zero, mem, trace)
     167
     168      | RTL.St_set_carry lbl ->
     169        State (sfrs, graph, lbl, sp, lenv, Val.of_int 1, mem, trace)
    166170
    167171      | RTL.St_load (destr, addr1, addr2, lbl) ->
     
    205209        CallState (sfrs, f_def, args, mem, trace)
    206210
    207       | RTL.St_condacc (srcr, lbl_true, lbl_false) ->
     211      | RTL.St_cond (srcr, lbl_true, lbl_false) ->
    208212        let v = get_local_value lenv srcr in
    209213        branch_state sfrs graph lbl_true lbl_false sp lenv carry mem trace v
     
    218222
    219223let interpret_external mem f args = match InterpretExternal.t mem f args with
    220   | (mem', InterpretExternal.V v) -> (mem', [v])
     224  | (mem', InterpretExternal.V vs) -> (mem', vs)
    221225  | (mem', InterpretExternal.A addr) -> (mem', addr)
    222226
     
    273277
    274278let compute_result vs =
    275   try
    276     let v = List.hd vs in
    277     if Val.is_int v then IntValue.Int8.cast (Val.to_int_repr v)
    278     else IntValue.Int8.zero
    279   with Not_found -> IntValue.Int8.zero
     279  let f res v = res && (Val.is_int v) in
     280  let is_int vs = (List.length vs > 0) && (List.fold_left f true vs) in
     281  if is_int vs then
     282    let chunks =
     283      List.map (fun v -> IntValue.Int32.cast (Val.to_int_repr v)) vs in
     284    IntValue.Int32.merge chunks
     285  else IntValue.Int32.zero
    280286
    281287let rec iter_small_step debug st =
     288  let print_and_return_result (res, cost_labels) =
     289    if debug then Printf.printf "Result = %s\n%!"
     290      (IntValue.Int32.to_string res) ;
     291    (res, cost_labels) in
    282292  if debug then print_state st ;
    283293  match small_step st with
    284     | ReturnState ([], vs, mem, trace) -> (compute_result vs, List.rev trace)
     294    | ReturnState ([], vs, mem, trace) ->
     295      print_and_return_result (compute_result vs, List.rev trace)
    285296    | st' -> iter_small_step debug st'
    286297
     
    288299let add_global_vars =
    289300  List.fold_left
    290     (fun mem (id, size) -> Mem.add_var mem id [AST.Data_reserve size])
     301    (fun mem (id, size) -> Mem.add_var mem id (AST.SQ (AST.QInt size)) None)
    291302
    292303let add_fun_defs =
     
    304315
    305316let interpret debug p =
    306   if debug then Printf.printf "*** RTL ***\n\n%!" ;
     317  Printf.printf "*** RTL interpret ***\n%!" ;
    307318  match p.RTL.main with
    308     | None -> (IntValue.Int8.zero, [])
     319    | None -> (IntValue.Int32.zero, [])
    309320    | Some main ->
    310321      let mem = init_mem p in
Note: See TracChangeset for help on using the changeset viewer.