Class: Symbol
- Inherits:
-
Object
- Object
- Symbol
- Defined in:
- lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/hruby_low2sym.rb
Overview
Extends the symbol class for auto declaration of input or output.
Constant Summary collapse
Instance Method Summary collapse
-
#to_hdr ⇒ Object
Convert to the equivalent HDLRuby object if any, returns nil if not.
-
#to_value ⇒ Object
(also: #to_expr)
Converts to a new value.
-
#to_value? ⇒ Boolean
Tell if the expression can be converted to a value.
Instance Method Details
#to_hdr ⇒ Object
Convert to the equivalent HDLRuby object if any, returns nil if not.
50 51 52 |
# File 'lib/HDLRuby/hruby_low2sym.rb', line 50 def to_hdr return Low2Symbol::Symbol2LowTable[self] end |
#to_value ⇒ Object Also known as: to_expr
Converts to a new value.
Returns nil if no value can be obtained from it.
5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 |
# File 'lib/HDLRuby/hruby_high.rb', line 5265 def to_value str = self.to_s return nil if str[0] != "_" # Bit string are prefixed by "_" # Get and check the type # type = str[0] type = str[1] if ["0", "1", "z", "Z", "o", "d", "h"].include?(type) then # Default binary type = "b" else # Not a default type # str = str[1..-1] str = str[2..-1] end return nil unless ["b","u","s"].include?(type) # Remove the "_" str = str.delete("_") return nil if str.empty? # Get the width if any. if str[0].match(/[0-9]/) then width = str.scan(/[0-9]*/)[0] else width = nil end # puts "width=#{width}" old_str = str # Save the string it this state since its first chars # can be erroneously considered as giving the width str = str[width.size..-1] if width # Get the base and the value base = str[0] # puts "base=#{base}\n" unless ["b", "o", "d", "h"].include?(base) then # No base found, default is bit base = "b" # And the width was actually a part of the value. value = old_str width = nil else # Get the value. value = str[1..-1] end # puts "value=#{value}" # Compute the bit width and the value case base when "b" then # base 2, compute the width width = width ? width.to_i : value.size # Check the value return nil unless value.match(/^[0-1zxZX]+$/) when "o" then # base 8, compute the width width = width ? width.to_i : value.size * 3 # Check the value if value.match(/^[0-7xXzZ]+$/) then # 4-state value, conpute the correspondig bit string. value = value.each_char.map do |c| c = c.upcase if c == "X" or c.upcase == "Z" then c * 3 else c.to_i(8).to_s(2).rjust(3,"0") end end.join else # Invalid value return nil end when "d" then # base 10, compute the width width = width ? width.to_i : value.to_i.to_s(2).size + 1 # Check the value return nil unless value.match(/^[0-9]+$/) # Compute it (base 10 values cannot be 4-state!) value = value.to_i.to_s(2) when "h" then # base 16, compute the width width = width ? width.to_i : value.size * 4 # Check the value if value.match(/^[0-9a-fA-FxXzZ]+$/) then # 4-state value, conpute the correspondig bit string. value = value.each_char.map do |c| c = c.upcase if c == "X" or c.upcase == "Z" then c * 4 else c.to_i(16).to_s(2).rjust(4,"0") end end.join else # Invalid value return nil end else # Unknown base return nil end # Compute the type. case type when "b" then type = bit[width] when "u" then type = unsigned[width] when "s" then type = signed[width] else # Unknown type return nil end # puts "type.width=#{type.width}, value=#{value}" # Create and return the value. return Value.new(type,value) end |
#to_value? ⇒ Boolean
Tell if the expression can be converted to a value.
5258 5259 5260 |
# File 'lib/HDLRuby/hruby_high.rb', line 5258 def to_value? return true end |