Class: BOAST::Index
- Inherits:
-
Expression
- Object
- Expression
- BOAST::Index
- Defined in:
- lib/BOAST/Index.rb
Instance Attribute Summary collapse
-
#indexes ⇒ Object
readonly
Returns the value of attribute indexes.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Attributes inherited from Expression
#operand1, #operand2, #operator
Instance Method Summary collapse
-
#initialize(source, indexes) ⇒ Index
constructor
A new instance of Index.
- #pr ⇒ Object
- #to_s ⇒ Object
- #to_s_c ⇒ Object
- #to_s_c_reversed ⇒ Object
- #to_s_fortran ⇒ Object
- #to_s_texture ⇒ Object
- #to_var ⇒ Object
Methods inherited from Expression
Methods included from Functor
Methods included from TypeTransition
#get_transition, #set_transition, #transition
Methods included from Inspectable
Methods included from Arithmetic
#!, #!=, #*, #+, #-, #-@, #/, #<, #<=, #==, #===, #>, #>=, #address, #and, #components, #dereference, #or
Methods included from PrivateStateAccessor
private_boolean_state_accessor, private_state_accessor
Constructor Details
#initialize(source, indexes) ⇒ Index
Returns a new instance of Index.
7 8 9 10 |
# File 'lib/BOAST/Index.rb', line 7 def initialize(source, indexes) @source = source @indexes = indexes end |
Instance Attribute Details
#indexes ⇒ Object (readonly)
Returns the value of attribute indexes.
5 6 7 |
# File 'lib/BOAST/Index.rb', line 5 def indexes @indexes end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
4 5 6 |
# File 'lib/BOAST/Index.rb', line 4 def source @source end |
Instance Method Details
#pr ⇒ Object
130 131 132 133 134 135 136 137 |
# File 'lib/BOAST/Index.rb', line 130 def pr s="" s += indent s += to_s s += ";" if [C, CL, CUDA].include?( lang ) output.puts s return self end |
#to_s ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/BOAST/Index.rb', line 17 def to_s if get_replace_constants then begin const = @source.constant indxs = @indexes.reverse dims = @source.dimension.reverse (0...dims.length).each { |indx| dim = dims[indx] s = "#{indxs[indx]}" if dim.val2 then s += " - (#{dim.val1})" elsif 0 != get_array_start then s += " - (#{get_array_start})" end ind = eval(s) ind = ind.to_i const = const[ind] } return "#{const}#{@source.type.suffix}" rescue Exception => e end end return to_s_fortran if lang == FORTRAN return to_s_c if [C, CL, CUDA].include?( lang ) end |
#to_s_c ⇒ Object
123 124 125 126 127 128 |
# File 'lib/BOAST/Index.rb', line 123 def to_s_c return to_s_texture if @source.texture sub = to_s_c_reversed s = "#{@source}[" + sub + "]" return s end |
#to_s_c_reversed ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/BOAST/Index.rb', line 95 def to_s_c_reversed indxs = @indexes.reverse dims = @source.dimension.reverse ss = nil (0...dims.length).each { |indx| s = "" dim = dims[indx] s += "#{indxs[indx]}" if dim.val2 then s += " - (#{dim.val1})" elsif 0 != get_array_start then s += " - (#{get_array_start})" end if ss then if dim.size then s += " + (#{dim.size}) * " elsif dim.val2 then s += " + (#{dim.val2} - (#{dim.val1}) + 1) * " else raise "Unkwown dimension size!" end s += "(#{ss})" end ss = s } return ss end |
#to_s_fortran ⇒ Object
43 44 45 46 47 |
# File 'lib/BOAST/Index.rb', line 43 def to_s_fortran s = "" s += "#{@source}(#{@indexes.join(", ")})" return s end |
#to_s_texture ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/BOAST/Index.rb', line 49 def to_s_texture raise "Unsupported language #{lang} for texture!" if not [CL, CUDA].include?( lang ) raise "Write is unsupported for textures!" if not ( @source.constant or @source.direction == :in ) dim_number = 1 if @source.dimension then dim_number == @source.dimension.size end raise "Unsupported number of dimension: #{dim_number}!" if dim_number > 3 s = "" if lang == CL then s += "as_#{@source.type.decl}(" s += "read_imageui(#{@source}, #{@source.sampler}, " if dim_number == 1 then s += "int2(#{@indexes[0]},0)" else if dim_number == 2 then s += "int2(" else s += "int3(" end s += "#{@indexes.join(", ")})" end s += ")" if @source.type.size == 4 then s += ".x" elsif @source.type.size == 8 then s += ".xy" end s += ")" else s += "tex#{dim_number}Dfetch(#{@source}," if dim_number == 1 then s += "#{@indexes[0]}" else if dim_number == 2 then s += "int2(" else s += "int3(" end s += "#{@indexes.join(", ")})" end s += ")" end return s end |
#to_var ⇒ Object
12 13 14 15 |
# File 'lib/BOAST/Index.rb', line 12 def to_var var = @source.copy("#{self}", :const => nil, :constant => nil, :dim => nil, :dimension => nil, :direction => nil, :dir => nil) return var end |