17 #include "pcodecompile.hh"
18 #include "filemanage.hh"
34 vector<RtlPair> named;
37 ConstructTpl *getMainSection(
void)
const {
return main.section; }
38 ConstructTpl *getNamedSection(int4 index)
const {
return named[index].section; }
39 RtlPair getMainPair(
void)
const {
return main; }
40 RtlPair getNamedPair(int4 i)
const {
return named[i]; }
41 void setNextIndex(int4 i) { nextindex = i; }
42 int4 getMaxId(
void)
const {
return named.size(); }
71 vector<ContextChange *> contvec;
77 static vector<ContextChange *> *collectAndPrependContext(
const list<WithBlock> &stack, vector<ContextChange *> *contvec);
78 static SubtableSymbol *getCurrentSubtable(
const list<WithBlock> &stack);
84 struct OptimizeRecord {
93 OptimizeRecord(
void) {
94 writeop = -1; readop = -1; inslot=-1; writecount=0; readcount=0; writesection=-2; readsection=-2; opttype=-1; }
97 int4 unnecessarypcode;
101 bool printextwarning;
102 bool printdeadwarning;
103 bool printlargetempwarning;
105 vector<SubtableSymbol *> postorder;
106 map<SubtableSymbol *,int4> sizemap;
108 void printOpName(ostream &s,
OpTpl *op);
109 void printOpError(
OpTpl *op,
Constructor *ct,int4 err1,int4 err2,
const string &message);
114 bool hasLargeTemporary(
OpTpl *op);
124 static void examineVn(map<uintb,OptimizeRecord> &recs,
const VarnodeTpl *vn,uint4 i,int4 inslot,int4 secnum);
126 bool readWriteInterference(
const VarnodeTpl *vn,
const OpTpl *op,
bool checkread)
const;
127 void optimizeGather1(
Constructor *ct,map<uintb,OptimizeRecord> &recs,int4 secnum)
const;
128 void optimizeGather2(
Constructor *ct,map<uintb,OptimizeRecord> &recs,int4 secnum)
const;
129 OptimizeRecord *findValidRule(
Constructor *ct,map<uintb,OptimizeRecord> &recs)
const;
130 void applyOptimization(
Constructor *ct,
const OptimizeRecord &rec);
131 void checkUnusedTemps(
Constructor *ct,
const map<uintb,OptimizeRecord> &recs);
137 bool testTruncations(
bool isbigendian);
138 void optimizeAll(
void);
139 int4 getNumUnnecessaryPcode(
void)
const {
return unnecessarypcode; }
140 int4 getNumReadNoWrite(
void)
const {
return readnowrite; }
141 int4 getNumWriteNoRead(
void)
const {
return writenoread; }
142 int4 getNumLargeTemporaries(
void)
const {
return largetemp;}
155 vector<OpTpl *> &outvec;
156 vector<HandleTpl *> params;
157 bool transferOp(
OpTpl *op,vector<HandleTpl *> ¶ms);
158 virtual void dump(
OpTpl *op );
160 void reportError(
const Location* loc,
const string &val);
163 slgh = sl; haserror =
false; }
164 void setMacroOp(
OpTpl *macroop);
165 bool hasError(
void)
const {
return haserror; }
167 virtual void appendBuild(
OpTpl *bld,int4 secnum) { dump(bld); }
168 virtual void delaySlot(
OpTpl *op) { dump(op); }
169 virtual void setLabel(
OpTpl *op);
170 virtual void appendCrossBuild(
OpTpl *bld,int4 secnum) { dump(bld); }
175 virtual uintb allocateTemp(
void);
177 virtual void reportError(
const Location* loc,
const string &msg);
178 virtual void reportWarning(
const Location* loc,
const string &msg);
190 map<string,string> preproc_defines;
191 vector<FieldContext> contexttable;
192 vector<ConstructTpl *> macrotable;
193 vector<Token *> tokentable;
194 vector<SubtableSymbol *> tables;
195 vector<SectionSymbol *> sections;
196 list<WithBlock> withstack;
200 vector<string> relpath;
201 vector<string> filename;
203 map<Constructor *, Location> ctorLocationMap;
204 map<SleighSymbol *, Location> symbolLocationMap;
206 bool warnunnecessarypcode;
208 bool lenientconflicterrors;
209 bool largetemporarywarning;
210 bool warnalllocalcollisions;
212 vector<string> noplist;
216 const Location* getCurrentLocation(
void)
const;
217 void predefinedSymbols(
void);
218 int4 calcContextVarLayout(int4 start,int4 sz,int4 numbits);
219 void buildDecisionTrees(
void);
220 void buildPatterns(
void);
221 void checkConsistency(
void);
222 static int4 findCollision(map<uintb,int4> &local2Operand,
const vector<uintb> &locals,
int operand);
224 void checkLocalCollisions(
void);
225 void checkNops(
void);
228 SleighSymbol *dedupSymbolList(vector<SleighSymbol *> *symlist);
229 bool expandMacros(
ConstructTpl *ctpl,
const vector<ConstructTpl *> ¯otable);
231 static void shiftUniqueVn(
VarnodeTpl *vn,int4 sa);
232 static void shiftUniqueOp(
OpTpl *op,int4 sa);
233 static void shiftUniqueHandle(
HandleTpl *hand,int4 sa);
234 static void shiftUniqueConstruct(
ConstructTpl *tpl,int4 sa);
235 void checkUniqueAllocation(
void);
240 string formatStatusMessage(
const Location* loc,
const string &msg);
241 void reportError(
const string &msg);
242 void reportError(
const Location *loc,
const string &msg);
243 void reportWarning(
const string &msg);
244 void reportWarning(
const Location *loc,
const string &msg);
245 int4 numErrors(
void)
const {
return errors; }
246 void reportInfo(
const string &msg);
247 void reportInfo(
const Location *loc,
const string &msg);
250 uintb getUniqueAddr(
void);
251 void setUnnecessaryPcodeWarning(
bool val) { warnunnecessarypcode = val; }
252 void setDeadTempWarning(
bool val) { warndeadtemps = val; }
253 void setEnforceLocalKeyWord(
bool val) { pcode.setEnforceLocalKey(val); }
254 void setLargeTemporaryWarning (
bool val) {largetemporarywarning = val;}
255 void setLenientConflict(
bool val) { lenientconflicterrors = val; }
256 void setLocalCollisionWarning(
bool val) { warnalllocalcollisions = val; }
257 void setAllNopWarning(
bool val) { warnallnops = val; }
261 void calcContextLayout(
void);
262 string grabCurrentFilePath(
void)
const;
263 void parseFromNewFile(
const string &fname);
264 void parsePreprocMacro(
void);
265 void parseFileFinished(
void);
266 void nextLine(
void) { lineno.back() += 1; }
267 bool getPreprocValue(
const string &nm,
string &res)
const;
268 void setPreprocValue(
const string &nm,
const string &value);
269 bool undefinePreprocValue(
const string &nm);
272 TokenSymbol *defineToken(
string *name,uintb *sz,int4 endian);
277 void setEndian(int4 end);
278 void setAlignment(int4 val) {
alignment = val; }
279 void defineVarnodes(
SpaceSymbol *spacesym,uintb *off,uintb *size,vector<string> *names);
280 void defineBitrange(
string *name,
VarnodeSymbol *sym,uint4 bitoffset,uint4 numb);
281 void addUserOp(vector<string> *names);
282 void attachValues(vector<SleighSymbol *> *symlist,vector<intb> *numlist);
283 void attachNames(vector<SleighSymbol *> *symlist,vector<string> *names);
284 void attachVarnodes(vector<SleighSymbol *> *symlist,vector<SleighSymbol *> *varlist);
296 MacroSymbol *createMacro(
string *name,vector<string> *param);
297 void compareMacroParams(
MacroSymbol *sym,
const vector<ExprTree *> ¶m);
298 vector<OpTpl *> *createMacroUse(
MacroSymbol *sym,vector<ExprTree *> *param);
305 bool isInRoot(
Constructor *ct)
const {
return (
root == ct->getParent()); }
306 void resetConstructors(
void);
311 void recordNop(
void);