#
# Rcsid[] = "$Id: Makefile,v 1.3 1999/10/14 23:41:51 seth Exp $";
#
# To run the demo, enter:
#
#      make run_compile
#      make demo
#      make demo_iddq
#
#
# This makefile is used to run a design through Zycad TDX compile/lsim/fsim/etc.,
# and will compare the results against results saved in the Test_sav directory.
#
# make test               - runs all of the tests and compares against previous results
# make update             - runs all of the tests and saves the results in Test_sav
# make copy               - saves the latest results in Test_sav
# make test_lsim          - runs only tdx_lsim and compares against previous results
# make test_fsim          - runs only tdx_fsim and compares against previous results
# make test_step          - runs only tdx_step and compares against previous results
# make test_atg           - runs only tdx_atg  and compares against previous results
# make update_lsim        - runs only tdx_lsim and saves the results in Test_sav
# make update_fsim        - runs only tdx_fsim and saves the results in Test_sav
# make update_step        - runs only tdx_step and saves the results in Test_sav
# make update_atg         - runs only tdx_atg  and saves the results in Test_sav
# make copy_lsim          - saves the latest tdx_lsim results in Test_sav
# make copy_fsim          - saves the latest tdx_fsim results in Test_sav
# make copy_step          - saves the latest tdx_step results in Test_sav
# make copy_atg           - saves the latest tdx_atg  results in Test_sav
#
# To use this makefile, you will probably have to add the following to your
# cshrc file: setenv MAKEFLAGS i   . Or use the -i option when running make.
# It may also be necessary to set the following: set nonomatch, and unset noclobber.
#
# The D macro below sets the circuit design_name. Almost all TDX output uses the
# circuit design_name and an extension.
#
# The results of comparisons are put in $D.diff_log
#
# Messages are printed to standard output when individual tests fail.
#
#
# Individual TDX programs can be changed when running this makefile with:
#
#     make test "LSIM_PROG=~user/work/tdx_lsim"
#     make test "FSIM_PROG=~user/work/tdx_fsim"
#
# Additional unix command-line options can be added when running
# individual TDX programs by setting the related macro:
#
#     make test "LSIM_OPTS=-l -t"
#
# These variables can also be changed with "setenv".
#

RM=@-rm -f
MV=@-mv -f
CP=@-cp
CAT=@-cat
TAIL=@-tail
ECHO=@-echo
MKDIR=@-mkdir
SORT=@-sort
GREP=@-grep

# put the bdiff_filter script into your path if not already there
# (it should be in the TDX_ROOT/bin directory)
#DIFF=@-diff -w
DIFF=@-bdiff_filter

# Null target to force a rule to be executed
FORCE:

ATG_PROG=tdx_atg
ATG_OPTS=
ATG=@-set -x; $(ATG_PROG)

FSIM_PROG=tdx_fsim
FSIM_OPTS=
FSIM=@-set -x; $(FSIM_PROG)

LSIM_PROG=tdx_lsim
LSIM_OPTS=
LSIM=@-set -x; $(LSIM_PROG)

IDDQ_PROG=tdx_iddq
IDDQ_OPTS=
IDDQ=@-set -x; $(IDDQ_PROG)

STEP_PROG=tdx_step
STEP_OPTS=
STEP=@-set -x; $(STEP_PROG)


CHANGEFLT_PROG=changeflt
CHANGEFLT_OPTS=
CHANGEFLT=@-set -x; $(CHANGEFLT_PROG)

COLLAPSE_PROG=collapse
COLLAPSE_OPTS=
COLLAPSE=@-set -x; $(COLLAPSE_PROG)

DCTTOOL_PROG=dcttool
DCTTOOL_OPTS=
DCTTOOL=@-set -x; $(DCTTOOL_PROG)

FCOMP_PROG=fcomp
FCOMP_OPTS=
FCOMP=@-set -x; $(FCOMP_PROG)

FGEN_PROG=fgen
FGEN_OPTS=
FGEN=@-set -x; $(FGEN_PROG)

FLT2FOG_PROG=flt2fog
FLT2FOG_OPTS=
FLT2FOG=@-set -x; $(FLT2FOG_PROG)

