HPCToolkit
lush-support.c
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // File:
50 // $HeadURL$
51 //
52 // Purpose:
53 // LUSH: Logical Unwind Support for HPCToolkit
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 // Author:
59 // Nathan Tallent, Rice University.
60 //
61 //***************************************************************************
62 
63 //************************* System Include Files ****************************
64 
65 #include <stdlib.h>
66 #include <stdio.h>
67 #include <string.h>
68 #include <errno.h>
69 #include <inttypes.h>
70 
71 //*************************** User Include Files ****************************
72 
73 #include <include/uint.h>
74 
75 #include "lush-support.h"
76 
77 //*************************** Forward Declarations **************************
78 
79 //***************************************************************************
80 //
81 //***************************************************************************
82 
84 
85 const char*
87 {
88  switch (as) {
89  case LUSH_ASSOC_NULL : return "NULL";
90  case LUSH_ASSOC_1_to_0: return "1-to-0";
91  case LUSH_ASSOC_1_to_1: return "1-to-1";
92  case LUSH_ASSOC_M_to_1: return "M-to-1";
93  case LUSH_ASSOC_1_to_M: return "1-to-M";
94  case LUSH_ASSOC_0_to_0: return "0-to-0";
95  default: return "ERROR!"; // FIXME: DIAG_assert
96  }
97 }
98 
99 
100 const char*
102 {
103  // INVARIANT: str must have at least LUSH_ASSOC_INFO_STR_MIN_LEN slots
104 
105  lush_assoc_t as = as_info.u.as;
106  unsigned len = as_info.u.len;
107 
108  const char* as_str = lush_assoc_tostr(as);
109  snprintf(str, LUSH_ASSOC_INFO_STR_MIN_LEN, "%s (%u)", as_str, len);
110  str[LUSH_ASSOC_INFO_STR_MIN_LEN - 1] = '\0';
111 
112  return str;
113 }
114 
115 //***************************************************************************
116 //
117 //***************************************************************************
118 
120 
121 const char*
122 lush_lip_sprintf(char* str, const lush_lip_t* x)
123 {
124  str[0] = '\0';
125 
126  if (x) {
127  int num;
128  char* p = str;
129  for (int i = 0; i < LUSH_LIP_DATA8_SZ; ++i) {
130  if (i != 0) {
131  sprintf(p, " ");
132  p++;
133  }
134  num = sprintf(p, "0x%"PRIx64, x->data8[i]);
135  p += num;
136  }
137  }
138 
139  return str;
140 }
141 
142 #if 0
143 void
144 lush_lip_fprint(FILE* fs, lush_lip_t* x);
145 {
146  if (x) {
147  for (int i = 0; i < LUSH_LIP_DATA8_SZ; ++i) {
148  fprintf(fs, " %"PRIx64, x->data8[i]);
149  }
150  }
151 }
152 #endif
#define LUSH_LIP_DATA8_SZ
Definition: lush-support.h:309
struct lush_assoc_info_u::lush_assoc_info_s u
lush_assoc_info_t lush_assoc_info_NULL
Definition: lush-support.c:83
const char * lush_assoc_info_sprintf(char *str, lush_assoc_info_t as_info)
Definition: lush-support.c:101
const char * lush_lip_sprintf(char *str, const lush_lip_t *x)
Definition: lush-support.c:122
lush_lip_t lush_lip_NULL
Definition: lush-support.c:119
enum lush_assoc lush_assoc_t
Definition: lush-support.h:164
const char * lush_assoc_tostr(lush_assoc_t as)
Definition: lush-support.c:86
#define LUSH_ASSOC_INFO_STR_MIN_LEN
Definition: lush-support.h:295
uint64_t data8[LUSH_LIP_DATA8_SZ]
Definition: lush-support.h:312