xref: /aosp_15_r20/external/tensorflow/tensorflow/c/experimental/ops/gen/cpp/renderers/cpp_file_renderer.cc (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 #include "tensorflow/c/experimental/ops/gen/cpp/renderers/cpp_file_renderer.h"
16 
17 #include "tensorflow/c/experimental/ops/gen/common/view_util.h"
18 #include "tensorflow/c/experimental/ops/gen/cpp/renderers/op_renderer.h"
19 #include "tensorflow/c/experimental/ops/gen/cpp/views/op_view.h"
20 
21 namespace tensorflow {
22 namespace generator {
23 namespace cpp {
24 
25 static const char *copyright =
26     R"(
27 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
28 
29 Licensed under the Apache License, Version 2.0 (the "License");
30 you may not use this file except in compliance with the License.
31 You may obtain a copy of the License at
32 
33     http://www.apache.org/licenses/LICENSE-2.0
34 
35 Unless required by applicable law or agreed to in writing, software
36 distributed under the License is distributed on an "AS IS" BASIS,
37 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38 See the License for the specific language governing permissions and
39 limitations under the License.
40 ==============================================================================*/
41 )";
42 
43 static const char *machine_generated =
44     "// This file is MACHINE GENERATED! Do not edit.";
45 
CppFileRenderer(RendererContext context,const std::vector<OpView> & ops)46 CppFileRenderer::CppFileRenderer(RendererContext context,
47                                  const std::vector<OpView> &ops)
48     : Renderer(context),
49       guard_(context),
50       name_space_(context),
51       includes_(context),
52       ops_(ops) {}
53 
Render()54 void CppFileRenderer::Render() {
55   CodeLines(copyright);
56   BlankLine();
57   CodeLine(machine_generated);
58   BlankLine();
59 
60   if (context_.mode == RendererContext::kHeader) {
61     guard_.Open();
62   } else {
63     includes_.SelfHeader();
64   }
65 
66   includes_.Headers();
67   name_space_.Open();
68   BlankLine();
69 
70   for (const OpView &op : ops_) {
71     OpRenderer(context_, op).Render();
72   }
73 
74   name_space_.Close();
75   if (context_.mode == RendererContext::kHeader) {
76     guard_.Close();
77   }
78 }
79 
80 }  // namespace cpp
81 }  // namespace generator
82 }  // namespace tensorflow
83