xref: /llvm-project/clang/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx_main.cpp (revision 2946cd701067404b99c39fb29dc9c74bd7193eb3)
1f051f5d1SMatt Morehouse //==-- proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion ----------==//
2f051f5d1SMatt Morehouse //
3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f051f5d1SMatt Morehouse //
7f051f5d1SMatt Morehouse //===----------------------------------------------------------------------===//
8f051f5d1SMatt Morehouse //
9f051f5d1SMatt Morehouse // Implements a simple driver to print a C++ program from a protobuf.
10f051f5d1SMatt Morehouse //
11f051f5d1SMatt Morehouse //===----------------------------------------------------------------------===//
12f051f5d1SMatt Morehouse #include <fstream>
13f051f5d1SMatt Morehouse #include <iostream>
14f051f5d1SMatt Morehouse #include <streambuf>
15f051f5d1SMatt Morehouse #include <string>
16f051f5d1SMatt Morehouse 
17f051f5d1SMatt Morehouse #include "proto_to_cxx.h"
18f051f5d1SMatt Morehouse 
main(int argc,char ** argv)19f051f5d1SMatt Morehouse int main(int argc, char **argv) {
20f051f5d1SMatt Morehouse   for (int i = 1; i < argc; i++) {
21f051f5d1SMatt Morehouse     std::fstream in(argv[i]);
22f051f5d1SMatt Morehouse     std::string str((std::istreambuf_iterator<char>(in)),
23f051f5d1SMatt Morehouse                     std::istreambuf_iterator<char>());
24f051f5d1SMatt Morehouse     std::cout << "// " << argv[i] << std::endl;
25f051f5d1SMatt Morehouse     std::cout << clang_fuzzer::ProtoToCxx(
26f051f5d1SMatt Morehouse         reinterpret_cast<const uint8_t *>(str.data()), str.size());
27f051f5d1SMatt Morehouse   }
28f051f5d1SMatt Morehouse }
29f051f5d1SMatt Morehouse 
30