Class: BOAST::Procedure

Inherits:
Object
  • Object
show all
Extended by:
Functor
Includes:
Annotation, Inspectable, PrivateStateAccessor
Defined in:
lib/BOAST/Language/Procedure.rb

Constant Summary collapse

ANNOTATIONS =
[ :name, :parameters, :constants, :locals ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Functor

extended

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 Inspectable

#inspect

Constructor Details

#initialize(name, parameters = [], properties = {}, &block) ⇒ Procedure

Creates a new Procedure

Parameters:

  • name (#to_s)

    Procedure identifier

  • parameters (Array<Variable>) (defaults to: [])

    list of the procedure parameters.

  • properties (Hash) (defaults to: {})

    set of named properties for the Procedure.

Options Hash (properties):

  • :constants (Array<Variables>)

    list of constant variables that are used in the Procedure. (see parameter in Fortran).

  • :headers (Array<#to_s>)

    list of headers that need to be included in order to compile the Procedure

  • :return (Variable)

    a Variable that will be returned. Procedure becomes a function, return type is the same as the returned variable. The variable will be declared at the start of the procedure.

  • :functions (Procedure)

    sub functions used by this Procedure (FORTRAN return type of functions are problematic)



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/BOAST/Language/Procedure.rb', line 26

def initialize(name, parameters=[], properties={}, &block)
  @name = name
  @parameters = parameters
  @constants = properties[:constants]
  @constants = [] unless @constants
  @locals = properties[:locals]
  @locals = [] unless @locals
  @block = block
  @properties = properties
  @headers = properties[:headers]
  @headers = [] unless @headers
end

Instance Attribute Details

#constantsObject (readonly)

Returns the value of attribute constants.



13
14
15
# File 'lib/BOAST/Language/Procedure.rb', line 13

def constants
  @constants
end

#headersObject (readonly)

Returns the value of attribute headers.



16
17
18
# File 'lib/BOAST/Language/Procedure.rb', line 16

def headers
  @headers
end

#localsObject (readonly)

Returns the value of attribute locals.



14
15
16
# File 'lib/BOAST/Language/Procedure.rb', line 14

def locals
  @locals
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/BOAST/Language/Procedure.rb', line 11

def name
  @name
end

#parametersObject (readonly)

Returns the value of attribute parameters.



12
13
14
# File 'lib/BOAST/Language/Procedure.rb', line 12

def parameters
  @parameters
end

#propertiesObject (readonly)

Returns the value of attribute properties.



15
16
17
# File 'lib/BOAST/Language/Procedure.rb', line 15

def properties
  @properties
end

Instance Method Details

#boast_header(lang = C) ⇒ Object



40
41
42
43
44
45
# File 'lib/BOAST/Language/Procedure.rb', line 40

def boast_header(lang=C)
  s = boast_header_s(lang)
  s << ";\n"
  output.print s
  return self
end

#call(*parameters) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/BOAST/Language/Procedure.rb', line 47

def call(*parameters)
  prefix = ""
  prefix << "call " if lang==FORTRAN and @properties[:return].nil?
  f = FuncCall::new(@name, *parameters, :return => @properties[:return] )
  f.prefix = prefix
  return f
end

#ckernel(*args) ⇒ Object

Returns a CKernel with the Procedure as entry point.



61
62
63
64
65
66
67
68
# File 'lib/BOAST/Language/Procedure.rb', line 61

def ckernel(* args)
  old_output = output
  k = CKernel::new(* args)
  k.procedure = self
  self.pr
  set_output( old_output )
  return k
end

#closeObject



55
56
57
58
# File 'lib/BOAST/Language/Procedure.rb', line 55

def close
  return close_fortran if lang==FORTRAN
  return close_c if [C, CL, CUDA].include?( lang )
end

#declObject



79
80
81
82
# File 'lib/BOAST/Language/Procedure.rb', line 79

def decl
  return decl_fortran if lang==FORTRAN
  return decl_c if [C, CL, CUDA].include?( lang )
end

#openObject



84
85
86
87
# File 'lib/BOAST/Language/Procedure.rb', line 84

def open
  return open_fortran if lang==FORTRAN
  return open_c if [C, CL, CUDA].include?( lang )
end

#prObject



70
71
72
73
74
75
76
77
# File 'lib/BOAST/Language/Procedure.rb', line 70

def pr
  open
  if @block then
    @block.call
    close
  end
  return self
end

#to_sObject



89
90
91
92
# File 'lib/BOAST/Language/Procedure.rb', line 89

def to_s
  return decl_c_s if [C, CL, CUDA].include?( lang )
  return to_s_fortran if lang==FORTRAN
end