Class: RTL::Circuit

Inherits:
Object
  • Object
show all
Defined in:
lib/rtl/circuit.rb

Direct Known Subclasses

BinaryGate, Mux, Reg, UnaryGate

Constant Summary collapse

@@id =
-1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ Circuit

Returns a new instance of Circuit.



14
15
16
17
18
19
20
21
22
# File 'lib/rtl/circuit.rb', line 14

def initialize name=nil
  @name=name
  @iname="#{name}_#{@@id+=1}"
  @ports={in:[],out:[]}
  @signals=[]
  @components=[]
  @properties={}
  @color="cadetblue"
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



11
12
13
# File 'lib/rtl/circuit.rb', line 11

def color
  @color
end

#componentsObject

Returns the value of attribute components.



7
8
9
# File 'lib/rtl/circuit.rb', line 7

def components
  @components
end

#fatherObject

Returns the value of attribute father.



8
9
10
# File 'lib/rtl/circuit.rb', line 8

def father
  @father
end

#inameObject

Returns the value of attribute iname.



5
6
7
# File 'lib/rtl/circuit.rb', line 5

def iname
  @iname
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/rtl/circuit.rb', line 4

def name
  @name
end

#portsObject

Returns the value of attribute ports.



6
7
8
# File 'lib/rtl/circuit.rb', line 6

def ports
  @ports
end

#propertiesObject

Returns the value of attribute properties.



10
11
12
# File 'lib/rtl/circuit.rb', line 10

def properties
  @properties
end

#signalsObject

Returns the value of attribute signals.



9
10
11
# File 'lib/rtl/circuit.rb', line 9

def signals
  @signals
end

Instance Method Details

#add(element) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rtl/circuit.rb', line 24

def add element
  port=circuit=sig=element
  case element
  when Sig
    @signals<< sig
    sig.circuit=self
  when Port
    @ports[port.dir] << port
    port.circuit=self
  when Circuit
    @components << circuit
    circuit.father=self
  else
    raise "ERROR : when adding '#{element}'"
  end
end

#component_named(name) ⇒ Object



50
51
52
# File 'lib/rtl/circuit.rb', line 50

def component_named name
  @components.find{|comp| comp.iname==name}
end

#inputsObject



54
55
56
# File 'lib/rtl/circuit.rb', line 54

def inputs
  @ports[:in]
end

#make_libObject



79
80
81
82
83
84
# File 'lib/rtl/circuit.rb', line 79

def make_lib
  filename="#{name}.lib"
  File.open(filename,'w') do |f|
    f.puts Marshal.dump(self)
  end
end

#new_instanceObject



70
71
72
73
74
75
76
77
# File 'lib/rtl/circuit.rb', line 70

def new_instance
  @@clone_id||={}
  @@clone_id[name]||=-1
  @@clone_id[name]+=1
  clone=Marshal.load(Marshal.dump(self))
  clone.iname=self.name+"_#{@@clone_id[name]}"
  clone
end

#outputsObject



58
59
60
# File 'lib/rtl/circuit.rb', line 58

def outputs
  @ports[:out]
end

#port(name) ⇒ Object



45
46
47
48
# File 'lib/rtl/circuit.rb', line 45

def port name
  all=@ports[:in]+@ports[:out]
  all.flatten.find{|p| p.name==name}
end

#port_named(dir, name) ⇒ Object



41
42
43
# File 'lib/rtl/circuit.rb', line 41

def port_named dir,name
  @ports[dir].find{|p| p.name==name}
end

#to_dotObject



86
87
88
# File 'lib/rtl/circuit.rb', line 86

def to_dot
  Printer.new.print self
end

#wiresObject



62
63
64
65
66
67
68
# File 'lib/rtl/circuit.rb', line 62

def wires
  wires=[]
  wires << inputs.map{|p| p.fanout}
  wires << signals.map{|p| p.fanout}
  wires << components.map{|comp| comp.outputs.map{|o| o.fanout}}
  wires.flatten
end