1 : // -*- C++ -*-
2 : // Copyright (C) 2005 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 :
17 :
18 : // ------------------------------------------------------------------------
19 :
20 : // Output context for systemtap translation, intended to allow
21 : // pretty-printing.
22 : class translator_output
23 : {
24 : char *buf;
25 : std::ofstream* o2;
26 : std::ostream& o;
27 : unsigned tablevel;
28 :
29 : public:
30 : translator_output (std::ostream& file);
31 : translator_output (const std::string& filename, size_t bufsize = 8192);
32 : ~translator_output ();
33 :
34 : std::ostream& newline (int indent = 0);
35 : void indent (int indent = 0);
36 : std::ostream& line();
37 :
38 45212 : std::ostream::pos_type tellp() { return o.tellp(); }
39 7632 : std::ostream& seekp(std::ostream::pos_type p) { return o.seekp(p); }
40 : };
41 :
42 :
43 : // An unparser instance is in charge of emitting code for generic
44 : // probe bodies, functions, globals.
45 : struct unparser
46 283 : {
47 283 : virtual ~unparser () {}
48 :
49 : virtual void emit_common_header () = 0;
50 : // #include<...>
51 : //
52 : // #define MAXNESTING nnn
53 : // #define MAXCONCURRENCY mmm
54 : // #define MAXSTRINGLEN ooo
55 : //
56 : // enum session_state_t {
57 : // starting, begin, running, suspended, errored, ending, ended
58 : // };
59 : // static atomic_t session_state;
60 : //
61 : // struct context {
62 : // unsigned errorcount;
63 : // unsigned busy;
64 : // ...
65 : // } context [MAXCONCURRENCY];
66 :
67 : // struct {
68 : virtual void emit_global (vardecl* v) = 0;
69 : // TYPE s_NAME; // NAME is prefixed with "s_" to avoid kernel id collisions
70 : // rwlock_t s_NAME_lock;
71 : // } global = {
72 : virtual void emit_global_init (vardecl* v) = 0;
73 : // };
74 :
75 : virtual void emit_global_param (vardecl* v) = 0;
76 : // module_param_... -- at end of file
77 :
78 : virtual void emit_functionsig (functiondecl* v) = 0;
79 : // static void function_NAME (context* c);
80 :
81 : virtual void emit_module_init () = 0;
82 : virtual void emit_module_exit () = 0;
83 : // XXX
84 :
85 : virtual void emit_function (functiondecl* v) = 0;
86 : // void function_NAME (struct context* c) {
87 : // ....
88 : // }
89 :
90 : virtual void emit_probe (derived_probe* v) = 0;
91 : // void probe_NUMBER (struct context* c) {
92 : // ... lifecycle
93 : // ....
94 : // }
95 : // ... then call over to the derived_probe's emit_probe_entries() fn
96 : };
97 :
98 :
99 : int translate_pass (systemtap_session& s);
100 :
101 :
102 : #endif // TRANSLATE_H
|