FOG2FLT_PROG=fog2flt
FOG2FLT_OPTS=
FOG2FLT=@-set -x; $(FOG2FLT_PROG)

LOADDC_PROG=loaddc
LOADDC_OPTS=
LOADDC=@-set -x; $(LOADDC_PROG)

LOOKVER_PROG=lookver
LOOKVER_OPTS=
LOOKVER=@-set -x; $(LOOKVER_PROG)

LOOKVHDL_PROG=lookvhdl
LOOKVHDL_OPTS=
LOOKVHDL=@-set -x; $(LOOKVHDL_PROG)

LOOKZYC_PROG=lookzyc
LOOKZYC_OPTS=
LOOKZYC=@-set -x; $(LOOKZYC_PROG)

MERGEFLT_PROG=mergeflt
MERGEFLT_OPTS=
MERGEFLT=@-set -x; $(MERGEFLT_PROG)

PARTFLT_PROG=partflt
PARTFLT_OPTS=
PARTFLT=@-set -x; $(PARTFLT_PROG)

REMOVEFLT_PROG=removeflt
REMOVEFLT_OPTS=
REMOVEFLT=@-set -x; $(REMOVEFLT_PROG)

REPORTER_PROG=reporter
REPORTER_OPTS=
REPORTER=@-set -x; $(REPORTER_PROG)

SFSIM_PROG=sfsim
SFSIM_OPTS=
SFSIM_BINS=-bin_path ~/work_o/sim
SFSIM=@-set -x; $(SFSIM_PROG)

TAP_PROG=tap
TAP_OPTS=
TAP=@-set -x; $(TAP_PROG)

VB2VHDL_PROG=vb2vhdl
VB2VHDL_OPTS=
VB2VHDL=@-set -x; $(VB2VHDL_PROG)

VBH2VHDL_PROG=vbh2vhdl
VBH2VHDL_OPTS=
VBH2VHDL=@-set -x; $(VBH2VHDL_PROG)

VEC2JED_PROG=vec2jed
VEC2JED_OPTS=
VEC2JED=@-set -x; $(VEC2JED_PROG)

VEC2ZYC_PROG=vec2zyc
VEC2ZYC_OPTS=
VEC2ZYC=@-set -x; $(VEC2ZYC_PROG)

VERILOGT_PROG=verilogt
VERILOGT_OPTS=
VERILOGT=@-set -x; $(VERILOGT_PROG)

VHDLT_PROG=vhdlt
VHDLT_OPTS=
VHDLT=@-set -x; $(VHDLT_PROG)

XPAND_PROG=xpand
XPAND_OPTS=
XPAND=@-set -x; $(XPAND_PROG)


D=gl85

SOURCES= \
    $D.fmd \
    $D.iddqinit \
    $D.lsiminit \
    $D.reporter_in \
    $D.reporter_in1 \
    $D.reporter_in2 \
    $D.tdxinit \
    $D.timeplate \
    $D.vec \
    $D.ver \
    acc_ctrl.ver \
    alu_8bit.ver \
    alu_ctrl.ver \
    alulogic.ver \
    buf8.ver \
    ctl_lgc1.ver \
    ctl_lgc2.ver \
    dataaddr.ver \
    decod2_4.ver \
    decod3_8.ver \
    flagunit.ver \
    g16bctr.ver \
    g4bctr.ver \
    hldlogic.ver \
    hltlogic.ver \
    inst_reg.ver \
    interupt.ver \
    intrupt1.ver \
    intrupt2.ver \
    intrupt3.ver \
    inv8.ver \
    m5.ver \
    mcdecode.ver \
    mux2to1.ver \
    mux_4bit.ver \
    ocnand.ver \
    oprlogic.ver \
    parity1.ver \
    pc_cntrl.ver \
    prioenco.ver \
    rdwrgen.ver \
    reg8bits.ver \
    reg_8bit.ver \
    reg_ctrl.ver \
    regctrl0.ver \
    regctrl1.ver \
    regpad.ver \
    regpairs.ver \
    shflogic.ver \
    sn54181.ver \
    sn85150.ver \
    sp_cntrl.ver \
    stater.ver \
    tempctrl.ver \
    vectrgen.ver


