blob: fa5544a0e0949e974da97f9ef7ecd3a7a322283b [file] [log] [blame]
Ethan Nicholas762466e2017-06-29 10:03:38 -04001/*
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
18constexpr const char* kFragmentProcessorHeader =
19R"(/*
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
31namespace SkSL {
32
33class HCodeGenerator : public CodeGenerator {
34public:
Ethan Nicholasc9472af2017-10-10 16:30:21 -040035 HCodeGenerator(const Context* context, const Program* program, ErrorReporter* errors,
36 String name, OutputStream* out);
Ethan Nicholas762466e2017-06-29 10:03:38 -040037
38 bool generateCode() override;
39
Ethan Nicholasd608c092017-10-26 09:30:08 -040040 static String ParameterType(const Context& context, const Type& type, const Layout& layout);
Ethan Nicholas762466e2017-06-29 10:03:38 -040041
Ethan Nicholasd608c092017-10-26 09:30:08 -040042 static String FieldType(const Context& context, const Type& type, const Layout& layout);
Ethan Nicholas762466e2017-06-29 10:03:38 -040043
44 static String FieldName(const char* varName) {
45 return String::printf("f%c%s", toupper(varName[0]), varName + 1);
46 }
47
48private:
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 Nicholas68990be2017-07-13 09:36:52 -040065 void failOnSection(const char* section, const char* msg);
66
Ethan Nicholasc9472af2017-10-10 16:30:21 -040067 const Context& fContext;
Ethan Nicholas762466e2017-06-29 10:03:38 -040068 String fName;
69 String fFullName;
70 SectionAndParameterHelper fSectionAndParameterHelper;
71
72 typedef CodeGenerator INHERITED;
73};
74
75} // namespace SkSL
76
77#endif