Class: HDLRuby::High::Program

Inherits:
Low::Program
  • Object
show all
Includes:
Hmissing
Defined in:
lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/hruby_rcsim.rb

Overview

Describes a program.

Constant Summary

Constants included from Hmissing

Hmissing::High, Hmissing::NAMES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hmissing

#method_missing

Constructor Details

#initialize(lang, func, &ruby_block) ⇒ Program

Create a program in language lang with start function named func and built through ruby_block.



2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
# File 'lib/HDLRuby/hruby_high.rb', line 2763

def initialize(lang, func, &ruby_block)
    # Create the program.
    super(lang,func)
    # Create the namespace for the program.
    @namespace = Namespace.new(self)
    # Build the program object.
    High.space_push(@namespace)
    High.top_user.instance_eval(&ruby_block)
    High.space_pop
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HDLRuby::High::Hmissing

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



2759
2760
2761
# File 'lib/HDLRuby/hruby_high.rb', line 2759

def namespace
  @namespace
end

#rccodeObject (readonly)

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.



534
535
536
# File 'lib/HDLRuby/hruby_rcsim.rb', line 534

def rccode
  @rccode
end

Instance Method Details

#actport(*evs) ⇒ Object

Adds new activation ports.



2793
2794
2795
# File 'lib/HDLRuby/hruby_high.rb', line 2793

def actport(*evs)
    evs.each(&method(:add_actport))
end

#arrayport(ports = {}) ⇒ Object

Adds new array ports.



2813
2814
2815
# File 'lib/HDLRuby/hruby_high.rb', line 2813

def arrayport(ports = {})
  ports.each { |k,v| self.add_arrayport(k,v) }
end

#code(*codes) ⇒ Object

Adds new code files.



2798
2799
2800
# File 'lib/HDLRuby/hruby_high.rb', line 2798

def code(*codes)
    codes.each(&method(:add_code))
end

#inport(ports = {}) ⇒ Object

Adds new input ports.



2803
2804
2805
# File 'lib/HDLRuby/hruby_high.rb', line 2803

def inport(ports = {})
  ports.each { |k,v| self.add_inport(k,v) }
end

#outport(ports = {}) ⇒ Object

Adds new output ports.



2808
2809
2810
# File 'lib/HDLRuby/hruby_high.rb', line 2808

def outport(ports = {})
  ports.each { |k,v| self.add_outport(k,v) }
end

#to_lowObject

Converts the if to HDLRuby::Low.



2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
# File 'lib/HDLRuby/hruby_high.rb', line 2775

def to_low
    # Create the resulting program.
    progL = HDLRuby::Low::Program.new(self.language,self.function)
    # Add the wakening events.
    self.each_actport  { |ev| progL.add_actport(ev.to_low) }
    # Add the code files.
    self.each_code   { |ev| progL.add_code(code) }
    # Add the input signals references.
    self.each_inport  { |p| progL.add_inport(p[0],p[1].to_low) }
    # Add the output signals references.
    self.each_outport { |p| progL.add_outport(p[0],p[1].to_low) }
    # Add the array signals references.
    self.each_arrayport { |p| progL.add_arrayport(p[0],p[1].to_low) }
    # Return the resulting program.
    return progL
end

#to_rcsim(rcowner) ⇒ Object

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.



540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/HDLRuby/hruby_rcsim.rb', line 540

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|
          if code.is_a?(Proc)
            Object.instance_eval(&code)
          else
            Kernel.require("./"+code.to_s)
          end
        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
        # Add the array ports.
        self.each_arrayport do |sym, sig|
            RubyHDL.arrayport(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
        # Add the array ports.
        self.each_arrayport do |sym, sig|
            RCSim::CPorts[sym] = sig.rcsignalI
        end
    end


    return @rccode
end