/* aec-file-epilogue
   Boiler plate epilogue code for files produced by AEC.
   Copyright (C) 1989, 1990 by James R. Larus (larus@cs.wisc.edu).

   AE and AEC are free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 1, or (at your option) any
   later version.

   AE and AEC are distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GNU CC; see the file COPYING.  If not, write to James R.
   Larus, Computer Sciences Department, University of Wisconsin--Madison,
   1210 West Dayton Street, Madison, WI 53706, USA or to the Free
   Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */

/* $Header: /var/home/larus/AE/AEC/RCS/aec-file-epilogue,v 2.0 90/02/09 17:23:37 larus Exp Locker: larus $ */


void ae_recreate(file_name, f)
     char *file_name;
     void (*f)();
{
  if (*file_name == '-' && *(file_name+1) =='\0')
    __ae_in_file = stdin;
  else
    if ((__ae_in_file = fopen(file_name, "r")) == NULL)
      {
	fprintf (stderr, "Cannot open file %s", file_name);
	exit (-1);
      }

  out_func = f;
  __aec_global_reg_init();
  if (setjmp (__ae_top_level_env) == 0)	/* i.e., first time call main */
#ifdef mips
    __ae_main();
#else
    __ae__main();
#endif
  fclose(__ae_in_file);
}


static default_callee() {};


static PFI address_to_callee(addr)
     unsigned long addr;
{
  register int low = 0;
  register int hi = ((sizeof(func_tbl)/sizeof(long))/2)-1;

  while (low <= hi)
    {
      register int mid = (low+hi)/2;
      if (func_tbl[2*mid] == addr)
	return (PFI) func_tbl[2*mid+1];
      else if (func_tbl[2*mid] < addr)
	low = mid+1;
      else
	hi = mid-1;
    }

  return default_callee;	/* Return call dummy function. */
}
