2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (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
11 open STDOUT,">$output" || die "can't open $output: $!";
13 $flavour = "linux32" if (!$flavour or $flavour eq "void");
16 my $dotinlocallabels=($flavour=~/linux/)?1:0;
18 ################################################################
19 # directives which need special treatment on different platforms
20 ################################################################
22 if ($flavour =~ /linux/) { ".arch\t".join(',',@_); }
26 if ($flavour =~ /linux/) { ".fpu\t".join(',',@_); }
30 if ($flavour =~ /ios/) { ".private_extern\t".join(',',@_); }
31 else { ".hidden\t".join(',',@_); }
34 my @args = split(/,\s*/,shift);
36 my $global = \$GLOBALS{$name};
39 if ($flavour =~ /ios32/) {
40 $ret = ".comm\t_$name,@args[1]\n";
41 $ret .= ".non_lazy_symbol_pointer\n";
43 $ret .= ".indirect_symbol\t_$name\n";
46 } else { $ret = ".comm\t".join(',',@args); }
53 my $global = \$GLOBALS{$name};
56 SWITCH: for ($flavour) {
57 /ios/ && do { $name = "_$name";
62 $ret = ".globl $name" if (!$ret);
69 return; # return nothing
72 if ($flavour =~ /linux/) { ".type\t".join(',',@_); }
73 elsif ($flavour =~ /ios32/) { if (join(',',@_) =~ /(\w+),%function/) {
74 "#ifdef __thumb2__\n".
82 if ($flavour =~ /linux/) { ".size\t".join(',',@_); }
86 if ($flavour =~ /linux/) { ".inst\t".join(',',@_); }
87 else { ".long\t".join(',',@_); }
90 my $line = join(",",@_);
91 if ($line =~ /^"(.*)"$/)
92 { ".byte " . join(",",unpack("C*",$1),0) . "\n.align 2"; }
98 my ($r,$sfx,$start,$end) = @_;
100 join(",",map("$r$_$sfx",($start..$end)));
109 while ($line =~ m/\G[^@\/\{\"]*/g) {
110 if ($line =~ m/\G(@|\/\/|$)/gc) {
113 elsif ($line =~ m/\G\{/gc) {
114 my $saved_pos = pos($line);
115 $line =~ s/\G([rdqv])([0-9]+)([^\-]*)\-\1([0-9]+)\3/range($1,$3,$2,$4)/e;
116 pos($line) = $saved_pos;
117 $line =~ m/\G[^\}]*\}/g;
119 elsif ($line =~ m/\G\"/gc) {
120 $line =~ m/\G[^\"]*\"/g;
124 $line =~ s/\b(\w+)/$GLOBALS{$1} or $1/ge;
131 if ($line =~ m/^\s*(#|@|\/\/)/) { print $line; next; }
133 $line =~ s|/\*.*\*/||; # get rid of C-style comments...
134 $line =~ s|^\s+||; # ... and skip white spaces in beginning...
135 $line =~ s|\s+$||; # ... and at the end
138 $line =~ s|[\b\.]L(\w{2,})|L$1|g; # common denominator for Locallabel
139 $line =~ s|\bL(\w{2,})|\.L$1|g if ($dotinlocallabels);
143 $line =~ s|(^[\.\w]+)\:\s*||;
146 printf "%s:",($GLOBALS{$label} or $label);
150 if ($line !~ m/^[#@]/) {
151 $line =~ s|^\s*(\.?)(\S+)\s*||;
152 my $c = $1; $c = "\t" if ($c eq "");
155 if ($mnemonic =~ m/([^\.]+)\.([^\.]+)/) {
156 $opcode = eval("\$$1_$2");
158 $opcode = eval("\$$mnemonic");
161 my $arg=expand_line($line);
163 if (ref($opcode) eq 'CODE') {
164 $line = &$opcode($arg);
165 } elsif ($mnemonic) {
166 $line = $c.$mnemonic;
167 $line.= "\t$arg" if ($arg ne "");
171 print $line if ($line);