Leaked source code of windows server 2003
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.

238 lines
5.4 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 = "ProfileMapping";
  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 =~ /\/\* (Profile.*?)\*\//;
  92. local($kprofile) = $1;
  93. $kprofile =~ tr/ \t//d;
  94. # Remove single line C "/* */" comments
  95. $line =~ s/\/\*.*?\*\///g;
  96. # Remove any "//" comments
  97. # Make sure the start of the comment is NOT
  98. # inside a string
  99. if (($line =~ /\/\//) && ($line !~ /\".*?\/\/.*?\"/))
  100. {
  101. $line =~ s/\/\/.*$/ /;
  102. }
  103. # Multi-line C comment?
  104. # Make sure the start of the comment is NOT
  105. # inside a string
  106. if (($line =~ /\/\*/) && ($line !~ /\".*?\/\*.*?\"/))
  107. {
  108. # Grab anything before the comment
  109. # Need to make it look like there's still a EOL marker
  110. $line = $` . "\n";
  111. # Remember that we're in "comment" mode
  112. $in_comment = 1;
  113. next LINE;
  114. }
  115. local($line_pack) = $line;
  116. # Replace spaces between word characters with '#'
  117. $line_pack =~ s/(\w)\s+(\w)/$1#$2/g;
  118. # remove whitespace
  119. $line_pack =~ tr/ \t//d;
  120. # Remove quoted double-quote characters
  121. $line_pack =~ s/'\\?"'/'_'/g;
  122. # Remove any strings
  123. # Note: Doesn't handle quoted quote characters correctly
  124. $line_pack =~ s/"[^"]*"/_/g;
  125. # Remove any "//" comments
  126. $line_pack =~ s/\/\/.*$//;
  127. # For empty lines,
  128. if ( $line_pack eq "\n" )
  129. {
  130. next LINE;
  131. }
  132. if ( $line_pack =~ /^\}/)
  133. {
  134. return $index;
  135. }
  136. # Remove beginning "{"
  137. $line_pack =~ s/^\{(.*)\}.*$/$1/;
  138. #print "line_pack: $line_pack\n";
  139. @words = split(/,/, $line_pack);
  140. HalpProfileMappingToSource( $index, $kprofile, @words );
  141. $index++;
  142. next LINE;
  143. }
  144. return 0;
  145. }
  146. sub HalpProfileMappingToSource
  147. {
  148. # print @_;
  149. local($idx, $kprofile, $supported, $event, $profileSource, $profileSourceMask, $interval, $defInterval, $maxInterval, $minInterval) = @_;
  150. local($name) = $kprofile;
  151. $name =~ s/Profile//;
  152. local($shortName) = $name;
  153. $shortName =~ s/Merced//;
  154. $shortName =~ s/McKinley//;
  155. if ( $idx eq 0 )
  156. {
  157. print " \{ \"ProfileTime\", ProfileTime, \"ProfileTime\", $defInterval, 0, FALSE \}";
  158. }
  159. elsif ( $supported eq "FALSE" ) {
  160. print ",\n \{ \"INVALID_$idx\", (KPROFILE_SOURCE)-1, \"INVALID_$idx\", 0, 0, FALSE \}";
  161. }
  162. else {
  163. print ",\n \{ \"$name\", $kprofile, \"$shortName\", $defInterval, 0, FALSE \}";
  164. }
  165. }
  166. sub PrintProlog
  167. {
  168. local($str) = @_;
  169. local($basename) = $filename;
  170. local($header) = $filename;
  171. local($arrayname);
  172. $basename =~ s/.*\\(.*).[ch]/$1/;
  173. $arrayname = $basename . "StaticSources";
  174. if ($header !~ /\.h/)
  175. {
  176. $header =~ s/\.c$/\.h/;
  177. }
  178. print "\/\/\n";
  179. print "\/\/ This file is automatically generated by $SCRIPT_CMD, parsing\n";
  180. print "\/\/ $filename.\n";
  181. print "\/\/\n\n";
  182. print "\#include \"$header\"\n\n";
  183. print "SOURCE\n";
  184. print "$arrayname\[\] = \{\n";
  185. }
  186. sub PrintEpilog
  187. {
  188. local($str) = @_;
  189. print "\n};\n";
  190. }
  191. sub Usage
  192. {
  193. local($error) = @_;
  194. die "$error\n",
  195. "$SCRIPT_LONGVERSION\n",
  196. "Usage : $SCRIPT_CMD filename\n",
  197. "Options:\n",
  198. " filename file containing the IA64 $typedstr definition\n";
  199. }