3 # Copyright (C) 2004-2007, Parrot Foundation.
9 as2c.pl - convert gas assembler listing to i386 code array
13 The plan behind of as2c.pl is to create compiler independent
14 machine code for an architecture. Code in e.g. masm, gas, nasm syntax
15 doesn't fit all compilers. Therefore as2c.pl translates gas syntax to a
16 bytestring, which is then used as the asm code.
18 as2c.pl is used very rarely. Once the code is generated and
19 checked in, there's usually no need to change it later.
27 my $cmd = "cc -c $src.c -Wall -O3 -fomit-frame-pointer -DNDEBUG -Wa,-a > $src.s";
40 * DO NOT EDIT THIS FILE
42 * Generated from $s.c via $s.s
53 * c-file-style: "parrot"
55 * vim: expandtab shiftwidth=4:
64 die "$cmd failed: $r";
70 open my $IN, "<", "$s" or die "Can't read '$s': $1";
76 next if (/#(?:NO_)?APP/); # APP, NO_APP
78 if (/^\s*\d+\s[\da-fA-F]{4}\s([\dA-F]{2,8})\s+(.*)/) {
82 my ( $bytes, $src ) = ( $1, $2 );
84 my $len = length($bytes);
85 my @pairs = ( $bytes =~ m/../g );
86 print " " . join '', map { "0x$_, " } @pairs;
87 print " " x
( 3 * ( 8 - $len ) );
88 print " /* $src */\n";
90 elsif (/\.type\s+(\w+)\s*,\s*\@function/) {
94 print "static const char ${func}_code[] = {\n";
96 elsif (/^\s*\d+\s+(\w+):/) {
97 print " " x
26, " /* $1: */\n";
111 open $IN, "<", "$s" or die "Can't read '$s': $1";
113 if (/\/\
*INTERFACE
/) {
116 last if (/INTERFACE\*\//);
119 $text =~ s/\@FUNC\@/$func/g;
120 $text =~ s!\@\*!/*!g;
121 $text =~ s!\*\@!*/!g;
130 # cperl-indent-level: 4
133 # vim: expandtab shiftwidth=4: