Skip to content

Commit

Permalink
Various fixes to codegen_c_hdr.pl for DFHack#12
Browse files Browse the repository at this point in the history
* Fix size of std::fstream on 64-bit Windows
* Remove "pad" from 32-bit Windows std::vector
* Apply proper name to Destructor vmethods
* Attempt to handle vectors of bitfields, defaulting to int32_t
* Attempt to handle vectors of unions
  • Loading branch information
quietust committed Sep 25, 2020
1 parent a264f06 commit 9b4b7d2
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions codegen_c_hdr.pl
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ sub render_class_vtable_fields {
my $voff = 0;
for my $meth ($vms->findnodes('child::vmethod')) {
my $name = $meth->getAttribute('name') || $meth->getAttribute('ld:anon-name') || "vmeth_$voff";
if ($meth->getAttribute('is-destructor')) { $name = "destructor" ; }
# TODO actual prototype ?
push @lines, "void *$name;";
$voff += 4;
Expand Down Expand Up @@ -556,6 +557,7 @@ sub render_stlvector {
}
} elsif ($tgm eq 'number') {
my $tgst = $tg->getAttribute('ld:subtype');
$tgst = 'int32_t' if !defined $tgst || ($tgst eq 'bitfield' && !$tg->getAttribute('base-type'));
$tgst = $tg->getAttribute('base-type') if (!$tgst or $tgst eq 'enum' or $tgst eq 'bitfield');
$tgst = 'int8_t' if $tgst eq 'bool'; # dont confuse with stl-bit-vector
push @lines, "struct stl_vector_$tgst";
Expand All @@ -565,6 +567,20 @@ sub render_stlvector {
if ($tgtm eq 'enum-type' or $tgtm eq 'bitfield-type') {
my $tgtst = $tgt->getAttribute('base-type') || 'int32_t';
push @lines, "struct stl_vector_$tgtst";
} elsif ($tgtm eq 'struct-type' && ($tgt->getAttribute('is-union') eq 'true')) {
my $utg = $tgt->findnodes('child::ld:field')->[0];
while (1) {
my $tgtst = $utg->getAttribute('ld:subtype');
if ($tgtst) {
push @lines, "struct stl_vector_$tgtst";
last;
}
$utg = $utg->findnodes('child::ld:field')->[0];
if (!$utg) {
push @lines, "// TODO in $prefix: struct stl_vector_global-$tgtm";
last;
}
}
} else {
push @lines, "// TODO in $prefix: struct stl_vector_global-$tgtm";
}
Expand Down Expand Up @@ -640,7 +656,7 @@ sub render_item_primitive {
if ($linux) {
push @lines, "int32_t fstream[71]"; # (284 bytes, 4o align)
} else {
push @lines, "int64_t fstream[24]"; # (192 bytes, 8o align)
push @lines, "int64_t fstream[35]"; # (280 bytes, 8o align)
}
} else {
print "no render primitive $subtype\n";
Expand Down Expand Up @@ -729,10 +745,6 @@ sub render_item_bytes {
};
EOS
if ($bin32) {
$vecpad = " int32_t pad;\n";
}

} else {
$hdr .= <<EOS;
// Linux Glibc STL
Expand Down

0 comments on commit 9b4b7d2

Please sign in to comment.