Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/flgen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
require_relative 'flgen/formatter'
require_relative 'flgen/file_list_formatter'
require_relative 'flgen/vivado_tcl_formatter'
require_relative 'flgen/genus_tcl_formatter'
require_relative 'flgen/file_list_xsim_formatter'
require_relative 'flgen/cli'
41 changes: 41 additions & 0 deletions lib/flgen/common_tcl_formatter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

module FLGen
class CommonTCLFormatter < Formatter
def format_header_line(line)
"# #{line}"
end

def pre_macros(io)
io.puts('set flgen_defines {}')
end

def format_macro(macro, value)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is also defined in the base formatter class. Please remove it from the CommonTCLFormatter class.

end

def post_macros(io)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as format_macro method.

end

def pre_include_directories(io)
io.puts('set flgen_include_directories {}')
end

def format_include_directory(directory)
"lappend flgen_include_directories \"#{directory}\""
end

def post_include_directories(io)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as format_macro method.

end

def pre_source_files(io)
io.puts('set flgen_source_files {}')
end

def format_file_path(path)
"lappend flgen_source_files \"#{path}\""
end

def post_source_files(io)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as format_macro method.

end
end
end
26 changes: 26 additions & 0 deletions lib/flgen/genus_tcl_formatter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require_relative 'common_tcl_formatter'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this like to flgen.rb.


module FLGen
class GenusTCLFormatter < CommonTCLFormatter
def format_macro(macro, value)
if value.nil?
"lappend flgen_defines -define #{macro}"
else
"lappend flgen_defines -define #{macro}=#{value}"
end
end

def post_include_directories(io)
io.puts("set_db init_hdl_search_path $flgen_include_directories")
end

def post_source_files(io)
io.puts("if {![info exists flgen_defines]} {set flgen_defines {}}")
io.puts("read_hdl -lib worklib {*}$flgen_defines -sv $flgen_source_files")
end

Formatter.add_formatter(:'genus-tcl', self)
end
end
28 changes: 3 additions & 25 deletions lib/flgen/vivado_tcl_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
# frozen_string_literal: true

module FLGen
class VivadoTCLFormatter < Formatter
def format_header_line(line)
"# #{line}"
end

def pre_macros(io)
io.puts('set flgen_defines {}')
end
require_relative 'common_tcl_formatter'

module FLGen
class VivadoTCLFormatter < CommonTCLFormatter
def format_macro(macro, value)
if value.nil?
"lappend flgen_defines \"#{macro}\""
Expand All @@ -22,26 +16,10 @@ def post_macros(io)
io.puts('set_property verilog_define $flgen_defines [current_fileset]')
end

def pre_include_directories(io)
io.puts('set flgen_include_directories {}')
end

def format_include_directory(directory)
"lappend flgen_include_directories \"#{directory}\""
end

def post_include_directories(io)
io.puts('set_property include_dirs $flgen_include_directories [current_fileset]')
end

def pre_source_files(io)
io.puts('set flgen_source_files {}')
end

def format_file_path(path)
"lappend flgen_source_files \"#{path}\""
end

def post_source_files(io)
io.puts('add_files -fileset [current_fileset] $flgen_source_files')
end
Expand Down
34 changes: 34 additions & 0 deletions spec/flgen/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,40 @@ def expand_sample_path(path)
end
end

context '--format=genus-tclが指定された場合' do
let(:output) do
'out.tcl'
end

before do
allow(File).to receive(:open).with(output, 'w').and_yield(io)
end

it 'genusで読み込み可能なTCLを書き出す' do
cli.run(["--output=#{output}", '--format=genus-tcl', file_list])
expect(io.string).to eq(<<~TCL)
# flgen version #{FLGen::VERSION}
# applied arguments
# --output=#{output}
# --format=genus-tcl
# #{file_list}
set flgen_defines {}
lappend flgen_defines -define #{macros[0]}
lappend flgen_defines -define #{macros[1]}
set flgen_include_directories {}
lappend flgen_include_directories "#{include_directories[0]}"
lappend flgen_include_directories "#{include_directories[1]}"
set_db init_hdl_search_path $flgen_include_directories
set flgen_source_files {}
lappend flgen_source_files "#{files[0]}"
lappend flgen_source_files "#{files[1]}"
lappend flgen_source_files "#{files[2]}"
if {![info exists flgen_defines]} {set flgen_defines {}}
read_hdl -lib worklib {*}$flgen_defines -sv $flgen_source_files
TCL
end
end

context '--format=filelist-xsimが指定された場合' do
let(:output) do
'out.f'
Expand Down