home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * get.c
- * Copyright © 1992 Niklas Röjemo
- */
-
- #include "get.h"
- #include "error.h"
- #include "input.h"
- #include "lex.h"
- #include "symbol.h"
- #include "expr.h"
- #include "reloc.h"
- #include "help_cpu.h"
- #include "fix.h"
-
- WORD getCpuReg(void)
- {
- Symbol *sym = symbolGet(lexGetId());
-
- if(sym->type & SYMBOL_DEFINED && sym->type & SYMBOL_ABSOLUTE) {
- if(SYMBOL_GETREG(sym->type) == SYMBOL_CPUREG)
- return sym->value.ValueInt.i;
- else
- error(ErrorError,TRUE,"'%s' (=%d) is not a cpu register.",sym->str,sym->value);
- } else
- error(ErrorError,TRUE,"Undefined register %s.",sym->str);
- return 0;
- }
-
- WORD getFpuReg(void)
- {
- Symbol *sym = symbolGet(lexGetId());
-
- if(sym->type & SYMBOL_DEFINED && sym->type & SYMBOL_ABSOLUTE) {
- if(SYMBOL_GETREG(sym->type) == SYMBOL_FPUREG)
- return sym->value.ValueInt.i;
- else
- error(ErrorError,TRUE,"'%s' (=%d) is not a fpu register.",sym->str,sym->value);
- } else
- error(ErrorError,TRUE,"Undefined float register %s.",sym->str);
- return 0;
- }
-
- WORD getCopReg(void)
- {
- Symbol *sym = symbolGet(lexGetId());
-
- if(sym->type & SYMBOL_DEFINED && sym->type & SYMBOL_ABSOLUTE) {
- if(SYMBOL_GETREG(sym->type) == SYMBOL_COPREG)
- return sym->value.ValueInt.i;
- else
- error(ErrorError,TRUE,"'%s' (=%d) is not a cop register.",sym->str,sym->value);
- } else
- error(ErrorError,TRUE,"Undefined coprocessor register %s.",sym->str);
- return 0;
- }
-
- static WORD getShiftOp(void)
- {
- WORD r;
- switch(inputLook()) {
- case 'a':case 'A':
- if(inputLookN(1) == 's' || inputLookN(1) == 'S') {
- switch(inputLookN(2)) {
- case 'l':case 'L': r = ASL; inputSkipN(3); break;
- case 'r':case 'R': r = ASR; inputSkipN(3); break;
- default: goto illegal;
- }
- } else
- goto illegal;
- break;
- case 'l':case 'L':
- if(inputLookN(1) == 's' || inputLookN(1) == 'S') {
- switch(inputLookN(2)) {
- case 'l':case 'L': r = LSL; inputSkipN(3); break;
- case 'r':case 'R': r = LSR; inputSkipN(3); break;
- default: goto illegal;
- }
- } else
- goto illegal;
- break;
- case 'r':case 'R':
- switch(inputLookN(1)) {
- case 'o':case 'O':
- if(inputLookN(2) == 'r' || inputLookN(2) == 'R') { r = ROR; inputSkipN(3); break;}
- else goto illegal;
- case 'r':case 'R':
- if(inputLookN(2) == 'x' || inputLookN(2) == 'X') { r = RRX; inputSkipN(3); break;}
- else goto illegal;
- default: goto illegal;
- }
- break;
- default:
- illegal:
- error(ErrorError,TRUE,"Illegal shiftop %c%c%c.",inputLook(),inputLookN(1),inputLookN(2));
- }
- return r;
- }
-
-
- static WORD getShift(BOOL immonly)
- {
- WORD shift;
- WORD op = 0;
- Value im;
- shift = getShiftOp();
-
- if(shift != RRX) {
- skipblanks();
- if(inputLook() == '#') {
- inputSkip();
- exprBuild();
- im = exprEval(ValueInt | ValueCode|ValueLateLabel);
- switch(im.Tag) {
- case ValueInt:
- op = fixShiftImm(inputLineNo,shift,im.ValueInt.i); /* !! Fixed !! */
- break;
- case ValueCode: case ValueLateLabel:
- relocShiftImm(shift,im);
- op = SHIFT_OP(shift); /* !! Fixed !! */
- break;
- default:
- error(ErrorError,TRUE,"Illegal shift expression.");
- break;
- }
- } else {
- if(immonly) {
- error(ErrorError,TRUE,"Only shift immediate allowed here.");
- } else {
- op = SHIFT_REG(getCpuReg()) | SHIFT_OP(shift);
- }
- }
- } else
- op = SHIFT_OP(shift);
- return op;
- }
-
- WORD getRhs(BOOL immonly, WORD ir)
- {
- Value im;
- if(inputLook() == '#') {
- ir |= IMM_RHS;
- inputSkip();
- exprBuild();
- im = exprEval(ValueInt | ValueCode|ValueLateLabel);
- switch(im.Tag) {
- case ValueInt:
- ir = fixImm8s4(inputLineNo,ir,im.ValueInt.i);
- break;
- case ValueCode: case ValueLateLabel:
- relocImm8s4(ir,im);
- break;
- default:
- error(ErrorError,TRUE,"Illegal immediate expression.");
- break;
- }
- } else {
- ir |= getCpuReg();
- skipblanks();
- if(inputLook() == ',') {
- inputSkip();
- skipblanks();
- ir |= getShift(immonly);
- } else {
- ir |= NO_SHIFT;
- }
- }
- return ir;
- }
-