1 /*
2  * Copyright 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "FuzzerCodeGenBase.h"
18 
19 #include <iostream>
20 
21 using std::cerr;
22 using std::cout;
23 using std::endl;
24 using std::string;
25 
26 namespace android {
27 namespace vts {
28 
GenerateAll(Formatter &,Formatter & source_out)29 void FuzzerCodeGenBase::GenerateAll(Formatter & /* header_out */,
30                                     Formatter &source_out) {
31   GenerateSourceFile(source_out);
32 }
33 
GenerateHeaderFile(Formatter &)34 void FuzzerCodeGenBase::GenerateHeaderFile(Formatter & /* out */) {
35   cout << "Headers are not generated for fuzzer." << endl;
36 }
37 
GenerateSourceFile(Formatter & out)38 void FuzzerCodeGenBase::GenerateSourceFile(Formatter &out) {
39   if (!comp_spec_.has_interface()) {
40     return;
41   }
42   GenerateWarningComment(out);
43   GenerateSourceIncludeFiles(out);
44   GenerateUsingDeclaration(out);
45   GenerateOpenNameSpaces(out);
46   GenerateGlobalVars(out);
47   GenerateLLVMFuzzerInitialize(out);
48   GenerateLLVMFuzzerTestOneInput(out);
49   GenerateCloseNameSpaces(out);
50 }
51 
GenerateOpenNameSpaces(Formatter & out)52 void FuzzerCodeGenBase::GenerateOpenNameSpaces(Formatter &out) {
53   out << "namespace android {\n";
54   out << "namespace vts {\n\n";
55 }
56 
GenerateCloseNameSpaces(Formatter & out)57 void FuzzerCodeGenBase::GenerateCloseNameSpaces(Formatter &out) {
58   out << "}  // namespace vts\n";
59   out << "}  // namespace android\n";
60 }
61 
GenerateWarningComment(Formatter & out)62 void FuzzerCodeGenBase::GenerateWarningComment(Formatter &out) {
63   out << "// This file was auto-generated by VTS compiler.\n\n";
64 }
65 
66 }  // namespace vts
67 }  // namespace android
68