Branch data Line data Source code
1 : : // -*- C++ -*-
2 : : // Copyright (C) 2005, 2009 Red Hat Inc.
3 : : //
4 : : // This file is part of systemtap, and is free software. You can
5 : : // redistribute it and/or modify it under the terms of the GNU General
6 : : // Public License (GPL); either version 2, or (at your option) any
7 : : // later version.
8 : :
9 : : #ifndef TRANSLATE_H
10 : : #define TRANSLATE_H
11 : :
12 : : #include "staptree.h"
13 : : #include "parse.h"
14 : : #include <iostream>
15 : : #include <fstream>
16 : : #include <string>
17 : :
18 : :
19 : : // ------------------------------------------------------------------------
20 : :
21 : : // Output context for systemtap translation, intended to allow
22 : : // pretty-printing.
23 : : class translator_output
24 : : {
25 : : char *buf;
26 : : std::ofstream* o2;
27 : : std::ostream& o;
28 : : unsigned tablevel;
29 : :
30 : : public:
31 : : std::string filename;
32 : :
33 : : translator_output (std::ostream& file);
34 : : translator_output (const std::string& filename, size_t bufsize = 8192);
35 : : ~translator_output ();
36 : :
37 : : std::ostream& newline (int indent = 0);
38 : : void indent (int indent = 0);
39 [ - + ]: 9153 : void assert_0_indent () { o << std::flush; assert (tablevel == 0); }
40 : : std::ostream& line();
41 : :
42 : 155187 : std::ostream::pos_type tellp() { return o.tellp(); }
43 : 11624 : std::ostream& seekp(std::ostream::pos_type p) { return o.seekp(p); }
44 : : };
45 : :
46 : :
47 : : // An unparser instance is in charge of emitting code for generic
48 : : // probe bodies, functions, globals.
49 : 645 : struct unparser
50 : : {
51 [ - + ]: 645 : virtual ~unparser () {}
52 : :
53 : : virtual void emit_common_header () = 0;
54 : : // #include<...>
55 : : //
56 : : // #define MAXNESTING nnn
57 : : // #define MAXCONCURRENCY mmm
58 : : // #define MAXSTRINGLEN ooo
59 : : //
60 : : // enum session_state_t {
61 : : // starting, begin, running, suspended, errored, ending, ended
62 : : // };
63 : : // static atomic_t session_state;
64 : : //
65 : : // struct context {
66 : : // unsigned errorcount;
67 : : // unsigned busy;
68 : : // ...
69 : : // } context [MAXCONCURRENCY];
70 : :
71 : : // struct {
72 : : virtual void emit_global (vardecl* v) = 0;
73 : : // TYPE s_NAME; // NAME is prefixed with "s_" to avoid kernel id collisions
74 : : // rwlock_t s_NAME_lock;
75 : : // } global = {
76 : : virtual void emit_global_init (vardecl* v) = 0;
77 : : // };
78 : :
79 : : virtual void emit_global_param (vardecl* v) = 0;
80 : : // module_param_... -- at end of file
81 : :
82 : : virtual void emit_functionsig (functiondecl* v) = 0;
83 : : // static void function_NAME (context* c);
84 : :
85 : : virtual void emit_module_init () = 0;
86 : : virtual void emit_module_refresh () = 0;
87 : : virtual void emit_module_exit () = 0;
88 : : // startup, probe refresh/activation, shutdown
89 : :
90 : : virtual void emit_function (functiondecl* v) = 0;
91 : : // void function_NAME (struct context* c) {
92 : : // ....
93 : : // }
94 : :
95 : : virtual void emit_probe (derived_probe* v) = 0;
96 : : // void probe_NUMBER (struct context* c) {
97 : : // ... lifecycle
98 : : // ....
99 : : // }
100 : : // ... then call over to the derived_probe's emit_probe_entries() fn
101 : :
102 : : // The following helper functions must be used by any code-generation
103 : : // infrastructure outside this file to properly mangle identifiers
104 : : // appearing in the final code:
105 : : virtual std::string c_localname (const std::string& e, bool mangle_oldstyle = false) = 0;
106 : : virtual std::string c_globalname (const std::string &e) = 0;
107 : : virtual std::string c_funcname (const std::string &e) = 0;
108 : : };
109 : :
110 : :
111 : : // Preparation done before checking the script cache, especially
112 : : // anything that might affect the hashed name.
113 : : int prepare_translate_pass (systemtap_session& s);
114 : :
115 : : int translate_pass (systemtap_session& s);
116 : :
117 : : #endif // TRANSLATE_H
118 : :
119 : : /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
|