Class: HDLRuby::High::Scope
- Inherits:
-
Low::Scope
- Object
- Low::Scope
- HDLRuby::High::Scope
- Includes:
- HScope_missing, Hinner, HmetaControl, Hmux, SingletonExtend, WithFullname
- Defined in:
- lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/hruby_rsim.rb,
lib/HDLRuby/hruby_rcsim.rb,
lib/HDLRuby/hruby_rsim_vcd.rb,
lib/HDLRuby/hruby_high_fullname.rb
Overview
Describes a scope for a system type
Constant Summary collapse
Constants included from Hmissing
Constants included from Low::Low2Symbol
Low::Low2Symbol::Low2SymbolPrefix, Low::Low2Symbol::Low2SymbolTable, Low::Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the scope if any.
-
#namespace ⇒ Object
readonly
The namespace.
-
#rcscope ⇒ Object
readonly
Extends the Scope class for hybrid Ruby-C simulation.
-
#return_value ⇒ Object
readonly
The return value when building the scope.
Attributes included from Low::Hparent
Instance Method Summary collapse
-
#add_export(name) ⇒ Object
Adds a +name+ to export.
-
#add_groupI(name, *instances) ⇒ Object
Adds a group of system +instances+ named +name+.
-
#add_inout(signal) ⇒ Object
Adds inout +signal+ in the current system.
-
#add_input(signal) ⇒ Object
Adds input +signal+ in the current system.
-
#add_output(signal) ⇒ Object
Adds output +signal+ in the current system.
-
#build(&ruby_block) ⇒ Object
Build the scope by executing +ruby_block+.
-
#build_top(base, *args) ⇒ Object
Builds the scope using +base+ as model scope with possible arguments +args+.
-
#code(*content, &ruby_block) ⇒ Object
Declares a non-HDLRuby set of code chunks described by +content+ and completed from +ruby_block+ execution result.
-
#cur_system ⇒ Object
Gets the current system.
-
#each_export(&ruby_block) ⇒ Object
Iterates over the exported constructs.
-
#each_groupI(&ruby_block) ⇒ Object
Iterates over the group of system instances.
-
#each_included(&ruby_block) ⇒ Object
Iterates over the included systems.
-
#export(*names) ⇒ Object
Sets the constructs corresponding to +names+ as exports.
-
#fill_low(scopeL) ⇒ Object
Fills a low level scope with self's contents.
-
#fullname ⇒ Object
Returns the name of the signal with its hierarchy.
-
#get_groupI(name) ⇒ Object
Access a group of system instances by +name+.
-
#get_vars_with_fullname(vars_with_fullname = {}) ⇒ Object
Gets the VCD variables with their long name.
-
#get_vars_with_idstr(vars_with_idstr = {}) ⇒ Object
Gets the VCD variables with their id string.
-
#hcase(value) ⇒ Object
Creates a new case statement with a +value+ used for deciding which block to execute.
-
#helse(mode = nil, &ruby_block) ⇒ Object
Sets the block executed when the condition is not met to the block in +mode+ generated by the execution of +ruby_block+.
-
#helsif(condition, mode = nil, &ruby_block) ⇒ Object
Sets the condition check when the condition is not met to the block, with a +condition+ that when met lead to the execution of the block in +mode+ generated by the +ruby_block+.
-
#hif(condition, mode = nil, &ruby_block) ⇒ Object
Creates a new if statement with a +condition+ that when met lead to the execution of the block in +mode+ generated by the +ruby_block+.
-
#hwhen(match, mode = nil, &ruby_block) ⇒ Object
Sets the block of a case structure executed when the +match+ is met to the block in +mode+ generated by the execution of +ruby_block+.
-
#include(system, *args) ⇒ Object
Include a +system+ type with possible +args+ instanciation arguments.
-
#init_sim(systemT) ⇒ Object
Initialize the simulation for system +systemT+.
-
#initialize(name = :"", systemT = nil, &ruby_block) ⇒ Scope
constructor
Creates a new scope with possible +name+.
-
#inout(*names) ⇒ Object
Declares high-level bit inout signals named +names+ in the current system.
-
#input(*names) ⇒ Object
Declares high-level bit input signals named +names+ in the current system.
-
#make_inouts(type, *names) ⇒ Object
Creates and adds a set of inouts typed +type+ from a list of +names+ in the current system.
-
#make_inputs(type, *names) ⇒ Object
Creates and adds a set of inputs typed +type+ from a list of +names+ in the current system.
-
#make_outputs(type, *names) ⇒ Object
Creates and adds a set of outputs typed +type+ from a list of +names+ in the current system.
-
#merge_included(systemT) ⇒ Object
Merge the included systems interface in +systemT+ NOTE: incompatible with further to_low transformation.
-
#merge_included! ⇒ Object
Merge the included systems interface in system instances.
-
#open(&ruby_block) ⇒ Object
Opens for extension.
-
#output(*names) ⇒ Object
Declares high-level bit output signals named +names+ in the current system.
-
#par(*events, name: nil, &ruby_block) ⇒ Object
Declares a high-level parallel behavior activated on a list of +events+, with possible name +name+ and built by executing +ruby_block+.
-
#program(lang, func, &ruby_block) ⇒ Object
Declares a program in language +lang+ with start function named +func+ and built through +ruby_block+.
-
#seq(*events, name: nil, &ruby_block) ⇒ Object
Declares a high-level sequential behavior activated on a list of +events+, with possible name +name+ and built by executing +ruby_block+.
-
#show_hierarchy(vcdout) ⇒ Object
Shows the hierarchy of the variables.
-
#sub(name = HDLRuby.uniq_name, &ruby_block) ⇒ Object
Declares a sub scope with possible +name+ and built from +ruby_block+.
-
#timed(&ruby_block) ⇒ Object
Declares a high-level timed behavior built by executing +ruby_block+.
-
#to_low(low_name = nil) ⇒ Object
Converts the scope to HDLRuby::Low.
-
#to_rcsim(rcowner) ⇒ Object
Generate the C description of the scope comming from object whose C description is +rcowner+.
-
#to_ref ⇒ Object
Converts to a new reference.
-
#to_user ⇒ Object
Converts to a namespace user.
Methods included from Hmux
Methods included from HmetaControl
#metacase, #metaelse, #metaelsif, #metaif, #metawhen
Methods included from HScope_missing
Methods included from Hmissing
Methods included from SingletonExtend
Methods included from Hinner
Methods inherited from Low::Scope
#add_behavior, #add_code, #add_connection, #add_inner, #add_program, #add_scope, #add_systemI, #add_systemT, #add_type, #blocks2seq!, #boolean_in_assign2select!, #break_concat_assigns!, #break_types!, #c_code_allocate, #casts_without_expression!, #cleanup!, #delete_all_behaviors!, #delete_all_connections!, #delete_behavior!, #delete_connection!, #delete_inner!, #delete_related!, #delete_scope!, #delete_systemI!, #delete_systemT!, #delete_type!, #delete_unless!, #each_behavior, #each_behavior_deep, #each_block_deep, #each_code, #each_connection, #each_connection_deep, #each_deep, #each_inner, #each_node_deep, #each_program, #each_scope, #each_scope_deep, #each_signal, #each_signal_deep, #each_statement_deep, #each_systemI, #each_systemT, #each_type, #eql?, #explicit_types!, #extract_behaviors!, #extract_connections!, #extract_declares!, #extract_port_assign!, #get_all_inners, #get_by_name, #get_code, #get_inner, #get_signal, #get_systemI, #get_systemT, #get_type, #has_behavior?, #has_code?, #has_connection?, #has_inner?, #has_program?, #has_scope?, #has_signal?, #has_systemI?, #has_systemT?, #has_type?, #hash, #initial_concat_to_timed!, #instance_port?, #last_behavior, #make_portw, #map_behaviors!, #map_connections!, #map_inners!, #map_scopes!, #map_systemIs!, #map_systemTs!, #map_types!, #mixblocks2seq!, #par_in_seq2seq!, #parent_system, #port_assign?, #portw2ref, #portw_name2sym, #replace_names!, #replace_names_subs!, #reverse_each_behavior, #select2case!, #signal2subs!, #sym2portw_name, #to_c, #to_ch, #to_hdr, #to_high, #to_upper_space!, #to_vhdl, #to_viz, #top_scope, #with_port!
Methods included from Low::ForceName
Methods included from Low::Low2Symbol
Methods included from Low::Hparent
#absolute_ref, #hierarchy, #no_parent!, #scope
Constructor Details
#initialize(name = :"", systemT = nil, &ruby_block) ⇒ Scope
Creates a new scope with possible +name+. If the scope is a top scope of a system, this systemT is given by +systemT+.
The proc +ruby_block+ is executed for building the scope. If no block is provided, the scope is the top of a system and is filled by the instantiation procedure of the system.
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 |
# File 'lib/HDLRuby/hruby_high.rb', line 1051 def initialize(name = :"", systemT = nil, &ruby_block) # Initialize the scope structure super(name) # Initialize the set of grouped system instances. @groupIs = {} # Creates the namespace. @namespace = Namespace.new(self) # Register the scope if it is not the top scope of a system # (in which case the system has already be registered with # the same name). unless name.empty? or systemT then # Named scope, set the hdl-like access to the scope. obj = self # For using the right self within the proc High.space_reg(name) { obj } end # Initialize the set of exported inner signals and instances @exports = {} # Initialize the set of included systems. # @includes = {} @includes = [] # Builds the scope if a ruby block is provided. self.build(&ruby_block) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class HDLRuby::High::HScope_missing
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the scope if any.
1035 1036 1037 |
# File 'lib/HDLRuby/hruby_high.rb', line 1035 def name @name end |
#namespace ⇒ Object (readonly)
The namespace
1038 1039 1040 |
# File 'lib/HDLRuby/hruby_high.rb', line 1038 def namespace @namespace end |
#rcscope ⇒ Object (readonly)
Extends the Scope class for hybrid Ruby-C simulation.
149 150 151 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 149 def rcscope @rcscope end |
#return_value ⇒ Object (readonly)
The return value when building the scope.
1041 1042 1043 |
# File 'lib/HDLRuby/hruby_high.rb', line 1041 def return_value @return_value end |
Instance Method Details
#add_export(name) ⇒ Object
Adds a +name+ to export.
NOTE: if the name do not corresponds to any inner signal nor instance, raise an exception.
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 |
# File 'lib/HDLRuby/hruby_high.rb', line 1122 def add_export(name) # Check the name. name = name.to_sym # Look for construct to make public. # Maybe it is an inner signals. inner = self.get_inner(name) if inner then # Yes set it as export. @exports[name] = inner return end # No, maybe it is an instance. instance = self.get_systemI(name) if instance then # Yes, set it as export. @exports[name] = instance return end # No, error. raise AnyError, "Invalid name for export: #{name}" end |
#add_groupI(name, *instances) ⇒ Object
Adds a group of system +instances+ named +name+.
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 |
# File 'lib/HDLRuby/hruby_high.rb', line 1087 def add_groupI(name, *instances) # Ensure name is a symbol and is not already used for another # group. name = name.to_sym if @groupIs.key?(name) raise AnyError, "Group of system instances named #{name} already exist." end # Add the group. @groupIs[name.to_sym] = instances # Sets the parent of the instances. instances.each { |instance| instance.parent = self } end |
#add_inout(signal) ⇒ Object
Adds inout +signal+ in the current system.
1238 1239 1240 |
# File 'lib/HDLRuby/hruby_high.rb', line 1238 def add_inout(signal) self.parent.add_inout(signal) end |
#add_input(signal) ⇒ Object
Adds input +signal+ in the current system.
1228 1229 1230 |
# File 'lib/HDLRuby/hruby_high.rb', line 1228 def add_input(signal) self.parent.add_input(signal) end |
#add_output(signal) ⇒ Object
Adds output +signal+ in the current system.
1233 1234 1235 |
# File 'lib/HDLRuby/hruby_high.rb', line 1233 def add_output(signal) self.parent.add_output(signal) end |
#build(&ruby_block) ⇒ Object
Build the scope by executing +ruby_block+.
NOTE: used when the scope is not the top of a system.
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 |
# File 'lib/HDLRuby/hruby_high.rb', line 1184 def build(&ruby_block) # Set the namespace for buidling the scope. High.space_push(@namespace) # Build the scope. @return_value = High.top_user.instance_eval(&ruby_block) # res = High.top_user.instance_eval(&ruby_block) High.space_pop # # Now gain access to the result within the sub scope. # # if (res.is_a?(HRef)) then # if (res.is_a?(HExpression)) then # High.space_push(@namespace) # @return_value = res.type.inner(HDLRuby.uniq_name) # @return_value <= res # High.space_pop # @return_value = RefObject.new(self,@return_value) # else # @return_value = res # end # This will be the return value. @return_value end |
#build_top(base, *args) ⇒ Object
Builds the scope using +base+ as model scope with possible arguments +args+.
NOTE: Used by the instantiation procedure of a system.
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 |
# File 'lib/HDLRuby/hruby_high.rb', line 1211 def build_top(base,*args) # Fills its namespace with the content of the base scope # (this latter may already contains access points if it has been # opended for extension previously). @namespace.concat_namespace(base.namespace) High.space_push(@namespace) # Execute the instantiation block base.parent.each_instance_proc do |instance_proc| @return_value = High.top_user.instance_exec(*args,&instance_proc) end High.space_pop end |
#code(*content, &ruby_block) ⇒ Object
Declares a non-HDLRuby set of code chunks described by +content+ and completed from +ruby_block+ execution result. NOTE: content includes the events to activate the code on and a description of the code as a hash assotiating names to code text.
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 |
# File 'lib/HDLRuby/hruby_high.rb', line 1310 def code(*content, &ruby_block) # Process the content. # Separate events from code chunks descriptions. events, chunks = content.partition {|elem| elem.is_a?(Event) } # Generates a large hash from the code. chunks = chunks.reduce(:merge) # Adds the result of the ruby block if any. if ruby_block then chunks.merge(HDLRuby::High.top_user.instance_eval(&ruby_block)) end # Create the chunk objects. chunks = chunks.each.map do |name,content| content = [*content] # Process the lumps content.map! do |lump| lump.respond_to?(:to_expr) ? lump.to_expr : lump end Chunk.new(name,*content) end # Create the code object. res = Code.new # Adds the events. events.each(&res.method(:add_event)) # Adds the chunks. chunks.each(&res.method(:add_chunk)) # Adds the resulting code to the current scope. HDLRuby::High.top_user.add_code(res) # Return the resulting code return res end |
#cur_system ⇒ Object
Gets the current system.
1556 1557 1558 |
# File 'lib/HDLRuby/hruby_high.rb', line 1556 def cur_system return HDLRuby::High.cur_system end |
#each_export(&ruby_block) ⇒ Object
Iterates over the exported constructs.
Returns an enumerator if no ruby block is given.
1147 1148 1149 1150 1151 1152 1153 1154 |
# File 'lib/HDLRuby/hruby_high.rb', line 1147 def each_export(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_export) unless ruby_block # A block? Apply it on each input signal instance. @exports.each_value(&ruby_block) # And apply on the sub scopes if any. @scopes.each {|scope| scope.each_export(&ruby_block) } end |
#each_groupI(&ruby_block) ⇒ Object
Iterates over the group of system instances.
Returns an enumerator if no ruby block is given.
1111 1112 1113 1114 1115 1116 |
# File 'lib/HDLRuby/hruby_high.rb', line 1111 def each_groupI(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_groupI) unless ruby_block # A block? Apply it on each input signal instance. @groupIs.each(&ruby_block) end |
#each_included(&ruby_block) ⇒ Object
Iterates over the included systems.
1157 1158 1159 1160 1161 1162 1163 1164 1165 |
# File 'lib/HDLRuby/hruby_high.rb', line 1157 def each_included(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_included) unless ruby_block # A block? Apply it on each included system. # @includes.each_value(&ruby_block) @includes.each(&ruby_block) # And apply on the sub scopes if any. @scopes.each {|scope| scope.each_included(&ruby_block) } end |
#export(*names) ⇒ Object
Sets the constructs corresponding to +names+ as exports.
1495 1496 1497 |
# File 'lib/HDLRuby/hruby_high.rb', line 1495 def export(*names) names.each {|name| self.add_export(name) } end |
#fill_low(scopeL) ⇒ Object
Fills a low level scope with self's contents.
NOTE: name conflicts are treated in the current NameStack state.
1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 |
# File 'lib/HDLRuby/hruby_high.rb', line 1639 def fill_low(scopeL) # Adds the content of its included systems. # @includes.each_value {|system| system.scope.fill_low(scopeL) } @includes.each {|system| system.scope.fill_low(scopeL) } # Adds the declared local system types. # NOTE: in the current version of HDLRuby::High, there should not # be any of them (only eigen systems are real system types). self.each_systemT { |systemT| scopeL.add_systemT(systemT.to_low) } # Adds the local types. self.each_type { |type| scopeL.add_type(type.to_low) } # Adds the inner scopes. self.each_scope { |scope| scopeL.add_scope(scope.to_low) } # Adds the inner signals. self.each_inner { |inner| scopeL.add_inner(inner.to_low) } # Adds the instances. # Single ones. self.each_systemI do |systemI| # puts "Filling with systemI=#{systemI.name}" systemI_low = scopeL.add_systemI(systemI.to_low) # Also add the eigen system to the list of local systems. scopeL.add_systemT(systemI_low.systemT) end # Grouped ones. self.each_groupI do |name,systemIs| systemIs.each.with_index { |systemI,i| # Sets the name of the system instance # (required for conversion of further accesses). # puts "systemI.respond_to?=#{systemI.respond_to?(:name=)}" systemI.name = name.to_s + "[#{i}]" # And convert it to low systemI_low = scopeL.add_systemI(systemI.to_low()) # Also add the eigen system to the list of local systems. scopeL.add_systemT(systemI_low.systemT) } end # Adds the programs. self.each_program { |prog| scopeL.add_program(prog.to_low) } # Adds the code chunks. self.each_code { |code| scopeL.add_code(code.to_low) } # Adds the behaviors. self.each_behavior { |behavior| scopeL.add_behavior(behavior.to_low) } # Adds the connections. self.each_connection { |connection| # puts "connection=#{connection}" scopeL.add_connection(connection.to_low) } # # Adds the behaviors. # self.each_behavior { |behavior| # scopeL.add_behavior(behavior.to_low) # } end |
#fullname ⇒ Object
Returns the name of the signal with its hierarchy.
369 370 371 372 |
# File 'lib/HDLRuby/hruby_rsim.rb', line 369 def fullname @fullname ||= self.parent.fullname + ":" + self.name.to_s return @fullname end |
#get_groupI(name) ⇒ Object
Access a group of system instances by +name+.
NOTE: the result is a copy of the group for avoiding side effects.
1104 1105 1106 |
# File 'lib/HDLRuby/hruby_high.rb', line 1104 def get_groupI(name) return @groupIs[name.to_sym].clone end |
#get_vars_with_fullname(vars_with_fullname = {}) ⇒ Object
Gets the VCD variables with their long name.
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/HDLRuby/hruby_rsim_vcd.rb', line 204 def get_vars_with_fullname(vars_with_fullname = {}) # # Adds the inner signals. # self.each_inner do |sig| # vars_with_fullname[sig] = HDLRuby::High.vcd_name(sig.fullname) # end # Recurse on the inner signals. self.each_inner do |sig| sig.get_vars_with_fullname(vars_with_fullname) # vars_with_fullname[sig] = HDLRuby::High.vcd_name(sig.fullname) end # Recurse on the behaviors' blocks self.each_behavior do |beh| beh.block.get_vars_with_fullname(vars_with_fullname) end # Recurse on the systemI's Eigen system. self.each_systemI do |sys| sys.systemT.get_vars_with_fullname(vars_with_fullname) end # Recurse on the subscopes. self.each_scope do |scope| scope.get_vars_with_fullname(vars_with_fullname) end return vars_with_fullname end |
#get_vars_with_idstr(vars_with_idstr = {}) ⇒ Object
Gets the VCD variables with their id string.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/HDLRuby/hruby_rsim_vcd.rb', line 230 def get_vars_with_idstr(vars_with_idstr = {}) # # Adds the inner signals. # self.each_inner do |sig| # vars_with_idstr[sig] = HDLRuby::High.vcd_idstr(sig) # end # Recurse on the inner signals. self.each_inner do |sig| sig.get_vars_with_idstr(vars_with_idstr) end # Recurse on the behaviors' blocks self.each_behavior do |beh| beh.block.get_vars_with_idstr(vars_with_idstr) end # Recurse on the systemI's Eigen system. self.each_systemI do |sys| sys.systemT.get_vars_with_idstr(vars_with_idstr) end # Recurse on the subscopes. self.each_scope do |scope| scope.get_vars_with_idstr(vars_with_idstr) end return vars_with_idstr end |
#hcase(value) ⇒ Object
Creates a new case statement with a +value+ used for deciding which block to execute.
NOTE:
- the when part is defined through the hwhen method.
- a new behavior is created to enclose the hcase.
1468 1469 1470 1471 1472 1473 |
# File 'lib/HDLRuby/hruby_high.rb', line 1468 def hcase(value) return if self.(value) self.par do hcase(value) end end |
#helse(mode = nil, &ruby_block) ⇒ Object
Sets the block executed when the condition is not met to the block in +mode+ generated by the execution of +ruby_block+.
Can only be used once.
NOTE: added to the hif of the last behavior.
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 |
# File 'lib/HDLRuby/hruby_high.rb', line 1425 def helse(mode = nil, &ruby_block) return if self.(&ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? # There is a ruby_block: the helse is assumed to be with # the last statement of the last behavior. statement = self.last_behavior.last_statement # Completes the hif or the hcase statement. unless statement.is_a?(If) or statement.is_a?(Case) then raise AnyError, "Error: helse statement without hif nor hcase (#{statement.class})." end statement.helse(mode, &ruby_block) end |
#helsif(condition, mode = nil, &ruby_block) ⇒ Object
Sets the condition check when the condition is not met to the block, with a +condition+ that when met lead to the execution of the block in +mode+ generated by the +ruby_block+.
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 |
# File 'lib/HDLRuby/hruby_high.rb', line 1442 def helsif(condition, mode = nil, &ruby_block) = self.(condition,&ruby_block) if == :toif then # Must be converted to hif. return self.hif(condition,mode, &ruby_block) elsif then return end # Ensure there is a block. ruby_block = proc {} unless block_given? # There is a ruby_block: the helse is assumed to be with # the last statement of the last behavior. statement = self.last_behavior.last_statement # Completes the hif statement. unless statement.is_a?(If) then raise AnyError, "Error: helsif statement without hif (#{statement.class})." end statement.helsif(condition, mode, &ruby_block) end |
#hif(condition, mode = nil, &ruby_block) ⇒ Object
Creates a new if statement with a +condition+ that when met lead to the execution of the block in +mode+ generated by the +ruby_block+.
NOTE:
- the else part is defined through the helse method.
- a behavior is created to enclose the hif.
1410 1411 1412 1413 1414 1415 1416 1417 |
# File 'lib/HDLRuby/hruby_high.rb', line 1410 def hif(condition, mode = nil, &ruby_block) return if self.(condition,&ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? self.par do hif(condition,mode,&ruby_block) end end |
#hwhen(match, mode = nil, &ruby_block) ⇒ Object
Sets the block of a case structure executed when the +match+ is met to the block in +mode+ generated by the execution of +ruby_block+.
Can only be used once.
1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 |
# File 'lib/HDLRuby/hruby_high.rb', line 1479 def hwhen(match, mode = nil, &ruby_block) return if self.(match,&ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? # There is a ruby_block: the helse is assumed to be with # the last statement of the last behavior. statement = @behaviors.last.last_statement # Completes the hcase statement. unless statement.is_a?(Case) then raise AnyError, "Error: hwhen statement without hcase (#{statement.class})." end statement.hwhen(match, mode, &ruby_block) end |
#include(system, *args) ⇒ Object
Include a +system+ type with possible +args+ instanciation arguments.
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 |
# File 'lib/HDLRuby/hruby_high.rb', line 1501 def include(system,*args) # if @includes.key?(system.name) then # raise AnyError, "Cannot include twice the same system: #{system}" # end if @includes.include?(system) then raise AnyError, "Cannot include twice the same system: #{system}" end # # puts "Include system=#{system.name}" # # Save the name of the included system, it will serve as key # # for looking for the included expanded version. # include_name = system.name # Expand the system to include system = system.(:"",*args) # Add the included system interface to the current one. if self.parent.is_a?(SystemT) then space = self.namespace # Interface signals # puts "i_name=#{i_name} @to_includes=#{@to_includes.size}" # system.each_signal_with_included do |signal| system.each_signal_all_with_included do |signal| # puts "signal=#{signal.name}" space.send(:define_singleton_method,signal.name) do signal end end # Exported objects system.each_export do |export| # puts "export=#{export.name}" space.send(:define_singleton_method,export.name) do export end end # Adds the task to execute on the instance. system.each_on_instance do |task| self.parent.on_instance(&task) end end # Adds it the list of includeds # @includes[include_name] = system @includes << system # puts "@includes=#{@includes}" end |
#init_sim(systemT) ⇒ Object
Initialize the simulation for system +systemT+.
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/HDLRuby/hruby_rsim.rb', line 336 def init_sim(systemT) # Recurse on the inner signals. self.each_inner { |sig| sig.init_sim(systemT) } # Recurse on the behaviors. self.each_behavior { |beh| beh.init_sim(systemT) } # Recurse on the systemI. self.each_systemI { |sys| sys.init_sim(systemT) } # Recurse on the connections. # self.each_connection { |cnx| cnx.init_sim(systemT) } self.each_connection do |cnx| # Connection to a real expression? if !cnx.right.is_a?(RefObject) then # Yes. cnx.init_sim(systemT) else # No, maybe the reverse connection is also required. # puts "cnx.left.object=#{cnx.left.object.fullname} cnx.right.object=#{cnx.right.object.fullname}" cnx.init_sim(systemT) if cnx.left.is_a?(RefObject) then sigL = cnx.left.object prtL = sigL.parent if prtL.is_a?(SystemT) and prtL.each_inout.any?{|e| e.object_id == sigL.object_id} then # puts "write to right with sigL=#{sigL.fullname}." Connection.new(cnx.right.clone,cnx.left.clone).init_sim(systemT) end end end end # Recurse on the sub scopes. self.each_scope { |sco| sco.init_sim(systemT) } end |
#inout(*names) ⇒ Object
Declares high-level bit inout signals named +names+ in the current system.
1290 1291 1292 |
# File 'lib/HDLRuby/hruby_high.rb', line 1290 def inout(*names) self.parent.inout(*names) end |
#input(*names) ⇒ Object
Declares high-level bit input signals named +names+ in the current system.
1278 1279 1280 |
# File 'lib/HDLRuby/hruby_high.rb', line 1278 def input(*names) self.parent.input(*names) end |
#make_inouts(type, *names) ⇒ Object
Creates and adds a set of inouts typed +type+ from a list of +names+ in the current system.
NOTE: a name can also be a signal, is which case it is duplicated.
1262 1263 1264 |
# File 'lib/HDLRuby/hruby_high.rb', line 1262 def make_inouts(type, *names) self.parent.make_inouts(type,*names) end |
#make_inputs(type, *names) ⇒ Object
Creates and adds a set of inputs typed +type+ from a list of +names+ in the current system.
NOTE: a name can also be a signal, is which case it is duplicated.
1246 1247 1248 |
# File 'lib/HDLRuby/hruby_high.rb', line 1246 def make_inputs(type, *names) self.parent.make_inputs(type,*names) end |
#make_outputs(type, *names) ⇒ Object
Creates and adds a set of outputs typed +type+ from a list of +names+ in the current system.
NOTE: a name can also be a signal, is which case it is duplicated.
1254 1255 1256 |
# File 'lib/HDLRuby/hruby_high.rb', line 1254 def make_outputs(type, *names) self.parent.make_outputs(type,*names) end |
#merge_included(systemT) ⇒ Object
Merge the included systems interface in +systemT+ NOTE: incompatible with further to_low transformation.
1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 |
# File 'lib/HDLRuby/hruby_high.rb', line 1566 def merge_included(systemT) # puts "merge_included for scope=#{self.name} with behaviors=#{self.each_behavior.count}" # Recurse on the sub. self.each_scope {|scope| scope.merge_included(systemT) } # Include for current scope. self.each_included do |included| included.merge_included! # Adds its interface signals. included.each_input do |input| input.no_parent! systemT.add_input(input) end included.each_output do |output| output.no_parent! systemT.add_output(output) end included.each_inout do |inout| inout.no_parent! systemT.add_inout(inout) end # Adds its behaviors. included.scope.each_behavior do |beh| beh.no_parent! systemT.scope.add_behavior(beh) end # Adds its connections. included.scope.each_connection do |cx| cx.no_parent! systemT.scope.add_connection(cx) end # Adds its sytem instances. included.scope.each_systemI do |sys| sys.no_parent! systemT.scope.add_systemI(sys) end # Adds it programs. included.scope.each_program do |program| program.no_parent! systemT.scope.add_program(program) end # Adds its code. included.scope.each_code do |code| code.no_parent! systemT.scope.add_code(code) end # Adds its subscopes. included.scope.each_scope do |scope| # Do not override scopes with same name since it is prioritary! next if !scope.name.empty? && systemT.scope.each_scope.find {|sc| sc.name == scope.name} scope.no_parent! systemT.scope.add_scope(scope) end # Add its inner signals. included.scope.each_inner do |inner| inner.no_parent! systemT.scope.add_inner(inner) end end end |
#merge_included! ⇒ Object
Merge the included systems interface in system instances. NOTE: incompatible with further to_low transformation.
1628 1629 1630 1631 1632 1633 |
# File 'lib/HDLRuby/hruby_high.rb', line 1628 def merge_included! # Recurse on the sub. self.each_scope {|scope| scope.merge_included! } # Merge in the system instances. self.each_systemI {|systemI| systemI.systemT.merge_included! } end |
#open(&ruby_block) ⇒ Object
Opens for extension.
NOTE: actually executes +ruby_block+ in the context.
1171 1172 1173 1174 1175 1176 1177 1178 |
# File 'lib/HDLRuby/hruby_high.rb', line 1171 def open(&ruby_block) High.space_push(@namespace) res = High.top_user.instance_eval(&ruby_block) High.space_pop # Return the result of the execution so that it can be used # as an expression res end |
#output(*names) ⇒ Object
Declares high-level bit output signals named +names+ in the current system.
1284 1285 1286 |
# File 'lib/HDLRuby/hruby_high.rb', line 1284 def output(*names) self.parent.output(*names) end |
#par(*events, name: nil, &ruby_block) ⇒ Object
Declares a high-level parallel behavior activated on a list of +events+, with possible name +name+ and built by executing +ruby_block+. def par(*events, &ruby_block)
1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 |
# File 'lib/HDLRuby/hruby_high.rb', line 1380 def par(*events, name: nil, &ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? # Preprocess the events. events.map! do |event| event.respond_to?(:to_event) ? event.to_event : event end # Create and add the resulting behavior. self.add_behavior(Behavior.new(:par,*events,name: name, &ruby_block)) end |
#program(lang, func, &ruby_block) ⇒ Object
Declares a program in language +lang+ with start function named +func+ and built through +ruby_block+.
1296 1297 1298 1299 1300 1301 1302 1303 |
# File 'lib/HDLRuby/hruby_high.rb', line 1296 def program(lang, func, &ruby_block) # Create the program. prog = Program.new(lang, func, &ruby_block) # Adds the resulting program to the current scope. HDLRuby::High.top_user.add_program(prog) # Return the resulting program return prog end |
#seq(*events, name: nil, &ruby_block) ⇒ Object
Declares a high-level sequential behavior activated on a list of +events+, with possible name +name+ and built by executing +ruby_block+. def seq(*events, &ruby_block)
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 |
# File 'lib/HDLRuby/hruby_high.rb', line 1363 def seq(*events, name: nil, &ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? # Preprocess the events. events.map! do |event| event.respond_to?(:to_event) ? event.to_event : event end # Create and add the resulting behavior. # self.add_behavior(Behavior.new(:seq,*events,&ruby_block)) self.add_behavior(Behavior.new(:seq,*events,name: name, &ruby_block)) end |
#show_hierarchy(vcdout) ⇒ Object
Shows the hierarchy of the variables.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/HDLRuby/hruby_rsim_vcd.rb', line 168 def show_hierarchy(vcdout) # puts "show_hierarchy for scope=#{self}" # Shows the current level of hierarchy if there is a name. ismodule = false if !self.name.empty? && !self.parent.is_a?(SystemT) then vcdout << "$scope module #{HDLRuby::High.vcd_name(self.fullname)} $end\n" ismodule = true end # Shows the inner signals. self.each_inner do |sig| sig.show_hierarchy(vcdout) # # puts "showing inner signal #{HDLRuby::High.vcd_name(sig.fullname)}" # vcdout << "$var wire #{sig.type.width} " # # vcdout << "#{HDLRuby::High.vcd_name(sig.fullname)} " # vcdout << "#{HDLRuby::High.vcd_idstr(sig)} " # vcdout << "#{HDLRuby::High.vcd_name(sig.name)} $end\n" end # Recurse on the behaviors' blocks self.each_behavior do |beh| beh.block.show_hierarchy(vcdout) end # Recurse on the systemI's Eigen system. self.each_systemI do |sys| sys.systemT.show_hierarchy(vcdout) end # Recurse on the subscopes. self.each_scope do |scope| scope.show_hierarchy(vcdout) end # Close the current level of hierarchy if there is a name. if ismodule then vcdout << "$upscope $end\n" end end |
#sub(name = HDLRuby.uniq_name, &ruby_block) ⇒ Object
Declares a sub scope with possible +name+ and built from +ruby_block+. def sub(name = :"", &ruby_block)
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 |
# File 'lib/HDLRuby/hruby_high.rb', line 1343 def sub(name = HDLRuby.uniq_name, &ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? # Creates the new scope. # scope = Scope.new(name,&ruby_block) scope = Scope.new(name) # Add it self.add_scope(scope) # Build it. scope.build(&ruby_block) # puts "self=#{self}" # puts "self scopes=#{self.each_scope.to_a.join(",")}" # Use its return value return scope.return_value end |
#timed(&ruby_block) ⇒ Object
Declares a high-level timed behavior built by executing +ruby_block+. By default, timed behavior are sequential.
1394 1395 1396 1397 1398 1399 |
# File 'lib/HDLRuby/hruby_high.rb', line 1394 def timed(&ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? # Create and add the resulting behavior. self.add_behavior(TimeBehavior.new(:seq,&ruby_block)) end |
#to_low(low_name = nil) ⇒ Object
Converts the scope to HDLRuby::Low. +name+ is the name of the system containing the new low scope in case of top scope, should be used as name for it. NOTE: by convention, the name of the top scope is the name of the system.
1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 |
# File 'lib/HDLRuby/hruby_high.rb', line 1698 def to_low(low_name = nil) # Create the resulting low scope. # scopeL = HDLRuby::Low::Scope.new() low_name = self.name unless low_name scopeL = HDLRuby::Low::Scope.new(low_name) # # For debugging: set the source high object # scopeL.properties[:low2high] = self.hdr_id # self.properties[:high2low] = scopeL # Push the private namespace for the low generation. High.space_push(@namespace) # Pushes on the name stack for converting the internals of # the system. High.names_push # Adds the content of the actual system. self.fill_low(scopeL) # Restores the name stack. High.names_pop # Restores the namespace stack. High.space_pop # Return theresulting system. return scopeL end |
#to_rcsim(rcowner) ⇒ Object
Generate the C description of the scope comming from object whose C description is +rcowner+
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 153 def to_rcsim(rcowner) # puts "to_rcsim for scope=#{self}" # Create the scope C object. @rcscope = RCSim.rcsim_make_scope(self.name.to_s) # Set the owner. RCSim.rcsim_set_owner(@rcscope,rcowner) # Of the scope is a son of a SystemT, the owner of the sub objects # will be this systemT. Otherwise, it is the scope. subowner = self.parent.is_a?(SystemT) ? rcowner : @rcscope # Create and add the inner signals. if self.each_inner.any? then RCSim.rcsim_add_scope_inners(@rcscope,self.each_inner.map do|sig| # sig.to_rcsim(@rcscope) sig.to_rcsim(subowner) end) end # Create and add the system instances. if self.each_systemI.any? then RCSim.rcsim_add_scope_systemIs(@rcscope, self.each_systemI.map do |sys| # sys.to_rcsim(@rcscope) sys.to_rcsim(subowner) end) end # Create and add the sub scopes. if self.each_scope.any? then RCSim.rcsim_add_scope_scopes(@rcscope,self.each_scope.map do|sub| # sub.to_rcsim(@rcscope) sub.to_rcsim(subowner) end) end # Create and add the behaviors and connections. rcbehs = self.each_behavior.map {|beh| beh.to_rcsim(subowner)} # + # self.each_connection.map {|cxt| cxt.to_rcsim(subowner) } self.each_connection do |cnx| if !cnx.right.is_a?(RefObject) then rcbehs << cnx.to_rcsim(subowner) else # puts "cnx.left.object=#{cnx.left.object.fullname} cnx.right.object=#{cnx.right.object.fullname}" rcbehs << cnx.to_rcsim(subowner) if cnx.left.is_a?(RefObject) then sigL = cnx.left.object prtL = sigL.parent if prtL.is_a?(SystemT) and prtL.each_inout.any?{|e| e.object_id == sigL.object_id} then # puts "write to right with sigL=#{sigL.fullname}." rcbehs << Connection.new(cnx.right.clone,cnx.left.clone).to_rcsim(subowner) end end end end if rcbehs.any? then RCSim.rcsim_add_scope_behaviors(@rcscope,rcbehs) end # Create and add the programs. rcprogs = self.each_program.map {|prog| prog.to_rcsim(subowner)} if rcprogs.any? then RCSim.rcsim_add_scope_codes(@rcscope,rcprogs); end return @rcscope end |
#to_ref ⇒ Object
Converts to a new reference.
1267 1268 1269 |
# File 'lib/HDLRuby/hruby_high.rb', line 1267 def to_ref return RefObject.new(this,self) end |
#to_user ⇒ Object
Converts to a namespace user.
1081 1082 1083 1084 |
# File 'lib/HDLRuby/hruby_high.rb', line 1081 def to_user # Already a user. return self end |