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 "src/sksl/SkSLCodeGenerator.h" |
12 | #include "src/sksl/SkSLSectionAndParameterHelper.h" |
13 | #include "src/sksl/ir/SkSLType.h" |
14 | #include "src/sksl/ir/SkSLVariable.h" |
15 | |
16 | #include <cctype> |
17 | |
18 | constexpr const char* = |
19 | R"( |
20 | /************************************************************************************************** |
21 | *** This file was autogenerated from %s.fp; do not modify. |
22 | **************************************************************************************************/ |
23 | )" ; |
24 | |
25 | namespace SkSL { |
26 | |
27 | class HCodeGenerator : public CodeGenerator { |
28 | public: |
29 | HCodeGenerator(const Context* context, const Program* program, ErrorReporter* errors, |
30 | String name, OutputStream* out); |
31 | |
32 | bool generateCode() override; |
33 | |
34 | static String ParameterType(const Context& context, const Type& type, const Layout& layout); |
35 | |
36 | static Layout::CType ParameterCType(const Context& context, const Type& type, |
37 | const Layout& layout); |
38 | |
39 | static String FieldType(const Context& context, const Type& type, const Layout& layout); |
40 | |
41 | // Either the field type, or a const reference of the field type if the field type is complex. |
42 | static String AccessType(const Context& context, const Type& type, const Layout& layout); |
43 | |
44 | static String FieldName(const char* varName) { |
45 | return String(varName); |
46 | } |
47 | |
48 | static String CoordTransformName(const String& arg, int index) { |
49 | if (arg.size()) { |
50 | return HCodeGenerator::FieldName(arg.c_str()) + "CoordTransform" ; |
51 | } |
52 | return "fCoordTransform" + to_string(index); |
53 | } |
54 | |
55 | static String (const Program& program, ErrorReporter& errors); |
56 | |
57 | private: |
58 | void writef(const char* s, va_list va) SKSL_PRINTF_LIKE(2, 0); |
59 | |
60 | void writef(const char* s, ...) SKSL_PRINTF_LIKE(2, 3); |
61 | |
62 | bool writeSection(const char* name, const char* prefix = "" ); |
63 | |
64 | // given a @constructorParams section of e.g. 'int x, float y', writes out "<separator>x, y". |
65 | // Writes nothing (not even the separator) if there is no @constructorParams section. |
66 | void (const char* separator); |
67 | |
68 | void writeMake(); |
69 | |
70 | void writeConstructor(); |
71 | |
72 | void writeFields(); |
73 | |
74 | void failOnSection(const char* section, const char* msg); |
75 | |
76 | const Context& fContext; |
77 | String fName; |
78 | String fFullName; |
79 | SectionAndParameterHelper fSectionAndParameterHelper; |
80 | |
81 | typedef CodeGenerator INHERITED; |
82 | }; |
83 | |
84 | } // namespace SkSL |
85 | |
86 | #endif |
87 | |