Exemple #1
0
std::string StringMessage::doToString() const
{
	std::string r;
	r = "string[" + to_string(getString().size()) + "]=" + getString()
	+ "; terminator[" + to_string(getTerminator().size()) + "]=" + getTerminator();

	return r;
}
			inline int64_t skipPattern(
				in_type & istr, 
				uint64_t & codelen)
			{
				// decode pattern length
				uint32_t const patlen = decodeUTF8(istr,codelen);
							
				if ( patlen == getTerminator() )
				{
					return -1;
				}
				else
				{
					// decode flags
					uint32_t const flags = decodeUTF8(istr,codelen);
					// compute length of encoded pattern
					uint32_t const skip = (flags&1)?((patlen+1)/2):(patlen+3)/4;
					
					// skip pattern data
					for ( uint64_t i = 0; i < skip; ++i )
						istr.get();

					codelen += skip;

					return patlen;
				}
			}
			inline int64_t skipPattern(
				in_type & istr, 
				uint64_t & patlencodelen, 
				uint64_t & flagcodelen, 
				uint64_t & datalen
			)
			{
				uint32_t const patlen = decodeUTF8(istr,patlencodelen);
							
				if ( patlen == getTerminator() )
				{
					return -1;
				}
				else
				{
					uint32_t const flags = decodeUTF8(istr,flagcodelen);
					uint32_t const skip = (flags&1)?((patlen+1)/2):(patlen+3)/4;
					
					for ( uint64_t i = 0; i < skip; ++i )
						istr.get();

					datalen += skip;

					return patlen;
				}
			}
Exemple #4
0
static bool LiftBlockIntoFunction(TranslationContext &ctx) {
  auto didError = false;

  //first, either create or look up the LLVM basic block for this native
  //block. we are either creating it for the first time, or, we are
  //going to look up a blank block
  auto block_name = ctx.natB->get_name();
  auto curLLVMBlock = ctx.va_to_bb[ctx.natB->get_base()];

  //then, create a basic block for every follow of this block, if we do not
  //already have that basic block in our LLVM CFG
  const auto &follows = ctx.natB->get_follows();
  for (auto succ_block_va : follows) {
    if (!ctx.va_to_bb.count(succ_block_va)) {
      throw TErr(__LINE__, __FILE__, "Missing successor block!");
    }
  }

  //now, go through each statement and translate it into LLVM IR
  //statements that branch SHOULD be the last statement in a block
  for (auto inst : ctx.natB->get_insts()) {
    ctx.natI = inst;
    switch (LiftInstIntoBlock(ctx, curLLVMBlock, true)) {
      case ContinueBlock:
        break;
      case EndBlock:
      case EndCFG:
        goto done;
      case TranslateErrorUnsupported:
        didError = !IgnoreUnsupportedInsts;
        goto done;
      case TranslateError:
        didError = true;
        goto done;
    }
  }
done:

  if (curLLVMBlock->getTerminator()) {
    return didError;
  }

  // we may need to insert a branch inst to the successor
  // if the block ended on a non-terminator (this happens since we
  // may split blocks in cfg recovery to avoid code duplication)
  if (follows.size() == 1) {
    llvm::BranchInst::Create(ctx.va_to_bb[follows.front()], curLLVMBlock);
  } else {
    new llvm::UnreachableInst(curLLVMBlock->getContext(), curLLVMBlock);
  }

  return didError;
}
 // Links blocks without a terminator to the next block
 void LinkBlocksWithoutTerminator(CodeGenerator *codegen, Function *function) {
     auto bb = function->getBasicBlockList().begin();
     auto next = bb;
     auto end = function->getBasicBlockList().end();
     // Save the current insert block
     BasicBlock *restorePoint = codegen->getBuilder().GetInsertBlock();
     for (; bb != end && ++next != end; ++bb) {
         if (bb->getTerminator() == nullptr) {
             codegen->getBuilder().SetInsertPoint(bb);
             codegen->getBuilder().CreateBr(next);
         }
     }
     // Restore the insert point position.
     codegen->getBuilder().SetInsertPoint(restorePoint);
 }
