2
* Copyright (c) 1997-1999 Massachusetts Institute of Technology
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
(* Data types and functions for dealing with variables in symbolic
21
* expressions and the abstract syntax tree. *)
23
(* Variables fall into one of four categories: temporary variables
24
* (which the generator can add or delete at will), named (fixed)
25
* variables, and the real/imaginary parts of complex arrays. Arrays
26
* can be either input arrays, output arrays, or arrays of precomputed
27
* twiddle factors (roots of unity). *)
29
type array = Input | Output | Twiddle
31
let arrayToString = function
39
| RealArrayElem of (array * int)
40
| ImagArrayElem of (array * int)
45
tmp_count := !tmp_count + 1;
49
let is_temporary = function
53
let is_real = function
54
| RealArrayElem _ -> true
57
let is_imag = function
58
| ImagArrayElem _ -> true
61
let is_output = function
62
| RealArrayElem (Output, _) -> true
63
| ImagArrayElem (Output, _) -> true
66
let is_input = function
67
| RealArrayElem (Input, _) -> true
68
| ImagArrayElem (Input, _) -> true
71
let is_twiddle = function
72
| RealArrayElem (Twiddle, _) -> true
73
| ImagArrayElem (Twiddle, _) -> true
76
let is_locative x = (is_input x) || (is_output x)
77
let is_constant = is_twiddle
82
| RealArrayElem(Input,i) -> i * 8
83
| ImagArrayElem(Input,i) -> -i * 8 + 1
84
| RealArrayElem(Output,i) -> i * 8 + 2
85
| ImagArrayElem(Output,i) -> -i * 8 + 3
86
| RealArrayElem(Twiddle,i) -> i * 8 + 4
87
| ImagArrayElem(Twiddle,i) -> -i * 8 + 5
93
| (RealArrayElem (a1, k1), ImagArrayElem (a2, k2)) -> a1 = a2 && k1 = k2
94
| (ImagArrayElem (a1, k1), RealArrayElem (a2, k2)) -> a1 = a2 && k1 = k2
97
(* true if assignment of a clobbers variable b *)
98
let clobbers a b = match (a, b) with
99
| (RealArrayElem (Output, k1), RealArrayElem (Input, k2)) -> k1 = k2
100
| (ImagArrayElem (Output, k1), ImagArrayElem (Input, k2)) -> k1 = k2
103
(* true if a is the real part and b the imaginary of the same array *)
104
let real_imag a b = match (a, b) with
105
| (RealArrayElem (a1, k1), ImagArrayElem (a2, k2)) -> a1 = a2 && k1 = k2
108
(* true if a and b are elements of the same array, and a has smaller index *)
109
let increasing_indices a b = match (a, b) with
110
| (RealArrayElem (a1, k1), RealArrayElem (a2, k2)) -> a1 = a2 && k1 < k2
111
| (RealArrayElem (a1, k1), ImagArrayElem (a2, k2)) -> a1 = a2 && k1 < k2
112
| (ImagArrayElem (a1, k1), RealArrayElem (a2, k2)) -> a1 = a2 && k1 < k2
113
| (ImagArrayElem (a1, k1), ImagArrayElem (a2, k2)) -> a1 = a2 && k1 < k2
116
let access array k = (RealArrayElem (array, k), ImagArrayElem (array, k))
118
let access_input = access Input
119
let access_output = access Output
120
let access_twiddle = access Twiddle
122
let make_named name = Named name
124
let unparse = function
125
| Temporary x -> "T" ^ (string_of_int x)
127
| RealArrayElem (a, x) -> "Re(" ^ (arrayToString a) ^ "[" ^
128
(string_of_int x) ^ "])"
129
| ImagArrayElem (a, x) -> "Im(" ^ (arrayToString a) ^ "[" ^
130
(string_of_int x) ^ "])"