toolsandutils/e32tools/tranasm/tranasm_x86.pl
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # Small Perl script for converting GCC inline X86 assembly instructions 
       
    15 # into a format acceptable to the MSVC compiler.
       
    16 # 
       
    17 #
       
    18 
       
    19 
       
    20 	# Read the input .cia file
       
    21 	open (INPUT_FILE,"$ARGV[0]") or
       
    22 		die "Couldn't open input file $!";
       
    23 	my @lines = <INPUT_FILE>;
       
    24 	close INPUT_FILE;
       
    25 
       
    26 	# Open the output file (somewhere under \epoc32\build)
       
    27 	open (OUTPUT_FILE,">$ARGV[1]") or
       
    28 		die "Couldn't open output file  $!";
       
    29 
       
    30 	# Iterate each line of the input .cia
       
    31 	foreach my $line (@lines) {
       
    32 
       
    33 		# Filter GCC inline assembly lines
       
    34 		$line=~s/\/\*(.*?)\*\///g;
       
    35 		my $output_line=$line;
       
    36 		if ($line=~m/^\s*asm\("(.*?)"(.*)\)(.*)/) {
       
    37 
       
    38 			# The above regexp seperates the asm declaration into the instruction part, and
       
    39 			# optionally a C expression as an operand
       
    40 			my $instr=$1;
       
    41 			my $c_arg=$2;
       
    42 			my $eol=$3;
       
    43 
       
    44 			# If a C operand is used, strip the weird GCC-specific syntax from it and paste
       
    45 			# it into the '%0' or '%a0' operand in the assembly instruction
       
    46 			if ($c_arg =~m/^\s*:\s*:\s*"i"\s*(.*)/) {
       
    47 				$c_arg = $1;
       
    48 				$output_line=$instr;
       
    49 
       
    50 				# Use of _FOFF has to be converted to MSVC syntax
       
    51 				if ($c_arg =~m/^_FOFF\((.*)\s*,\s*(.*)\)/) {
       
    52 					my $classname=$1;
       
    53 					my $member=$2;
       
    54 					$output_line=~s/\+%0]/]$classname.$member/;
       
    55 					$output_line=~s/\%0/$classname.$member/;
       
    56 				}
       
    57 				else {
       
    58 
       
    59 					$c_arg=~s/&//;			# strip the '&' used for address-of global code/data
       
    60 					$output_line=~s/%0/$c_arg/;
       
    61 					$output_line=~s/%a0/$c_arg/;
       
    62 				}
       
    63 			}
       
    64 			else {
       
    65 				$output_line="$instr$c_arg";
       
    66 			}
       
    67 
       
    68 			# Prefix the MSVC __asm keyword
       
    69 			$output_line = "__asm $output_line $eol\n";
       
    70 		}
       
    71 		print OUTPUT_FILE "$output_line";
       
    72 	}
       
    73 
       
    74 	close OUTPUT_FILE;
       
    75