Class: Inst

Inherits:
Object
  • Object
show all
Defined in:
lib/Inst.rb

Overview

This class defines the Inst object. Inst is a superclass for many different subclasses. This class handles mostly generalizations of what happens in all of its subclasses. Inst objects are instantiated by the Parser component as they are found, and are connected to each other via their Port objects.

Direct Known Subclasses

Bufz, Dffpc, FivePorts, FourPorts, Mux2, OnePort, ThreePorts, TwoPorts

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, inputs = [], outputs = [], createnode = true) ⇒ Inst

This method is responsible for creating the correct number of input ports and output ports for each Inst object based on the arguments it recieves (inputs and outputs). It is also responsible for generating nodes for each output pin (this is the default behavior) unless is is explicitly instructed not to do so via an argument (createnode).



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/Inst.rb', line 10

def initialize(name,inputs = [], outputs = [], createnode = true)
  # make it so insts know their own name
  self.name = name
  self.nodes = ""
  self.inputs = ""
  self.outputs = ""
  @iports = {}
  
  # iterate to create input port(s)
  inputs.each do |d|
    portname = "#{name}p#{d}"
    @iports["#{portname}"] = Port.new(name, 'in', portname)
  end
  # iterate to create output port(s) and node(s) (for output pins)
  outputs.each do |d|
    portname = "#{name}p#{d}"
    @iports["#{portname}"] = Port.new(name, 'out', portname)
    nodes<<"#{name}p#{d}\tnode;\n" if createnode
  end
end

Instance Attribute Details

#inputsObject

Returns the value of attribute inputs.



6
7
8
# File 'lib/Inst.rb', line 6

def inputs
  @inputs
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/Inst.rb', line 6

def name
  @name
end

#nodesObject

Returns the value of attribute nodes.



6
7
8
# File 'lib/Inst.rb', line 6

def nodes
  @nodes
end

#outputsObject

Returns the value of attribute outputs.



6
7
8
# File 'lib/Inst.rb', line 6

def outputs
  @outputs
end

Instance Method Details

#abeloutObject

Generally this method returns the specific ABEL code to be output for this Inst object based on its connections on its input ports. The inst superclass defaults this value to a blank string so that if abelout is not defined in the subclass there will not be a method not found error.



47
48
49
# File 'lib/Inst.rb', line 47

def abelout
  ""
end

#get_port(pname) ⇒ Object

This method takes a port name as input (pname) and returns the port object corresponding to that port name



33
34
35
36
37
38
39
40
41
42
# File 'lib/Inst.rb', line 33

def get_port(pname)
  # get the port from the iports hash
  if pname =~ /p\d+/ 
    @iports["#{self.name}#{pname}"]
  elsif pname =~ /out/
    @iports["#{self.name}out"]
  else
    []
  end
end