Skip to content

Commit

Permalink
Add license to autogenerated files.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-hegna committed Apr 22, 2023
1 parent 82a1285 commit b5e669f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler_opt/tools/tflite_to_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def main(argv):
tflite_to_cpp_lib.print_llvm_registration_handle(
model=model, base_class=FLAGS.base_class)

model = tflite_to_cpp_lib.add_license_and_notice(model=model)

if FLAGS.clang_format_path:
model = tflite_to_cpp_lib.format_model(
model=model,
Expand Down
25 changes: 25 additions & 0 deletions compiler_opt/tools/tflite_to_cpp_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@
_TFAGENTS_POLICY_NAME = 'action'
_MODEL_NAMESPACE = 'llvm::emitc::generated'

# pylint: disable=line-too-long
_LICENSE_AND_NOTICE = """// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
// This code was originally sourced from github.com/iml130/mlir-emitc and has
// been modified to fit the needs of generated C++ models in LLVM.
"""


def _fmt_includes(includes):
return '\n'.join([f'#include "{hdr}"' for hdr in includes]) + '\n'
Expand Down Expand Up @@ -316,6 +335,12 @@ def add_additional_headers(model: EmitCModel, additional_headers: list[str]):
return dataclasses.replace(model, hdr=new_hdr)


def add_license_and_notice(model: EmitCModel) -> EmitCModel:
new_cpp = _LICENSE_AND_NOTICE + model.cpp
new_hdr = _LICENSE_AND_NOTICE + model.hdr
return dataclasses.replace(model, cpp=new_cpp, hdr=new_hdr)


def print_llvm_registration_handle(model: EmitCModel, base_class: str):
"""Prints LLVM model registration code.
Expand Down

0 comments on commit b5e669f

Please sign in to comment.