dan sinclair | eee8d88 | 2022-10-28 01:22:58 +0000 | [diff] [blame] | 1 | // 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 sinclair | 19ebcb2 | 2022-12-15 19:17:22 +0000 | [diff] [blame] | 20 | #include "src/tint/constant/value.h" |
dan sinclair | eee8d88 | 2022-10-28 01:22:58 +0000 | [diff] [blame] | 21 | #include "src/tint/ir/function.h" |
dan sinclair | 31e0850 | 2022-11-29 23:29:47 +0000 | [diff] [blame] | 22 | #include "src/tint/ir/instruction.h" |
dan sinclair | 2d108ae | 2022-11-29 20:36:59 +0000 | [diff] [blame] | 23 | #include "src/tint/ir/value.h" |
dan sinclair | f8abdc7 | 2023-01-05 21:07:15 +0000 | [diff] [blame] | 24 | #include "src/tint/program_id.h" |
| 25 | #include "src/tint/symbol_table.h" |
dan sinclair | 19ebcb2 | 2022-12-15 19:17:22 +0000 | [diff] [blame] | 26 | #include "src/tint/type/manager.h" |
dan sinclair | eee8d88 | 2022-10-28 01:22:58 +0000 | [diff] [blame] | 27 | #include "src/tint/utils/block_allocator.h" |
| 28 | #include "src/tint/utils/result.h" |
| 29 | #include "src/tint/utils/vector.h" |
| 30 | |
dan sinclair | eee8d88 | 2022-10-28 01:22:58 +0000 | [diff] [blame] | 31 | namespace tint::ir { |
| 32 | |
| 33 | /// Main module class for the IR. |
| 34 | class Module { |
| 35 | public: |
dan sinclair | eee8d88 | 2022-10-28 01:22:58 +0000 | [diff] [blame] | 36 | /// Constructor |
dan sinclair | 8bcb4e9 | 2023-01-06 19:45:13 +0000 | [diff] [blame] | 37 | Module(); |
dan sinclair | eee8d88 | 2022-10-28 01:22:58 +0000 | [diff] [blame] | 38 | /// 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 sinclair | f8abdc7 | 2023-01-05 21:07:15 +0000 | [diff] [blame] | 49 | private: |
| 50 | /// Program Id required to create other components |
| 51 | ProgramID prog_id_; |
| 52 | |
| 53 | public: |
dan sinclair | eee8d88 | 2022-10-28 01:22:58 +0000 | [diff] [blame] | 54 | /// The flow node allocator |
| 55 | utils::BlockAllocator<FlowNode> flow_nodes; |
dan sinclair | 19ebcb2 | 2022-12-15 19:17:22 +0000 | [diff] [blame] | 56 | /// The constant allocator |
| 57 | utils::BlockAllocator<constant::Value> constants; |
dan sinclair | 2d108ae | 2022-11-29 20:36:59 +0000 | [diff] [blame] | 58 | /// The value allocator |
| 59 | utils::BlockAllocator<Value> values; |
dan sinclair | 31e0850 | 2022-11-29 23:29:47 +0000 | [diff] [blame] | 60 | /// The instruction allocator |
| 61 | utils::BlockAllocator<Instruction> instructions; |
dan sinclair | eee8d88 | 2022-10-28 01:22:58 +0000 | [diff] [blame] | 62 | |
| 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 sinclair | c970e80 | 2023-05-02 15:47:29 +0000 | [diff] [blame^] | 68 | /// The block containing module level declarations, if any exist. |
| 69 | Block* root_block = nullptr; |
| 70 | |
dan sinclair | 19ebcb2 | 2022-12-15 19:17:22 +0000 | [diff] [blame] | 71 | /// The type manager for the module |
| 72 | type::Manager types; |
dan sinclair | f8abdc7 | 2023-01-05 21:07:15 +0000 | [diff] [blame] | 73 | |
| 74 | /// The symbol table for the module |
| 75 | SymbolTable symbols{prog_id_}; |
dan sinclair | eee8d88 | 2022-10-28 01:22:58 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | } // namespace tint::ir |
| 79 | |
| 80 | #endif // SRC_TINT_IR_MODULE_H_ |