home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / scripts / purify.awk < prev    next >
Encoding:
AWK Script  |  1996-09-12  |  1.6 KB  |  91 lines

  1. BEGIN {
  2. #    for (t=0; t<ARGC; t++)
  3. #     print t ": " ARGV[t];
  4.  
  5.     infile=ARGV[1];
  6.     outfile=ARGV[3];
  7.     emit_strings=0;
  8.  
  9. #    printf ("Reading %s\n", infile);
  10.  
  11.     while ((getline < infile) > 0)
  12.     {
  13.     if ($1==".file")
  14.     {
  15.         file=$2
  16.         emit_strings=1;
  17.     }
  18.     else if ($1==".stabn")
  19.     {
  20.         split($2,a,",");
  21.         line=a[3];
  22.     }
  23.     else if ($1=="call" && !match($2,/^\*\%/))
  24.     {
  25.         strings[$2]=1;
  26.         emit_strings=1;
  27.     }
  28.     else if (match($0,/^.LC/))
  29.     {
  30.         t=int(substr($0,4));
  31.         if (t>lc)
  32.         lc=t;
  33.     }
  34.     }
  35.  
  36.     gsub(/"/,"",file);
  37.     strings[file]=1;
  38.  
  39.     close (infile);
  40.     lc++;
  41.  
  42. #    printf ("Writing %s\n", outfile);
  43.  
  44.     printf ("") > outfile;
  45.     line=-1;
  46.  
  47.     while ((getline < infile) > 0)
  48.     {
  49.     if ($1==".text")
  50.     {
  51.         if (emit_strings)
  52.         {
  53.         print ".section\t.rodata" >> outfile
  54.         for (str in strings)
  55.         {
  56.             print ".LC" lc ":" >> outfile
  57.             print "\t.string \"" str "\"" >> outfile;
  58.             strings[str] = lc;
  59.             lc ++;
  60.         }
  61.         emit_strings=0;
  62.         }
  63.     }
  64.     else if ($1==".stabn")
  65.     {
  66.         split($2,a,",");
  67.         line=a[3];
  68.     }
  69.     else if ($1=="call" && !match($2,/^\*\%/))
  70.     {
  71.         if (line==-1)
  72.         print "\tpushl\t$" NF  >> outfile;
  73.         else
  74.         print "\tpushl\t$" line  >> outfile;
  75.         print "\tpushl\t$.LC" strings[file] >> outfile;
  76.         print "\tpushl\t$.LC" strings[$2] >> outfile;
  77.         print "\tcall\tRT_IntEnter" >> outfile;
  78.         print "\taddl\t$12,%esp" >> outfile;
  79.         strings[$2]=1;
  80.         #print "call to " $2 " at " file ":" line
  81.         print >> outfile
  82.         print "\tcall\tRT_Leave" >> outfile;
  83.         continue;
  84.     }
  85.     print >> outfile;
  86.  
  87.     if ($1=="main:")
  88.         print "\tcall\tRT_Init" >> outfile;
  89.     }
  90. }
  91.