示例#1
0
 void DisassemblerContext::print_function(const ValuePtr<Function>& term) {
   print_function_type_term(term->function_type(), term);
   if (!term->blocks().empty()) {
     *m_output << " {\n";
     
     for (Function::BlockList::const_iterator ii = term->blocks().begin(), ie = term->blocks().end(); ii != ie; ++ii)
       print_block(*ii, m_local_definitions[*ii]);
     
     *m_output << "}";
   }
   *m_output << ";\n";
 }
示例#2
0
    void DisassemblerContext::setup_function(const ValuePtr<Function>& function) {
      for (Function::ParameterList::const_iterator ii = function->parameters().begin(), ie = function->parameters().end(); ii != ie; ++ii)
        setup_term_definition(*ii);
      
      setup_term(function->result_type());

      for (Function::BlockList::const_iterator ii = function->blocks().begin(), ie = function->blocks().end(); ii != ie; ++ii) {
        const ValuePtr<Block>& block = *ii;

        setup_term_name(block);

        for (Block::PhiList::const_iterator ji = block->phi_nodes().begin(), je = block->phi_nodes().end(); ji != je; ++ji)
          m_names.insert(std::make_pair(*ji, make_term_name(*ji, function)));
        
        for (Block::InstructionList::const_iterator ji = block->instructions().begin(), je = block->instructions().end(); ji != je; ++ji)
          m_names.insert(std::make_pair(*ji, make_term_name(*ji, function)));

        for (Function::BlockList::const_iterator ji = function->blocks().begin(), je = function->blocks().end(); ji != je; ++ji) {
          setup_term_name(*ji);
          setup_block(*ji);
        }
      }
    }
示例#3
0
    DisassemblerContext::TermDefinitionList* DisassemblerContext::term_definition_list(const ValuePtr<>& term) {
#if PSI_DEBUG
      switch (term->term_type()) {
      case term_global_variable:
      case term_function:
      case term_block:
      case term_phi:
      case term_parameter_placeholder:
      case term_function_parameter:
        PSI_FAIL("term type should not go in definition lists");
        
      default:
        break;
      }
#endif

      // Should this term be named?
      ValuePtr<Block> block;
      ValuePtr<Function> function;
      if (Value *source = term->disassembler_source()) {
        switch (source->term_type()) {
        case term_global_variable:
        case term_function:
        case term_recursive:
          return &m_global_definitions;

        case term_block: block.reset(value_cast<Block>(source)); break;
        case term_phi: block = value_cast<Phi>(source)->block(); break;
        case term_instruction: block = value_cast<Instruction>(source)->block(); break;

        case term_parameter_placeholder: return NULL;

        case term_function_parameter:
          function = value_cast<FunctionParameter>(source)->function();
          block = function->blocks().front();
          break;

        default: PSI_FAIL("unexpected source term type");
        }
      }

      if (m_in_function_mode || (!block && !function))
        return &m_global_definitions;
      
      if (block)
        return &m_local_definitions[block];
      
      return NULL;
    }