Ignore:
Timestamp:
Nov 4, 2011, 12:22:17 PM (8 years ago)
Author:
ayache
Message:

Function pointers in D2.2/8051. Bugged for now.

File:
1 edited

Legend:

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

    r1462 r1488  
    88let do_dev_test (filenames : string list) : unit =
    99
     10  let main_lbl = "main" in
     11  let exit_lbl = "exit" in
     12  let lbl = "label" in
     13
     14  let code =
     15    [(* Prelude *)
     16      `Call main_lbl ; (* call main *)
     17      `Label exit_lbl ; (* when coming back from main, do an infinite
     18                           jump here *)
     19      `Jmp exit_lbl ;
     20    (* Main *)
     21      `Label main_lbl ;
     22      `Mov (`DPTR, lbl) ; (* fetch the address of lbl in DPTR *)
     23    (* Push the address of lbl on the stack. *)
     24      `PUSH (I8051.reg_addr I8051.dpl) ; (* low bytes first *)
     25      `PUSH (I8051.reg_addr I8051.dph) ; (* then high bytes *)
     26      `RET ; (* this should jump to lbl, i.e. right below *)
     27      `Label lbl ;
     28      `RET (* jump to the exit label *)] in
     29
     30  (* Create a labelled ASM program with the code. *)
     31  let prog =
     32    { ASM.ppreamble = [] ;
     33      ASM.pexit_label = exit_lbl ;
     34      ASM.pcode = code ;
     35      ASM.phas_main = true } in
     36
     37  (* Assemble it. *)
     38  let prog = Languages.AstASM (ASMInterpret.assembly prog) in
     39
     40  (* Save the result in a fresh file prefixed by "yop" and whose extension is
     41     "hex". *)
     42  Languages.save false false "yop" "" prog
     43
     44(*
    1045  let f filename =
    11     Printf.printf "Processing %s...\n%!" filename ;
    12     let target = Languages.RTL in
    13     let print = false in
    14     let debug = true in
    15     let interpret = true in
    16     let p = Languages.parse Languages.Clight filename in
    17     let p = Languages.add_runtime p in
    18     let p = Languages.labelize p in
    19     let ps = Languages.compile false Languages.Clight target p in
    20     let f f' p = match Languages.language_of_ast p with
    21       | l when l = target -> f' p
    22       | _ -> ()
    23     in
    24     let actions =
    25       [(print, Languages.save false false filename "") ;
    26        (interpret, (fun p -> ignore (Languages.interpret debug p)))] in
    27     List.iter (fun (b, f') -> if b then List.iter (f f') ps else ()) actions
     46  Printf.printf "Processing %s...\n%!" filename ;
     47  let target = Languages.RTL in
     48  let print = false in
     49  let debug = true in
     50  let interpret = true in
     51  let p = Languages.parse Languages.Clight filename in
     52  let p = Languages.add_runtime p in
     53  let p = Languages.labelize p in
     54  let ps = Languages.compile false Languages.Clight target p in
     55  let f f' p = match Languages.language_of_ast p with
     56  | l when l = target -> f' p
     57  | _ -> ()
     58  in
     59  let actions =
     60  [(print, Languages.save false false filename "") ;
     61  (interpret, (fun p -> ignore (Languages.interpret debug p)))] in
     62  List.iter (fun (b, f') -> if b then List.iter (f f') ps else ()) actions
    2863  in
    2964
    3065  List.iter f filenames
     66*)
Note: See TracChangeset for help on using the changeset viewer.