Ignore:
Timestamp:
Oct 11, 2011, 5:42:20 PM (9 years ago)
Author:
tranquil
Message:
  • changed implementation of constant indexings with extensible arrays
  • work on ASM completed
  • next: optimizations!
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.2/8051-indexed-labels-branch/src/common/costLabel.ml

    r1328 r1357  
    2020type indexing = sexpr list
    2121
    22 type const_indexing = int array
     22type const_indexing = int ExtArray.t
    2323
    24 (** [enter_loop n indexing] is used to update indexing when one is entering a
    25     loop indexed by [n].
    26                 The function recycles the same constant indexing *)
    27 let rec enter_loop n indexing = match n with
    28         | None -> ()
    29         | Some x -> try indexing.(x) <- 0 with | _ -> assert false
     24let const_ind_iter = ExtArray.iter
    3025
    31 (** [enter_loop n indexing] is used to update indexing when one is continuing a
    32     loop indexed by [n]. *)
    33 let rec continue_loop n indexing = match n with
    34         | None -> ()
    35         | Some x -> try indexing.(x) <- indexing.(x) + 1 with | _ -> assert false
     26let curr_const_ind = function
     27    | hd :: _ -> hd
     28    | _ -> invalid_arg "curr_const_ind applied to non-empty list"
     29
     30let init_const_indexing () = ExtArray.make ~buff:1 0 0
     31
     32let enter_loop_single indexing n = ExtArray.set indexing n 0
     33
     34let continue_loop_single indexing n =
     35        try
     36                ExtArray.set indexing n (ExtArray.get indexing n + 1)
     37        with | _ ->
     38          invalid_arg "uninitialized loop index"
     39
     40let curr_ind = function
     41    | hd :: _ -> hd
     42    | _ -> invalid_arg "non-empty indexing stack"
     43
     44let enter_loop inds = enter_loop_single (curr_ind inds)
     45
     46let continue_loop inds = continue_loop_single (curr_ind inds)
     47
     48let enter_loop_opt indexing = Option.iter (enter_loop indexing)
     49
     50let continue_loop_opt indexing = Option.iter (continue_loop indexing)
     51
     52let new_const_ind inds = init_const_indexing () :: inds
     53
     54let forget_const_ind = function
     55        | _ :: inds -> inds
     56        | _ -> invalid_arg "non-empty indexing stack"
    3657
    3758let sexpr_of i l =
     
    6990        | s :: l ->
    7091                try
    71                   const_sexpr (ev_sexpr c.(i) s) :: compose_const_indexing_i (i+1) c l
     92                  const_sexpr (ev_sexpr (ExtArray.get c i) s) ::
     93                         compose_const_indexing_i (i+1) c l
    7294                with
    73                         | Invalid_argument _ -> assert false
     95                        | Invalid_argument _ ->
     96                                invalid_arg "constant indexing not enough to be applied"
    7497
    7598module IndexingSet = Set.Make(struct
     
    83106}
    84107
    85 let apply_const_indexing c lbl =
     108let ev_indexing c lbl =
    86109    {lbl with i = compose_const_indexing_i 0 c lbl.i}
    87110
Note: See TracChangeset for help on using the changeset viewer.