Class: Symbol
- Inherits:
-
Object
- Object
- Symbol
- Defined in:
- lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/hruby_low2sym.rb
Overview
Extends the Symbol class with of equivalent HDLRuby object.
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.
49 50 51 |
# File 'lib/HDLRuby/hruby_low2sym.rb', line 49 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.
4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 |
# File 'lib/HDLRuby/hruby_high.rb', line 4163 def to_value str = self.to_s return nil if str[0] != "_" # Bit string are prefixed by "_" # Remove the "_" not needed any longer. str = str[1..-1] # Get and check the type type = str[0] if type == "0" or type == "1" or type == "z" or type == "Z" then # Default binary type = "b" else # Not a default type str = str[1..-1] end return nil if str.empty? return nil unless ["b","u","s"].include?(type) # 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.
4156 4157 4158 |
# File 'lib/HDLRuby/hruby_high.rb', line 4156 def to_value? return true end |