head	1.3;
access;
symbols
	bobbase:1.3
	bob:1.3
	r2_1:1.3
	r2_0:1.3
	r1_1_beta:1.2
	r1_1_alpha:1.2
	r1_0:1.2
	r0_11:1.1
	r0_10:1.1;
locks; strict;
comment	@# @;


1.3
date	94.08.22.15.20.29;	author thoth;	state Exp;
branches;
next	1.2;

1.2
date	94.05.08.19.42.21;	author thoth;	state Exp;
branches;
next	1.1;

1.1
date	94.01.31.16.50.30;	author thoth;	state Exp;
branches;
next	;


desc
@Generates code from a description of the neighborhood reductions.
@


1.3
log
@DOS-inspired name rework.
@
text
@#!/local/bin/perl

#
#	Copyright 1993, Center for Computer Vision and Visualization,
#	University of Florida.  All rights reserved.
#

#
# $Log: gen-nbh-c.perl,v $
# Revision 1.2  1994/05/08  19:42:21  thoth
# Automatic neighborhood reductions require change in spec file.
#
# Revision 1.1  1994/01/31  16:50:30  thoth
# Initial revision
#

sub absorber_subst {
	local ($fname,
		$init, $forw_init, $accum, $accvar, $forw_accvar, $final,
		$rtype, $name, $itype, $zero) = @@_;
	local ($ival, $tval, $rval) = ("#undef#","#undef#","#undef#");
	local($_);
	local($/) = -1;

	open(FILE, "<$fname") ||
		die "couldn't open $fname";

	$_ = <FILE>;

	if (m-^// _IVAL_=-) {
		print STDERR "IVAL: ", $';
	}

	s/\bFORW_INITIALIZE\b/$forw_init/g;
	s/\bINITIALIZE\b/$init/g;

	s/\bFORW_ACCUMULATEVAR\b/$forw_accvar/g;
	s/\bACCUMULATE\b/$accum/g;
	s/\bACCUMULATEVAR\b/$accvar/g;
	s/\bRESULT\b/$final/g;

	s/\bRTYPE\b/$rtype/g;
	s/CONV/$name/g;
	s/IBTYPE\b/$itype/g;
	s/\bZERO\b/$zero/g;

	local(@@_) = split("\n");
	foreach (@@_) {
		if (m:^\s*//\s*_IVAL_=:)    { $ival = $'; next; }
		if (m:^\s*//\s*_IRESULT_=:) { $rval = $'; next; }
		s/\bIVAL\b/$ival/g;
		s/\bIRESULT\b/$rval/g;
	}

	print join("\n", @@_);
	print "\n";

	$/ = '\n';

	close(FILE);
}

while (<>) {
    next if /^\s*$/;

    if (/^#/) {
	print "//", $';
	next;
    } elsif (/^"H?C/) {
	print $';
	next;
    }

    print "// $_";

    @@_ = split;

    local($sort) = shift(@@_);

    if ($sort eq "neighborhood") {

	local($rtype, $name, $itype, @@blah) = @@_;

	@@_ = @@blah;

	local($zero);

	while (@@_) {
	    $_ = shift(@@_);

	    if (/^zero=/) {
		$zero = $';
	    } else {
		warn "Unknown option $_. ";
	    }
	}

	local($init,$accum,$accvar,$final,$forw_init,$forw_accumvar);

	while ($_ = <>) {
	    chop;
	    next if /^#/;
	    last if $_ eq "end";

	    if (0) {
#	    } elsif (/^init:\s*/) {
#		$init = $';
	    } elsif (/^accum:\s*/) {
		$accum = $';
	    } elsif (/^accvar:\s*/) {
		$accvar = $';
#	    } elsif (/^final:\s*/) {
#		$final = $';
	    } elsif (/^forw_init:\s*/) {
		$forw_init = $'
	    } elsif (/^forw_accumvar:\s*/) {
		$forw_accumvar = $'
	    } else {
		die "unknown nbh-reduction field: $_\n";
	    }
	}
#	defined $init || die "no initiazlier for backward reduction $name\n";
	defined $accum || die "no accumulator for backward reduction $name\n";
	$accvar = $accum unless defined $accvar;
#	defined $final || die "no final for backward reduction $name\n";
	defined $forw_init || die "no initializer for forward reduction $name\n";
	defined $forw_accumvar || die "no accumulator for forward reduction $name\n";

	if ($zero ne "") {
	    &absorber_subst("nbh-reduction", $init, $forw_init,
			    $accum, $accvar, $forw_accumvar, $final,
			    $rtype, $name, $itype, $zero);
	} else {
	    print "// non-absorbers not handled yet\n";
	}

	print "\n";
    }
}
@


1.2
log
@Automatic neighborhood reductions require change in spec file.
@
text
@d9 4
a12 1
# $Log: gen-neighborhood-c.perl,v $
d130 1
a130 1
	    &absorber_subst("neighborhood-reduction", $init, $forw_init,
@


1.1
log
@Initial revision
@
text
@d9 4
a12 1
# $Log: gen-conv-c.perl,v $
d66 3
d99 1
d102 3
a104 2
	    if (/^init:\s*/) {
		$init = $';
d109 2
a110 2
	    } elsif (/^final:\s*/) {
		$final = $';
d116 1
a116 1
		die "unknown convolution field: $_\n";
d119 1
a119 1
	defined $init || die "no initiazlier for backward reduction $name\n";
d122 1
a122 1
	defined $final || die "no final for backward reduction $name\n";
@
