lib/HDLRuby/hruby_rcsim.rb in HDLRuby-3.2.0 vs lib/HDLRuby/hruby_rcsim.rb in HDLRuby-3.3.0
- old
+ new
@@ -1,11 +1,13 @@
require 'set'
require 'HDLRuby'
require 'hruby_high_fullname'
require 'hruby_sim/hruby_sim'
+require 'rubyHDL'
+
module HDLRuby::High
##
# Library for describing the hybrid Ruby-C simulator of HDLRuby
@@ -187,11 +189,10 @@
# 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|
- # ICIICI
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)
@@ -207,12 +208,15 @@
end
if rcbehs.any? then
RCSim.rcsim_add_scope_behaviors(@rcscope,rcbehs)
end
- # Create and add the codes.
- # TODO!!
+ # 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
end
@@ -510,15 +514,95 @@
end
class Chunk
## Extends the Chunk class for hybrid Ruby-C simulation.
- # TODO!!
+ # Deprecated!!
end
class Code
## Extends the Code class for hybrid Ruby-C simulation.
- # TODO!!
+ # Deprecated!!
+ end
+
+ class Program
+ ## Extends the Program class for hybrid Ruby-C simulation.
+ # NOTE: produce a low-level Code, and not program. For now,
+ # Program is a high-level interface for software description and
+ # is not ment to be simulated as is. It may hcange in the future
+ # though.
+
+ attr_reader :rccode # The access to the C version of the code.
+
+ # Generate the C description of the code comming from object
+ # whose C description is +rcowner+.
+ # NOTE: also update the table of signals accessed from software
+ # code.
+ def to_rcsim(rcowner)
+ # puts "to_rcsim for program=#{self}"
+
+ # Create the code C object.
+ # puts "make code with self.class=#{self.class}"
+ @rccode = RCSim.rcsim_make_code(self.language.to_s, self.function.to_s)
+
+ # Set the owner.
+ RCSim.rcsim_set_owner(@rccode,rcowner)
+
+ # Create and add the events.
+ if self.each_actport.any? then
+ RCSim.rcsim_add_code_events(@rccode, self.each_actport.map do|ev|
+ ev.to_rcsim(@rccode)
+ end)
+ end
+
+ # Create the software interface.
+ if self.language == :ruby then
+ # Loads the code files.
+ self.each_code do |code|
+ Kernel.require("./"+code.to_s)
+ end
+ # Add the input ports.
+ self.each_inport do |sym, sig|
+ RubyHDL.inport(sym,sig.rcsignalI)
+ end
+ # Add the output ports.
+ self.each_outport do |sym, sig|
+ RubyHDL.outport(sym,sig.rcsignalI)
+ end
+ elsif self.language == :c then
+ # Loads the code file: only the last one remains.
+ self.each_code do |code|
+ code = code.to_s
+ # Check if the file exists.
+ unless File.file?(code) then
+ # The code name may be not complete,
+ # try ".so", ".bundle" or ".dll" extensions.
+ if File.file?(code+".so") then
+ code += ".so"
+ elsif File.file?(code + ".bundle") then
+ code += ".bundle"
+ elsif File.file?(code + ".dll") then
+ code += ".dll"
+ else
+ # Code not found.
+ raise "C code library not found: " + code
+ end
+ end
+ RCSim.rcsim_load_c(@rccode,code,self.function.to_s)
+ end
+ # Add the input ports.
+ self.each_inport do |sym, sig|
+ RCSim::CPorts[sym] = sig.rcsignalI
+ end
+ # Add the output ports.
+ self.each_outport do |sym, sig|
+ RCSim::CPorts[sym] = sig.rcsignalI
+ end
+ end
+
+
+ return @rccode
+ end
end
class Statement
## Extends the Statement class for hybrid Ruby-C simulation.