blob: c6031b27792a9a3b5dffc96a8824a507b865ae0e [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 =
Ethan Nicholas130fb3f2018-02-01 12:14:34 -050019R"(
20/**************************************************************************************************
21 *** This file was autogenerated from %s.fp; do not modify.
22 **************************************************************************************************/
Ethan Nicholas762466e2017-06-29 10:03:38 -040023)";
24
25namespace SkSL {
26
27class HCodeGenerator : public CodeGenerator {
28public:
Ethan Nicholasc9472af2017-10-10 16:30:21 -040029 HCodeGenerator(const Context* context, const Program* program, ErrorReporter* errors,
30 String name, OutputStream* out);
Ethan Nicholas762466e2017-06-29 10:03:38 -040031
32 bool generateCode() override;
33
Ethan Nicholasd608c092017-10-26 09:30:08 -040034 static String ParameterType(const Context& context, const Type& type, const Layout& layout);
Ethan Nicholas762466e2017-06-29 10:03:38 -040035
Ethan Nicholasd608c092017-10-26 09:30:08 -040036 static String FieldType(const Context& context, const Type& type, const Layout& layout);
Ethan Nicholas762466e2017-06-29 10:03:38 -040037
38 static String FieldName(const char* varName) {
39 return String::printf("f%c%s", toupper(varName[0]), varName + 1);
40 }
41
Ethan Nicholas130fb3f2018-02-01 12:14:34 -050042 static String GetHeader(const Program& program, ErrorReporter& errors);
43
Ethan Nicholas762466e2017-06-29 10:03:38 -040044private:
45 void writef(const char* s, va_list va) SKSL_PRINTF_LIKE(2, 0);
46
47 void writef(const char* s, ...) SKSL_PRINTF_LIKE(2, 3);
48
49 bool writeSection(const char* name, const char* prefix = "");
50
51 // given a @constructorParams section of e.g. 'int x, float y', writes out "<separator>x, y".
52 // Writes nothing (not even the separator) if there is no @constructorParams section.
53 void writeExtraConstructorParams(const char* separator);
54
55 void writeMake();
56
57 void writeConstructor();
58
59 void writeFields();
60
Ethan Nicholas68990be2017-07-13 09:36:52 -040061 void failOnSection(const char* section, const char* msg);
62
Ethan Nicholasc9472af2017-10-10 16:30:21 -040063 const Context& fContext;
Ethan Nicholas762466e2017-06-29 10:03:38 -040064 String fName;
65 String fFullName;
66 SectionAndParameterHelper fSectionAndParameterHelper;
67
68 typedef CodeGenerator INHERITED;
69};
70
71} // namespace SkSL
72
73#endif