Class: RubyHDL::High::Type
- Inherits:
-
Object
- Object
- RubyHDL::High::Type
- Includes:
- HDLRuby::Tprocess
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes a high-level data type.
NOTE: by default a type is not specified.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#[](rng) ⇒ Object
Creates a new vector type of range
rngand with current type as base. -
#base ⇒ Object
Gets the base type, by default base type is not defined.
-
#base? ⇒ Boolean
Tells if the type has a base.
-
#binary(operator, expr0, expr1) ⇒ Object
Performs binary operation
operatoron expressionsexpr0andexpr1. -
#comp_operator(op) ⇒ Object
Gets the computation method for
operator. -
#constant(hsh) ⇒ Object
Declares high-level untyped constant signals by name and value given by
hshof the current type. -
#define_operator(operator, &ruby_block) ⇒ Object
Redefinition of
operator. -
#define_operator_with_context(operator, &ruby_block) ⇒ Object
Redefinition of
operatorwhen requiring the context to be passed as argument (normally only used internally). -
#direction ⇒ Object
Get the direction of the type, little or big endian.
-
#each_overload(&ruby_block) ⇒ Object
Interates over the overloaded operators.
-
#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
typeis 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.
-
#hierarchical? ⇒ Boolean
Tells if the type is hierarchical.
-
#htype? ⇒ Boolean
Tells htype has been included.
-
#initialize(name = nil) ⇒ Type
constructor
Creates a new type named
name. -
#inner(*names) ⇒ Object
Declares high-level untyped inner signals named
namesof the current type. -
#input(*names) ⇒ Object
Declares high-level input signals named
namesof the current type. -
#leaf? ⇒ Boolean
Tells if the type is a leaf.
-
#left ⇒ Object
Gets the type as left value.
-
#max ⇒ Object
Gets the type max value if any.
-
#min ⇒ Object
Gets the type min value if any.
-
#output(*names) ⇒ Object
Declares high-level untyped output signals named
namesof the current type. -
#range ⇒ Object
Gets the range of the type, by default range is not defined.
-
#range? ⇒ Boolean
Tells if the type has a range.
-
#register(name) ⇒ Object
Register the
nameof the type. -
#regular? ⇒ Boolean
Tells if the type is regular (applies for tuples).
-
#right ⇒ Object
Gets the type as right value.
-
#signed? ⇒ Boolean
Tells if the type signed.
-
#struct? ⇒ Boolean
Tells if the type has named sub types.
-
#to_c ⇒ Object
Convert to C code.
-
#to_c_init ⇒ Object
Convert to C initialization code.
-
#to_python_init ⇒ Object
Convert to Python initialization code.
-
#to_tf_init ⇒ Object
Convert to tensorflow initialization code.
-
#to_type ⇒ Object
Converts to a type.
-
#to_vector ⇒ Object
Converts to a bit vector.
-
#typedef(name) ⇒ Object
Declares a new type definition with
nameequivalent to current one. -
#types? ⇒ Boolean
Tells if the type has sub types.
-
#unary(operator, expr) ⇒ Object
Performs unary operation
operatoron expressionexpr. -
#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, by default 0.
Methods included from HDLRuby::Tprocess
#&, #*, #+, #+@, #-@, #/, #<<, #==, #abs, #lr, #make, #resolve, #slice, #~
Constructor Details
#initialize(name = nil) ⇒ Type
Creates a new type named name.
1133 1134 1135 1136 1137 1138 1139 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1133 def initialize(name = nil) if name then @name = name.to_sym # Registers the name. self.register(name) end end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
1128 1129 1130 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1128 def name @name end |
Instance Method Details
#[](rng) ⇒ Object
Creates a new vector type of range rng and with current type as
base.
1342 1343 1344 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1342 def [](rng) return TypeVector.new(:"",self,rng) end |
#base ⇒ Object
Gets the base type, by default base type is not defined.
1229 1230 1231 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1229 def base raise "No base type for type #{self} (#{self.name})" end |
#base? ⇒ Boolean
Tells if the type has a base.
1224 1225 1226 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1224 def base? return false end |
#binary(operator, expr0, expr1) ⇒ Object
Performs binary operation operator on expressions expr0
and expr1.
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1401 def binary(operator, expr0, expr1) # Look for a specific computation method. comp = comp_operator(operator) if self.respond_to?(comp) then # Found, use it. self.send(comp,expr0,expr1) else # Not found, back to default computation. expr0.to_value.send(operator,expr1) end end |
#comp_operator(op) ⇒ Object
Gets the computation method for operator.
1382 1383 1384 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1382 def comp_operator(op) return (op.to_s + ":C").to_sym end |
#constant(hsh) ⇒ Object
Declares high-level untyped constant signals by name and
value given by hsh of the current type.
1375 1376 1377 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1375 def constant(hsh) RubyHDL::High.top_sblock.make_constants(self,hsh) end |
#define_operator(operator, &ruby_block) ⇒ Object
Redefinition of operator.
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1414 def define_operator(operator,&ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? # Register the operator as overloaded. @overloads ||= {} @overloads[operator] = ruby_block # Set the new method for the operator. self.define_singleton_method(comp_operator(operator)) do |*args| # puts "Top user=#{HDLRuby::High.top_user}" RubyHDL::High.top_sblock.sub(RubyHDL.uniq_name) do ruby_block.call(*args) end end end |
#define_operator_with_context(operator, &ruby_block) ⇒ Object
Redefinition of operator when requiring the context to be passed
as argument (normally only used internally).
1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1431 def define_operator_with_context(operator,&ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? # Register the operator as overloaded. @overloads ||= {} @overloads[operator] = ruby_block # Set the new method for the operator. self.define_singleton_method(comp_operator(operator)) do |*args| # puts "Top user=#{HDLRuby::High.top_user}" RubyHDL::High.top_sblock.sub(RubyHDL.uniq_name) do # It is assumed that the first argument of the ruby_block # is the context in which it must be executed. ruby_block.call(self,*args) end end end |
#direction ⇒ Object
Get the direction of the type, little or big endian.
1208 1209 1210 1211 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1208 def direction # By default, little endian. return :little end |
#each_overload(&ruby_block) ⇒ Object
Interates over the overloaded operators.
1449 1450 1451 1452 1453 1454 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1449 def each_overload(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_overload) unless ruby_block # A block? Apply it on each overload if any. @overloads.each(&ruby_block) if @overloads end |
#each_type_deep(&ruby_block) ⇒ Object Also known as: each_deep
Iterates over the types deeply if any.
1263 1264 1265 1266 1267 1268 1269 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1263 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 that's all by default. end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
1144 1145 1146 1147 1148 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1144 def eql?(obj) return false unless obj.is_a?(Type) return false unless @name.eql?(obj.name) 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.
1257 1258 1259 1260 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1257 def equivalent?(type) # By default, types are equivalent iff they have the same name. return (type.is_a?(Type) and self.name == type.name) end |
#fixed? ⇒ Boolean
Tells if the type is fixed point.
1166 1167 1168 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1166 def fixed? return false end |
#float? ⇒ Boolean
Tells if the type is floating point.
1171 1172 1173 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1171 def float? return false end |
#hash ⇒ Object
Hash function.
1151 1152 1153 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1151 def hash return [@name].hash end |
#hierarchical? ⇒ Boolean
Tells if the type is hierarchical.
1249 1250 1251 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1249 def hierarchical? return self.base? || self.types? end |
#htype? ⇒ Boolean
Tells htype has been included.
1278 1279 1280 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1278 def htype? return true end |
#inner(*names) ⇒ Object
Declares high-level untyped inner signals named names of the
current type.
1369 1370 1371 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1369 def inner(*names) RubyHDL::High.top_sblock.make_inners(self,*names) end |
#input(*names) ⇒ Object
Declares high-level input signals named names of the current type.
1349 1350 1351 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1349 def input(*names) RubyHDL::High.top_sblock.make_inputs(self,*names) end |
#leaf? ⇒ Boolean
Tells if the type is a leaf.
1176 1177 1178 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1176 def leaf? return false end |
#left ⇒ Object
Gets the type as left value.
NOTE: used for asymetric types like TypeSystemI.
1315 1316 1317 1318 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1315 def left # By default self. self end |
#max ⇒ Object
Gets the type max value if any. Default: not defined.
1197 1198 1199 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1197 def max raise "No max value for type #{self} (#{self.name})" end |
#min ⇒ Object
Gets the type min value if any. Default: not defined.
1203 1204 1205 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1203 def min raise "No min value for type #{self} (#{self.name})" end |
#output(*names) ⇒ Object
Declares high-level untyped output signals named names of the
current type.
1355 1356 1357 1358 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1355 def output(*names) # High.top_user.make_outputs(self.instantiate,*names) RubyHDL::High.top_sblock.make_outputs(self,*names) end |
#range ⇒ Object
Gets the range of the type, by default range is not defined.
1219 1220 1221 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1219 def range raise "No range for type #{self} (#{self.name})" end |
#range? ⇒ Boolean
Tells if the type has a range.
1214 1215 1216 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1214 def range? return false end |
#register(name) ⇒ Object
Register the name of the type.
1306 1307 1308 1309 1310 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1306 def register(name) # Sets the hdl-like access to the type. obj = self # For using the right self within the proc RubyHDL::High.top_sblock.register(name) { obj } end |
#regular? ⇒ Boolean
Tells if the type is regular (applies for tuples).
1239 1240 1241 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1239 def regular? return false end |
#right ⇒ Object
Gets the type as right value.
NOTE: used for asymetric types like TypeSystemI.
1323 1324 1325 1326 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1323 def right # By default self. self end |
#signed? ⇒ Boolean
Tells if the type signed.
1156 1157 1158 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1156 def signed? return false end |
#struct? ⇒ Boolean
Tells if the type has named sub types.
1244 1245 1246 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1244 def struct? return false end |
#to_c ⇒ Object
Convert to C code.
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1457 def to_c case @name when :void return "void" when :bit, :unsigned return "unsigned" when :signed return "signed" when :float return "double" when :string return "char*" else return @name.to_s end end |
#to_c_init ⇒ Object
Convert to C initialization code.
1475 1476 1477 1478 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1475 def to_c_init # By default: 0 return "0" end |
#to_python_init ⇒ Object
Convert to Python initialization code.
1481 1482 1483 1484 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1481 def to_python_init # By default: 0 return "0" end |
#to_tf_init ⇒ Object
Convert to tensorflow initialization code.
1487 1488 1489 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1487 def to_tf_init return "tf.constant(0)" end |
#to_type ⇒ Object
Converts to a type. Returns self since it is already a type.
1284 1285 1286 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1284 def to_type return self end |
#to_vector ⇒ Object
Converts to a bit vector.
1273 1274 1275 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1273 def to_vector return TypeVector.new(:"", Bit, self.width-1..0) end |
#typedef(name) ⇒ Object
Declares a new type definition with name equivalent to current one.
1331 1332 1333 1334 1335 1336 1337 1338 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1331 def typedef(name) # Create the new type. typ = TypeDef.new(name,self) # Register it. High.top_sblock.register(name) { typ } # Return it. return typ end |
#types? ⇒ Boolean
Tells if the type has sub types.
1234 1235 1236 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1234 def types? return false end |
#unary(operator, expr) ⇒ Object
Performs unary operation operator on expression expr.
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1387 def unary(operator,expr) # Look for a specific computation method. comp = comp_operator(operator) if self.respond_to?(comp) then # Found, use it. self.send(comp,expr) else # Not found, back to default computation. expr.to_value.send(operator) end end |
#unsigned? ⇒ Boolean
Tells if the type is unsigned.
1161 1162 1163 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1161 def unsigned? return false end |
#vector? ⇒ Boolean
Tells if the type of of vector kind.
1181 1182 1183 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1181 def vector? return false end |
#width ⇒ Object
Gets the bitwidth of the type, by default 0. Bit, signed, unsigned and Float base have a width of 1.
1187 1188 1189 1190 1191 1192 1193 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1187 def width if [:bit, :signed, :unsigned, :float ].include?(@name) then return 1 else return 0 end end |