// Evaluate // Tokenizes the string, converts to post-fix order, and evaluates that // Parameters: // str (input char array) - string to evaluate // Pre-condition: str must be a valid integer arithmetic expression including matching parentheses. void compile(const char str[], VarTree &vars, FunctionDef& funs, Instruction *prog[], int& pBegin, int& pEnd) { TokenList list(str); ListIterator iter = list.begin(); int tempCounter = 0; if (tokenText(iter,list) == "deffn") { //cout << list << endl; makeFunction(iter, list, funs); //return 0; } else { ExprNode* root = assignmentToTree(iter,list,funs); #ifdef DEBUG cout << *root << endl; #endif //return root->evaluate(vars, funs); int tempCounter = 0; int answerReg = root->toInstruction(prog, pEnd, tempCounter, vars); pBegin = 0; prog[pEnd++] = new Print(answerReg); } //cout << root->makedc() << endl //cout << *root << endl; }
U32 ObjectDeclNode::compileSubObject(U32 *codeStream, U32 ip, bool root) { U32 start = ip; codeStream[ip++] = OP_PUSH_FRAME; ip = classNameExpr->compile(codeStream, ip, TypeReqString); codeStream[ip++] = OP_PUSH; ip = objectNameExpr->compile(codeStream, ip, TypeReqString); codeStream[ip++] = OP_PUSH; for(ExprNode *exprWalk = argList; exprWalk; exprWalk = (ExprNode *) exprWalk->getNext()) { ip = exprWalk->compile(codeStream, ip, TypeReqString); codeStream[ip++] = OP_PUSH; } codeStream[ip++] = OP_CREATE_OBJECT; codeStream[ip] = STEtoU32(parentObject, ip); ip++; codeStream[ip++] = isDatablock; codeStream[ip++] = isClassNameInternal; codeStream[ip++] = isSingleton; codeStream[ip++] = dbgLineNumber; codeStream[ip++] = start + failOffset; for(SlotAssignNode *slotWalk = slotDecls; slotWalk; slotWalk = (SlotAssignNode *) slotWalk->getNext()) ip = slotWalk->compile(codeStream, ip, TypeReqNone); codeStream[ip++] = OP_ADD_OBJECT; codeStream[ip++] = root; for(ObjectDeclNode *objectWalk = subObjects; objectWalk; objectWalk = (ObjectDeclNode *) objectWalk->getNext()) ip = objectWalk->compileSubObject(codeStream, ip, false); codeStream[ip++] = OP_END_OBJECT; codeStream[ip++] = root || isDatablock; // Added to fix the object creation issue [7/9/2007 Black] codeStream[ip++] = OP_FINISH_OBJECT; return ip; }
int evaluate(const char str[], VarTree &vars, FunctionDef &fmap) { TokenList l(str); // Declare and construct our linked list ExprNode *root; static int ans = 0; // For handling previous answers ListIterator i = l.begin(); if((!i.token().isInteger()) && (i.token().isOperator())) { Token newHead(ans); l.push_front(newHead); i = l.begin(); } if(i.token().tokenChar() == "deffn") { doDefine(i, fmap); root = new Value(0); } else doCompare(i, root); // Here begins the Conversion cout << *root << endl; return root->evaluate(vars, fmap); }
bool ListExpr::ExtractNumericElements(vector<double> &output) { bool all_numeric = true; double val = 0.0; output.clear(); std::vector<ListElemExpr*> *elems = GetElems(); for (int i = 0 ; i < elems->size() ; i++) { ExprNode *item = (*elems)[i]->GetItem(); if (item->GetTypeName() == "FloatConst") { ConstExpr *c = dynamic_cast<ConstExpr*>(item); val = (double) dynamic_cast<FloatConstExpr*>(c)->GetValue(); output.push_back(val); } else if (item->GetTypeName() == "IntegerConst") { ConstExpr *c = dynamic_cast<ConstExpr*>(item); val = (double) dynamic_cast<IntegerConstExpr*>(c)->GetValue(); output.push_back(val); } else { all_numeric = false; } } return all_numeric; }
void avtApplyEnumerationExpression::ProcessArguments(ArgsExpr *args, ExprPipelineState *state) { // Check the number of arguments std::vector<ArgExpr*> *arguments = args->GetArgs(); if (arguments->size() != 2) { EXCEPTION2(ExpressionException, outputVariableName, "the enumerate expression accepts only two arguments"); } ArgExpr *listarg = (*arguments)[1]; ExprParseTreeNode *listTree = listarg->GetExpr(); if (listTree->GetTypeName() != "List") { debug1 << "avtApplyEnumerationExpression: second arg is not a list: " << listTree->GetTypeName() << endl; EXCEPTION2(ExpressionException, outputVariableName, "the last argument to enumerate " "must be a list"); } ListExpr *list = dynamic_cast<ListExpr*>(listTree); std::vector<ListElemExpr*> *elems = list->GetElems(); enumeratedValues.resize(elems->size()); for (int i = 0 ; i < elems->size() ; i++) { if ((*elems)[i]->GetEnd()) { EXCEPTION2(ExpressionException, outputVariableName, "the list for the enumerate " "expression cannot contain ranges."); } ExprNode *item = (*elems)[i]->GetItem(); if (item->GetTypeName() == "FloatConst") { ConstExpr *c = dynamic_cast<ConstExpr*>(item); enumeratedValues[i] = dynamic_cast<FloatConstExpr*>(c)->GetValue(); } else if (item->GetTypeName() == "IntegerConst") { ConstExpr *c = dynamic_cast<ConstExpr*>(item); enumeratedValues[i] = dynamic_cast<IntegerConstExpr*>(c)->GetValue(); } else { EXCEPTION2(ExpressionException, outputVariableName, "the list for the enumerate " "expression may contain only numbers."); } } // Let the base class do this processing. We only had to over-ride this // function to determine the number of arguments. avtMultipleInputExpressionFilter::ProcessArguments(args, state); }
void* ExprCaseWhen::ExprEvaluate(void* tuple, Schema* schema) { ExprNode* then = case_then_[case_then_.size() - 1]; void* result; for (int i = 0; i < case_when_.size(); i++) { if (*static_cast<bool*>(case_when_[i]->ExprEvaluate(tuple, schema)) == true) { then = case_then_[i]; break; } } // case_then_ shouldn't be NULL, checked before result = then->ExprEvaluate(tuple, schema); return type_cast_func_(result, value_); }
//! Checks if there is whitespace in the range specified in the string inline std::string findComment(const ExprNode& node) { const Expression& expr = *node.expr(); typedef std::vector<std::pair<int, int> > Comments; const Comments& comments = expr.getComments(); const std::string& s = expr.getExpr(); // TODO: user lower_bound to make this O(lg n) instead of O(n) for (Comments::const_iterator i = comments.begin(); i != comments.end(); ++i) { if (i->first >= node.endPos() && isWS(s.c_str(), node.endPos(), i->first)) return s.substr(i->first, i->second - i->first + 1); } return ""; }
void ExprPrototypeNode::addArgs(ExprNode* surrogate) { ExprNode::addChildren(surrogate); #if 0 ExprNode * child; ExprType type; for(int i = 0; i < numChildren(); i++) { child = this->child(i); type = child->type(); _argTypes.push_back(type); _env.add(((ExprVarNode*)child)->name(), new ExprLocalVar(type)); } #endif }
U32 ObjectDeclNode::precompileSubObject(bool) { // goes // OP_PUSHFRAME 1 // name expr // OP_PUSH 1 // args... PUSH // OP_CREATE_OBJECT 1 // parentObject 1 // isDatablock 1 // internalName 1 // isSingleton 1 // lineNumber 1 // fail point 1 // for each field, eval // OP_ADD_OBJECT (to UINT[0]) 1 // root? 1 // add all the sub objects. // OP_END_OBJECT 1 // root? 1 // To fix the stack issue [7/9/2007 Black] // OP_FINISH_OBJECT <-- fail point jumps to this opcode U32 argSize = 0; precompileIdent(parentObject); for(ExprNode *exprWalk = argList; exprWalk; exprWalk = (ExprNode *) exprWalk->getNext()) argSize += exprWalk->precompile(TypeReqString) + 1; argSize += classNameExpr->precompile(TypeReqString) + 1; U32 nameSize = objectNameExpr->precompile(TypeReqString) + 1; U32 slotSize = 0; for(SlotAssignNode *slotWalk = slotDecls; slotWalk; slotWalk = (SlotAssignNode *) slotWalk->getNext()) slotSize += slotWalk->precompile(TypeReqNone); // OP_ADD_OBJECT U32 subObjSize = 0; for(ObjectDeclNode *objectWalk = subObjects; objectWalk; objectWalk = (ObjectDeclNode *) objectWalk->getNext()) subObjSize += objectWalk->precompileSubObject(false); failOffset = 12 + nameSize + argSize + slotSize + subObjSize; // +1 because the failOffset should jump to OP_FINISH_OBJECT [7/9/2007 Black] return failOffset + 1; }
void cleanup(const ExprNode& expr, bool delete_symbols) { const ExprNode** nodes=expr.subnodes(); int size=expr.size; // (warning: expr will be deleted in the loop) for (int i=0; i<size; i++) if (delete_symbols || (!dynamic_cast<const ExprSymbol*>(nodes[i]))) delete (ExprNode*) nodes[i]; delete[] nodes; }
ExprType ExprLocalFunctionNode::prep(bool wantScalar, ExprVarEnvBuilder& envBuilder) { #if 0 // TODO: no local functions for now bool error = false; // prep prototype and check for errors ExprPrototypeNode* prototype = (ExprPrototypeNode*)child(0); ExprVarEnv functionEnv; functionEnv.resetAndSetParent(&env); if (!prototype->prep(false, functionEnv).isValid()) error = true; // decide what return type we want bool returnWantsScalar = false; if (!error && prototype->isReturnTypeSet()) returnWantsScalar = prototype->returnType().isFP(1); // prep block and check for errors ExprNode* block = child(1); ExprType blockType = block->prep(returnWantsScalar, functionEnv); if (!error && blockType.isValid()) { if (prototype->isReturnTypeSet()) { if (blockType != prototype->returnType()) { checkCondition(false, "In function result of block '" + blockType.toString() + "' does not match given return type " + prototype->returnType().toString(), error); } } else prototype->setReturnType(blockType); // register the function in the symbol table env.addFunction(prototype->name(), this); } else { checkCondition(false, "Invalid type for blockType is " + blockType.toString(), error); error = true; } return _type = error ? ExprType().Error() : ExprType().None().Varying(); #else bool error=false; checkCondition(false,"Local functions are currently not supported.",error); return ExprType().Error(); #endif }
U32 FuncCallExprNode::precompile(TypeReq type) { // OP_PUSH_FRAME // arg OP_PUSH arg OP_PUSH arg OP_PUSH // eval all the args, then call the function. // OP_CALLFUNC // function // namespace // isDot U32 size = 0; if(type != TypeReqString) size++; precompileIdent(funcName); precompileIdent(nameSpace); for(ExprNode *walk = args; walk; walk = (ExprNode *) walk->getNext()) size += walk->precompile(TypeReqString) + 1; return size + 5; }
U32 FuncCallExprNode::compile(U32 *codeStream, U32 ip, TypeReq type) { codeStream[ip++] = OP_PUSH_FRAME; for(ExprNode *walk = args; walk; walk = (ExprNode *) walk->getNext()) { ip = walk->compile(codeStream, ip, TypeReqString); codeStream[ip++] = OP_PUSH; } if(callType == MethodCall || callType == ParentCall) codeStream[ip++] = OP_CALLFUNC; else codeStream[ip++] = OP_CALLFUNC_RESOLVE; codeStream[ip] = STEtoU32(funcName, ip); ip++; codeStream[ip] = STEtoU32(nameSpace, ip); ip++; codeStream[ip++] = callType; if(type != TypeReqString) codeStream[ip++] = conversionOp(TypeReqString, type); return ip; }
// **************************************************************************** // Function: main // // Programmer: Jeremy Meredith // Creation: April 5, 2002 // // Modifications: // Jeremy Meredith, Mon Jul 28 16:53:15 PDT 2003 // Made the expression parser print error messages to the console. // (Another simultaneous change made the default be the viewer error // reporting mechanism.) // // Jeremy Meredith, Wed Nov 24 12:13:20 PST 2004 // Refactored the parser into generic and VisIt Expression specific pieces. // // **************************************************************************** int main(int argc, char *argv[]) { if (argc<2) {cerr<<"needs an argument\n"; exit(-1);} Parser *parser = new ExprParser(new ExprNodeFactory()); ExprParser::SetErrorMessageTarget(ExprParser::EMT_CONSOLE); for (int i=1; i<argc; i++) { cout << "\n----\n"; cout << "PARSING '"<<argv[i]<<"'"<<endl; cout << "----\n\n"; ExprNode *node = (ExprNode*)parser->Parse(argv[i]); if (node) node->Print(cout); else cout << "ERROR\n"; } return 0; }
bool ListExpr::ExtractStringElements(vector<std::string> &output) { bool all_string = true; output.clear(); std::vector<ListElemExpr*> *elems = GetElems(); for (int i = 0 ; i < elems->size() ; i++) { ExprNode *item = (*elems)[i]->GetItem(); if (item->GetTypeName() == "StringConst") { ConstExpr *c = dynamic_cast<ConstExpr*>(item); output.push_back(dynamic_cast<StringConstExpr*>(c)->GetValue()); } else { all_string = false; } } return all_string; }
virtual void deleteAll() { lhs->deleteAll(); rhs->deleteAll(); }
void CompiledFunction::visit(const ExprNode& e) { e.acceptVisitor(*this); }
void RuleOptimizer::checkStetRule(ExprNode *node, const Area *area) { Logger::trace << "checking for STET rule " << rule2string(db, cube, node) << endl; if (!node->isValid()) { Logger::trace << "rule is invalid, stopping STET rule check" << endl; return; } // the rule should be "[] = IF(...,STET(),...)" or "[] = IF(...,...,STET())" Node::NodeType t = node->getNodeType(); if (t != Node::NODE_FUNCTION_IF) { Logger::trace << "no IF clause, stopping STET rule check" << endl; return; } FunctionNode * ifNode = dynamic_cast<FunctionNode*>(node); ExprNode* clause = dynamic_cast<ExprNode*>(ifNode->getParameters()->at(0)); if (clause == 0) { Logger::warning << "something is wrong, corrupted rule " << rule2string(db, cube, node) << endl; return; } Node* trueNode = ifNode->getParameters()->at(1); Node* falseNode = ifNode->getParameters()->at(2); // either true or false node must be STET Node* nonStetNode = 0; bool isInclusive = false; if (trueNode->getNodeType() == Node::NODE_FUNCTION_STET) { nonStetNode = falseNode; isInclusive = false; // use complementary clause-set } else if (falseNode->getNodeType() == Node::NODE_FUNCTION_STET) { nonStetNode = trueNode; isInclusive = true; // use clause-set } else { Logger::trace << "no STET as true or false value, stopping STET rule check" << endl; return; } // check if clause is a dimension restriction Logger::trace << "checking if-clause " << rule2string(db, cube, clause) << endl; IdentifierType dimensionId; bool restriction = clause->isDimensionRestriction(cube, &dimensionId); if (!restriction) { Logger::trace << "if-clause is no dimension restriction, stopping STET rule check" << endl; return; } CPDimension dimension = db->lookupDimension(dimensionId, false); if (dimension == 0) { Logger::trace << "restricted dimension cannot be found, id: " << dimensionId << endl; return; } // ok find the dimension restriction set<Element*> elements = clause->computeDimensionRestriction(db, cube); // find dimension position int pos = 0; const IdentifiersType *dimensionIds = cube->getDimensions(); for (IdentifiersType::const_iterator iter = dimensionIds->begin(); iter != dimensionIds->end(); ++iter, pos++) { if (*iter == dimensionId) { break; } } Logger::trace << "dimension restriction for dimension '" << dimensionId << "', position " << pos << endl; // find existing restriction set<IdentifierType> computedRestriction; // intersect with computed restriction if (isInclusive) { // no given restriction if (!area->elemCount(pos)) { for (set<Element*>::iterator iter = elements.begin(); iter != elements.end(); ++iter) { Element* element = *iter; IdentifierType id = element->getIdentifier(); computedRestriction.insert(id); Logger::trace << "dimension element " << element->getName(dimension->getElemNamesVector()) << endl; } } else { // restriction given in rule for (set<Element*>::iterator iter = elements.begin(); iter != elements.end(); ++iter) { Element* element = *iter; IdentifierType id = element->getIdentifier(); if (area->find(pos, id) != area->elemEnd(pos)) { computedRestriction.insert(id); Logger::trace << "dimension element " << element->getName(dimension->getElemNamesVector()) << endl; } } } } else { // intersect with complement of computed restriction // no given restriction if (!area->elemCount(pos)) { ElementsType allElements = dimension->getElements(PUser(), false); for (ElementsType::iterator iter = allElements.begin(); iter != allElements.end(); ++iter) { Element* element = *iter; if (elements.find(element) == elements.end()) { IdentifierType id = element->getIdentifier(); computedRestriction.insert(id); Logger::trace << "dimension element " << element->getName(dimension->getElemNamesVector()) << endl; } } } else { // restriction given in rule set<IdentifierType> idList; for (set<Element*>::iterator iter = elements.begin(); iter != elements.end(); ++iter) { Element* element = *iter; IdentifierType id = element->getIdentifier(); idList.insert(id); } for (Area::ConstElemIter iter = area->elemBegin(pos); iter != area->elemEnd(pos); ++iter) { IdentifierType id = *iter; if (idList.find(id) == idList.end()) { computedRestriction.insert(id); Logger::trace << "dimension element identifier " << id << endl; } } } } restrictedRule = dynamic_cast<ExprNode*>(nonStetNode->clone()); restrictedDimension = dimension->getId(); restrictedIdentifiers = computedRestriction; Logger::trace << "using rule " << rule2string(db, cube, restrictedRule) << " for restricted area" << endl; }
virtual void deleteAll() { id->deleteAll(); expr->deleteAll(); }
virtual void deleteAll() { typedId->deleteAll(); expr->deleteAll(); }
virtual void deleteAll() { func->deleteAll(); args->deleteAll(); }
ExprAtan2::ExprAtan2(const ExprNode& left, const ExprNode& right) : ExprBinaryOp(left,right,Dim()) { if (!(left.type() == Dim::SCALAR)) throw DimException("\"atan2\" expects scalar arguments"); if (!(right.type() == Dim::SCALAR)) throw DimException("\"atan2\" expects scalar arguments"); }
void avtArrayComposeWithBinsExpression::ProcessArguments(ArgsExpr *args, ExprPipelineState *state) { // Check the number of arguments std::vector<ArgExpr*> *arguments = args->GetArgs(); nvars = (int)arguments->size()-1; int idx_of_list = arguments->size()-1; ArgExpr *listarg = (*arguments)[idx_of_list]; ExprParseTreeNode *listTree = listarg->GetExpr(); if (listTree->GetTypeName() != "List") { debug1 << "avtArrayComposeWithBinsExpression: second arg is not a " << "list: " << listTree->GetTypeName() << endl; EXCEPTION2(ExpressionException, outputVariableName, "the last argument to array_compose_" "with_bins must be a list"); } ListExpr *list = dynamic_cast<ListExpr*>(listTree); std::vector<ListElemExpr*> *elems = list->GetElems(); binRanges.resize(elems->size()); if ((int)elems->size() != nvars+1) { EXCEPTION2(ExpressionException, outputVariableName, "the list for array_compose_with_bins" " must have one more number than there are variables. " " For two variables (V1 and V2), there should be a list of" " size 3: [L0, L1, L2]. V1's bin goes from L0 to L1, " "and V2's bin goes from L1 to L2."); } for (size_t i = 0 ; i < elems->size() ; i++) { if ((*elems)[i]->GetEnd()) { EXCEPTION2(ExpressionException, outputVariableName, "the list for array_compose_with" "_bins expression cannot contain ranges."); } ExprNode *item = (*elems)[i]->GetItem(); if (item->GetTypeName() == "FloatConst") { ConstExpr *c = dynamic_cast<ConstExpr*>(item); binRanges[i] = dynamic_cast<FloatConstExpr*>(c)->GetValue(); } else if (item->GetTypeName() == "IntegerConst") { ConstExpr *c = dynamic_cast<ConstExpr*>(item); binRanges[i] = dynamic_cast<IntegerConstExpr*>(c)->GetValue(); } else { EXCEPTION2(ExpressionException, outputVariableName, "the list for the array_compose" "_with_bins expression may contain only numbers."); } } // Let the base class do this processing. We only had to over-ride this // function to determine the number of arguments. avtMultipleInputExpressionFilter::ProcessArguments(args, state); }
void FinalMachineCodeGen::convert_IC_MC(InterCode *interCode, ostream &os) { string dst_regName ; string src1_regName; string src2_regName; ExprNode **opndsList = (ExprNode **)interCode->get3Operands(); switch(interCode->getOPNType()) { case CALL : { string func_name = ((InvocationNode*)opndsList[0])->symTabEntry()->name(); string retAddrReg; if (int_reg_used_cnt || fl_reg_used_cnt) { retAddrReg = LabelClass::assignLabel()->getLabel(); } else { retAddrReg = opndsList[0]->next()->getLabel(); } push_registers(retAddrReg, os); os << "JMP " << func_name << endl; if ((int_reg_used_cnt-1) || fl_reg_used_cnt || opndsList[1]) { os << retAddrReg << ": "; pop_registers(os); if (opndsList[1]) { ExprNode *src1 = opndsList[1]; string retValueReg = src1->getRegisterName(); if(IS_FLOAT(src1->type())) os<<"MOVF "<<RRV_F<<" "; else os<<"MOVI "<<RRV_I<<" "; os<<retValueReg<<endl; //int_reg_used_cnt--; } } reg_list.resize(0); break; } case FPARAM: { ExprNode *src1 = opndsList[0]; dst_regName = src1->getRegisterName(); os << "ADD "<<RSP<<" 4 "<<RSP << endl; if (IS_FLOAT(src1->type())) os << "LDF "<<RSP<<" "<<dst_regName; else os << "LDI "<<RSP<<" "<<dst_regName; os << C_FPARAM << endl; break; } case APARAM: { ExprNode *param = opndsList[0]; Type *ret_type = (param) ? (param->coercedType() ? (Type*)param ->coercedType() : param->type()): NULL ; string str; string regName; if(param) { if(param->exprNodeType() == ExprNode::ExprNodeType::VALUE_NODE) { if(IS_FLOAT(ret_type)) { regName = allocateNewRegName(true); str = "STF "+regName+" "+RSP; //fl_reg_used_cnt--; } else str = "STI "+param->getRefName()+" "+RSP; } else { if(IS_FLOAT(ret_type)) { string temp; regName = param->getRegisterName(); if(regName.at(0) == 'R') { temp = convertToFloat(param, os); str = "STF "+temp+" "+RSP; } else str = "STF "+param->getRegisterName()+" "+RSP; } else str = "STI "+param->getRegisterName()+" "+RSP; } reg_list.push_back(str + C_APARAM); } break; } case RETURN: { if (opndsList[0]) { ExprNode *ret_val = opndsList[0]; Type *ret_type = (ret_val) ? (ret_val ->coercedType() ? (Type*)ret_val ->coercedType() : ret_val ->type()): NULL ; if (IS_FLOAT(ret_type)) { dst_regName = ret_val->getRegisterName(); os<<"MOVF "<<dst_regName<<" "<<RRV_F; } else { dst_regName = ret_val->getRegisterName(); os<<"MOVI "<<dst_regName<<" "<<RRV_I; } os<<endl; } os<<"ADD " << RSP << " 4 " << RSP << endl; os<<"LDI " << RSP << " " << RRET_ADD << C_POP_RET << endl; os << "JMPI " << RRET_ADD << endl; break; } case EXPR: { ExprNode *dst = opndsList[0]; Type *type_dst = dst ->coercedType() ? (Type*)dst ->coercedType() : dst ->type(); if (opndsList[0] && opndsList[1] && opndsList[2]) { ExprNode *src1 = opndsList[1]; ExprNode *src2 = opndsList[2]; Type *type_src1 = src1->coercedType() ? (Type*)src1->coercedType() : src1->type(); Type *type_src2 = src2->coercedType() ? (Type*)src2->coercedType() : src2->type(); if (IS_FLOAT(type_dst)) { if (src1) { src1_regName = src1->getRegisterName(); if (!IS_FLOAT(type_src1)) src1_regName = convertToFloat(src1, os); } if (src2) { src2_regName = src2->getRegisterName(); if(!IS_FLOAT(type_src2)) src2_regName= convertToFloat(src2, os); } if (dst) dst_regName = dst->getRegisterName(); switch(interCode->getsubCode()) { case OpNode::OpCode::PLUS : { os<<"FADD "; PRT_REG; break; } case OpNode::OpCode::MINUS : { os<<"FSUB "; PRT_REG; break; } case OpNode::OpCode::MULT : { os<<"FMUL "; PRT_REG; break; } case OpNode::OpCode::DIV : { os<<"FDIV "; PRT_REG; break; } case OpNode::OpCode::GT : { os<<"FGT " ; PRT_REG; break; } case OpNode::OpCode::GE : { os<<"FGE " ; PRT_REG; break; } case OpNode::OpCode::LT : { os<<"FLT " ; PRT_REG; break; } case OpNode::OpCode::LE : { os<<"FLE " ; PRT_REG; break; } case OpNode::OpCode::EQ : { os<<"FEQ " ; PRT_REG; break; } case OpNode::OpCode::NE : { os<<"FEQ " ; PRT_REG; break; } default : break; } } else { if (src1) { src1_regName = src1->getRegisterName(); if(IS_FLOAT(type_src1)) src1_regName = convertToInt(src1, os); } if (src2) { src2_regName = src2->getRegisterName(); if(IS_FLOAT(type_src2)) src2_regName= convertToInt(src2, os); } if (dst) dst_regName = dst->getRegisterName(); switch(interCode->getsubCode()) { case OpNode::OpCode::PLUS : { os<<"ADD "; PRT_REG; break; } case OpNode::OpCode::MINUS : { os<<"SUB "; PRT_REG; break; } case OpNode::OpCode::MULT : { os<<"MUL "; PRT_REG; break; } case OpNode::OpCode::MOD : { os<<"MOD "; PRT_REG; break; } case OpNode::OpCode::DIV : { os<<"DIV "; PRT_REG; break; } case OpNode::OpCode::BITAND: { os<<"AND "; PRT_REG; break; } case OpNode::OpCode::BITOR : { os<<"OR " ; PRT_REG; break; } case OpNode::OpCode::BITXOR: { os<<"XOR "; PRT_REG; break; } case OpNode::OpCode::GT : { os<<"JMPC GT " <<src1_regName<<" "<<src2_regName<<" "; relational( dst_regName, os); break; } case OpNode::OpCode::GE : { os<<"JMPC GE " <<src1_regName<<" "<<src2_regName<<" "; relational( dst_regName, os); break; } case OpNode::OpCode::LT : { os<<"JMPC LT " <<src1_regName<<" "<<src2_regName<<" "; relational( dst_regName, os); break; } case OpNode::OpCode::LE : { os<<"JMPC LE " <<src1_regName<<" "<<src2_regName<<" "; relational( dst_regName, os); break; } case OpNode::OpCode::EQ : { os<<"JMPC EQ " <<src1_regName<<" "<<src2_regName<<" "; relational( dst_regName, os); break; } case OpNode::OpCode::NE : { os<<"JMPC NE " <<src1_regName<<" "<<src2_regName<<" "; relational( dst_regName, os); break; } case OpNode::OpCode::SHL : { ShiftLogic(true, src1_regName, src2_regName, dst_regName, os); break; } case OpNode::OpCode::SHR : { ShiftLogic(false, src1_regName, src2_regName, dst_regName, os); break; } case OpNode::OpCode::AND : { ANDLogic (src1_regName, src2_regName, dst_regName, os); break; } case OpNode::OpCode::OR : { ORLogic (src1_regName, src2_regName, dst_regName, os); break; } default : break; } } } else if(opndsList[0] && opndsList[1]) { ExprNode *src1 = opndsList[1]; Type *type_src1 = src1->coercedType() ? (Type*)src1->coercedType() : src1->type(); bool IsEndlNeeded = true; src1_regName = src1->getRegisterName(); if(dst) dst_regName = dst->getRegisterName(); if (IS_FLOAT(type_dst)) { if (interCode->getsubCode() == OpNode::OpCode::ASSIGN) { if (!IS_FLOAT(type_src1)) src1_regName = convertToFloat(src1, os); os<<"MOVF "<<src1_regName<<" "<<dst_regName; } else if (interCode->getsubCode() == OpNode::OpCode::UMINUS) { if (!IS_FLOAT(type_src1)) src1_regName = convertToFloat(src1, os); os<<"FNEG "<<src1_regName<<" "<<dst_regName; } } else { if (interCode->getsubCode() == OpNode::OpCode::ASSIGN) { if (IS_STRING(type_src1)) { os<<"MOVS "<<src1_regName<<" "<<dst_regName; } else { if (IS_FLOAT(type_src1)) src1_regName = convertToInt(src1, os); os<<"MOVI "<<src1_regName<<" "<<dst_regName; } } else if (interCode->getsubCode() == OpNode::OpCode::UMINUS) { if (IS_FLOAT(type_src1)) src1_regName = convertToInt(src1, os); os<<"NEG "<<src1_regName<<" "<<dst_regName; } else if (interCode->getsubCode() == OpNode::OpCode::NOT) { NOTLogic(src1_regName, dst_regName, os); IsEndlNeeded = false; } else if (interCode->getsubCode() == OpNode::OpCode::BITNOT) { os << "BNOT " << src1_regName << " " << dst_regName; } } if (IsEndlNeeded) os<<endl; } break; } case LABEL : { os<<interCode->getLabel()<<endl; break; } case GOTO : { InterCode* goto_lab = (InterCode*) opndsList[0]; os<<"JMP "<<goto_lab->getLabel() <<endl; break; } case IFREL : { ExprNode* cond = (ExprNode*) opndsList[0]; InterCode* true_lab = cond->OnTrue(); InterCode* false_lab = cond->OnFalse(); ExprNode* expr1 = (ExprNode*) opndsList[1]; ExprNode* expr2 = (ExprNode*) opndsList[2]; bool if_cond_int = false; Type *type_src1 = (expr1) ? (expr1->coercedType() ? (Type*)expr1->coercedType() : expr1->type()): NULL ; Type *type_src2 = (expr2) ? (expr2->coercedType() ? (Type*)expr2->coercedType() : expr2->type()): NULL ; if (opndsList[2] && opndsList[1]) { src1_regName = expr1->getRegisterName(); src2_regName = expr2->getRegisterName(); if(!IS_FLOAT(type_src1) && !IS_FLOAT(type_src2)) if_cond_int = true; else { if(!IS_FLOAT(type_src1)) src1_regName = convertToFloat(expr1, os); if(!IS_FLOAT(type_src2)) src2_regName= convertToFloat(expr2, os); if_cond_int = false; } os<<"JMPC "; switch(interCode->getsubCode()) { case OpNode::OpCode::EQ : (if_cond_int) ? os<<"EQ " : os<<"FEQ "; break; case OpNode::OpCode::NE : (if_cond_int) ? os<<"NE " : os<<"FNE "; break; case OpNode::OpCode::GT : (if_cond_int) ? os<<"GT " : os<<"FGT "; break; case OpNode::OpCode::GE : (if_cond_int) ? os<<"GE " : os<<"FGE "; break; case OpNode::OpCode::LT : (if_cond_int) ? os<<"LT " : os<<"FLT "; break; case OpNode::OpCode::LE : (if_cond_int) ? os<<"LE " : os<<"FLE "; break; default : break ; } os<<src1_regName<<" "<<src2_regName<<" "<<(true_lab->getLabel())<<endl; if(false_lab) os<<"JMP "<<(false_lab->getLabel())<<endl; } else if(opndsList[1]) { if(cond->exprNodeType() == ExprNode::ExprNodeType::VALUE_NODE) src1_regName = expr1->getRefName(); else src1_regName = expr1->getRegisterName(); if(Type::isBool(type_src1->tag())) { if(interCode->getsubCode() == OpNode::OpCode::NOT) os<<"JMPC EQ "; os<<src1_regName<<" 0 "<<(true_lab->getLabel())<<endl; if(false_lab) os<<"JMP "<<(false_lab->getLabel())<<endl; } } else { if(cond->exprNodeType() == ExprNode::ExprNodeType::VALUE_NODE) src1_regName = cond->getRefName(); else src1_regName = cond->getRegisterName(); os<<"JMPC NE "; os<<src1_regName<<" 0 "<<(true_lab->getLabel())<<endl; if(false_lab) os<<"JMP "<<(false_lab->getLabel())<<endl; } break; } case ENTER : { IsLastBlockEmpty = true; fl_reg_used_cnt = 0 ; int_reg_used_cnt = 0 ; break; } case LEAVE : { os<<"ADD "<<RSP<<" 4 "<<RSP << endl; os<<"LDI "<<RSP <<" "<<RRET_ADD << C_POP_RET << endl; os << "JMPI " << RRET_ADD << endl; break; } case PRINT : { ExprNode *param = opndsList[0]; Type *type_dst = (param ) ? (param ->coercedType() ? (Type*)param ->coercedType() : param ->type()): NULL ; if (IS_FLOAT(type_dst)) os<<"PRTF "; else if (IS_STRING(type_dst)) os<<"PRTS "; else os<<"PRTI "; if (param->exprNodeType() == ExprNode::ExprNodeType::VALUE_NODE) os << opndsList[0]->getRefName(); else os << opndsList[0]->getRegisterName(); os << endl; break; } default: { assert(0 && "Invalid 3 address Opcode"); } } }
void ParallelCoordinatesViewerPluginInfo::InitializePlotAtts( AttributeSubject *atts, ViewerPlot *plot) { // If we had scalar names, we can just copy the default atts // and return. if (defaultAtts->GetScalarAxisNames().size() != 0) { // One helpful thing we can do: make sure the user set the // visual axis names. They really should have, but since // we can blindly copy them from the scalar axis names in // this case, no harm doing it for them. if (defaultAtts->GetVisualAxisNames().size() == 0) defaultAtts->SetVisualAxisNames(defaultAtts->GetScalarAxisNames()); *(ParallelCoordinatesAttributes*)atts = *defaultAtts; return; } // Otherwise, we must be an array variable; try to get // some names for its components.... const avtDatabaseMetaData *md = plot->GetMetaData(); const std::string &var = plot->GetVariableName(); const avtArrayMetaData *array = md->GetArray(var); stringVector subNames; if (array) { subNames = array->compNames; } else { Expression *exp = ParsingExprList::GetExpression(plot->GetVariableName()); if (exp == NULL || exp->GetType() != Expression::ArrayMeshVar) { debug3 << "ParallelCoordinatesAttributes::InitializePlotAtts: " << "variable wasn't an array database variable, an " << "array expression, or a list of scalars. This can " << "happen if the user attempts to create this plot " << "without the use off a wizard, e.g. in the case of " << "the cli. Assuming this is the case and continuing " << "without error.\n"; return; } // If we have any problems walking the expression tree, just return; // the worst case scenario if we don't populate the visual axis // name list is that the GUI window is temporarily blank. ExprNode *root = ParsingExprList::GetExpressionTree(exp); if (root->GetTypeName() != "Function") return; FunctionExpr *fn = dynamic_cast<FunctionExpr*>(root); if (fn->GetName() != "array_compose" && fn->GetName() != "array_compose_with_bins") return; ArgsExpr *argsExpr = fn->GetArgsExpr(); std::vector<ArgExpr*> *args = argsExpr ? argsExpr->GetArgs() : NULL; if (!args) return; for (size_t i=0; i<args->size(); i++) { ExprNode *arg = (ExprNode*)((*args)[i]->GetExpr()); if (arg->GetTypeName() == "List") break; subNames.push_back(arg->GetPos().GetText(exp->GetDefinition())); } } doubleVector extMin(subNames.size(), -1e+37); doubleVector extMax(subNames.size(), +1e+37); // Set up the default attributes to contain these values, so // if the user hits reset, the axis names are retained. defaultAtts->SetVisualAxisNames(subNames); defaultAtts->SetExtentMinima(extMin); defaultAtts->SetExtentMaxima(extMax); *(ParallelCoordinatesAttributes*)atts = *defaultAtts; }
virtual void deleteAll() { expr->deleteAll(); }
ExprDiv::ExprDiv(const ExprNode& left, const ExprNode& right) : ExprBinaryOp(left,right,Dim()) { if (!(left.type() == Dim::SCALAR)) throw DimException("cannot divide a non-scalar expression"); if (!(right.type() == Dim::SCALAR)) throw DimException("cannot divide by a non-scalar expression"); }
virtual void deleteAll() { var->deleteAll(); cond->deleteAll(); body->deleteAll(); }
void ExprCopy::visit(const ExprNode& e) { if (!clone.found(e)) { e.acceptVisitor(*this); } }
virtual void deleteAll() { cond->deleteAll(); body->deleteAll(); }