Class: Bufz

Inherits:
Inst show all
Defined in:
lib/Bufz.rb

Overview

This class defines the Tri-State Buffer part

Instance Attribute Summary

Attributes inherited from Inst

#inputs, #name, #nodes, #outputs

Instance Method Summary collapse

Methods inherited from Inst

#get_port

Constructor Details

#initialize(name) ⇒ Bufz

This method is called when a new object is instantiated, it takes the name of the Inst object (name) as its only argument. Because of its unique functionality, this object does not call its superclass upon instantiation but rather handles all initialization procedures itself, it sets its attributes, defines the apropriate input and output pins, definines its nodes, and initializes the apropriate ports.



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

def initialize(name)
  # TODO - it is retarted that this inherits from Inst since it never calls super
  # make it so insts know their own name
  self.name = name
  self.inputs = ""
  # create constant definitions for each output pin
  self.nodes = "#{name}out\tnode;\n"
  self.outputs = "#{name}pin\tpin;\n"
  @iports = {}
  
  # iterate to create input port(s)
  (0..1).to_a.each do |d|
    portname = "#{name}p#{d}"
    @iports["#{portname}"] = Port.new(name, 'in', portname)
  end
  
  # Fake out an output port (we will act like we are connecting pins to this port, but really it references an output pin)
  # ABEL doesn't know the difference since we have called our output pin the same name as this faked out port
  @iports["#{name}out"] = Port.new(name, 'out', "#{name}out")
end

Instance Method Details

#abeloutObject

This method defines the connections held by the ports of this object and returns the specific ABEL code to be output for this object based on the connections on its input ports.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/Bufz.rb', line 31

def abelout
 # create defs only for inputs to inst
 # make these insts just for consistency's sake
 @p0 = self.get_port("p0").connections.collect{|p| p.name}.to_s
 @p1 = self.get_port("p1").connections.collect{|p| p.name}.to_s
 
 # code for all tristate buffers on b2logic component
 s = "\n\"tristate buffer - consumes one external pin\n#{self.name}pin.oe = 0;\n"
 unless @p0.empty? || @p1.empty?
   s << "WHEN (#{@p0}) THEN \n\t{#{self.name}pin.oe = 1;\n"
   s << "\t#{self.name}pin = #{@p1};}\n"
 end
   s << "#{self.name}out = #{self.name}pin.pin;\n\n"
end