Class: Comet::DSL::Hardware

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/comet/dsl/hardware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#quote

Constructor Details

#initialize(name, targets:, &block) ⇒ Hardware

Returns a new instance of Hardware.



20
21
22
23
24
25
26
27
28
# File 'lib/comet/dsl/hardware.rb', line 20

def initialize(name, targets:, &block)
  @name = name
  @targets = targets
  @sources = []
  @linker_ = nil
  @libraries = Set[]

  instance_exec(&block) if block_given?
end

Instance Attribute Details

#linker_Object (readonly)

Returns the value of attribute linker_.



36
37
38
# File 'lib/comet/dsl/hardware.rb', line 36

def linker_
  @linker_
end

#sourcesObject (readonly)

Returns the value of attribute sources.



35
36
37
# File 'lib/comet/dsl/hardware.rb', line 35

def sources
  @sources
end

#targetsObject (readonly)

Returns the value of attribute targets.



34
35
36
# File 'lib/comet/dsl/hardware.rb', line 34

def targets
  @targets
end

Instance Method Details

#hardware_for(device) ⇒ Object



42
43
44
# File 'lib/comet/dsl/hardware.rb', line 42

def hardware_for(device)
  device == targets ? self : []
end

#import(name, path: nil) ⇒ Object



16
17
18
# File 'lib/comet/dsl/hardware.rb', line 16

def import(name, path: nil)
  @libraries.add Library.new(name, path: path)
end

#librariesObject



38
39
40
# File 'lib/comet/dsl/hardware.rb', line 38

def libraries
  @libraries.to_a
end

#linker(*args, **kwargs, &block) ⇒ Object



11
12
13
14
# File 'lib/comet/dsl/hardware.rb', line 11

def linker(*args, **kwargs, &block)
  raise 'linker section redefined' unless @linker_.nil?
  @linker_ = Linker.new(*args, **kwargs, &block)
end

#linker?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/comet/dsl/hardware.rb', line 46

def linker?
  !@linker_.nil?
end

#source(language:, **kwargs, &block) ⇒ Object



7
8
9
# File 'lib/comet/dsl/hardware.rb', line 7

def source(language:, **kwargs, &block)
  @sources.push Source.create(language: language, **kwargs, &block)
end

#to_sObject



30
31
32
# File 'lib/comet/dsl/hardware.rb', line 30

def to_s
  "hardware #{@name} for #{@targets}"
end

#validate!Object



50
51
52
53
# File 'lib/comet/dsl/hardware.rb', line 50

def validate!
  sources.each(&:validate!)
  @linker.validate! unless @linker.nil?
end