| 1 |
/* |
| 2 |
* Copyright 2024 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef SKSL_MODULE |
| 9 |
#define SKSL_MODULE |
| 10 |
|
| 11 |
#include "src/sksl/ir/SkSLProgramElement.h" |
| 12 |
#include "src/sksl/ir/SkSLSymbolTable.h" |
| 13 |
|
| 14 |
#include <cstdint> |
| 15 |
#include <memory> |
| 16 |
#include <string> |
| 17 |
#include <vector> |
| 18 |
|
| 19 |
namespace SkSL { |
| 20 |
|
| 21 |
/** |
| 22 |
* Documentation for modules in SkSL: http://go/modules-in-sksl |
| 23 |
* https://docs.google.com/document/d/1P8LkkimNr-nPlxMimUsz3K_7qMM7-tZOxDCWZejPcWg/edit?usp=sharing |
| 24 |
*/ |
| 25 |
|
| 26 |
// A list of modules used in SkSL. |
| 27 |
// Using an X-Macro (https://en.wikipedia.org/wiki/X_Macro) to manage the list. |
| 28 |
#define SKSL_MODULE_LIST(M) \ |
| 29 |
M(sksl_shared) \ |
| 30 |
M(sksl_compute) \ |
| 31 |
M(sksl_frag) \ |
| 32 |
M(sksl_gpu) \ |
| 33 |
M(sksl_public) \ |
| 34 |
M(sksl_rt_shader) \ |
| 35 |
M(sksl_vert) \ |
| 36 |
M(sksl_graphite_frag) \ |
| 37 |
M(sksl_graphite_vert) |
| 38 |
|
| 39 |
enum class ModuleType : int8_t { |
| 40 |
// `program` code is not in a module at all. |
| 41 |
program = 0, |
| 42 |
// `unknown` code exists in a module outside of SKSL_MODULE_LIST. |
| 43 |
unknown = 1, |
| 44 |
#define M(type) type, |
| 45 |
SKSL_MODULE_LIST(M) |
| 46 |
#undef M |
| 47 |
}; |
| 48 |
|
| 49 |
struct Module { |
| 50 |
const Module* fParent = nullptr; |
| 51 |
std::unique_ptr<SymbolTable> fSymbols; |
| 52 |
std::vector<std::unique_ptr<ProgramElement>> fElements; |
| 53 |
ModuleType fModuleType = ModuleType::unknown; |
| 54 |
}; |
| 55 |
|
| 56 |
// Given a ModuleType, returns its name. |
| 57 |
const char* ModuleTypeToString(ModuleType type); |
| 58 |
|
| 59 |
std::string GetModuleData(ModuleType type, const char* filename); |
| 60 |
|
| 61 |
} // namespace SkSL |
| 62 |
|
| 63 |
#endif // SKSL_MODULE |