Ignore:
Timestamp:
Nov 25, 2011, 7:43:39 PM (8 years ago)
Author:
tranquil
Message:
  • Immediates introduced (but not fully used yet in RTLabs to RTL pass)
  • translation streamlined
  • BUGGY: interpretation fails in LTL, trying to fetch a function with incorrect address
Location:
Deliverables/D2.2/8051/src/RTL
Files:
4 edited

Legend:

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

    r1542 r1568  
    99type registers = Register.t list
    1010
     11(* arguments to certain operations: either registers or immediate args *)
     12type argument =
     13  | Reg of Register.t
     14  | Imm of int
     15
    1116type statement =
    1217
     
    1722  | St_cost of CostLabel.t * Label.t
    1823
    19   (* Reset to 0 a loop index *) 
     24  (* Reset to 0 a loop index *)
    2025  | St_ind_0 of CostLabel.index * Label.t
    2126
     
    3237  | St_stackaddr of Register.t * Register.t * Label.t
    3338
    34   (* Assign an integer constant to a register. Parameters are the destination
    35      register, the integer and the label of the next statement. *)
    36   | St_int of Register.t * int * Label.t
     39  (* (\* Assign an integer constant to a register. Parameters are the destination *)
     40  (*    register, the integer and the label of the next statement. *\) *)
     41  (* | St_int of Register.t * int * Label.t *)
    3742
    3843  (* Move the content of a register to another. Parameters are the destination
    39      register, the source register, and the label of the next statement. *)
    40   | St_move of Register.t * Register.t * Label.t
     44     register, the source argument, and the label of the next statement. *)
     45  | St_move of Register.t * argument * Label.t
    4146
    4247  (* Apply a binary operation that will later be translated in an operation on
     
    5257
    5358  (* Apply a binary operation. Parameters are the operation, the destination
    54      register, the source registers, and the label of the next statement. *)
    55   | St_op2 of I8051.op2 * Register.t * Register.t * Register.t * Label.t
     59     register, the source arguments, and the label of the next statement. *)
     60  | St_op2 of I8051.op2 * Register.t * Register.t * argument * Label.t
    5661
    5762  (* Set the carry flag to zero. Parameter is the label of the next
  • Deliverables/D2.2/8051/src/RTL/RTLInterpret.ml

    r1542 r1568  
    8989  if Register.Map.mem r lenv then Register.Map.find r lenv
    9090  else error ("Unknown local register \"" ^ (Register.print r) ^ "\".")
     91
     92let get_local_arg_value (lenv : local_env) : RTL.argument -> Val.t = function
     93  | RTL.Reg r -> get_local_value lenv r
     94  | RTL.Imm i -> Val.of_int i
     95
    9196let get_arg_values lenv args = List.map (get_local_value lenv) args
    9297
     
    159164        assign_state sfrs graph lbl sp lenv carry mem inds trace [r1 ; r2] sp
    160165
    161       | RTL.St_int (r, i, lbl) ->
    162         assign_state sfrs graph lbl sp lenv carry mem inds trace [r] [Val.of_int i]
     166      (* | RTL.St_int (r, i, lbl) -> *)
     167      (*   assign_state sfrs graph lbl sp lenv carry mem inds trace [r] [Val.of_int i] *)
    163168
    164169      | RTL.St_move (destr, srcr, lbl) ->
    165170        assign_state sfrs graph lbl sp lenv carry mem inds trace [destr]
    166           [get_local_value lenv srcr]
     171          [get_local_arg_value lenv srcr]
    167172
    168173      | RTL.St_opaccs (opaccs, destr1, destr2, srcr1, srcr2, lbl) ->
     
    182187          Eval.op2 carry op2
    183188            (get_local_value lenv srcr1)
    184             (get_local_value lenv srcr2) in
     189            (get_local_arg_value lenv srcr2) in
    185190        assign_state sfrs graph lbl sp lenv carry mem inds trace [destr] [v]
    186191
  • Deliverables/D2.2/8051/src/RTL/RTLPrinter.ml

    r1542 r1568  
    1616
    1717let print_reg = Register.print
     18
     19let print_arg = function
     20  | RTL.Reg r -> print_reg r
     21  | RTL.Imm i -> string_of_int i
    1822
    1923let reg_set_to_list rs =
     
    4448  | RTL.St_cost (cost_lbl, lbl) ->
    4549    let cost_lbl = CostLabel.string_of_cost_label ~pretty:true cost_lbl in
    46     Printf.sprintf "emit %s --> %s" cost_lbl lbl
     50    Printf.sprintf "_emit %s --> %s" cost_lbl lbl
    4751  | RTL.St_ind_0 (i, lbl) ->
    48     Printf.sprintf "index %d --> %s" i lbl
     52    Printf.sprintf "_index %d --> %s" i lbl
    4953  | RTL.St_ind_inc (i, lbl) ->
    50     Printf.sprintf "increment %d --> %s" i lbl
     54    Printf.sprintf "_increment %d --> %s" i lbl
    5155  | RTL.St_addr (dstr1, dstr2, id, lbl) ->
    52     Printf.sprintf "imm (%s, %s), %s --> %s"
     56    Printf.sprintf "move (%s, %s), %s --> %s"
    5357      (print_reg dstr1) (print_reg dstr2) id lbl
    5458  | RTL.St_stackaddr (dstr1, dstr2, lbl) ->
    55     Printf.sprintf "imm (%s, %s), STACK --> %s"
     59    Printf.sprintf "move (%s, %s), STACK --> %s"
    5660      (print_reg dstr1) (print_reg dstr2) lbl
    57   | RTL.St_int (dstr, i, lbl) ->
    58     Printf.sprintf "imm %s, %d --> %s" (print_reg dstr) i lbl
     61  (* | RTL.St_int (dstr, i, lbl) -> *)
     62  (*   Printf.sprintf "imm %s, %d --> %s" (print_reg dstr) i lbl *)
    5963  | RTL.St_move (dstr, srcr, lbl) ->
    6064    Printf.sprintf "move %s, %s --> %s"
    61       (print_reg dstr) (print_reg srcr) lbl
     65      (print_reg dstr) (print_arg srcr) lbl
    6266  | RTL.St_opaccs (opaccs, dstr1, dstr2, srcr1, srcr2, lbl) ->
    6367    Printf.sprintf "%s (%s, %s) %s, %s --> %s"
     
    7680      (print_reg dstr)
    7781      (print_reg srcr1)
    78       (print_reg srcr2)
     82      (print_arg srcr2)
    7983      lbl
    8084  | RTL.St_clear_carry lbl ->
  • Deliverables/D2.2/8051/src/RTL/RTLToERTL.ml

    r1542 r1568  
    3434  | ERTL.St_addrH (r, id, _) -> ERTL.St_addrH (r, id, lbl)
    3535  | ERTL.St_addrL (r, id, _) -> ERTL.St_addrL (r, id, lbl)
    36   | ERTL.St_int (r, i, _) -> ERTL.St_int (r, i, lbl)
    37   | ERTL.St_move (r1, r2, _) -> ERTL.St_move (r1, r2, lbl)
     36  | ERTL.St_move (r1, a, _) -> ERTL.St_move (r1, a, lbl)
    3837  | ERTL.St_opaccsA (opaccs, dstr, srcr1, srcr2, _) ->
    3938    ERTL.St_opaccsA (opaccs, dstr, srcr1, srcr2, lbl)
     
    102101let restore_hdws l =
    103102  let f (destr, srcr) start_lbl =
    104     adds_graph [ERTL.St_set_hdw (destr, srcr, start_lbl)] start_lbl in
     103    adds_graph [ERTL.St_set_hdw (destr, RTL.Reg srcr, start_lbl)] start_lbl in
    105104  List.map f (List.map (fun (x, y) -> (y, x)) l)
    106105
     
    118117  adds_graph
    119118    [ERTL.St_framesize (addr1, start_lbl) ;
    120      ERTL.St_int (tmpr, off+I8051.int_size, start_lbl) ;
    121      ERTL.St_op2 (I8051.Sub, addr1, addr1, tmpr, start_lbl) ;
     119     ERTL.St_op2 (I8051.Sub, addr1, addr1, RTL.Imm (off+I8051.int_size),
     120                 start_lbl) ;
    122121     ERTL.St_get_hdw (tmpr, I8051.spl, start_lbl) ;
    123      ERTL.St_op2 (I8051.Add, addr1, addr1, tmpr, start_lbl) ;
    124      ERTL.St_int (addr2, 0, start_lbl) ;
     122     ERTL.St_op2 (I8051.Add, addr1, addr1, RTL.Reg tmpr, start_lbl) ;
    125123     ERTL.St_get_hdw (tmpr, I8051.sph, start_lbl) ;
    126      ERTL.St_op2 (I8051.Addc, addr2, addr2, tmpr, start_lbl) ;
     124     ERTL.St_op2 (I8051.Addc, addr2, tmpr, RTL.Imm 0, start_lbl) ;
    127125     ERTL.St_load (destr, addr1, addr2, start_lbl)]
    128126    start_lbl dest_lbl def
     
    176174
    177175let save_return ret_regs start_lbl dest_lbl def =
    178   let (def, tmpr) = fresh_reg def in
    179176  let ((common1, rest1), (common2, _)) =
    180177    MiscPottier.reduce I8051.sts ret_regs in
    181   let init_tmpr = ERTL.St_int (tmpr, 0, start_lbl) in
    182   let f_save st r = ERTL.St_set_hdw (st, r, start_lbl) in
     178  let f_save st r = ERTL.St_set_hdw (st, RTL.Reg r, start_lbl) in
    183179  let saves = List.map2 f_save common1 common2 in
    184   let f_default st = ERTL.St_set_hdw (st, tmpr, start_lbl) in
     180  let f_default st = ERTL.St_set_hdw (st, RTL.Imm 0, start_lbl) in
    185181  let defaults = List.map f_default rest1 in
    186   adds_graph (init_tmpr :: saves @ defaults) start_lbl dest_lbl def
     182  adds_graph (saves @ defaults) start_lbl dest_lbl def
    187183
    188184let assign_result start_lbl =
     
    252248  let (def, tmpr) = fresh_reg def in
    253249  adds_graph
    254     [ERTL.St_int (addr1, off+I8051.int_size, start_lbl) ;
    255      ERTL.St_get_hdw (tmpr, I8051.spl, start_lbl) ;
     250    [ERTL.St_get_hdw (tmpr, I8051.spl, start_lbl) ;
    256251     ERTL.St_clear_carry start_lbl ;
    257      ERTL.St_op2 (I8051.Sub, addr1, tmpr, addr1, start_lbl) ;
     252     ERTL.St_op2 (I8051.Sub, addr1, tmpr, RTL.Imm (off+I8051.int_size),
     253                  start_lbl) ;
    258254     ERTL.St_get_hdw (tmpr, I8051.sph, start_lbl) ;
    259      ERTL.St_int (addr2, 0, start_lbl) ;
    260      ERTL.St_op2 (I8051.Sub, addr2, tmpr, addr2, start_lbl) ;
     255     ERTL.St_op2 (I8051.Sub, addr2, tmpr, RTL.Imm 0, start_lbl) ;
    261256     ERTL.St_store (addr1, addr2, srcr, start_lbl)]
    262257    start_lbl dest_lbl def
     
    338333      lbl lbl' def
    339334
    340   | RTL.St_int (r, i, lbl') ->
    341     add_graph lbl (ERTL.St_int (r, i, lbl')) def
     335  (* | RTL.St_int (r, i, lbl') -> *)
     336  (*   add_graph lbl (ERTL.St_int (r, i, lbl')) def *)
    342337
    343338  | RTL.St_move (r1, r2, lbl') ->
     
    444439    | ERTL.St_set_hdw (_, _, lbl) | ERTL.St_hdw_to_hdw (_, _, lbl)
    445440    | ERTL.St_pop (_, lbl) | ERTL.St_push (_, lbl) | ERTL.St_addrH (_, _, lbl)
    446     | ERTL.St_addrL (_, _, lbl) | ERTL.St_int (_, _, lbl)
     441    | ERTL.St_addrL (_, _, lbl) (* | ERTL.St_int (_, _, lbl) *)
    447442    | ERTL.St_move (_, _, lbl) | ERTL.St_opaccsA (_, _, _, _, lbl)
    448443    | ERTL.St_opaccsB (_, _, _, _, lbl)
Note: See TracChangeset for help on using the changeset viewer.