<commit_before># Copyright 2020 Efabless Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

proc get_yosys_bin {} {
    set synth_bin yosys
    if { [info exists ::env(SYNTH_BIN)] } {
	set synth_bin $::env(SYNTH_BIN)
    }
    return $synth_bin
}

proc convert_pg_pins {lib_in lib_out} {
	try_catch sed -E {s/^([[:space:]]+)pg_pin(.*)/\1pin\2\n\1    direction : "inout";/g} $lib_in > $lib_out
}

proc run_yosys {args} {
	set ::env(CURRENT_STAGE) synthesis

	TIMER::timer_start

	set options {
		{-output optional}
	}
	set flags {
		-no_set_netlist
	}

    parse_key_args "run_yosys" args arg_values $options flags_map $flags

    if { [info exists arg_values(-output)] } {
		set ::env(SAVE_NETLIST) $arg_values(-output)
    } else {
		set ::env(SAVE_NETLIST) $::env(yosys_result_file_tag).v
    }
	if { [ info exists ::env(SYNTH_ADDER_TYPE)] && $::env(SYNTH_ADDER_TYPE) == "RCA" } {
		set ::env(SYNTH_READ_BLACKBOX_LIB) 1
	}

    set ::env(LIB_SYNTH_COMPLETE_NO_PG) [list]
	foreach lib $::env(LIB_SYNTH_COMPLETE) {
		set fbasename [file rootname [file tail $lib]]
		convert_pg_pins $lib $::env(TMP_DIR)/$fbasename.no_pg.lib
		lappend ::env(LIB_SYNTH_COMPLETE_NO_PG) $::env(TMP_DIR)/$fbasename.no_pg.lib
	}

	set report_tag_saver $::env(yosys_report_file_tag)
	set ::env(yosys_report_file_tag) [index_file $::env(yosys_report_file_tag)]

	try_catch [get_yosys_bin] \
		-c $::env(SYNTH_SCRIPT) \
		-l [index_file $::env(yosys_log_file_tag).log 0] \
		|& tee $::env(TERMINAL_OUTPUT)

	set ::env(yosys_report_file_tag) $report_tag_saver

	if { ! [info exists flags_map(-no_set_netlist)] } {
    	set_netlist $::env(SAVE_NETLIST)
	}

    if { $::env(LEC_ENABLE) && [file exists $::env(PREV_NETLIST)] } {
		logic_equiv_check -rhs $::env(PREV_NETLIST) -lhs $::env(CURRENT_NETLIST)
    }

    # The following is a naive workaround to the defparam issue.. it should be handled with
    # an issue to the OpenROAD verilog parser.
    if { [info exists ::env(SYNTH_EXPLORE)] && $::env(SYNTH_EXPLORE) } {
        puts_info "This is a Synthesis Exploration and so no need to remove the defparam lines."
    } else {
        try_catch sed -i {/defparam/d} $::env(CURRENT_NETLIST)
    }
    TIMER::timer_stop
    exec echo "[TIMER::get_runtime]" >> [index_file $::env(yosys_log_file_tag)_runtime.txt 0]
}

proc run_sta {args} {
    puts_info "Running Static Timing Analysis..."
	TIMER::timer_start
    if {[info exists ::env(CLOCK_PORT)]} {
		set report_tag_saver $::env(opensta_report_file_tag)
		set ::env(opensta_report_file_tag) [index_file $::env(opensta_report_file_tag)]

        try_catch sta $::env(SCRIPTS_DIR)/sta.tcl \
        |& tee $::env(TERMINAL_OUTPUT) [index_file $::env(opensta_log_file_tag) 0]

		set ::env(opensta_report_file_tag) $report_tag_saver
    } else {
        puts_warn "No CLOCK_PORT found. Skipping STA..."
    }
	TIMER::timer_stop
    exec echo "[TIMER::get_runtime]" >> [index_file $::env(opensta_log_file_tag)_runtime.txt 0]
}

