X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fgenerate.h;h=f76c2c2d8fba55d7231f95dfd487d20e897b3061;hb=1d02efce746aa8b6e678a3bf56bfbbbe0aea6952;hp=511a460793d4e162fb05c24119c37c8538114322;hpb=99719790df8a1215465a68c7b1d87a495bff87eb;p=libs%2Fgl.git diff --git a/source/glsl/generate.h b/source/glsl/generate.h index 511a4607..f76c2c2d 100644 --- a/source/glsl/generate.h +++ b/source/glsl/generate.h @@ -11,6 +11,7 @@ namespace Msp { namespace GL { namespace SL { +/** Combines multiple declarations of the same identifier into one. */ class DeclarationCombiner: private TraversingVisitor { private: @@ -23,31 +24,49 @@ public: private: virtual void visit(Block &); - virtual void visit(FunctionDeclaration &); virtual void visit(VariableDeclaration &); - using TraversingVisitor::visit; + virtual void visit(FunctionDeclaration &) { } }; -class BlockResolver: private TraversingVisitor +/** Manipulates specialization constants. If values are specified, turns +specialization constants into normal constants. Without values assigns +automatic constant_ids to specialization constants. */ +class ConstantSpecializer: private TraversingVisitor { +private: + const std::map *values; + public: - void apply(Stage &s) { visit(s.content); } + ConstantSpecializer(); + + void apply(Stage &, const std::map *); private: - virtual void visit(Block &); - virtual void visit(InterfaceBlock &); - using TraversingVisitor::visit; + virtual void visit(VariableDeclaration &); +}; + +/** Forms links between nested blocks in the syntax tree. */ +class BlockHierarchyResolver: private TraversingVisitor +{ +public: + void apply(Stage &s) { s.content.visit(*this); } + +private: + virtual void enter(Block &); }; +/** Resolves variable references. Variable references which match the name +of an interface block are turned into interface block references. */ class VariableResolver: private TraversingVisitor { private: - Block *builtins; - StructDeclaration *type; + Stage *stage; + std::map *r_members; + RefPtr r_iface_ref; std::string block_interface; bool record_target; - VariableDeclaration *assignment_target; - bool self_referencing; + VariableDeclaration *r_assignment_target; + bool r_self_referencing; public: VariableResolver(); @@ -55,41 +74,52 @@ public: void apply(Stage &); private: - Block *next_block(Block &); - - virtual void visit(Block &); + virtual void enter(Block &); virtual void visit(VariableReference &); + virtual void visit(InterfaceBlockReference &); virtual void visit(MemberAccess &); + virtual void visit(UnaryExpression &); virtual void visit(BinaryExpression &); virtual void visit(Assignment &); + virtual void visit(FunctionCall &); virtual void visit(StructDeclaration &); virtual void visit(VariableDeclaration &); virtual void visit(InterfaceBlock &); - virtual void visit(FunctionDeclaration &); - virtual void visit(Iteration &); - using TraversingVisitor::visit; }; +/** Resolves function declarations and calls. */ class FunctionResolver: private TraversingVisitor { private: - std::map > functions; + Stage *stage; + std::map > declarations; public: - void apply(Stage &s) { visit(s.content); } + void apply(Stage &); private: virtual void visit(FunctionCall &); virtual void visit(FunctionDeclaration &); - using TraversingVisitor::visit; }; +/** Materializes implicitly declared interfaces. + +Out variable declarations inside functions are moved to the global scope. + +Passthrough statements are processed, generating out variables to match in +variables and copying values. + +Unresolved variables are looked up in the previous stage's out variables. */ class InterfaceGenerator: private TraversingVisitor { private: Stage *stage; std::string in_prefix; std::string out_prefix; + bool function_scope; + InterfaceBlock *iface_block; + bool copy_block; + Block *iface_target_block; NodeList::iterator iface_insert_point; NodeList::iterator assignment_insert_point; std::set nodes_to_remove; @@ -104,43 +134,13 @@ private: std::string change_prefix(const std::string &, const std::string &) const; virtual void visit(Block &); bool generate_interface(VariableDeclaration &, const std::string &, const std::string &); + bool generate_interface(InterfaceBlock &); ExpressionStatement &insert_assignment(const std::string &, Expression *); virtual void visit(VariableReference &); virtual void visit(VariableDeclaration &); - virtual void visit(Passthrough &); - using TraversingVisitor::visit; -}; - -class DeclarationReorderer: private TraversingVisitor -{ -private: - enum DeclarationKind - { - NO_DECLARATION, - LAYOUT, - STRUCT, - VARIABLE, - FUNCTION - }; - - DeclarationKind kind; - std::set ordered_funcs; - std::set needed_funcs; - -public: - DeclarationReorderer(); - - void apply(Stage &s) { visit(s.content); } - -private: - virtual void visit(Block &); - virtual void visit(FunctionCall &); - virtual void visit(InterfaceLayout &) { kind = LAYOUT; } - virtual void visit(StructDeclaration &) { kind = STRUCT; } - virtual void visit(VariableDeclaration &); - virtual void visit(InterfaceBlock &) { kind = VARIABLE; } + virtual void visit(InterfaceBlock &); virtual void visit(FunctionDeclaration &); - using TraversingVisitor::visit; + virtual void visit(Passthrough &); }; } // namespace SL