Class: ClassHDL::HDLFunction

Inherits:
Object
  • Object
show all
Defined in:
lib/tdl/class_hdl/hdl_function.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(belong_to_module, name, return_type, *argvs) ⇒ HDLFunction

Returns a new instance of HDLFunction.



62
63
64
65
66
67
68
# File 'lib/tdl/class_hdl/hdl_function.rb', line 62

def initialize(belong_to_module,name,return_type,*argvs)
    @opertor_chains = []
    @name = name
    @argvs = argvs
    @return_type = return_type
    @belong_to_module = belong_to_module
end

Instance Attribute Details

#belong_to_moduleObject (readonly)

Returns the value of attribute belong_to_module.



60
61
62
# File 'lib/tdl/class_hdl/hdl_function.rb', line 60

def belong_to_module
  @belong_to_module
end

#nameObject

Returns the value of attribute name.



57
58
59
# File 'lib/tdl/class_hdl/hdl_function.rb', line 57

def name
  @name
end

#open_ivokeObject

Returns the value of attribute open_ivoke.



58
59
60
# File 'lib/tdl/class_hdl/hdl_function.rb', line 58

def open_ivoke
  @open_ivoke
end

#opertor_chainsObject

Returns the value of attribute opertor_chains.



57
58
59
# File 'lib/tdl/class_hdl/hdl_function.rb', line 57

def opertor_chains
  @opertor_chains
end

#return_typeObject (readonly)

Returns the value of attribute return_type.



59
60
61
# File 'lib/tdl/class_hdl/hdl_function.rb', line 59

def return_type
  @return_type
end

Instance Method Details

#inst_portObject



70
71
72
# File 'lib/tdl/class_hdl/hdl_function.rb', line 70

def inst_port
    return @argvs.map{|e| "#{e.inst_port[0]} #{e.inst_port[1]}" }.join(',')
end

#instanceObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/tdl/class_hdl/hdl_function.rb', line 74

def instance
    str = []
    if @return_type
        if @return_type.is_a? EnumStruct
            str.push "function #{@return_type.typedef_name} #{@name}(#{inst_port}); "
        elsif @return_type.is_a? StructMeta
            str.push "function #{@return_type.name} #{@name}(#{inst_port}); "
        else
            str.push "function #{@return_type.to_s} #{@name}(#{inst_port}); "
        end
    else
        str.push "function #{@name}(#{inst_port}); "
    end

    opertor_chains.each do |op|
        unless op.is_a? OpertorChain
            str.push op.instance(:assign).gsub(/^./){ |m| "    #{m}"}
        else 
            unless op.slaver
                rel_str = ClassHDL.compact_op_ch(op.instance(:assign,belong_to_module))
                str.push "    #{rel_str};"
            end
        end
        
    end
    str.push "endfunction:#{@name}\n"
    str.join("\n")
end

#ivoked(*fargvs) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/tdl/class_hdl/hdl_function.rb', line 103

def ivoked(*fargvs)
    str = fargvs.map do |e| 
        if e.is_a? OpertorChain
            e.slaver = true 
        end
        
        if e.instance_of? String
            "\"#{e}\""
        else 
            e.to_s 
        end
    end.join(",")

    return "#{@name}(#{str})".to_nq
end