00001
00002
00003
00004
00005
00006 #include "global.h"
00007 #include "decoder.h"
00008 #include "mc68k.pat.h"
00009 #include "ss.h"
00010 #include "csr.h"
00011
00012 #define VAR true
00013 #define VAL false
00014 int InstructionPatterns::SP = 7;
00015 int InstructionPatterns::FP = 6;
00016 bool InstructionPatterns::Aline(ADDRESS& lc, int& a, bool a_isVAR) {
00017 ADDRESS nextPC;
00018 match lc to
00019 | Aline(_a) =>
00020 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00021 lc = nextPC;
00022 return true;
00023 else
00024 return false;
00025 endmatch
00026 }
00027 bool InstructionPatterns::addaw_d16(ADDRESS& lc, int& a, bool a_isVAR) {
00028 ADDRESS nextPC;
00029 match lc to
00030 | addaw_d16(_a) =>
00031 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00032 lc = nextPC;
00033 return true;
00034 else
00035 return false;
00036 endmatch
00037 }
00038 bool InstructionPatterns::addil$daIndirect(ADDRESS& lc, int& a, bool a_isVAR, int& b, bool b_isVAR) {
00039 ADDRESS nextPC;
00040 match lc to
00041 | addil(_a, _b) =>
00042 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00043 if (!daIndirect(_b, b, b_isVAR)) return false;
00044 lc = nextPC;
00045 return true;
00046 else
00047 return false;
00048 endmatch
00049 }
00050 bool InstructionPatterns::bsr(ADDRESS& lc, int& a, bool a_isVAR) {
00051 ADDRESS nextPC;
00052 match lc to
00053 | bsr(_a) =>
00054 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00055 lc = nextPC;
00056 return true;
00057 else
00058 return false;
00059 endmatch
00060 }
00061 bool InstructionPatterns::call_(ADDRESS& lc, int& a, bool a_isVAR) {
00062 ADDRESS nextPC;
00063 match lc to
00064 | call_(_a) =>
00065 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00066 lc = nextPC;
00067 return true;
00068 else
00069 return false;
00070 endmatch
00071 }
00072 bool InstructionPatterns::daIndirect(ADDRESS& lc, int& a, bool a_isVAR) {
00073 match lc to
00074 | daIndirect(_a) =>
00075 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00076 return true;
00077 else
00078 return false;
00079 endmatch
00080 }
00081 bool InstructionPatterns::daPostInc(ADDRESS& lc, int& a, bool a_isVAR) {
00082 match lc to
00083 | daPostInc(_a) =>
00084 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00085 return true;
00086 else
00087 return false;
00088 endmatch
00089 }
00090 bool InstructionPatterns::daPreDec(ADDRESS& lc, int& a, bool a_isVAR) {
00091 match lc to
00092 | daPreDec(_a) =>
00093 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00094 return true;
00095 else
00096 return false;
00097 endmatch
00098 }
00099 bool InstructionPatterns::leaSpSp(ADDRESS& lc, int& a, bool a_isVAR) {
00100 ADDRESS nextPC;
00101 match lc to
00102 | leaSpSp(_a) =>
00103 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00104 lc = nextPC;
00105 return true;
00106 else
00107 return false;
00108 endmatch
00109 }
00110 bool InstructionPatterns::link(ADDRESS& lc, int& a, bool a_isVAR, int& b, bool b_isVAR) {
00111 ADDRESS nextPC;
00112 match lc to
00113 | link(_a, _b) =>
00114 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00115 if (!b_isVAR && (int)_b != b) return false; else b = _b;
00116 lc = nextPC;
00117 return true;
00118 else
00119 return false;
00120 endmatch
00121 }
00122 bool InstructionPatterns::movemrl$daPostInc(ADDRESS& lc, int& a, bool a_isVAR, int& b, bool b_isVAR) {
00123 ADDRESS nextPC;
00124 match lc to
00125 | movemrl(_a, _b) =>
00126 if (!daPostInc(_a, a, a_isVAR)) return false;
00127 if (!b_isVAR && (int)_b != b) return false; else b = _b;
00128 lc = nextPC;
00129 return true;
00130 else
00131 return false;
00132 endmatch
00133 }
00134 bool InstructionPatterns::moverml$daPreDec(ADDRESS& lc, int& a, bool a_isVAR, int& b, bool b_isVAR) {
00135 ADDRESS nextPC;
00136 match lc to
00137 | moverml(_a, _b) =>
00138 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00139 if (!daPreDec(_b, b, b_isVAR)) return false;
00140 lc = nextPC;
00141 return true;
00142 else
00143 return false;
00144 endmatch
00145 }
00146 bool InstructionPatterns::peaPcDisp(ADDRESS& lc, int& a, bool a_isVAR) {
00147 ADDRESS nextPC;
00148 match lc to
00149 | peaPcDisp(_a) =>
00150 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00151 lc = nextPC;
00152 return true;
00153 else
00154 return false;
00155 endmatch
00156 }
00157 bool InstructionPatterns::popreg(ADDRESS& lc, int& a, bool a_isVAR) {
00158 ADDRESS nextPC;
00159 match lc to
00160 | popreg(_a) =>
00161 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00162 lc = nextPC;
00163 return true;
00164 else
00165 return false;
00166 endmatch
00167 }
00168 bool InstructionPatterns::pushreg(ADDRESS& lc, int& a, bool a_isVAR) {
00169 ADDRESS nextPC;
00170 match lc to
00171 | pushreg(_a) =>
00172 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00173 lc = nextPC;
00174 return true;
00175 else
00176 return false;
00177 endmatch
00178 }
00179 bool InstructionPatterns::rts(ADDRESS& lc) {
00180 ADDRESS nextPC;
00181 match lc to
00182 | rts() =>
00183 lc = nextPC;
00184 return true;
00185 else
00186 return false;
00187 endmatch
00188 }
00189 bool InstructionPatterns::trap(ADDRESS& lc, int& a, bool a_isVAR) {
00190 ADDRESS nextPC;
00191 match lc to
00192 | trap(_a) =>
00193 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00194 lc = nextPC;
00195 return true;
00196 else
00197 return false;
00198 endmatch
00199 }
00200 bool InstructionPatterns::unlk(ADDRESS& lc, int& a, bool a_isVAR) {
00201 ADDRESS nextPC;
00202 match lc to
00203 | unlk(_a) =>
00204 if (!a_isVAR && (int)_a != a) return false; else a = _a;
00205 lc = nextPC;
00206 return true;
00207 else
00208 return false;
00209 endmatch
00210 }
00211 Logue* InstructionPatterns::std_call(CSR& csr, ADDRESS& lc, int& addr)
00212 {
00213 ADDRESS __save = lc;
00214 if (
00215 call_(lc, addr, VAR)) {
00216 vector<int> params(1); params = addr;
00217 if (__save == lc) return NULL;
00218 return csr.instantiateLogue("std_call",params);
00219 } else {
00220 lc = __save;
00221 return NULL;
00222 }
00223 }
00224 Logue* InstructionPatterns::near_call(CSR& csr, ADDRESS& lc, int& addr)
00225 {
00226 ADDRESS __save = lc;
00227 if (
00228 bsr(lc, addr, VAR)) {
00229 vector<int> params(1); params = addr;
00230 if (__save == lc) return NULL;
00231 return csr.instantiateLogue("near_call",params);
00232 } else {
00233 lc = __save;
00234 return NULL;
00235 }
00236 }
00237 Logue* InstructionPatterns::pea_add_rts(CSR& csr, ADDRESS& lc, int& d32)
00238 {
00239 ADDRESS __save = lc;
00240 int __loc0;
00241 if (
00242 peaPcDisp(lc, __loc0 = 4, VAL) &&
00243 addil$daIndirect(lc, d32, VAR, SP, VAL) &&
00244 rts(lc)) {
00245 vector<int> params(1); params = d32;
00246 if (__save == lc) return NULL;
00247 return csr.instantiateLogue("pea_add_rts",params);
00248 } else {
00249 lc = __save;
00250 return NULL;
00251 }
00252 }
00253 Logue* InstructionPatterns::pea_pea_add_rts(CSR& csr, ADDRESS& lc, int& d32)
00254 {
00255 ADDRESS __save = lc;
00256 int __loc0;
00257 if (
00258 peaPcDisp(lc, __loc0 = 14, VAL) &&
00259 peaPcDisp(lc, __loc0 = 4, VAL) &&
00260 addil$daIndirect(lc, d32, VAR, SP, VAL) &&
00261 rts(lc)) {
00262 vector<int> params(1); params = d32;
00263 if (__save == lc) return NULL;
00264 return csr.instantiateLogue("pea_pea_add_rts",params);
00265 } else {
00266 lc = __save;
00267 return NULL;
00268 }
00269 }
00270 Logue* InstructionPatterns::trap_syscall(CSR& csr, ADDRESS& lc, int& d16)
00271 {
00272 ADDRESS __save = lc;
00273 int __loc0;
00274 if (
00275 trap(lc, __loc0 = 15, VAL) &&
00276 Aline(lc, d16, VAR)) {
00277 vector<int> params(1); params = d16;
00278 if (__save == lc) return NULL;
00279 return csr.instantiateLogue("trap_syscall",params);
00280 } else {
00281 lc = __save;
00282 return NULL;
00283 }
00284 }
00285 Logue* InstructionPatterns::std_link(CSR& csr, ADDRESS& lc, int& locals)
00286 {
00287 ADDRESS __save = lc;
00288 if (
00289 link(lc, FP, VAL, locals, VAR)) {
00290 vector<int> params(1); params = locals;
00291 if (__save == lc) return NULL;
00292 return csr.instantiateLogue("std_link",params);
00293 } else {
00294 lc = __save;
00295 return NULL;
00296 }
00297 }
00298 Logue* InstructionPatterns::link_save(CSR& csr, ADDRESS& lc, int& locals, int& d16)
00299 {
00300 ADDRESS __save = lc;
00301 if (
00302 link(lc, FP, VAL, locals, VAR) &&
00303 moverml$daPreDec(lc, d16, VAR, SP, VAL)) {
00304 vector<int> params(2); params = locals; params = d16;
00305 if (__save == lc) return NULL;
00306 return csr.instantiateLogue("link_save",params);
00307 } else {
00308 lc = __save;
00309 return NULL;
00310 }
00311 }
00312 Logue* InstructionPatterns::link_save1(CSR& csr, ADDRESS& lc, int& locals, int& reg)
00313 {
00314 ADDRESS __save = lc;
00315 if (
00316 link(lc, FP, VAL, locals, VAR) &&
00317 pushreg(lc, reg, VAR)) {
00318 vector<int> params(2); params = locals; params = reg;
00319 if (__save == lc) return NULL;
00320 return csr.instantiateLogue("link_save1",params);
00321 } else {
00322 lc = __save;
00323 return NULL;
00324 }
00325 }
00326 Logue* InstructionPatterns::push_lea(CSR& csr, ADDRESS& lc, int& locals, int& reg)
00327 {
00328 ADDRESS __save = lc;
00329 if (
00330 pushreg(lc, reg, VAR) &&
00331 leaSpSp(lc, locals, VAR)) {
00332 vector<int> params(2); params = locals; params = reg;
00333 if (__save == lc) return NULL;
00334 return csr.instantiateLogue("push_lea",params);
00335 } else {
00336 lc = __save;
00337 return NULL;
00338 }
00339 }
00340 Logue* InstructionPatterns::bare_ret(CSR& csr, ADDRESS& lc)
00341 {
00342 ADDRESS __save = lc;
00343 if (
00344 rts(lc)) {
00345 vector<int> params(0);
00346 if (__save == lc) return NULL;
00347 return csr.instantiateLogue("bare_ret",params);
00348 } else {
00349 lc = __save;
00350 return NULL;
00351 }
00352 }
00353 Logue* InstructionPatterns::std_ret(CSR& csr, ADDRESS& lc)
00354 {
00355 ADDRESS __save = lc;
00356 if (
00357 unlk(lc, FP, VAL) &&
00358 rts(lc)) {
00359 vector<int> params(0);
00360 if (__save == lc) return NULL;
00361 return csr.instantiateLogue("std_ret",params);
00362 } else {
00363 lc = __save;
00364 return NULL;
00365 }
00366 }
00367 Logue* InstructionPatterns::rest_ret(CSR& csr, ADDRESS& lc, int& d16)
00368 {
00369 ADDRESS __save = lc;
00370 if (
00371 movemrl$daPostInc(lc, SP, VAL, d16, VAR) &&
00372 unlk(lc, FP, VAL) &&
00373 rts(lc)) {
00374 vector<int> params(1); params = d16;
00375 if (__save == lc) return NULL;
00376 return csr.instantiateLogue("rest_ret",params);
00377 } else {
00378 lc = __save;
00379 return NULL;
00380 }
00381 }
00382 Logue* InstructionPatterns::rest1_ret(CSR& csr, ADDRESS& lc, int& reg)
00383 {
00384 ADDRESS __save = lc;
00385 if (
00386 popreg(lc, reg, VAR) &&
00387 unlk(lc, FP, VAL) &&
00388 rts(lc)) {
00389 vector<int> params(1); params = reg;
00390 if (__save == lc) return NULL;
00391 return csr.instantiateLogue("rest1_ret",params);
00392 } else {
00393 lc = __save;
00394 return NULL;
00395 }
00396 }
00397 Logue* InstructionPatterns::pop_ret(CSR& csr, ADDRESS& lc, int& reg)
00398 {
00399 ADDRESS __save = lc;
00400 if (
00401 popreg(lc, reg, VAR) &&
00402 rts(lc)) {
00403 vector<int> params(1); params = reg;
00404 if (__save == lc) return NULL;
00405 return csr.instantiateLogue("pop_ret",params);
00406 } else {
00407 lc = __save;
00408 return NULL;
00409 }
00410 }
00411 Logue* InstructionPatterns::clear_stack(CSR& csr, ADDRESS& lc, int& n)
00412 {
00413 ADDRESS __save = lc;
00414 if (
00415 (leaSpSp(lc, n, VAR) ||
00416 addaw_d16(lc, n, VAR))) {
00417 vector<int> params(1); params = n;
00418 if (__save == lc) return NULL;
00419 return csr.instantiateLogue("clear_stack",params);
00420 } else {
00421 lc = __save;
00422 return NULL;
00423 }
00424 }
00425 LogueDict::LogueDict()
00426 {
00427 {
00428 list<string> params;
00429 params.push_back("addr");
00430 theSemTable.addItem("addr");
00431 this->newLogue("std_call","CALLER_PROLOGUE",params);
00432 }
00433 {
00434 list<string> params;
00435 params.push_back("addr");
00436 theSemTable.addItem("addr");
00437 this->newLogue("near_call","CALLER_PROLOGUE",params);
00438 }
00439 {
00440 list<string> params;
00441 params.push_back("d32");
00442 theSemTable.addItem("d32");
00443 this->newLogue("pea_add_rts","CALLER_PROLOGUE",params);
00444 }
00445 {
00446 list<string> params;
00447 params.push_back("d32");
00448 theSemTable.addItem("d32");
00449 this->newLogue("pea_pea_add_rts","CALLER_PROLOGUE",params);
00450 }
00451 {
00452 list<string> params;
00453 params.push_back("d16");
00454 theSemTable.addItem("d16");
00455 this->newLogue("trap_syscall","CALLER_PROLOGUE",params);
00456 }
00457 {
00458 list<string> params;
00459 params.push_back("locals");
00460 theSemTable.addItem("locals");
00461 this->newLogue("std_link","CALLEE_PROLOGUE",params);
00462 }
00463 {
00464 list<string> params;
00465 params.push_back("locals");
00466 theSemTable.addItem("locals");
00467 params.push_back("d16");
00468 theSemTable.addItem("d16");
00469 this->newLogue("link_save","CALLEE_PROLOGUE",params);
00470 }
00471 {
00472 list<string> params;
00473 params.push_back("locals");
00474 theSemTable.addItem("locals");
00475 params.push_back("reg");
00476 theSemTable.addItem("reg");
00477 this->newLogue("link_save1","CALLEE_PROLOGUE",params);
00478 }
00479 {
00480 list<string> params;
00481 params.push_back("locals");
00482 theSemTable.addItem("locals");
00483 params.push_back("reg");
00484 theSemTable.addItem("reg");
00485 this->newLogue("push_lea","CALLEE_PROLOGUE",params);
00486 }
00487 {
00488 list<string> params;
00489 this->newLogue("bare_ret","CALLEE_PROLOGUE",params);
00490 }
00491 {
00492 list<string> params;
00493 this->newLogue("std_ret","CALLEE_EPILOGUE",params);
00494 }
00495 {
00496 list<string> params;
00497 params.push_back("d16");
00498 theSemTable.addItem("d16");
00499 this->newLogue("rest_ret","CALLEE_EPILOGUE",params);
00500 }
00501 {
00502 list<string> params;
00503 params.push_back("reg");
00504 theSemTable.addItem("reg");
00505 this->newLogue("rest1_ret","CALLEE_EPILOGUE",params);
00506 }
00507 {
00508 list<string> params;
00509 params.push_back("reg");
00510 theSemTable.addItem("reg");
00511 this->newLogue("pop_ret","CALLEE_EPILOGUE",params);
00512 }
00513 {
00514 list<string> params;
00515 params.push_back("n");
00516 theSemTable.addItem("n");
00517 this->newLogue("clear_stack","CALLER_EPILOGUE",params);
00518 }
00519 }