yosys -import

{% if verilog_defines -%}
set defines {{ verilog_defines }}

foreach d ${defines} {
  set key [lindex $d 0]
  set val [lindex $d 1]
  verilog_defines "-D$key=$val"
}
{%- endif %}

verilog_defaults -push
verilog_defaults -add -defer

{% if incdirs -%}
verilog_defaults -add {{ incdirs }}
{%- endif %}

set file_table {{ file_table }}

foreach f ${file_table} {
  set file_path [lindex $f 0]
  set opts ""
  if {[llength $f] == 2} {
    set opts [lindex $f 1]
  }

  # Yosys does not like empty $opt variables
  if {$opts eq ""} {
    read_verilog $file_path
  } else {
    read_verilog $opts $file_path
  }
}

{% if verilog_params -%}
{{ verilog_params }}
{%- endif %}

verilog_defaults -pop

{{ synth_command }} {{ synth_options }} -top {{ top }}
write_blif {{ name }}.blif
write_json {{ name }}.json
write_edif {{ edif_opts }} {{ name }}.edif
