Class: BlifUtils::Netlist::Latch

Inherits:
Component show all
Defined in:
lib/blifutils/netlist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

#isGate?, #isLatch?, #isSubcircuit?

Constructor Details

#initialize(input, output, initValue, ctrlType = :re, ctrlSig = nil) ⇒ Latch

Returns a new instance of Latch.



153
154
155
156
157
158
159
# File 'lib/blifutils/netlist.rb', line 153

def initialize (input, output, initValue, ctrlType = :re, ctrlSig = nil)
	@input = input
	@output = output
	@initValue = initValue
	@ctrlType = ctrlType
	@ctrlSig = ctrlSig
end

Instance Attribute Details

#ctrlSigObject (readonly)

Net



151
152
153
# File 'lib/blifutils/netlist.rb', line 151

def ctrlSig
  @ctrlSig
end

#ctrlTypeObject (readonly)

:fe, :re, :ah, :al, :as



150
151
152
# File 'lib/blifutils/netlist.rb', line 150

def ctrlType
  @ctrlType
end

#initValueObject (readonly)

0, 1, 2 for don’t care and 3 for unknown



149
150
151
# File 'lib/blifutils/netlist.rb', line 149

def initValue
  @initValue
end

#inputObject

Net



147
148
149
# File 'lib/blifutils/netlist.rb', line 147

def input
  @input
end

#outputObject

Net



148
149
150
# File 'lib/blifutils/netlist.rb', line 148

def output
  @output
end

Instance Method Details

#inputsObject



183
184
185
# File 'lib/blifutils/netlist.rb', line 183

def inputs
	return [@input]
end

#nameObject



188
189
190
# File 'lib/blifutils/netlist.rb', line 188

def name
	return @output.name
end

#set_clock(net_or_name) ⇒ Object



204
205
206
# File 'lib/blifutils/netlist.rb', line 204

def set_clock (net_or_name)
	@ctrlSig = net_or_name
end

#set_initial_value(value) ⇒ Object



209
210
211
212
# File 'lib/blifutils/netlist.rb', line 209

def set_initial_value (value)
	raise "Initial value must be an integer in the range 0..3" unless (value.kind_of?(Integer) and value >= 0 and value <= 3)
	@initValue = value
end

#set_type(type) ⇒ Object



198
199
200
201
# File 'lib/blifutils/netlist.rb', line 198

def set_type (type)
	raise "Type must be one of [nil, :fe, :re, :ah, :al, :as]" unless [nil, :fe, :re, :ah, :al, :as].include?(type)
	@ctrlType = type
end

#to_blifObject



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/blifutils/netlist.rb', line 162

def to_blif
	res  = ".latch #{@input.name} #{@output.name}"
	if @ctrlType
		res += " #{@ctrlType} "
		if @ctrlSig.nil?
			res += "NIL"
		elsif @ctrlSig.kind_of?(BlifUtils::Netlist::Net)
			res += @ctrlSig.name
		else
			res += @ctrlSig
		end
	end
	if @initValue
		res += " #{@initValue} "
	end
	res += "\n"

	return res
end

#to_sObject



193
194
195
# File 'lib/blifutils/netlist.rb', line 193

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