# Sample Makefile for using Machine SUIF.  
# 
# Two passes, dce and peep, are optional.  You invoke them by adding
# definitions to the make command.  For example:
#
#   make DO_DCE=yes DO_PEEP=yes test-input.s
#
# will produce the assembly file test-input from test-input.c using the
# optional dce and peep passes.
#
#
# See the notes under `Rules for a Machine SUIF back end' (below) for
# instructions on how to change the sequence of back-end passes.

ifndef CODETARGET
CODETARGET = alpha
# change above to 'x86' for x86 code generation
endif

# By default, do nothing!

all:
	@echo "Will generate code for $(CODETARGET)"

# Rules for the SUIF2 C front end:  low SUIF from C
#
%.suif: %.c
ifeq ($(CODETARGET),alpha)
	c2sby1	  $<
else
	c2s       $<
endif

%.lsf: %.suif
	do_lower  $< $@
IN   := lsf


# Rules for a Machine SUIF back end
#
# Each section below describes a pass in the sequence used to generate an
# Alpha assembly file.  The order of the passes is the same as the order of
# their sections in this file.
#
# To reorder passes, just rearrange the sections.  To delete a pass, just
# delete its section.
#
# To add a pass, insert a copy of an existing section in the desired place
# in the sequence.  Change the definition of OUT (the extension of the
# file you want your new pass to produce) and the `do_...' command that
# runs your pass.


### Begin s2m section:  SUIFvm (.svm) from low SUIF (.lsf)
#
OUT  := svm

.PRECIOUS: %.$(OUT)
%.$(OUT): %.$(IN)
	do_s2m    $< $@
IN   := $(OUT)
#
### End s2m section


### Begin gen section:  Alpha code with virtual registers (.avr) from SUIFvm (.svm)
#
OUT  := avr

.PRECIOUS: %.$(OUT)
%.$(OUT): %.$(IN)
	do_gen    -target_lib ${CODETARGET} $< $@
IN   := $(OUT)
#
### End gen section


### Begin il2cfg section:  alpha code in linear instruction lists (.ail)
#
OUT  := afg

.PRECIOUS: %.$(OUT)
%.$(OUT): %.$(IN)
	do_il2cfg $< $@
IN   := $(OUT)
#
### End il2cfg section


### Begin dce section:  SUIFvm with dead code eliminated (.dce)
#
ifdef DO_DCE

OUT  := dce

.PRECIOUS: %.$(OUT)
%.$(OUT): %.$(IN)
	do_dce    $< $@
IN   := $(OUT)

endif
#
### End dce section


### Begin raga section:  Alpha code with registers allocated (.ara)
#
OUT  := ara

.PRECIOUS: %.$(OUT)
%.$(OUT): %.$(IN)
	do_raga   $< $@
IN   := $(OUT)
#
### End raga section


### Begin peep section:  Alpha code with moves optimized (.amo)
#
ifdef DO_PEEP

OUT  := amo

.PRECIOUS: %.$(OUT)
%.$(OUT): %.$(IN)
	do_peep   $< $@
IN   := $(OUT)

endif
#
### End peep section


### Begin cfg2il section:  alpha code in linear instruction lists (.ail)
#
OUT  := ail

.PRECIOUS: %.$(OUT)
%.$(OUT): %.$(IN)
	do_cfg2il $< $@
IN   := $(OUT)
#
### End cfg2il section


### Begin fin section:  Alpha code with stack frames allocated (.asa)
#
OUT  := asa

.PRECIOUS: %.$(OUT)
%.$(OUT): %.$(IN)
	do_fin    $< $@
IN   := $(OUT)
#
### End fin section


### Begin m2a section:  Alpha assembly code (.s)
#
OUT  := s

%.$(OUT): %.$(IN)
	do_m2a    $< $@
IN   := $(OUT)
#
### End m2a section

