Class: HDLRuby::Low::StringE

Inherits:
Expression
  • Object
show all
Defined in:
lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2vhd.rb,
lib/HDLRuby/hruby_verilog.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_mutable.rb,
lib/HDLRuby/hruby_low_fix_types.rb,
lib/HDLRuby/hruby_low_bool2select.rb,
lib/HDLRuby/hruby_low_casts_without_expression.rb

Overview

Extends the StringE class with functionality for extracting expressions from cast.

Direct Known Subclasses

High::StringE

Constant Summary

Constants included from Low2Symbol

Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable

Instance Attribute Summary collapse

Attributes inherited from Expression

#type

Attributes included from Hparent

#parent

Instance Method Summary collapse

Methods inherited from Expression

#boolean?, #break_types!, #each_ref_deep, #extract_selects_to!, #leftvalue?, #replace_expressions!, #replace_names!, #rightvalue?, #set_type!, #signal2subs!, #statement, #to_c, #to_c_expr, #to_hdr, #use_name?

Methods included from Low2Symbol

#to_sym

Methods included from Hparent

#hierarchy, #no_parent!, #scope

Constructor Details

#initialize(content, *args) ⇒ StringE

Creates a new string whose content is +str+ and is modified using the objects of +args+.



6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
# File 'lib/HDLRuby/hruby_low.rb', line 6165

def initialize(content,*args)
    super(StringT)
    # Checks and set the content.
    @content = content.to_s
    # Process the arguments.
    @args = args.map do |arg|
        arg.parent = self 
        arg
    end
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



6161
6162
6163
# File 'lib/HDLRuby/hruby_low.rb', line 6161

def content
  @content
end

Instance Method Details

#boolean_in_assign2selectObject

Converts booleans in assignments to select operators.



351
352
353
354
355
356
357
# File 'lib/HDLRuby/hruby_low_bool2select.rb', line 351

def boolean_in_assign2select
    # Apply on the content.
    # Apply on the arguments.
    return StringE.new(self.content.clone,*self.each_arg.map do |arg|
        arg.boolean_in_assign2select
    end)
end

#casts_without_expression!Object

Extracts the expressions from the casts.



369
370
371
372
373
374
# File 'lib/HDLRuby/hruby_low_casts_without_expression.rb', line 369

def casts_without_expression!
    # return StringE.new(self.content,
    #                    *self.each_arg.map(&:casts_without_expression))
    self.map_args! {|arg| arg.casts_without_expression! }
    return self
end

#cloneObject

Clones the string.



6220
6221
6222
# File 'lib/HDLRuby/hruby_low.rb', line 6220

def clone
    return StringE.new(@content.clone,*@args.map {|arg| arg.clone})
end

#each_arg(&ruby_block) ⇒ Object

Iterates over each argument.

Returns an enumerator if no ruby block is given.



6195
6196
6197
6198
6199
6200
# File 'lib/HDLRuby/hruby_low.rb', line 6195

def each_arg(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_arg) unless ruby_block
    # A ruby block? First apply it to each argument.
    @args.each(&ruby_block)
end

#each_block(&ruby_block) ⇒ Object

Iterates over the sub blocks.



6244
6245
6246
6247
6248
6249
6250
6251
6252
# File 'lib/HDLRuby/hruby_low.rb', line 6244

def each_block(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_block) unless ruby_block
    # A ruby block?
    # Recurse on each argument.
    @args.each do |arg|
        arg.each_block(&ruby_block) if arg.respond_to?(:each_block)
    end
end

#each_block_deep(&ruby_block) ⇒ Object

Iterates over all the blocks contained in the current block.



6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
# File 'lib/HDLRuby/hruby_low.rb', line 6255

def each_block_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_block_deep) unless ruby_block
    # A ruby block?
    # Recurse on each argument.
    @args.each do |arg|
        if arg.respond_to?(:each_block_deep) then
            arg.each_block_deep(&ruby_block)
        end
    end
end

#each_deep(&ruby_block) ⇒ Object

Iterates over each object deeply.

Returns an enumerator if no ruby block is given.



6205
6206
6207
6208
6209
6210
6211
6212
# File 'lib/HDLRuby/hruby_low.rb', line 6205

