#include "DataDesc/datadesc_private.h"
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(DataDesc,GRAS);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(datadesc,GRAS);
/* FIXME: make this host-dependent using a trick such as UserData*/
gras_set_t *gras_datadesc_set_local=NULL;
gras_datadesc_init(void) {
gras_error_t errcode;
gras_datadesc_type_t *ddt; /* What to add */
- gras_datadesc_type_t *elm; /* element of ddt when needed */
/* only initialize once */
if (gras_datadesc_set_local != NULL)
e_gras_dd_scalar_encoding_float,
NULL, &ddt));
TRYFAIL(gras_datadesc_declare_scalar("double",
- gras_ddt_scalar_float,
+ gras_ddt_scalar_double,
e_gras_dd_scalar_encoding_float,
NULL,&ddt));
- TRYFAIL(gras_datadesc_declare_array_dyn("string",
+ TRYFAIL(gras_datadesc_declare_array_dyn("char[]",
gras_datadesc_by_name("char"),
_strlen_cb,&ddt));
+ TRYFAIL(gras_datadesc_declare_ref("string",
+ gras_datadesc_by_name("char[]"),
+ &ddt));
- // elm=ddt;
- // TRYFAIL(gras_datadesc_declare_ref("string", elm, &ddt));
}
/**
VERB0("Exiting DataDesc");
gras_set_free(&gras_datadesc_set_local);
gras_datadesc_set_local = NULL;
+ DEBUG0("Exited DataDesc");
+}
+
+/**
+ * gras_datadesc_get_name:
+ *
+ * Returns the name of a datadescription (to ease the debug)
+ */
+char *
+gras_datadesc_get_name(gras_datadesc_type_t *ddt) {
+ return ddt->name;
+}
+/**
+ * gras_datadesc_get_id:
+ *
+ * Returns the name of a datadescription (to ease the debug)
+ */
+int
+gras_datadesc_get_id(gras_datadesc_type_t *ddt) {
+ return ddt->code;
+}
+
+/**
+ * gras_datadesc_size:
+ *
+ * Returns the size occuped by data of this type (on the current arch).
+ *
+ */
+int gras_datadesc_size(gras_datadesc_type_t *type) {
+ return type->size[GRAS_THISARCH];
}
+/**
+ * gras_datadesc_type_dump:
+ *
+ * For debugging purpose
+ */
+void gras_datadesc_type_dump(const gras_datadesc_type_t *ddt){
+ int cpt;
+ gras_error_t errcode;
+ printf("DataDesc dump:");
+ if(!ddt) {
+ printf("(null)\n");
+ return;
+ }
+ printf ("%s (ID:%d)\n",ddt->name,ddt->code);
+ printf (" refcounter=%d\n",ddt->refcounter);
+ printf (" category: %s\n",gras_datadesc_cat_names[ddt->category_code]);
+
+ printf (" size[");
+ for (cpt=0; cpt<gras_arch_count; cpt++) {
+ printf("%s%s%ld%s",
+ cpt>0?", ":"",
+ cpt == GRAS_THISARCH ? "*":"",
+ ddt->size[cpt],
+ cpt == GRAS_THISARCH ? "*":"");
+ }
+ printf ("]\n");
+
+ printf (" alignment[");
+ for (cpt=0; cpt<gras_arch_count; cpt++) {
+ printf("%s%s%ld%s",
+ cpt>0?", ":"",
+ cpt == GRAS_THISARCH ? "*":"",
+ ddt->alignment[cpt],
+ cpt == GRAS_THISARCH ? "*":"");
+ }
+ printf ("]\n");
+
+ printf (" aligned_size[");
+ for (cpt=0; cpt<gras_arch_count; cpt++) {
+ printf("%s%s%ld%s",
+ cpt>0?", ":"",
+ cpt == GRAS_THISARCH ? "*":"",
+ ddt->aligned_size[cpt],
+ cpt == GRAS_THISARCH ? "*":"");
+ }
+ printf ("]\n");
+ if (ddt->category_code == e_gras_datadesc_type_cat_struct) {
+ gras_dd_cat_struct_t struct_data;
+ gras_dd_cat_field_t *field;
+ gras_datadesc_type_t *sub_type;
+
+ struct_data = ddt->category.struct_data;
+ gras_dynar_foreach(struct_data.fields, cpt, field) {
+ printf(">>> Dump field #%d (%s) (offset=%ld)\n",
+ cpt,field->name,field->offset[GRAS_THISARCH]);
+ errcode=gras_datadesc_by_id(field->code, &sub_type);
+ if (errcode != no_error) {
+ ERROR4("Got %s while searching for the sub type %d, #%d of %s",
+ gras_error_name(errcode),field->code,cpt,ddt->name);
+ gras_abort();
+ }
+ gras_datadesc_type_dump(sub_type);
+ printf("<<< end dump field #%d (%s)\n",cpt,field->name);
+ }
+ }
+ fflush(stdout);
+}