unsigned sc61860_dasm(char *dst, unsigned oldpc) { int pc=oldpc; int oper=PEEK_OP(pc++); int t; UINT16 adr; switch(oper&0xc0) { case 0x80: sprintf(dst,"%-6s%.2x",table[oper&0x80].mnemonic, oper&0x3f); break; default: switch(oper&0xe0) { case 0xe0: sprintf(dst,"%-6s%.4x",table[oper&0xe0].mnemonic, PEEK_OP(pc++)|((oper&0x1f)<<8)); break; default: switch (table[oper].adr) { case Ill: sprintf(dst,"?%.2x",oper);break; case Imp: sprintf(dst,"%s",table[oper].mnemonic); break; case Imm: sprintf(dst,"%-6s%.2x",table[oper].mnemonic, PEEK_OP(pc++)); break; case ImmW: adr=(PEEK_OP(pc)<<8)|PEEK_OP(pc+1);pc+=2; sprintf(dst,"%-6s%.4x",table[oper].mnemonic, adr); break; case Abs: adr=(PEEK_OP(pc)<<8)|PEEK_OP(pc+1);pc+=2; sprintf(dst,"%-6s%.4x",table[oper].mnemonic, adr); break; case RelM: adr=pc-PEEK_OP(pc++); sprintf(dst,"%-6s%.4x",table[oper].mnemonic, adr&0xffff); break; case RelP: adr=pc+PEEK_OP(pc++); sprintf(dst,"%-6s%.4x",table[oper].mnemonic, adr&0xffff); break; case Ptc: t=PEEK_OP(pc++); adr=(PEEK_OP(pc)<<8)|PEEK_OP(pc+1);pc+=2; sprintf(dst,"%-6s%.2x,%.4x",table[oper].mnemonic,t, adr); break; case Etc: sprintf(dst,"%-6s",table[oper].mnemonic); /*H imm, abs */ /* abs */ break; case Cal: case Lp: break; } break; } break; } return pc-oldpc; }
static Expr* WFS_ExprBuildInternal(char*** ppapszTokens, ExprBuildContext* psBuildContext) { Expr* expr = NULL; Expr* op = NULL; Expr* val1 = NULL; Expr* val2 = NULL; CPLList* psValExprList = NULL; CPLList* psOpExprList = NULL; char** papszTokens = *ppapszTokens; char* pszToken = NULL; #define PEEK_OP(my_op) my_op = (Expr*)CPLListGetData(psOpExprList) #define PUSH_OP(my_op) psOpExprList = CPLListInsert(psOpExprList, my_op, 0) #define POP_OP(my_op) do { my_op = (Expr*)CPLListGetData(psOpExprList); \ if (my_op != NULL) { \ CPLList* psNext = psOpExprList->psNext; \ CPLFree(psOpExprList); \ psOpExprList = psNext; \ } \ } while(0) #define PUSH_VAL(my_val) psValExprList = CPLListInsert(psValExprList, my_val, 0) #define POP_VAL(my_val) do { my_val = (Expr*)CPLListGetData(psValExprList); \ if (my_val != NULL) { \ CPLList* psNext = psValExprList->psNext; \ CPLFree(psValExprList); \ psValExprList = psNext; \ } \ } while(0) while(TRUE) { pszToken = *papszTokens; if (pszToken == NULL) break; papszTokens ++; if (EQUAL(pszToken, "(")) { char** papszSub = papszTokens; psBuildContext->nParenthesisLevel ++; Expr* expr = WFS_ExprBuildInternal(&papszSub, psBuildContext); psBuildContext->nParenthesisLevel --; if (expr == NULL) goto invalid_expr; PUSH_VAL(expr); papszTokens = papszSub; if (*papszTokens == NULL) break; continue; } else if (EQUAL(pszToken, ")")) { if (psBuildContext->nParenthesisLevel > 0) break; else goto invalid_expr; } if (psBuildContext->bExpectVarName) { if (EQUAL(pszToken, "NOT")) op = WFS_ExprBuildOperator(TOKEN_NOT); else { PUSH_VAL(WFS_ExprBuildVarName(pszToken)); psBuildContext->bExpectVarName = FALSE; psBuildContext->bExpectComparisonOperator = TRUE; } } else if (psBuildContext->bExpectComparisonOperator) { psBuildContext->bExpectComparisonOperator = FALSE; psBuildContext->bExpectValue = TRUE; if (EQUAL(pszToken, "IS")) { if (*papszTokens != NULL && EQUAL(*papszTokens, "NOT")) { op = WFS_ExprBuildOperator(TOKEN_NOT_EQUAL); papszTokens ++; } else op = WFS_ExprBuildOperator(TOKEN_EQUAL); } else if (EQUAL(pszToken, "=")) op = WFS_ExprBuildOperator(TOKEN_EQUAL); else if (EQUAL(pszToken, "LIKE") || EQUAL(pszToken, "ILIKE")) op = WFS_ExprBuildOperator(TOKEN_LIKE); else if (EQUAL(pszToken, "!=") || EQUAL(pszToken, "<>")) op = WFS_ExprBuildOperator(TOKEN_NOT_EQUAL); else if (EQUAL(pszToken, "<")) op = WFS_ExprBuildOperator(TOKEN_LESSER); else if (EQUAL(pszToken, "<=")) op = WFS_ExprBuildOperator(TOKEN_LESSER_OR_EQUAL); else if (EQUAL(pszToken, ">")) op = WFS_ExprBuildOperator(TOKEN_GREATER); else if (EQUAL(pszToken, ">=")) op = WFS_ExprBuildOperator(TOKEN_GREATER_OR_EQUAL); else goto invalid_expr; } else if (psBuildContext->bExpectLogicalOperator) { psBuildContext->bExpectLogicalOperator = FALSE; psBuildContext->bExpectVarName = TRUE; if (EQUAL(pszToken, "AND")) op = WFS_ExprBuildOperator(TOKEN_AND); else if (EQUAL(pszToken, "OR")) op = WFS_ExprBuildOperator(TOKEN_OR); else if (EQUAL(pszToken, "NOT")) op = WFS_ExprBuildOperator(TOKEN_NOT); else goto invalid_expr; } else if (psBuildContext->bExpectValue) { PUSH_VAL(WFS_ExprBuildValue(pszToken)); psBuildContext->bExpectValue = FALSE; psBuildContext->bExpectLogicalOperator = TRUE; } else goto invalid_expr; if (op != NULL) { Expr* prevOp; while(TRUE) { PEEK_OP(prevOp); if (prevOp != NULL && (WFS_ExprGetPriority(op) <= WFS_ExprGetPriority(prevOp))) { if (prevOp->eType != TOKEN_NOT) { POP_VAL(val2); if (val2 == NULL) goto invalid_expr; } POP_VAL(val1); if (val1 == NULL) goto invalid_expr; PUSH_VAL(WFS_ExprBuildBinary(prevOp->eType, val1, val2)); POP_OP(prevOp); WFS_ExprFree(prevOp); val1 = val2 = NULL; } else break; } PUSH_OP(op); op = NULL; } } *ppapszTokens = papszTokens; while(TRUE) { POP_OP(op); if (op == NULL) break; if (op->eType != TOKEN_NOT) { POP_VAL(val2); if (val2 == NULL) goto invalid_expr; } POP_VAL(val1); if (val1 == NULL) goto invalid_expr; PUSH_VAL(WFS_ExprBuildBinary(op->eType, val1, val2)); val1 = val2 = NULL; WFS_ExprFree(op); op = NULL; } POP_VAL(expr); return expr; invalid_expr: WFS_ExprFree(op); WFS_ExprFree(val1); WFS_ExprFree(val2); WFS_ExprFreeList(psValExprList); WFS_ExprFreeList(psOpExprList); return NULL; }