Expression *UnaryOperator::rewrite() { rewriteChild(operand_); switch (operatorKind()) { case DEREFERENCE: { if (UnaryOperator *unary = operand()->as<UnaryOperator>()) { if (unary->operatorKind() == REFERENCE) { return unary->releaseOperand().release(); } } return this; } case LOGICAL_NOT: { while (Typecast *typecast = operand()->as<Typecast>()) { if (typecast->type()->isScalar() && typecast->operand()->getType()->isScalar()) { setOperand(typecast->releaseOperand()); } else { break; } } if (BinaryOperator *binary = operand()->as<BinaryOperator>()) { switch (binary->operatorKind()) { case BinaryOperator::EQ: binary->setOperatorKind(BinaryOperator::NEQ); return releaseOperand().release(); case BinaryOperator::NEQ: binary->setOperatorKind(BinaryOperator::EQ); return releaseOperand().release(); case BinaryOperator::LT: binary->setOperatorKind(BinaryOperator::GEQ); return releaseOperand().release(); case BinaryOperator::LEQ: binary->setOperatorKind(BinaryOperator::GT); return releaseOperand().release(); case BinaryOperator::GT: binary->setOperatorKind(BinaryOperator::LEQ); return releaseOperand().release(); case BinaryOperator::GEQ: binary->setOperatorKind(BinaryOperator::LT); return releaseOperand().release(); default: break; } } if (UnaryOperator *unary = operand()->as<UnaryOperator>()) { if (unary->operatorKind() == LOGICAL_NOT) { if (unary->operand()->getType()->size() == 1) { return unary->releaseOperand().release(); } } } return this; } default: return this; } }
// constructor / destructor: Processor::Processor() : Trace(0) { Accumulator(0); setInstructionCounter(0); InstructionRegister(0); setOperationCode(0); setOperand(0); // this is an address of cell in the current command }
Expression *Typecast::rewrite() { rewriteChild(operand_); /* Convert cast of pointer to a structure to a cast of pointer to its first field. */ if (type_->isPointer() && !type_->isStructurePointer()) { if (const PointerType *pointerType = operand()->getType()->as<PointerType>()) { if (const StructType *structType = pointerType->pointeeType()->as<StructType>()) { if (const MemberDeclaration *member = structType->getMember(0)) { setOperand(std::make_unique<UnaryOperator>(tree(), UnaryOperator::REFERENCE, std::make_unique<MemberAccessOperator>(tree(), MemberAccessOperator::ARROW, releaseOperand(), member))); } } } } /* * (int32_t*)(int64_t)expr -> (int32_t*)expr */ if (type_->isScalar()) { if (Typecast *typecast = operand()->as<Typecast>()) { const Type *operandType = typecast->operand()->getType(); if (typecast->type()->isScalar() && operandType->isScalar() && type_->size() == typecast->type()->size() && typecast->type()->size() == operandType->size()) { setOperand(typecast->releaseOperand()); } } } /* This really must be the last rule. */ if (type_ == operand()->getType()) { return releaseOperand().release(); } return this; }
void User::replaceUsesOfWith(Value *From, Value *To) { if (From == To) return; // Duh what? assert((!isa<Constant>(this) || isa<GlobalValue>(this)) && "Cannot call User::replaceUsesOfWith on a constant!"); for (unsigned i = 0, E = getNumOperands(); i != E; ++i) if (getOperand(i) == From) { // Is This operand is pointing to oldval? // The side effects of this setOperand call include linking to // "To", adding "this" to the uses list of To, and // most importantly, removing "this" from the use list of "From". setOperand(i, To); // Fix it now... } }
void User::setOperands(std::vector<Value *> Ops) { assert(Ops.size() == NumOperands && "Incorrect number passed to setOperands()"); for (unsigned OpN = 0; OpN < NumOperands; OpN++) { setOperand(OpN, Ops[OpN]); } }
void Processor::GetCOPO() { setOperationCode(instructionRegister / 100); setOperand(instructionRegister % 100); }
Unary::Unary( Type type, Coll& operand ) : Coll( type ) { setOperand( operand ); }
/* pull apart the name and value from the given message, and set operand value. * ignore any other messages. * return 0 if found a recognized operand else -1 */ static int setOp (XMLEle *root) { char *t = tagXMLEle (root); const char *d = findXMLAttValu (root, "device"); const char *n = findXMLAttValu (root, "name"); int nset = 0; double v; char prop[1024]; XMLEle *ep; /* check values */ if (!strcmp (t,"defNumberVector") || !strcmp (t,"setNumberVector")) { for (ep = nextXMLEle(root,1); ep; ep = nextXMLEle(root,0)) { char *et = tagXMLEle(ep); if (!strcmp (et,"defNumber") || !strcmp (et,"oneNumber")) { sprintf (prop, "%s.%s.%s", d, n, findXMLAttValu(ep,"name")); v = atof(pcdataXMLEle(ep)); if (setOperand (prop, v) == 0) { nset++; if (oflag) fprintf (stderr, "%s=%g\n", prop, v); } } } } else if(!strcmp(t,"defSwitchVector") || !strcmp(t,"setSwitchVector")){ for (ep = nextXMLEle(root,1); ep; ep = nextXMLEle(root,0)) { char *et = tagXMLEle(ep); if (!strcmp (et,"defSwitch") || !strcmp (et,"oneSwitch")) { sprintf (prop, "%s.%s.%s", d, n, findXMLAttValu(ep,"name")); v = (double)!strcmp(pcdataXMLEle(ep),"On"); if (setOperand (prop, v) == 0) { nset++; if (oflag) fprintf (stderr, "%s=%g\n", prop, v); } } } } else if(!strcmp(t,"defLightVector") || !strcmp(t,"setLightVector")){ for (ep = nextXMLEle(root,1); ep; ep = nextXMLEle(root,0)) { char *et = tagXMLEle(ep); if (!strcmp (et,"defLight") || !strcmp (et,"oneLight")) { sprintf (prop, "%s.%s.%s", d, n, findXMLAttValu(ep,"name")); v = (double)pstatestr(pcdataXMLEle(ep)); if (setOperand (prop, v) == 0) { nset++; if (oflag) fprintf (stderr, "%s=%g\n", prop, v); } } } } /* check special elements */ t = (char *) findXMLAttValu (root, "state"); if (t[0]) { sprintf (prop, "%s.%s._STATE", d, n); v = (double)pstatestr(t); if (setOperand (prop, v) == 0) { nset++; if (oflag) fprintf (stderr, "%s=%g\n", prop, v); } } t = (char *) findXMLAttValu (root, "timestamp"); if (t[0]) { sprintf (prop, "%s.%s._TS", d, n); v = (double)timestamp(t); if (setOperand (prop, v) == 0) { nset++; if (oflag) fprintf (stderr, "%s=%g\n", prop, v); } } /* return whether any were set */ return (nset > 0 ? 0 : -1); }