2012-03-26 06:37:18 -06:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use XML::LibXML;
|
|
|
|
|
|
|
|
our @lines_rb;
|
2012-05-29 08:10:33 -06:00
|
|
|
|
2016-08-05 15:12:07 -06:00
|
|
|
my $os = $ARGV[2] or die('os not provided (argv[2])');
|
|
|
|
if ($os =~ /linux/i or $os =~ /darwin/i) {
|
2012-05-29 08:10:33 -06:00
|
|
|
$os = 'linux';
|
2016-08-05 15:12:07 -06:00
|
|
|
} elsif ($os =~ /windows/i) {
|
2012-05-29 08:10:33 -06:00
|
|
|
$os = 'windows';
|
2016-08-05 15:12:07 -06:00
|
|
|
} else {
|
|
|
|
die "Unknown OS: " . $ARGV[2] . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $arch = $ARGV[3] or die('arch not provided (argv[3])');
|
|
|
|
if ($arch =~ /64/i) {
|
|
|
|
$arch = 64;
|
|
|
|
} elsif ($arch =~ /32/i) {
|
|
|
|
$arch = 32;
|
|
|
|
} else {
|
|
|
|
die "Unknown architecture: " . $ARGV[3] . "\n";
|
2012-05-29 08:10:33 -06:00
|
|
|
}
|
2016-08-05 15:12:07 -06:00
|
|
|
|
|
|
|
# 32 bits on Windows and 32-bit *nix, 64 bits on 64-bit *nix
|
|
|
|
my $SIZEOF_LONG;
|
|
|
|
if ($os eq 'windows' || $arch == 32) {
|
|
|
|
$SIZEOF_LONG = 4;
|
|
|
|
} else {
|
|
|
|
$SIZEOF_LONG = 8;
|
|
|
|
}
|
|
|
|
|
2016-08-05 15:29:24 -06:00
|
|
|
my $SIZEOF_PTR = ($arch == 64) ? 8 : 4;
|
2012-03-26 06:37:18 -06:00
|
|
|
|
|
|
|
sub indent_rb(&) {
|
|
|
|
my ($sub) = @_;
|
|
|
|
my @lines;
|
|
|
|
{
|
|
|
|
local @lines_rb;
|
|
|
|
$sub->();
|
|
|
|
@lines = map { " " . $_ } @lines_rb;
|
|
|
|
}
|
|
|
|
push @lines_rb, @lines
|
|
|
|
}
|
|
|
|
|
|
|
|
sub rb_ucase {
|
|
|
|
my ($name) = @_;
|
2012-03-31 17:33:30 -06:00
|
|
|
return $name if ($name eq uc($name));
|
2012-03-26 06:37:18 -06:00
|
|
|
return join("", map { ucfirst $_ } (split('_', $name)));
|
|
|
|
}
|
|
|
|
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
my %item_renderer = (
|
2012-03-31 17:33:30 -06:00
|
|
|
'global' => \&render_item_global,
|
2012-04-02 11:00:38 -06:00
|
|
|
'number' => \&render_item_number,
|
2012-03-31 17:33:30 -06:00
|
|
|
'container' => \&render_item_container,
|
|
|
|
'compound' => \&render_item_compound,
|
2012-04-02 11:00:38 -06:00
|
|
|
'pointer' => \&render_item_pointer,
|
|
|
|
'static-array' => \&render_item_staticarray,
|
|
|
|
'primitive' => \&render_item_primitive,
|
|
|
|
'bytes' => \&render_item_bytes,
|
2012-03-26 06:37:18 -06:00
|
|
|
);
|
|
|
|
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-04-26 12:03:56 -06:00
|
|
|
my %global_types;
|
2012-05-29 08:10:33 -06:00
|
|
|
our $current_typename;
|
2012-04-02 11:00:38 -06:00
|
|
|
|
2012-03-26 06:37:18 -06:00
|
|
|
sub render_global_enum {
|
|
|
|
my ($name, $type) = @_;
|
|
|
|
|
|
|
|
my $rbname = rb_ucase($name);
|
2012-05-10 15:27:42 -06:00
|
|
|
push @lines_rb, "class $rbname < MemHack::Enum";
|
2012-03-26 06:37:18 -06:00
|
|
|
indent_rb {
|
2012-03-31 17:33:30 -06:00
|
|
|
render_enum_fields($type);
|
2012-03-26 06:37:18 -06:00
|
|
|
};
|
2012-04-13 08:17:56 -06:00
|
|
|
push @lines_rb, "end\n";
|
2012-03-26 06:37:18 -06:00
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-03-31 17:33:30 -06:00
|
|
|
sub render_enum_fields {
|
|
|
|
my ($type) = @_;
|
|
|
|
|
2012-05-10 15:27:42 -06:00
|
|
|
push @lines_rb, "ENUM = Hash.new";
|
|
|
|
push @lines_rb, "NUME = Hash.new";
|
2012-04-26 12:03:56 -06:00
|
|
|
|
|
|
|
my %attr_type;
|
2012-05-06 14:42:06 -06:00
|
|
|
my %attr_list;
|
2012-05-29 09:28:51 -06:00
|
|
|
render_enum_initattrs($type, \%attr_type, \%attr_list);
|
|
|
|
|
|
|
|
my $value = -1;
|
|
|
|
for my $item ($type->findnodes('child::enum-item'))
|
|
|
|
{
|
|
|
|
$value = $item->getAttribute('value') || ($value+1);
|
|
|
|
my $elemname = $item->getAttribute('name'); # || "unk_$value";
|
|
|
|
|
|
|
|
if ($elemname)
|
|
|
|
{
|
|
|
|
my $rbelemname = rb_ucase($elemname);
|
|
|
|
push @lines_rb, "ENUM[$value] = :$rbelemname ; NUME[:$rbelemname] = $value";
|
|
|
|
for my $iattr ($item->findnodes('child::item-attr'))
|
|
|
|
{
|
|
|
|
my $attr = render_enum_attr($rbelemname, $iattr, \%attr_type, \%attr_list);
|
|
|
|
$lines_rb[$#lines_rb] .= ' ; ' . $attr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub render_enum_initattrs {
|
|
|
|
my ($type, $attr_type, $attr_list) = @_;
|
|
|
|
|
|
|
|
for my $attr ($type->findnodes('child::enum-attr'))
|
|
|
|
{
|
2012-04-26 12:03:56 -06:00
|
|
|
my $rbattr = rb_ucase($attr->getAttribute('name'));
|
|
|
|
my $typeattr = $attr->getAttribute('type-name');
|
2012-04-26 12:55:52 -06:00
|
|
|
# find how we need to encode the attribute values: string, symbol (for enums), raw (number, bool)
|
2012-04-26 12:03:56 -06:00
|
|
|
if ($typeattr) {
|
|
|
|
if ($global_types{$typeattr}) {
|
2012-05-29 09:28:51 -06:00
|
|
|
$attr_type->{$rbattr} = 'symbol';
|
2012-04-26 12:03:56 -06:00
|
|
|
} else {
|
2012-05-29 09:28:51 -06:00
|
|
|
$attr_type->{$rbattr} = 'naked';
|
2012-04-26 12:03:56 -06:00
|
|
|
}
|
|
|
|
} else {
|
2012-05-29 09:28:51 -06:00
|
|
|
$attr_type->{$rbattr} = 'quote';
|
2012-04-26 12:03:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
my $def = $attr->getAttribute('default-value');
|
2012-05-29 09:28:51 -06:00
|
|
|
if ($attr->getAttribute('is-list'))
|
|
|
|
{
|
2012-05-06 14:42:06 -06:00
|
|
|
push @lines_rb, "$rbattr = Hash.new { |h, k| h[k] = [] }";
|
2012-05-29 09:28:51 -06:00
|
|
|
$attr_list->{$rbattr} = 1;
|
|
|
|
}
|
|
|
|
elsif ($def)
|
|
|
|
{
|
|
|
|
$def = ":$def" if ($attr_type->{$rbattr} eq 'symbol');
|
|
|
|
$def =~ s/'/\\'/g if ($attr_type->{$rbattr} eq 'quote');
|
|
|
|
$def = "'$def'" if ($attr_type->{$rbattr} eq 'quote');
|
2012-04-26 12:03:56 -06:00
|
|
|
push @lines_rb, "$rbattr = Hash.new($def)";
|
2012-05-29 09:28:51 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-26 12:03:56 -06:00
|
|
|
push @lines_rb, "$rbattr = Hash.new";
|
|
|
|
}
|
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
}
|
2012-04-26 12:03:56 -06:00
|
|
|
|
2012-05-29 09:28:51 -06:00
|
|
|
sub render_enum_attr {
|
|
|
|
my ($rbelemname, $iattr, $attr_type, $attr_list) = @_;
|
2012-03-31 17:33:30 -06:00
|
|
|
|
2012-05-29 09:28:51 -06:00
|
|
|
my $ian = $iattr->getAttribute('name');
|
|
|
|
my $iav = $iattr->getAttribute('value');
|
|
|
|
my $rbattr = rb_ucase($ian);
|
|
|
|
|
|
|
|
my $op = ($attr_list->{$rbattr} ? '<<' : '=');
|
|
|
|
|
|
|
|
$iav = ":$iav" if ($attr_type->{$rbattr} eq 'symbol');
|
|
|
|
$iav =~ s/'/\\'/g if ($attr_type->{$rbattr} eq 'quote');
|
|
|
|
$iav = "'$iav'" if ($attr_type->{$rbattr} eq 'quote');
|
|
|
|
|
|
|
|
return "${rbattr}[:$rbelemname] $op $iav";
|
2012-03-31 17:33:30 -06:00
|
|
|
}
|
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
|
2012-03-26 06:37:18 -06:00
|
|
|
sub render_global_bitfield {
|
|
|
|
my ($name, $type) = @_;
|
|
|
|
|
|
|
|
my $rbname = rb_ucase($name);
|
2012-04-19 17:29:52 -06:00
|
|
|
push @lines_rb, "class $rbname < MemHack::Compound";
|
2012-03-26 06:37:18 -06:00
|
|
|
indent_rb {
|
2012-03-31 17:33:30 -06:00
|
|
|
render_bitfield_fields($type);
|
2012-03-26 06:37:18 -06:00
|
|
|
};
|
2012-04-13 08:17:56 -06:00
|
|
|
push @lines_rb, "end\n";
|
2012-03-26 06:37:18 -06:00
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-03-31 17:33:30 -06:00
|
|
|
sub render_bitfield_fields {
|
|
|
|
my ($type) = @_;
|
|
|
|
|
2012-04-13 08:17:56 -06:00
|
|
|
push @lines_rb, "field(:_whole, 0) {";
|
|
|
|
indent_rb {
|
2012-05-29 08:10:33 -06:00
|
|
|
render_item_number($type);
|
2012-04-13 08:17:56 -06:00
|
|
|
};
|
|
|
|
push @lines_rb, "}";
|
|
|
|
|
2012-03-31 17:33:30 -06:00
|
|
|
my $shift = 0;
|
2012-05-29 09:28:51 -06:00
|
|
|
for my $field ($type->findnodes('child::ld:field'))
|
|
|
|
{
|
2012-03-31 17:33:30 -06:00
|
|
|
my $count = $field->getAttribute('count') || 1;
|
|
|
|
my $name = $field->getAttribute('name');
|
2012-04-26 12:55:52 -06:00
|
|
|
my $type = $field->getAttribute('type-name');
|
|
|
|
my $enum = rb_ucase($type) if ($type and $global_types{$type});
|
2012-03-31 17:33:30 -06:00
|
|
|
$name = $field->getAttribute('ld:anon-name') if (!$name);
|
|
|
|
print "bitfield $name !number\n" if (!($field->getAttribute('ld:meta') eq 'number'));
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
if ($name)
|
|
|
|
{
|
2012-08-03 08:53:54 -06:00
|
|
|
if ($enum) {
|
2012-05-29 09:28:51 -06:00
|
|
|
push @lines_rb, "field(:$name, 0) { bits $shift, $count, $enum }";
|
2012-08-03 08:53:54 -06:00
|
|
|
} elsif ($count == 1) {
|
|
|
|
push @lines_rb, "field(:$name, 0) { bit $shift }";
|
2012-05-29 09:28:51 -06:00
|
|
|
} else {
|
|
|
|
push @lines_rb, "field(:$name, 0) { bits $shift, $count }";
|
|
|
|
}
|
2012-03-31 17:33:30 -06:00
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-03-31 17:33:30 -06:00
|
|
|
$shift += $count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
|
2012-04-06 11:30:58 -06:00
|
|
|
my %seen_class;
|
2012-05-29 08:10:33 -06:00
|
|
|
our $compound_off;
|
2012-05-29 09:28:51 -06:00
|
|
|
our $compound_pointer;
|
|
|
|
|
2012-03-26 06:37:18 -06:00
|
|
|
sub render_global_class {
|
|
|
|
my ($name, $type) = @_;
|
|
|
|
|
2012-05-29 09:28:51 -06:00
|
|
|
my $meta = $type->getAttribute('ld:meta');
|
2012-04-06 11:30:58 -06:00
|
|
|
my $rbname = rb_ucase($name);
|
|
|
|
|
|
|
|
# ensure pre-definition of ancestors
|
|
|
|
my $parent = $type->getAttribute('inherits-from');
|
|
|
|
render_global_class($parent, $global_types{$parent}) if ($parent and !$seen_class{$parent});
|
|
|
|
|
|
|
|
return if $seen_class{$name};
|
|
|
|
$seen_class{$name}++;
|
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
local $compound_off = 0;
|
2016-10-21 06:52:26 -06:00
|
|
|
$compound_off = $SIZEOF_PTR if ($meta eq 'class-type');
|
2012-05-29 09:28:51 -06:00
|
|
|
$compound_off = sizeof($global_types{$parent}) if $parent;
|
|
|
|
local $current_typename = $rbname;
|
2012-05-29 08:10:33 -06:00
|
|
|
|
2012-04-27 06:13:44 -06:00
|
|
|
my $rtti_name;
|
2012-05-29 09:28:51 -06:00
|
|
|
if ($meta eq 'class-type')
|
|
|
|
{
|
2012-04-27 06:13:44 -06:00
|
|
|
$rtti_name = $type->getAttribute('original-name') ||
|
2012-05-29 09:28:51 -06:00
|
|
|
$type->getAttribute('type-name') ||
|
|
|
|
$name;
|
2012-04-18 10:46:33 -06:00
|
|
|
}
|
|
|
|
|
2012-04-19 17:29:52 -06:00
|
|
|
my $rbparent = ($parent ? rb_ucase($parent) : 'MemHack::Compound');
|
2012-04-06 11:30:58 -06:00
|
|
|
push @lines_rb, "class $rbname < $rbparent";
|
2012-03-26 06:37:18 -06:00
|
|
|
indent_rb {
|
2012-05-29 08:10:33 -06:00
|
|
|
my $sz = sizeof($type);
|
|
|
|
# see comment is sub sizeof ; but gcc has sizeof(cls) aligned
|
2016-10-21 06:52:26 -06:00
|
|
|
$sz = align_field($sz, $SIZEOF_PTR) if $os eq 'linux' and $meta eq 'class-type';
|
2012-05-29 09:28:51 -06:00
|
|
|
push @lines_rb, "sizeof $sz\n";
|
|
|
|
|
|
|
|
push @lines_rb, "rtti_classname :$rtti_name\n" if $rtti_name;
|
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
render_struct_fields($type);
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-03 11:19:58 -06:00
|
|
|
my $vms = $type->findnodes('child::virtual-methods')->[0];
|
2012-10-11 09:51:49 -06:00
|
|
|
if ($vms)
|
|
|
|
{
|
|
|
|
my $voff = render_class_vmethods_voff($parent);
|
|
|
|
render_class_vmethods($vms, $voff);
|
|
|
|
}
|
2012-03-26 06:37:18 -06:00
|
|
|
};
|
2012-04-13 08:17:56 -06:00
|
|
|
push @lines_rb, "end\n";
|
2012-03-26 06:37:18 -06:00
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
sub render_struct_fields {
|
2012-05-29 08:10:33 -06:00
|
|
|
my ($type) = @_;
|
2012-03-26 06:37:18 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
my $isunion = $type->getAttribute('is-union');
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
for my $field ($type->findnodes('child::ld:field'))
|
|
|
|
{
|
2012-04-02 11:00:38 -06:00
|
|
|
my $name = $field->getAttribute('name');
|
|
|
|
$name = $field->getAttribute('ld:anon-name') if (!$name);
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
if (!$name and $field->getAttribute('ld:anon-compound'))
|
|
|
|
{
|
2012-05-29 08:10:33 -06:00
|
|
|
render_struct_fields($field);
|
2012-05-29 09:28:51 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-29 08:10:33 -06:00
|
|
|
$compound_off = align_field($compound_off, get_field_align($field));
|
2012-05-29 09:28:51 -06:00
|
|
|
if ($name)
|
|
|
|
{
|
2012-05-29 08:10:33 -06:00
|
|
|
push @lines_rb, "field(:$name, $compound_off) {";
|
|
|
|
indent_rb {
|
|
|
|
render_item($field);
|
|
|
|
};
|
|
|
|
push @lines_rb, "}";
|
2012-06-25 11:05:50 -06:00
|
|
|
|
2012-06-27 06:52:34 -06:00
|
|
|
render_struct_field_refs($type, $field, $name);
|
2012-05-29 08:10:33 -06:00
|
|
|
}
|
2012-04-17 14:42:23 -06:00
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
$compound_off += sizeof($field) if (!$isunion);
|
2012-03-31 17:33:30 -06:00
|
|
|
}
|
2012-03-26 06:37:18 -06:00
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-06-27 06:52:34 -06:00
|
|
|
# handle generating accessor for xml attributes ref-target, refers-to etc
|
|
|
|
sub render_struct_field_refs {
|
|
|
|
my ($parent, $field, $name) = @_;
|
|
|
|
|
|
|
|
my $reftg = $field->getAttribute('ref-target');
|
|
|
|
|
|
|
|
my $refto = $field->getAttribute('refers-to');
|
|
|
|
render_field_refto($parent, $name, $refto) if ($refto);
|
|
|
|
|
|
|
|
my $meta = $field->getAttribute('ld:meta');
|
|
|
|
my $item = $field->findnodes('child::ld:item')->[0];
|
|
|
|
if ($meta and $meta eq 'container' and $item) {
|
|
|
|
my $itemreftg = $item->getAttribute('ref-target');
|
|
|
|
render_container_reftarget($parent, $item, $name, $itemreftg) if $itemreftg;
|
2012-10-12 03:42:42 -06:00
|
|
|
} elsif ($reftg) {
|
|
|
|
render_field_reftarget($parent, $field, $name, $reftg);
|
2012-06-27 06:52:34 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-25 11:05:50 -06:00
|
|
|
sub render_field_reftarget {
|
|
|
|
my ($parent, $field, $name, $reftg) = @_;
|
|
|
|
|
|
|
|
my $tg = $global_types{$reftg};
|
|
|
|
return if (!$tg);
|
2014-01-04 07:04:56 -07:00
|
|
|
|
|
|
|
my $tgname = "${name}_tg";
|
|
|
|
$tgname =~ s/_id(.?.?)_tg/_tg$1/;
|
|
|
|
|
|
|
|
my $aux = $field->getAttribute('aux-value');
|
|
|
|
if ($aux) {
|
|
|
|
# minimal support (aims is unit.caste_tg)
|
|
|
|
return if $aux !~ /^\$\$\.[^_][\w\.]+$/;
|
|
|
|
$aux =~ s/\$\$\.//;
|
|
|
|
|
|
|
|
for my $codehelper ($tg->findnodes('child::code-helper')) {
|
|
|
|
if ($codehelper->getAttribute('name') eq 'find-instance') {
|
|
|
|
my $helper = $codehelper->textContent;
|
|
|
|
$helper =~ s/\$global/df/;
|
|
|
|
$helper =~ s/\$\$/$aux/;
|
|
|
|
$helper =~ s/\$/$name/;
|
|
|
|
if ($helper =~ /^[\w\.\[\]]+$/) {
|
|
|
|
push @lines_rb, "def $tgname ; $helper ; end";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-25 11:05:50 -06:00
|
|
|
my $tgvec = $tg->getAttribute('instance-vector');
|
|
|
|
return if (!$tgvec);
|
2012-07-04 07:18:36 -06:00
|
|
|
my $idx = $tg->getAttribute('key-field');
|
2012-06-27 06:52:34 -06:00
|
|
|
|
2012-07-03 11:51:52 -06:00
|
|
|
$tgvec =~ s/^\$global/df/;
|
|
|
|
return if $tgvec !~ /^[\w\.]+$/;
|
|
|
|
|
|
|
|
for my $othername (map { $_->getAttribute('name') } $parent->findnodes('child::ld:field')) {
|
|
|
|
$tgname .= '_' if ($othername and $tgname eq $othername);
|
|
|
|
}
|
|
|
|
|
2012-07-04 07:18:36 -06:00
|
|
|
if ($idx) {
|
|
|
|
my $fidx = '';
|
|
|
|
$fidx = ', :' . $idx if ($idx ne 'id');
|
|
|
|
push @lines_rb, "def $tgname ; ${tgvec}.binsearch($name$fidx) ; end";
|
|
|
|
} else {
|
|
|
|
push @lines_rb, "def $tgname ; ${tgvec}[$name] ; end";
|
|
|
|
}
|
|
|
|
|
2012-06-27 06:52:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
sub render_field_refto {
|
|
|
|
my ($parent, $name, $tgvec) = @_;
|
|
|
|
|
|
|
|
$tgvec =~ s/^\$global/df/;
|
|
|
|
$tgvec =~ s/\[\$\]$//;
|
2012-06-25 11:05:50 -06:00
|
|
|
return if $tgvec !~ /^[\w\.]+$/;
|
|
|
|
|
|
|
|
my $tgname = "${name}_tg";
|
2012-06-27 06:52:34 -06:00
|
|
|
$tgname =~ s/_id(.?.?)_tg/_tg$1/;
|
2012-06-25 11:05:50 -06:00
|
|
|
|
2012-06-27 06:52:34 -06:00
|
|
|
for my $othername (map { $_->getAttribute('name') } $parent->findnodes('child::ld:field')) {
|
2012-06-25 11:05:50 -06:00
|
|
|
$tgname .= '_' if ($othername and $tgname eq $othername);
|
|
|
|
}
|
|
|
|
|
|
|
|
push @lines_rb, "def $tgname ; ${tgvec}[$name] ; end";
|
|
|
|
}
|
|
|
|
|
2012-06-27 06:52:34 -06:00
|
|
|
sub render_container_reftarget {
|
|
|
|
my ($parent, $item, $name, $reftg) = @_;
|
|
|
|
|
|
|
|
my $aux = $item->getAttribute('aux-value');
|
|
|
|
return if ($aux); # TODO
|
|
|
|
|
|
|
|
my $tg = $global_types{$reftg};
|
|
|
|
return if (!$tg);
|
|
|
|
my $tgvec = $tg->getAttribute('instance-vector');
|
|
|
|
return if (!$tgvec);
|
2012-07-04 07:18:36 -06:00
|
|
|
my $idx = $tg->getAttribute('key-field');
|
2012-06-27 06:52:34 -06:00
|
|
|
|
|
|
|
$tgvec =~ s/^\$global/df/;
|
|
|
|
return if $tgvec !~ /^[\w\.]+$/;
|
|
|
|
|
|
|
|
my $tgname = "${name}_tg";
|
|
|
|
$tgname =~ s/_id(.?.?)_tg/_tg$1/;
|
|
|
|
|
|
|
|
for my $othername (map { $_->getAttribute('name') } $parent->findnodes('child::ld:field')) {
|
|
|
|
$tgname .= '_' if ($othername and $tgname eq $othername);
|
|
|
|
}
|
|
|
|
|
2012-07-04 07:18:36 -06:00
|
|
|
if ($idx) {
|
|
|
|
my $fidx = '';
|
|
|
|
$fidx = ', :' . $idx if ($idx ne 'id');
|
|
|
|
push @lines_rb, "def $tgname ; $name.map { |i| $tgvec.binsearch(i$fidx) } ; end";
|
|
|
|
} else {
|
|
|
|
push @lines_rb, "def $tgname ; $name.map { |i| ${tgvec}[i] } ; end";
|
|
|
|
}
|
2012-06-27 06:52:34 -06:00
|
|
|
}
|
|
|
|
|
2012-10-11 09:51:49 -06:00
|
|
|
# return the size of the parent's vtables
|
|
|
|
sub render_class_vmethods_voff {
|
|
|
|
my ($name) = @_;
|
|
|
|
|
|
|
|
return 0 if !$name;
|
|
|
|
|
|
|
|
my $type = $global_types{$name};
|
|
|
|
my $parent = $type->getAttribute('inherits-from');
|
|
|
|
|
|
|
|
my $voff = render_class_vmethods_voff($parent);
|
|
|
|
my $vms = $type->findnodes('child::virtual-methods')->[0];
|
|
|
|
|
|
|
|
for my $meth ($vms->findnodes('child::vmethod'))
|
|
|
|
{
|
2016-10-21 06:52:26 -06:00
|
|
|
$voff += $SIZEOF_PTR if $meth->getAttribute('is-destructor') and $os eq 'linux';
|
|
|
|
$voff += $SIZEOF_PTR;
|
2012-10-11 09:51:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return $voff;
|
|
|
|
}
|
|
|
|
|
2012-05-03 10:49:12 -06:00
|
|
|
sub render_class_vmethods {
|
2012-10-11 09:51:49 -06:00
|
|
|
my ($vms, $voff) = @_;
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
for my $meth ($vms->findnodes('child::vmethod'))
|
|
|
|
{
|
2012-05-03 10:49:12 -06:00
|
|
|
my $name = $meth->getAttribute('name');
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
if ($name)
|
|
|
|
{
|
2012-05-03 10:49:12 -06:00
|
|
|
my @argnames;
|
2012-05-10 17:34:03 -06:00
|
|
|
my @argargs;
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
# check if arguments need special treatment (eg auto-convert from symbol to enum value)
|
|
|
|
for my $arg ($meth->findnodes('child::ld:field'))
|
|
|
|
{
|
2012-05-03 10:49:12 -06:00
|
|
|
my $nr = $#argnames + 1;
|
2012-05-10 17:34:03 -06:00
|
|
|
my $argname = lcfirst($arg->getAttribute('name') || "arg$nr");
|
|
|
|
push @argnames, $argname;
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-10 17:34:03 -06:00
|
|
|
if ($arg->getAttribute('ld:meta') eq 'global' and $arg->getAttribute('ld:subtype') eq 'enum') {
|
2012-05-29 09:28:51 -06:00
|
|
|
push @argargs, rb_ucase($arg->getAttribute('type-name')) . ".int($argname)";
|
2012-05-10 17:34:03 -06:00
|
|
|
} else {
|
|
|
|
push @argargs, $argname;
|
|
|
|
}
|
2012-05-03 10:49:12 -06:00
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
# write vmethod ruby wrapper
|
2012-05-03 10:49:12 -06:00
|
|
|
push @lines_rb, "def $name(" . join(', ', @argnames) . ')';
|
|
|
|
indent_rb {
|
2012-05-10 17:34:03 -06:00
|
|
|
my $args = join('', map { ", $_" } @argargs);
|
|
|
|
my $call = "DFHack.vmethod_call(self, $voff$args)";
|
|
|
|
my $ret = $meth->findnodes('child::ret-type')->[0];
|
|
|
|
render_class_vmethod_ret($call, $ret);
|
2012-05-03 10:49:12 -06:00
|
|
|
};
|
|
|
|
push @lines_rb, 'end';
|
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-03 11:19:58 -06:00
|
|
|
# on linux, the destructor uses 2 entries
|
2016-10-21 06:52:26 -06:00
|
|
|
$voff += $SIZEOF_PTR if $meth->getAttribute('is-destructor') and $os eq 'linux';
|
|
|
|
$voff += $SIZEOF_PTR;
|
2012-05-03 10:49:12 -06:00
|
|
|
}
|
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-10 17:34:03 -06:00
|
|
|
sub render_class_vmethod_ret {
|
|
|
|
my ($call, $ret) = @_;
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
if (!$ret)
|
|
|
|
{
|
|
|
|
# method returns void, hide return value
|
2012-05-10 17:34:03 -06:00
|
|
|
push @lines_rb, "$call ; nil";
|
|
|
|
return;
|
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-10 17:34:03 -06:00
|
|
|
my $retmeta = $ret->getAttribute('ld:meta') || '';
|
2012-05-29 09:28:51 -06:00
|
|
|
if ($retmeta eq 'global')
|
|
|
|
{
|
|
|
|
# method returns an enum value: auto-convert to symbol
|
2012-05-10 17:34:03 -06:00
|
|
|
my $retname = $ret->getAttribute('type-name');
|
|
|
|
if ($retname and $global_types{$retname} and
|
2012-05-29 09:28:51 -06:00
|
|
|
$global_types{$retname}->getAttribute('ld:meta') eq 'enum-type')
|
|
|
|
{
|
|
|
|
push @lines_rb, rb_ucase($retname) . ".sym($call)";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-10 17:34:03 -06:00
|
|
|
print "vmethod global nonenum $call\n";
|
|
|
|
push @lines_rb, $call;
|
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
elsif ($retmeta eq 'number')
|
|
|
|
{
|
|
|
|
# raw method call returns an int32, mask according to actual return type
|
2012-05-10 17:34:03 -06:00
|
|
|
my $retsubtype = $ret->getAttribute('ld:subtype');
|
2016-08-05 15:12:07 -06:00
|
|
|
my $retbits = sizeof($ret) * 8;
|
2012-05-10 17:34:03 -06:00
|
|
|
push @lines_rb, "val = $call";
|
2012-05-29 09:28:51 -06:00
|
|
|
if ($retsubtype eq 'bool')
|
|
|
|
{
|
2012-05-10 17:34:03 -06:00
|
|
|
push @lines_rb, "(val & 1) != 0";
|
2012-05-29 09:28:51 -06:00
|
|
|
}
|
|
|
|
elsif ($ret->getAttribute('ld:unsigned'))
|
|
|
|
{
|
|
|
|
push @lines_rb, "val & ((1 << $retbits) - 1)";
|
|
|
|
}
|
|
|
|
elsif ($retbits != 32)
|
|
|
|
{
|
|
|
|
# manual sign extension
|
|
|
|
push @lines_rb, "val &= ((1 << $retbits) - 1)";
|
2012-05-10 17:34:03 -06:00
|
|
|
push @lines_rb, "((val >> ($retbits-1)) & 1) == 0 ? val : val - (1 << $retbits)";
|
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
elsif ($retmeta eq 'pointer')
|
|
|
|
{
|
|
|
|
# method returns a pointer to some struct, create the correct ruby wrapper
|
2012-05-10 17:34:03 -06:00
|
|
|
push @lines_rb, "ptr = $call";
|
|
|
|
push @lines_rb, "class << self";
|
|
|
|
indent_rb {
|
|
|
|
render_item($ret->findnodes('child::ld:item')->[0]);
|
|
|
|
};
|
|
|
|
push @lines_rb, "end._at(ptr) if ptr != 0";
|
2012-05-29 09:28:51 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-10 17:34:03 -06:00
|
|
|
print "vmethod unkret $call\n";
|
|
|
|
push @lines_rb, $call;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-13 08:17:56 -06:00
|
|
|
sub render_global_objects {
|
|
|
|
my (@objects) = @_;
|
|
|
|
my @global_objects;
|
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
local $compound_off = 0;
|
|
|
|
local $current_typename = 'Global';
|
2012-04-13 08:17:56 -06:00
|
|
|
|
2012-05-29 09:28:51 -06:00
|
|
|
# define all globals as 'fields' of a virtual globalobject wrapping the whole address space
|
|
|
|
push @lines_rb, 'class GlobalObjects < MemHack::Compound';
|
2012-04-13 08:17:56 -06:00
|
|
|
indent_rb {
|
2012-05-29 09:28:51 -06:00
|
|
|
for my $obj (@objects)
|
|
|
|
{
|
2012-04-13 08:17:56 -06:00
|
|
|
my $oname = $obj->getAttribute('name');
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
# check if the symbol is defined in xml to avoid NULL deref
|
2012-04-13 08:17:56 -06:00
|
|
|
my $addr = "DFHack.get_global_address('$oname')";
|
2012-04-24 11:07:54 -06:00
|
|
|
push @lines_rb, "addr = $addr";
|
|
|
|
push @lines_rb, "if addr != 0";
|
2012-04-13 08:17:56 -06:00
|
|
|
indent_rb {
|
2012-04-24 11:07:54 -06:00
|
|
|
push @lines_rb, "field(:$oname, addr) {";
|
|
|
|
my $item = $obj->findnodes('child::ld:item')->[0];
|
|
|
|
indent_rb {
|
2012-05-29 08:10:33 -06:00
|
|
|
render_item($item);
|
2012-04-24 11:07:54 -06:00
|
|
|
};
|
|
|
|
push @lines_rb, "}";
|
2012-04-13 08:17:56 -06:00
|
|
|
};
|
2012-04-24 11:07:54 -06:00
|
|
|
push @lines_rb, "end";
|
2012-04-13 08:17:56 -06:00
|
|
|
|
|
|
|
push @global_objects, $oname;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
push @lines_rb, "end";
|
|
|
|
|
2012-05-29 09:28:51 -06:00
|
|
|
# define friendlier accessors, eg df.world -> DFHack::GlobalObjects.new._at(0).world
|
2012-04-13 08:17:56 -06:00
|
|
|
indent_rb {
|
|
|
|
push @lines_rb, "Global = GlobalObjects.new._at(0)";
|
2012-05-29 09:28:51 -06:00
|
|
|
for my $obj (@global_objects)
|
|
|
|
{
|
2012-04-13 08:17:56 -06:00
|
|
|
push @lines_rb, "def self.$obj ; Global.$obj ; end";
|
|
|
|
push @lines_rb, "def self.$obj=(v) ; Global.$obj = v ; end";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-29 09:28:51 -06:00
|
|
|
my %align_cache;
|
|
|
|
my %sizeof_cache;
|
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
sub align_field {
|
|
|
|
my ($off, $fldalign) = @_;
|
|
|
|
my $dt = $off % $fldalign;
|
|
|
|
$off += $fldalign - $dt if $dt > 0;
|
|
|
|
return $off;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_field_align {
|
|
|
|
my ($field) = @_;
|
2016-10-21 06:52:26 -06:00
|
|
|
my $al = $SIZEOF_PTR;
|
2012-05-29 08:10:33 -06:00
|
|
|
my $meta = $field->getAttribute('ld:meta');
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
if ($meta eq 'number') {
|
2016-08-05 15:12:07 -06:00
|
|
|
$al = sizeof($field);
|
2016-10-21 06:52:26 -06:00
|
|
|
# linux aligns int64_t to $SIZEOF_PTR, windows to 8
|
2012-07-03 06:12:32 -06:00
|
|
|
# floats are 4 bytes so no pb
|
2016-10-21 06:52:26 -06:00
|
|
|
$al = 4 if ($al > 4 and (($os eq 'linux' and $arch == 32) or $al != 8));
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($meta eq 'global') {
|
2012-05-29 09:28:51 -06:00
|
|
|
$al = get_global_align($field);
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($meta eq 'compound') {
|
2012-05-29 09:28:51 -06:00
|
|
|
$al = get_compound_align($field);
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($meta eq 'static-array') {
|
|
|
|
my $tg = $field->findnodes('child::ld:item')->[0];
|
|
|
|
$al = get_field_align($tg);
|
|
|
|
} elsif ($meta eq 'bytes') {
|
|
|
|
$al = $field->getAttribute('alignment') || 1;
|
2014-09-24 15:37:25 -06:00
|
|
|
} elsif ($meta eq 'primitive') {
|
|
|
|
my $subtype = $field->getAttribute('ld:subtype');
|
|
|
|
if ($subtype eq 'stl-fstream' and $os eq 'windows') { $al = 8; }
|
2012-05-29 08:10:33 -06:00
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
return $al;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_global_align {
|
|
|
|
my ($field) = @_;
|
|
|
|
|
|
|
|
my $typename = $field->getAttribute('type-name');
|
|
|
|
return $align_cache{$typename} if $align_cache{$typename};
|
|
|
|
|
|
|
|
my $g = $global_types{$typename};
|
|
|
|
|
|
|
|
my $st = $field->getAttribute('ld:subtype') || '';
|
|
|
|
if ($st eq 'bitfield' or $st eq 'enum' or $g->getAttribute('ld:meta') eq 'bitfield-type')
|
|
|
|
{
|
|
|
|
my $base = $field->getAttribute('base-type') || $g->getAttribute('base-type') || 'uint32_t';
|
|
|
|
print "$st type $base\n" if $base !~ /int(\d+)_t/;
|
|
|
|
# dont cache, field->base-type may differ
|
|
|
|
return $1/8;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $al = 1;
|
|
|
|
for my $gf ($g->findnodes('child::ld:field')) {
|
|
|
|
my $fld_al = get_field_align($gf);
|
|
|
|
$al = $fld_al if $fld_al > $al;
|
|
|
|
}
|
|
|
|
$align_cache{$typename} = $al;
|
|
|
|
|
|
|
|
return $al;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_compound_align {
|
|
|
|
my ($field) = @_;
|
|
|
|
|
|
|
|
my $st = $field->getAttribute('ld:subtype') || '';
|
|
|
|
if ($st eq 'bitfield' or $st eq 'enum')
|
|
|
|
{
|
|
|
|
my $base = $field->getAttribute('base-type') || 'uint32_t';
|
2016-08-27 13:24:53 -06:00
|
|
|
if ($base eq 'long') {
|
|
|
|
return $SIZEOF_LONG;
|
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
print "$st type $base\n" if $base !~ /int(\d+)_t/;
|
|
|
|
return $1/8;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $al = 1;
|
|
|
|
for my $f ($field->findnodes('child::ld:field')) {
|
|
|
|
my $fal = get_field_align($f);
|
|
|
|
$al = $fal if $fal > $al;
|
|
|
|
}
|
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
return $al;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub sizeof {
|
|
|
|
my ($field) = @_;
|
|
|
|
my $meta = $field->getAttribute('ld:meta');
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
if ($meta eq 'number') {
|
2016-08-05 15:12:07 -06:00
|
|
|
if ($field->getAttribute('ld:subtype') eq 'long') {
|
|
|
|
return $SIZEOF_LONG;
|
|
|
|
}
|
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
return $field->getAttribute('ld:bits')/8;
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($meta eq 'pointer') {
|
2016-08-05 15:29:24 -06:00
|
|
|
return $SIZEOF_PTR;
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($meta eq 'static-array') {
|
|
|
|
my $count = $field->getAttribute('count');
|
|
|
|
my $tg = $field->findnodes('child::ld:item')->[0];
|
|
|
|
return $count * sizeof($tg);
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($meta eq 'bitfield-type' or $meta eq 'enum-type') {
|
|
|
|
my $base = $field->getAttribute('base-type') || 'uint32_t';
|
|
|
|
print "$meta type $base\n" if $base !~ /int(\d+)_t/;
|
|
|
|
return $1/8;
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($meta eq 'global') {
|
|
|
|
my $typename = $field->getAttribute('type-name');
|
|
|
|
return $sizeof_cache{$typename} if $sizeof_cache{$typename};
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
my $g = $global_types{$typename};
|
|
|
|
my $st = $field->getAttribute('ld:subtype') || '';
|
2012-05-29 09:28:51 -06:00
|
|
|
if ($st eq 'bitfield' or $st eq 'enum' or $g->getAttribute('ld:meta') eq 'bitfield-type')
|
|
|
|
{
|
2012-05-29 08:10:33 -06:00
|
|
|
my $base = $field->getAttribute('base-type') || $g->getAttribute('base-type') || 'uint32_t';
|
|
|
|
print "$st type $base\n" if $base !~ /int(\d+)_t/;
|
|
|
|
return $1/8;
|
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
return sizeof($g);
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
} elsif ($meta eq 'class-type' or $meta eq 'struct-type' or $meta eq 'compound') {
|
|
|
|
return sizeof_compound($field);
|
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($meta eq 'container') {
|
|
|
|
my $subtype = $field->getAttribute('ld:subtype');
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
if ($subtype eq 'stl-vector') {
|
2016-08-07 11:11:17 -06:00
|
|
|
if ($os eq 'linux' or $os eq 'windows') {
|
2016-08-05 15:29:24 -06:00
|
|
|
return ($arch == 64) ? 24 : 12;
|
2012-05-29 08:10:33 -06:00
|
|
|
} else {
|
|
|
|
print "sizeof stl-vector on $os\n";
|
|
|
|
}
|
|
|
|
} elsif ($subtype eq 'stl-bit-vector') {
|
|
|
|
if ($os eq 'linux') {
|
2016-08-05 15:29:24 -06:00
|
|
|
return ($arch == 64) ? 40 : 20;
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($os eq 'windows') {
|
2016-08-07 11:11:17 -06:00
|
|
|
return ($arch == 64) ? 32 : 16;
|
2012-05-29 08:10:33 -06:00
|
|
|
} else {
|
|
|
|
print "sizeof stl-bit-vector on $os\n";
|
|
|
|
}
|
|
|
|
} elsif ($subtype eq 'stl-deque') {
|
|
|
|
if ($os eq 'linux') {
|
2016-08-05 15:29:24 -06:00
|
|
|
return ($arch == 64) ? 80 : 40;
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($os eq 'windows') {
|
2016-08-07 11:11:17 -06:00
|
|
|
return ($arch == 64) ? 40 : 20;
|
2012-05-29 08:10:33 -06:00
|
|
|
} else {
|
|
|
|
print "sizeof stl-deque on $os\n";
|
|
|
|
}
|
|
|
|
} elsif ($subtype eq 'df-linked-list') {
|
2016-08-05 15:29:24 -06:00
|
|
|
return 3 * $SIZEOF_PTR;
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($subtype eq 'df-flagarray') {
|
2016-08-05 15:29:24 -06:00
|
|
|
return 4 + $SIZEOF_PTR;
|
2012-12-04 09:46:13 -07:00
|
|
|
} elsif ($subtype eq 'df-static-flagarray') {
|
|
|
|
return $field->getAttribute('count');
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($subtype eq 'df-array') {
|
2016-08-05 15:29:24 -06:00
|
|
|
return 4 + $SIZEOF_PTR; # XXX 4->2 ?
|
2012-05-29 08:10:33 -06:00
|
|
|
} else {
|
|
|
|
print "sizeof container $subtype\n";
|
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($meta eq 'primitive') {
|
|
|
|
my $subtype = $field->getAttribute('ld:subtype');
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2016-08-05 15:29:24 -06:00
|
|
|
if ($subtype eq 'stl-string') {
|
|
|
|
if ($os eq 'linux') {
|
|
|
|
return ($arch == 64) ? 8 : 4;
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($os eq 'windows') {
|
2016-08-07 11:11:17 -06:00
|
|
|
return ($arch == 64) ? 32 : 24;
|
2012-05-29 08:10:33 -06:00
|
|
|
} else {
|
|
|
|
print "sizeof stl-string on $os\n";
|
|
|
|
}
|
|
|
|
print "sizeof stl-string\n";
|
2016-08-05 15:29:24 -06:00
|
|
|
} elsif ($subtype eq 'stl-fstream') {
|
|
|
|
if ($os eq 'linux') {
|
|
|
|
return 284; # TODO: fix on x64
|
2014-09-24 15:37:25 -06:00
|
|
|
} elsif ($os eq 'windows') {
|
2016-08-07 11:11:17 -06:00
|
|
|
return ($arch == 64) ? 280 : 192;
|
2014-09-24 15:37:25 -06:00
|
|
|
} else {
|
|
|
|
print "sizeof stl-fstream on $os\n";
|
|
|
|
}
|
|
|
|
print "sizeof stl-fstream\n";
|
2012-05-29 08:10:33 -06:00
|
|
|
} else {
|
|
|
|
print "sizeof primitive $subtype\n";
|
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
} elsif ($meta eq 'bytes') {
|
|
|
|
return $field->getAttribute('size');
|
|
|
|
} else {
|
|
|
|
print "sizeof $meta\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-29 09:28:51 -06:00
|
|
|
sub sizeof_compound {
|
|
|
|
my ($field) = @_;
|
|
|
|
|
|
|
|
my $typename = $field->getAttribute('type-name');
|
|
|
|
return $sizeof_cache{$typename} if $typename and $sizeof_cache{$typename};
|
|
|
|
|
|
|
|
my $meta = $field->getAttribute('ld:meta');
|
|
|
|
|
|
|
|
my $st = $field->getAttribute('ld:subtype') || '';
|
|
|
|
if ($st eq 'bitfield' or $st eq 'enum')
|
|
|
|
{
|
|
|
|
my $base = $field->getAttribute('base-type') || 'uint32_t';
|
2016-08-27 13:24:53 -06:00
|
|
|
if ($base eq 'long') {
|
|
|
|
$sizeof_cache{$typename} = $SIZEOF_LONG if $typename;
|
|
|
|
return $SIZEOF_LONG;
|
|
|
|
}
|
2016-10-21 06:52:26 -06:00
|
|
|
print "$st type $base\n" if $base !~ /int(\d+)_t/;
|
|
|
|
$sizeof_cache{$typename} = $1/8 if $typename;
|
|
|
|
return $1/8;
|
2012-05-29 09:28:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($field->getAttribute('is-union'))
|
|
|
|
{
|
|
|
|
my $sz = 0;
|
|
|
|
for my $f ($field->findnodes('child::ld:field'))
|
|
|
|
{
|
|
|
|
my $fsz = sizeof($f);
|
|
|
|
$sz = $fsz if $fsz > $sz;
|
|
|
|
}
|
|
|
|
return $sz;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $parent = $field->getAttribute('inherits-from');
|
|
|
|
my $off = 0;
|
2016-10-21 06:52:26 -06:00
|
|
|
$off = $SIZEOF_PTR if ($meta eq 'class-type');
|
2012-05-29 09:28:51 -06:00
|
|
|
$off = sizeof($global_types{$parent}) if ($parent);
|
|
|
|
|
|
|
|
my $al = 1;
|
2016-10-21 06:52:26 -06:00
|
|
|
$al = $SIZEOF_PTR if ($meta eq 'class-type');
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
for my $f ($field->findnodes('child::ld:field'))
|
|
|
|
{
|
|
|
|
my $fa = get_field_align($f);
|
|
|
|
$al = $fa if $fa > $al;
|
|
|
|
$off = align_field($off, $fa);
|
|
|
|
$off += sizeof($f);
|
|
|
|
}
|
|
|
|
|
|
|
|
# GCC: class a { vtable; char; } ; class b:a { char c2; } -> c2 has offset 5 (Windows MSVC: offset 8)
|
|
|
|
$al = 1 if ($meta eq 'class-type' and $os eq 'linux');
|
|
|
|
$off = align_field($off, $al);
|
|
|
|
$sizeof_cache{$typename} = $off if $typename;
|
|
|
|
|
|
|
|
return $off;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
sub render_item {
|
2012-05-29 08:10:33 -06:00
|
|
|
my ($item) = @_;
|
2012-04-02 11:00:38 -06:00
|
|
|
return if (!$item);
|
|
|
|
|
|
|
|
my $meta = $item->getAttribute('ld:meta');
|
|
|
|
|
|
|
|
my $renderer = $item_renderer{$meta};
|
|
|
|
if ($renderer) {
|
2012-05-29 08:10:33 -06:00
|
|
|
$renderer->($item);
|
2012-03-26 06:37:18 -06:00
|
|
|
} else {
|
2012-04-02 11:00:38 -06:00
|
|
|
print "no render item $meta\n";
|
2012-03-26 06:37:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
sub render_item_global {
|
2012-05-29 08:10:33 -06:00
|
|
|
my ($item) = @_;
|
2012-03-31 17:33:30 -06:00
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
my $typename = $item->getAttribute('type-name');
|
2012-04-13 09:19:53 -06:00
|
|
|
my $subtype = $item->getAttribute('ld:subtype');
|
2012-03-31 17:33:30 -06:00
|
|
|
|
2012-04-13 09:19:53 -06:00
|
|
|
if ($subtype and $subtype eq 'enum') {
|
2012-05-29 08:10:33 -06:00
|
|
|
render_item_number($item);
|
2012-04-13 09:19:53 -06:00
|
|
|
} else {
|
|
|
|
my $rbname = rb_ucase($typename);
|
|
|
|
push @lines_rb, "global :$rbname";
|
|
|
|
}
|
2012-03-31 17:33:30 -06:00
|
|
|
}
|
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
sub render_item_number {
|
2012-05-29 08:10:33 -06:00
|
|
|
my ($item, $classname) = @_;
|
2012-03-31 17:33:30 -06:00
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
my $subtype = $item->getAttribute('ld:subtype');
|
2012-04-27 09:24:15 -06:00
|
|
|
my $meta = $item->getAttribute('ld:meta');
|
2012-04-26 06:16:47 -06:00
|
|
|
my $initvalue = $item->getAttribute('init-value');
|
2012-09-14 13:45:01 -06:00
|
|
|
$initvalue ||= -1 if $item->getAttribute('refers-to') or $item->getAttribute('ref-target');
|
2012-04-26 12:55:52 -06:00
|
|
|
my $typename = $item->getAttribute('type-name');
|
2012-04-27 09:24:15 -06:00
|
|
|
undef $typename if ($meta and $meta eq 'bitfield-type');
|
2012-06-15 13:02:04 -06:00
|
|
|
my $g = $global_types{$typename} if ($typename);
|
2012-04-26 12:55:52 -06:00
|
|
|
$typename = rb_ucase($typename) if $typename;
|
2012-05-29 08:10:33 -06:00
|
|
|
$typename = $classname if (!$typename and $subtype and $subtype eq 'enum'); # compound enum
|
2012-04-26 06:16:47 -06:00
|
|
|
|
|
|
|
$initvalue = 1 if ($initvalue and $initvalue eq 'true');
|
2012-04-26 12:55:52 -06:00
|
|
|
$initvalue = ":$initvalue" if ($initvalue and $typename and $initvalue =~ /[a-zA-Z]/);
|
|
|
|
$initvalue ||= 'nil' if $typename;
|
2012-04-26 06:16:47 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
$subtype = $item->getAttribute('base-type') if (!$subtype or $subtype eq 'bitfield' or $subtype eq 'enum');
|
2012-06-29 03:25:41 -06:00
|
|
|
$subtype ||= $g->getAttribute('base-type') if ($g);
|
2012-04-02 11:00:38 -06:00
|
|
|
$subtype = 'int32_t' if (!$subtype);
|
|
|
|
|
2016-08-05 15:12:07 -06:00
|
|
|
if ($subtype eq 'uint64_t') {
|
|
|
|
push @lines_rb, 'number 64, false';
|
|
|
|
} elsif ($subtype eq 'int64_t') {
|
2012-04-02 11:00:38 -06:00
|
|
|
push @lines_rb, 'number 64, true';
|
|
|
|
} elsif ($subtype eq 'uint32_t') {
|
|
|
|
push @lines_rb, 'number 32, false';
|
|
|
|
} elsif ($subtype eq 'int32_t') {
|
|
|
|
push @lines_rb, 'number 32, true';
|
|
|
|
} elsif ($subtype eq 'uint16_t') {
|
|
|
|
push @lines_rb, 'number 16, false';
|
|
|
|
} elsif ($subtype eq 'int16_t') {
|
|
|
|
push @lines_rb, 'number 16, true';
|
|
|
|
} elsif ($subtype eq 'uint8_t') {
|
|
|
|
push @lines_rb, 'number 8, false';
|
|
|
|
} elsif ($subtype eq 'int8_t') {
|
2013-02-16 18:05:01 -07:00
|
|
|
push @lines_rb, 'number 8, true';
|
2012-04-02 11:00:38 -06:00
|
|
|
} elsif ($subtype eq 'bool') {
|
|
|
|
push @lines_rb, 'number 8, true';
|
2012-06-27 06:52:34 -06:00
|
|
|
$initvalue ||= 'nil';
|
2012-05-29 09:28:51 -06:00
|
|
|
$typename ||= 'BooleanEnum';
|
2016-08-05 15:12:07 -06:00
|
|
|
} elsif ($subtype eq 'long') {
|
|
|
|
push @lines_rb, 'number ' . $SIZEOF_LONG . ', true';
|
2012-04-02 11:00:38 -06:00
|
|
|
} elsif ($subtype eq 's-float') {
|
|
|
|
push @lines_rb, 'float';
|
2012-04-26 06:16:47 -06:00
|
|
|
return;
|
2012-12-04 09:18:09 -07:00
|
|
|
} elsif ($subtype eq 'd-float') {
|
|
|
|
push @lines_rb, 'double';
|
|
|
|
return;
|
2012-03-31 17:33:30 -06:00
|
|
|
} else {
|
2012-04-02 11:00:38 -06:00
|
|
|
print "no render number $subtype\n";
|
2012-04-26 06:16:47 -06:00
|
|
|
return;
|
2012-03-31 17:33:30 -06:00
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-04-26 06:16:47 -06:00
|
|
|
$lines_rb[$#lines_rb] .= ", $initvalue" if ($initvalue);
|
2012-05-10 15:27:42 -06:00
|
|
|
$lines_rb[$#lines_rb] .= ", $typename" if ($typename);
|
2012-03-31 17:33:30 -06:00
|
|
|
}
|
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
sub render_item_compound {
|
2012-05-29 08:10:33 -06:00
|
|
|
my ($item) = @_;
|
2012-03-31 17:33:30 -06:00
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
my $subtype = $item->getAttribute('ld:subtype');
|
2012-04-27 09:59:54 -06:00
|
|
|
|
2012-05-29 08:10:33 -06:00
|
|
|
local $compound_off = 0;
|
|
|
|
my $classname = $current_typename . '_' . rb_ucase($item->getAttribute('ld:typedef-name'));
|
|
|
|
local $current_typename = $classname;
|
2012-04-27 09:59:54 -06:00
|
|
|
|
2012-05-29 09:28:51 -06:00
|
|
|
if (!$subtype || $subtype eq 'bitfield')
|
|
|
|
{
|
2012-04-27 09:59:54 -06:00
|
|
|
push @lines_rb, "compound(:$classname) {";
|
2012-04-02 11:00:38 -06:00
|
|
|
indent_rb {
|
2012-05-29 09:28:51 -06:00
|
|
|
# declare sizeof() only for useful compound, eg the one behind pointers
|
|
|
|
# that the user may want to allocate
|
|
|
|
my $sz = sizeof($item);
|
|
|
|
push @lines_rb, "sizeof $sz\n" if $compound_pointer;
|
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
if (!$subtype) {
|
2012-05-29 09:28:51 -06:00
|
|
|
local $compound_pointer = 0;
|
2012-05-29 08:10:33 -06:00
|
|
|
render_struct_fields($item);
|
2012-04-02 11:00:38 -06:00
|
|
|
} else {
|
|
|
|
render_bitfield_fields($item);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
push @lines_rb, "}"
|
2012-05-29 09:28:51 -06:00
|
|
|
}
|
|
|
|
elsif ($subtype eq 'enum')
|
|
|
|
{
|
2012-05-10 15:27:42 -06:00
|
|
|
push @lines_rb, "class ::DFHack::$classname < MemHack::Enum";
|
2012-04-26 12:55:52 -06:00
|
|
|
indent_rb {
|
|
|
|
# declare constants
|
|
|
|
render_enum_fields($item);
|
|
|
|
};
|
|
|
|
push @lines_rb, "end\n";
|
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
# actual field
|
2012-04-27 09:59:54 -06:00
|
|
|
render_item_number($item, $classname);
|
2012-05-29 09:28:51 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-02 11:00:38 -06:00
|
|
|
print "no render compound $subtype\n";
|
2012-03-31 17:33:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
sub render_item_container {
|
2012-05-29 08:10:33 -06:00
|
|
|
my ($item) = @_;
|
2012-03-26 06:37:18 -06:00
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
my $subtype = $item->getAttribute('ld:subtype');
|
|
|
|
my $rbmethod = join('_', split('-', $subtype));
|
|
|
|
my $tg = $item->findnodes('child::ld:item')->[0];
|
2012-04-25 09:18:24 -06:00
|
|
|
my $indexenum = $item->getAttribute('index-enum');
|
2012-12-04 09:46:13 -07:00
|
|
|
my $count = $item->getAttribute('count');
|
2012-05-29 09:28:51 -06:00
|
|
|
if ($tg)
|
|
|
|
{
|
2012-04-20 10:20:24 -06:00
|
|
|
if ($rbmethod eq 'df_linked_list') {
|
|
|
|
push @lines_rb, "$rbmethod {";
|
|
|
|
} else {
|
2012-05-29 08:10:33 -06:00
|
|
|
my $tglen = sizeof($tg) if $tg;
|
2012-04-20 10:20:24 -06:00
|
|
|
push @lines_rb, "$rbmethod($tglen) {";
|
|
|
|
}
|
2012-04-02 11:00:38 -06:00
|
|
|
indent_rb {
|
2012-05-29 08:10:33 -06:00
|
|
|
render_item($tg);
|
2012-04-02 11:00:38 -06:00
|
|
|
};
|
|
|
|
push @lines_rb, "}";
|
2012-05-29 09:28:51 -06:00
|
|
|
}
|
|
|
|
elsif ($indexenum)
|
|
|
|
{
|
2012-04-25 09:18:24 -06:00
|
|
|
$indexenum = rb_ucase($indexenum);
|
2012-12-04 09:46:13 -07:00
|
|
|
if ($count) {
|
|
|
|
push @lines_rb, "$rbmethod($count, $indexenum)";
|
|
|
|
} else {
|
|
|
|
push @lines_rb, "$rbmethod($indexenum)";
|
|
|
|
}
|
2012-05-29 09:28:51 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-04 09:46:13 -07:00
|
|
|
if ($count) {
|
|
|
|
push @lines_rb, "$rbmethod($count)";
|
|
|
|
} else {
|
|
|
|
push @lines_rb, "$rbmethod";
|
|
|
|
}
|
2012-03-26 06:37:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
sub render_item_pointer {
|
2012-05-29 08:10:33 -06:00
|
|
|
my ($item) = @_;
|
2012-03-31 17:33:30 -06:00
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
my $tg = $item->findnodes('child::ld:item')->[0];
|
2012-05-29 09:28:51 -06:00
|
|
|
my $ary = $item->getAttribute('is-array') || '';
|
|
|
|
|
|
|
|
if ($ary eq 'true') {
|
2012-05-29 08:10:33 -06:00
|
|
|
my $tglen = sizeof($tg) if $tg;
|
2012-04-19 17:29:52 -06:00
|
|
|
push @lines_rb, "pointer_ary($tglen) {";
|
|
|
|
} else {
|
|
|
|
push @lines_rb, "pointer {";
|
|
|
|
}
|
2012-04-02 11:00:38 -06:00
|
|
|
indent_rb {
|
2012-05-29 09:28:51 -06:00
|
|
|
local $compound_pointer = 1;
|
2012-05-29 08:10:33 -06:00
|
|
|
render_item($tg);
|
2012-04-02 11:00:38 -06:00
|
|
|
};
|
|
|
|
push @lines_rb, "}";
|
2012-03-31 17:33:30 -06:00
|
|
|
}
|
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
sub render_item_staticarray {
|
2012-05-29 08:10:33 -06:00
|
|
|
my ($item) = @_;
|
2012-03-31 17:33:30 -06:00
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
my $count = $item->getAttribute('count');
|
|
|
|
my $tg = $item->findnodes('child::ld:item')->[0];
|
2012-05-29 08:10:33 -06:00
|
|
|
my $tglen = sizeof($tg) if $tg;
|
2012-04-25 09:18:24 -06:00
|
|
|
my $indexenum = $item->getAttribute('index-enum');
|
2012-05-29 09:28:51 -06:00
|
|
|
|
2012-04-25 09:18:24 -06:00
|
|
|
if ($indexenum) {
|
|
|
|
$indexenum = rb_ucase($indexenum);
|
2012-05-10 15:27:42 -06:00
|
|
|
push @lines_rb, "static_array($count, $tglen, $indexenum) {";
|
2012-04-25 09:18:24 -06:00
|
|
|
} else {
|
|
|
|
push @lines_rb, "static_array($count, $tglen) {";
|
|
|
|
}
|
2012-04-02 11:00:38 -06:00
|
|
|
indent_rb {
|
2012-05-29 08:10:33 -06:00
|
|
|
render_item($tg);
|
2012-04-02 11:00:38 -06:00
|
|
|
};
|
|
|
|
push @lines_rb, "}";
|
2012-03-31 17:33:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
sub render_item_primitive {
|
2012-05-29 08:10:33 -06:00
|
|
|
my ($item) = @_;
|
2012-03-31 17:33:30 -06:00
|
|
|
|
|
|
|
my $subtype = $item->getAttribute('ld:subtype');
|
|
|
|
if ($subtype eq 'stl-string') {
|
2012-04-02 11:00:38 -06:00
|
|
|
push @lines_rb, "stl_string";
|
2014-09-24 15:37:25 -06:00
|
|
|
} elsif ($subtype eq 'stl-fstream') {
|
2012-03-31 17:33:30 -06:00
|
|
|
} else {
|
2012-04-02 11:00:38 -06:00
|
|
|
print "no render primitive $subtype\n";
|
2012-03-31 17:33:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
sub render_item_bytes {
|
2012-05-29 08:10:33 -06:00
|
|
|
my ($item) = @_;
|
2012-03-26 06:37:18 -06:00
|
|
|
|
2012-04-02 11:00:38 -06:00
|
|
|
my $subtype = $item->getAttribute('ld:subtype');
|
|
|
|
if ($subtype eq 'padding') {
|
|
|
|
} elsif ($subtype eq 'static-string') {
|
2012-09-19 06:25:14 -06:00
|
|
|
my $size = $item->getAttribute('size') || -1;
|
2012-04-02 11:00:38 -06:00
|
|
|
push @lines_rb, "static_string($size)";
|
2012-03-31 17:33:30 -06:00
|
|
|
} else {
|
2012-04-02 11:00:38 -06:00
|
|
|
print "no render bytes $subtype\n";
|
2012-03-31 17:33:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 08:09:29 -06:00
|
|
|
|
2012-05-29 09:28:51 -06:00
|
|
|
|
|
|
|
my $input = $ARGV[0] or die "need input xml";
|
2012-04-03 08:09:29 -06:00
|
|
|
my $output = $ARGV[1] or die "need output file";
|
2012-03-26 06:37:18 -06:00
|
|
|
|
|
|
|
my $doc = XML::LibXML->new()->parse_file($input);
|
|
|
|
$global_types{$_->getAttribute('type-name')} = $_ foreach $doc->findnodes('/ld:data-definition/ld:global-type');
|
|
|
|
|
2012-05-29 09:28:51 -06:00
|
|
|
# render enums first, this allows later code to refer to them directly
|
2012-05-10 15:27:42 -06:00
|
|
|
my @nonenums;
|
2012-05-29 09:28:51 -06:00
|
|
|
for my $name (sort { $a cmp $b } keys %global_types)
|
|
|
|
{
|
2012-03-26 06:37:18 -06:00
|
|
|
my $type = $global_types{$name};
|
|
|
|
my $meta = $type->getAttribute('ld:meta');
|
2012-05-10 15:27:42 -06:00
|
|
|
if ($meta eq 'enum-type') {
|
|
|
|
render_global_enum($name, $type);
|
|
|
|
} else {
|
|
|
|
push @nonenums, $name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-29 09:28:51 -06:00
|
|
|
# render other structs/bitfields/classes
|
|
|
|
for my $name (@nonenums)
|
|
|
|
{
|
2012-05-10 15:27:42 -06:00
|
|
|
my $type = $global_types{$name};
|
|
|
|
my $meta = $type->getAttribute('ld:meta');
|
2012-05-29 08:10:33 -06:00
|
|
|
if ($meta eq 'struct-type' or $meta eq 'class-type') {
|
2012-05-10 15:27:42 -06:00
|
|
|
render_global_class($name, $type);
|
|
|
|
} elsif ($meta eq 'bitfield-type') {
|
|
|
|
render_global_bitfield($name, $type);
|
2012-03-26 06:37:18 -06:00
|
|
|
} else {
|
|
|
|
print "no render global type $meta\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-29 09:28:51 -06:00
|
|
|
# render globals
|
2012-04-13 08:17:56 -06:00
|
|
|
render_global_objects($doc->findnodes('/ld:data-definition/ld:global-object'));
|
|
|
|
|
2012-03-26 06:37:18 -06:00
|
|
|
|
2012-04-03 08:09:29 -06:00
|
|
|
open FH, ">$output";
|
2012-05-29 08:10:33 -06:00
|
|
|
print FH "module DFHack\n";
|
|
|
|
print FH "$_\n" for @lines_rb;
|
|
|
|
print FH "end\n";
|
2012-03-26 06:37:18 -06:00
|
|
|
close FH;
|