proc run_synth_exploration {args} {
    puts_info "Running Synthesis Exploration..."

    set ::env(SYNTH_EXPLORE) 1

    run_yosys

    try_catch perl $::env(SCRIPTS_DIR)/synth_exp/analyze.pl $::env(yosys_log_file_tag).log > $::env(yosys_report_file_tag).exploration.html
    file copy $::env(SCRIPTS_DIR)/synth_exp/table.css $::env(REPORTS_DIR)/synthesis<commit_msg>index the input log file to synth_explore, fixes https://github.com/efabless/openlane/issues/250<commit_after># Copyright 2020 Efabless Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

proc get_yosys_bin {} {
    set synth_bin yosys
    if { [info exists ::env(SYNTH_BIN)] } {
	set synth_bin $::env(SYNTH_BIN)
    }
    return $synth_bin
}

proc convert_pg_pins {lib_in lib_out} {
	try_catch sed -E {s/^([[:space:]]+)pg_pin(.*)/\1pin\2\n\1    direction : "inout";/g} $lib_in > $lib_out
}

proc run_yosys {args} {
	set ::env(CURRENT_STAGE) synthesis

	TIMER::timer_start

	set options {
		{-output optional}
	}
	set flags {
		-no_set_netlist
	}

    parse_key_args "run_yosys" args arg_values $options flags_map $flags

    if { [info exists arg_values(-output)] } {
		set ::env(SAVE_NETLIST) $arg_values(-output)
    } else {
		set ::env(SAVE_NETLIST) $::env(yosys_result_file_tag).v
    }
	if { [ info exists ::env(SYNTH_ADDER_TYPE)] && $::env(SYNTH_ADDER_TYPE) == "RCA" } {
		set ::env(SYNTH_READ_BLACKBOX_LIB) 1
	}

    set ::env(LIB_SYNTH_COMPLETE_NO_PG) [list]
	foreach lib $::env(LIB_SYNTH_COMPLETE) {
		set fbasename [file rootname [file tail $lib]]
		convert_pg_pins $lib $::env(TMP_DIR)/$fbasename.no_pg.lib
		lappend ::env(LIB_SYNTH_COMPLETE_NO_PG) $::env(TMP_DIR)/$fbasename.no_pg.lib
	}

	set report_tag_saver $::env(yosys_report_file_tag)
	set ::env(yosys_report_file_tag) [index_file $::env(yosys_report_file_tag)]

	try_catch [get_yosys_bin] \
		-c $::env(SYNTH_SCRIPT) \
		-l [index_file $::env(yosys_log_file_tag).log 0] \
		|& tee $::env(TERMINAL_OUTPUT)

	set ::env(yosys_report_file_tag) $report_tag_saver

	if { ! [info exists flags_map(-no_set_netlist)] } {
    	set_netlist $::env(SAVE_NETLIST)
	}

    if { $::env(LEC_ENABLE) && [file exists $::env(PREV_NETLIST)] } {
		logic_equiv_check -rhs $::env(PREV_NETLIST) -lhs $::env(CURRENT_NETLIST)
    }

    # The following is a naive workaround to the defparam issue.. it should be handled with
    # an issue to the OpenROAD verilog parser.
    if { [info exists ::env(SYNTH_EXPLORE)] && $::env(SYNTH_EXPLORE) } {
        puts_info "This is a Synthesis Exploration and so no need to remove the defparam lines."
    } else {
        try_catch sed -i {/defparam/d} $::env(CURRENT_NETLIST)
    }
    TIMER::timer_stop
    exec echo "[TIMER::get_runtime]" >> [index_file $::env(yosys_log_file_tag)_runtime.txt 0]
}

proc run_sta {args} {
    puts_info "Running Static Timing Analysis..."
	TIMER::timer_start
    if {[info exists ::env(CLOCK_PORT)]} {
		set report_tag_saver $::env(opensta_report_file_tag)
		set ::env(opensta_report_file_tag) [index_file $::env(opensta_report_file_tag)]

        try_catch sta $::env(SCRIPTS_DIR)/sta.tcl \
        |& tee $::env(TERMINAL_OUTPUT) [index_file $::env(opensta_log_file_tag) 0]

		set ::env(opensta_report_file_tag) $report_tag_saver
    } else {
        puts_warn "No CLOCK_PORT found. Skipping STA..."
    }
	TIMER::timer_stop
    exec echo "[TIMER::get_runtime]" >> [index_file $::env(opensta_log_file_tag)_runtime.txt 0]
}

proc run_synth_exploration {args} {
    puts_info "Running Synthesis Exploration..."

    set ::env(SYNTH_EXPLORE) 1

    run_yosys

    try_catch perl $::env(SCRIPTS_DIR)/synth_exp/analyze.pl [index_file $::env(yosys_log_file_tag).log 0] > $::env(yosys_report_file_tag).exploration.html
    file copy $::env(SCRIPTS_DIR)/synth_exp/table.css $::env(REPORTS_DIR)/synthesis
{'fraction_non_alphanumeric': 0.12993548387096773, 'fraction_numerical': 0.004903225806451613, 'mean_word_length': 4.375173370319001, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3291925', 'n_tokens_mistral': 3051, 'n_tokens_neox': 2941, 'n_words': 659}