BOAST 0.9995 → 0.9996
Sign up to get free protection for your applications and to get access to all the features.
- data/BOAST.gemspec +3 -1
- data/lib/BOAST/Algorithm.rb +82 -189
- data/lib/BOAST/Arithmetic.rb +16 -16
- data/lib/BOAST/BOAST_OpenCL.rb +44 -41
- data/lib/BOAST/CKernel.rb +471 -344
- data/lib/BOAST/Case.rb +21 -23
- data/lib/BOAST/ControlStructure.rb +9 -1
- data/lib/BOAST/DataTypes.rb +70 -51
- data/lib/BOAST/Expression.rb +22 -17
- data/lib/BOAST/For.rb +37 -23
- data/lib/BOAST/FuncCall.rb +11 -10
- data/lib/BOAST/Functors.rb +29 -4
- data/lib/BOAST/If.rb +21 -23
- data/lib/BOAST/Index.rb +14 -13
- data/lib/BOAST/Inspectable.rb +6 -13
- data/lib/BOAST/Operators.rb +82 -61
- data/lib/BOAST/Parens.rb +4 -25
- data/lib/BOAST/Pragma.rb +7 -6
- data/lib/BOAST/Print.rb +7 -0
- data/lib/BOAST/Procedure.rb +46 -34
- data/lib/BOAST/State.rb +79 -0
- data/lib/BOAST/Transitions.rb +13 -5
- data/lib/BOAST/Variable.rb +104 -68
- data/lib/BOAST/While.rb +15 -17
- data/lib/BOAST.rb +2 -0
- metadata +4 -2
data/lib/BOAST/Functors.rb
CHANGED
@@ -1,17 +1,42 @@
|
|
1
1
|
module BOAST
|
2
|
+
|
3
|
+
module_function
|
4
|
+
def functorize(klass)
|
5
|
+
name = klass.name.split('::').last
|
6
|
+
s = <<EOF
|
7
|
+
def #{name}(*args,&block)
|
8
|
+
#{name}::new(*args,&block)
|
9
|
+
end
|
10
|
+
|
11
|
+
module_function :#{name}
|
12
|
+
EOF
|
13
|
+
eval s
|
14
|
+
end
|
15
|
+
|
16
|
+
def var_functorize(klass)
|
17
|
+
name = klass.name.split('::').last
|
18
|
+
s = <<EOF
|
19
|
+
def #{name}(*args,&block)
|
20
|
+
Variable::new(args[0],#{name},*args[1..-1], &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
module_function :#{name}
|
24
|
+
EOF
|
25
|
+
eval s
|
26
|
+
end
|
2
27
|
|
3
28
|
module Functor
|
4
29
|
|
5
|
-
def
|
6
|
-
|
30
|
+
def self.extended(mod)
|
31
|
+
BOAST::functorize(mod)
|
7
32
|
end
|
8
33
|
|
9
34
|
end
|
10
35
|
|
11
36
|
module VarFunctor
|
12
37
|
|
13
|
-
def
|
14
|
-
|
38
|
+
def self.extended(mod)
|
39
|
+
BOAST::var_functorize(mod)
|
15
40
|
end
|
16
41
|
|
17
42
|
end
|
data/lib/BOAST/If.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module BOAST
|
2
2
|
|
3
|
-
class If <
|
4
|
-
include BOAST::Inspectable
|
5
|
-
extend BOAST::Functor
|
3
|
+
class If < ControlStructure
|
6
4
|
|
7
5
|
attr_reader :conditions
|
8
6
|
|
@@ -43,10 +41,10 @@ module BOAST
|
|
43
41
|
}
|
44
42
|
|
45
43
|
@@strings = {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
C => @@c_strings,
|
45
|
+
CL => @@c_strings,
|
46
|
+
CUDA => @@c_strings,
|
47
|
+
FORTRAN => @@f_strings
|
50
48
|
}
|
51
49
|
|
52
50
|
eval token_string_generator( * %w{if cond} )
|
@@ -70,38 +68,38 @@ module BOAST
|
|
70
68
|
|
71
69
|
def open
|
72
70
|
s=""
|
73
|
-
s +=
|
74
|
-
s +=
|
75
|
-
|
76
|
-
|
71
|
+
s += indent
|
72
|
+
s += to_s
|
73
|
+
output.puts s
|
74
|
+
increment_indent_level
|
77
75
|
return self
|
78
76
|
end
|
79
77
|
|
80
|
-
def
|
78
|
+
def pr(*args)
|
81
79
|
if @blocks.size > 0 then
|
82
|
-
|
80
|
+
increment_indent_level
|
83
81
|
@blocks.each_index { |indx|
|
84
|
-
|
82
|
+
decrement_indent_level
|
85
83
|
s=""
|
86
|
-
s +=
|
87
|
-
s +=
|
88
|
-
|
89
|
-
|
84
|
+
s += indent
|
85
|
+
s += to_s(indx)
|
86
|
+
output.puts s
|
87
|
+
increment_indent_level
|
90
88
|
@blocks[indx].call(*args)
|
91
89
|
}
|
92
|
-
|
90
|
+
close
|
93
91
|
else
|
94
|
-
|
92
|
+
open
|
95
93
|
end
|
96
94
|
return self
|
97
95
|
end
|
98
96
|
|
99
97
|
def close
|
100
|
-
|
98
|
+
decrement_indent_level
|
101
99
|
s = ""
|
102
|
-
s +=
|
100
|
+
s += indent
|
103
101
|
s += end_string
|
104
|
-
|
102
|
+
output.puts s
|
105
103
|
return self
|
106
104
|
end
|
107
105
|
|
data/lib/BOAST/Index.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module BOAST
|
2
|
+
|
2
3
|
class Index < Expression
|
3
|
-
include BOAST::Inspectable
|
4
4
|
attr_reader :source
|
5
5
|
attr_reader :indexes
|
6
|
+
|
6
7
|
def initialize(source, indexes)
|
7
8
|
@source = source
|
8
9
|
@indexes = indexes
|
@@ -14,8 +15,8 @@ module BOAST
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def to_s
|
17
|
-
return
|
18
|
-
return
|
18
|
+
return to_s_fortran if lang == FORTRAN
|
19
|
+
return to_s_c if [C, CL, CUDA].include?( lang )
|
19
20
|
end
|
20
21
|
|
21
22
|
def to_s_fortran
|
@@ -25,7 +26,7 @@ module BOAST
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def to_s_texture
|
28
|
-
raise "Unsupported language #{
|
29
|
+
raise "Unsupported language #{lang} for texture!" if not [CL, CUDA].include?( lang )
|
29
30
|
raise "Write is unsupported for textures!" if not ( @source.constant or @source.direction == :in )
|
30
31
|
dim_number = 1
|
31
32
|
if @source.dimension then
|
@@ -33,7 +34,7 @@ module BOAST
|
|
33
34
|
end
|
34
35
|
raise "Unsupported number of dimension: #{dim_number}!" if dim_number > 3
|
35
36
|
s = ""
|
36
|
-
if
|
37
|
+
if lang == CL then
|
37
38
|
s += "as_#{@source.type.decl}("
|
38
39
|
s += "read_imageui(#{@source}, #{@source.sampler}, "
|
39
40
|
if dim_number == 1 then
|
@@ -76,7 +77,7 @@ module BOAST
|
|
76
77
|
if dim.val2 then
|
77
78
|
start = dim.val1
|
78
79
|
else
|
79
|
-
start =
|
80
|
+
start = get_array_start
|
80
81
|
end
|
81
82
|
sub = "#{@indexes.first} - (#{start})"
|
82
83
|
i=1
|
@@ -93,12 +94,12 @@ module BOAST
|
|
93
94
|
if dim.val2 then
|
94
95
|
start = dim.val1
|
95
96
|
else
|
96
|
-
start =
|
97
|
+
start = get_array_start
|
97
98
|
end
|
98
99
|
sub += " + (#{@indexes[i]} - (#{start}))"+ss
|
99
100
|
i+=1
|
100
101
|
}
|
101
|
-
if
|
102
|
+
if get_replace_constants then
|
102
103
|
begin
|
103
104
|
# puts sub
|
104
105
|
indx = eval(sub)
|
@@ -112,12 +113,12 @@ module BOAST
|
|
112
113
|
return s
|
113
114
|
end
|
114
115
|
|
115
|
-
def
|
116
|
+
def pr
|
116
117
|
s=""
|
117
|
-
s +=
|
118
|
-
s +=
|
119
|
-
s += ";" if [C, CL, CUDA].include?(
|
120
|
-
|
118
|
+
s += indent
|
119
|
+
s += to_s
|
120
|
+
s += ";" if [C, CL, CUDA].include?( lang )
|
121
|
+
output.puts s
|
121
122
|
return self
|
122
123
|
end
|
123
124
|
|
data/lib/BOAST/Inspectable.rb
CHANGED
@@ -1,25 +1,18 @@
|
|
1
1
|
module BOAST
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
def self.inspect?
|
6
|
-
return @@inspect
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.inspect=(val)
|
10
|
-
@@inspect = val
|
11
|
-
end
|
3
|
+
boolean_state_accessor :boast_inspect
|
4
|
+
@@boast_inspect = false
|
12
5
|
|
13
6
|
module Inspectable
|
14
7
|
|
15
8
|
def inspect
|
16
|
-
if BOAST::
|
17
|
-
variables =
|
9
|
+
if BOAST::boast_inspect? then
|
10
|
+
variables = instance_variables.map{ |v|
|
18
11
|
instance_variable_get(v) ? "#{v}=#{instance_variable_get(v).inspect}" : nil
|
19
12
|
}.reject{ |v| v.nil? }.join(", ")
|
20
|
-
"#<#{self.class}
|
13
|
+
"#<#{self.class}:0x#{(self.object_id<<1).to_s(16)}#{variables == "" ? "" : " #{variables}" }>"
|
21
14
|
else
|
22
|
-
|
15
|
+
to_s
|
23
16
|
end
|
24
17
|
end
|
25
18
|
|
data/lib/BOAST/Operators.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
module BOAST
|
2
2
|
|
3
3
|
class Operator
|
4
|
+
extend PrivateStateAccessor
|
5
|
+
|
4
6
|
def Operator.inspect
|
5
|
-
return "#{
|
7
|
+
return "#{name}"
|
6
8
|
end
|
7
9
|
|
8
10
|
def Operator.get_vector_name(type)
|
9
|
-
case
|
11
|
+
case get_architecture
|
10
12
|
when X86
|
11
13
|
case type
|
12
|
-
when
|
14
|
+
when Int
|
13
15
|
size = "#{type.size*8}"
|
14
16
|
name = ""
|
15
17
|
if type.total_size*8 > 64
|
@@ -26,7 +28,7 @@ module BOAST
|
|
26
28
|
name += "u"
|
27
29
|
end
|
28
30
|
return name += size
|
29
|
-
when
|
31
|
+
when Real
|
30
32
|
case type.size
|
31
33
|
when 4
|
32
34
|
return "ps" if type.vector_length > 1
|
@@ -38,13 +40,13 @@ module BOAST
|
|
38
40
|
else
|
39
41
|
raise "Undefined vector type!"
|
40
42
|
end
|
41
|
-
when
|
43
|
+
when ARM
|
42
44
|
case type
|
43
|
-
when
|
45
|
+
when Int
|
44
46
|
name = "#{ type.signed ? "s" : "u" }"
|
45
47
|
name += "#{ type.size * 8}"
|
46
48
|
return name
|
47
|
-
when
|
49
|
+
when Real
|
48
50
|
return "f#{type.size*8}"
|
49
51
|
else
|
50
52
|
raise "Undefined vector type!"
|
@@ -55,8 +57,8 @@ module BOAST
|
|
55
57
|
end
|
56
58
|
|
57
59
|
def Operator.convert(arg, type)
|
58
|
-
case
|
59
|
-
when
|
60
|
+
case get_architecture
|
61
|
+
when X86
|
60
62
|
s1 = arg.type.total_size*8
|
61
63
|
s2 = type.total_size*8
|
62
64
|
n1 = get_vector_name(arg.type)
|
@@ -68,14 +70,14 @@ module BOAST
|
|
68
70
|
elsif [s1, s2].max <= 512 then
|
69
71
|
return "_mm512_cvt#{n1}_#{n2}( #{arg} )"
|
70
72
|
end
|
71
|
-
when
|
73
|
+
when ARM
|
72
74
|
if type.class != arg.type.class then
|
73
75
|
if type.size == arg.type.size then
|
74
76
|
s = type.total_size*8
|
75
77
|
n1 = get_vector_name(arg.type)
|
76
78
|
n2 = get_vector_name(type)
|
77
79
|
return "vcvt#{ s == 128 ? "q" : "" }_#{n2}_#{n1}( #{arg} )"
|
78
|
-
elsif type.class ==
|
80
|
+
elsif type.class == Real then
|
79
81
|
intr = convert(arg, arg.type.copy(:size=>type.size))
|
80
82
|
return convert(arg.copy(intr, :size => type.size ), type)
|
81
83
|
else
|
@@ -84,9 +86,9 @@ module BOAST
|
|
84
86
|
t2 = type.copy(:size => arg.type.size)
|
85
87
|
n2 = get_vector_name( t2 )
|
86
88
|
intr = "vcvt#{ s == 128 ? "q" : "" }_#{n2}_#{n1}( #{arg} )"
|
87
|
-
return convert(
|
89
|
+
return convert(Variable::from_type(intr, t2), type)
|
88
90
|
end
|
89
|
-
elsif type.class !=
|
91
|
+
elsif type.class != Real then
|
90
92
|
n = get_vector_name(arg.type)
|
91
93
|
if type.size == arg.type.size then
|
92
94
|
if type.signed == arg.type.signed then
|
@@ -108,19 +110,20 @@ module BOAST
|
|
108
110
|
raise "Unsupported architecture!"
|
109
111
|
end
|
110
112
|
end
|
113
|
+
|
111
114
|
end
|
112
115
|
|
113
|
-
class BasicBinaryOperator <
|
116
|
+
class BasicBinaryOperator < Operator
|
114
117
|
|
115
118
|
def BasicBinaryOperator.to_s(arg1, arg2, return_type)
|
116
119
|
#puts "#{arg1.class} * #{arg2.class} : #{arg1} * #{arg2}"
|
117
|
-
if
|
120
|
+
if lang == C and (arg1.class == Variable and arg2.class == Variable) and (arg1.type.vector_length > 1 or arg2.type.vector_length > 1) then
|
118
121
|
raise "Vectors have different length: #{arg1} #{arg1.type.vector_length}, #{arg2} #{arg2.type.vector_length}" if arg1.type.vector_length != arg2.type.vector_length
|
119
122
|
#puts "#{arg1.type.signed} #{arg2.type.signed} #{return_type.type.signed}"
|
120
123
|
return_name = get_vector_name(return_type.type)
|
121
124
|
size = return_type.type.total_size * 8
|
122
|
-
case
|
123
|
-
when
|
125
|
+
case get_architecture
|
126
|
+
when X86
|
124
127
|
if arg1.type != return_type.type
|
125
128
|
a1 = convert(arg1, return_type.type)
|
126
129
|
else
|
@@ -137,7 +140,7 @@ module BOAST
|
|
137
140
|
end
|
138
141
|
intr_name += "_#{intr_name_X86}_#{return_name}"
|
139
142
|
return "#{intr_name}( #{a1}, #{a2} )"
|
140
|
-
when
|
143
|
+
when ARM
|
141
144
|
if arg1.type.class != return_type.type.class then
|
142
145
|
a1 = convert(arg1, return_type.type)
|
143
146
|
else
|
@@ -159,32 +162,33 @@ module BOAST
|
|
159
162
|
return basic_usage( arg1, arg2 )
|
160
163
|
end
|
161
164
|
end
|
165
|
+
|
162
166
|
end
|
163
167
|
|
164
|
-
class Set <
|
168
|
+
class Set < Operator
|
165
169
|
|
166
170
|
def Set.to_s(arg1, arg2, return_type)
|
167
|
-
if
|
168
|
-
if arg1.class ==
|
171
|
+
if lang == C then
|
172
|
+
if arg1.class == Variable and arg1.type.vector_length > 1 then
|
169
173
|
if arg1.type == arg2.type then
|
170
174
|
return basic_usage(arg1, arg2)
|
171
175
|
elsif arg1.type.vector_length == arg2.type.vector_length then
|
172
176
|
return "(#{arg1} = #{convert(arg2, arg1.type)})"
|
173
177
|
elsif arg2.type.vector_length == 1 then
|
174
178
|
size = arg1.type.total_size*8
|
175
|
-
case
|
176
|
-
when
|
179
|
+
case get_architecture
|
180
|
+
when ARM
|
177
181
|
intr_name = "vmov"
|
178
182
|
intr_name += "q" if size == 128
|
179
183
|
intr_name += "_n_#{get_vector_name(arg1.type)}"
|
180
|
-
when
|
181
|
-
return "(#{arg1} = _m_from_int64( #{a2} ))" if arg1.type.class ==
|
184
|
+
when X86
|
185
|
+
return "(#{arg1} = _m_from_int64( #{a2} ))" if arg1.type.class == Int and arg1.type.size == 8 and size == 64
|
182
186
|
intr_name = "_mm"
|
183
187
|
if size > 128 then
|
184
188
|
intr_name += "#{size}"
|
185
189
|
end
|
186
190
|
intr_name += "_set1_#{get_vector_name(arg1.type).gsub("u","")}"
|
187
|
-
intr_name += "x" if arg1.type.class ==
|
191
|
+
intr_name += "x" if arg1.type.class == Int and arg1.type.size == 8
|
188
192
|
else
|
189
193
|
raise "Unsupported architecture!"
|
190
194
|
end
|
@@ -203,23 +207,27 @@ module BOAST
|
|
203
207
|
def Set.basic_usage(arg1, arg2)
|
204
208
|
return "(#{arg1} = #{arg2})"
|
205
209
|
end
|
210
|
+
|
206
211
|
end
|
207
212
|
|
208
|
-
class Different <
|
213
|
+
class Different < Operator
|
214
|
+
|
209
215
|
def Different.to_s(arg1, arg2, return_type)
|
210
216
|
return basic_usage(arg1, arg2)
|
211
217
|
end
|
212
218
|
|
213
219
|
def Different.basic_usage(arg1, arg2)
|
214
|
-
return "#{arg1} /= #{arg2}" if
|
220
|
+
return "#{arg1} /= #{arg2}" if lang == FORTRAN
|
215
221
|
return "#{arg1} != #{arg2}"
|
216
222
|
end
|
223
|
+
|
217
224
|
end
|
218
225
|
|
219
|
-
class Affectation <
|
226
|
+
class Affectation < Operator
|
227
|
+
|
220
228
|
def Affectation.to_s(arg1, arg2, return_type)
|
221
|
-
if
|
222
|
-
if arg1.class ==
|
229
|
+
if lang == C then
|
230
|
+
if arg1.class == Variable and arg1.type.vector_length > 1 then
|
223
231
|
#puts "#{arg1.type.vector_length} #{arg2.type.vector_length}"
|
224
232
|
if arg1.type == arg2.type then
|
225
233
|
return basic_usage(arg1, arg2)
|
@@ -233,13 +241,13 @@ module BOAST
|
|
233
241
|
else
|
234
242
|
a2 = a2[1..-1]
|
235
243
|
end
|
236
|
-
case
|
237
|
-
when
|
244
|
+
case get_architecture
|
245
|
+
when ARM
|
238
246
|
intr_name = "vldl"
|
239
247
|
intr_name += "q" if size == 128
|
240
248
|
intr_name += "_#{get_vector_name(arg1.type)}"
|
241
|
-
when
|
242
|
-
if arg1.type.class ==
|
249
|
+
when X86
|
250
|
+
if arg1.type.class == Int and size == 64 then
|
243
251
|
return "#{arg1} = _m_from_int64( *((int64_t * ) #{a2} ) )"
|
244
252
|
end
|
245
253
|
intr_name = "_mm"
|
@@ -247,7 +255,7 @@ module BOAST
|
|
247
255
|
intr_name += "#{size}"
|
248
256
|
end
|
249
257
|
intr_name += "_load_"
|
250
|
-
if arg1.type.class ==
|
258
|
+
if arg1.type.class == Int then
|
251
259
|
intr_name += "si#{size}"
|
252
260
|
else
|
253
261
|
intr_name += "#{get_vector_name(arg1.type)}"
|
@@ -259,7 +267,7 @@ module BOAST
|
|
259
267
|
else
|
260
268
|
raise "Unknown convertion between vectors of different length!"
|
261
269
|
end
|
262
|
-
elsif arg2.class ==
|
270
|
+
elsif arg2.class == Variable and arg2.type.vector_length > 1 then
|
263
271
|
size = arg2.type.total_size*8
|
264
272
|
a1 = "#{arg1}"
|
265
273
|
if a1[0] != "*" then
|
@@ -267,13 +275,13 @@ module BOAST
|
|
267
275
|
else
|
268
276
|
a1 = a1[1..-1]
|
269
277
|
end
|
270
|
-
case
|
271
|
-
when
|
278
|
+
case get_architecture
|
279
|
+
when ARM
|
272
280
|
intr_name = "vstl"
|
273
281
|
intr_name += "q" if size == 128
|
274
282
|
intr_name += "_#{get_vector_name(arg2.type)}"
|
275
|
-
when
|
276
|
-
if arg2.type.class ==
|
283
|
+
when X86
|
284
|
+
if arg2.type.class == Int and size == 64 then
|
277
285
|
return " *((int64_t * ) #{a1}) = _m_to_int64( #{arg2} )"
|
278
286
|
end
|
279
287
|
intr_name = "_mm"
|
@@ -281,7 +289,7 @@ module BOAST
|
|
281
289
|
intr_name += "#{size}"
|
282
290
|
end
|
283
291
|
intr_name += "_store_"
|
284
|
-
if arg2.type.class ==
|
292
|
+
if arg2.type.class == Int then
|
285
293
|
intr_name += "si#{size}"
|
286
294
|
else
|
287
295
|
intr_name += "#{get_vector_name(arg2.type)}"
|
@@ -301,9 +309,11 @@ module BOAST
|
|
301
309
|
def Affectation.basic_usage(arg1, arg2)
|
302
310
|
return "#{arg1} = #{arg2}"
|
303
311
|
end
|
312
|
+
|
304
313
|
end
|
305
314
|
|
306
|
-
class Multiplication <
|
315
|
+
class Multiplication < BasicBinaryOperator
|
316
|
+
|
307
317
|
class << self
|
308
318
|
|
309
319
|
def symbol
|
@@ -323,9 +333,11 @@ module BOAST
|
|
323
333
|
end
|
324
334
|
|
325
335
|
end
|
336
|
+
|
326
337
|
end
|
327
338
|
|
328
|
-
class Addition <
|
339
|
+
class Addition < BasicBinaryOperator
|
340
|
+
|
329
341
|
class << self
|
330
342
|
|
331
343
|
def symbol
|
@@ -345,9 +357,11 @@ module BOAST
|
|
345
357
|
end
|
346
358
|
|
347
359
|
end
|
360
|
+
|
348
361
|
end
|
349
362
|
|
350
|
-
class Substraction <
|
363
|
+
class Substraction < BasicBinaryOperator
|
364
|
+
|
351
365
|
class << self
|
352
366
|
|
353
367
|
def symbol
|
@@ -367,9 +381,11 @@ module BOAST
|
|
367
381
|
end
|
368
382
|
|
369
383
|
end
|
384
|
+
|
370
385
|
end
|
371
386
|
|
372
|
-
class Division <
|
387
|
+
class Division < BasicBinaryOperator
|
388
|
+
|
373
389
|
class << self
|
374
390
|
|
375
391
|
def symbol
|
@@ -389,27 +405,30 @@ module BOAST
|
|
389
405
|
end
|
390
406
|
|
391
407
|
end
|
408
|
+
|
392
409
|
end
|
393
410
|
|
394
|
-
class Minus <
|
411
|
+
class Minus < Operator
|
412
|
+
|
395
413
|
def Minus.to_s(arg1, arg2, return_type)
|
396
414
|
return " -(#{arg2})"
|
397
415
|
end
|
416
|
+
|
398
417
|
end
|
399
418
|
|
400
|
-
class Not <
|
419
|
+
class Not < Operator
|
420
|
+
|
401
421
|
def Not.to_s(arg1, arg2, return_type)
|
402
422
|
return " ! #{arg2}"
|
403
423
|
end
|
424
|
+
|
404
425
|
end
|
405
426
|
|
406
427
|
class Ternary
|
407
|
-
|
408
|
-
include
|
409
|
-
|
410
|
-
|
411
|
-
return self::new(*args,&block)
|
412
|
-
end
|
428
|
+
extend Functor
|
429
|
+
include Arithmetic
|
430
|
+
include Inspectable
|
431
|
+
include PrivateStateAccessor
|
413
432
|
|
414
433
|
attr_reader :operand1
|
415
434
|
attr_reader :operand2
|
@@ -422,8 +441,8 @@ module BOAST
|
|
422
441
|
end
|
423
442
|
|
424
443
|
def to_s
|
425
|
-
raise "Ternary operator unsupported in FORTRAN!" if
|
426
|
-
return
|
444
|
+
raise "Ternary operator unsupported in FORTRAN!" if lang == FORTRAN
|
445
|
+
return to_s_c if [C, CL, CUDA].include?( lang )
|
427
446
|
end
|
428
447
|
|
429
448
|
def to_s_c
|
@@ -431,13 +450,15 @@ module BOAST
|
|
431
450
|
s += "(#{@operand1} ? #{@operand2} : #{@operand3})"
|
432
451
|
end
|
433
452
|
|
434
|
-
def
|
453
|
+
def pr
|
435
454
|
s=""
|
436
|
-
s +=
|
437
|
-
s +=
|
438
|
-
s += ";" if [
|
439
|
-
|
455
|
+
s += indent
|
456
|
+
s += to_s
|
457
|
+
s += ";" if [C, CL, CUDA].include?( lang )
|
458
|
+
output.puts s
|
440
459
|
return self
|
441
460
|
end
|
461
|
+
|
442
462
|
end
|
463
|
+
|
443
464
|
end
|
data/lib/BOAST/Parens.rb
CHANGED
@@ -1,32 +1,11 @@
|
|
1
|
-
class Object
|
2
|
-
alias_method :orig_method_missing, :method_missing
|
3
|
-
|
4
|
-
def method_missing(m, *a, &b)
|
5
|
-
#puts "WARNING: unknown #{m}"
|
6
|
-
s=nil
|
7
|
-
klass = begin
|
8
|
-
s = (self.is_a?(Module) ? self : self.class)
|
9
|
-
s.const_get(m)
|
10
|
-
rescue NameError
|
11
|
-
end
|
12
|
-
|
13
|
-
return klass.send(:parens, *a, &b) if klass.respond_to? :parens
|
14
|
-
|
15
|
-
if s == BOAST then
|
16
|
-
STDERR.puts "Warning unkwown function #{m} generated as BOAST::FuncCall!" if BOAST::debug
|
17
|
-
return BOAST::FuncCall::new(m,*a,&b)
|
18
|
-
end
|
19
|
-
|
20
|
-
orig_method_missing m, *a, &b
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
1
|
module BOAST
|
25
2
|
|
26
|
-
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def register_funccall(name)
|
27
6
|
s =<<EOF
|
28
7
|
def self.#{name}(*args)
|
29
|
-
return
|
8
|
+
return FuncCall("#{name}", *args)
|
30
9
|
end
|
31
10
|
EOF
|
32
11
|
eval s
|
data/lib/BOAST/Pragma.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module BOAST
|
2
2
|
|
3
3
|
class Pragma
|
4
|
-
include
|
5
|
-
|
4
|
+
include PrivateStateAccessor
|
5
|
+
include Inspectable
|
6
|
+
extend Functor
|
6
7
|
|
7
8
|
attr_reader :name
|
8
9
|
attr_reader :options
|
@@ -14,7 +15,7 @@ module BOAST
|
|
14
15
|
|
15
16
|
def to_s
|
16
17
|
s = ""
|
17
|
-
if
|
18
|
+
if lang == FORTRAN then
|
18
19
|
s += "$!"
|
19
20
|
else
|
20
21
|
s += "#pragma"
|
@@ -25,10 +26,10 @@ module BOAST
|
|
25
26
|
return s
|
26
27
|
end
|
27
28
|
|
28
|
-
def
|
29
|
+
def pr
|
29
30
|
s=""
|
30
|
-
s +=
|
31
|
-
|
31
|
+
s += to_s
|
32
|
+
output.puts s
|
32
33
|
return self
|
33
34
|
end
|
34
35
|
end
|