3 # ARM assembler distiller by <appro>.
7 open STDOUT,">$output" || die "can't open $output: $!";
9 $flavour = "linux32" if (!$flavour or $flavour eq "void");
12 my $dotinlocallabels=($flavour=~/linux/)?1:0;
14 ################################################################
15 # directives which need special treatment on different platforms
16 ################################################################
18 if ($flavour =~ /linux/) { ".arch\t".join(',',@_); }
22 if ($flavour =~ /linux/) { ".fpu\t".join(',',@_); }
26 if ($flavour =~ /ios/) { ".private_extern\t".join(',',@_); }
27 else { ".hidden\t".join(',',@_); }
30 my @args = split(/,\s*/,shift);
32 my $global = \$GLOBALS{$name};
35 if ($flavour =~ /ios32/) {
36 $ret = ".comm\t_$name,@args[1]\n";
37 $ret .= ".non_lazy_symbol_pointer\n";
39 $ret .= ".indirect_symbol\t_$name\n";
42 } else { $ret = ".comm\t".join(',',@args); }
49 my $global = \$GLOBALS{$name};
52 SWITCH: for ($flavour) {
53 /ios/ && do { $name = "_$name";
58 $ret = ".globl $name" if (!$ret);
65 return; # return nothing
68 if ($flavour =~ /linux/) { ".type\t".join(',',@_); }
69 elsif ($flavour =~ /ios32/) { if (join(',',@_) =~ /(\w+),%function/) {
70 "#ifdef __thumb2__\n".
78 if ($flavour =~ /linux/) { ".size\t".join(',',@_); }
82 if ($flavour =~ /linux/) { ".inst\t".join(',',@_); }
83 else { ".long\t".join(',',@_); }
86 my $line = join(",",@_);
87 if ($line =~ /^"(.*)"$/)
88 { ".byte " . join(",",unpack("C*",$1),0) . "\n.align 2"; }
94 my ($r,$sfx,$start,$end) = @_;
96 join(",",map("$r$_$sfx",($start..$end)));
105 while ($line =~ m/\G[^@\/\{\"]*/g) {
106 if ($line =~ m/\G(@|\/\/|$)/gc) {
109 elsif ($line =~ m/\G\{/gc) {
110 my $saved_pos = pos($line);
111 $line =~ s/\G([rdqv])([0-9]+)([^\-]*)\-\1([0-9]+)\3/range($1,$3,$2,$4)/e;
112 pos($line) = $saved_pos;
113 $line =~ m/\G[^\}]*\}/g;
115 elsif ($line =~ m/\G\"/gc) {
116 $line =~ m/\G[^\"]*\"/g;
120 $line =~ s/\b(\w+)/$GLOBALS{$1} or $1/ge;
127 if ($line =~ m/^\s*(#|@|\/\/)/) { print $line; next; }
129 $line =~ s|/\*.*\*/||; # get rid of C-style comments...
130 $line =~ s|^\s+||; # ... and skip white spaces in beginning...
131 $line =~ s|\s+$||; # ... and at the end
134 $line =~ s|[\b\.]L(\w{2,})|L$1|g; # common denominator for Locallabel
135 $line =~ s|\bL(\w{2,})|\.L$1|g if ($dotinlocallabels);
139 $line =~ s|(^[\.\w]+)\:\s*||;
142 printf "%s:",($GLOBALS{$label} or $label);
146 if ($line !~ m/^[#@]/) {
147 $line =~ s|^\s*(\.?)(\S+)\s*||;
148 my $c = $1; $c = "\t" if ($c eq "");
151 if ($mnemonic =~ m/([^\.]+)\.([^\.]+)/) {
152 $opcode = eval("\$$1_$2");
154 $opcode = eval("\$$mnemonic");
157 my $arg=expand_line($line);
159 if (ref($opcode) eq 'CODE') {
160 $line = &$opcode($arg);
161 } elsif ($mnemonic) {
162 $line = $c.$mnemonic;
163 $line.= "\t$arg" if ($arg ne "");
167 print $line if ($line);