Module: HDLRuby::High::HExpression
- Defined in:
- lib/HDLRuby/hruby_high.rb
Overview
Module giving high-level expression properties
Instance Attribute Summary collapse
-
#systemT ⇒ Object
readonly
The system type the expression has been resolved in, if any.
-
#type ⇒ Object
The type of the expression if any.
Class Method Summary collapse
-
.orig_operator(op) ⇒ Object
Gets the origin method for operation +op+.
Instance Method Summary collapse
-
#[](rng) ⇒ Object
Creates an access to elements of range +rng+ of the signal.
-
#as(type) ⇒ Object
Casts as +type+.
-
#coerce(obj) ⇒ Object
Coerce by forcing convertion of obj to expression.
-
#constant? ⇒ Boolean
Tell if the expression is constant.
-
#mux(*choices) ⇒ Object
Converts to a select operator using current expression as condition for one of the +choices+.
- #orig_operator(op) ⇒ Object
-
#to_expr ⇒ Object
Converts to a new expression.
-
#to_value ⇒ Object
Converts to a new value.
-
#to_value? ⇒ Boolean
Tell if the expression can be converted to a value.
Instance Attribute Details
#systemT ⇒ Object (readonly)
The system type the expression has been resolved in, if any.
2166 2167 2168 |
# File 'lib/HDLRuby/hruby_high.rb', line 2166 def systemT @systemT end |
#type ⇒ Object
The type of the expression if any.
2168 2169 2170 |
# File 'lib/HDLRuby/hruby_high.rb', line 2168 def type @type end |
Class Method Details
.orig_operator(op) ⇒ Object
Gets the origin method for operation +op+.
2211 2212 2213 |
# File 'lib/HDLRuby/hruby_high.rb', line 2211 def self.orig_operator(op) return (op.to_s + "_orig").to_sym end |
Instance Method Details
#[](rng) ⇒ Object
Creates an access to elements of range +rng+ of the signal.
NOTE: +rng+ can be a single expression in which case it is an index.
2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 |
# File 'lib/HDLRuby/hruby_high.rb', line 2262 def [](rng) if rng.respond_to?(:to_expr) then # Number range: convert it to an expression. rng = rng.to_expr end if rng.is_a?(HDLRuby::Low::Expression) then # Index case return RefIndex.new(self.type.base,self.to_expr,rng) else # Range case, ensure it is made among expression. first = rng.first.to_expr last = rng.last.to_expr # Abd create the reference. return RefRange.new(self.type.slice(first..last), self.to_expr,first..last) end end |
#as(type) ⇒ Object
Casts as +type+.
2206 2207 2208 |
# File 'lib/HDLRuby/hruby_high.rb', line 2206 def as(type) return Cast.new(type.to_type,self.to_expr) end |
#coerce(obj) ⇒ Object
Coerce by forcing convertion of obj to expression.
2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 |
# File 'lib/HDLRuby/hruby_high.rb', line 2232 def coerce(obj) if obj.is_a?(HDLRuby::Low::Expression) then # Already an expression, nothing to do. return [obj,self] elsif obj.respond_to?(:to_expr) then # Can be converted to an expression, do it. return [obj.to_expr, self] else return [obj,self] end end |
#constant? ⇒ Boolean
Tell if the expression is constant.
2184 2185 2186 2187 2188 2189 2190 |
# File 'lib/HDLRuby/hruby_high.rb', line 2184 def constant? # By default not constant. return false unless self.each_node.any? # If any sub node, check if all of them are constants. self.each_node { |node| return false unless node.constant? } return true end |
#mux(*choices) ⇒ Object
Converts to a select operator using current expression as condition for one of the +choices+.
NOTE: +choices+ can either be a list of arguments or an array. If +choices+ has only two entries (and it is not a hash), +value+ will be converted to a boolean.
2287 2288 2289 2290 2291 2292 2293 |
# File 'lib/HDLRuby/hruby_high.rb', line 2287 def mux(*choices) # Process the choices. choices = choices.flatten(1) if choices.size == 1 choices.map! { |choice| choice.to_expr } # Generate the select expression. return Select.new(choices[0].type,"?",self.to_expr,*choices) end |
#orig_operator(op) ⇒ Object
2214 2215 2216 |
# File 'lib/HDLRuby/hruby_high.rb', line 2214 def orig_operator(op) HExpression.orig_operator(op) end |
#to_expr ⇒ Object
Converts to a new expression.
NOTE: to be redefined in case of non-expression class.
2196 2197 2198 |
# File 'lib/HDLRuby/hruby_high.rb', line 2196 def to_expr raise AnyError, "Internal error: to_expr not defined yet for class: #{self.class}" end |
#to_value ⇒ Object
Converts to a new value.
NOTE: to be redefined.
2178 2179 2180 2181 |
# File 'lib/HDLRuby/hruby_high.rb', line 2178 def to_value raise AnyError, "Expression cannot be converted to a value: #{self.class}" end |
#to_value? ⇒ Boolean
Tell if the expression can be converted to a value.
2171 2172 2173 |
# File 'lib/HDLRuby/hruby_high.rb', line 2171 def to_value? return false end |