os/graphics/graphicsdeviceinterface/bitgdi/bitgdi_switch/generate_stubs.pl
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 #!/bin/perl -w
     2 
     3 # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     4 # All rights reserved.
     5 # This component and the accompanying materials are made available
     6 # under the terms of "Eclipse Public License v1.0"
     7 # which accompanies this distribution, and is available
     8 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
     9 #
    10 # Initial Contributors:
    11 # Nokia Corporation - initial contribution.
    12 #
    13 # Contributors:
    14 #
    15 # Description:
    16 # Generates the bitgdi_stubs.h header file and the bitgdiswitchU.def
    17 # file from the bitgdi2U def file.
    18 # 
    19 #
    20 
    21 use strict;
    22 my $COPYRIGHT = "Copyright (c) 2004-2009 Nokia Corporation. All rights reserved.";
    23 
    24 my $BITGDI_DEF = "../BWINS/BITGDI2U.def";
    25 my $BITGDISWITCH_HEADER = "bitgdi_stubs.h";
    26 my $BITGDISWITCH_DEF = "../BWINS/bitgdiswitchu.def";
    27 my $SOURCE_DEF_SIZE = 0;
    28 
    29 &main();
    30 exit(0);
    31 
    32 sub main() {
    33 	my $maxOrdinal = 1;
    34 
    35 	open DEF, $BITGDI_DEF or
    36 		die "Cannot open $BITGDI_DEF\n";
    37 
    38 	my ($dev, $ino, $mode, $nlink, $uid, $gid, 
    39 		$rdev, $size, $atime, $mtime, $ctime, 
    40 		$blksize, $blocks) 
    41 		= stat($BITGDI_DEF);
    42 	# the file size could be checked by the switcher build to verify that the stub is up to date.
    43     $SOURCE_DEF_SIZE= $size;
    44     
    45 	open HEADER_OUT, ">${BITGDISWITCH_HEADER}" or
    46 		die "Cannot create $BITGDISWITCH_HEADER\n";
    47 
    48 	open DEF_OUT, ">${BITGDISWITCH_DEF}" or
    49 		die "Cannot create $BITGDISWITCH_DEF\n";
    50 
    51 	&printHeaderStart(\*HEADER_OUT);
    52 	&printDefStart(\*DEF_OUT);
    53 
    54 	while (<DEF>) {
    55 		chomp;
    56 		if (/^\s+\?/) {
    57 			if (s/.*;/;/) {
    58 				&printDefEntry(\*DEF_OUT, $maxOrdinal, $_);
    59 				&printHeaderEntry(\*HEADER_OUT,$maxOrdinal,$_);
    60 			} else {
    61 				&printDefEntry(\*DEF_OUT, $maxOrdinal, "");
    62 				&printHeaderEntry(\*HEADER_OUT,$maxOrdinal, "(noname)");
    63 			}
    64 			$maxOrdinal++;
    65 		}
    66 	}
    67 	&printHeaderEnd(\*HEADER_OUT,$maxOrdinal);
    68 	&printDefEnd(\*DEF_OUT);
    69 
    70 	close DEF;
    71 	close HEADER_OUT;
    72 	close DEF_OUT;
    73 }
    74 
    75 sub printDefStart(\$) {
    76 	my ($fh) = @_;
    77 	print $fh "EXPORTS\n";
    78 }
    79 
    80 sub printDefEntry(\$\$\$) {
    81 	my ($fh, $ordinal, $comment) = @_;
    82 	print $fh "\tcall_vector_${ordinal} @ ${ordinal} NONAME $comment\n";
    83 }
    84 
    85 sub printDefEnd(\$) {
    86 	my ($fh) = @_;
    87 	print $fh "\n";
    88 }
    89 
    90 sub printHeaderStart(\$) {
    91 	my ($fh) = @_;
    92 
    93 	print $fh "// Generated from \"$BITGDI_DEF\" file size: $SOURCE_DEF_SIZE\n" .
    94 		"// $COPYRIGHT\n" .
    95 		"\n" .
    96 		"extern \"C\" {\n" .
    97 		"void common_dispatch();\n" .
    98 		"\n";
    99 }
   100 
   101 sub printHeaderEntry(\$\$\$) {
   102 	my ($fh, $ordinal, $comment) = @_;
   103 
   104 	print $fh "__declspec(dllexport)\n" .
   105 		"__declspec(naked)\n" .
   106 		"void call_vector_${ordinal} ()\n" .
   107 		"\t{\n" .
   108 		"\t// ${comment}\n" .
   109 		"\t_asm mov eax, $ordinal\n" .
   110 		"\t_asm jmp common_dispatch\n" .
   111 		"\t}\n\n";
   112 }
   113 
   114 sub printHeaderEnd(\$\$) {
   115 	my ($fh, $maxOrdinal) = @_;
   116 	print $fh "}\n" .
   117 		"#define MAX_ORDINAL $maxOrdinal\n\n";
   118 }