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(',',@_); }
72 if ($flavour =~ /linux/) { ".size\t".join(',',@_); }
76 if ($flavour =~ /linux/) { ".inst\t".join(',',@_); }
77 else { ".long\t".join(',',@_); }
80 my $line = join(",",@_);
81 if ($line =~ /^"(.*)"$/)
82 { ".byte " . join(",",unpack("C*",$1),0) . "\n.align 2"; }
88 my ($r,$sfx,$start,$end) = @_;
90 join(",",map("$r$_$sfx",($start..$end)));
99 while ($line =~ m/\G[^@\/\{\"]*/g) {
100 if ($line =~ m/\G(@|\/\/|$)/gc) {
103 elsif ($line =~ m/\G\{/gc) {
104 my $saved_pos = pos($line);
105 $line =~ s/\G([rdqv])([0-9]+)([^\-]*)\-\1([0-9]+)\3/range($1,$3,$2,$4)/e;
106 pos($line) = $saved_pos;
107 $line =~ m/\G[^\}]*\}/g;
109 elsif ($line =~ m/\G\"/gc) {
110 $line =~ m/\G[^\"]*\"/g;
114 $line =~ s/\b(\w+)/$GLOBALS{$1} or $1/ge;
121 if ($line =~ m/^\s*(#|@|\/\/)/) { print $line; next; }
123 $line =~ s|/\*.*\*/||; # get rid of C-style comments...
124 $line =~ s|^\s+||; # ... and skip white spaces in beginning...
125 $line =~ s|\s+$||; # ... and at the end
128 $line =~ s|[\b\.]L(\w{2,})|L$1|g; # common denominator for Locallabel
129 $line =~ s|\bL(\w{2,})|\.L$1|g if ($dotinlocallabels);
133 $line =~ s|(^[\.\w]+)\:\s*||;
136 printf "%s:",($GLOBALS{$label} or $label);
140 if ($line !~ m/^[#@]/) {
141 $line =~ s|^\s*(\.?)(\S+)\s*||;
142 my $c = $1; $c = "\t" if ($c eq "");
145 if ($mnemonic =~ m/([^\.]+)\.([^\.]+)/) {
146 $opcode = eval("\$$1_$2");
148 $opcode = eval("\$$mnemonic");
151 my $arg=expand_line($line);
153 if (ref($opcode) eq 'CODE') {
154 $line = &$opcode($arg);
155 } elsif ($mnemonic) {
156 $line = $c.$mnemonic;
157 $line.= "\t$arg" if ($arg ne "");
161 print $line if ($line);