• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
35     HCodeGenerator(const Program* program, ErrorReporter* errors, String name, OutputStream* out);
36 
37     bool generateCode() override;
38 
39     static String ParameterType(const Type& type);
40 
41     static String FieldType(const Type& type);
42 
FieldName(const char * varName)43     static String FieldName(const char* varName) {
44         return String::printf("f%c%s", toupper(varName[0]), varName + 1);
45     }
46 
47 private:
48     void writef(const char* s, va_list va) SKSL_PRINTF_LIKE(2, 0);
49 
50     void writef(const char* s, ...) SKSL_PRINTF_LIKE(2, 3);
51 
52     bool writeSection(const char* name, const char* prefix = "");
53 
54     // given a @constructorParams section of e.g. 'int x, float y', writes out "<separator>x, y".
55     // Writes nothing (not even the separator) if there is no @constructorParams section.
56     void writeExtraConstructorParams(const char* separator);
57 
58     void writeMake();
59 
60     void writeConstructor();
61 
62     void writeFields();
63 
64     void failOnSection(const char* section, const char* msg);
65 
66     String fName;
67     String fFullName;
68     SectionAndParameterHelper fSectionAndParameterHelper;
69 
70     typedef CodeGenerator INHERITED;
71 };
72 
73 } // namespace SkSL
74 
75 #endif
76