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

Location:
Deliverables/D2.2/8051/src/LTL
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.2/8051/src/LTL/LTL.mli

    r486 r818  
    6060  | St_clear_carry of Label.t
    6161
     62  (* Set the carry flag to 1. Parameter is the label of the next statement. *)
     63  | St_set_carry of Label.t
     64
    6265  (* Load from external memory (address in DPTR) to the accumulator. Parameter
    6366     is the label of the next statement. *)
  • Deliverables/D2.2/8051/src/LTL/LTLInterpret.ml

    r740 r818  
    177177
    178178let interpret_external mem f args = match InterpretExternal.t mem f args with
    179   | (mem', InterpretExternal.V v) -> (mem', [v])
     179  | (mem', InterpretExternal.V vs) -> (mem', vs)
    180180  | (mem', InterpretExternal.A addr) -> (mem', addr)
    181181
    182 let fetch_external_args st =
    183   (* TODO: this is bad when parameters are the empty list. *)
    184   [get_reg (List.hd I8051.parameters) st]
    185 
    186 let set_result st = function
    187   | [] -> assert false (* should be impossible: at least one value returned *)
    188   | [v] -> add_reg I8051.dpl v st
    189   | v1 :: v2 :: _ ->
    190     let st = add_reg I8051.dpl v1 st in
    191     add_reg I8051.dph v2 st
     182let fetch_external_args f st =
     183  let size = Mem.size_of_quantity (Primitive.args_byte_size f) in
     184  let params = MiscPottier.prefix size I8051.parameters in
     185  List.map (fun r -> get_reg r st) params
     186
     187let set_result st vs =
     188  let f st (r, v) = add_reg r v st in
     189  List.fold_left f st (MiscPottier.combine I8051.rets vs)
    192190
    193191let interpret_external_call st f next_pc =
    194   let args = fetch_external_args st in
     192  let args = fetch_external_args f st in
    195193  let (mem, vs) = interpret_external st.mem f args in
    196194  let st = change_mem st mem in
     
    262260
    263261    | LTL.St_opaccs (opaccs, lbl) ->
    264       let v =
     262      let (a, b) =
    265263        Eval.opaccs opaccs
    266264          (get_reg I8051.a st)
    267265          (get_reg I8051.b st) in
    268       let st = add_reg I8051.a v st in
     266      let st = add_reg I8051.a a st in
     267      let st = add_reg I8051.b b st in
    269268      next_pc st lbl
    270269
     
    287286      next_pc st lbl
    288287
     288    | LTL.St_set_carry lbl ->
     289      let st = change_carry st (Val.of_int 1) in
     290      next_pc st lbl
     291
    289292    | LTL.St_load lbl ->
    290293      let addr = dptr st in
     
    316319
    317320let compute_result st =
    318   let v = get_reg I8051.dpl st in
    319   if Val.is_int v then IntValue.Int8.cast (Val.to_int_repr v)
    320   else IntValue.Int8.zero
     321  let vs = List.map (fun r -> get_reg r st) I8051.rets in
     322  let f res v = res && (Val.is_int v) in
     323  let is_int vs = (List.length vs > 0) && (List.fold_left f true vs) in
     324  if is_int vs then
     325    let chunks =
     326      List.map (fun v -> IntValue.Int32.cast (Val.to_int_repr v)) vs in
     327    IntValue.Int32.merge chunks
     328  else IntValue.Int32.zero
    321329
    322330let rec iter_small_step debug lbls_offs st =
     331  let print_and_return_result (res, cost_labels) =
     332    if debug then Printf.printf "Result = %s\n%!"
     333      (IntValue.Int32.to_string res) ;
     334    (res, cost_labels) in
    323335  if debug then print_state lbls_offs st ;
    324336  match fetch_stmt lbls_offs st with
    325337    | LTL.St_return when Val.eq_address (snd (return_pc st)) st.exit ->
    326       (compute_result st, List.rev st.trace)
     338      print_and_return_result (compute_result st, List.rev st.trace)
    327339    | stmt ->
    328340      let st' = interpret_stmt lbls_offs st stmt in
     
    332344let add_global_vars =
    333345  List.fold_left
    334     (fun mem (id, size) -> Mem.add_var mem id [AST.Data_reserve size])
     346    (fun mem (id, size) -> Mem.add_var mem id (AST.SQ (AST.QInt size)) None)
    335347
    336348let add_fun_defs =
     
    390402
    391403let interpret debug p =
    392   if debug then Printf.printf "*** LTL ***\n\n%!" ;
     404  Printf.printf "*** LTL interpret ***\n%!" ;
    393405  match p.LTL.main with
    394406    | None -> (IntValue.Int8.zero, [])
  • Deliverables/D2.2/8051/src/LTL/LTLPrinter.ml

    r486 r818  
    4848  | LTL.St_clear_carry lbl ->
    4949    Printf.sprintf "clear CARRY --> %s" lbl
     50  | LTL.St_set_carry lbl ->
     51    Printf.sprintf "set CARRY --> %s" lbl
    5052  | LTL.St_load lbl ->
    5153    Printf.sprintf "movex %s, @DPTR --> %s" print_a lbl
  • Deliverables/D2.2/8051/src/LTL/LTLToLIN.ml

    r486 r818  
    3232  | LTL.St_clear_carry _ ->
    3333    LIN.St_clear_carry
     34  | LTL.St_set_carry _ ->
     35    LIN.St_set_carry
    3436  | LTL.St_from_acc (r, _) ->
    3537    LIN.St_from_acc (r)
  • Deliverables/D2.2/8051/src/LTL/LTLToLINI.ml

    r486 r818  
    127127        | LTL.St_op2 (_, _, l)
    128128        | LTL.St_clear_carry l
     129        | LTL.St_set_carry l
    129130        | LTL.St_load l
    130131        | LTL.St_store l
  • Deliverables/D2.2/8051/src/LTL/branch.ml

    r486 r818  
    6262    | LTL.St_clear_carry l ->
    6363      LTL.St_clear_carry (rep l)
     64    | LTL.St_set_carry l ->
     65      LTL.St_set_carry (rep l)
    6466    | LTL.St_from_acc (r, l) ->
    6567      LTL.St_from_acc (r, rep l)
Note: See TracChangeset for help on using the changeset viewer.