Class: BOAST::Slice
- Inherits:
-
Expression
- Object
- Expression
- BOAST::Slice
- Defined in:
- lib/BOAST/Language/Slice.rb
Defined Under Namespace
Classes: SliceItem
Constant Summary
Constants inherited from Expression
Instance Attribute Summary collapse
-
#alignment ⇒ Object
Returns the value of attribute alignment.
-
#slices ⇒ Object
readonly
Returns the value of attribute slices.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Attributes inherited from Expression
#operand1, #operand2, #operator
Instance Method Summary collapse
-
#[](*args) ⇒ Slice, Index
Indexes a Slice.
- #align? ⇒ Boolean
- #dimension ⇒ Object
- #dimension? ⇒ Boolean
-
#initialize(source, *slices) ⇒ Slice
constructor
A new instance of Slice.
- #pr ⇒ Object
- #set_align(align) ⇒ Object
- #to_s ⇒ Object
- #to_var ⇒ Object
Methods inherited from Expression
Methods included from Functor
Methods included from Annotation
#annotate_array, #annotate_indepth?, #annotate_scalar, #annotate_var, #annotation, #annotation_identifier
Methods included from PrivateStateAccessor
#address_size, #address_size=, #annotate, #annotate=, #annotate?, #annotate_indepth_list, #annotate_indepth_list=, #annotate_level, #annotate_level=, #annotate_list, #annotate_list=, #architecture, #architecture=, #array_start, #array_start=, #chain_code, #chain_code=, #chain_code?, #debug, #debug=, #debug?, #debug_kernel_source, #debug_kernel_source=, #debug_kernel_source?, #debug_source, #debug_source=, #debug_source?, #decl_module, #decl_module=, #decl_module?, #default_align, #default_align=, #default_int_signed, #default_int_signed=, #default_int_signed?, #default_int_size, #default_int_size=, #default_real_size, #default_real_size=, #default_type, #default_type=, #disable_openmp, #disable_openmp=, #disable_openmp?, #executable, #executable=, #executable?, #ffi, #ffi=, #ffi?, #fortran_line_length, #fortran_line_length=, #get_address_size, #get_annotate, #get_annotate_indepth_list, #get_annotate_level, #get_annotate_list, #get_architecture, #get_array_start, #get_chain_code, #get_debug, #get_debug_kernel_source, #get_debug_source, #get_decl_module, #get_default_align, #get_default_int_signed, #get_default_int_size, #get_default_real_size, #get_default_type, #get_disable_openmp, #get_executable, #get_ffi, #get_fortran_line_length, #get_indent_increment, #get_indent_level, #get_keep_temp, #get_lang, #get_model, #get_optimizer_log, #get_optimizer_log_file, #get_output, #get_replace_constants, #get_synchro, #get_use_vla, #get_verbose, #indent_increment, #indent_increment=, #indent_level, #indent_level=, #keep_temp, #keep_temp=, #keep_temp?, #lang, #lang=, #model, #model=, #optimizer_log, #optimizer_log=, #optimizer_log?, #optimizer_log_file, #optimizer_log_file=, #output, #output=, #replace_constants, #replace_constants=, #replace_constants?, #set_address_size, #set_annotate, #set_annotate_indepth_list, #set_annotate_level, #set_annotate_list, #set_architecture, #set_array_start, #set_chain_code, #set_debug, #set_debug_kernel_source, #set_debug_source, #set_decl_module, #set_default_align, #set_default_int_signed, #set_default_int_size, #set_default_real_size, #set_default_type, #set_disable_openmp, #set_executable, #set_ffi, #set_fortran_line_length, #set_indent_increment, #set_indent_level, #set_keep_temp, #set_lang, #set_model, #set_optimizer_log, #set_optimizer_log_file, #set_output, #set_replace_constants, #set_synchro, #set_use_vla, #set_verbose, #synchro, #synchro=, #use_vla, #use_vla=, #use_vla?, #verbose, #verbose=, #verbose?
Methods included from TypeTransition
#get_transition, #set_transition, #transition
Methods included from Inspectable
Methods included from Arithmetic
#!, #!=, #*, #**, #+, #+@, #-, #-@, #/, #<, #<=, #==, #===, #>, #>=, #and, #cast, #coerce, #components, #dereference, #or, #reference
Constructor Details
#initialize(source, *slices) ⇒ Slice
Returns a new instance of Slice.
94 95 96 97 98 99 |
# File 'lib/BOAST/Language/Slice.rb', line 94 def initialize(source, *slices) raise "Cannot slice a non array Variable!" unless source.dimension? raise "Invalid slice!" if slices.length != source.dimension.length @source = source @slices = slices.collect{ |s| SliceItem::new(s) } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class BOAST::Expression
Instance Attribute Details
#alignment ⇒ Object
Returns the value of attribute alignment.
92 93 94 |
# File 'lib/BOAST/Language/Slice.rb', line 92 def alignment @alignment end |
#slices ⇒ Object (readonly)
Returns the value of attribute slices.
91 92 93 |
# File 'lib/BOAST/Language/Slice.rb', line 91 def slices @slices end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
90 91 92 |
# File 'lib/BOAST/Language/Slice.rb', line 90 def source @source end |
Instance Method Details
#[](*args) ⇒ Slice, Index
Indexes a BOAST::Slice
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/BOAST/Language/Slice.rb', line 158 def [](*args) slice = false args.each { |a| slice = true if a.kind_of?(Range) or a.kind_of?(Array) or a.kind_of?(Symbol) or a.nil? } new_args = [] slices.each_with_index { |s, i| unless s.scalar? raise "Invalid slice!" if args.length == 0 new_arg = SliceItem::new(args.shift) new_arg.recurse!(s, @source.dimension[i]) new_args.push new_arg else new_args.push s end } if slice then return Slice::new(@source, *new_args) else return Index::new(@source, *(new_args.collect(&:first))) end end |
#align? ⇒ Boolean
137 138 139 |
# File 'lib/BOAST/Language/Slice.rb', line 137 def align? return @alignment end |
#dimension ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/BOAST/Language/Slice.rb', line 105 def dimension dims = [] slices.each_with_index { |slice, i| unless slice.scalar? then if slice.all? then if source.dimension[i].size then dims.push Dimension::new( source.dimension[i].size ) else dims.push Dimension::new end else dims.push Dimension::new( slice.length ) end end } return dims end |
#dimension? ⇒ Boolean
101 102 103 |
# File 'lib/BOAST/Language/Slice.rb', line 101 def dimension? true end |
#pr ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/BOAST/Language/Slice.rb', line 128 def pr s="" s << indent s << to_s s << ";" if [C, CL, CUDA].include?( lang ) output.puts s return self end |
#set_align(align) ⇒ Object
141 142 143 144 |
# File 'lib/BOAST/Language/Slice.rb', line 141 def set_align(align) @alignment = align return self end |
#to_s ⇒ Object
123 124 125 126 |
# File 'lib/BOAST/Language/Slice.rb', line 123 def to_s return to_s_fortran if lang == FORTRAN return to_s_c if [C, CL, CUDA].include?( lang ) end |
#to_var ⇒ Object
146 147 148 149 |
# File 'lib/BOAST/Language/Slice.rb', line 146 def to_var var = @source.copy("#{self}", :const => nil, :constant => nil, :dim => nil, :dimension => nil, :direction => nil, :dir => nil, :align => alignment) return var end |