CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Generator.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
11
14
16
18
20
22
23 // Output code generator base class.
24 class Generator : protected VisitorTracker {
25 public:
27
28 bool generateCode(Program& program, const ShaderInput& inputDesc, const ShaderOutput& outputDesc, Log* log = nullptr);
29
30 protected:
31 virtual void generateCodePrimary(Program& program, const ShaderInput& inputDesc, const ShaderOutput& outputDesc) = 0;
32
33 void error(const String& msg, const AST* ast = nullptr, bool breakWithException = true);
34 void warning(const String& msg, const AST* ast = nullptr);
35
36 void beginLn();
37 void endLn();
38
41
42 void separator();
43
44 void writeScopeOpen(bool compact = false, bool endWithSemicolon = false, bool useBraces = true);
47
48 [[nodiscard]] bool isOpenLine() const;
49
50 void write(const String& text);
51 void writeLn(const String& text);
52
55
56 void pushOptions(const CodeWriter::Options& options);
57 void popOptions();
58
59 // Push the specified text to the write-prefix which will be written in front of the text of the next "Write"/"WriteLn" call.
60 void pushWritePrefix(const String& text);
61 void popWritePrefix(const String& text = "");
62
63 // Returns true, if the current (top most) write prefix was written out.
64 [[nodiscard]] bool isTopWritePrefix() const;
65
66 void blank();
67
68 // Returns the current date and time point (can be used in a headline comment).
70
71 // Returns the AST root node.
72 [[nodiscard]] inline Program* getProgram() const { return mProgram; }
73
74 // Returns the shader target.
75 [[nodiscard]] inline ShaderTarget getShaderTarget() const { return mShaderTarget; }
76
77 // Returns true if the specified warnings flags are enabled.
78 [[nodiscard]] bool isWarningEnabled(UInt32 flags) const;
79
80 [[nodiscard]] bool isVertexShader() const;
83 [[nodiscard]] bool isGeometryShader() const;
84 [[nodiscard]] bool isFragmentShader() const;
85 [[nodiscard]] bool isComputeShader() const;
86
87 private:
92 struct WritePrefix {
93 String text; // Specifies the prefix text.
94 bool written; // Specifies whether this prefix has already been written out.
95 };
96
97 // Writes all prefixes that have not already been written.
99
102
103 Program* mProgram = nullptr;
104
107
108 bool mAllowBlanks = true;
110
112 };
113
114} // namespace CeresEngine::ShaderCompiler
Definition CodeWriter.hpp:57
Definition Flags.hpp:235
Definition Generator.hpp:24
void pushOptions(const CodeWriter::Options &options)
RawFlags mWarnings
Definition Generator.hpp:106
Program * mProgram
Definition Generator.hpp:103
bool mAllowBlanks
Definition Generator.hpp:108
bool mAllowLineSeparation
Definition Generator.hpp:109
void pushWritePrefix(const String &text)
void writeLn(const String &text)
ReportHandler mReportHandler
Definition Generator.hpp:101
ShaderTarget mShaderTarget
Definition Generator.hpp:105
void popWritePrefix(const String &text="")
bool isWarningEnabled(UInt32 flags) const
bool generateCode(Program &program, const ShaderInput &inputDesc, const ShaderOutput &outputDesc, Log *log=nullptr)
ShaderTarget getShaderTarget() const
Definition Generator.hpp:75
void write(const String &text)
virtual void generateCodePrimary(Program &program, const ShaderInput &inputDesc, const ShaderOutput &outputDesc)=0
void warning(const String &msg, const AST *ast=nullptr)
void error(const String &msg, const AST *ast=nullptr, bool breakWithException=true)
Program * getProgram() const
Definition Generator.hpp:72
CodeWriter mWriter
Definition Generator.hpp:100
void writeScopeOpen(bool compact=false, bool endWithSemicolon=false, bool useBraces=true)
Vector< WritePrefix > mWritePrefixStack
Definition Generator.hpp:111
Log base class.
Definition Log.hpp:19
Definition ReportHandler.hpp:31
Definition VisitorTracker.hpp:18
Definition AST.hpp:33
ShaderTarget
Shader target enumeration.
Definition Targets.hpp:16
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition CodeWriter.hpp:59
Prefix text that can be written in front of the text of the next "Write"/"WriteLn" call.
Definition Generator.hpp:92
String text
Definition Generator.hpp:93
Shader input descriptor structure.
Definition ShaderCompiler.hpp:223
Shader output descriptor structure.
Definition ShaderCompiler.hpp:293