implemented new code splitting mechanism (split to equal slices)
[deliverable/titan.core.git] / compiler2 / CodeGenHelper.hh
1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Raduly, Csaba
11 * Szabo, Bence Janos
12 * Zalanyi, Balazs Andor
13 *
14 ******************************************************************************/
15 #ifndef _Common_CodeGenHelper_HH
16 #define _Common_CodeGenHelper_HH
17
18 #include "ttcn3/compiler.h"
19 #include "map.hh"
20 #include "vector.hh"
21 #include "string.hh"
22 #include "ttcn3/AST_ttcn3.hh"
23 #include "Type.hh"
24
25 namespace Ttcn {
26 class Definition;
27 }
28
29 namespace Common {
30
31 class CodeGenHelper {
32 public:
33 enum split_type {
34 SPLIT_NONE, ///< original code generation
35 SPLIT_BY_KIND, ///< place different kind of types in their own file
36 SPLIT_BY_NAME, ///< place all definitions/assignments in their own file
37 SPLIT_BY_HEURISTICS,///< heuristic function will decide the structure
38 SPLIT_TO_SLICES ///< split large files into smaller ones
39 };
40
41 private:
42 struct generated_output_t {
43
44 generated_output_t();
45 ~generated_output_t();
46
47 output_struct os;
48 string modulename;
49 string module_dispname;
50 string filename;
51 bool is_module;
52 bool is_ttcn;
53 bool has_circular_import;
54 };
55
56 static const char* const typetypemap[];
57
58 typedef map<string, generated_output_t> output_map_t;
59
60 output_map_t generated_code;
61 split_type split_mode;
62 unsigned int slice_num;
63
64 struct module_names_t {
65 string name;
66 string dispname;
67 };
68
69 vector<module_names_t> modules;
70 string current_module;
71
72 static CodeGenHelper* instance;
73
74 public:
75 CodeGenHelper();
76
77 static CodeGenHelper& GetInstance();
78
79 void set_split_mode(split_type st);
80 bool set_split_mode(const char* type);
81 split_type get_split_mode() const;
82
83 void add_module(const string& name, const string& dispname, bool is_ttcn,
84 bool has_circular_import);
85 output_struct* get_outputstruct(const string& name);
86 output_struct* get_outputstruct(Ttcn::Definition* def);
87 output_struct* get_outputstruct(Type* type);
88 output_struct* get_current_outputstruct();
89 void finalize_generation(Type* type);
90
91 void set_current_module(const string& name);
92
93 static void update_intervals(output_struct* const output);
94
95 size_t size_of_sources(output_struct * const output);
96
97 size_t get_next_chunk_pos(const output_struct * const from, output_struct * const to, const size_t base_pos, const size_t chunk_size);
98
99 void get_chunk_from_poslist(const char* from, char *& to, const size_t interval_array[], const size_t interval_array_size, const size_t base_pos, const size_t chunk_size, size_t& pos);
100
101 void write_output();
102
103 ~CodeGenHelper();
104
105 private:
106 string get_key(Ttcn::Definition& def) const;
107 string get_key(Type& type) const;
108 static void transfer_value(char* &dst, char* &src);
109 };
110
111 }
112
113 #endif /* _Common_CodeGenHelper_HH */
This page took 0.03217 seconds and 5 git commands to generate.