Exemplo n.º 1
0
string CBackendx86::Label(string label) const
{
  CScope *cs = GetScope();
  assert(cs != NULL);

  return "l_" + cs->GetName() + "_" + label;
}
string CBackendx86::Operand(const CTac *op)
{
  string operand;
  // TODO
  // return a string representing op
  // hint: take special care of references (op of type CTacReference)
  std::stringstream buffer ;
  buffer << op ;
  
  CScope *cs = GetScope();
  CSymtab *st = cs->GetSymbolTable();
  vector<CSymbol*> slist = st->GetSymbols();
 
  vector< CSymbol * > symbols = st->GetSymbols() ;
  //CTacName
  if (st->FindSymbol(buffer.str()) != NULL){
      operand =  buffer.str() ;
  }   
  //CTacConstant
  else if (buffer.str()[0] > 47 && buffer.str()[0] < 58){
       operand =  Imm(atoi(buffer.str().c_str())) ;
  }
      
  //CTacReference
  
  else {
      
  }
  
  
  return operand ;
}
Exemplo n.º 3
0
	CValue CallFunction(
		CScope& scope,
		CStack& stack,
		const CSourceLocation& location,
		const std::string& symbol,
		const std::vector<CValue>& argValues)
	{
		// Analyze function value.
		CValue functionValue = scope.GetValue(symbol, location, stack);
		if (!IsFunction(functionValue)) {
			throw ExScopeSymbolIsNotFunction{ location, stack };
		}

		if (argValues.size() > functionValue.GetFuncArity()) {
			throw ExScopeFormalActualArgCountMismatch{ location, stack };
		}

		// Analyze function definition.
		const auto& functionDef = functionValue.GetFuncDef();
		const auto& captures = functionValue.GetFuncCaptures();
		auto applArgs = functionValue.GetAppliedArgs();
		std::copy(begin(argValues), end(argValues), std::back_inserter(applArgs));

		if (argValues.size() < functionValue.GetFuncArity()) {
			// "Curry on"...			
			return CValue::MakeFunction(&functionDef, captures, applArgs);
		}

		// Call function
		const auto& argNames = functionDef.GetFormalArgs();
		const auto& argLocations = functionDef.GetArgLocations();
		assert(argNames.size() == argLocations.size());

		unsigned argsCount = argNames.size();

		CLocalScope funcScope{ scope.GetGlobalScope() };

		for (unsigned i = 0; i < argsCount; ++i) {
			funcScope.TryRegisteringBind(
				stack, 
				argNames[i], 
				applArgs[i], 
				argLocations[i]);
		}

		for (const auto& pr : captures) {
			funcScope.TryRegisteringBind(
				stack, 
				pr.first, 
				pr.second.value, 
				pr.second.location);
		}

		stack.PushCall(symbol);
		CValue result = functionDef.Execute(funcScope, stack);
		stack.PopCall();

		return result;
	}
