Fennel: /home/pub/open/dev/fennel/calculator/InstructionSignature.cpp Source File (original) (raw)

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 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 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 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 00134 InstructionSignature::typeVector( 00135 bool(*typeFunction)(StandardTypeDescriptorOrdinal)) 00136 { 00137 vector 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