#! /bin/sh
#
# make-dll2svr -- Copyright (c) 2001 Eberhard Mattes
#
# This file is part of epocemx.
#
# epocemx is 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 2, or (at your option)
# any later version.
#
# epocemx is 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 epocemx; see the file COPYING.  If not, write to the
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#


# Generating assembly code is simpler than making pseudo C++ code like
# this work (would require declarations and casts and parsing <e32std.h>
# and <e32svr.h> is slow anyway):
#
# TInt Dll::GlobalAlloc (TInt aSize)
# {
#   return UserSvr::DllGlobalAlloc (_E32Dll, aSize);
# }

while read file args dllfun svrfun
do
  echo "@ $file.s -- this is a generated file, don't modify!" >$file.s

  >make-dll2svr.tmp
  dst=$args
  while [ "$dst" -gt 0 ]
  do
    src=`expr $dst - 1`
    echo "	mov	r$dst, r$src" >>make-dll2svr.tmp
    dst=$src  
  done
  sed -e "s/DLLFUN/$dllfun/" -e "s/SVRFUN/$svrfun/" \
      -e "/SHUFFLEARGS/r make-dll2svr.tmp" -e "/SHUFFLEARGS/d" \
      <dll2svr.template >>$file.s
done
rm make-dll2svr.tmp
