ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 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_INTERFACEBLOCK |
| 9 | #define SKSL_INTERFACEBLOCK |
| 10 | |
| 11 | #include "SkSLProgramElement.h" |
| 12 | #include "SkSLVarDeclaration.h" |
| 13 | |
| 14 | namespace SkSL { |
| 15 | |
| 16 | /** |
| 17 | * An interface block, as in: |
| 18 | * |
| 19 | * out gl_PerVertex { |
| 20 | * layout(builtin=0) vec4 gl_Position; |
| 21 | * layout(builtin=1) float gl_PointSize; |
| 22 | * }; |
| 23 | * |
| 24 | * At the IR level, this is represented by a single variable of struct type. |
| 25 | */ |
| 26 | struct InterfaceBlock : public ProgramElement { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 27 | InterfaceBlock(Position position, const Variable& var, std::shared_ptr<SymbolTable> typeOwner) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 28 | : INHERITED(position, kInterfaceBlock_Kind) |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 29 | , fVariable(std::move(var)) |
| 30 | , fTypeOwner(typeOwner) { |
| 31 | ASSERT(fVariable.fType.kind() == Type::kStruct_Kind); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | std::string description() const override { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 35 | std::string result = fVariable.fModifiers.description() + fVariable.fName + " {\n"; |
| 36 | for (size_t i = 0; i < fVariable.fType.fields().size(); i++) { |
| 37 | result += fVariable.fType.fields()[i].description() + "\n"; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 38 | } |
| 39 | result += "};"; |
| 40 | return result; |
| 41 | } |
| 42 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 43 | const Variable& fVariable; |
| 44 | const std::shared_ptr<SymbolTable> fTypeOwner; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 45 | |
| 46 | typedef ProgramElement INHERITED; |
| 47 | }; |
| 48 | |
| 49 | } // namespace |
| 50 | |
| 51 | #endif |