コード例 #1
0
ファイル: xml_symbol_hashing.cpp プロジェクト: Dthird/CBMC
void xml_symbol_convertt::convert(const symbolt& sym, xmlt &root)
{
  xmlt &xmlsym = root.new_element("symbol");
  irepcache.push_back(irept());
  sym.to_irep(irepcache.back());  
  irepconverter.reference_convert(irepcache.back(), xmlsym);
}
コード例 #2
0
ファイル: xml_symbol.cpp プロジェクト: diffblue/cbmc
void convert(const xmlt &xmlsym, symbolt& symbol)
{
  symbol.name=xmlsym.get_attribute("name");

  for(xmlt::elementst::const_iterator
      it=xmlsym.elements.begin();
      it!=xmlsym.elements.end();
      it++)
  {
    if (it->name=="type")
    {
      convert(*it, symbol.type);
    }
    else if (it->name=="value")
    {
      if (it->data=="compiled")
      {
        symbol.value.id("code");
      }
      else
      {
        convert(*it, symbol.value);
      }
    }
    else if (it->name=="flags")
    {
      symbol.is_lvalue = it->get_attribute_bool("lvalue");
      symbol.is_static_lifetime = it->get_attribute_bool("static_lifetime");
      symbol.is_file_local = it->get_attribute_bool("file_local");
      symbol.is_property = it->get_attribute_bool("theorem");
      symbol.is_thread_local = it->get_attribute_bool("thread_local");
      symbol.is_type = it->get_attribute_bool("type");
      symbol.is_extern = it->get_attribute_bool("extern");
      symbol.is_input = it->get_attribute_bool("input");
      symbol.is_output = it->get_attribute_bool("output");
      symbol.is_macro = it->get_attribute_bool("macro");
      //symbol.is_actual = it->get_attribute_bool("actual");
      //symbol.binding = it->get_attribute_bool("binding");
      //symbol.free_var = it->get_attribute_bool("free_var");
      symbol.is_state_var = it->get_attribute_bool("statevar");

      for(xmlt::elementst::const_iterator
          fit=it->elements.begin();
          fit!=it->elements.end();
          fit++)
      {
        if(fit->name=="mode")
          symbol.mode=fit->data;
        else if(fit->name=="base_name")
          symbol.base_name=fit->data;
        else if(fit->name=="module")
          symbol.module=fit->data;
      }
    }
    else if(it->name=="location")
    {
      convert(*it, symbol.location);
    }
  }
}
コード例 #3
0
ファイル: call_graph.cpp プロジェクト: AnnaTrost/2ls
void summary_to_call_graph(const xmlt &xml, call_grapht &dest)
{
  xmlt::elementst::const_iterator functions=xml.find("functions");
  
  if(functions!=xml.elements.end())
  {
    for(xmlt::elementst::const_iterator
        f_it=functions->elements.begin();
        f_it!=functions->elements.end();
        f_it++)
    {
      irep_idt caller=f_it->get_attribute("id");

      for(xmlt::elementst::const_iterator
          c_it=f_it->elements.begin();
          c_it!=f_it->elements.end();
          c_it++)
      {
        if(c_it->name=="called")
        {
          irep_idt callee=c_it->get_attribute("id");
          dest.add(caller, callee);
        }
      }
    }
  }
}
コード例 #4
0
ファイル: xml_symbol.cpp プロジェクト: diffblue/cbmc
void convert(const symbolt& sym, xmlt &root)
{
  xmlt &xmlsym = root.new_element("symbol");
  xmlsym.set_attribute("name", id2string(sym.name));

  xmlt &xmltype = xmlsym.new_element("type");
  convert(sym.type, xmltype);

  xmlt &xmlval = xmlsym.new_element("value");
  if(!sym.is_type && sym.type.id() == "code" && !sym.value.is_nil())
    xmlval.data = "compiled"; // only for implemented functions
  else
    convert(sym.value, xmlval);

  xmlt &flags = xmlsym.new_element("flags");

  flags.set_attribute_bool("lvalue", sym.is_lvalue);
  flags.set_attribute_bool("static_lifetime", sym.is_static_lifetime);
  flags.set_attribute_bool("file_local", sym.is_file_local);
  flags.set_attribute_bool("theorem", sym.is_property);
  flags.set_attribute_bool("thread_local", sym.is_thread_local);
  flags.set_attribute_bool("type", sym.is_type);
  flags.set_attribute_bool("extern", sym.is_extern);
  flags.set_attribute_bool("input", sym.is_input);
  flags.set_attribute_bool("output", sym.is_output);
  flags.set_attribute_bool("macro", sym.is_macro);
  //flags.set_attribute_bool("actual", sym.is_actual);
  //flags.set_attribute_bool("binding", sym.binding);
  //flags.set_attribute_bool("free_var", sym.free_var);
  flags.set_attribute_bool("statevar", sym.is_state_var);

  xmlt &mode = flags.new_element("mode");
  mode.data = id2string(sym.mode);

  flags.new_element("base_name").data=id2string(sym.base_name);
  flags.new_element("module").data=id2string(sym.module);

  if (sym.pretty_name.size()>0)
    flags.new_element("pretty_name").data=id2string(sym.pretty_name);

  xmlt &xmlloc = xmlsym.new_element("location");
  convert(sym.location, xmlloc);
  xmlloc.name = "location"; // convert overwrote this
}
コード例 #5
0
ファイル: xml_goto_program.cpp プロジェクト: dcattaruzza/cbmc
void convert(const goto_programt &goto_program,
             xmlt &xml)
{
  std::stringstream tmp;
  // std::cout << "TNO: " << goto_program.target_numbers.size() << std::endl;

  for(const auto &inst : goto_program.instructions)
  {
    xmlt &ins=xml.new_element("instruction");

    if(!inst.location.is_nil())
    {
      convert(inst.location, ins.new_element("location"));
    }

    if(!inst.labels.empty())
    {
      xmlt &lbl=ins.new_element("labels");
      for(goto_programt::instructiont::labelst::const_iterator
          l_it=inst.labels.begin();
          l_it!=inst.labels.end();
          l_it++)
      {
        lbl.new_element("label").set_attribute("name", id2string(*l_it));
      }
    }


    if(inst.target_number!=0)
    {
      // std::cout << "Targetlabel found!" << std::endl;
      tmp.str("");
      tmp << inst.target_number;
      ins.set_attribute("targetlabel", tmp.str());
    }

    switch(inst.type)
    {
        case GOTO:
        {
          ins.name="goto";
          if(!inst.guard.is_true())
          {
            xmlt &g=ins.new_element("guard");
            convert(inst.guard, g);
          }
          xmlt &tgt=ins.new_element("targets");
          for(goto_programt::instructiont::targetst::const_iterator
              gt_it=inst.targets.begin();
              gt_it!=inst.targets.end();
              gt_it++)
          {
            tmp.str("");
            tmp << (*gt_it)->target_number;
            tgt.new_element("target").data=tmp.str();
          }
          break;
        }

        case ASSUME:
        {
          ins.name="assume";
          xmlt &g=ins.new_element("guard");
          convert(inst.guard, g);

          const irep_idt &comment=inst.location.get("comment");

          if(comment!="")
            ins.new_element("comment").data=id2string(comment);

          break;
        }

        case ASSERT:
        {
          ins.name="assert";
          xmlt &g=ins.new_element("guard");
          convert(inst.guard, g);
          const irep_idt &comment=inst.location.get("comment");

          if(comment!="")
            ins.new_element("comment").data=id2string(comment);

          break;
        }

        case SKIP:
        ins.name="skip";
        break;

        case END_FUNCTION:
        ins.name="end_function";
        break;

        case LOCATION:
        ins.name="location";
        break;

        case DEAD:
        ins.name="dead";
        break;

        case ATOMIC_BEGIN:
        ins.name="atomic_begin";
        break;

        case ATOMIC_END:
        ins.name="atomic_end";
        break;

        case RETURN:
        {
          ins.name="return";
          xmlt &c=ins.new_element("code");
          convert(inst.code, c);
          break;
        }

        case OTHER:
        {
          ins.name="instruction";
          xmlt &c=ins.new_element("code");
          convert(inst.code, c);
          break;
        }

        case ASSIGN:
        {
          ins.name="assign";
          xmlt &c=ins.new_element("code");
          convert(inst.code, c);
          break;
        }

        case FUNCTION_CALL:
        {
          ins.name="functioncall";
          xmlt &c=ins.new_element("code");
          convert(inst.code, c);
          break;
        }

        case START_THREAD:
        {
          ins.name="thread_start";
          xmlt &tgt=ins.new_element("targets");
          if(inst.targets.size()==1)
          {
            tmp.str("");
            tmp << inst.targets.front()->target_number;
            tgt.new_element("target").data=tmp.str();
          }
          break;
        }

        case END_THREAD:
        ins.name="thread_end";
        break;

        default:
        ins.name="unknown";
        break;
    }

    if(inst.function!="")
    {
      xmlt &fnc=ins.new_element("function");
      fnc.data=id2string(inst.function);
    }
  }
}
コード例 #6
0
ファイル: xml_goto_trace.cpp プロジェクト: diffblue/cbmc
void convert(
  const namespacet &ns,
  const goto_tracet &goto_trace,
  xmlt &dest)
{
  dest=xmlt("goto_trace");

  source_locationt previous_source_location;

  for(const auto & it : goto_trace.steps)
  {
    const source_locationt &source_location=it.pc->source_location;

    xmlt xml_location;
    if(source_location.is_not_nil() && source_location.get_file()!="")
      xml_location=xml(source_location);

    switch(it.type)
    {
    case goto_trace_stept::ASSERT:
      if(!it.cond_value)
      {
        irep_idt property_id;

        if(it.pc->is_assert())
          property_id=source_location.get_property_id();
        else if(it.pc->is_goto()) // unwinding, we suspect
        {
          property_id=
            id2string(it.pc->source_location.get_function())+".unwind."+
            i2string(it.pc->loop_number);
        }

        xmlt &xml_failure=dest.new_element("failure");

        xml_failure.set_attribute_bool("hidden", it.hidden);
        xml_failure.set_attribute("thread", i2string(it.thread_nr));
        xml_failure.set_attribute("step_nr", i2string(it.step_nr));
        xml_failure.set_attribute("reason", id2string(it.comment));
        xml_failure.set_attribute("property", id2string(property_id));

        if(xml_location.name!="")
          xml_failure.new_element().swap(xml_location);
      }
      break;

    case goto_trace_stept::ASSIGNMENT:
    case goto_trace_stept::DECL:
      {
        irep_idt identifier=it.lhs_object.get_identifier();
        xmlt &xml_assignment=dest.new_element("assignment");

        if(xml_location.name!="")
          xml_assignment.new_element().swap(xml_location);

        std::string value_string, binary_string, type_string,
                    full_lhs_string, full_lhs_value_string;

        if(it.lhs_object_value.is_not_nil())
          value_string=from_expr(ns, identifier, it.lhs_object_value);

        if(it.full_lhs.is_not_nil())
          full_lhs_string=from_expr(ns, identifier, it.full_lhs);

        if(it.full_lhs_value.is_not_nil())
          full_lhs_value_string=from_expr(ns, identifier, it.full_lhs_value);

        if(it.lhs_object_value.type().is_not_nil())
          type_string=from_type(ns, identifier, it.lhs_object_value.type());

        const symbolt *symbol;
        irep_idt base_name, display_name;

        if(!ns.lookup(identifier, symbol))
        {
          base_name=symbol->base_name;
          display_name=symbol->display_name();
          if(type_string=="")
            type_string=from_type(ns, identifier, symbol->type);

          xml_assignment.set_attribute("mode", id2string(symbol->mode));
        }

        xml_assignment.new_element("type").data=type_string;
        xml_assignment.new_element("full_lhs").data=full_lhs_string;
        xml_assignment.new_element("full_lhs_value").data=full_lhs_value_string;
        xml_assignment.new_element("value").data=value_string;

        xml_assignment.set_attribute_bool("hidden", it.hidden);
        xml_assignment.set_attribute("thread", i2string(it.thread_nr));
        xml_assignment.set_attribute("identifier", id2string(identifier));
        xml_assignment.set_attribute("base_name", id2string(base_name));
        xml_assignment.set_attribute("display_name", id2string(display_name));
        xml_assignment.set_attribute("step_nr", i2string(it.step_nr));

        xml_assignment.set_attribute("assignment_type",
          it.assignment_type==goto_trace_stept::ACTUAL_PARAMETER?"actual_parameter":
          "state");

        if(it.lhs_object_value.is_not_nil())
          xml_assignment.new_element("value_expression").new_element(xml(it.lhs_object_value, ns));
      }
      break;

    case goto_trace_stept::OUTPUT:
      {
        printf_formattert printf_formatter(ns);
        printf_formatter(id2string(it.format_string), it.io_args);
        std::string text=printf_formatter.as_string();
        xmlt &xml_output=dest.new_element("output");

        xml_output.new_element("text").data=text;

        xml_output.set_attribute_bool("hidden", it.hidden);
        xml_output.set_attribute("thread", i2string(it.thread_nr));
        xml_output.set_attribute("step_nr", i2string(it.step_nr));

        if(xml_location.name!="")
          xml_output.new_element().swap(xml_location);

        for(const auto l_it : it.io_args)
        {
          xml_output.new_element("value").data=from_expr(ns, "", l_it);
          xml_output.new_element("value_expression").
            new_element(xml(l_it, ns));
        }
      }
      break;

    case goto_trace_stept::INPUT:
      {
        xmlt &xml_input=dest.new_element("input");
        xml_input.new_element("input_id").data=id2string(it.io_id);

        xml_input.set_attribute_bool("hidden", it.hidden);
        xml_input.set_attribute("thread", i2string(it.thread_nr));
        xml_input.set_attribute("step_nr", i2string(it.step_nr));

        for(const auto & l_it : it.io_args)
        {
          xml_input.new_element("value").data=from_expr(ns, "", l_it);
          xml_input.new_element("value_expression").
            new_element(xml(l_it, ns));
        }

        if(xml_location.name!="")
          xml_input.new_element().swap(xml_location);
      }
      break;

    case goto_trace_stept::FUNCTION_CALL:
    case goto_trace_stept::FUNCTION_RETURN:
      {
        std::string tag=
          (it.type==goto_trace_stept::FUNCTION_CALL)?"function_call":"function_return";
        xmlt &xml_call_return=dest.new_element(tag);

        xml_call_return.set_attribute_bool("hidden", it.hidden);
        xml_call_return.set_attribute("thread", i2string(it.thread_nr));
        xml_call_return.set_attribute("step_nr", i2string(it.step_nr));

        const symbolt &symbol=ns.lookup(it.identifier);
        xmlt &xml_function=xml_call_return.new_element("function");
        xml_function.set_attribute("display_name", id2string(symbol.display_name()));
        xml_function.set_attribute("identifier", id2string(it.identifier));
        xml_function.new_element()=xml(symbol.location);

        if(xml_location.name!="")
          xml_call_return.new_element().swap(xml_location);
      }
      break;

    default:
      if(source_location!=previous_source_location)
      {
        // just the source location
        if(xml_location.name!="")
        {
          xmlt &xml_location_only=dest.new_element("location-only");

          xml_location_only.set_attribute_bool("hidden", it.hidden);
          xml_location_only.set_attribute("thread", i2string(it.thread_nr));
          xml_location_only.set_attribute("step_nr", i2string(it.step_nr));

          xml_location_only.new_element().swap(xml_location);
        }
      }
    }

    if(source_location.is_not_nil() && source_location.get_file()!="")
      previous_source_location=source_location;
  }
}