IR visitor: Add initial version of ir_visitor classes
The ir_visitor class is the abstract base class for all visitors. ir_print_visitor contains the beginnings of a concrete visitor class that will print out an IR sequence in a Lisp / Scheme-like syntax.
This commit is contained in:
@@ -25,7 +25,8 @@ AUTOMAKE_OPTIONS = foreign
|
|||||||
bin_PROGRAMS = glsl
|
bin_PROGRAMS = glsl
|
||||||
glsl_SOURCES = symbol_table.c hash_table.c glsl_types.cpp \
|
glsl_SOURCES = symbol_table.c hash_table.c glsl_types.cpp \
|
||||||
glsl_parser.ypp glsl_lexer.lpp glsl_parser_extras.cpp \
|
glsl_parser.ypp glsl_lexer.lpp glsl_parser_extras.cpp \
|
||||||
ast_expr.cpp ast_to_hir.cpp ir.cpp hir_field_selection.cpp
|
ast_expr.cpp ast_to_hir.cpp ir.cpp hir_field_selection.cpp \
|
||||||
|
ir_print_visitor.cpp
|
||||||
|
|
||||||
BUILT_SOURCES = glsl_parser.h builtin_types.h
|
BUILT_SOURCES = glsl_parser.h builtin_types.h
|
||||||
|
|
||||||
|
43
ir.h
43
ir.h
@@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "ir_visitor.h"
|
||||||
|
|
||||||
struct ir_program {
|
struct ir_program {
|
||||||
void *bong_hits;
|
void *bong_hits;
|
||||||
@@ -48,6 +49,8 @@ public:
|
|||||||
unsigned mode;
|
unsigned mode;
|
||||||
const struct glsl_type *type;
|
const struct glsl_type *type;
|
||||||
|
|
||||||
|
virtual void accept(ir_visitor *) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ir_instruction(int mode);
|
ir_instruction(int mode);
|
||||||
|
|
||||||
@@ -81,6 +84,11 @@ class ir_variable : public ir_instruction {
|
|||||||
public:
|
public:
|
||||||
ir_variable(const struct glsl_type *, const char *);
|
ir_variable(const struct glsl_type *, const char *);
|
||||||
|
|
||||||
|
virtual void accept(ir_visitor *v)
|
||||||
|
{
|
||||||
|
v->visit(this);
|
||||||
|
}
|
||||||
|
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
unsigned read_only:1;
|
unsigned read_only:1;
|
||||||
@@ -96,6 +104,11 @@ class ir_label : public ir_instruction {
|
|||||||
public:
|
public:
|
||||||
ir_label(const char *label);
|
ir_label(const char *label);
|
||||||
|
|
||||||
|
virtual void accept(ir_visitor *v)
|
||||||
|
{
|
||||||
|
v->visit(this);
|
||||||
|
}
|
||||||
|
|
||||||
const char *label;
|
const char *label;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -105,6 +118,11 @@ class ir_function_signature : public ir_instruction {
|
|||||||
public:
|
public:
|
||||||
ir_function_signature(void);
|
ir_function_signature(void);
|
||||||
|
|
||||||
|
virtual void accept(ir_visitor *v)
|
||||||
|
{
|
||||||
|
v->visit(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function return type.
|
* Function return type.
|
||||||
*
|
*
|
||||||
@@ -131,6 +149,11 @@ class ir_function : public ir_instruction {
|
|||||||
public:
|
public:
|
||||||
ir_function(void);
|
ir_function(void);
|
||||||
|
|
||||||
|
virtual void accept(ir_visitor *v)
|
||||||
|
{
|
||||||
|
v->visit(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the function.
|
* Name of the function.
|
||||||
*/
|
*/
|
||||||
@@ -148,6 +171,11 @@ public:
|
|||||||
ir_assignment(ir_instruction *lhs, ir_instruction *rhs,
|
ir_assignment(ir_instruction *lhs, ir_instruction *rhs,
|
||||||
ir_expression *condition);
|
ir_expression *condition);
|
||||||
|
|
||||||
|
virtual void accept(ir_visitor *v)
|
||||||
|
{
|
||||||
|
v->visit(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Left-hand side of the assignment.
|
* Left-hand side of the assignment.
|
||||||
*/
|
*/
|
||||||
@@ -234,6 +262,11 @@ public:
|
|||||||
ir_expression(int op, const struct glsl_type *type,
|
ir_expression(int op, const struct glsl_type *type,
|
||||||
ir_instruction *, ir_instruction *);
|
ir_instruction *, ir_instruction *);
|
||||||
|
|
||||||
|
virtual void accept(ir_visitor *v)
|
||||||
|
{
|
||||||
|
v->visit(this);
|
||||||
|
}
|
||||||
|
|
||||||
ir_expression_operation operation;
|
ir_expression_operation operation;
|
||||||
ir_instruction *operands[2];
|
ir_instruction *operands[2];
|
||||||
};
|
};
|
||||||
@@ -262,6 +295,11 @@ class ir_dereference : public ir_instruction {
|
|||||||
public:
|
public:
|
||||||
ir_dereference(struct ir_instruction *);
|
ir_dereference(struct ir_instruction *);
|
||||||
|
|
||||||
|
virtual void accept(ir_visitor *v)
|
||||||
|
{
|
||||||
|
v->visit(this);
|
||||||
|
}
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ir_reference_variable,
|
ir_reference_variable,
|
||||||
ir_reference_array,
|
ir_reference_array,
|
||||||
@@ -287,6 +325,11 @@ class ir_constant : public ir_instruction {
|
|||||||
public:
|
public:
|
||||||
ir_constant(const struct glsl_type *type, const void *data);
|
ir_constant(const struct glsl_type *type, const void *data);
|
||||||
|
|
||||||
|
virtual void accept(ir_visitor *v)
|
||||||
|
{
|
||||||
|
v->visit(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Value of the constant.
|
* Value of the constant.
|
||||||
*
|
*
|
||||||
|
89
ir_print_visitor.cpp
Normal file
89
ir_print_visitor.cpp
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2010 Intel Corporation
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice (including the next
|
||||||
|
* paragraph) shall be included in all copies or substantial portions of the
|
||||||
|
* Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include <cstdio>
|
||||||
|
#include "ir_print_visitor.h"
|
||||||
|
|
||||||
|
void ir_print_visitor::visit(ir_variable *ir)
|
||||||
|
{
|
||||||
|
printf("(declare \n");
|
||||||
|
|
||||||
|
const char *const cent = (ir->centroid) ? "centroid " : "";
|
||||||
|
const char *const inv = (ir->invariant) ? "invariant " : "";
|
||||||
|
const char *const mode[] = { "", "uniform ", "in ", "out ", "inout " };
|
||||||
|
const char *const interp[] = { "", "flat", "noperspective" };
|
||||||
|
|
||||||
|
printf(" (%s%s%s%s)\n",
|
||||||
|
cent, inv, mode[ir->mode], interp[ir->interpolation]);
|
||||||
|
|
||||||
|
printf(" (FINISHME: type goes here)\n");
|
||||||
|
printf(" (%s)\n", ir->name);
|
||||||
|
printf(")\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ir_print_visitor::visit(ir_label *ir)
|
||||||
|
{
|
||||||
|
printf("(label %s)\n", ir->label);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ir_print_visitor::visit(ir_function_signature *ir)
|
||||||
|
{
|
||||||
|
printf("%s:%d:\n", __func__, __LINE__);
|
||||||
|
(void) ir;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ir_print_visitor::visit(ir_function *ir)
|
||||||
|
{
|
||||||
|
printf("(function %s\n", ir->name);
|
||||||
|
printf(")\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ir_print_visitor::visit(ir_expression *ir)
|
||||||
|
{
|
||||||
|
printf("%s:%d:\n", __func__, __LINE__);
|
||||||
|
(void) ir;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ir_print_visitor::visit(ir_dereference *ir)
|
||||||
|
{
|
||||||
|
printf("%s:%d:\n", __func__, __LINE__);
|
||||||
|
(void) ir;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ir_print_visitor::visit(ir_assignment *ir)
|
||||||
|
{
|
||||||
|
printf("%s:%d:\n", __func__, __LINE__);
|
||||||
|
(void) ir;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ir_print_visitor::visit(ir_constant *ir)
|
||||||
|
{
|
||||||
|
printf("%s:%d:\n", __func__, __LINE__);
|
||||||
|
(void) ir;
|
||||||
|
}
|
65
ir_print_visitor.h
Normal file
65
ir_print_visitor.h
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2010 Intel Corporation
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice (including the next
|
||||||
|
* paragraph) shall be included in all copies or substantial portions of the
|
||||||
|
* Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#ifndef IR_PRINT_VISITOR_H
|
||||||
|
#define IR_PRINT_VISITOR_H
|
||||||
|
|
||||||
|
#include "ir.h"
|
||||||
|
#include "ir_visitor.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base class of visitors of IR instruction trees
|
||||||
|
*/
|
||||||
|
class ir_print_visitor : public ir_visitor {
|
||||||
|
public:
|
||||||
|
ir_print_visitor()
|
||||||
|
{
|
||||||
|
/* empty */
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~ir_print_visitor()
|
||||||
|
{
|
||||||
|
/* empty */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \name Visit methods
|
||||||
|
*
|
||||||
|
* As typical for the visitor pattern, there must be one \c visit method for
|
||||||
|
* each concrete subclass of \c ir_instruction. Virtual base classes within
|
||||||
|
* the hierarchy should not have \c visit methods.
|
||||||
|
*/
|
||||||
|
/*@{*/
|
||||||
|
virtual void visit(ir_variable *);
|
||||||
|
virtual void visit(ir_label *);
|
||||||
|
virtual void visit(ir_function_signature *);
|
||||||
|
virtual void visit(ir_function *);
|
||||||
|
virtual void visit(ir_expression *);
|
||||||
|
virtual void visit(ir_dereference *);
|
||||||
|
virtual void visit(ir_assignment *);
|
||||||
|
virtual void visit(ir_constant *);
|
||||||
|
/*@}*/
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* IR_PRINT_VISITOR_H */
|
57
ir_visitor.h
Normal file
57
ir_visitor.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2010 Intel Corporation
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice (including the next
|
||||||
|
* paragraph) shall be included in all copies or substantial portions of the
|
||||||
|
* Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#ifndef IR_VISITOR_H
|
||||||
|
#define IR_VISITOR_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base class of visitors of IR instruction trees
|
||||||
|
*/
|
||||||
|
class ir_visitor {
|
||||||
|
public:
|
||||||
|
virtual ~ir_visitor()
|
||||||
|
{
|
||||||
|
/* empty */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \name Visit methods
|
||||||
|
*
|
||||||
|
* As typical for the visitor pattern, there must be one \c visit method for
|
||||||
|
* each concrete subclass of \c ir_instruction. Virtual base classes within
|
||||||
|
* the hierarchy should not have \c visit methods.
|
||||||
|
*/
|
||||||
|
/*@{*/
|
||||||
|
virtual void visit(class ir_variable *) = 0;
|
||||||
|
virtual void visit(class ir_label *) = 0;
|
||||||
|
virtual void visit(class ir_function_signature *) = 0;
|
||||||
|
virtual void visit(class ir_function *) = 0;
|
||||||
|
virtual void visit(class ir_expression *) = 0;
|
||||||
|
virtual void visit(class ir_dereference *) = 0;
|
||||||
|
virtual void visit(class ir_assignment *) = 0;
|
||||||
|
virtual void visit(class ir_constant *) = 0;
|
||||||
|
/*@}*/
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* IR_VISITOR_H */
|
Reference in New Issue
Block a user