Exemplo n.º 4
0
string CBackendx86::Label(const CTacLabel* label) const
{
  CScope *cs = GetScope();
  assert(cs != NULL);

  ostringstream o;
  o << "l_" << cs->GetName() << "_" << label->GetLabel();
  return o.str();
  return "l_" + cs->GetName() + "_" + label->GetLabel();
}
Exemplo n.º 5
0
bool CScope::DefineSymbol(const QString& desScope, CSymbol* symbol)
{
	CScope* scopeFound = FindScopeScrollDown(desScope);
	if (!scopeFound)
	{
		return false;
	}
	scopeFound->DefineSymbol(symbol);
	return true;
}
Exemplo n.º 6
0
CBioseq_Handle CPrefetchTokenOld_Impl::NextBioseqHandle(CScope& scope)
{
    TTSE_Lock tse;
    CSeq_id_Handle id;
    {{
            CFastMutexGuard guard(m_Lock);
            // Can not call bool(*this) - creates deadlock
            _ASSERT(m_CurrentId < m_Ids.size());
            id = m_Ids[m_CurrentId];
            // Keep temporary TSE lock
            tse = m_TSEs[m_CurrentId];
            m_TSEs[m_CurrentId].Reset();
            ++m_CurrentId;
            if ( tse ) {
                TTSE_Map::iterator it = m_TSEMap.find(tse);
                if ( --(it->second) < 1 ) {
                    m_TSEMap.erase(it);
                    // Signal that next TSE or next token may be prefetched
                    m_TSESemaphore.Post();
                }
            }
        }
    }
    return scope.GetBioseqHandle(id);
}
Exemplo n.º 7
0
void CPrefetchTokenOld_Impl::x_InitPrefetch(CScope& scope)
{
    m_TSEs.resize(m_Ids.size());
    m_CurrentId = 0;
    CRef<CDataSource> source(scope.GetImpl().GetFirstLoaderSource());
    if (!source) {
        return;
    }
    source->Prefetch(*this);
}
Exemplo n.º 8
0
CSeqVector::CSeqVector(const CSeq_loc& loc, CScope& scope,
                       EVectorCoding coding, ENa_strand strand)
    : m_Scope(&scope),
      m_SeqMap(CSeqMap::GetSeqMapForSeq_loc(loc, &scope)),
      m_Strand(strand),
      m_Coding(CSeq_data::e_not_set)
{
    if ( const CSeq_id* id = loc.GetId() ) {
        if ( CBioseq_Handle bh = scope.GetBioseqHandle(*id) ) {
            m_TSE = bh.GetTSE_Handle();
        }
    }
    m_Size = m_SeqMap->GetLength(m_Scope);
    m_Mol = m_SeqMap->GetMol();
    SetCoding(coding);
}
Exemplo n.º 9
0
CRef<CSeq_loc>
CBlastFastaInputSource::x_FastaToSeqLoc(CRef<objects::CSeq_loc>& lcase_mask,
                                        CScope& scope)
{
    static const TSeqRange kEmptyRange(TSeqRange::GetEmpty());
    CRef<CBlastScopeSource> query_scope_source;

    if (m_Config.GetLowercaseMask())
        lcase_mask = m_InputReader->SaveMask();

    CRef<CSeq_entry> seq_entry(m_InputReader->ReadOneSeq());
    if (lcase_mask) {
        if (lcase_mask->Which() != CSeq_loc::e_not_set) {
            lcase_mask->SetStrand(eNa_strand_plus);
        }
        _ASSERT(lcase_mask->GetStrand() == eNa_strand_plus ||
                lcase_mask->GetStrand() == eNa_strand_unknown);
    }
    _ASSERT(seq_entry.NotEmpty());
    scope.AddTopLevelSeqEntry(*seq_entry);

    CTypeConstIterator<CBioseq> itr(ConstBegin(*seq_entry));

    CRef<CSeq_loc> retval(new CSeq_loc());

    if ( !blast::HasRawSequenceData(*itr) ) {
        CBlastInputReader* blast_reader = 
            dynamic_cast<CBlastInputReader*>(m_InputReader.get());
        _ASSERT(blast_reader);
        CRef<CBlastScopeSource> query_scope_source =
            blast_reader->GetQueryScopeSource();
        query_scope_source->AddDataLoaders(CRef<CScope>(&scope));
    }

    if (m_ReadProteins && itr->IsNa()) {
        NCBI_THROW(CInputException, eSequenceMismatch,
                   "Nucleotide FASTA provided for protein sequence");
    } else if ( !m_ReadProteins && itr->IsAa() ) {
        NCBI_THROW(CInputException, eSequenceMismatch,
                   "Protein FASTA provided for nucleotide sequence");
    }

    // set strand
    if (m_Config.GetStrand() == eNa_strand_other ||
        m_Config.GetStrand() == eNa_strand_unknown) {
        if (m_ReadProteins)
            retval->SetInt().SetStrand(eNa_strand_unknown);
        else
            retval->SetInt().SetStrand(eNa_strand_both);
    } else {
        if (m_ReadProteins) {
            NCBI_THROW(CInputException, eInvalidStrand,
                       "Cannot assign nucleotide strand to protein sequence");
        }
        retval->SetInt().SetStrand(m_Config.GetStrand());
    }

    // sanity checks for the range
    const TSeqPos from = m_Config.GetRange().GetFrom() == kEmptyRange.GetFrom()
        ? 0 : m_Config.GetRange().GetFrom();
    const TSeqPos to = m_Config.GetRange().GetTo() == kEmptyRange.GetTo()
        ? 0 : m_Config.GetRange().GetTo();

    // Get the sequence length
    const TSeqPos seqlen = seq_entry->GetSeq().GetInst().GetLength();
    //if (seqlen == 0) {
    //    NCBI_THROW(CInputException, eEmptyUserInput,
    //               "Query contains no sequence data");
    //}
    _ASSERT(seqlen != numeric_limits<TSeqPos>::max());
    if (to > 0 && to < from) {
        NCBI_THROW(CInputException, eInvalidRange, 
                   "Invalid sequence range");
    }
    if (from > seqlen) {
        NCBI_THROW(CInputException, eInvalidRange, 
                   "Invalid from coordinate (greater than sequence length)");
    }
    // N.B.: if the to coordinate is greater than or equal to the sequence
    // length, we fix that silently


    // set sequence range
    retval->SetInt().SetFrom(from);
    retval->SetInt().SetTo((to > 0 && to < seqlen) ? to : (seqlen-1));

    // set ID
    retval->SetInt().SetId().Assign(*FindBestChoice(itr->GetId(), CSeq_id::BestRank));

    return retval;
}
Exemplo n.º 10
0
void CBackendx86::EmitInstruction(CTacInstr *i)
{
  assert(i != NULL);

  ostringstream cmt;
  string mnm;
  cmt << i;

  EOperation op = i->GetOperation();
  CScope* sc = GetScope() ;
  const CSymbol* symbol ; 
  int size ;
  
  switch (op) {
      
    // binary operators
    // dst = src1 op src2
    // TODO
      case opAdd :
      //case opSub :
      case opMul :
      //case opDiv :
      //case opAnd :
      //case opOr :          
          EmitInstruction("movl", Operand(i->GetSrc(1)) + ", %eax", cmt.str());         
          EmitInstruction("movl", Operand(i->GetSrc(2)) + ", %ebx");
          
          if (op == opAdd)
             EmitInstruction("addl", "%ebx, %eax");  
          else if (op == opMul)
             EmitInstruction("imull", "%ebx");  
          
          symbol = sc->GetSymbolTable()->FindSymbol(Operand(i->GetSrc(1)));
          
          size = symbol->GetOffset() ; 
          cmt.str("");
          cmt << size ;
          EmitInstruction("movl", "%eax, -" + cmt.str() + "(%ebp)"  );
          
          break ;              
 
    // unary operators
    // dst = op src1
    // TODO
    case opNeg :
    //case opPos :
    //case opNot :
        symbol = sc->GetSymbolTable()->FindSymbol(Operand(i->GetSrc(1)));
        if (symbol != NULL){
            EmitInstruction("movl", Operand(i->GetSrc(1)) + ", %eax", cmt.str());
            EmitInstruction("negl", "%eax");
            size = symbol->GetOffset() ;cmt.str("");
            cmt << size ;
            EmitInstruction("movl", "%eax, -" + cmt.str() + "(%ebp)"  );
            
        } 
        else {
            EmitInstruction("movl", Operand(i->GetSrc(1)) + ", %eax", cmt.str());
            EmitInstruction("negl", "%eax");
        }
        
        break ;
    // memory operations
    // dst = src1
    // TODO
      case opAssign :
          if (false) {
              
          }else {
              //cmt << " assign\t" + Operand(i->GetDest()) + "  <-  " << i->GetSrc(1) ;
              Load(i->GetSrc(1), "%eax", cmt.str() ) ;
              Store(i->GetDest(), 'a', "") ;  
          }
       break ;
    // pointer operations
    // dst = &src1
    // TODO
    // dst = *src1
    case opDeref:
      // opDeref not generated for now
      EmitInstruction("# opDeref", "not implemented", cmt.str());
      break;


    // unconditional branching
    // goto dst
    // TODO

    // conditional branching
    // if src1 relOp src2 then goto dst
    // TODO
      

    // function call-related operations
    // TODO

    // special
    case opLabel:
      _out << Label(dynamic_cast<CTacLabel*>(i)) << ":" << endl;
      break;

    case opNop:
      EmitInstruction("nop", "", cmt.str());
      break;


    default:
      EmitInstruction("# ???", "not implemented", cmt.str());
  }
}