Exemple #6
0
llvm::Value * Generator::visit(If & node)
{
    auto condition = node.condition->accept(this);

    auto function = builder.GetInsertBlock()->getParent();

    auto thenBlock = llvm::BasicBlock::Create(*context, "then", function);
    auto elseBlock = llvm::BasicBlock::Create(*context, "else");
    auto mergeBlock = llvm::BasicBlock::Create(*context, "ifcont");

    if (node.elseBlock) {
        builder.CreateCondBr(condition, thenBlock, elseBlock);
    } else {
        builder.CreateCondBr(condition, thenBlock, mergeBlock);
    }

    builder.SetInsertPoint(thenBlock);

    createScope();
    node.thenBlock->accept(this);
    popScope();

    thenBlock = builder.GetInsertBlock();

    if (thenBlock->getTerminator() == nullptr) {
        builder.CreateBr(mergeBlock);
    }

    if (node.elseBlock) {
        function->getBasicBlockList().push_back(elseBlock);
        builder.SetInsertPoint(elseBlock);

        createScope();
        node.elseBlock->accept(this);
        popScope();

        builder.CreateBr(mergeBlock);
    }

    function->getBasicBlockList().push_back(mergeBlock);
    builder.SetInsertPoint(mergeBlock);

    return nullptr;
}
			static bool decode(
				pattern_type & pattern, in_type & istr,
				::libmaus::parallel::SynchronousCounter<uint64_t> & nextid
			)
			{
				try
				{
					// decode pattern length
					uint32_t const patlen = decodeUTF8(istr);
					
					// check for terminator
					if ( patlen == getTerminator() )
					{
						return false;
					}
					else
					{
						// decode flags
						uint32_t const flags = decodeUTF8(istr);
						
						// resize pattern
						try
						{
							pattern.spattern.resize(patlen);
						}
						catch(std::exception const & ex)
						{
							std::cerr << "exception while resizing pattern to length " << patlen << " in CompactFastDecoderBase::decode(): " << ex.what() << std::endl;
							throw;
						}
						
						// pattern has indeterminate bases
						if ( flags & 1 )
						{
							uint64_t const full = (patlen >> 1);		
							uint64_t const brok = patlen&1;
							std::string::iterator ita = pattern.spattern.begin();
							
							for ( uint64_t i = 0; i < full; ++i )
							{
								int v = istr.get();
								if ( v < 0 )
								{
									::libmaus::exception::LibMausException se;
									se.getStream() << "EOF in getNextPatternUnlocked()";
									se.finish();
									throw se;
								}

								*(ita++) = v & 0xF; v >>= 4;
								*(ita++) = v & 0xF; v >>= 4;
							}
							
							if ( brok )
							{
								int v = istr.get();
								if ( v < 0 )
								{
									::libmaus::exception::LibMausException se;
									se.getStream() << "EOF in getNextPatternUnlocked()";
									se.finish();
									throw se;
								}

								*(ita++) = v & 0xF; v >>= 4;				
							}
						}
						// pattern has determinate bases only
						else
						{
							// full bytes
							uint64_t const full = (patlen >> 2);		
							// fractional rest
							uint64_t const brok = patlen&3;
							std::string::iterator ita = pattern.spattern.begin();
							
							// decode full bytes (four symbols each)
							for ( uint64_t i = 0; i < full; ++i )
							{
								int v = istr.get();
								if ( v < 0 )
								{
									::libmaus::exception::LibMausException se;
									se.getStream() << "EOF in getNextPatternUnlocked()";
									se.finish();
									throw se;
								}

								*(ita++) = v & 0x3; v >>= 2;
								*(ita++) = v & 0x3; v >>= 2;
								*(ita++) = v & 0x3; v >>= 2;
								*(ita++) = v & 0x3; v >>= 2;
							}
							
							// decode fractional
							if ( brok == 3 )
							{
								int v = istr.get();
								if ( v < 0 )
								{
									::libmaus::exception::LibMausException se;
									se.getStream() << "EOF in getNextPatternUnlocked()";
									se.finish();
									throw se;
								}

								*(ita++) = v & 0x3; v >>= 2;
								*(ita++) = v & 0x3; v >>= 2;
								*(ita++) = v & 0x3; v >>= 2;
							}
							else if ( brok == 2 )