Class: ArtDecomp::Executable

Inherits:
Object
  • Object
show all
Defined in:
lib/art-decomp/executable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ Executable

Returns a new instance of Executable.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/art-decomp/executable.rb', line 7

def initialize args = ARGV
  opts = Trollop.options(args) do
    opt :archs,        'Target architecture(s)',               :type => :strings
    opt :outdir,       'Output directory',                     :type => :string
    opt :iters,        'Number of iterations, 0 for infinite', :default => 1
    opt :uv,           'UV generator(s)',                      :default => ['UniqueRelevance']
    opt :qu,           'Qu generator(s)',                      :default => ['EdgeLabels']
    opt :qv,           'Qv generator(s)',                      :default => ['GraphColouring']
    opt :binary,       'Compute binary decompositions',        :default => false
    opt :non_disjoint, 'Compute non-disjoint decompositions',  :default => false
    opt :deep_ndj,     'Compute deep non-dj decompositions',   :default => false
    opt :log,          'Logging target',                       :type => :string
    opt :debug,        'Log debug-level activities',           :default => false
  end

  opts[:uv] = UVGenerator.constants.map(&:to_s).sort if opts[:uv] == ['all']
  opts[:qu] = QuGenerator.constants.map(&:to_s).sort if opts[:qu] == ['all']
  opts[:qv] = QvGenerator.constants.map(&:to_s).sort if opts[:qv] == ['all']

  Trollop.die          'no FSM given'                      if     args.empty?
  Trollop.die          'FSM does not exist'                unless File.exists? args.first
  Trollop.die          'no architecture given'             unless opts[:archs_given]
  Trollop.die          'no output directory given'         unless opts[:outdir_given]
  Trollop.die :archs,  'not in the form of inputs/outputs' unless opts[:archs].all? { |s| s =~ /^\d+\/\d+$/ }
  Trollop.die :outdir, 'output directory exists'           if     File.exists? opts[:outdir]
  Trollop.die :uv,     'no such UV generator'              unless (opts[:uv] - UVGenerator.constants.map(&:to_s)).empty?
  Trollop.die :qu,     'no such Qu generator'              unless (opts[:qu] - QuGenerator.constants.map(&:to_s)).empty?
  Trollop.die :qv,     'no such Qv generator'              unless (opts[:qv] - QvGenerator.constants.map(&:to_s)).empty?

  Dir.mkdir opts[:outdir] rescue Trollop.die :outdir, 'output directory cannot be created'

  @dir          = opts[:outdir]
  @fsm          = FSM.from_kiss args.first
  @archs        = opts[:archs].map { |s| Arch[*s.split('/').map(&:to_i)] }.to_set
  @iters        = opts[:iters]
  @binary       = opts[:binary]
  @non_disjoint = opts[:non_disjoint]
  @deep_ndj     = opts[:deep_ndj]

  @uv_gens = opts[:uv].map { |gen| UVGenerator.const_get gen }
  @qu_gens = opts[:qu].map { |gen| QuGenerator.const_get gen }
  @qv_gens = opts[:qv].map { |gen| QvGenerator.const_get gen }

  if opts[:log_given]
    require_relative 'logging'
    Logging.log = opts[:log] == '-' ? $stdout : opts[:log]
    Logging.level = Logger::DEBUG if opts[:debug]
  end
end

Instance Attribute Details

#archsObject (readonly)

Returns the value of attribute archs.



5
6
7
# File 'lib/art-decomp/executable.rb', line 5

def archs
  @archs
end

#bestObject (readonly)

Returns the value of attribute best.



5
6
7
# File 'lib/art-decomp/executable.rb', line 5

def best
  @best
end

#dirObject (readonly)

Returns the value of attribute dir.



5
6
7
# File 'lib/art-decomp/executable.rb', line 5

def dir
  @dir
end

#itersObject (readonly)

Returns the value of attribute iters.



5
6
7
# File 'lib/art-decomp/executable.rb', line 5

def iters
  @iters
end

Instance Method Details

#gensObject



57
58
59
60
61
# File 'lib/art-decomp/executable.rb', line 57

def gens
  [@uv_gens, @qu_gens, @qv_gens].map do |gens|
    gens.map { |gen| gen.to_s.split('::').last }.join '+'
  end.join ', '
end

#run(dump_decs = true) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/art-decomp/executable.rb', line 63

def run dump_decs = true
  @best = @fsm.fsm_cells @archs
  dumps = Hash.new { |h, k| h[k] = [] }
  decompositions(@fsm, @iters, @dir, 0).each do |dec, dir, i|
    dumps[dir] << dec
    File.dump_object dec, "#{dir}/#{i}.dec" if dump_decs
  end unless @fsm.implementable_in? @archs
  dumps.each do |dir, decs|
    File.dump_object decs, "#{dir}/decompositions"
  end
end