OpenMPI  0.1.1
vt_libwrapgen.h
1 /**
2  * VampirTrace
3  * http://www.tu-dresden.de/zih/vampirtrace
4  *
5  * Copyright (c) 2005-2012, ZIH, TU Dresden, Federal Republic of Germany
6  *
7  * Copyright (c) 1998-2005, Forschungszentrum Juelich, Juelich Supercomputing
8  * Centre, Federal Republic of Germany
9  *
10  * See the file COPYING in the package base directory for details
11  **/
12 
13 #ifndef _VT_LIBWRAPGEN_H_
14 #define _VT_LIBWRAPGEN_H_
15 
16 #include "vt_libwrapgen_defs.h"
17 #include "vt_libwrapgen_filter.h"
18 #include "vt_libwrapgen_parser.h"
19 
20 #include "vt_inttypes.h"
21 
22 #include <fstream>
23 #include <map>
24 #include <string>
25 #include <vector>
26 
27 #include <limits.h>
28 #ifndef PATH_MAX
29 # ifdef _POSIX_PATH_MAX
30 # define PATH_MAX _POSIX_PATH_MAX
31 # else // _POSIX_PATH_MAX
32 # define PATH_MAX 256
33 # endif // _POSIX_PATH_MAX
34 #endif // PATH_MAX
35 
36 // typedef for generator modes
37 //
38 typedef enum
39 {
40  MODE_GENSRC, // generates wrapper source file
41  MODE_BUILDLIB // builds wrapper library from generated source file
42 } GenModeT;
43 
44 // data structure for program parameters
45 //
46 struct ParamsS
47 {
48  ParamsS()
49  : output_dir("."),
50  verbose_level(1), mode(MODE_GENSRC),
51  g_output_srcfile(VT_LIBWRAPGEN_DEFAULT_OUTPUT_SRC_FILE),
52  g_cpp_cmd(VT_LIBWRAPGEN_DEFAULT_CPP),
53  g_use_cpp(true), g_keep_cpp_file(false),
54  b_output_libprefix(VT_LIBWRAPGEN_DEFAULT_OUTPUT_LIB_PREFIX),
55  b_libtool_cmd(""),
56  b_cc_cmd(VT_LIBWRAPGEN_DEFAULT_CC),
57  b_cc_flags(VT_LIBWRAPGEN_DEFAULT_CFLAGS),
58  b_shared(false), b_static(false) {}
59 
60  // whole command line
61  std::string command_line;
62 
63  // output directory
64  std::string output_dir;
65 
66  // command line parameters
67  //
68 
69  // general
70  uint32_t verbose_level;
71  GenModeT mode;
72 
73  // generate
74  bool g_progress;
75  std::string g_output_srcfile;
76  std::string g_input_filtfile;
77  std::string g_group;
78  std::vector<std::string> g_input_headers;
79  std::vector<std::string> g_allowed_sysheaders;
80  std::vector<std::string> g_shlibs;
81  // CTool
82  std::string g_cpp_cmd;
83  std::string g_cpp_flags;
84  std::string g_cpp_dir;
85  bool g_use_cpp;
86  bool g_keep_cpp_file;
87 
88  // build
89  std::string b_output_libprefix;
90  std::string b_input_srcfile;
91  std::string b_libtool_cmd;
92  std::string b_libtool_flags;
93  std::string b_cc_cmd;
94  std::string b_cc_flags;
95  std::string b_ld_cmd;
96  std::string b_ld_flags;
97  std::string b_libs;
98  bool b_shared;
99  bool b_static;
100 
101 };
102 
103 // Generator class
104 //
106 {
107  friend class ParserC;
108 
109 public:
110 
111  // contructor
112  GeneratorC();
113 
114  // destructor
115  ~GeneratorC();
116 
117  // generate library wrapper source file
118  bool genSource( void );
119 
120  // build wrapper library from generated source file
121  bool buildLib( void );
122 
123 private:
124 
125  // data structure for a function to be generated
126  //
127  struct FuncS
128  {
129  std::string name;
130  std::string rettype;
131 
132  struct LocS
133  {
134  std::string file;
135  uint32_t line;
136  } loc;
137 
138  struct ArgS
139  {
140  std::string name;
141  std::string type;
142  std::string type_base;
143  std::string type_before;
144  std::string type_after;
145  };
146  std::vector<ArgS> args;
147 
148  bool noret;
149  };
150 
151  // write head of wrapper source file
152  void writeHead( void );
153 
154  // write wrapper function to source file
155  void writeFunction( const FuncS& func );
156 
157  // remove a non-empty directory (like 'rm -rf')
158  bool removeDir( const std::string& path );
159 
160  // pointer to instance of class Filter
161  FilterC* m_filter;
162 
163  // pointer to instance of class Parser
164  ParserC* m_parser;
165 
166  // output file stream of wrapper source file
167  std::ofstream m_outputStream;
168 
169  // map of already generated functions
170  std::map<std::string, bool> genFuncs;
171 
172 };
173 
174 extern void VPrint( uint8_t level, const char * fmt, ... );
175 
176 // global variables
177 //
178 
179 // name of program's executable
180 extern const std::string ExeName;
181 
182 // program parameters
183 extern ParamsS Params;
184 
185 // instance of class Generator
186 extern GeneratorC* theGenerator;
187 
188 #endif // _VT_LIBWRAPGEN_H_
Definition: vt_libwrapgen.h:105
Definition: datastructs.h:41
Definition: vt_libwrapgen.h:138
Definition: vt_dyn.h:53
VampirTrace http://www.tu-dresden.de/zih/vampirtrace.
Definition: vt_libwrapgen_filter.h:26
VampirTrace http://www.tu-dresden.de/zih/vampirtrace.
Definition: vt_libwrapgen_parser.h:20
Definition: vt_libwrapgen.h:132