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(',',@_); }
23 my $global = \$GLOBALS{$name};
26 SWITCH: for ($flavour) {
27 /ios/ && do { $name = "_$name";
32 $ret = ".globl $name" if (!$ret);
39 return; # return nothing
42 if ($flavour =~ /linux/) { ".type\t".join(',',@_); }
46 if ($flavour =~ /linux/) { ".size\t".join(',',@_); }
50 if ($flavour =~ /linux/) { ".inst\t".join(',',@_); }
51 else { ".long\t".join(',',@_); }
54 my $line = join(",",@_);
55 if ($line =~ /^"(.*)"$/)
56 { ".byte " . join(",",unpack("C*",$1),0) . "\n.align 2"; }
62 my ($r,$sfx,$start,$end) = @_;
64 join(",",map("$r$_$sfx",($start..$end)));
74 if ($line =~ m/\G\[/gc) {
75 $line =~ m/\G([^\]]+\][^,]*)\s*/g;
78 elsif ($line =~ m/\G\{/gc) {
79 $line =~ m/\G([^\}]+\}[^,]*)\s*/g;
81 $arg =~ s/([rdqv])([0-9]+)([^\-]*)\-\1([0-9]+)\3/range($1,$3,$2,$4)/ge;
84 elsif ($line =~ m/\G([^,]+)\s*/g) {
88 last if ($line =~ m/\G$/gc);
93 map {my $s=$_;$s=~s/\b(\w+)/$GLOBALS{$1} or $1/ge;$s} @ret;
98 $line =~ s|/\*.*\*/||; # get rid of C-style comments...
99 $line =~ s|^\s+||; # ... and skip white spaces in beginning...
100 $line =~ s|\s+$||; # ... and at the end
103 $line =~ s|[\b\.]L(\w+)|L$1|g; # common denominator for Locallabel
104 $line =~ s|\bL(\w+)|\.L$1|g if ($dotinlocallabels);
108 $line =~ s|(^[\.\w]+)\:\s*||;
111 printf "%s:",($GLOBALS{$label} or $label);
115 if ($line !~ m/^#/o) {
116 $line =~ s|^\s*(\.?)(\S+)\s*||o;
117 my $c = $1; $c = "\t" if ($c eq "");
120 if ($mnemonic =~ m/([^\.]+)\.([^\.]+)/o) {
121 $opcode = eval("\$$1_$2");
123 $opcode = eval("\$$mnemonic");
126 my @args=parse_args($line);
128 if (ref($opcode) eq 'CODE') {
129 $line = &$opcode(@args);
130 } elsif ($mnemonic) {
131 $line = $c.$mnemonic;
132 $line.= "\t".join(',',@args) if ($#args>=0);
136 print $line if ($line);