3 # PowerPC assembler distiller by <appro>.
7 open STDOUT,">$output" || die "can't open $output: $!";
10 my $dotinlocallabels=($flavour=~/linux/)?1:0;
12 ################################################################
13 # directives which need special treatment on different platforms
14 ################################################################
18 my $global = \$GLOBALS{$name};
23 SWITCH: for ($flavour) {
24 /aix/ && do { $name = ".$name";
27 /osx/ && do { $name = "_$name";
30 /linux.*32/ && do { $ret .= ".globl $name\n";
31 $ret .= ".type $name,\@function";
34 /linux.*64/ && do { $ret .= ".globl .$name\n";
35 $ret .= ".type .$name,\@function\n";
36 $ret .= ".section \".opd\",\"aw\"\n";
37 $ret .= ".globl $name\n";
40 $ret .= ".quad .$name,.TOC.\@tocbase,0\n";
41 $ret .= ".size $name,24\n";
42 $ret .= ".previous\n";
49 $ret = ".globl $name" if (!$ret);
54 ($flavour =~ /aix/) ? ".csect" : ".text";
59 if ($flavour =~ /osx/)
61 $arch = ($flavour=~/64/) ? "ppc970-64" : "ppc970" if ($arch eq "any");
67 my $line = join(",",@_);
68 if ($line =~ /^"(.*)"$/)
69 { ".byte " . join(",",unpack("C*",$1),0) . "\n.align 2"; }
74 ################################################################
75 # simplified mnemonics not handled by at least one assembler
76 ################################################################
79 my $cr = 0; $cr = shift if ($#_>1);
80 # Some out-of-date 32-bit GNU assembler just can't handle cmplw...
81 ($flavour =~ /linux.*32/) ?
82 " .long ".sprintf "0x%x",31<<26|$cr<<23|$_[0]<<16|$_[1]<<11|64 :
83 " cmplw ".join(',',$cr,@_);
87 my $bo = $f=~/[\+\-]/ ? 16+9 : 16; # optional "to be taken" hint
89 } if ($flavour!~/linux/);
92 my $bo = $f=~/\-/ ? 12+2 : 12; # optional "not to be taken" hint
93 ($flavour =~ /linux/) ? # GNU as doesn't allow most recent hints
94 " .long ".sprintf "0x%x",19<<26|$bo<<21|16<<1 :
99 my $bo = $f=~/\-/ ? 4+2 : 4; # optional "not to be taken" hint
100 ($flavour =~ /linux/) ? # GNU as doesn't allow most recent hints
101 " .long ".sprintf "0x%x",19<<26|$bo<<21|2<<16|16<<1 :
106 my $bo = $f=~/-/ ? 12+2 : 12; # optional "not to be taken" hint
107 ($flavour =~ /linux/) ? # GNU as doesn't allow most recent hints
108 " .long ".sprintf "0x%X",19<<26|$bo<<21|2<<16|16<<1 :
111 # GNU assembler can't handle extrdi rA,rS,16,48, or when sum of last two
112 # arguments is 64, with "operand out of range" error.
114 my ($f,$ra,$rs,$n,$b) = @_;
115 $b = ($b+$n)&63; $n = 64-$n;
116 " rldicl $ra,$rs,$b,$n";
121 $line =~ s|[#!;].*$||; # get rid of asm-style comments...
122 $line =~ s|/\*.*\*/||; # ... and C-style comments...
123 $line =~ s|^\s+||; # ... and skip white spaces in beginning...
124 $line =~ s|\s+$||; # ... and at the end
127 $line =~ s|\b\.L(\w+)|L$1|g; # common denominator for Locallabel
128 $line =~ s|\bL(\w+)|\.L$1|g if ($dotinlocallabels);
132 $line =~ s|(^[\.\w]+)\:\s*||;
134 printf "%s:",($GLOBALS{$label} or $label) if ($label);
138 $line =~ s|^\s*(\.?)(\w+)([\.\+\-]?)\s*||;
139 my $c = $1; $c = "\t" if ($c eq "");
142 my $opcode = eval("\$$mnemonic");
143 $line =~ s|\bc?[rf]([0-9]+)\b|$1|g if ($c ne "." and $flavour !~ /osx/);
144 if (ref($opcode) eq 'CODE') { $line = &$opcode($f,split(',',$line)); }
145 elsif ($mnemonic) { $line = $c.$mnemonic.$f."\t".$line; }
148 print $line if ($line);