[GCC-XML] pragmas, preprocessor
Thomas Heller
theller at python.net
Thu Sep 23 13:52:18 EDT 2004
Brad King <brad.king at kitware.com> writes:
> Thomas Heller wrote:
>> First tests show that this patch seems to do what I want.
>> Now that I've been playing with this stuff, I'll think about what I need
>> further;-)
> > + fprintf (xdi->file, " align=\"%d\"", TYPE_ALIGN(rt));
> > +
>
> This looks like a good start. However, it may not solve your
> problem. Unless pragmas are actually given I wouldn't be surprised if
> GCC's parser produced different alignments than the actual binaries
> from MSVC would have for a structure. You may not be able to get away
> from the approach of compiling small programs with the original
> compiler.
As far as I can tell, it works now. The patch generated 'offset=...'
attributes for structure fields, and 'size=...' and 'align=...'
attributes for structures. 'size' and 'offset' are measured in bits,
'align' is measured in bytes.
I'm able to parse <windows.h> into xml, and create a C program full of
asserts like these:
assert(sizeof(DLGITEMTEMPLATE) == 18);
assert(offsetof(DLGITEMTEMPLATE, style) == 0);
assert(offsetof(DLGITEMTEMPLATE, dwExtendedStyle) == 4);
assert(offsetof(DLGITEMTEMPLATE, x) == 8);
assert(offsetof(DLGITEMTEMPLATE, y) == 10);
assert(offsetof(DLGITEMTEMPLATE, cx) == 12);
assert(offsetof(DLGITEMTEMPLATE, cy) == 14);
assert(offsetof(DLGITEMTEMPLATE, id) == 16);
This program compiles and works (1300 structures, more than 8000
asserts), apart from one problem. This structure gives the incorrect
size (4 instead of 8):
struct {
int a;
struct U {
int b;
};
} X;
Changing the definition to either this
struct {
int a;
struct U {
int b;
} u;
} X;
or this
struct {
int a;
struct {
int b;
};
} X;
gives the correct results. I'm not sure the first definition is
valid C - but it is in MS header files (objidl.h, struct _userSTGMEDIUM).
Thomas
Index: xml.c
===================================================================
RCS file: /cvsroot/GCC_XML/gccxml/GCC/gcc/cp/xml.c,v
retrieving revision 1.89
diff -c -r1.89 xml.c
*** xml.c 29 Jul 2004 12:09:53 -0000 1.89
--- xml.c 23 Sep 2004 17:41:57 -0000
***************
*** 1322,1327 ****
--- 1322,1338 ----
{
xml_print_type_attribute (xdi, TREE_TYPE (fd), dn->complete);
}
+ {
+ tree tree_byte_ofs = DECL_FIELD_OFFSET(fd);
+ tree tree_bit_ofs = DECL_FIELD_BIT_OFFSET(fd);
+ if (tree_byte_ofs && host_integerp(tree_byte_ofs, 1)
+ && tree_bit_ofs && host_integerp(tree_bit_ofs, 1))
+ {
+ unsigned HOST_WIDE_INT bit_ofs = tree_low_cst(tree_bit_ofs, 1);
+ unsigned HOST_WIDE_INT byte_ofs = tree_low_cst(tree_byte_ofs, 1);
+ fprintf(xdi->file, " offset=\"%u\"", byte_ofs * 8 + bit_ofs);
+ }
+ }
xml_print_context_attribute (xdi, fd);
xml_print_mangled_attribute (xdi, fd);
xml_print_mutable_attribute(xdi, fd);
***************
*** 1363,1368 ****
--- 1374,1390 ----
xml_print_artificial_attribute (xdi, TYPE_NAME (rt));
xml_print_attributes_attribute (xdi, TYPE_ATTRIBUTES(rt), 0);
+ {
+ tree size_tree = TYPE_SIZE(rt);
+ if (size_tree && host_integerp (size_tree, 1))
+ {
+ unsigned int size = tree_low_cst(size_tree, 1);
+ fprintf (xdi->file, " size=\"%u\"", size);
+ }
+ }
+
+ fprintf (xdi->file, " align=\"%d\"", TYPE_ALIGN(rt));
+
if (dn->complete && COMPLETE_TYPE_P (rt))
{
fprintf (xdi->file, " members=\"");
More information about the gccxml
mailing list