mycpp.pl

Go to the documentation of this file.
00001 #!/usr/bin/perl
00002 use File::Temp;
00003 while(<>)
00004 {
00005 if(/(.*)tgt_compile\s*\(\s*(".*")\s*\)(.*)/)
00006 {
00007 $head=$1;
00008 $self=$2;
00009 $tail=$3;
00010 $tmpname=File::Temp::tempnam( "/tmp", "mycpp_");
00011 
00012 print qq(${head}\{\n);
00013         open F,">$tmpname.S";
00014         print F ".set noreorder;\n.set noat;\n";
00015         while($self=m/"([^"]*)"/g)
00016         {
00017         ($a=$1)=~s/deret/.word 0x4200001f;\n/g;
00018         $a=~s/\\n/\n/g;
00019         print F "$a";
00020         }
00021         close F;
00022         if(index(`uname -m`,"mips")>=0)
00023         {
00024         system("gcc -include include/regdef.h -c -o $tmpname.o $tmpname.S && objcopy  -j .text -O binary $tmpname.o $tmpname.bin");
00025         }
00026         else
00027         {
00028         system("mipsel-linux-gcc -include include/regdef.h -c -o $tmpname.o $tmpname.S && mipsel-linux-objcopy  -j .text -O binary $tmpname.o $tmpname.bin");
00029         }
00030         if($?)
00031         {
00032         print qq(#error mycpp\n);
00033         }
00034         else
00035         {
00036                 unlink qq($tmpname.o);
00037                 unlink qq($tmpname.S);
00038         open FS,"$tmpname.bin";
00039         my ($x,$i,$d);
00040         $i=0;
00041         while(!eof(FS))
00042         {
00043         printf  ("/*%08x:*/",$i*4) if($i%4==0);
00044         read FS,$d,4;
00045         $x=unpack "I",$d;
00046         printf  ("0x%08x",$x);
00047         $i++;
00048         if(!eof(FS))
00049         {
00050         printf  (","); 
00051         }
00052         }
00053         close(FS);
00054                 unlink qq($tmpname.bin);
00055         }
00056 
00057 print qq(\n\}$tail\n);
00058 
00059 }
00060 else { print; }
00061 }

Generated on Fri Nov 5 07:24:46 2010 for ejtag debug tools for loongson 232 cpu by  doxygen 1.5.6