Class: Reggae::Compiler

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCompiler

Returns a new instance of Compiler.



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

def initialize
  puts "Reggae generator #{VERSION}"
  @options={}
end

Instance Attribute Details

#astObject

Returns the value of attribute ast.



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

def ast
  @ast
end

Instance Method Details

#analyze_options(args) ⇒ Object



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/reggae/compiler.rb', line 19

def analyze_options args
  args << "-h" if args.empty?

  opt_parser = OptionParser.new do |opts|
    opts.banner = "Usage: reggae <filename.sexp>"

    opts.on("-v", "--version", "Prints version") do
      puts VERSION
      abort
    end

    opts.on("-h", "--help", "Prints this help") do
      puts
      puts "Generates an IP-based system, from its memory-map expressed in s-expressions."
      puts
      puts "Author mail: [email protected]"
      puts
      @options[:show_help]=true
      puts opts
      abort
    end

    opts.on("-s", "--system", "Generates a top-level system") do
      @options[:gen_system]=true
    end

    opts.on("-d","Shows VHDL generated in the terminal,during generation") do
      @options[:show_code]=true
    end

    opts.on("-u", "--include_uart", "Generates an UART Master in the system top-level") do
      @options[:include_uart]=true
    end

    opts.on("--gen_ruby", "Generates Ruby code to interact with the system from a PC host") do
      @options[:gen_ruby]=true
    end

    opts.on("-x", "--gen_xdc", "Generates a Xilinx XDC constraint file for Artix7 FPGA (IP only)") do
      @options[:gen_xdc]=true
    end

    opts.on("--from_vivado_hls", "Indicates that the sexp file is generated from VHDL_WRAP tuned for VivadoHLS") do
      @options[:from_vivado_hls]=true
    end
  end

  begin
    opt_parser.parse!(args)
  rescue Exception => e
    puts e
    #puts e.backtrace
    exit
  end
  @filename = ARGV.pop
  $dirname = File.dirname(@filename) if @filename
  unless @filename or @options[:show_help]
    puts "Need to specify a filename to process"
    #exit
  end
end

#compileObject



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/reggae/compiler.rb', line 81

def compile
  if @options.any?
    puts
    puts "running with the following options :"
    pp @options
    puts
  end
  @ast=parse(@filename)
  #pretty_print
  generate_vhdl
end

#generate_vhdlObject



104
105
106
107
# File 'lib/reggae/compiler.rb', line 104

def generate_vhdl
  puts "=> generating VHDL..."
  Reggae::VHDLGenerator.new(@options).generate_from(ast)
end

#parse(filename) ⇒ Object



93
94
95
96
97
# File 'lib/reggae/compiler.rb', line 93

def parse filename
  puts "=> parsing #{filename}"
  $working_dir=Dir.pwd
  @ast=Reggae::Parser.new.parse(filename)
end

#pretty_printObject



99
100
101
102
# File 'lib/reggae/compiler.rb', line 99

def pretty_print
  puts "=> pretty print..."
  Reggae::Visitor.new.visit(ast)
end