Ignore:
Timestamp:
Oct 21, 2011, 2:02:41 PM (8 years ago)
Author:
tranquil
Message:
  • added infrastructure to add same-language transformations along the compilation chain from command line options
  • started work on cost expression semplification
File:
1 edited

Legend:

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

    r818 r1433  
    3535  | AstLIN    of LIN.program
    3636  | AstASM    of ASM.program
     37
     38type transformation = name * (ast -> ast)
    3739
    3840let language_of_ast = function
     
    134136]
    135137
    136 let compile debug src tgt =
    137   (* Find the maximal suffix of the chain that starts with the
    138      language [src]. *)
    139   let rec subchain = function
    140     | [] ->
    141       (* The chain is assumed to be well-formed: such a suffix
    142          exists. *)
    143       assert false
    144     | ((l, _, _) :: _) as chain when l = src -> chain
    145     | _ :: chain -> subchain chain
    146   in
     138let insert_transformations ts chain =
     139        (* turn transformation into elements of the compilation chain *)
     140        let trans_to_comp (n, t) = (n, n, t) in
     141        let ts = List.map trans_to_comp ts in
     142        (* ts and chain are merged, and then sorted so that the resulting list is *)
     143        (* still a well formed compilation chain. Stable sort preserves order *)
     144        (* between transformations on the same language as appearing in ts *)
     145        let compare (n1, n2, s) (m1, m2, t) = compare (n1, n2) (m1, m2) in
     146        List.stable_sort compare (ts @ chain)
     147
     148let compile debug ts src tgt =
     149        (* insert intermediate transformations *)
     150  let chain = insert_transformations ts compilation_chain in
     151        (* erase transformations whose source is strictly before src *)
     152        let chain = List.filter (function (l1, _, _) -> l1 >= src) chain in
     153  (* erase transformations whose target is strictly after tgt *)
     154        let chain = List.filter (function (_, l2, _) -> l2 <= tgt) chain in
    147155  (* Compose the atomic translations to build a compilation function
    148156     from [src] to [tgt]. Again, we assume that the compilation chain
     
    151159     translation from [src] to [tgt]. *)
    152160  let rec compose iprogs src tgt chains ast =
    153     if src = tgt then List.rev (ast :: iprogs)
    154     else
    155       match chains with
    156         | [] ->
     161    match chains with
     162        | [] when src = tgt -> List.rev (ast :: iprogs)
     163        | [] -> 
    157164          Error.global_error "During compilation configuration"
    158165            (Printf.sprintf "It is not possible to compile from `%s' to `%s'."
     
    166173          ast :: l2_to_tgt iprog
    167174  in
    168   compose [] src tgt (subchain compilation_chain)
     175  compose [] src tgt chain
    169176
    170177
Note: See TracChangeset for help on using the changeset viewer.