Example #1
0
 void DisassemblerContext::print_instruction_term(const ValuePtr<Instruction>& term) {
   *m_output << term->operation_name();
   
   class MyVisitor : public InstructionVisitor {
     DisassemblerContext *m_self;
     
   public:
     MyVisitor(DisassemblerContext *self) : m_self(self) {}
     
     virtual void next(ValuePtr<>& ptr) {
       *m_self->m_output << ' ';
       m_self->print_term(ptr, true);
     }
   };
   
   MyVisitor my_visitor(this);
   term->instruction_visit(my_visitor);
   *m_output << ";\n";
 }
Example #2
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;
      }
    }