warning.c \
walk.c \
wrappergen/write_fluffy.c \
- wrappergen/write_jna.c
+ wrappergen/write_jna.c \
+ wrappergen/write_compoundsizes.c
OBJECTS = $(SOURCES:%.c=$(BUILDDIR)/%.o)
DEPENDS = $(OBJECTS:%.o=%.d)
#include "adt/array.h"
#include "wrappergen/write_fluffy.h"
#include "wrappergen/write_jna.h"
+#include "wrappergen/write_compoundsizes.h"
#include "revision.h"
#include "warning.h"
#include "help.h"
CompileAssembleLink,
PrintAst,
PrintFluffy,
- PrintJna
+ PrintJna,
+ PrintCompoundSizes,
} compile_mode_t;
static void usage(const char *argv0)
} else if (mode == PrintJna) {
write_jna_decls(out, unit->ast);
break;
+ } else if (mode == PrintCompoundSizes) {
+ write_compoundsizes(out, unit->ast);
+ break;
}
/* build the firm graph */
print_parenthesis = true;
} else if (streq(option, "print-fluffy")) {
mode = PrintFluffy;
+ } else if (streq(option, "print-compound-sizes")) {
+ mode = PrintCompoundSizes;
} else if (streq(option, "print-jna")) {
mode = PrintJna;
} else if (streq(option, "jna-limit")) {
case PrintAst:
case PrintFluffy:
case PrintJna:
+ case PrintCompoundSizes:
case PreprocessOnly:
case ParseOnly:
outname = "-";
--- /dev/null
+#include "type_t.h"
+#include "ast_t.h"
+#include "entity_t.h"
+#include "attribute_t.h"
+#include "write_compoundsizes.h"
+
+void write_compoundsizes(FILE *output, const translation_unit_t *unit)
+{
+ for (const entity_t *entity = unit->scope.entities;
+ entity != NULL; entity = entity->base.next) {
+ if (entity->kind != ENTITY_TYPEDEF)
+ continue;
+
+ type_t *type = skip_typeref(entity->typedefe.type);
+ if (!is_type_compound(type))
+ continue;
+
+ /* see if we have the required attributes */
+ const compound_t *compound = type->compound.compound;
+ bool had_dllexport = false;
+ const char *string = NULL;
+ for (const attribute_t *attrib = compound->attributes;
+ attrib != NULL; attrib = attrib->next) {
+ if (attrib->kind == ATTRIBUTE_GNU_DLLEXPORT)
+ had_dllexport = true;
+ if (attrib->kind == ATTRIBUTE_GNU_DEPRECATED) {
+ const attribute_argument_t *argument = attrib->a.arguments;
+ assert(argument != NULL && argument->kind == ATTRIBUTE_ARGUMENT_EXPRESSION);
+ const expression_t *expr = argument->v.expression;
+ assert(expr->kind == EXPR_STRING_LITERAL);
+ string = expr->string_literal.value.begin;
+ }
+ }
+
+ if (had_dllexport && string != NULL) {
+ fprintf(output, "%s %u\n", string, get_type_size(type));
+ }
+ }
+}