2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
13 open STDOUT,">$output" || die "can't open $output: $!";
15 $flavour = "linux32" if (!$flavour or $flavour eq "void");
18 my $dotinlocallabels=($flavour=~/linux/)?1:0;
20 ################################################################
21 # directives which need special treatment on different platforms
22 ################################################################
24 if ($flavour =~ /linux/) { ".arch\t".join(',',@_); }
28 if ($flavour =~ /linux/) { ".fpu\t".join(',',@_); }
32 if ($flavour =~ /ios/) { ".private_extern\t".join(',',@_); }
33 else { ".hidden\t".join(',',@_); }
36 my @args = split(/,\s*/,shift);
38 my $global = \$GLOBALS{$name};
41 if ($flavour =~ /ios32/) {
42 $ret = ".comm\t_$name,@args[1]\n";
43 $ret .= ".non_lazy_symbol_pointer\n";
45 $ret .= ".indirect_symbol\t_$name\n";
48 } else { $ret = ".comm\t".join(',',@args); }
55 my $global = \$GLOBALS{$name};
58 SWITCH: for ($flavour) {
59 /ios/ && do { $name = "_$name";
64 $ret = ".globl $name" if (!$ret);
71 return; # return nothing
74 if ($flavour =~ /linux/) { ".type\t".join(',',@_); }
75 elsif ($flavour =~ /ios32/) { if (join(',',@_) =~ /(\w+),%function/) {
76 "#ifdef __thumb2__\n".
84 if ($flavour =~ /linux/) { ".size\t".join(',',@_); }
88 if ($flavour =~ /linux/) { ".inst\t".join(',',@_); }
89 else { ".long\t".join(',',@_); }
92 my $line = join(",",@_);
93 if ($line =~ /^"(.*)"$/)
94 { ".byte " . join(",",unpack("C*",$1),0) . "\n.align 2"; }
100 my ($r,$sfx,$start,$end) = @_;
102 join(",",map("$r$_$sfx",($start..$end)));
111 while ($line =~ m/\G[^@\/\{\"]*/g) {
112 if ($line =~ m/\G(@|\/\/|$)/gc) {
115 elsif ($line =~ m/\G\{/gc) {
116 my $saved_pos = pos($line);
117 $line =~ s/\G([rdqv])([0-9]+)([^\-]*)\-\1([0-9]+)\3/range($1,$3,$2,$4)/e;
118 pos($line) = $saved_pos;
119 $line =~ m/\G[^\}]*\}/g;
121 elsif ($line =~ m/\G\"/gc) {
122 $line =~ m/\G[^\"]*\"/g;
126 $line =~ s/\b(\w+)/$GLOBALS{$1} or $1/ge;
133 if ($line =~ m/^\s*(#|@|\/\/)/) { print $line; next; }
135 $line =~ s|/\*.*\*/||; # get rid of C-style comments...
136 $line =~ s|^\s+||; # ... and skip white spaces in beginning...
137 $line =~ s|\s+$||; # ... and at the end
140 $line =~ s|[\b\.]L(\w{2,})|L$1|g; # common denominator for Locallabel
141 $line =~ s|\bL(\w{2,})|\.L$1|g if ($dotinlocallabels);
145 $line =~ s|(^[\.\w]+)\:\s*||;
148 printf "%s:",($GLOBALS{$label} or $label);
152 if ($line !~ m/^[#@]/) {
153 $line =~ s|^\s*(\.?)(\S+)\s*||;
154 my $c = $1; $c = "\t" if ($c eq "");
157 if ($mnemonic =~ m/([^\.]+)\.([^\.]+)/) {
158 $opcode = eval("\$$1_$2");
160 $opcode = eval("\$$mnemonic");
163 my $arg=expand_line($line);
165 if (ref($opcode) eq 'CODE') {
166 $line = &$opcode($arg);
167 } elsif ($mnemonic) {
168 $line = $c.$mnemonic;
169 $line.= "\t$arg" if ($arg ne "");
173 print $line if ($line);