Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions codegen_c_hdr.pl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
my $bin32 = grep { $_ eq '--32' } @ARGV;
@ARGV = grep { $_ ne '--32' } @ARGV if $bin32;

my $input = $ARGV[0] || 'codegen/codegen.out.xml';
my $input = $ARGV[0] || 'codegen.out.xml';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this script is intended to be run from the df-structures root, where codegen/codegen.out.xml is the correct path if codegen.pl is run with default arguments.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but i only found the codegen.out.xml in df's include folder, there isn't codegen/codegen.out.xml

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Historically, this tool has been run against a copy of the df-structures repo, with codegen.pl run with default arguments, which results in codegen.out.xml being placed in the codegen subfolder. DF build scripting runs codegen.pl with nondefault arguments and is not the default use case here.

my $output = $ARGV[1] || 'codegen.h';


Expand Down Expand Up @@ -422,7 +422,16 @@ sub render_item_global {

my $typename = $item->getAttribute('type-name');
my $subtype = $item->getAttribute('ld:subtype');
my $type = $global_types{$typename};
my $type = $global_types{$typename} if $typename;

if (!$type) {
print "unknown global type $typename\n" if $typename;
fwd_decl_class($typename) if $typename;
push @lines, "struct $typename";
$lines[$#lines] .= " $name" if ($name);
return;
}

my $tname = $type->getAttribute('original-name') ||
$type->getAttribute('type-name') ||
$typename;
Expand Down Expand Up @@ -641,44 +650,67 @@ sub render_item_staticarray {
if ($name and $name =~ /^\*/) {
render_item($tg, "*${name}");
} else {
render_item($tg, "${name}[$count]");
render_item($tg, $name . "[$count]");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reason for these changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is an error like this Global symbol "@name" requires explicit package name (did you forget to declare "my @name"?) at E:\Development\OnGoing_Project\dfhack\library\include\df\codegen_c_hdr.pl line 665. so i need to change that to new format

}
}

sub render_item_primitive {
my ($item, $name) = @_;

my $subtype = $item->getAttribute('ld:subtype');
my $subtype = $item->getAttribute('ld:subtype') || '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ld:subtype was required before, this probably means some new type we have added isn't generating it, and we should fix that instead.

if ($subtype eq 'stl-string') {
push @lines, "struct stl_string";
$lines[$#lines] .= " $name" if ($name);
push @lines, "struct stl_string $name";
} elsif ($subtype eq 'stl-fstream') {
if ($linux) {
push @lines, "int32_t fstream[71]"; # (284 bytes, 4o align)
push @lines, "int32_t " . $name . "[71]"; # (284 bytes, 4o align)
} else {
push @lines, "int64_t fstream[35]"; # (280 bytes, 8o align)
push @lines, "int64_t " . $name . "[35]"; # (280 bytes, 8o align)
}
} elsif ($subtype eq 'stl-mutex') {
if ($linux) {
# 40 bytes on glibc
push @lines, "int64_t " . $name . "[5]";
} else {
# 80 bytes on msvc
push @lines, "int64_t " . $name . "[10]";
}
} elsif ($subtype eq 'stl-condition-variable') {
if ($linux) {
# 48 bytes on glibc
push @lines, "int64_t " . $name . "[6]";
} else {
# 8 bytes on msvc
push @lines, "int64_t " . $name . "[1]";
}
} elsif ($subtype eq 'stl-fs-path') {
push @lines, "struct stl_string $name";
} elsif ($subtype eq 'stl-future') {
# roughly a pointer
push @lines, "void *${name}";
} else {
print "no render primitive $subtype\n";
push @lines, "/* UNKNOWN primitive: $subtype */ $name";
}
}

sub render_item_bytes {
my ($item, $name) = @_;

my $subtype = $item->getAttribute('ld:subtype');
my $subtype = $item->getAttribute('ld:subtype') || '';
if ($subtype eq 'padding') {
my $size = $item->getAttribute('size');
push @lines, "char ${name}[$size]";
} elsif ($subtype eq 'static-string') {
my $size = $item->getAttribute('size');
if ($size) {
push @lines, "char ${name}[$size]";
push @lines, "char ". $name . "[$size]";
} else {
push @lines, "char *${name}";
}
} else {
print "no render bytes $subtype\n";
my $size = $item->getAttribute('size') || 1;
push @lines, "char ${name}[$size]";
}
}

Expand Down Expand Up @@ -776,7 +808,7 @@ sub render_item_bytes {
EOS
}

foreach my $vtype ('ptr', 'strptr', 'int32_t', 'uint32_t', 'int16_t', 'uint16_t', 'int8_t', 'uint8_t') {
foreach my $vtype ('ptr', 'strptr', 'long', 'int32_t', 'uint32_t', 'int16_t', 'uint16_t', 'int8_t', 'uint8_t') {
my $ctype = $vtype . ' ';
$ctype = 'void *' if ($vtype eq 'ptr');
$ctype = 'struct stl_string *' if ($vtype eq 'strptr');
Expand Down