Commit 53218ff7 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Introduced a simple memory pool.

parent 06df2e2d
HEADERS += $$PWD/glsl.h $$PWD/glsllexer.h $$PWD/glslparser.h $$PWD/glslparsertable_p.h $$PWD/glslast.h \
$$PWD/glslastvisitor.h $$PWD/glslengine.h
$$PWD/glslastvisitor.h $$PWD/glslengine.h $$PWD/glslmemorypool.h
SOURCES += $$PWD/glslkeywords.cpp $$PWD/glslparser.cpp $$PWD/glslparsertable.cpp \
$$PWD/glsllexer.cpp $$PWD/glslast.cpp \
$$PWD/glslastvisitor.cpp $$PWD/glslengine.cpp
$$PWD/glslastvisitor.cpp $$PWD/glslengine.cpp $$PWD/glslmemorypool.cpp
OTHER_FILES = $$PWD/glsl.g \
$$PWD/specs/grammar.txt
......@@ -277,6 +277,7 @@ private:
void reduce(int ruleno);
private:
Engine *_engine;
int _tos;
int _index;
std::vector<int> _stateStack;
......@@ -319,6 +320,7 @@ private:
**************************************************************************/
#include "glslparser.h"
#include "glslengine.h"
#include <iostream>
#include <cstdio>
#include <cassert>
......@@ -326,7 +328,7 @@ private:
using namespace GLSL;
Parser::Parser(Engine *engine, const char *source, unsigned size, int variant)
: _tos(-1), _index(0)
: _engine(engine), _tos(-1), _index(0)
{
_tokens.reserve(1024);
......@@ -2602,14 +2604,14 @@ case $rule_number: {
external_declaration_list ::= external_declaration ;
/.
case $rule_number: {
sym(1).declaration_list = new List<Declaration *>(sym(1).declaration);
sym(1).declaration_list = new (_engine->pool()) List<Declaration *>(sym(1).declaration);
} break;
./
external_declaration_list ::= external_declaration_list external_declaration ;
/.
case $rule_number: {
sym(1).declaration_list = new List<Declaration *>(sym(1).declaration_list, sym(2).declaration);
sym(1).declaration_list = new (_engine->pool()) List<Declaration *>(sym(1).declaration_list, sym(2).declaration);
} break;
./
......
......@@ -46,6 +46,7 @@ namespace GLSL {
class Engine;
class Lexer;
class Parser;
class MemoryPool;
class AST;
template <typename T> class List;
}
......
......@@ -30,6 +30,7 @@
#define GLSLAST_H
#include "glsl.h"
#include "glslmemorypool.h"
#include <vector>
#include <string>
......@@ -66,7 +67,7 @@ class StructType;
class Visitor;
template <typename T>
class GLSL_EXPORT List
class GLSL_EXPORT List: public Managed
{
public:
List(const T &value)
......@@ -90,7 +91,7 @@ public:
List *next;
};
class GLSL_EXPORT AST
class GLSL_EXPORT AST // : public Managed
{
public:
enum Kind {
......
......@@ -19,3 +19,8 @@ const std::string *Engine::identifier(const char *s, int n)
{
return &*_identifiers.insert(std::string(s, n)).first;
}
MemoryPool *Engine::pool()
{
return &_pool;
}
......@@ -2,6 +2,7 @@
#define GLSLENGINE_H
#include "glsl.h"
#include "glslmemorypool.h"
#include <set>
#include <string>
......@@ -16,8 +17,11 @@ public:
const std::string *identifier(const std::string &s);
const std::string *identifier(const char *s, int n);
MemoryPool *pool();
private:
std::set<std::string> _identifiers;
MemoryPool _pool;
};
} // namespace GLSL
......
This diff is collapsed.
......@@ -68,6 +68,7 @@ private:
void reduce(int ruleno);
private:
Engine *_engine;
int _tos;
int _index;
std::vector<int> _stateStack;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment