#! /usr/pkg/gnu/bin/perl

require "getopts.pl";		# including this to handle the command
				# line args

# acts as the driver for the translation from rcc output to mulsim
# acceptable input 

#	check the command line input, arg should be file.mas

die "usage: $0 -f filename -p path [-v]\n\t\t-v\tverbose\n" if $#ARGV < 0;

&Getopts('f:p:v');

$infile = $opt_f;
$mcc_path = $opt_p;
$verbose = $opt_v;

die if ($infile eq "");

@post_proc_calls = ("post_rcc_reorder_segments.prl $mcc_path",
		    'post_rcc_append_end.prl',
		    'post_rcc_strip_ampersands.prl',
		    'post_rcc_assembler_add.prl',
		    'post_rcc_strip_special_functions.prl',
		    'post_rcc_strip_print_string.prl',
		    'post_rcc_atomic_ops.prl',
		    'post_rcc_check_ERR.prl',
		    );		

foreach $index (0 .. $#post_proc_calls) {
    printf("\trunning:\t$post_proc_calls[$index]\n") if $verbose;
    $comm = $mcc_path . '/lib/' . $post_proc_calls[$index];
    if ($ret_val = system("$comm $infile")) { exit($ret_val) };
    printf("\tcompleted:\t$post_proc_calls[$index]\n") if $verbose;
}

open (INF, ">> $infile");
print INF "; $0 has run\n";
close (INF);


