Class: RubyHDL::High::TypeVector
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes a vector type.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
The base type of the vector.
-
#range ⇒ Object
readonly
The range of the vector.
Instance Method Summary collapse
-
#base? ⇒ Boolean
Tells if the type has a base.
-
#dir ⇒ Object
Gets the direction of the range.
-
#direction ⇒ Object
Get the direction of the type, little or big endian.
-
#each_type_deep(&ruby_block) ⇒ Object
(also: #each_deep)
Iterates over the types deeply if any.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#equivalent?(type) ⇒ Boolean
Tell if +type+ is equivalent to current type.
-
#fixed? ⇒ Boolean
Tells if the type is fixed point.
-
#float? ⇒ Boolean
Tells if the type is floating point.
-
#hash ⇒ Object
Hash function.
-
#initialize(name, base, range) ⇒ TypeVector
constructor
Creates a new vector type named +name+ from +base+ type and with +range+.
-
#max ⇒ Object
Gets the type max value if any.
-
#min ⇒ Object
Gets the type min value if any.
-
#signed? ⇒ Boolean
Tells if the type signed.
-
#size ⇒ Object
Gets the size of the type in number of base elements.
-
#unsigned? ⇒ Boolean
Tells if the type is unsigned.
-
#vector? ⇒ Boolean
Tells if the type of of vector kind.
-
#width ⇒ Object
Gets the bitwidth of the type, nil for undefined.
Methods inherited from Type
#[], #binary, #comp_operator, #constant, #define_operator, #define_operator_with_context, #each_overload, #hierarchical?, #htype?, #inner, #leaf?, #left, #name=, #range?, #register, #regular?, #right, #struct?, #to_type, #to_vector, #typedef, #types?, #unary
Methods included from HDLRuby::Tprocess
#&, #*, #+, #+@, #-@, #/, #<<, #==, #abs, #lr, #make, #resolve, #slice, #~
Constructor Details
#initialize(name, base, range) ⇒ TypeVector
Creates a new vector type named +name+ from +base+ type and with +range+. NOTE: if +range+ is a positive integer it is converted to (range-1)..0, if it is a negative integer it is converted to 0..(-range-1)
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1013 def initialize(name,base,range) # Initialize the type. super(name) # Check and set the base unless base.is_a?(Type) raise AnyError, "Invalid class for VectorType base: #{base.class}." end @base = base # Check and set the range. if range.respond_to?(:to_i) then # Integer case: convert to 0..(range-1). range = range > 0 ? (range-1)..0 : 0..(-range-1) elsif # Other cases: assume there is a first and a last to create # the range. range = range.first..range.last end @range = range end |
Instance Attribute Details
#base ⇒ Object (readonly)
The base type of the vector
993 994 995 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 993 def base @base end |
#range ⇒ Object (readonly)
The range of the vector.
1006 1007 1008 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1006 def range @range end |
Instance Method Details
#base? ⇒ Boolean
Tells if the type has a base.
1001 1002 1003 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1001 def base? return true end |
#dir ⇒ Object
Gets the direction of the range.
1091 1092 1093 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1091 def dir return (@range.last - @range.first) end |
#direction ⇒ Object
Get the direction of the type, little or big endian.
1086 1087 1088 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1086 def direction return @range.first < @range.last ? :big : :little end |
#each_type_deep(&ruby_block) ⇒ Object Also known as: each_deep
Iterates over the types deeply if any.
1136 1137 1138 1139 1140 1141 1142 1143 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1136 def each_type_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_type_deep) unless ruby_block # A ruby block? First apply it to current. ruby_block.call(self) # And recurse on the base. @base.each_type_deep(&ruby_block) end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
1037 1038 1039 1040 1041 1042 1043 1044 1045 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1037 def eql?(obj) # # General type comparison. # return false unless super(obj) # Specific comparison. return false unless obj.is_a?(TypeVector) return false unless @base.eql?(obj.base) return false unless @range.eql?(obj.range) return true end |
#equivalent?(type) ⇒ Boolean
Tell if +type+ is equivalent to current type.
NOTE: type can be compatible while not being equivalent, please
refer to hruby_types.rb
for type compatibility.
1119 1120 1121 1122 1123 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1119 def equivalent?(type) return (type.is_a?(TypeVector) and @range == type.range @base.equivalent?(type.base) ) end |
#fixed? ⇒ Boolean
Tells if the type is fixed point.
1106 1107 1108 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1106 def fixed? return @base.signed? end |
#float? ⇒ Boolean
Tells if the type is floating point.
1111 1112 1113 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1111 def float? return @base.float? end |
#hash ⇒ Object
Hash function.
1048 1049 1050 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1048 def hash return [super,@base,@range].hash end |
#max ⇒ Object
Gets the type max value if any.
1067 1068 1069 1070 1071 1072 1073 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1067 def max if (self.signed?) then return (2**(self.width-1))-1 else return (2**(self.width))-1 end end |
#min ⇒ Object
Gets the type min value if any. Default: not defined.
1077 1078 1079 1080 1081 1082 1083 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1077 def min if (self.signed?) then return -(2**(self.width-1)) else return 0 end end |
#signed? ⇒ Boolean
Tells if the type signed.
1096 1097 1098 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1096 def signed? return @base.signed? end |
#size ⇒ Object
Gets the size of the type in number of base elements.
1053 1054 1055 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1053 def size return (@range.first.to_i - @range.last.to_i).abs + 1 end |
#unsigned? ⇒ Boolean
Tells if the type is unsigned.
1101 1102 1103 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1101 def unsigned? return @base.unsigned? end |
#vector? ⇒ Boolean
Tells if the type of of vector kind.
996 997 998 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 996 def vector? return true end |
#width ⇒ Object
Gets the bitwidth of the type, nil for undefined.
NOTE: must be redefined for specific types.
1060 1061 1062 1063 1064 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1060 def width first = @range.first.to_i last = @range.last.to_i return @base.width * ((first-last).abs + 1) end |