1 /* Copyright 2017 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 16 #include <string> 17 18 #include "tensorflow/core/lib/strings/str_util.h" 19 #include "tensorflow/core/platform/logging.h" 20 #include "tensorflow/java/src/gen/cc/op_generator.h" 21 22 namespace tensorflow { 23 namespace java { 24 namespace { 25 26 string CamelCase(const string& str, char delimiter, bool upper) { 27 string result; 28 bool cap = upper; 29 for (string::const_iterator it = str.begin(); it != str.end(); ++it) { 30 const char c = *it; 31 if (c == delimiter) { 32 cap = true; 33 } else if (cap) { 34 result += toupper(c); 35 cap = false; 36 } else { 37 result += c; 38 } 39 } 40 return result; 41 } 42 43 } // namespace 44 45 OpGenerator::OpGenerator() : env(Env::Default()) {} 46 47 OpGenerator::~OpGenerator() {} 48 49 Status OpGenerator::Run(const OpList& ops, const string& lib_name, 50 const string& base_package, const string& output_dir) { 51 const string package = 52 base_package + '.' + str_util::StringReplace(lib_name, "_", "", true); 53 const string package_path = 54 output_dir + '/' + str_util::StringReplace(package, ".", "/", true); 55 const string group = CamelCase(lib_name, '_', false); 56 57 if (!env->FileExists(package_path).ok()) { 58 TF_CHECK_OK(env->RecursivelyCreateDir(package_path)); 59 } 60 61 LOG(INFO) << "Generating Java wrappers for '" << lib_name << "' operations"; 62 // TODO(karllessard) generate wrappers from list of ops 63 64 return Status::OK(); 65 } 66 67 } // namespace java 68 } // namespace tensorflow 69