annotate src/fftw-3.3.3/genfft/variable.ml @ 23:619f715526df sv_v2.1

Update Vamp plugin SDK to 2.5
author Chris Cannam
date Thu, 09 May 2013 10:52:46 +0100
parents 37bf6b4a2645
children
rev   line source
Chris@10 1 (*
Chris@10 2 * Copyright (c) 1997-1999 Massachusetts Institute of Technology
Chris@10 3 * Copyright (c) 2003, 2007-11 Matteo Frigo
Chris@10 4 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
Chris@10 5 *
Chris@10 6 * This program is free software; you can redistribute it and/or modify
Chris@10 7 * it under the terms of the GNU General Public License as published by
Chris@10 8 * the Free Software Foundation; either version 2 of the License, or
Chris@10 9 * (at your option) any later version.
Chris@10 10 *
Chris@10 11 * This program is distributed in the hope that it will be useful,
Chris@10 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@10 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@10 14 * GNU General Public License for more details.
Chris@10 15 *
Chris@10 16 * You should have received a copy of the GNU General Public License
Chris@10 17 * along with this program; if not, write to the Free Software
Chris@10 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@10 19 *
Chris@10 20 *)
Chris@10 21
Chris@10 22 type variable =
Chris@10 23 (* temporary variables generated automatically *)
Chris@10 24 | Temporary of int
Chris@10 25 (* memory locations, e.g., array elements *)
Chris@10 26 | Locative of (Unique.unique * Unique.unique *
Chris@10 27 (int -> string) * int * string)
Chris@10 28 (* constant values, e.g., twiddle factors *)
Chris@10 29 | Constant of (Unique.unique * string)
Chris@10 30
Chris@10 31 let hash v = Hashtbl.hash v
Chris@10 32
Chris@10 33 let same a b = (a == b)
Chris@10 34
Chris@10 35 let is_constant = function
Chris@10 36 | Constant _ -> true
Chris@10 37 | _ -> false
Chris@10 38
Chris@10 39 let is_temporary = function
Chris@10 40 | Temporary _ -> true
Chris@10 41 | _ -> false
Chris@10 42
Chris@10 43 let is_locative = function
Chris@10 44 | Locative _ -> true
Chris@10 45 | _ -> false
Chris@10 46
Chris@10 47 let same_location a b =
Chris@10 48 match (a, b) with
Chris@10 49 | (Locative (location_a, _, _, _, _), Locative (location_b, _, _, _, _)) ->
Chris@10 50 Unique.same location_a location_b
Chris@10 51 | _ -> false
Chris@10 52
Chris@10 53 let same_class a b =
Chris@10 54 match (a, b) with
Chris@10 55 | (Locative (_, class_a, _, _, _), Locative (_, class_b, _, _, _)) ->
Chris@10 56 Unique.same class_a class_b
Chris@10 57 | (Constant (class_a, _), Constant (class_b, _)) ->
Chris@10 58 Unique.same class_a class_b
Chris@10 59 | _ -> false
Chris@10 60
Chris@10 61 let make_temporary =
Chris@10 62 let tmp_count = ref 0
Chris@10 63 in fun () -> begin
Chris@10 64 tmp_count := !tmp_count + 1;
Chris@10 65 Temporary !tmp_count
Chris@10 66 end
Chris@10 67
Chris@10 68 let make_constant class_token name =
Chris@10 69 Constant (class_token, name)
Chris@10 70
Chris@10 71 let make_locative location_token class_token name i vs =
Chris@10 72 Locative (location_token, class_token, name, i, vs)
Chris@10 73
Chris@10 74 let vstride_of_locative = function
Chris@10 75 | Locative (_, _, _, _, vs) -> vs
Chris@10 76 | _ -> failwith "vstride_of_locative"
Chris@10 77
Chris@10 78 (* special naming conventions for variables *)
Chris@10 79 let rec base62_of_int k =
Chris@10 80 let x = k mod 62
Chris@10 81 and y = k / 62 in
Chris@10 82 let c =
Chris@10 83 if x < 10 then
Chris@10 84 Char.chr (x + Char.code '0')
Chris@10 85 else if x < 36 then
Chris@10 86 Char.chr (x + Char.code 'a' - 10)
Chris@10 87 else
Chris@10 88 Char.chr (x + Char.code 'A' - 36)
Chris@10 89 in
Chris@10 90 let s = String.make 1 c in
Chris@10 91 let r = if y == 0 then "" else base62_of_int y in
Chris@10 92 r ^ s
Chris@10 93
Chris@10 94 let varname_of_int k =
Chris@10 95 if !Magic.compact then
Chris@10 96 base62_of_int k
Chris@10 97 else
Chris@10 98 string_of_int k
Chris@10 99
Chris@10 100 let unparse = function
Chris@10 101 | Temporary k -> "T" ^ (varname_of_int k)
Chris@10 102 | Constant (_, name) -> name
Chris@10 103 | Locative (_, _, name, i, _) -> name i
Chris@10 104
Chris@10 105 let unparse_for_alignment m = function
Chris@10 106 | Locative (_, _, name, i, _) -> name (i mod m)
Chris@10 107 | _ -> failwith "unparse_for_alignment"
Chris@10 108