Class: HDLRuby::Low::StringE

Inherits:
Expression 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

Describes a string.

NOTE: This is not synthesizable!

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!, #fix_scope_refnames!, #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

#absolute_ref, #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+.



6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
# File 'lib/HDLRuby/hruby_low.rb', line 6333

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.



6329
6330
6331
# File 'lib/HDLRuby/hruby_low.rb', line 6329

def content
  @content
end

Instance Method Details

#boolean_in_assign2selectObject

Converts booleans in assignments to select operators.



366
367
368
369
370
371
372
# File 'lib/HDLRuby/hruby_low_bool2select.rb', line 366

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.



381
382
383
384
385
386
# File 'lib/HDLRuby/hruby_low_casts_without_expression.rb', line 381

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.



6388
6389
6390
# File 'lib/HDLRuby/hruby_low.rb', line 6388

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.



6363
6364
6365
6366
6367
6368
# File 'lib/HDLRuby/hruby_low.rb', line 6363

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.



6412
6413
6414
6415
6416
6417
6418
6419
6420
# File 'lib/HDLRuby/hruby_low.rb', line 6412

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.



6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
# File 'lib/HDLRuby/hruby_low.rb', line 6423

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.



6373
6374
6375
6376
6377
6378
6379
6380
# File 'lib/HDLRuby/hruby_low.rb', line 6373

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.



6393
6394
6395
6396
6397
6398
6399
# File 'lib/HDLRuby/hruby_low.rb', line 6393

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.



6402
6403
6404
6405
6406
6407
6408
6409
# File 'lib/HDLRuby/hruby_low.rb', line 6402

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.



6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
# File 'lib/HDLRuby/hruby_low.rb', line 6436

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)


6351
6352
6353
6354
6355
6356
6357
6358
# File 'lib/HDLRuby/hruby_low.rb', line 6351

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.



511
512
513
514
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 511

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

#hashObject

Hash function.



6383
6384
6385
# File 'lib/HDLRuby/hruby_low.rb', line 6383

def hash
    return @args.hash
end

#immutable?Boolean

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

Returns:

  • (Boolean)


6345
6346
6347
6348
# File 'lib/HDLRuby/hruby_low.rb', line 6345

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

#map_args!(&ruby_block) ⇒ Object

Maps on the arguments.



1944
1945
1946
1947
1948
1949
1950
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1944

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.



1953
1954
1955
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1953

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

#to_highObject

Creates a new high string expression.



557
558
559
560
# File 'lib/HDLRuby/hruby_low2high.rb', line 557

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.



2460
2461
2462
2463
2464
2465
2466
# File 'lib/HDLRuby/hruby_verilog.rb', line 2460

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.



1568
1569
1570
1571
1572
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 1568

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