/libsrc/veclib/obj_args.c

https://gitlab.com/oytunistrator/QuIP · C · 203 lines · 159 code · 28 blank · 16 comment · 33 complexity · a7f7d36ae116dd70141d5f403c956331 MD5 · raw file

  1. #include "quip_config.h"
  2. #ifdef HAVE_STRING_H
  3. #include <string.h>
  4. #endif
  5. #include "quip_prot.h"
  6. #include "veclib/vecgen.h"
  7. #include "nvf.h"
  8. #include "warn.h" // advise
  9. const char *type_strings[N_ARGSET_PRECISIONS]={
  10. "byte", "short", "int32", "int64", "float", "double",
  11. "u_byte", "u_short", "uint32", "uint64",
  12. "u_byte/short", "short/byte", "u_short/long", "float/double", "bitmap"
  13. };
  14. /* This version takes a buffer, so it can be used by different threads simultaneously */
  15. void private_show_obj_args(QSP_ARG_DECL char *buf, const Vec_Obj_Args *oap, void (*report_func)(QSP_ARG_DECL const char *))
  16. {
  17. int i;
  18. if( OA_DEST(oap) != NO_OBJ ){
  19. sprintf(buf,"Destination object: %s",OBJ_NAME( OA_DEST(oap) ) );
  20. (*report_func)(DEFAULT_QSP_ARG buf);
  21. longlist(QSP_ARG OA_DEST(oap) );
  22. }
  23. for(i=0;i<MAX_N_ARGS; i++){
  24. if( OA_SRC_OBJ(oap,i) != NO_OBJ ){
  25. sprintf(buf,"Source object %d: %s",i+1,OBJ_NAME( OA_SRC_OBJ(oap,i) ) );
  26. (*report_func)(DEFAULT_QSP_ARG buf);
  27. longlist(QSP_ARG OA_SRC_OBJ(oap,i) );
  28. }
  29. }
  30. for(i=0;i<MAX_RETSCAL_ARGS; i++){
  31. if( OA_SCLR_OBJ(oap,i) != NO_OBJ ){
  32. sprintf(buf,"Scalar object %d: %s",i+1,OBJ_NAME( OA_SCLR_OBJ(oap,i) ) );
  33. (*report_func)(DEFAULT_QSP_ARG buf);
  34. }
  35. }
  36. for(i=0;i<MAX_SRCSCAL_ARGS; i++){
  37. if( OA_SVAL(oap,i) != NULL ){
  38. prec_t prec;
  39. char msgbuf[LLEN];
  40. prec = PREC_FOR_ARGSET( OA_ARGSPREC(oap) );
  41. //fprintf(stderr,"formatting as float: %g\n",*((float *)OA_SVAL(oap,i)) );
  42. if( prec != PREC_NONE ){
  43. format_scalar_value(QSP_ARG msgbuf,(void *)OA_SVAL(oap,i),prec_for_code(prec));
  44. }
  45. else strcpy(msgbuf,"(invalid precision)");
  46. sprintf(buf,"Scalar value at addr 0x%lx = %s",
  47. (int_for_addr)OA_SVAL(oap,i),msgbuf);
  48. (*report_func)(DEFAULT_QSP_ARG buf);
  49. /* argset precision is not the same as regular precision? */
  50. }
  51. }
  52. if( /* OA_ARGSPREC(oap) >= 0 && */ OA_ARGSPREC(oap) < N_ARGSET_PRECISIONS ){
  53. sprintf(buf,"\targsprec: %s (%d)",type_strings[ OA_ARGSPREC(oap) ], OA_ARGSPREC(oap) );
  54. (*report_func)(DEFAULT_QSP_ARG buf);
  55. } else if( OA_ARGSPREC(oap) == INVALID_ARGSET_PREC ){
  56. (*report_func)(DEFAULT_QSP_ARG "\targsprec not set");
  57. } else {
  58. sprintf(buf,"\targsprec: garbage value (%d)", OA_ARGSPREC(oap) );
  59. (*report_func)(DEFAULT_QSP_ARG buf);
  60. }
  61. if( /* OA_ARGSTYPE(oap) >= 0 && */ OA_ARGSTYPE(oap) < N_ARGSET_TYPES ){
  62. sprintf(buf,"\targstype: %s (%d)",argset_type_name[OA_ARGSTYPE(oap)],OA_ARGSTYPE(oap));
  63. (*report_func)(DEFAULT_QSP_ARG buf);
  64. } else if( OA_ARGSTYPE(oap) == INVALID_ARGSET_TYPE ){
  65. (*report_func)(DEFAULT_QSP_ARG "\targstype not set");
  66. } else {
  67. sprintf(buf,"\targstype: garbage value (%d)",OA_ARGSTYPE(oap));
  68. (*report_func)(DEFAULT_QSP_ARG buf);
  69. }
  70. /* BUG uninitialized functype generates garbage values */
  71. if( OA_FUNCTYPE(oap) == -1 ){
  72. (*report_func)(DEFAULT_QSP_ARG "\tfunctype not set");
  73. } else {
  74. argset_prec ap;
  75. //prec_t p;
  76. int dt;
  77. const char *ap_string;
  78. /* these are reported, but not used!?!? */
  79. ap = (argset_prec) (OA_FUNCTYPE(oap) % N_ARGSET_PRECISIONS);
  80. //ap = ARGSET_PREC(p);
  81. dt = 1 + OA_FUNCTYPE(oap) / N_ARGSET_PRECISIONS;
  82. /* BUG (just ugly and easy to break) this code relies on the argset precisions
  83. * being in the same order as the data object machine precisions,
  84. * but without the null precision at 0.
  85. *
  86. * Worse than that, this is only good for the simple machine precisions.
  87. * The mixed types and bit precision don't correspond to prec codes...
  88. */
  89. if( ap < (N_MACHINE_PRECS-1) ){
  90. ap_string=NAME_FOR_PREC_CODE(ap+1);
  91. } else {
  92. switch(ap){
  93. case BYIN_ARGS: ap_string="byte/int16"; break;
  94. case INBY_ARGS: ap_string="int16/byte"; break;
  95. case INDI_ARGS: ap_string="int16/int32"; break;
  96. case SPDP_ARGS: ap_string="float/double"; break;
  97. case BIT_ARGS: ap_string="bit"; break;
  98. #ifdef CAUTIOUS
  99. default:
  100. NWARN("CAUTIOUS: private_show_obj_args: bad argset precision!?");
  101. ap_string="(invalid)";
  102. break;
  103. #endif /* CAUTIOUS */
  104. }
  105. }
  106. sprintf(buf,"\tfunctype: %d (0x%x), argset_prec = %s (%d), argset type = %d",
  107. OA_FUNCTYPE(oap),OA_FUNCTYPE(oap),
  108. ap_string, ap,dt);
  109. (*report_func)(DEFAULT_QSP_ARG buf);
  110. }
  111. } // end private_show_obj_args
  112. void show_obj_args(QSP_ARG_DECL const Vec_Obj_Args *oap)
  113. {
  114. private_show_obj_args(QSP_ARG ERROR_STRING,oap,_advise);
  115. }
  116. void set_obj_arg_flags(Vec_Obj_Args *oap)
  117. {
  118. SET_OA_ARGSPREC(oap, ARGSET_PREC( OBJ_PREC( OA_DEST(oap) ) ) );
  119. if( IS_COMPLEX(OA_DEST(oap)) )
  120. OA_ARGSTYPE(oap) = COMPLEX_ARGS;
  121. else
  122. OA_ARGSTYPE(oap) = REAL_ARGS;
  123. SET_OA_FUNCTYPE(oap , FUNCTYPE_FOR( OA_ARGSPREC(oap),OA_ARGSTYPE(oap)) );
  124. //TELL_FUNCTYPE( OA_ARGSPREC(oap),OA_ARGSTYPE(oap))
  125. }
  126. void clear_obj_args(Vec_Obj_Args *oap)
  127. {
  128. #ifdef HAVE_MEMSET
  129. memset(oap,0,sizeof(Vec_Obj_Args));
  130. #else // ! HAVE_MEMSET
  131. unsigned char *p;
  132. int n;
  133. p = (unsigned char *) oap;
  134. n = sizeof(Vec_Obj_Args);
  135. while(n--)
  136. *p++ = 0;
  137. #endif // ! HAVE_MEMSET
  138. // These fields have non-null initial values...
  139. SET_OA_ARGSPREC(oap, INVALID_ARGSET_PREC );
  140. SET_OA_ARGSTYPE(oap, INVALID_ARGSET_TYPE);
  141. SET_OA_FUNCTYPE(oap, -1);
  142. }
  143. const char *name_for_argsprec(argset_prec t)
  144. {
  145. switch(t){
  146. case BY_ARGS: return "byte"; break;
  147. case IN_ARGS: return "short"; break;
  148. case DI_ARGS: return "int32"; break;
  149. case LI_ARGS: return "int64"; break;
  150. case SP_ARGS: return "float"; break;
  151. case DP_ARGS: return "double"; break;
  152. case UBY_ARGS: return "u_byte"; break;
  153. case UIN_ARGS: return "u_short"; break;
  154. case UDI_ARGS: return "uint32"; break;
  155. case ULI_ARGS: return "uint64"; break;
  156. case BYIN_ARGS: return "byte/short"; break;
  157. case INBY_ARGS: return "short/byte"; break;
  158. case INDI_ARGS: return "short/int32"; break;
  159. case SPDP_ARGS: return "float/double"; break;
  160. case BIT_ARGS: return "bit"; break;
  161. default: return "invalid"; break;
  162. }
  163. }
  164. const char *name_for_argtype(argset_type t)
  165. {
  166. switch(t){
  167. case UNKNOWN_ARGS: return "unknown"; break;
  168. case REAL_ARGS: return "real"; break;
  169. case COMPLEX_ARGS: return "complex"; break;
  170. case MIXED_ARGS: return "real/complex"; break;
  171. case QUATERNION_ARGS: return "quaternion"; break;
  172. case QMIXED_ARGS: return "real/quaternion"; break;
  173. default: return "invalid"; break;
  174. }
  175. }