--- OpenCL/gengetinfo 2012/05/05 13:30:07 1.17 +++ OpenCL/gengetinfo 2012/05/05 15:43:02 1.19 @@ -39,9 +39,23 @@ Program => ['cl_program', 'OpenCL::Program', 'program'], CommandQueue => ['cl_command_queue', 'OpenCL::Queue', 'queue'], cl_context_properties => ['cl_context_properties', 'newSVuv ((UV)value [i])', 'property_int'], - cl_program_binary_type => ['cl_program_binary_type', 'newSVuv (UV)value [i])', 'binary_type'], + cl_program_binary_type => ['cl_program_binary_type', 'newSVuv ((UV)value [i])', 'binary_type'], ); + +# try to re-use types with same representation in C - if we +# ever overload bitfields etc. then we need to remove all +# typesimplify code. +my %typesimplify; +{ + open my $h, ") { + $typesimplify{$2} = $1 + if /typedef\s+(cl_\S+)\s+(cl_\S+);/; + } +} + { my %tmap = ( T_IV => "newSViv (value [i])", @@ -179,13 +193,16 @@ . "XXXNAMEXXX (OpenCL::$classmap{$real_class} self$extra_xs_args)\n"; $XS2 = " PPCODE:\n"; + my $stype = $type->[0]; # simplified type + $stype = $typesimplify{$stype} while exists $typesimplify{$stype}; + if ($dynamic) { $XS2 .= " size_t size;\n" . " NEED_SUCCESS (Get${cbase}Info, (self$extra_args, ix, 0, 0, &size));\n" - . " $type->[0] *value = tmpbuf (size);\n" + . " $stype *value = tmpbuf (size);\n" . " NEED_SUCCESS (Get${cbase}Info, (self$extra_args, ix, size, value, 0));\n"; } else { - $XS2 .= " $type->[0] value [1];\n" + $XS2 .= " $stype value [1];\n" . " NEED_SUCCESS (Get${cbase}Info, (self$extra_args, ix, sizeof (value), value, 0));\n"; } @@ -207,10 +224,8 @@ $stash =~ s/opencl:://; $stash =~ s/::/_/g; - $XS2 .= " {\n"; - $XS2 .= " NEED_SUCCESS (Retain$oclass, (value [i]));\n" unless $oclass eq "Platform" || $oclass eq "Device"; - $XS2 .= " PUSH_CLOBJ (stash_$stash, value [i]);\n"; - $XS2 .= " }\n"; + $XS2 .= " NEED_SUCCESS (Retain$oclass, (value [i]));\n" unless $oclass eq "Platform" || $oclass eq "Device"; + $XS2 .= " PUSH_CLOBJ (stash_$stash, value [i]);\n"; } else { $XS2 .= " PUSHs (sv_2mortal ($type->[1]));\n"; } @@ -235,7 +250,7 @@ $_->[2] =~ s/\bix\b/$_->[1][0][1]/g; $_->[1] = ""; } else { - $_->[1] = " ALIAS:\n" . join "", map " $_->[0] = $_->[1]\n", @{ $_->[1] }; + $_->[1] = " ALIAS:\n" . join "", sort, map " $_->[0] = $_->[1]\n", @{ $_->[1] }; } $XS .= join "", @$_; }