示例#1
0
    void DisassemblerContext::print_function_type_term(const ValuePtr<FunctionType>& term, bool bracket, const ValuePtr<Function>& use_names) {
      PSI_ASSERT(!use_names || (term->parameter_types().size() == use_names->parameters().size()));
      
      if (bracket)
        *m_output << '(';

      *m_output << "function";
      switch (term->calling_convention()) {
      case cconv_c: break;
      case cconv_x86_stdcall: *m_output << " cc_x86_stdcall";
      case cconv_x86_thiscall: *m_output << " cc_x86_thiscall";
      case cconv_x86_fastcall: *m_output << " cc_x86_fastcall";
      default: PSI_FAIL("Unknown calling convention in disassembler");
      }
      if (term->sret())
        *m_output << " sret";
      *m_output << " (";
      
      unsigned n_parameters = term->parameter_types().size();
      unsigned parameter_name_base = m_parameter_name_index;
      m_parameter_name_index += n_parameters;
      
      boost::format name_formatter("%%%s");
      
      m_parameter_names.push_back(ParameterNameList::value_type());
      ParameterNameList::value_type& name_list = m_parameter_names.back();
      for (unsigned ii = 0; ii != n_parameters; ++ii) {
        if (ii)
          *m_output << ", ";
        
        std::string name;
        if (use_names) {
          *m_output << TermNamePrinter(&m_names.find(use_names->parameters().at(ii))->second->name);
        } else {
          *m_output << name_formatter % (parameter_name_base + ii);
        }
        
        const ParameterType& ty = term->parameter_types()[ii];
        *m_output << " :";
        print_parameter_attributes(ty.attributes);
        *m_output << ' ';
        print_term(ty.value, false);
        
        name_list.push_back(name);
      }
      
      *m_output << ") >";
      print_parameter_attributes(term->result_type().attributes);
      *m_output << ' ';
      print_term(term->result_type().value, true);
      
      m_parameter_names.pop_back();
      m_parameter_name_index = parameter_name_base;
      
      if (bracket)
        *m_output << ')';
    }
示例#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);
        }
      }
    }