sbsv1/abld/e32util/armasm2as.pl
author Ross Qin <ross.qin@nokia.com>
Thu, 18 Nov 2010 16:02:32 +0800
changeset 697 818fe0ed324b
parent 626 ac03b93ca9c4
permissions -rw-r--r--
Moving feature configuration out of the buildrom scope.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     2
# All rights reserved.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     3
# This component and the accompanying materials are made available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     4
# under the terms of "Eclipse Public License v1.0"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     5
# which accompanies this distribution, and is available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     7
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     8
# Initial Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    10
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    11
# Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    12
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    13
# Description:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    14
# e32toolp\e32util\armasm2as.pl
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    15
# Convert an ARMASM assembler source or include file to AS format
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    16
# Syntax:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    17
# perl armasm2as.pl <input> <output>
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    18
# 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
if (scalar(@ARGV)!=2) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
	die "perl armasm2as.pl <input> <output>\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
my ($infile, $outfile) = @ARGV;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
open IN, $infile or die "Can't open $infile for input\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
my $gccfile;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
my @input;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
while (<IN>) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
	push @input, $_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
	next if defined($gccfile);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
	next if (/^\s*$/);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
	if (/^\s*\@/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
		$gccfile = 1;	# If first non-blank line starts with @, assume already in GCC format
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
	} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    35
		$gccfile = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    36
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    37
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
close IN;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
my @output;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
my $outref = \@output;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
if ($gccfile) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    42
	$outref = \@input;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    44
	process(\@input, \@output);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    45
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    46
open OUT, ">$outfile" or die "Can't open $outfile for write\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    47
print OUT @$outref;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    48
close OUT;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    49
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    50
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
sub process($$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
	my $level=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
	my @block;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
	my ($inref, $outref) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
	foreach $line (@$inref) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
		$line=~s/\s*$//;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
		my $comment;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    59
		if ($line =~ /\;(.*)$/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    60
			$comment = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    61
			$line =~ s/\;(.*)$//o;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    62
			if ($line =~ /^\s*$/o and $level==0) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    63
				push @$outref, "$line\@$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    64
				next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    65
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    66
			$comment = "\t\@$comment";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    67
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    68
		if ($line =~ /^\s+PRESERVE8/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    69
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    70
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    71
		if ($level == 1) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    72
			if ($line =~ /^\s+MEND/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    73
				process_macro(\@block, $outref);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
				$level = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
			} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
				push @block, $line;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
		} elsif ($level == 0) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
			if ($line =~ /^\s+MACRO\s*$/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
				@block = ();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
				$level = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
				next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
		if ($line =~ /^\s+GBLL\s+(\S+)/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    87
			push @$outref, "\t.set\t$1, 0$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    88
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    89
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
		if ($line =~ /^\s+GBLA\s+(\S+)/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
			push @$outref, "\t.set\t$1, 0$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
		if ($line =~ /^\s+INCLUDE\s+(\S+)/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
			my $arg = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
			if ($arg =~ /(\w+)\.inc/io) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
				$arg = $1.'.ginc';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    98
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    99
			push @$outref, "\t.include\t\"$arg\"$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   100
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
		if ($line =~ /^\s+IMPORT\s+(\S+)/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
			push @$outref, "\t.extern\t$1$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   105
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   106
		if ($line =~ /^\s+EXPORT\s+(\S+)/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   107
			push @$outref, "\t.global\t$1$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   108
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   109
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   110
		if ($line =~ /^\s+ELSE/i or $line =~ /^\s+\|/i ) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   111
			push @$outref, "\t.else$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   112
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   113
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   114
		if ($line =~ /^\s+ENDIF/i or $line =~ /^\s+\]/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   115
			push @$outref, "\t.endif$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   116
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   117
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   118
		if ($line =~ /^\s+LTORG/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   119
			push @$outref, "\t.ltorg$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   120
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   121
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   122
		if ($line =~ /^\s+END$/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   123
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   124
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   125
		if ($line =~ /^\s+\!\s*(\d+)\,\s*(.*?)$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   126
			my $msg = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   127
			push @$outref, "\t.print $msg\n\t.err$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   128
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   129
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   130
		if ($line =~ /^\s+INIT_LOGICAL_SYMBOL\s+(\w+)(.*?)$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   131
			process_init_logical_symbol($1, $2, $outref, $comment);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   132
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   133
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   134
		if ($line =~ /^\s+INIT_NUMERIC_SYMBOL\s+(\w+)\s*\,\s*(.*?)$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   135
			process_init_numeric_symbol($1, $2, $outref, $comment);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   136
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   137
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   138
		if ($line =~ /^\s+AREA\s+(.*?)$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   139
			process_area($1, $outref, $comment);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   140
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   141
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   142
		if ($line =~ /^\s+\%\s+(.*?)$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   143
			my $expr = process_numeric_expr($1, $outref);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   144
			push @$outref, "\t.space $expr$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   145
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   146
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   147
		if ($line =~ /^\s+ALIGN\s*(.*?)$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   148
			process_align($1, $outref, $comment);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   149
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   150
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   151
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   152
		# Strip label if there is one
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   153
		my $label;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   154
		if ($line =~ /^(\S+)\s*(.*?)$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   155
			$label = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   156
			$line = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   157
		} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   158
			$line =~ s/^\s*//;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   159
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   160
		if ($line =~ /^SETL\s+(\S+)/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   161
			my $val = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   162
			my $expr = process_logical_expr($val, $outref);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   163
			push @$outref, "\t.set\t$label,$expr$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   164
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   165
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   166
		if ($line =~ /^SETA\s+(.*?)$/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   167
			my $val = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   168
			my $expr = process_numeric_expr($val, $outref);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   169
			push @$outref, "\t.set\t$label,$expr$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   170
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   171
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   172
		if ($line =~ /^(EQU|\*)\s+(.*?)$/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   173
			my $val = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   174
			my $expr = process_numeric_expr($val, $outref);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   175
			push @$outref, "\t.equ\t$label,$expr$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   176
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   177
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   178
		if ($line =~ /^(if|\[)\s+(.*?)$/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   179
			my $cond = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   180
			if ($cond =~ /^\s*(\:LNOT\:)?\s*\:DEF\:\s*(.*?)$/i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   181
				my $n = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   182
				my $sym = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   183
				if ($sym =~ /^(\w|\\|\:)+$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   184
					if (uc($n) eq ':LNOT:') {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   185
						push @$outref, "\t.ifndef\t$sym$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   186
					} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   187
						push @$outref, "\t.ifdef\t$sym$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   188
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   189
					next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   190
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   191
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   192
			my $expr = process_logical_expr($cond, $outref);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   193
			push @$outref, "\t.if $expr$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   194
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   195
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   196
		if ($line =~ /^(\=|DCB)\s*(.*?)$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   197
			process_dcb($label, $2, $outref, $comment);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   198
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   199
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   200
		if ($line =~ /^DCW\s*(.*?)$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   201
			process_dcw($label, $1, $outref, $comment);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   202
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   203
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   204
		if ($line =~ /^DCD\s*(.*?)$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   205
			process_dcd($label, $1, $outref, $comment);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   206
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   207
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   208
		if ($line =~ /^ROUT\s*$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   209
			$line = '';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   210
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   211
		if ($line =~ /^(\w+)\s+\%(\w+)\s*$/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   212
			# ARMASM local label reference
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   213
			my $inst = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   214
			my $llab = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   215
			if ($llab =~ /F\w?(\d+)/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   216
				$line = "$inst $1f";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   217
			} elsif ($llab =~ /B\w?(\d+)/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   218
				$line = "$inst $1b";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   219
			} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   220
				die "Can't determine local label direction\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   221
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   222
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   223
		if ($line =~ /^(\w+)\s+(\w+)\s*\,\s*\%(\w+)\s*$/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   224
			# ARMASM local label reference
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   225
			my $inst = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   226
			my $op1 = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   227
			my $llab = $3;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   228
			if ($llab =~ /F\w?(\d+)/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   229
				$line = "$inst $op1\, $1f";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   230
			} elsif ($llab =~ /B\w?(\d+)/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   231
				$line = "$inst $op1\, $1b";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   232
			} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   233
				die "Can't determine local label direction\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   234
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   235
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   236
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   237
		$line = process_numeric_expr($line, $outref);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   238
		if (defined($label)) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   239
			push @$outref, "$label\:\t$line$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   240
		} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   241
			push @$outref, "\t$line$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   242
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   243
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   244
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   245
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   246
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   247
sub process_macro($$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   248
	my ($inref, $outref) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   249
	my $line;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   250
	while(1) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   251
		$line = shift @$inref;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   252
		last if ($line !~ /^\s*$/);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   253
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   254
	unless ($line =~ /^\s+(\w+)\s*(.*?)$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   255
		die "Bad macro - no name\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   256
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   257
	my $macro_name = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   258
	if ($macro_name eq 'INIT_LOGICAL_SYMBOL' or $macro_name eq 'INIT_NUMERIC_SYMBOL') {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   259
		return;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   260
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   261
	$line = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   262
	my @args = split ( '\s*,\s*', $line );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   263
	foreach (@args) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   264
		die "Bad macro argument name\n" unless (/^\$\w+$/);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   265
		s/^\$//;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   266
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   267
	my $ev = '';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   268
	foreach $arg (@args) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   269
		$ev.="s/\\\$$arg(\\W\|\$)/\\\\$arg\$1/go;";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   270
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   271
	foreach (@$inref) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   272
		eval $ev;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   273
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   274
	push @$outref, "\t.macro $macro_name ".join(',',@args)."\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   275
	process($inref, $outref);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   276
	push @$outref, "\t.endm\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   277
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   278
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   279
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   280
sub process_logical_expr($$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   281
	my ($val, $outref) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   282
	$val = process_numeric_expr($val, $outref);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   283
	$val =~ s/\<\=/________LE________/g;	# protect <= and >= during expansion of =
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   284
	$val =~ s/\>\=/________GE________/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   285
	$val =~ s/\=/\=\=/g;					# equality operator is = on ARMASM, == on AS
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   286
	$val =~ s/________LE________/\<\=/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   287
	$val =~ s/________GE________/\>\=/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   288
	$val =~ s/\{TRUE\}/(1)/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   289
	$val =~ s/\{FALSE\}/(0)/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   290
626
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   291
	my @lops = split( /(\s*\:LAND\:\s*|\s*\:LOR\:\s*|\s*\:LNOT\:\s*|\s*\:DEF\:\s*|\s*\(\s*|\s*\)\s*)/, $val );
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   292
	foreach (@lops) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   293
		s/\s*\:LAND\:\s*/\:LAND\:/go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   294
		s/\s*\:LOR\:\s*/\:LOR\:/go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   295
		s/\s*\:LNOT\:\s*/\:LNOT\:/go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   296
		s/\s*\:DEF\:\s*/\:DEF\:/go;
626
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   297
		s/\s*\(\s*/\(/go;
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   298
		s/\s*\)\s*/\)/go;
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   299
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   300
	my @lops2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   301
	while (scalar (@lops)) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   302
		my $x = shift @lops;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   303
		if ($x eq ':DEF:') {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   304
			my $sym = shift @lops;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   305
			$sym =~ s/^\s*//;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   306
			$sym =~ s/\s*$//;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   307
			if ($sym =~ /^(\w|\$|\\)+$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   308
				push @$outref, "\t.ifdef $sym\n\t.set __defined__$sym, 1\n\t.else\n\t.set __defined__$sym, 0\n\t.endif\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   309
				push @lops2, " __defined__$sym ";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   310
			} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   311
				die "Bad :DEF: operand\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   312
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   313
		} elsif ($x eq ':LAND:') {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   314
			push @lops2, ' && ';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   315
		} elsif ($x eq ':LOR:') {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   316
			push @lops2, ' || ';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   317
		} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   318
			push @lops2, $x;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   319
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   320
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   321
	my @lops3;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   322
	while (scalar (@lops2)) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   323
		my $x = shift @lops2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   324
		if ($x eq ':LNOT:') {
626
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   325
			my $operand= shift @lops2;
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   326
			while( @lops2 && $operand =~ /^\s*$/) {
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   327
				$operand = shift @lops2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   328
			}
626
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   329
			if($operand eq '(') {
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   330
				my $balance = 1;
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   331
				my $compound = $operand;
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   332
				while($balance > 0 && @lops2) {
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   333
					$operand = shift @lops2;
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   334
					if($operand eq '(') {
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   335
						++$balance;
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   336
					}
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   337
					elsif ($operand eq ')') {
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   338
						--$balance;
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   339
					}
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   340
					$compound .= $operand;
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   341
				}
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   342
				push @lops3, "(0==$compound)";
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   343
			}
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   344
			else {
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   345
				push @lops3, "(0==($operand))";
ac03b93ca9c4 ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents: 599
diff changeset
   346
			}
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   347
		} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   348
			push @lops3, $x;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   349
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   350
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   351
	return join('',@lops3);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   352
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   353
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   354
sub process_numeric_expr($$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   355
	my ($val, $outref) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   356
	$val =~ s/\&/0x/g;			# ARMASM accepts hex numbers starting with & or 0x, AS only accepts 0x
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   357
	$val =~ s/(\W|^)2_([0|1]+)(\W|$)/$1 0b$2$3/g;	# Binary numbers start with 2_ on ARMASM, 0b on AS
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   358
	$val =~ s/\:AND\:/\&/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   359
	$val =~ s/\:OR\:/\|/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   360
	$val =~ s/\:SHL\:/\<\</g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   361
	$val =~ s/\:SHR\:/\>\>/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   362
	return $val;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   363
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   364
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   365
sub process_init_logical_symbol($$$$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   366
	my ($name, $rest, $outref, $comment) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   367
	my $counter;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   368
	if ($rest =~ /^\s*\,\s*(\w+)\s*$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   369
		$counter = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   370
	} elsif ($rest !~ /^\s*$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   371
		die "Bad INIT_LOGICAL_SYMBOL\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   372
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   373
	push @$outref, "\t.ifndef $name$comment\n\t.set $name, 0\n\t.else\n\t.set $name, 1\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   374
	if ($counter) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   375
		push @$outref, "\t.set $counter, $counter \+ 1\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   376
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   377
	push @$outref, "\t.endif\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   378
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   379
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   380
sub process_init_numeric_symbol($$$$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   381
	my ($name, $value, $outref, $comment) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   382
	my $expr = process_numeric_expr($value, $outref);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   383
	push @$outref, "\t.ifndef $name$comment\n\t.set $name, $expr\n\t.endif\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   384
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   385
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   386
sub process_area($$$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   387
	my ($line, $outref, $comment) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   388
	my @args = split(',',$line);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   389
	my $align = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   390
	foreach (@args) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   391
		if (/^\s*ALIGN\s*\=\s*(\d+)\s*$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   392
			$align = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   393
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   394
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   395
	push @$outref, "\t.text$comment\n\t.p2align $align\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   396
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   397
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   398
sub process_align($$$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   399
	my ($line, $outref, $comment) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   400
	if ($line =~ /^\s*$/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   401
		push @$outref, "\t.align$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   402
	} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   403
		push @$outref, "\t.balign $line$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   404
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   405
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   406
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   407
sub process_dcb($$$$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   408
	my ($label, $args, $outref, $comment) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   409
	if (defined($label)) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   410
		push @$outref, "$label\:";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   411
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   412
	while ($args !~ /^\s*$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   413
		my $arg;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   414
		$args =~ s/^\s*//;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   415
		if ($args =~ /^\"/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   416
			$args =~ s/\\\"/________ESCAPED_QUOTE________/go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   417
			$args =~ /\"(.*?)\"\s*(.*?)$/o or die "Unterminated string literal\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   418
			$arg = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   419
			$args = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   420
			$arg =~ s/________ESCAPED_QUOTE________/\\\"/go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   421
			push @$outref, "\t.ascii \"$arg\"$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   422
			undef $comment;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   423
			last if ($args !~ /\s*\,(.*?)$/o);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   424
			$args = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   425
		} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   426
			$args =~ /(.*?)\s*(\,|$)(.*?)$/o;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   427
			$arg = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   428
			$args = $3;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   429
			my $expr = process_numeric_expr($arg, $outref);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   430
			push @$outref, "\t.byte $expr$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   431
			undef $comment;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   432
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   433
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   434
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   435
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   436
sub process_dcw($$$$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   437
	my ($label, $args, $outref, $comment) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   438
	if (defined($label)) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   439
		push @$outref, "$label\:";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   440
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   441
	while ($args !~ /^\s*$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   442
		my $arg;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   443
		$args =~ s/^\s*//;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   444
		$args =~ /(.*?)\s*(\,|$)(.*?)$/o;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   445
		$arg = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   446
		$args = $3;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   447
		my $expr = process_numeric_expr($arg, $outref);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   448
		push @$outref, "\t.hword $expr$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   449
		undef $comment;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   450
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   451
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   452
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   453
sub process_dcd($$$$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   454
	my ($label, $args, $outref, $comment) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   455
	if (defined($label)) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   456
		push @$outref, "$label\:";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   457
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   458
	while ($args !~ /^\s*$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   459
		my $arg;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   460
		$args =~ s/^\s*//;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   461
		$args =~ /(.*?)\s*(\,|$)(.*?)$/o;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   462
		$arg = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   463
		$args = $3;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   464
		my $expr = process_numeric_expr($arg, $outref);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   465
		push @$outref, "\t.word $expr$comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   466
		undef $comment;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   467
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   468
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   469
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   470
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   471