gltracegen 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #! /usr/bin/perl
  2. #
  3. # Copyright (C) 2010 Google Inc.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. use strict;
  17. sub rtrim($)
  18. {
  19. my $string = shift;
  20. $string =~ s/\s+$//;
  21. return $string;
  22. }
  23. while (my $line = <>) {
  24. next if $line =~ /^\//;
  25. next if $line =~ /^#/;
  26. next if $line =~ /^\s*$/;
  27. if ($line !~ /^GL_ENTRY\(([^,]+), ([^,]+), ([^\)]+)\)/) {
  28. next;
  29. }
  30. my $type = $1;
  31. my $name = $2;
  32. my $args = $3;
  33. my @args = split ',', $args;
  34. my $len = scalar(@args);
  35. my $nonVoidArgLen = 0;
  36. for (my $num = 0; $num < $len; $num++) {
  37. if ($args[$num] ne "void") {
  38. $nonVoidArgLen++;
  39. }
  40. }
  41. if ($type eq "void") {
  42. printf("TRACE_GL_VOID(");
  43. } else {
  44. printf("TRACE_GL(%s, ", $type);
  45. }
  46. printf("%s, (%s), (", $name, $args);
  47. for (my $num = 0; $num < $len; $num++) {
  48. if ($args[$num] ne "void") {
  49. if ($num > 0) {
  50. print ", ";
  51. }
  52. #
  53. # extract the name from the parameter
  54. # type name
  55. # const type *name
  56. # type *name
  57. # type name[4]
  58. #
  59. if ($args[$num] =~ /(\S+\s)+\**\s*([\w]+)/) {
  60. printf("%s", $2);
  61. }
  62. }
  63. }
  64. printf("), %d", $nonVoidArgLen);
  65. for (my $num = 0; $num < $len; $num++) {
  66. if ($args[$num] ne "void") {
  67. #
  68. # extract the name from the parameter
  69. # type name
  70. # const type *name
  71. # type *name
  72. # type name[4]
  73. #
  74. my $arg = $args[$num];
  75. if ($arg =~ /(\S+\s)+\**\s*([\w]+)/) {
  76. my $name = $2;
  77. if ($arg =~ /((const )*(\S+\s)+\**)\s*([\w]+)/) {
  78. my $type = rtrim($1);
  79. printf(", \"%s\", %s", $type, $name);
  80. }
  81. }
  82. }
  83. }
  84. printf(")\n");
  85. }