Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
4.8 KiB

  1. # profevts.pl
  2. # Thierry Fevrier 25-Feb-2000
  3. #
  4. # Perl script to generate IA64 profiling events.
  5. #
  6. # Caveats:
  7. # sorry but it is my first perl script...
  8. # and it was done very quickly to satisfy the needs
  9. # of a simple program.
  10. #
  11. require 5.001;
  12. # Forward declarations
  13. sub Usage;
  14. sub PrintProlog;
  15. sub PrintBody;
  16. sub HalpProfileMappingToSource;
  17. sub PrintEpilog;
  18. # Contants
  19. my $SCRIPT_VERSION = "1.00";
  20. my $SCRIPT_CMD = "profevts.pl";
  21. my $SCRIPT_LONGVERSION = "PROFEVTS.PL Version $SCRIPT_VERSION";
  22. my $typedstr = "HalpProfileMapping";
  23. if ($#ARGV != 0)
  24. {
  25. $error = "requires 1 arguments...";
  26. Usage($error);
  27. }
  28. my $filename = $ARGV[0];
  29. if (-e $filename && -T $filename)
  30. {
  31. open(FH, "<$filename") || die "$SCRIPT_CMD: could not open $filename...\n";
  32. }
  33. else
  34. {
  35. $error = "$filename does not exist or is not a text file...";
  36. Usage($error);
  37. }
  38. while ( <FH> )
  39. {
  40. # look for the specified string
  41. if ( ($_ =~ /$typedstr/) && ($_ =~ /\[.*\]/) && ($_ =~ /\{/) ) {
  42. chop $_;
  43. PrintProlog( $typedstr );
  44. if ( PrintBody( ) )
  45. {
  46. PrintEpilog( $typedstr );
  47. last;
  48. }
  49. else
  50. {
  51. print "Parsing failed...\n";
  52. }
  53. }
  54. }
  55. close(FH);
  56. exit 0;
  57. sub PrintBody
  58. {
  59. # Note: in_comment is really for the section defining the structure.
  60. # I do not handle the case if the structure is inside a comment block.
  61. my $in_comment = 0;
  62. my $index = 0;
  63. LINE:
  64. while (<FH>)
  65. {
  66. local($line) = $_;
  67. #print $line;
  68. if ( $line =~ /^\s*#.*$/ ) {
  69. chop $line;
  70. #print "Found pre-processor macro \"$line\" in $typedstr...\n";
  71. print "$line\n";
  72. next LINE;
  73. }
  74. local($line) = $_;
  75. if ( $in_comment ) {
  76. # Does this line have the end of the C comment?
  77. #
  78. if ($line =~ /\*\//)
  79. {
  80. # Yes. Keep everything after the end of the
  81. # comment and keep going with normal processing
  82. $line = $';
  83. $in_comment = 0;
  84. }
  85. else
  86. {
  87. next LINE;
  88. }
  89. }
  90. # Remove single line C "/* */" comments
  91. $line =~ s/\/\*.*?\*\///g;
  92. # Remove any "//" comments
  93. # Make sure the start of the comment is NOT
  94. # inside a string
  95. if (($line =~ /\/\//) && ($line !~ /\".*?\/\/.*?\"/))
  96. {
  97. $line =~ s/\/\/.*$/ /;
  98. }
  99. # Multi-line C comment?
  100. # Make sure the start of the comment is NOT
  101. # inside a string
  102. if (($line =~ /\/\*/) && ($line !~ /\".*?\/\*.*?\"/))
  103. {
  104. # Grab anything before the comment
  105. # Need to make it look like there's still a EOL marker
  106. $line = $` . "\n";
  107. # Remember that we're in "comment" mode
  108. $in_comment = 1;
  109. next LINE;
  110. }
  111. local($line_pack) = $line;
  112. # Replace spaces between word characters with '#'
  113. $line_pack =~ s/(\w)\s+(\w)/$1#$2/g;
  114. # remove whitespace
  115. $line_pack =~ tr/ \t//d;
  116. # Remove quoted double-quote characters
  117. $line_pack =~ s/'\\?"'/'_'/g;
  118. # Remove any strings
  119. # Note: Doesn't handle quoted quote characters correctly
  120. $line_pack =~ s/"[^"]*"/_/g;
  121. # Remove any "//" comments
  122. $line_pack =~ s/\/\/.*$//;
  123. # For empty lines,
  124. if ( $line_pack eq "\n" )
  125. {
  126. next LINE;
  127. }
  128. if ( $line_pack =~ /^\}/)
  129. {
  130. return $index;
  131. }
  132. # Remove beginning "{"
  133. $line_pack =~ s/^\{(.*)\}.*$/$1/;
  134. # print "line_pack: $line_pack\n";
  135. @words = split(/,/, $line_pack);
  136. HalpProfileMappingToSource( $index, @words );
  137. $index++;
  138. next LINE;
  139. }
  140. return 0;
  141. }
  142. sub HalpProfileMappingToSource
  143. {
  144. local($idx, $supported, $event, $profileSource, $profileSourceMask, $interval, $defInterval, $maxInterval, $minInterval) = @_;
  145. if ( $idx eq 0 )
  146. {
  147. print " \{ \"ProfileTime\", ProfileTime, \"ProfileTime\", $defInterval, $defInterval \}";
  148. }
  149. elsif ( $supported eq "FALSE" ) {
  150. print ",\n \{ \"INVALID_$idx\", ProfileIA64Maximum, \"INVALID_$idx\", 0, 0 \}";
  151. }
  152. else {
  153. print ",\n \{ \"$event\", Profile$event, \"$event\", $defInterval, 0 \}";
  154. }
  155. }
  156. sub PrintProlog
  157. {
  158. local($str) = @_;
  159. local($basename) = $filename;
  160. local($header) = $filename;
  161. local($arrayname);
  162. $basename =~ s/.*\\(.*).[ch]/$1/;
  163. $arrayname = $basename . "StaticSources";
  164. if ($header !~ /\.h/)
  165. {
  166. $header =~ s/\.c$/\.h/;
  167. }
  168. print "\/\/\n";
  169. print "\/\/ This file is automatically generated by $SCRIPT_CMD, parsing\n";
  170. print "\/\/ $filename.\n";
  171. print "\/\/\n\n";
  172. print "\#include \"$header\"\n\n";
  173. print "SOURCE\n";
  174. print "$arrayname\[\] = \{\n";
  175. }
  176. sub PrintEpilog
  177. {
  178. local($str) = @_;
  179. print "\n};\n";
  180. }
  181. sub Usage
  182. {
  183. local($error) = @_;
  184. die "$error\n",
  185. "$SCRIPT_LONGVERSION\n",
  186. "Usage : $SCRIPT_CMD filename\n",
  187. "Options:\n",
  188. " filename file containing the IA64 $typedstr definition\n";
  189. }