class Bliftax::Gate
Represents one logic gate in the BLIF file
Attributes
implicants[RW]
input_labels[R]
output_label[R]
Public Class Methods
new(labels)
click to toggle source
Initializes this gate with the labels for inputs and output.
@param labels [Array] the label names for the inputs and output. The
last element in the Array is the output label.
# File lib/bliftax/gate.rb, line 14 def initialize(labels) (*@input_labels, @output_label) = labels @implicants = [] end
Public Instance Methods
[](index)
click to toggle source
Returns the specified implicant.
@param index [Integer] the index of the implicant.
@return [Implicant] the specified implicant.
# File lib/bliftax/gate.rb, line 48 def [](index) @implicants[index] end
add_implicant(implicant)
click to toggle source
Adds an Implicant
to this gate.
@param implicant [Implicant, String, Array<Implicant, String>] the
implicant to add. If a String is passed, it is considered to be a two-token string with the first being the input bits and the second being the output bit. For example, '010 1' represents the three inputs being 0, 1, 0 and the output being 1 in this case. If an Array is given, it will add all of the implicants.
@return [Gate] the gate itself.
# File lib/bliftax/gate.rb, line 29 def add_implicant(implicant) case implicant when Implicant @implicants << implicant when String @implicants << Implicant.new(@input_labels, @output_label, implicant) when Array # Recursive call implicant.each { |i| add(i) } end self end
Also aliased as: <<
input_size()
click to toggle source
Returns the size of the inputs.
@return [Integer] the size of the inputs.
# File lib/bliftax/gate.rb, line 55 def input_size @input_labels.size end
to_blif()
click to toggle source
Returns a string representation of this gate in BLIF format.
@return [String] this gate in BLIF format.
# File lib/bliftax/gate.rb, line 62 def to_blif str = format(".names %s %s\n", @input_labels.join(SPACE), @output_label) @implicants.each do |implicant| str += format("%s\n", implicant.to_blif) end str end