use File::Path qw(make_path);
use File::Basename;
+use Time::HiRes qw(clock_gettime CLOCK_REALTIME);
use strict;
);
# ###################################################################### #
+my $now = clock_gettime(CLOCK_REALTIME);
+my $next;
my $sys = {};
$sys->{output} = 'bin/gen/notzed.vulkan/classes';
my $vk = new vulkan($sys);
+printf "%9.6f load registry\n", (($next = clock_gettime(CLOCK_REALTIME)) - $now); $now = $next;
+
my $api = $vk->buildFeatures(
[ 'VK_VERSION_1_0', 'VK_VERSION_1_1', 'VK_VERSION_1_2', 'VK_VERSION_1_3' ],
[ 'xlib',
#'wayland',
'xcb' ]);
+printf "%9.6f build api view\n", (($next = clock_gettime(CLOCK_REALTIME)) - $now); $now = $next;
+
my $structTypes = loadTypes($api, 'struct-types.api');
my $commandTypes = loadTypes($api, 'command-types.api');
+printf "%9.6f load templates\n", (($next = clock_gettime(CLOCK_REALTIME)) - $now); $now = $next;
+
analyseTypes($vk, $api);
+printf "%9.6f analyse types\n", (($next = clock_gettime(CLOCK_REALTIME)) - $now); $now = $next;
+
# Use some heuristics to create overrides for improving the api
# - object constructor functions return values rather take pointer* values
}
}
+printf "%9.6f guess overrides\n", (($next = clock_gettime(CLOCK_REALTIME)) - $now); $now = $next;
+
if (0) {
analyseAccessors($api);
exit 1;
closeOutput($sys, $s->{name}, $f);
}
+printf "%9.6f export classes\n", (($next = clock_gettime(CLOCK_REALTIME)) - $now); $now = $next;
+
exit 0;
# ###################################################################### #
}
}
- print "Unique Types:\n";
- my $base = {};
- map { $base->{$_} = 1 } values %$seen;
+ if ($sys->{verbose}) {
+ print "Unique Types:\n";
+ my $base = {};
+ map { $base->{$_} = 1 } values %$seen;
- foreach my $k (sort keys %$base) {
- print " $k\n";
+ foreach my $k (sort keys %$base) {
+ print " $k\n";
+ }
}
}
$t = eval $t if $type->{accessor}->{"$field:eval"};
die "$@" if !defined($t);
- push @{$info->{$field}}, code::formatTemplate($t, $v);
+ push @{$info->{$field}}, code::formatTemplate($t, $v) if $t;
}
}
}
# {setall-arg}
# {setall}
+# ###################################################################### #
+
code value {
get {{
/* {deref} */
setallat {{ self$.set{Name}AtIndex(index$, {name}); }}
}
+# ###################################################################### #
+
code value-array {
getorset {{
/* value-array {deref} */
}}
}
+# ###################################################################### #
# don't like having to pass scope here, not sure what else to do though
code handle-array {
getorset {{
}}
}
+# ###################################################################### #
+
code value-array2d {
getorset {{
/* value-array2d {deref} */
}}
}
+# ###################################################################### #
+
code inline {
getorset {{
/* inline {deref} */
}}
}
+# ###################################################################### #
# inline type that we also want to include expanded in initialiser
+# We also create expanded setters and a getter for each simple embedded field.
+
code inline-expand {
+
+ # These are basic object based accessors
+
getorset {{
/* inline {deref} */
public {type} get{Name}() {
}
}
}}
+
getorsetat {{
/* inline {deref} */
public {type} get{Name}AtIndex(long i$) {
}
}
}}
- setall-arg eval {{
- my @list;
- return 0 if $m->{len1};
+
+ # subroutine to the all-args info, only eval if len1 == 0
+ # this will also include it's own inline struct's fields
+ analyse-args eval {{
+ use integer;
+ my $list = [];
+
foreach my $a (@{$api->{data}->{$m->{baseType}}->{items}}) {
my $name = "$m->{name}\$$a->{name}";
- if ($primitiveMap{$a->{baseType}}) {
- push @list, "$primitiveMap{$a->{baseType}} $name";
+ my $offset = ($m->{bitOffset} + $a->{bitOffset}) / 8;
+ my $atype = $primitiveMap{$a->{baseType}};
+
+ if ($atype) {
+ push @$list, {
+ name=> $name,
+ type => $atype,
+ offset => $offset,
+ };
} else {
my $as = $api->{data}->{$a->{baseType}};
- foreach my $aa (@{$as->{items}}) {
- push @list, "$primitiveMap{$aa->{baseType}} $name\$$aa->{name}";
+ foreach my $b (@{$as->{items}}) {
+ my $btype = $primitiveMap{$b->{baseType}};
+ if ($btype) {
+ push @$list, {
+ name => "$name\$$b->{name}",
+ type => $btype,
+ offset => $offset + $b->{bitOffset} / 8
+ };
+ }
}
}
}
- join ', ', @list;
+ $list;
}}
- setall eval {{
- my @list;
+
+ # setBlah(all-simple-blah-fields)
+ set eval {{
return 0 if $m->{len1};
- foreach my $a (@{$api->{data}->{$m->{baseType}}->{items}}) {
- my $pt = $primitiveMap{$a->{baseType}};
- if ($pt) {
- push @list, 'self$.segment.set(Memory.'.uc($pt).', '
- .(($m->{bitOffset} + $a->{bitOffset})/8).", $m->{name}\$$a->{name}".');';
- } else {
- my $as = $api->{data}->{$a->{baseType}};
- foreach my $aa (@{$as->{items}}) {
- $pt = $primitiveMap{$aa->{baseType}};
- push @list, 'self$.segment.set(Memory.'.uc($pt).', '
- .(($m->{bitOffset} + $aa->{bitOffset} + $a->{bitOffset})/8).", $m->{name}\$$a->{name}\$$aa->{name}".');';
- }
- }
+ my $setall_arg = eval($type->{accessor}->{'setall-arg'});
+ my $setall = eval($type->{accessor}->{setall});
+ <<END;
+ public void set{Name}($setall_arg) {
+ var self\$ = this;
+ $setall
}
- join "\n", @list;
+END
}}
- setallat eval {{
- my @list;
+
+ # getBlah$field0(), getBlah$field1() etc.
+ get eval {{
+ die if ($m->{len1});
+
return 0 if $m->{len1};
- foreach my $a (@{$api->{data}->{$m->{baseType}}->{items}}) {
- my $pt = $primitiveMap{$a->{baseType}};
- if ($pt) {
- push @list, 'self$.segment.set(Memory.'.uc($pt).', index$ * '.($s->{bitSize} / 8).' + '
- .(($m->{bitOffset} + $a->{bitOffset})/8).", $m->{name}\$$a->{name}".');';
- } else {
- my $as = $api->{data}->{$a->{baseType}};
- foreach my $aa (@{$as->{items}}) {
- $pt = $primitiveMap{$aa->{baseType}};
- push @list, 'self$.segment.set(Memory.'.uc($pt).', index$ * '.($s->{bitSize} / 8).' + '
- .(($m->{bitOffset} + $aa->{bitOffset} + $a->{bitOffset})/8).", $m->{name}\$$a->{name}\$$aa->{name}".');';
- }
- }
+
+ my $list = eval($type->{accessor}->{'analyse-args'}); die "$@" if !defined $list;
+
+ join("\n", map {
+ my $tname = uc($_->{type});
+ my $fname = ucfirst($_->{name});
+ <<END;
+ public $_->{type} get$fname() {
+ return this.segment.get(Memory.$tname, $_->{offset});
+ }
+END
+ } @$list);
+ }}
+
+ # setBlahAtIndex(index, all-simple-blah-fields)
+ setat eval {{
+ return 0 if $m->{len1};
+ my $setall_arg = eval($type->{accessor}->{'setall-arg'});
+ my $setallat = eval($type->{accessor}->{setallat});
+ <<END;
+ public void set{Name}AtIndex(long index\$, $setall_arg) {
+ var self\$ = this;
+ $setallat
}
- join "\n", @list;
+END
+ }}
+
+ # create arg-list for setall template
+ setall-arg eval {{
+ return 0 if $m->{len1};
+
+ my $list = eval($type->{accessor}->{'analyse-args'}); die "$@" if !defined $list;
+
+ join(', ', map { "$_->{type} $_->{name}" } @$list);
+ }}
+
+ setall eval {{
+ return 0 if $m->{len1};
+
+ my $list = eval($type->{accessor}->{'analyse-args'}); die "$@" if !defined $list;
+
+ join("\n\t", map { 'self$.segment.set(Memory.'.uc($_->{type}).", $_->{offset}, $_->{name});" } @$list);
+ }}
+
+ setallat eval {{
+ use integer;
+
+ return 0 if $m->{len1};
+
+ my $list = eval($type->{accessor}->{'analyse-args'}); die "$@" if !defined $list;
+ my $stride = $s->{bitSize} / 8;
+
+ join("\n\t", map { 'self$.segment.set(Memory.'.uc($_->{type}).", index\$ * $stride + $_->{offset}, $_->{name});" } @$list);
}}
}
+# ###################################################################### #
+
# value with a SegmentAllocator passed to set()
code value-alloc value {
set {{