From 826ac0352d03ca32ae524fbdd48a2a603a70fe12 Mon Sep 17 00:00:00 2001 From: Parth Kalgaonkar Date: Wed, 22 Apr 2026 15:48:52 +0530 Subject: [PATCH 1/5] Add formattter for genus tcl --- lib/flgen.rb | 1 + lib/flgen/genus_tcl_formatter.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 lib/flgen/genus_tcl_formatter.rb diff --git a/lib/flgen.rb b/lib/flgen.rb index 30c3a25..a32b840 100644 --- a/lib/flgen.rb +++ b/lib/flgen.rb @@ -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' diff --git a/lib/flgen/genus_tcl_formatter.rb b/lib/flgen/genus_tcl_formatter.rb new file mode 100644 index 0000000..cebb89c --- /dev/null +++ b/lib/flgen/genus_tcl_formatter.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module FLGen + class CadenceTCLFormatter < VivadoTCLFormatter + def format_macro(macro, value) + if value.nil? + "lappend flgen_defines -define #{macro}" + else + "lappend flgen_defines -define #{macro}=#{value}" + end + end + + def post_macros(io) + # do nothing + 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]} {} else {set flgen_defines {}}") + io.puts("read_hdl -lib worklib {*}$flgen_defines -sv $flgen_source_files") + end + + Formatter.add_formatter(:'genus-tcl', self) + end +end From ed595a86b4092b2dcaea397fe7a5d4c463a79482 Mon Sep 17 00:00:00 2001 From: Parth Kalgaonkar Date: Wed, 22 Apr 2026 19:57:14 +0530 Subject: [PATCH 2/5] Move common tcl formatting options to CommonTCLFormatter and add unittest for GenusTCLFormatter --- lib/flgen/common_tcl_formatter.rb | 41 +++++++++++++++++++++++++++++++ lib/flgen/genus_tcl_formatter.rb | 10 +++----- lib/flgen/vivado_tcl_formatter.rb | 28 +++------------------ spec/flgen/cli_spec.rb | 35 ++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 31 deletions(-) create mode 100644 lib/flgen/common_tcl_formatter.rb diff --git a/lib/flgen/common_tcl_formatter.rb b/lib/flgen/common_tcl_formatter.rb new file mode 100644 index 0000000..f181aea --- /dev/null +++ b/lib/flgen/common_tcl_formatter.rb @@ -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) + end + + def post_macros(io) + 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) + 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) + end + end +end diff --git a/lib/flgen/genus_tcl_formatter.rb b/lib/flgen/genus_tcl_formatter.rb index cebb89c..4e4f981 100644 --- a/lib/flgen/genus_tcl_formatter.rb +++ b/lib/flgen/genus_tcl_formatter.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true +require_relative 'common_tcl_formatter' + module FLGen - class CadenceTCLFormatter < VivadoTCLFormatter + class GenusTCLFormatter < CommonTCLFormatter def format_macro(macro, value) if value.nil? "lappend flgen_defines -define #{macro}" @@ -10,16 +12,12 @@ def format_macro(macro, value) end end - def post_macros(io) - # do nothing - 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]} {} else {set flgen_defines {}}") + io.puts("if {![info exists flgen_defines]} {set flgen_defines {}}") io.puts("read_hdl -lib worklib {*}$flgen_defines -sv $flgen_source_files") end diff --git a/lib/flgen/vivado_tcl_formatter.rb b/lib/flgen/vivado_tcl_formatter.rb index 61b1d30..d2db744 100644 --- a/lib/flgen/vivado_tcl_formatter.rb +++ b/lib/flgen/vivado_tcl_formatter.rb @@ -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}\"" @@ -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 diff --git a/spec/flgen/cli_spec.rb b/spec/flgen/cli_spec.rb index 4484f13..f3a35ed 100644 --- a/spec/flgen/cli_spec.rb +++ b/spec/flgen/cli_spec.rb @@ -139,6 +139,41 @@ 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 'vivadoで読み込み可能な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=vivado-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 + add_files -fileset [current_fileset] $flgen_source_files + TCL + end + end + context '--format=filelist-xsimが指定された場合' do let(:output) do 'out.f' From afc71bc8b741cc10b89c28f0080460ecb150ff77 Mon Sep 17 00:00:00 2001 From: Parth Kalgaonkar Date: Wed, 22 Apr 2026 19:59:40 +0530 Subject: [PATCH 3/5] Fix name in GenusTCLFormatter unittest --- spec/flgen/cli_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/flgen/cli_spec.rb b/spec/flgen/cli_spec.rb index f3a35ed..72dfaff 100644 --- a/spec/flgen/cli_spec.rb +++ b/spec/flgen/cli_spec.rb @@ -148,7 +148,7 @@ def expand_sample_path(path) allow(File).to receive(:open).with(output, 'w').and_yield(io) end - it 'vivadoで読み込み可能なTCLを書き出す' do + it 'genusで読み込み可能なTCLを書き出す' do cli.run(["--output=#{output}", '--format=genus-tcl', file_list]) expect(io.string).to eq(<<~TCL) # flgen version #{FLGen::VERSION} From da24f0fd4df84c9e45ec6baa950ceaf5d58db68c Mon Sep 17 00:00:00 2001 From: Parth Kalgaonkar Date: Wed, 22 Apr 2026 20:05:15 +0530 Subject: [PATCH 4/5] Fix header in expected file contents for genus-tcl unittest --- spec/flgen/cli_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/flgen/cli_spec.rb b/spec/flgen/cli_spec.rb index 72dfaff..ceb4130 100644 --- a/spec/flgen/cli_spec.rb +++ b/spec/flgen/cli_spec.rb @@ -154,7 +154,7 @@ def expand_sample_path(path) # flgen version #{FLGen::VERSION} # applied arguments # --output=#{output} - # --format=vivado-tcl + # --format=genus-tcl # #{file_list} set flgen_defines {} lappend flgen_defines -define #{macros[0]} From b831f30480bf26900f081402951ad07898befecd Mon Sep 17 00:00:00 2001 From: Parth Kalgaonkar Date: Wed, 22 Apr 2026 21:37:21 +0530 Subject: [PATCH 5/5] Fix expected text in GenusTCLFormatter unittest --- spec/flgen/cli_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/flgen/cli_spec.rb b/spec/flgen/cli_spec.rb index ceb4130..411234c 100644 --- a/spec/flgen/cli_spec.rb +++ b/spec/flgen/cli_spec.rb @@ -169,7 +169,6 @@ def expand_sample_path(path) lappend flgen_source_files "#{files[2]}" if {![info exists flgen_defines]} {set flgen_defines {}} read_hdl -lib worklib {*}$flgen_defines -sv $flgen_source_files - add_files -fileset [current_fileset] $flgen_source_files TCL end end