blob: de32204bfb9feb4711dfedcf98221e5054597b1e [file] [log] [blame]
Keun Soo Yimb8edda32016-04-27 17:31:00 -07001/*
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#ifndef __VTS_SYSFUZZER_COMPILER_CODEGENBASE_H__
18#define __VTS_SYSFUZZER_COMPILER_CODEGENBASE_H__
19
20#include <fstream>
21#include <iostream>
22#include <sstream>
23#include <string>
24
25#include "test/vts/sysfuzzer/common/proto/InterfaceSpecificationMessage.pb.h"
26
27using namespace std;
28
29namespace android {
30namespace vts {
31
32class CodeGenBase {
33 public:
34 explicit CodeGenBase(const char* input_vts_file_path, const char* vts_name);
35 virtual ~CodeGenBase();
36
37 // Generate both a C/C++ file and its header file.
38 void GenerateAll(std::stringstream& cpp_ss,
39 std::stringstream& h_ss,
40 const InterfaceSpecificationMessage& message);
41
42 protected:
43 // Generates code for Fuzz(...) function body.
44 virtual void GenerateCppBodyFuzzFunction(
45 std::stringstream& cpp_ss,
46 const InterfaceSpecificationMessage& message,
47 const string& fuzzer_extended_class_name) = 0;
48
49 // Generates header code to declare the C/C++ global functions.
50 virtual void GenerateHeaderGlobalFunctionDeclarations(
51 std::stringstream& h_ss,
52 const string& function_prototype) = 0;
53
54 // Generates code for the bodies of the C/C++ global functions.
55 virtual void GenerateCppBodyGlobalFunctions(
56 std::stringstream& cpp_ss,
57 const string& function_prototype,
58 const string& fuzzer_extended_class_name) = 0;
59
60 // Generates code that opens the default namespaces.
61 void GenerateOpenNameSpaces(std::stringstream& ss);
62
63 // Generates code that closes the default namespaces.
64 void GenerateCloseNameSpaces(std::stringstream& ss);
65
Keun Soo Yimffb07ba2016-05-18 16:22:45 -070066 // Generates code that starts the measurement.
67 void GenerateCodeToStartMeasurement(std::stringstream& ss);
68
69 // Generates code that stops the measurement.
70 void GenerateCodeToStopMeasurement(std::stringstream& ss);
71
Keun Soo Yimb8edda32016-04-27 17:31:00 -070072 private:
73 const char* input_vts_file_path_;
74 const char* vts_name_;
75};
76
77} // namespace vts
78} // namespace android
79
80#endif // __VTS_SYSFUZZER_COMPILER_CODEGENBASE_H__