sbsv1/abld/e32util/genshimsrc.bat
changeset 629 541af5ee3ed9
parent 599 fa7a3cc6effd
equal deleted inserted replaced
628:7c4a911dc066 629:541af5ee3ed9
       
     1 @REM Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 @REM All rights reserved.
       
     3 @REM This component and the accompanying materials are made available
       
     4 @REM under the terms of "Eclipse Public License v1.0"
       
     5 @REM which accompanies this distribution, and is available
       
     6 @REM at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 @REM
       
     8 @REM Initial Contributors:
       
     9 @REM Nokia Corporation - initial contribution.
       
    10 @REM 
       
    11 @REM Contributors:
       
    12 @REM
       
    13 
       
    14 @goto invoke
       
    15 
       
    16 #!perl
       
    17 
       
    18 use FindBin;		# for FindBin::Bin
       
    19 use Getopt::Long;
       
    20 use Cwd;
       
    21 
       
    22 $_ = cwd;
       
    23 tr/\//\\/;
       
    24 my $Pwd = $_;
       
    25 
       
    26 my $PerlLibPath;    # fully qualified pathname of the directory containing our Perl modules
       
    27 
       
    28 # establish the path to the Perl binaries
       
    29 BEGIN {
       
    30 	require 5.005_03;				# check user has a version of perl that will cope
       
    31 # establish the path to the Perl libraries: currently the same directory as this script
       
    32 	$PerlLibPath = $FindBin::Bin;	# X:/epoc32/tools
       
    33 	$PerlLibPath =~ s/\//\\/g;	# X:\epoc32\tools
       
    34 	$PerlLibPath .= "\\";
       
    35 }
       
    36 use lib $PerlLibPath;
       
    37 
       
    38 use Defutl;
       
    39 use Genutl;
       
    40 
       
    41 my %opts = ();
       
    42 
       
    43 my $result = GetOptions(\%opts,
       
    44 			"srcpath:s",
       
    45 			"defpath:s",
       
    46 			"name:s",
       
    47 			"version:s",
       
    48 			"alignstack",
       
    49 			"help",
       
    50 		       );
       
    51 
       
    52 Usage() if(!$result || $opts{'help'} || @ARGV < 1);
       
    53 
       
    54 my $srcPath = $opts{"srcpath"} || $Pwd;
       
    55 my $defPath = $opts{"defpath"} || $srcPath;
       
    56 my $outputName = $opts{"name"} || "shim";
       
    57 my %Version;
       
    58 if ($opts{version}) {
       
    59 	%Version = &Genutl_StringToVersion($opts{version}) or die "Bad version number\n";
       
    60 } else {
       
    61 	$Version{major} = 0;
       
    62 	$Version{minor} = 0;
       
    63 }
       
    64 
       
    65 my $infile = pop @ARGV;
       
    66 
       
    67 my @DefData;
       
    68 eval { &Def_ReadFileL(\@DefData, $infile); } ;
       
    69 die $@ if $@;
       
    70 
       
    71 sub WriteFunction($$$) {
       
    72   my ($ordinal, $branchTarget, $comment) = @_;
       
    73   my $fnName = "export_at_ordinal_$ordinal";
       
    74   if ($branchTarget =~ /^\"(.*)\"$/) {
       
    75 	  $branchTarget = $1;
       
    76 	}
       
    77   if ($comment =~ /(null)/) {
       
    78     $comment = $branchTarget;
       
    79   }
       
    80 
       
    81   print CPP <<FUNCTION_DEFINITION;
       
    82 
       
    83 EXPORT_C __NAKED__ int $fnName()
       
    84 //
       
    85 // $comment
       
    86 //
       
    87 	{
       
    88 	asm("B $branchTarget ");
       
    89 	}
       
    90 
       
    91 FUNCTION_DEFINITION
       
    92 }
       
    93 
       
    94 sub WriteFunctionAligned($$$) {
       
    95   my ($ordinal, $branchTarget, $comment) = @_;
       
    96   my $fnName = "export_at_ordinal_$ordinal";
       
    97   if ($branchTarget =~ /^\"(.*)\"$/) {
       
    98 	  $branchTarget = $1;
       
    99 	}
       
   100   if ($comment =~ /(null)/) {
       
   101     $comment = $branchTarget;
       
   102   }
       
   103 
       
   104   print CPP <<FUNCTION_DEFINITION2;
       
   105 
       
   106 EXPORT_C __NAKED__ int $fnName()
       
   107 //
       
   108 // $comment
       
   109 //
       
   110 	{
       
   111 	asm("stmfd sp!, {r4,lr} ");
       
   112 	asm("mov r4, sp ");
       
   113 	asm("bic sp, sp, #4 ");
       
   114 	asm("bl $branchTarget ");
       
   115 	asm("mov sp, r4 ");
       
   116 	asm("ldmfd sp!, {r4,pc} ");
       
   117 	}
       
   118 
       
   119 FUNCTION_DEFINITION2
       
   120 }
       
   121 
       
   122 sub WriteCppHeader($) {
       
   123   my ($filename) = @_;
       
   124   print CPP <<FILE_HEADER;
       
   125 //
       
   126 // $filename - generated by GENSHIMSRC.BAT
       
   127 //
       
   128 
       
   129 #include <e32def.h>
       
   130 #include <e32const.h>
       
   131 #include <cpudefs.h>
       
   132 
       
   133 FILE_HEADER
       
   134 }
       
   135 
       
   136 sub WriteExport($$$) {
       
   137   my ($ordinal, $export, $comment) = @_;
       
   138 
       
   139   if ($comment =~ /(null)/) {
       
   140     $comment = $export;
       
   141   }
       
   142   printf DEF "\t${export}=export_at_ordinal_${ordinal}__Fv \@ $ordinal NONAME \; $comment\n";
       
   143 }
       
   144 
       
   145 my $cppFile = "$srcPath\\$outputName\.cia";
       
   146 die "ERROR: Couldn't open $cppFile\n" unless open CPP, ">$cppFile";
       
   147 my $vstring = &Genutl_VersionToFileAugment(%Version);
       
   148 my $defFile = "$defPath\\${outputName}$vstring\.def";
       
   149 die "ERROR: Couldn't open $defFile\n" unless open DEF, ">$defFile";
       
   150 
       
   151 WriteCppHeader(uc "${outputName}.cia");
       
   152 printf DEF "EXPORTS\n";
       
   153 
       
   154 foreach my $defData (@DefData){
       
   155   my $ord = $$defData{Ordinal};
       
   156   if ($ord) {
       
   157 	my $name = $$defData{Name};
       
   158 	my $comment = $$defData{Comment};
       
   159 	if ($opts{alignstack}) {
       
   160 		WriteFunctionAligned($ord, $name, $comment);
       
   161 	} else {
       
   162 		WriteFunction($ord, $name, $comment);
       
   163 	}
       
   164 	WriteExport($ord, $name, $comment);
       
   165   }
       
   166 }
       
   167 
       
   168 close CPP;
       
   169 close DEF;
       
   170 
       
   171 #####################################################################
       
   172 sub Usage
       
   173 {
       
   174 	print <<EOT;
       
   175 
       
   176 genshimsrc
       
   177 
       
   178 	Generate source for a shim DLL and its associated deffile from a supplied deffile
       
   179 
       
   180 Usage:
       
   181 	genshimsrc [options] deffile
       
   182 
       
   183 Where:
       
   184 	[deffile]     The source deffile
       
   185 
       
   186 Options:
       
   187 	--srcpath         the path for the output source file (defaults to CWD)
       
   188 	--defpath         the path for the output DEF file (defaults to srcpath)
       
   189 	--name            the name to use for the output files (defaults to shim)
       
   190 	--version         the version to use for the output DEF file (defaults to 0.0)
       
   191 	--alignstack      use shims which align the stack to an 8 byte boundary
       
   192 EOT
       
   193 	exit 1;
       
   194 }
       
   195 
       
   196 1;
       
   197 
       
   198 __END__
       
   199 
       
   200 # Tell emacs that this is a perl script even 'though it has a .bat extension
       
   201 # Local Variables:
       
   202 # mode:perl
       
   203 # tab-width:4
       
   204 # End:
       
   205 
       
   206 :invoke
       
   207 @perl -x -S genshimsrc.bat %1 %2 %3 %4 %5 %6 %7 %8 %9