class BlifUtils::Netlist::LogicGate
Attributes
inputs[RW]
output[RW]
singleOutputCoverList[R]
Public Class Methods
new(inputs, output, single_output_cover_list)
click to toggle source
# File lib/blifutils/netlist.rb, line 59 def initialize (inputs, output, single_output_cover_list) @inputs = inputs @output = output @singleOutputCoverList = single_output_cover_list end
Public Instance Methods
get_LookUpTable()
click to toggle source
# File lib/blifutils/netlist.rb, line 95 def get_LookUpTable outputCovered = @singleOutputCoverList.collect{|inputs_output| inputs_output[1]}.uniq if outputCovered.length != 1 then abort "ERROR: Output cover list of gate \"#{@output.name}\" covers 1 and 0:\n#{@singleOutputCoverList.collect{|ins_out| " #{ins_out[0].collect{|ins| ins.to_s}.join.gsub('2','-')} #{ins_out[1]}\n"}.join}" end statedVal = outputCovered[0] if statedVal == 0 then defaultVal = 1 else defaultVal = 0 end tableLength = 2**(@inputs.length) #table = (0 ... tableLength).collect{defaultVal} table = Array.new(tableLength){defaultVal} statedIndexes = [] @singleOutputCoverList.each{|inputs_output| statedIndexes += expand_input_cover_list(inputs_output[0])} statedIndexes.uniq.each{|ind| table[ind] = statedVal} return table end
get_simulation_table()
click to toggle source
# File lib/blifutils/simulator_generator.rb, line 30 def get_simulation_table table = get_LookUpTable() tableLength = table.length uint32table = [] pos = 0 begin tableCont = 0 (0 ... 32).each do |j| tagada = pos + j break if tagada >= tableLength if table[tagada] == 1 then tableCont |= (1 << j) end end pos += 32 uint32table << tableCont end while pos < tableLength return uint32table.collect{|num| num.to_s}.join(', ') end
input_bit_width()
click to toggle source
# File lib/blifutils/netlist.rb, line 66 def input_bit_width return @inputs.length end
is_buffer?()
click to toggle source
# File lib/blifutils/netlist.rb, line 80 def is_buffer? return (@inputs.length == 1 and @singleOutputCoverList.length == 1 and @singleOutputCoverList[0][0][0] == 1 and @singleOutputCoverList[0][1] == 1) end
is_constant?()
click to toggle source
# File lib/blifutils/netlist.rb, line 85 def is_constant? return (@inputs.length == 0) end
to_blif()
click to toggle source
# File lib/blifutils/netlist.rb, line 71 def to_blif str = ".names #{@inputs.collect{|net| net.name}.join(' ')} #{@output.name}\n" @singleOutputCoverList.each do |inputs_output| str += "#{inputs_output[0].collect{|strbit| case strbit when 0 then '0' when 1 then '1' else '-' end}.join}#{unless inputs_output[0].empty? then ' ' end}#{inputs_output[1]}\n" end return str end
to_s()
click to toggle source
# File lib/blifutils/netlist.rb, line 90 def to_s return "Logic Gate \"#{@output.name}\"" end
Private Instance Methods
expand_input_cover_list(icl)
click to toggle source
# File lib/blifutils/netlist.rb, line 123 def expand_input_cover_list (icl) # icl is an array of 0, 1 and 2 for '-' # expanded = [] index = icl.index(2) if index.nil? then expanded << icl.reverse.collect{|n| n.to_s}.join.to_i(2) else newIcl1 = icl.collect{|n| n} newIcl2 = icl.collect{|n| n} newIcl1[index] = 0 newIcl2[index] = 1 expanded += expand_input_cover_list(newIcl1) expanded += expand_input_cover_list(newIcl2) end return expanded end