Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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_HCODEGENERATOR |
| 9 | #define SKSL_HCODEGENERATOR |
| 10 | |
| 11 | #include "SkSLCodeGenerator.h" |
| 12 | #include "SkSLSectionAndParameterHelper.h" |
| 13 | #include "ir/SkSLType.h" |
| 14 | #include "ir/SkSLVariable.h" |
| 15 | |
| 16 | #include <cctype> |
| 17 | |
| 18 | constexpr const char* kFragmentProcessorHeader = |
| 19 | R"(/* |
| 20 | * Copyright 2017 Google Inc. |
| 21 | * |
| 22 | * Use of this source code is governed by a BSD-style license that can be |
| 23 | * found in the LICENSE file. |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * This file was autogenerated from %s.fp; do not modify. |
| 28 | */ |
| 29 | )"; |
| 30 | |
| 31 | namespace SkSL { |
| 32 | |
| 33 | class HCodeGenerator : public CodeGenerator { |
| 34 | public: |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 35 | HCodeGenerator(const Context* context, const Program* program, ErrorReporter* errors, |
| 36 | String name, OutputStream* out); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 37 | |
| 38 | bool generateCode() override; |
| 39 | |
Ethan Nicholas | d608c09 | 2017-10-26 09:30:08 -0400 | [diff] [blame] | 40 | static String ParameterType(const Context& context, const Type& type, const Layout& layout); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 41 | |
Ethan Nicholas | d608c09 | 2017-10-26 09:30:08 -0400 | [diff] [blame] | 42 | static String FieldType(const Context& context, const Type& type, const Layout& layout); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 43 | |
| 44 | static String FieldName(const char* varName) { |
| 45 | return String::printf("f%c%s", toupper(varName[0]), varName + 1); |
| 46 | } |
| 47 | |
| 48 | private: |
| 49 | void writef(const char* s, va_list va) SKSL_PRINTF_LIKE(2, 0); |
| 50 | |
| 51 | void writef(const char* s, ...) SKSL_PRINTF_LIKE(2, 3); |
| 52 | |
| 53 | bool writeSection(const char* name, const char* prefix = ""); |
| 54 | |
| 55 | // given a @constructorParams section of e.g. 'int x, float y', writes out "<separator>x, y". |
| 56 | // Writes nothing (not even the separator) if there is no @constructorParams section. |
| 57 | void writeExtraConstructorParams(const char* separator); |
| 58 | |
| 59 | void writeMake(); |
| 60 | |
| 61 | void writeConstructor(); |
| 62 | |
| 63 | void writeFields(); |
| 64 | |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 65 | void failOnSection(const char* section, const char* msg); |
| 66 | |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 67 | const Context& fContext; |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 68 | String fName; |
| 69 | String fFullName; |
| 70 | SectionAndParameterHelper fSectionAndParameterHelper; |
| 71 | |
| 72 | typedef CodeGenerator INHERITED; |
| 73 | }; |
| 74 | |
| 75 | } // namespace SkSL |
| 76 | |
| 77 | #endif |