Folder.h

Go to the documentation of this file.
00001 /*
00002  *      Folder.h - The core of the folding utility
00003  *
00004  *  Copyright (C) 2002-2003 The Pentagram Team
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #ifndef FOLDER_H
00022 #define FOLDER_H
00023 
00024 #include "GenericNodes.h"
00025 #include "IfNode.h"
00026 #include "CallNodes.h"
00027 #include "FuncNodes.h"
00028 #include "CommonBases.h"
00029 
00030 #include <deque>
00031 #include <set>
00032 
00033 class Unit
00034 {
00035         public:
00036                 Unit(const uint32 _id) : id(_id) {};
00037                 
00038                 void print_extern_unk(Console &o, const uint32 isize) const;
00039                 void print_unk(Console &o, const uint32 isize) const;
00040                 void print_asm(Console &o) const;
00041                 void print_bin(ODequeDataSource &o) const;
00042                 
00043                 std::string name; // the cannonical name of the unit
00044                 uint32 id; // the cannonical id number of the class
00045                 
00046                 std::set<DCCallNode *>   externFuncs;
00047                 std::set<DCCallNode *>   externIntrinsics;
00048                 std::deque<DCFuncNode *> functions;
00049 };
00050 
00051 class DCUnit : public Unit
00052 {
00053         public:
00054                 DCUnit(const uint32 _id) : Unit(_id), debugOffset(0) {};
00055                 
00056                 const bool fold(Node *n);
00057                 
00058                 void setDebugOffset(const uint32 newDebugOffset) { debugOffset=newDebugOffset; };
00059                 void setClassName(const std::string &newName) { name=newName; };
00060                 void registerExternIntrinsic(DCCallNode *i) { externIntrinsics.insert(i); };
00061                 void registerExternFunc(DCCallNode *f) { externFuncs.insert(f); };
00062                 
00063                 void setJump(IfNode *in) { ifstack.push_back(in); };
00064                 const std::deque<IfNode *> &IfStack() const { return ifstack; };
00065                 
00066         private:
00067                 std::deque<Node *> nodes;
00068                 /* a bizzare way of walking through the if stack:
00069                         Now the general way we're going to walk through and correctly associate
00070                         a if{...} with the appropriate nodes list when called is that for
00071                 */
00072                 std::deque<IfNode *> ifstack;
00073                 std::deque<IfNode *> elsestack;
00074                 
00075                 uint32 debugOffset;
00076 
00077                 friend bool print_assert(const Node *n, const DCUnit *u);
00078 };
00079 
00080 class Folder
00081 {
00082         public:
00083                 Folder() : curr(0), num(10) {};
00084                 ~Folder() {};
00085                 void fold(Node *n);
00086 
00087                 void print_unk(Console &o) const;
00088                 void print_asm(Console &o) const;
00089                 void print_bin(ODequeDataSource &o) const;
00090 
00091                 inline void SelectUnit(const uint32 id)
00092                 {
00094                         if(curr!=0 && curr->id!=id)
00095                                 NewUnit(id);
00096                         else if(curr==0)
00097                                 NewUnit(id);
00098                         // else, the id==the old one, so we don't need to change units, return.
00099                 };
00100                 
00101                 inline void NewUnit(const uint32 id)
00102                 {
00103                         if(curr!=0) units.push_back(curr);
00104                         curr = new DCUnit(id);
00105                 };
00106                 
00107                 inline void FinalUnit()
00108                 {
00109                         if(curr!=0)
00110                                 units.push_back(curr);
00111                         curr=0;
00112                 }
00113 
00114         private:
00115                 DCUnit *curr;
00116                 std::deque<DCUnit *> units;
00117                 uint32 num;
00118 };
00119 
00120 
00121 #endif

Generated on Fri Jul 27 22:27:15 2007 for pentagram by  doxygen 1.4.7