sources: init

all: init clean test

test tests: init test_compile test_lsim test_fsim test_step test_iddq

update: init update_compile update_lsim update_fsim update_step update_iddq

copy: init copy_compile copy_lsim copy_fsim copy_step copy_iddq

run_compile: init FORCE $D.fcomp_in
	$(RM) $D.compile_log
	$(RM) $D.flt
	$(RM) *.err
	$(VERILOGT) $(VERILOGT_OPTS) \
        buf8.ver \
        inv8.ver \
        decod2_4.ver \
        decod3_8.ver \
        mux_4bit.ver \
        sn85150.ver \
        mux2to1.ver \
        reg8bits.ver \
        reg_8bit.ver \
        acc_ctrl.ver \
        alu_ctrl.ver \
        ocnand.ver \
        flagunit.ver \
        g4bctr.ver \
        g16bctr.ver \
        hldlogic.ver \
        hltlogic.ver \
        inst_reg.ver \
        prioenco.ver \
        intrupt1.ver \
        intrupt2.ver \
        intrupt3.ver \
        m5.ver \
        mcdecode.ver \
        oprlogic.ver \
        pc_cntrl.ver \
        rdwrgen.ver \
        regctrl0.ver \
        regctrl1.ver \
        regpairs.ver \
        shflogic.ver \
        sn54181.ver \
        parity1.ver \
        alu_8bit.ver \
        sp_cntrl.ver \
        stater.ver \
        tempctrl.ver \
        vectrgen.ver \
        alulogic.ver \
        regpad.ver \
        ctl_lgc1.ver \
        ctl_lgc2.ver \
        dataaddr.ver \
        interupt.ver \
        reg_ctrl.ver \
        $D.ver lib/lca300k.ver                               >> $D.compile_log 2>&1
	$(FCOMP) -o $D.fcomp.flt -d $D.fcomp_in $(FCOMP_OPTS) $D >> $D.compile_log 2>&1
	$(COLLAPSE) -o $D.coll.flt -u -w -f $D.fcomp.flt      $D >> $D.compile_log 2>&1
	$(FCOMP) -c $(FCOMP_OPTS) $D                             >> $D.compile_log 2>&1

test_compile: init run_compile
	$(DIFF) $D.compile_log                 Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.flt                         Test_sav >> $D.diff_log 2>&1

update_compile: init run_compile copy_compile

copy_compile: init Test_sav FORCE
	$(CP)   $D.compile_log                 Test_sav
	$(CP)   $D.flt                         Test_sav

run_lsim: init FORCE
	$(RM) $D.lsim_log
	$(RM) $D.lsim.*
	$(LSIM) $D -spt_prtime off -spt      -outmodel $D.lsim $(LSIM_OPTS) >> $D.lsim_log 2>&1

test_lsim: init run_lsim
	$(DIFF) $D.lsim_log                 Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.lsim.log                 Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.lsim.spt                 Test_sav >> $D.diff_log 2>&1

update_lsim: init run_lsim copy_lsim

copy_lsim: init Test_sav FORCE
	$(CP)   $D.lsim_log    Test_sav
	$(CP)   $D.lsim.log    Test_sav
	$(CP)   $D.lsim.spt    Test_sav

run_fsim: init FORCE
	$(RM) $D.fsim_log
	$(RM) $D.fsim.*
	$(RM) *.stt
	$(FSIM) $D -spt_prtime off -spt       -outmodel $D.fsim $(FSIM_OPTS) >> $D.fsim_log 2>&1
	$(REPORTER) -d $D.reporter_in -f $D.fsim.out.flt $(REPORTER_OPTS) $D >> $D.fsim_log 2>&1

test_fsim: init run_fsim
	$(DIFF) $D.fsim_log                   Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.fsim.log                   Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.fsim.spt                   Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.fsim.dct                   Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.fsim.stt                   Test_sav >> $D.diff_log 2>&1

update_fsim: init run_fsim copy_fsim

copy_fsim: init Test_sav FORCE
	$(CP)   $D.fsim_log      Test_sav
	$(CP)   $D.fsim.log      Test_sav
	$(CP)   $D.fsim.spt      Test_sav
	$(CP)   $D.fsim.dct      Test_sav
	$(CP)   $D.fsim.stt      Test_sav

run_step: init FORCE $D.step_in
	$(RM) $D.step_log
	$(RM) $D.log
	$(RM) $D.step_fsim*
	$(STEP) $D -fault_file $D.fsim.out.flt -vector_file $D.vec \
                      >> $D.step_log < $D.step_in 2>&1
	$(FSIM) $D -spt_prtime off -spt null -ST -sc $D.1.step \
               -outmodel $D.step_fsim $(FSIM_OPTS) >> $D.step_fsim_log 2>&1
	$(REPORTER) -d $D.reporter_in -f $D.step_fsim.out.flt $D >> $D.step_fsim_log 2>&1

test_step: init run_step
	$(DIFF) $D.step_log                   Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.steplog                    Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.1.step                     Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.step_fsim_log              Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.step_fsim.log              Test_sav >> $D.diff_log 2>&1

update_step: init run_step copy_step

copy_step: init Test_sav FORCE
	$(CP)   $D.step_log       Test_sav
	$(CP)   $D.steplog        Test_sav
	$(CP)   $D.1.step         Test_sav
	$(CP)   $D.step_fsim_log  Test_sav
	$(CP)   $D.step_fsim.log  Test_sav

run_iddq: init FORCE
	$(RM) $D.iddq_log
	$(RM) $D.iddq.*
	$(IDDQ) $D -spt_prtime off -spt null -init_file $D.iddqinit \
                -outmodel $D.iddq $(IDDQ_OPTS) >> $D.iddq_log 2>&1

test_iddq: init run_iddq
	$(DIFF) $D.iddq_log                 Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.iddq.log                 Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.iddq.idq                 Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.iddq.iut                 Test_sav >> $D.diff_log 2>&1

update_iddq: init run_iddq copy_iddq

copy_iddq: init Test_sav FORCE
	$(CP)   $D.iddq_log    Test_sav
	$(CP)   $D.iddq.log    Test_sav
	$(CP)   $D.iddq.idq    Test_sav
	$(CP)   $D.iddq.iut    Test_sav

demo: init $D.step_in FORCE
	$(RM) $D.fsim_log
	$(RM) $D.fsim.*
	$(ECHO) "\
This is a demo of TDX_FSIM on the GL85 circuit described in Zycad's\
Information Packet.  The GL85 is a model of the 8085 microprocessor.\
The circuit contains 3000 gates and 193 flip-flops.  The timing and\
delays in the circuit are CRUCIAL for correct operation.  The fault\
simulation runs 2275 vectors on 5406 faults in less than 5 minutes\
getting 74% coverage."
	$(ECHO) ""
	$(DCTTOOL) -f $D.fsim.stt &
	$(FSIM) $D -spt null -outmodel $D.fsim >> $D.fsim_log 2>&1
	tail $D.fsim_log
	@sleep 5
	$(ECHO) ""
	$(ECHO) ""
	$(ECHO) "\
Next the fault REPORTER is run to identify the fault coverage in each\
of the major modules of the GL85.  Note that the fault coverage in the\
interrupt module (IT) is only 15%.  At this point the user may wish\
to add more vectors to exercise this module more completely."
	$(ECHO) ""
	$(REPORTER) -d $D.reporter_in -f $D.fsim.out.flt $D
	@sleep 5
	$(ECHO) ""
	$(ECHO) ""
	$(ECHO) "\
Next the TDX_STEP dynamic testability analysis tool is run to identify\
observation points that can be added to the circuit to quickly improve\
the fault coverage without adding more test vectors.  TDX_FSIM is then\
re-run using the observation points suggested by TDX_STEP.  The coverage\
of the original design verification vectors goes from 74% to 87%.  In the\
DCTTOOL display, the green curve (top) is the run with virtual observation\
points, and the yellow curve (bottom) is the coverage from the original\
TDX_FSIM run."
	$(ECHO) ""
	$(RM) $D.step_log
	$(RM) $D.log
	$(RM) $D.step_fsim*
	$(STEP) $D -fault_file $D.fsim.out.flt -vector_file $D.vec \
            < $D.step_in >> $D.step_log 2>&1
	$(DCTTOOL) -n 2 -f $D.step_fsim.stt -f $D.fsim.stt &
	$(FSIM) $D -spt_prtime off -spt null -ST -sc $D.1.step \
               -outmodel $D.step_fsim >> $D.step_fsim_log 2>&1
	$(REPORTER) -d $D.reporter_in -f $D.step_fsim.out.flt $D

