| 1107 | } // namespace |
| 1108 | |
| 1109 | void WriteCCOps(const OpList& ops, const ApiDefMap& api_def_map, |
| 1110 | const string& dot_h_fname, const string& dot_cc_fname) { |
| 1111 | Env* env = Env::Default(); |
| 1112 | |
| 1113 | // Write the initial boilerplate to the .h and .cc files. |
| 1114 | std::unique_ptr<WritableFile> h = nullptr; |
| 1115 | std::unique_ptr<WritableFile> cc = nullptr; |
| 1116 | TF_CHECK_OK(env->NewWritableFile(dot_h_fname, &h)); |
| 1117 | TF_CHECK_OK(env->NewWritableFile(dot_cc_fname, &cc)); |
| 1118 | string op_header_guard; |
| 1119 | StartFiles(false, dot_h_fname, h.get(), cc.get(), &op_header_guard); |
| 1120 | |
| 1121 | // Create the internal versions of these files for the hidden ops. |
| 1122 | std::unique_ptr<WritableFile> internal_h = nullptr; |
| 1123 | std::unique_ptr<WritableFile> internal_cc = nullptr; |
| 1124 | const string internal_dot_h_fname = MakeInternal(dot_h_fname); |
| 1125 | TF_CHECK_OK(env->NewWritableFile(internal_dot_h_fname, &internal_h)); |
| 1126 | TF_CHECK_OK(env->NewWritableFile(MakeInternal(dot_cc_fname), &internal_cc)); |
| 1127 | string internal_op_header_guard; |
| 1128 | StartFiles(true /* internal */, internal_dot_h_fname, internal_h.get(), |
| 1129 | internal_cc.get(), &internal_op_header_guard); |
| 1130 | |
| 1131 | for (const auto& graph_op_def : ops.op()) { |
| 1132 | // Skip deprecated ops. |
| 1133 | // TODO(josh11b): If needed, can put them into a "deprecated" namespace |
| 1134 | // instead of skipping. |
| 1135 | if (graph_op_def.has_deprecation() && |
| 1136 | graph_op_def.deprecation().version() <= TF_GRAPH_DEF_VERSION) { |
| 1137 | continue; |
| 1138 | } |
| 1139 | |
| 1140 | // We use a hand-written wrapper for "Const", since the generated |
| 1141 | // code depends on it. |
| 1142 | if (graph_op_def.name() == "Const") continue; |
| 1143 | |
| 1144 | const auto* api_def = api_def_map.GetApiDef(graph_op_def.name()); |
| 1145 | |
| 1146 | std::vector<string> aliases; |
| 1147 | if (api_def->visibility() == ApiDef::SKIP) continue; |
| 1148 | // First endpoint is canonical, the rest are aliases. |
| 1149 | for (int endpoint_i = 1; endpoint_i < api_def->endpoint_size(); |
| 1150 | ++endpoint_i) { |
| 1151 | aliases.push_back(api_def->endpoint(endpoint_i).name()); |
| 1152 | } |
| 1153 | if (api_def->visibility() == ApiDef::HIDDEN) { |
| 1154 | // Write hidden ops to _internal.h and _internal.cc. |
| 1155 | WriteCCOp(graph_op_def, *api_def, aliases, internal_h.get(), |
| 1156 | internal_cc.get()); |
| 1157 | continue; |
| 1158 | } |
| 1159 | // This isn't a hidden op, write it to the main files. |
| 1160 | WriteCCOp(graph_op_def, *api_def, aliases, h.get(), cc.get()); |
| 1161 | } |
| 1162 | |
| 1163 | FinishFiles(false, h.get(), cc.get(), op_header_guard); |
| 1164 | FinishFiles(true /* internal */, internal_h.get(), internal_cc.get(), |
| 1165 | internal_op_header_guard); |
| 1166 | } |