Skip to content

Commit

Permalink
Compiler: Continue multipass implementation (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLynix committed Jul 3, 2024
1 parent 7b608cd commit a1d4cd2
Show file tree
Hide file tree
Showing 20 changed files with 1,244 additions and 272 deletions.
40 changes: 40 additions & 0 deletions include/NZSL/Ast/Transformations/AssignmentTransformer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Shading Language" project
// For conditions of distribution and use, see copyright notice in Config.hpp

#pragma once

#ifndef NZSL_AST_TRANSFORMATIONS_ASSIGNMENTTRANSFORMER_HPP
#define NZSL_AST_TRANSFORMATIONS_ASSIGNMENTTRANSFORMER_HPP

#include <NZSL/Ast/Transformations/Transformer.hpp>

namespace nzsl::Ast
{
class NZSL_API AssignmentTransformer final : public Transformer
{
public:
struct Options;

inline AssignmentTransformer();

inline bool Transform(Module& module, Context& context, std::string* error = nullptr);
bool Transform(Module& module, Context& context, const Options& options, std::string* error = nullptr);

struct Options
{
bool allowPartialSanitization = false;
bool removeCompoundAssignment = false;
};

private:
using Transformer::Transform;
ExpressionPtr Transform(AssignExpression&& assign) override;

const Options* m_options;
};
}

#include <NZSL/Ast/Transformations/AssignmentTransformer.inl>

#endif // NZSL_AST_TRANSFORMATIONS_ASSIGNMENTTRANSFORMER_HPP
16 changes: 16 additions & 0 deletions include/NZSL/Ast/Transformations/AssignmentTransformer.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Shading Language" project
// For conditions of distribution and use, see copyright notice in Config.hpp

namespace nzsl::Ast
{
inline AssignmentTransformer::AssignmentTransformer() :
Transformer(true)
{
}

inline bool AssignmentTransformer::Transform(Module& module, Context& context, std::string* error)
{
return Transform(module, context, {}, error);
}
}
39 changes: 39 additions & 0 deletions include/NZSL/Ast/Transformations/BranchSplitterTransformer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Shading Language" project
// For conditions of distribution and use, see copyright notice in Config.hpp

#pragma once

#ifndef NZSL_AST_TRANSFORMATIONS_BRANCHSPLITTERTRANSFORMER_HPP
#define NZSL_AST_TRANSFORMATIONS_BRANCHSPLITTERTRANSFORMER_HPP

#include <NZSL/Ast/Transformations/Transformer.hpp>

namespace nzsl::Ast
{
class NZSL_API BranchSplitterTransformer final : public Transformer
{
public:
struct Options;

inline BranchSplitterTransformer();

inline bool Transform(Module& module, Context& context, std::string* error = nullptr);
bool Transform(Module& module, Context& context, const Options& options, std::string* error = nullptr);

struct Options
{
bool allowPartialSanitization = false;
};

private:
using Transformer::Transform;
StatementPtr Transform(BranchStatement&& statement) override;

const Options* m_options;
};
}

#include <NZSL/Ast/Transformations/BranchSplitterTransformer.inl>

#endif // NZSL_AST_TRANSFORMATIONS_BRANCHSPLITTERTRANSFORMER_HPP
16 changes: 16 additions & 0 deletions include/NZSL/Ast/Transformations/BranchSplitterTransformer.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Shading Language" project
// For conditions of distribution and use, see copyright notice in Config.hpp

namespace nzsl::Ast
{
inline BranchSplitterTransformer::BranchSplitterTransformer() :
Transformer(false)
{
}

inline bool BranchSplitterTransformer::Transform(Module& module, Context& context, std::string* error)
{
return Transform(module, context, {}, error);
}
}
8 changes: 5 additions & 3 deletions include/NZSL/Ast/Transformations/ForToWhileTransformer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
#ifndef NZSL_AST_TRANSFORMATIONS_FORTOWHILETRANSFORMER_HPP
#define NZSL_AST_TRANSFORMATIONS_FORTOWHILETRANSFORMER_HPP

#include <NZSL/Ast/Transformations/StatementTransformer.hpp>
#include <NZSL/Ast/Transformations/Transformer.hpp>

namespace nzsl::Ast
{
class NZSL_API ForToWhileTransformer final : public StatementTransformer
class NZSL_API ForToWhileTransformer final : public Transformer
{
public:
struct Options;

inline ForToWhileTransformer();

inline bool Transform(Module& module, Context& context, std::string* error = nullptr);
bool Transform(Module& module, Context& context, const Options& options, std::string* error = nullptr);

Expand All @@ -27,7 +29,7 @@ namespace nzsl::Ast
};

private:
using StatementTransformer::Transform;
using Transformer::Transform;
StatementPtr Transform(ForEachStatement&& statement) override;
StatementPtr Transform(ForStatement&& statement) override;

Expand Down
5 changes: 5 additions & 0 deletions include/NZSL/Ast/Transformations/ForToWhileTransformer.inl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace nzsl::Ast
{
inline ForToWhileTransformer::ForToWhileTransformer() :
Transformer(false)
{
}

inline bool ForToWhileTransformer::Transform(Module& module, Context& context, std::string* error)
{
return Transform(module, context, {}, error);
Expand Down
42 changes: 42 additions & 0 deletions include/NZSL/Ast/Transformations/MatrixTransformer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Shading Language" project
// For conditions of distribution and use, see copyright notice in Config.hpp

#pragma once

#ifndef NZSL_AST_TRANSFORMATIONS_MATRIXTRANSFORMER_HPP
#define NZSL_AST_TRANSFORMATIONS_MATRIXTRANSFORMER_HPP

#include <NZSL/Ast/Transformations/Transformer.hpp>

namespace nzsl::Ast
{
class NZSL_API MatrixTransformer final : public Transformer
{
public:
struct Options;

inline MatrixTransformer();

inline bool Transform(Module& module, Context& context, std::string* error = nullptr);
bool Transform(Module& module, Context& context, const Options& options, std::string* error = nullptr);

struct Options
{
bool removeMatrixBinaryAddSub = false;
bool removeMatrixCast = false;
};

private:
using Transformer::Transform;

ExpressionPtr Transform(BinaryExpression&& binExpr) override;
ExpressionPtr Transform(CastExpression&& castExpr) override;

const Options* m_options;
};
}

#include <NZSL/Ast/Transformations/MatrixTransformer.inl>

#endif // NZSL_AST_TRANSFORMATIONS_MATRIXTRANSFORMER_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@

namespace nzsl::Ast
{
inline MatrixTransformer::MatrixTransformer() :
Transformer(true)
{
}

inline bool MatrixTransformer::Transform(Module& module, Context& context, std::string* error)
{
return Transform(module, context, {}, error);
}
}
64 changes: 0 additions & 64 deletions include/NZSL/Ast/Transformations/StatementTransformer.hpp

This file was deleted.

40 changes: 40 additions & 0 deletions include/NZSL/Ast/Transformations/SwizzleTransformer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Shading Language" project
// For conditions of distribution and use, see copyright notice in Config.hpp

#pragma once

#ifndef NZSL_AST_TRANSFORMATIONS_SWIZZLETRANSFORMER_HPP
#define NZSL_AST_TRANSFORMATIONS_SWIZZLETRANSFORMER_HPP

#include <NZSL/Ast/Transformations/Transformer.hpp>

namespace nzsl::Ast
{
class NZSL_API SwizzleTransformer final : public Transformer
{
public:
struct Options;

inline SwizzleTransformer();

inline bool Transform(Module& module, Context& context, std::string* error = nullptr);
bool Transform(Module& module, Context& context, const Options& options, std::string* error = nullptr);

struct Options
{
bool allowPartialSanitization = false;
bool removeScalarSwizzling = false;
};

private:
using Transformer::Transform;
ExpressionPtr Transform(SwizzleExpression&& swizzle) override;

const Options* m_options;
};
}

#include <NZSL/Ast/Transformations/SwizzleTransformer.inl>

#endif // NZSL_AST_TRANSFORMATIONS_SWIZZLETRANSFORMER_HPP
16 changes: 16 additions & 0 deletions include/NZSL/Ast/Transformations/SwizzleTransformer.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Shading Language" project
// For conditions of distribution and use, see copyright notice in Config.hpp

namespace nzsl::Ast
{
inline SwizzleTransformer::SwizzleTransformer() :
Transformer(true)
{
}

inline bool SwizzleTransformer::Transform(Module& module, Context& context, std::string* error)
{
return Transform(module, context, {}, error);
}
}
Loading

0 comments on commit a1d4cd2

Please sign in to comment.