void equalizeTypes(Value* &Op1, Value* &Op2, bool isSigned, IRBuilder<> Builder){

	if (Op1->getType() != Op2->getType()) {

		if (Op1->getType()->getIntegerBitWidth() > Op2->getType()->getIntegerBitWidth() ) {
			//expand op2
			if (isSigned) Op2 = Builder.CreateSExt(Op2, Op1->getType(), "");
			else Op2 = Builder.CreateZExt(Op2, Op1->getType(), "");

		} else {
			//expand op1
			if (isSigned) Op1 = Builder.CreateSExt(Op1, Op2->getType(), "");
			else Op1 = Builder.CreateZExt(Op1, Op2->getType(), "");

		}

	}

}
Esempio n. 2
0
/// compile_put - Emit code for '.'                                                                                                                                                         
void BrainFTraceRecorder::compile_put(BrainFTraceNode *node,
                                      IRBuilder<>& builder) {
  Value *Loaded = builder.CreateLoad(DataPtr);
  Value *Print =
    builder.CreateSExt(Loaded, IntegerType::get(Loaded->getContext(), 32));
  builder.CreateCall(putchar_func, Print);
  if (node->left != (BrainFTraceNode*)~0ULL)
    compile_opcode(node->left, builder);
  else {
    HeaderPHI->addIncoming(DataPtr, builder.GetInsertBlock());
    builder.CreateBr(Header);
  }
}