Class: HDLRuby::High::Value

Inherits:
Low::Value show all
Includes:
Enumerable, HExpression, Vprocess
Defined in:
lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/hruby_rsim.rb,
lib/HDLRuby/hruby_rcsim.rb

Overview

Describes a value.

Constant Summary

Constants included from Low::Low2Symbol

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

Instance Attribute Summary

Attributes included from HExpression

#systemT, #type

Attributes inherited from Low::Value

#content

Attributes inherited from Low::Expression

#type

Attributes included from Low::Hparent

#parent

Instance Method Summary collapse

Methods included from Enumerable

#hsize, #seach

Methods included from Vprocess

#as, #cast, #coerce, concat, #eql?, #impedence?, #to_f, #to_i, #to_vstr, #trunc, #zero?

Methods included from HExpression

#<=>, #[], #as, #coerce, #heach, #hsize, #htimes, #hupto, #inout, #input, #ljust, #lr, #ls, #match_type, #mux, orig_operator, #orig_operator, #output, #rjust, #rr, #rs, #sdownto, #seach, #sext, #stimes, #supto, #to_bit, #to_signed, #to_unsigned, #zext

Methods inherited from Low::Value

#<=>, #boolean_in_assign2select, #casts_without_expression!, #clone, #each_deep, #eql?, #even?, #explicit_types, #hash, #immutable?, #initialize, #odd?, #set_content!, #to_arith, #to_c, #to_c_expr, #to_c_make, #to_ch, #to_getrange, #to_hdr, #to_high, #to_i, #to_verilog, #to_vhdl, #to_viz_node, #width

Methods inherited from Low::Expression

#boolean?, #break_types!, #clone, #each_node, #each_node_deep, #each_ref_deep, #eql?, #explicit_types, #extract_selects_to!, #fix_scope_refnames!, #hash, #immutable?, #initialize, #leftvalue?, #map_nodes!, #replace_expressions!, #replace_names!, #rightvalue?, #set_type!, #signal2subs!, #statement, #to_c, #to_c_expr, #to_hdr, #to_high, #to_vhdl, #to_viz_names, #use_name?

Methods included from Low::Low2Symbol

#to_sym

Methods included from Low::Hparent

#absolute_ref, #hierarchy, #no_parent!, #scope

Constructor Details

This class inherits a constructor from HDLRuby::Low::Value

Instance Method Details

#constant?Boolean

Tell if the expression is constant.

Returns:

  • (Boolean)


3584
3585
3586
3587
# File 'lib/HDLRuby/hruby_high.rb', line 3584

def constant?
    # A value is a constant.
    return true
end

#each(&ruby_block) ⇒ Object

Iterate over the elements.

Returns an enumerator if no ruby block is given.



3611
3612
3613
3614
3615
3616
3617
3618
# File 'lib/HDLRuby/hruby_high.rb', line 3611

def each(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each) unless ruby_block
    # A block? Apply it on each element.
    self.type.range.heach do |i|
      yield(self.content[i])
    end
end

#execute(mode) ⇒ Object

Executes the expression.



1047
1048
1049
# File 'lib/HDLRuby/hruby_rsim.rb', line 1047

def execute(mode)
    return self
end

#init_sim(systemT) ⇒ Object

Initialize the simulation for system +systemT+.



1040
1041
1042
# File 'lib/HDLRuby/hruby_rsim.rb', line 1040

def init_sim(systemT)
    # Nothing to do.
end

#to_exprObject

Converts to a new expression.



3590
3591
3592
# File 'lib/HDLRuby/hruby_high.rb', line 3590

def to_expr
    return self.to_value
end

#to_lowObject

Converts the value to HDLRuby::Low.



3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
# File 'lib/HDLRuby/hruby_high.rb', line 3595

def to_low
    # Clone the content if possible
    content = self.content.frozen? ? self.content : self.content.clone
    # Create and return the resulting low-level value
    # return HDLRuby::Low::Value.new(self.type.to_low,self.content)
    valueL = HDLRuby::Low::Value.new(self.type.to_low,self.content)
    # # For debugging: set the source high object 
    # valueL.properties[:low2high] = self.hdr_id
    # self.properties[:high2low] = valueL
    return valueL
end

#to_rcsimObject

Generate the C description of the value.



898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
# File 'lib/HDLRuby/hruby_rcsim.rb', line 898

def to_rcsim
    # Create the value C object.
    if self.content.is_a?(::Integer) then
        # puts "self.type.width=#{self.type.width} and content=#{self.content}" ; $stdout.flush
        if self.type.width <= 64 then
            if self.content.bit_length <= 63 then
                return RCSim.rcsim_make_value_numeric(self.type.to_rcsim,
                                                      self.content)
            else
                return RCSim.rcsim_make_value_numeric(self.type.to_rcsim,
                                                      self.content & 0xFFFFFFFFFFFF)
            end
        else
            if self.content < 0 then
                str = (2**self.type.width + self.content).to_s(2)
                str = "1" * (self.type.width-str.length) + str
            else
                str = self.content.to_s(2)
                str = "0" * (self.type.width-str.length) + str
            end
            # puts "now str=#{str} (#{str.length})" ; $stdout.flush
            return RCSim.rcsim_make_value_bitstring(self.type.to_rcsim,
                                                    str.reverse)
        end
    else
        return RCSim.rcsim_make_value_bitstring(self.type.to_rcsim,
                                                self.content.to_s.reverse)
    end
end

#to_valueObject

Converts to a new value.



3577
3578
3579
3580
3581
# File 'lib/HDLRuby/hruby_high.rb', line 3577

def to_value
    # # Already a value.
    # self
    return Value.new(self.type,self.content)
end

#to_value?Boolean

Tell if the expression can be converted to a value.

Returns:

  • (Boolean)


3572
3573
3574
# File 'lib/HDLRuby/hruby_high.rb', line 3572

def to_value?
    return true
end