InstructionSignature.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/calculator/InstructionSignature.cpp#3 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2004-2009 SQLstream, Inc.
00006 // Copyright (C) 2009-2009 LucidEra, Inc.
00007 //
00008 // This program is free software; you can redistribute it and/or modify it
00009 // under the terms of the GNU General Public License as published by the Free
00010 // Software Foundation; either version 2 of the License, or (at your option)
00011 // any later version approved by The Eigenbase Project.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 #include "fennel/common/CommonPreamble.h"
00024 #include "fennel/calculator/InstructionSignature.h"
00025 
00026 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/calculator/InstructionSignature.cpp#3 $");
00027 
00028 InstructionSignature::InstructionSignature(
00029     string const & name)
00030     : name(name),
00031       hasRegisters(false),
00032       hasPc(false)
00033 {
00034 }
00035 
00036 InstructionSignature::InstructionSignature(
00037     string const & name,
00038     vector<StandardTypeDescriptorOrdinal>
00039     const &operands)
00040     : name(name),
00041       types(operands),
00042       hasRegisters(false),
00043       hasPc(false)
00044 {
00045 }
00046 
00047 InstructionSignature::InstructionSignature(
00048     string const & name,
00049     vector<RegisterReference*> const & operands)
00050     : name(name),
00051       registers(operands),
00052       hasRegisters(true),
00053       hasPc(false)
00054 {
00055     registersToTypes();
00056 }
00057 
00058 InstructionSignature::InstructionSignature(
00059     string const & name,
00060     TProgramCounter pc,
00061     vector<StandardTypeDescriptorOrdinal>
00062     const &operands)
00063     : name(name),
00064       types(operands),
00065       hasRegisters(false),
00066       pc(pc),
00067       hasPc(true)
00068 {
00069 }
00070 
00071 InstructionSignature::InstructionSignature(
00072     string const & name,
00073     TProgramCounter pc,
00074     vector<RegisterReference*> const & operands)
00075     : name(name),
00076       registers(operands),
00077       hasRegisters(true),
00078       pc(pc),
00079       hasPc(true)
00080 {
00081     registersToTypes();
00082 }
00083 
00084 string
00085 InstructionSignature::compute() const
00086 {
00087     ostringstream ostr;
00088     uint size = types.size();
00089 
00090     ostr << name << "(";
00091     if (hasPc) {
00092         ostr << "PC";
00093         if (size) {
00094             ostr << ",";
00095         }
00096     }
00097     for (uint i = 0; i < size; i++) {
00098         if (i > 0) {
00099             ostr << ",";
00100         }
00101         ostr << StandardTypeDescriptor::toString(types[i]);
00102     }
00103     ostr << ")";
00104     return ostr.str();
00105 }
00106 
00107 string
00108 InstructionSignature::getName() const
00109 {
00110     return name;
00111 }
00112 
00113 RegisterReference*
00114 InstructionSignature::operator[] (uint index) const
00115 {
00116     assert(hasRegisters);
00117     return registers[index];
00118 }
00119 
00120 uint
00121 InstructionSignature::size() const
00122 {
00123     return types.size();
00124 }
00125 
00126 TProgramCounter
00127 InstructionSignature::getPc() const
00128 {
00129     assert(hasPc);
00130     return pc;
00131 }
00132 
00133 vector<StandardTypeDescriptorOrdinal>
00134 InstructionSignature::typeVector(
00135     bool(*typeFunction)(StandardTypeDescriptorOrdinal))
00136 {
00137     vector<StandardTypeDescriptorOrdinal> v;
00138     int iter;
00139     StandardTypeDescriptorOrdinal iter2;
00140     assert(STANDARD_TYPE_MIN < STANDARD_TYPE_END_NO_UNICODE);
00141     assert(STANDARD_TYPE_MIN == STANDARD_TYPE_INT_8);
00142     assert(STANDARD_TYPE_END_NO_UNICODE == STANDARD_TYPE_VARBINARY + 1);
00143 
00144     for (iter = STANDARD_TYPE_MIN; iter < STANDARD_TYPE_END_NO_UNICODE;
00145          iter++)
00146     {
00147         iter2 = StandardTypeDescriptorOrdinal(iter);
00148         if (typeFunction(iter2)) {
00149             v.push_back(iter2);
00150         }
00151     }
00152 
00153     return v;
00154 }
00155 
00156 void
00157 InstructionSignature::registersToTypes()
00158 {
00159     for (uint i = 0; i < registers.size(); i++) {
00160         assert(registers[i] != NULL);
00161         types.push_back(registers[i]->type());
00162     }
00163 
00164 }
00165 
00166 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/calculator/InstructionSignature.cpp#3 $");
00167 
00168 // End InstructionSignature.cpp

Generated on Mon Jun 22 04:00:17 2009 for Fennel by  doxygen 1.5.1