From df3615a758a795543440a9b51311669c9fe6d787 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 26 Jul 2012 15:51:30 +0200 Subject: [PATCH] New output mode to generate size (in bytes) of some compound types This will be used by the X10 native code integration. --- Makefile | 3 ++- main.c | 10 +++++++- wrappergen/write_compoundsizes.c | 39 ++++++++++++++++++++++++++++++++ wrappergen/write_compoundsizes.h | 3 +++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 wrappergen/write_compoundsizes.c create mode 100644 wrappergen/write_compoundsizes.h diff --git a/Makefile b/Makefile index 3e8ee4a..6387123 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,8 @@ SOURCES := \ 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) diff --git a/main.c b/main.c index 675247e..ebf4500 100644 --- a/main.c +++ b/main.c @@ -77,6 +77,7 @@ #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" @@ -583,7 +584,8 @@ typedef enum compile_mode_t { CompileAssembleLink, PrintAst, PrintFluffy, - PrintJna + PrintJna, + PrintCompoundSizes, } compile_mode_t; static void usage(const char *argv0) @@ -1290,6 +1292,9 @@ again: } 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 */ @@ -1916,6 +1921,8 @@ int main(int argc, char **argv) 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")) { @@ -2106,6 +2113,7 @@ int main(int argc, char **argv) case PrintAst: case PrintFluffy: case PrintJna: + case PrintCompoundSizes: case PreprocessOnly: case ParseOnly: outname = "-"; diff --git a/wrappergen/write_compoundsizes.c b/wrappergen/write_compoundsizes.c new file mode 100644 index 0000000..4b30bdd --- /dev/null +++ b/wrappergen/write_compoundsizes.c @@ -0,0 +1,39 @@ +#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)); + } + } +} diff --git a/wrappergen/write_compoundsizes.h b/wrappergen/write_compoundsizes.h new file mode 100644 index 0000000..b190012 --- /dev/null +++ b/wrappergen/write_compoundsizes.h @@ -0,0 +1,3 @@ +#include "ast.h" + +void write_compoundsizes(FILE *out, const translation_unit_t *unit); -- 2.20.1