Changeset 1491 for Deliverables/D2.2


Ignore:
Timestamp:
Nov 4, 2011, 1:39:01 PM (8 years ago)
Author:
ayache
Message:

Function pointers good and working.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.2/8051/src/LIN/LINToASM.ml

    r1488 r1491  
    5656let data16_of_int i = `DATA16 (vect_of_int i `Sixteen)
    5757let acc_addr = I8051.reg_addr I8051.a
     58let dpl_addr = I8051.reg_addr I8051.dpl
     59let dph_addr = I8051.reg_addr I8051.dph
     60let st0_addr = I8051.reg_addr I8051.st0
     61let st1_addr = I8051.reg_addr I8051.st1
    5862
    5963
    60 let rec translate_statement env = function
     64let translate_statement env = function
    6165  | LIN.St_goto lbl -> [`Jmp lbl]
    6266  | LIN.St_label lbl -> [`Label lbl]
     
    7276  | LIN.St_push ->
    7377    [`PUSH acc_addr]
    74 (*
    75   | LIN.St_addr x when List.mem_assoc x env.globals_addr ->
    76     [`MOV (`U4 (`DPTR, data16_of_int (List.assoc x env.globals_addr)))]
    77   | LIN.St_addr x when List.mem x env.fun_names ->
    78     [`Mov (`DPTR, x)]
    79   | LIN.St_addr x ->
    80     error
    81       ("unknown symbol " ^ x ^ ". Primitives and externals are not supported")
    82 *)
    8378  | LIN.St_addr x when List.mem x env.externals ->
    8479    error ("Primitive or external " ^ x ^ " is not supported.")
     
    117112  | LIN.St_store ->
    118113    [`MOVX (`U2 (`EXT_IND_DPTR, `A))]
     114  | LIN.St_call_id x when List.mem x env.externals ->
     115    error ("Primitive or external " ^ x ^ " is not supported.")
    119116  | LIN.St_call_id f ->
    120117    [`Call f]
    121 (*
    122   | LIN.St_call_ptr ->
    123     (`Call env.set_ra_lbl) :: (call_ptr_instrs env)
    124 *)
    125118  | LIN.St_call_ptr ->
    126119    let lbl = env.fresh () in
    127     translate_code env
    128       [LIN.St_to_acc I8051.dpl ;
    129        LIN.St_from_acc I8051.st0 ;
    130        LIN.St_to_acc I8051.dph ;
    131        LIN.St_from_acc I8051.st1 ;
    132        LIN.St_addr lbl ;
    133        LIN.St_to_acc I8051.dpl ;
    134        LIN.St_push ;
    135        LIN.St_to_acc I8051.dph ;
    136        LIN.St_push ;
    137        LIN.St_to_acc I8051.st0 ;
    138        LIN.St_push ;
    139        LIN.St_to_acc I8051.st1 ;
    140        LIN.St_push ;
    141        LIN.St_return ;
    142        LIN.St_label lbl]
     120    [`MOV (`U3 (st0_addr, dpl_addr)) ;
     121     `MOV (`U3 (st1_addr, dph_addr)) ;
     122     `Mov (`DPTR, lbl) ;
     123     `PUSH dpl_addr ;
     124     `PUSH dph_addr ;
     125     `PUSH st0_addr ;
     126     `PUSH st1_addr ;
     127     `RET ;
     128     `Label lbl]
    143129  | LIN.St_condacc lbl ->
    144130    [`WithLabel (`JNZ (`Label lbl))]
     
    146132    [`RET]
    147133
    148 and translate_code env code =
     134let translate_code env code =
    149135  List.flatten (List.map (translate_statement env) code)
    150136
Note: See TracChangeset for help on using the changeset viewer.