Class: Vertigo::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/vertigo/compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Compiler

Returns a new instance of Compiler.



14
15
16
# File 'lib/vertigo/compiler.rb', line 14

def initialize options={}
  @options=options
end

Instance Attribute Details

#astObject

Returns the value of attribute ast.



12
13
14
# File 'lib/vertigo/compiler.rb', line 12

def ast
  @ast
end

#optionsObject

Returns the value of attribute options.



11
12
13
# File 'lib/vertigo/compiler.rb', line 11

def options
  @options
end

Instance Method Details

#compile(filename) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vertigo/compiler.rb', line 18

def compile filename
  begin
    parse(filename)
    puts "=> parsed successfully. Good" unless options[:mute]
    dump_ast if options[:dump_ast]
    pretty_print if options[:pp] or options[:pp_to_file]
    return true
  rescue Exception => e
    puts e.backtrace unless options[:mute]
    puts e unless options[:mute]
    raise
  end
end

#dump_astObject



38
39
40
# File 'lib/vertigo/compiler.rb', line 38

def dump_ast
  pp @ast
end

#gen_tb(filename) ⇒ Object



56
57
58
59
# File 'lib/vertigo/compiler.rb', line 56

def gen_tb filename
  parse filename
  TestBenchGenerator.new(options).generate_from(ast)
end

#parse(filename) ⇒ Object



32
33
34
35
36
# File 'lib/vertigo/compiler.rb', line 32

def parse filename
  puts "=> parsing VHDL file : #{filename}" unless options[:mute]
  @basename=File.basename(filename,File.extname(filename))
  @ast=Parser.new(options).parse filename
end

#pretty_printObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vertigo/compiler.rb', line 42

def pretty_print
  puts "=> pretty printing" unless options[:mute]
  begin
    code=PrettyPrinter.new.print(ast)
    file=code.save_as "#{@basename}_pp.vhd" if options[:pp_to_file]
    puts "   - saved as #{file}" if options[:pp_to_file] unless options[:mute]
    puts code.finalize if options[:pp]
  rescue Exception => e
    puts e.backtrace if options[:pp]
    puts e if options[:pp]
    raise "pp error"
  end
end