Bash Shell Scripts

Writing shell scripts

Bash shell scripts are text files Text files most efficiently built with programming editors (emacs or vi) File must be executable and in search path chmod 700 my_script PATH may not include .! An example shell script: #!/bin/bash #My first script "Hello World!" Bash Shell Scripts

Writing Bash shell scripts Compile a Verilog file with vlog #!/bin/bash if [ ! d work ] ; then echo work does not exist, making it vlib work fi if [ ! s adder.v ] ; then vlog adder.v fi work directory must exist before compilation Get scripts via wget, eg: wget http://web.engr.oregonstate.edu/~traylor/ece474/script

--- Bash Shell Scripts

Writing Bash shell scripts File attribute checking #!/bin/bash if [ ! s junk_dir ] ; then junk_dir fi Spaces around brackets are needed! File attribute checking d exists and is a directory e, a file exists f exists and is a regular file s file exists and is not empty

--- Bash Shell Scripts

Writing Bash shell scripts Compile Verilog then run a simultion #!/bin/bash if [ ! -d "work" ] ; then vlib work fi if [ -s "adder.v" ] ; then vlog adder.v #runs simulation with a do file and no GUI vsim adder -do do.do quiet else echo verilog file missing fi

--- Bash Shell Scripts

Writing Bash shell scripts vsim and arguments vsim entity_name do dofile.do quiet -c

-quiet (do not report loading file messages) -c (console mode, no GUI) -do (run vsim from a do file) +nowarnTFMPC (don’t warn about mismatched ports, scary) +nowarnTSCALE (don’t warn about timing mismatches) Try vsim help for command line arguements

--- Bash Shell Scripts

Writing Bash Shell Scripts (TCL Script) In another text file, we create a TCL script with commands for the simulator. The bash shell call to vsim will run the TCL script. First, add some waves.

#add all signals to wave window #add wave - -hex /* #or add signals one by one add wave -hex clk add wave -hex reset_n add wave -hex first_select add wave -hex rd_fifo add wave -hex data add wave -hex acc_out

--- Bash Shell Scripts

Writing Bash Shell Scripts (TCL script) Add a tabular output for automatic checking (list file) to the TCL script for vsim.

add list -nodelta configure list -strobestart {99 ns} -strobeperiod {100 ns} configure list -usestrobe 1 add list -notrigger -hex -width 12 -label data data add list -notrigger -hex -width 12 -label acc_out acc_out add list -notrigger -hex -width 12 -label first_select first_select

--- Bash Shell Scripts

Putting it all together If our TCL script has the command: write list adder.list it will write out the simulation results to adder.list like this:

ps data acc_out first_select rd_fifo 99000 22 000 1 0 199000 22 000 1 0 299000 22 000 1 0 399000 22 000 1 0 599000 22 000 0 0

Could we compare this data against another file? Sure!

--- Bash Shell Scripts

Putting it all together To compare against a golden vector file, first a verified correct first run, and save the results. These are the golden vectors.

#!/bin/bash #after the first run of vsim, save the vectors off to the side: vsim adder -do do.do -quiet -c +nowarnTFMPC +nowarnTSCALE adder.list adder.golden.list

## other stuff happens right here ##

#after the second run of vsim, compare the two list files diff adder.list adder.rtl.list >| diff_report

if [ ! -s "diff_report" ] ; then echo "HOORAY IT WORKS!" else echo "BOO HOO HOO, ITS BROKEN! fi

--- Bash Shell Scripts

Putting it all together File > write to file, but no clobbering >> append output >| clobber (overwrite) the file

--- Bash Shell Scripts

Putting it all together Shell variables and looping -dollar signs dereference variables #!/bin/bash #compiles verilog cell library into local work directory verilog_file_dir=/nfs/guille/a1/cadlibs/synop_lib/SAED_EDK90nm\ /Digital_Standard_Cell_Library/verilog echo "Compiling verilog source files in directory: $verilog_file_dir" for verilog_source in ‘ $verilog_file_dir‘ do vlog $verilog_file_dir/$verilog_source -work work done

--- Bash Shell Scripts

Putting it all together Make sure you remove old list files so you avoid false compares. for listfiles in ‘ls *.list‘ do Rf $listfiles echo "--> deleting listfile $listfiles <--" done

Split output vlog my_module.v | tee compile_log output goes to screen and to the file

---