def each_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_deep) unless ruby_block
    # A ruby block? First apply it to current.
    ruby_block.call(self)
    # Then apply on the arguments.
    self.each_arg(&ruby_block)
end

#each_node(&ruby_block) ⇒ Object

Iterates over the expression children if any.



6225
6226
6227
6228
6229
6230
6231
# File 'lib/HDLRuby/hruby_low.rb', line 6225

def each_node(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_node) unless ruby_block
    # A ruby block?
    # Apply it on each argument.
    @args.each(&ruby_block)
end

#each_node_deep(&ruby_block) ⇒ Object

Iterates over the nodes deeply if any.



6234
6235
6236
6237
6238
6239
6240
6241
# File 'lib/HDLRuby/hruby_low.rb', line 6234

def each_node_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_node_deep) unless ruby_block
    # A ruby block? First apply it to current.
    ruby_block.call(self)
    # And apply it on each argument.
    @args.each(&ruby_block)
end

#each_statement_deep(&ruby_block) ⇒ Object

Iterates over all the statements contained in the current block.



6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
# File 'lib/HDLRuby/hruby_low.rb', line 6268

def each_statement_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_statement_deep) unless ruby_block
    # A ruby block?
    # Apply it on self.
    ruby_block.call(self)
    # Recurse on each argument.
    @args.each do |arg|
        if arg.respond_to?(:each_statement_deep) then
            arg.each_statement_deep(&ruby_block)
        end
    end
end

#eql?(obj) ⇒ Boolean

Comparison for hash: structural comparison.

Returns:

  • (Boolean)


6183
6184
6185
6186
6187
6188
6189
6190
# File 'lib/HDLRuby/hruby_low.rb', line 6183

def eql?(obj)
    return false unless obj.is_a?(StringE)
    return false unless @content.eql?(obj.content)
    return false if @args.each.zip(obj.each_arg).any? do |a0,a1|
        !a0.eql?(a1)
    end
    return true
end

#explicit_types(type = nil) ⇒ Object

Explicit the types conversions in the concat where +type+ is the expected type of the condition if any.



479
480
481
482
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 479

def explicit_types(type = nil)
    return StringE.new(self.content, 
                       *self.each_arg.map(&:explicit_types))
end

#hashObject

Hash function.



6215
6216
6217
# File 'lib/HDLRuby/hruby_low.rb', line 6215

def hash
    return @args.hash
end

#immutable?Boolean

Tells if the expression is immutable (cannot be written.)

Returns:

  • (Boolean)


6177
6178
6179
6180
# File 'lib/HDLRuby/hruby_low.rb', line 6177

def immutable?
    # String objects are always immutable.
    true
end

#map_args!(&ruby_block) ⇒ Object

Maps on the arguments.



2009
2010
2011
2012
2013
2014
2015
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 2009

def map_args!(&ruby_block)
    @args.map! do |arg|
        arg = ruby_block.call(arg)
        arg.parent = self unless arg.parent
        arg
    end
end

#map_nodes!(&ruby_block) ⇒ Object Also known as: map_expressions!

Maps on the children.



2018
2019
2020
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 2018

def map_nodes!(&ruby_block)
    self.map_args!(&ruby_block)
end

#to_highObject

Creates a new high string expression.



515
516
517
518
# File 'lib/HDLRuby/hruby_low2high.rb', line 515

def to_high
    return HDLRuby::High::StringE.new(self.content,
                        *self.each_arg.map {|arg| arg.to_high })
end

#to_verilog(spc = 3) ⇒ Object

Converts the system to Verilog code.



2260
2261
2262
2263
2264
2265
2266
# File 'lib/HDLRuby/hruby_verilog.rb', line 2260

def to_verilog(spc = 3)
    code = "\"#{Low.v_string(self.content)}" +
        "#{self.each_arg.map do |arg| 
        to.to_verilog
    end.join(",")}\""
    return code
end

#to_vhdl(level = 0, std_logic = false) ⇒ Object

Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.



1533
1534
1535
1536
1537
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 1533

def to_vhdl(level = 0, std_logic = false)
    # Generate a report statement.
    return "\"#{Low2VHDL.vhdl_string(self.content)}\"" +
        self.each_arg.map { |arg| arg.to_vhdl }.join(" & ")
end