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/RTLToERTL.ml

    r740 r818  
    3434  | ERTL.St_int (r, i, _) -> ERTL.St_int (r, i, lbl)
    3535  | ERTL.St_move (r1, r2, _) -> ERTL.St_move (r1, r2, lbl)
    36   | ERTL.St_opaccs (opaccs, dstr, srcr1, srcr2, _) ->
    37     ERTL.St_opaccs (opaccs, dstr, srcr1, srcr2, lbl)
     36  | ERTL.St_opaccsA (opaccs, dstr, srcr1, srcr2, _) ->
     37    ERTL.St_opaccsA (opaccs, dstr, srcr1, srcr2, lbl)
     38  | ERTL.St_opaccsB (opaccs, dstr, srcr1, srcr2, _) ->
     39    ERTL.St_opaccsB (opaccs, dstr, srcr1, srcr2, lbl)
    3840  | ERTL.St_op1 (op1, dstr, srcr, _) -> ERTL.St_op1 (op1, dstr, srcr, lbl)
    3941  | ERTL.St_op2 (op2, dstr, srcr1, srcr2, _) ->
    4042    ERTL.St_op2 (op2, dstr, srcr1, srcr2, lbl)
    4143  | ERTL.St_clear_carry _ -> ERTL.St_clear_carry lbl
     44  | ERTL.St_set_carry _ -> ERTL.St_set_carry lbl
    4245  | ERTL.St_load (dstrs, addr1, addr2, _) ->
    4346    ERTL.St_load (dstrs, addr1, addr2, lbl)
     
    4548    ERTL.St_store (addr1, addr2, srcrs, lbl)
    4649  | ERTL.St_call_id (f, nb_args, _) -> ERTL.St_call_id (f, nb_args, lbl)
    47   | ERTL.St_condacc _ as inst -> inst
     50  | ERTL.St_cond _ as inst -> inst
    4851  | ERTL.St_return _ as inst -> inst
    4952
     
    5255
    5356let rec adds_graph stmt_list start_lbl dest_lbl def = match stmt_list with
    54   | [] -> def
     57  | [] -> add_graph start_lbl (ERTL.St_skip dest_lbl) def
    5558  | [stmt] ->
    5659    add_graph start_lbl (change_label dest_lbl stmt) def
     
    6669let rec add_translates translate_list start_lbl dest_lbl def =
    6770  match translate_list with
    68     | [] -> def
     71    | [] -> add_graph start_lbl (ERTL.St_skip dest_lbl) def
    6972    | [trans] -> trans start_lbl dest_lbl def
    7073    | trans :: translate_list ->
     
    168171   before jumping out of the function. *)
    169172
    170 let save_return ret_regs = match ret_regs with
    171   | [] -> [fun start_lbl -> adds_graph [ERTL.St_skip start_lbl] start_lbl]
    172   | [r] ->
    173     [fun start_lbl dest_lbl def ->
    174       let (def, r_tmp) = fresh_reg def in
    175       adds_graph [ERTL.St_int (r_tmp, 0, start_lbl) ;
    176                   ERTL.St_set_hdw (I8051.st0, r, start_lbl) ;
    177                   ERTL.St_set_hdw (I8051.st1, r_tmp, start_lbl)]
    178         start_lbl dest_lbl def]
    179   | r1 :: r2 :: _ ->
    180     [(fun start_lbl ->
    181       adds_graph [ERTL.St_set_hdw (I8051.st0, r1, start_lbl) ;
    182                   ERTL.St_set_hdw (I8051.st1, r2, start_lbl)] start_lbl)]
     173let save_return ret_regs start_lbl dest_lbl def =
     174  let (def, tmpr) = fresh_reg def in
     175  let ((common1, rest1), (common2, _)) =
     176    MiscPottier.reduce I8051.sts ret_regs in
     177  let init_tmpr = ERTL.St_int (tmpr, 0, start_lbl) in
     178  let f_save st r = ERTL.St_set_hdw (st, r, start_lbl) in
     179  let saves = List.map2 f_save common1 common2 in
     180  let f_default st = ERTL.St_set_hdw (st, tmpr, start_lbl) in
     181  let defaults = List.map f_default rest1 in
     182  adds_graph (init_tmpr :: saves @ defaults) start_lbl dest_lbl def
     183
     184let assign_result start_lbl =
     185  let ((common1, _), (common2, _)) = MiscPottier.reduce I8051.rets I8051.sts in
     186  let f ret st = ERTL.St_hdw_to_hdw (ret, st, start_lbl) in
     187  let insts = List.map2 f common1 common2 in
     188  adds_graph insts start_lbl
    183189
    184190let add_epilogue ret_regs sral srah sregs def =
     
    190196      ([adds_graph [ERTL.St_comment ("Epilogue", start_lbl)]] @
    191197       (* save return value *)
    192        (save_return ret_regs) @
     198       [save_return ret_regs] @
    193199       (* restore callee-saved registers *)
    194200       [adds_graph [ERTL.St_comment ("Restore callee-saved registers",
     
    204210       (* assign the result to actual return registers *)
    205211       [adds_graph [ERTL.St_comment ("Set result", start_lbl)]] @
    206        [adds_graph [ERTL.St_hdw_to_hdw (I8051.dpl, I8051.st0, start_lbl) ;
    207                     ERTL.St_hdw_to_hdw (I8051.dph, I8051.st1, start_lbl) ;
    208                     ERTL.St_comment ("End Epilogue", start_lbl)]])
     212       [assign_result] @
     213       [adds_graph [ERTL.St_comment ("End Epilogue", start_lbl)]])
    209214      start_lbl tmp_lbl def in
    210215  let def = add_graph tmp_lbl last_stmt def in
     
    243248  let (def, tmpr) = fresh_reg def in
    244249  adds_graph
    245     [ERTL.St_int (addr2, off+I8051.int_size, start_lbl) ;
     250    [ERTL.St_int (addr1, off+I8051.int_size, start_lbl) ;
    246251     ERTL.St_get_hdw (tmpr, I8051.spl, start_lbl) ;
    247252     ERTL.St_clear_carry start_lbl ;
     
    275280   pseudo-register. *)
    276281
    277 let fetch_result ret_regs start_lbl = match ret_regs with
    278   | [] -> adds_graph [ERTL.St_skip start_lbl] start_lbl
    279   | [r] ->
    280       adds_graph
    281       [ERTL.St_hdw_to_hdw (I8051.st0, I8051.dpl, start_lbl) ;
    282        ERTL.St_get_hdw (r, I8051.st0, start_lbl)]
    283       start_lbl
    284   | r1 :: r2 :: _ ->
    285     adds_graph
    286       [ERTL.St_hdw_to_hdw (I8051.st0, I8051.dpl, start_lbl) ;
    287        ERTL.St_hdw_to_hdw (I8051.st1, I8051.dph, start_lbl) ;
    288        ERTL.St_get_hdw (r1, I8051.st0, start_lbl) ;
    289        ERTL.St_get_hdw (r2, I8051.st1, start_lbl)]
    290       start_lbl
     282let fetch_result ret_regs start_lbl =
     283  let ((common1, _), (common2, _)) = MiscPottier.reduce I8051.sts I8051.rets in
     284  let f_save st ret = ERTL.St_hdw_to_hdw (st, ret, start_lbl) in
     285  let saves = List.map2 f_save common1 common2 in
     286  let ((common1, _), (common2, _)) = MiscPottier.reduce ret_regs I8051.sts in
     287  let f_restore r st = ERTL.St_get_hdw (r, st, start_lbl) in
     288  let restores = List.map2 f_restore common1 common2 in
     289  adds_graph (saves @ restores) start_lbl
    291290
    292291(* When calling a function, we need to set its parameters in specific locations:
     
    299298    ([adds_graph [ERTL.St_comment ("Starting a call", start_lbl)] ;
    300299      adds_graph [ERTL.St_comment ("Setting up parameters", start_lbl)]] @
    301         set_params args @
    302         [adds_graph [ERTL.St_call_id (f, nb_args, start_lbl)] ;
    303          adds_graph [ERTL.St_comment ("Fetching result", start_lbl)] ;
    304          fetch_result ret_regs])
     300     set_params args @
     301     [adds_graph [ERTL.St_call_id (f, nb_args, start_lbl)] ;
     302      adds_graph [ERTL.St_comment ("Fetching result", start_lbl)] ;
     303      fetch_result ret_regs ;
     304      adds_graph [ERTL.St_comment ("End of call sequence", start_lbl)]])
    305305    start_lbl dest_lbl def
    306306
     
    334334    add_graph lbl (ERTL.St_move (r1, r2, lbl')) def
    335335
    336   | RTL.St_opaccs (op, destr, srcr1, srcr2, lbl') ->
    337     add_graph lbl (ERTL.St_opaccs (op, destr, srcr1, srcr2, lbl')) def
     336  | RTL.St_opaccs (op, destr1, destr2, srcr1, srcr2, lbl') ->
     337    adds_graph [ERTL.St_opaccsA (op, destr1, srcr1, srcr2, lbl) ;
     338                ERTL.St_opaccsB (op, destr2, srcr1, srcr2, lbl) ;]
     339      lbl lbl' def
    338340
    339341  | RTL.St_op1 (op1, destr, srcr, lbl') ->
     
    345347  | RTL.St_clear_carry lbl' ->
    346348    add_graph lbl (ERTL.St_clear_carry lbl') def
     349
     350  | RTL.St_set_carry lbl' ->
     351    add_graph lbl (ERTL.St_set_carry lbl') def
    347352
    348353  | RTL.St_load (destr, addr1, addr2, lbl') ->
     
    366371  *)
    367372
    368   | RTL.St_condacc (srcr, lbl_true, lbl_false) ->
    369     add_graph lbl (ERTL.St_condacc (srcr, lbl_true, lbl_false)) def
     373  | RTL.St_cond (srcr, lbl_true, lbl_false) ->
     374    add_graph lbl (ERTL.St_cond (srcr, lbl_true, lbl_false)) def
    370375
    371376  | RTL.St_return ret_regs ->
     
    427432    | ERTL.St_pop (_, lbl) | ERTL.St_push (_, lbl) | ERTL.St_addrH (_, _, lbl)
    428433    | ERTL.St_addrL (_, _, lbl) | ERTL.St_int (_, _, lbl)
    429     | ERTL.St_move (_, _, lbl) | ERTL.St_opaccs (_, _, _, _, lbl)
     434    | ERTL.St_move (_, _, lbl) | ERTL.St_opaccsA (_, _, _, _, lbl)
     435    | ERTL.St_opaccsB (_, _, _, _, lbl)
    430436    | ERTL.St_op1 (_, _, _, lbl) | ERTL.St_op2 (_, _, _, _, lbl)
    431     | ERTL.St_clear_carry lbl | ERTL.St_load (_, _, _, lbl)
     437    | ERTL.St_clear_carry lbl | ERTL.St_set_carry lbl
     438    | ERTL.St_load (_, _, _, lbl)
    432439    | ERTL.St_store (_, _, _, lbl) | ERTL.St_call_id (_, _, lbl)
    433440    | ERTL.St_newframe lbl | ERTL.St_delframe lbl | ERTL.St_framesize (_, lbl)
    434441      ->
    435442      aux lbl
    436     | ERTL.St_condacc _ | ERTL.St_return _ ->
     443    | ERTL.St_cond _ | ERTL.St_return _ ->
    437444      (* No cost label found (no labelling performed). Indeed, the first cost
    438445         label must after some linear instructions. *)
Note: See TracChangeset for help on using the changeset viewer.