blob: ebf9209133bf8643c607a09fd11753090d00926f [file] [log] [blame]
dan sinclaireee8d882022-10-28 01:22:58 +00001// Copyright 2022 The Tint Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef SRC_TINT_IR_MODULE_H_
16#define SRC_TINT_IR_MODULE_H_
17
18#include <string>
19
dan sinclair19ebcb22022-12-15 19:17:22 +000020#include "src/tint/constant/value.h"
dan sinclaireee8d882022-10-28 01:22:58 +000021#include "src/tint/ir/function.h"
dan sinclair31e08502022-11-29 23:29:47 +000022#include "src/tint/ir/instruction.h"
dan sinclair2d108ae2022-11-29 20:36:59 +000023#include "src/tint/ir/value.h"
dan sinclairf8abdc72023-01-05 21:07:15 +000024#include "src/tint/program_id.h"
25#include "src/tint/symbol_table.h"
dan sinclair19ebcb22022-12-15 19:17:22 +000026#include "src/tint/type/manager.h"
dan sinclaireee8d882022-10-28 01:22:58 +000027#include "src/tint/utils/block_allocator.h"
28#include "src/tint/utils/result.h"
29#include "src/tint/utils/vector.h"
30
dan sinclaireee8d882022-10-28 01:22:58 +000031namespace tint::ir {
32
33/// Main module class for the IR.
34class Module {
35 public:
dan sinclaireee8d882022-10-28 01:22:58 +000036 /// Constructor
dan sinclair8bcb4e92023-01-06 19:45:13 +000037 Module();
dan sinclaireee8d882022-10-28 01:22:58 +000038 /// Move constructor
39 /// @param o the module to move from
40 Module(Module&& o);
41 /// Destructor
42 ~Module();
43
44 /// Move assign
45 /// @param o the module to assign from
46 /// @returns a reference to this module
47 Module& operator=(Module&& o);
48
dan sinclairf8abdc72023-01-05 21:07:15 +000049 private:
50 /// Program Id required to create other components
51 ProgramID prog_id_;
52
53 public:
dan sinclaireee8d882022-10-28 01:22:58 +000054 /// The flow node allocator
55 utils::BlockAllocator<FlowNode> flow_nodes;
dan sinclair19ebcb22022-12-15 19:17:22 +000056 /// The constant allocator
57 utils::BlockAllocator<constant::Value> constants;
dan sinclair2d108ae2022-11-29 20:36:59 +000058 /// The value allocator
59 utils::BlockAllocator<Value> values;
dan sinclair31e08502022-11-29 23:29:47 +000060 /// The instruction allocator
61 utils::BlockAllocator<Instruction> instructions;
dan sinclaireee8d882022-10-28 01:22:58 +000062
63 /// List of functions in the program
64 utils::Vector<Function*, 8> functions;
65 /// List of indexes into the functions list for the entry points
66 utils::Vector<Function*, 8> entry_points;
67
dan sinclairc970e802023-05-02 15:47:29 +000068 /// The block containing module level declarations, if any exist.
69 Block* root_block = nullptr;
70
dan sinclair19ebcb22022-12-15 19:17:22 +000071 /// The type manager for the module
72 type::Manager types;
dan sinclairf8abdc72023-01-05 21:07:15 +000073
74 /// The symbol table for the module
75 SymbolTable symbols{prog_id_};
dan sinclaireee8d882022-10-28 01:22:58 +000076};
77
78} // namespace tint::ir
79
80#endif // SRC_TINT_IR_MODULE_H_