demo_iddq: init FORCE
	$(RM) $D.iddq_log
	$(RM) $D.iddq.*
	$(ECHO) "\
TDX_IDDQ is a fast and flexible tool for generating and selecting\
quiesent current tests for CMOS circuits.  TDX_IDDQ offers a rich\
set of features for selecting a near-optimal set current measurement\
strobes, and to identify which vectors should NOT be strobed because\
of higher-than-normal fault-free quiesent current.  TDX_IDDQ also\
supports a fully programmable fault model.  Please see the file\
'gl85.fmd' for a description of the programmable fault model."
	$(ECHO) ""
	$(DCTTOOL) -n 2 -f $D.iddq.itt -f $D.fsim.stt &
	$(IDDQ) $D -spt_prtime off -spt null -init_file $D.iddqinit -outmodel $D.iddq >> $D.iddq_log 2>&1
	tail $D.iddq_log

# step command input file
$D.step_in: FORCE
	$(RM)                         $(@F)
	$(ECHO) "summary"         >> $(@F)
	$(ECHO) "advice all"      >> $(@F)
	$(ECHO) "levelize"        >> $(@F)
	$(ECHO) "tap range"       >> $(@F)
	$(ECHO) "quit"            >> $(@F)

# fcomp command input file for all faults
$D.fcomp_in: FORCE
	$(RM)                      $(@F)
	$(ECHO) "net loads VCC SA01 ignore" >> $(@F)
	$(ECHO) "net loads GND SA01 ignore" >> $(@F)
	$(ECHO) "net drivers WIRE_NET* SA01 ignore" >> $(@F)
	$(ECHO) "~.CK SA01 ignore"          >> $(@F)
	$(ECHO) "~.* SA01"                  >> $(@F)

Test_sav:
	$(MKDIR) Test_sav

clean: FORCE
	$(RM) \
    $D.atg.* \
    $D.atg_in \
    $D.atg_log \
    $D.iddq.* \
    $D.iddq_log \
    $D.step.* \
    $D.step_in \
    $D.step_log \
    $D.*.step \
    $D.*.scnviol \
    $D.level.scn \
    $D.step_fsim.* \
    $D.step_fsim_log \
    $D.c \
    $D.ckt \
    $D.cof \
    $D.compile_log \
    $D.dct \
    $D.diag \
    $D.diff_log \
    $D.ech \
    $D.err \
    $D.fcomp_in \
    $D.fff \
    $D.flt \
    $D.fcomp.flt \
    $D.coll.flt \
    $D.fsim.* \
    $D.fsim_log \
    $D.fst \
    $D.grf \
    $D.his \
    $D.ins \
    $D.kbg \
    $D.log \
    $D.luk \
    $D.nam \
    $D.names \
    $D.nnm \
    $D.o \
    $D.out.flt \
    $D.out.vec \
    $D.pat \
    $D.plb \
    $D.pnd \
    $D.rsc \
    $D.sfsim.* \
    $D.sfsim_falt* \
    $D.sfsim_good* \
    $D.sfsim_log \
    $D.smo \
    $D.sms \
    $D.steplog \
    $D.stt \
    $D.*.itt \
    $D.tap \
    $D.lsim.* \
    $D.lsim_log \
    $D.tme \
    verilogt.log \
    vhdlt.log \
    xpand.log \
    bxpand.log \
    *.smo *.sms *.err *.ind *.udp \
    *.ckt *.nam *.nnm *.eqv *.fff \
    *.wgl *.tstl *.vcd


init: $(SOURCES)
	$(RM) $D.diff_log

.DEFAULT:
	@echo "Unknown Makefile target '$@'"

# get from RCS
CO=co
COFLAGS=
%:: RCS/%,v
	$(CO) $(COFLAGS) $< $@
