Class: BlifUtils::Netlist::LogicGate

Inherits:
Component
  • Object
show all
Defined in:
lib/blifutils/netlist.rb,
lib/blifutils/simulator_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

#isGate?, #isLatch?, #isSubcircuit?

Constructor Details

#initialize(inputs, output, single_output_cover_list) ⇒ LogicGate

Returns a new instance of LogicGate.



59
60
61
62
63
# 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

Instance Attribute Details

#inputsObject

Net, …

inputs output



55
56
57
# File 'lib/blifutils/netlist.rb', line 55

def inputs
  @inputs
end

#outputObject

Net | |



56
57
58
# File 'lib/blifutils/netlist.rb', line 56

def output
  @output
end

#singleOutputCoverListObject (readonly)

[[val, …], val], …

val is 0, 1 or 2 for -



57
58
59
# File 'lib/blifutils/netlist.rb', line 57

def singleOutputCoverList
  @singleOutputCoverList
end

Instance Method Details

#get_LookUpTableObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 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_tableObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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_widthObject



66
67
68
# File 'lib/blifutils/netlist.rb', line 66

def input_bit_width
	return @inputs.length
end

#is_buffer?Boolean

Returns:

  • (Boolean)


80
81
82
# 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?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/blifutils/netlist.rb', line 85

def is_constant?
	return (@inputs.length == 0)
end

#to_blifObject



71
72
73
74
75
76
77
# 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_sObject



90
91
92
# File 'lib/blifutils/netlist.rb', line 90

def to_s
	return "Logic Gate \"#{@output.name}\""
end