Ejemplo n.º 1
0
 void DisassemblerContext::print_exists(const ValuePtr<Exists>& term, bool bracket) {
   if (bracket)
     *m_output << '(';
   *m_output << "exists (";
   
   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 = str(name_formatter % (parameter_name_base + ii));
     *m_output << name << " : ";
     print_term(term->parameter_types()[ii], false);
     
     name_list.push_back(name);
   }
   
   *m_output << ") > ";
   
   print_term(term->result(), true);
   
   m_parameter_names.pop_back();
   m_parameter_name_index = parameter_name_base;
   
   if (bracket)
     *m_output << ')';
 }
Ejemplo n.º 2
0
    void DisassemblerContext::setup_term(const ValuePtr<>& term) {
      if (!m_visited_terms.insert(term).second)
        return;

      setup_term_name(term);
      
      switch (term->term_type()) {
      case term_apply: {
        ValuePtr<ApplyType> apply = value_cast<ApplyType>(term);
        setup_term(apply->recursive());
        for (std::vector<ValuePtr<> >::const_iterator ii = apply->parameters().begin(), ie = apply->parameters().end(); ii != ie; ++ii)
          setup_term(*ii);
        break;
      }
      
      case term_exists: {
        ValuePtr<Exists> exists = value_cast<Exists>(term);
        setup_term(exists->result());
        break;
      }
        
      case term_parameter_placeholder:
      case term_recursive_parameter: {
        setup_term(term->type());
        break;
      }
        
      case term_functional: {
        class MyVisitor : public FunctionalValueVisitor {
          DisassemblerContext *m_self;
        public:
          MyVisitor(DisassemblerContext *self) : m_self(self) {}
          virtual void next(const ValuePtr<>& v) {if (v) m_self->setup_term(v);}
        };
        
        MyVisitor my_visitor(this);
        value_cast<FunctionalValue>(term)->functional_visit(my_visitor);
        break;
      }
        
      case term_function_type: {
        ValuePtr<FunctionType> cast_term = value_cast<FunctionType>(term);
        const std::vector<ParameterType>& parameter_types = cast_term->parameter_types();
        for (std::vector<ParameterType>::const_iterator ii = parameter_types.begin(), ie = parameter_types.end(); ii != ie; ++ii)
          setup_term(ii->value);
        setup_term(cast_term->result_type().value);
        break;
      }
      
      default:
        return; // Skip adding to definition list
      }
      
      if (TermDefinitionList *dl = term_definition_list(term))
        dl->push_back(term);
    }
Ejemplo n.º 3
0
 void DisassemblerContext::print_recursive(const ValuePtr<RecursiveType>& term) {
   *m_output << "recursive (";
   
   boost::format name_formatter("%%%s");
   
   for (RecursiveType::ParameterList::const_iterator ib = term->parameters().begin(), ii = term->parameters().begin(), ie = term->parameters().end(); ii != ie; ++ii) {
     if (ii != ib)
       *m_output << ", ";
     
     *m_output << name(*ii) << " : ";
     print_term((*ii)->type(), false);
   }
   
   *m_output << ") > ";
   
   if (term->result())
     print_term(term->result(), true);
   else
     *m_output << "NULL";
   
   *m_output << ";\n";
 }
Ejemplo n.º 4
0
    void DisassemblerContext::setup_term_definition(const ValuePtr<>& term) {
      if (!m_defined_terms.insert(term).second)
        return;
      
      setup_term_name(term);

      switch (term->term_type()) {
      case term_recursive: {
        ValuePtr<RecursiveType> recursive = value_cast<RecursiveType>(term);
        for (RecursiveType::ParameterList::const_iterator ii = recursive->parameters().begin(), ie = recursive->parameters().end(); ii != ie; ++ii) {
          setup_term_name(*ii);
          setup_term((*ii)->type());
        }
        if (recursive->result())
          setup_term(recursive->result());
        break;
      }
        
      case term_global_variable: {
        ValuePtr<GlobalVariable> gvar = value_cast<GlobalVariable>(term);
        setup_term(gvar->value_type());
        if (gvar->value())
          setup_term(gvar->value());
        break;
      }
      
      case term_function: {
        ValuePtr<Function> function = value_cast<Function>(term);
        setup_function(function);
        break;
      }
      
      case term_function_parameter: {
        ValuePtr<FunctionParameter> param = value_cast<FunctionParameter>(term);
        setup_term(param->type());
        break;
      }
      
      case term_instruction: {
        class MyVisitor : public InstructionVisitor {
          DisassemblerContext *m_self;
        public:
          MyVisitor(DisassemblerContext *self) : m_self(self) {}
          virtual void next(ValuePtr<>& v) {if (v) m_self->setup_term(v);}
        };
        
        MyVisitor my_visitor(this);
        ValuePtr<Instruction> insn = value_cast<Instruction>(term);
        insn->instruction_visit(my_visitor);
        m_local_definitions[insn->block()].push_back(insn);
        break;
      }
      
      case term_phi: {
        ValuePtr<Phi> phi = value_cast<Phi>(term);
        const std::vector<PhiEdge>& edges = phi->edges();
        for (std::vector<PhiEdge>::const_iterator ii = edges.begin(), ie = edges.end(); ii != ie; ++ii) {
          setup_term(ii->block);
          setup_term(ii->value);
        }
        break;
      }
      
      default:
        setup_term(term);
        break;
      }
    }