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