Class: BOAST::For
- Inherits:
-
ControlStructure
- Object
- ControlStructure
- BOAST::For
- Includes:
- Annotation
- Defined in:
- lib/BOAST/Language/For.rb
Constant Summary collapse
- ANNOTATIONS =
[ :iterator, :first, :last, :step, :operator ]
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#iterator ⇒ Object
readonly
Returns the value of attribute iterator.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#step ⇒ Object
readonly
Returns the value of attribute step.
Attributes inherited from ControlStructure
Instance Method Summary collapse
-
#close ⇒ self
Closes the For construct (keyword, closing bracket in C like languages).
-
#initialize(iterator, first, last, options = {}, &block) ⇒ For
constructor
Creates a new instance of the For construct.
-
#open ⇒ self
Opens the For construct (keyword, iterator, bounds, step, opening bracket in C like languages).
-
#pr(*args, &block) ⇒ self
Prints the For construct to the BOAST output (see #open).
-
#to_s ⇒ Object
Returns a string representation of the For construct.
-
#unroll(flag = true) ⇒ For
Creates a copy of this For construct with the unroll option set and returns it if it is different from the current unroll flag.
-
#unroll=(val) ⇒ Object
Sets the unroll attribute to val.
-
#unroll? ⇒ Boolean
returns the Boolean evaluation of the unroll attribute.
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_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_use_vla, #set_verbose, #use_vla, #use_vla=, #use_vla?, #verbose, #verbose=, #verbose?
Methods inherited from ControlStructure
Methods included from Inspectable
Constructor Details
#initialize(iterator, first, last, options = {}, &block) ⇒ For
Creates a new instance of the For construct.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/BOAST/Language/For.rb', line 34 def initialize(iterator, first, last, ={}, &block) super() = {:step => 1} .update( ) @options = @iterator = iterator @first = first @last = last @step = [:step] @operator = "<=" @block = block @openmp = [:openmp] @unroll = [:unroll] @args = [:args] if @openmp then if @openmp.kind_of?(Hash) then @openmp = OpenMP::For(@openmp) else @openmp = OpenMP::For({}) end end push_env( :replace_constants => true ) { begin if @step.kind_of?(Variable) then step = @step.constant elsif @step.kind_of?(Expression) then step = eval "#{@step}" else step = @step.to_i end @operator = ">=" if step < 0 rescue STDERR.puts "Warning could not determine sign of step (#{@step}) assuming positive" if [C, CL, CUDA].include?( lang ) and debug? end } end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
12 13 14 |
# File 'lib/BOAST/Language/For.rb', line 12 def block @block end |
#first ⇒ Object (readonly)
Returns the value of attribute first.
9 10 11 |
# File 'lib/BOAST/Language/For.rb', line 9 def first @first end |
#iterator ⇒ Object (readonly)
Returns the value of attribute iterator.
8 9 10 |
# File 'lib/BOAST/Language/For.rb', line 8 def iterator @iterator end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
10 11 12 |
# File 'lib/BOAST/Language/For.rb', line 10 def last @last end |
#step ⇒ Object (readonly)
Returns the value of attribute step.
11 12 13 |
# File 'lib/BOAST/Language/For.rb', line 11 def step @step end |
Instance Method Details
#close ⇒ self
Closes the For construct (keyword, closing bracket in C like languages). The result is printed to the BOAST output.
188 189 190 191 192 193 194 195 196 |
# File 'lib/BOAST/Language/For.rb', line 188 def close decrement_indent_level s = "" s += indent s += end_string output.puts s @openmp.close if @openmp return self end |
#open ⇒ self
Opens the For construct (keyword, iterator, bounds, step, opening bracket in C like languages). The result is printed to the BOAST output.
159 160 161 162 163 164 165 166 167 |
# File 'lib/BOAST/Language/For.rb', line 159 def open @openmp.open if @openmp s="" s += indent s += to_s output.puts s increment_indent_level return self end |
#pr(*args, &block) ⇒ self
174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/BOAST/Language/For.rb', line 174 def pr(*args, &block) args = @args if args.length == 0 and @args block = @block unless block return pr_unroll(*args, &block) if unroll? open if block then block.call(*args) close end return self end |
#to_s ⇒ Object
Returns a string representation of the For construct.
90 91 92 93 |
# File 'lib/BOAST/Language/For.rb', line 90 def to_s s = for_string(@iterator, @first, @last, @step, @operator) return s end |
#unroll(flag = true) ⇒ For
Creates a copy of this For construct with the unroll option set and returns it if it is different from the current unroll flag.
98 99 100 101 102 103 104 105 106 |
# File 'lib/BOAST/Language/For.rb', line 98 def unroll( flag = true ) if flag ^ @unroll then opts = @options.clone opts[:unroll] = flag return For::new(@iterator, @first, @last, opts, &block) else return self end end |
#unroll=(val) ⇒ Object
Sets the unroll attribute to val.
20 21 22 |
# File 'lib/BOAST/Language/For.rb', line 20 def unroll=(val) @unroll = val end |
#unroll? ⇒ Boolean
returns the Boolean evaluation of the unroll attribute.
15 16 17 |
# File 'lib/BOAST/Language/For.rb', line 15 def unroll? return !!@unroll end |