docstr: Write the Python-C++ bridge (myproject_bridge.cpp)
  
  Args:
      model (ModelGraph): the hls4ml model.
docstr_tok: ["Write","the","Python-C++","bridge","(","myproject_bridge.cpp",")","Args",":","model","(","ModelGraph",")",":","the","hls4ml","model","."]
code: def write_bridge(self, model):
      """Write the Python-C++ bridge (myproject_bridge.cpp)
  
      Args:
          model (ModelGraph): the hls4ml model.
      """
  
      filedir = os.path.dirname(os.path.abspath(__file__))
      f = open(
          os.path.join(
              filedir, "../templates/vivado/myproject_bridge.cpp"
          )
      )
      fout = open(
          f"{model.config.get_output_dir()}/{model.config.get_project_name()}_bridge.cpp",
          "w",
      )
  
      model_inputs = model.get_input_variables()
      model_outputs = model.get_output_variables()
      model_brams = [
          var
          for var in model.get_weight_variables()
          if var.storage.lower() == "bram"
      ]
  
      indent = "    "
  
      for line in f.readlines():
          if "MYPROJECT" in line:
              newline = line.replace(
                  "MYPROJECT",
                  format(model.config.get_project_name().upper()),
              )
          elif "myproject" in line:
              newline = line.replace(
                  "myproject", format(model.config.get_project_name())
              )
          elif "// hls-fpga-machine-learning insert bram" in line:
              newline = line
              for bram in model_brams:
                  newline += (
                      f'#include "firmware/weights/{bram.name}.h"\n'
                  )
          elif "// hls-fpga-machine-learning insert header" in line:
              dtype = line.split("#", 1)[1].strip()
              inputs_str = ", ".join(
                  [
                      f"{dtype} {i.name}[{i.size_cpp()}]"
                      for i in model_inputs
                  ]
              )
              outputs_str = ", ".join(
                  [
                      f"{dtype} {o.name}[{o.size_cpp()}]"
                      for o in model_outputs
                  ]
              )
  
              newline = ""
              newline += indent + inputs_str + ",\n"
              newline += indent + outputs_str + "\n"
          elif "// hls-fpga-machine-learning insert wrapper" in line:
              dtype = line.split("#", 1)[1].strip()
              newline = ""
              for i in model_inputs:
                  newline += indent + "{var};\n".format(
                      var=i.definition_cpp(name_suffix="_ap")
                  )
                  newline += (
                      indent
                      + "nnet::convert_data<{}, {}, {}>({}, {}_ap);\n".format(
                          dtype,
                          i.type.name,
                          i.size_cpp(),
                          i.name,
                          i.name,
                      )
                  )
              newline += "\n"
  
              for o in model_outputs:
                  newline += indent + "{var};\n".format(
                      var=o.definition_cpp(name_suffix="_ap")
                  )
  
              newline += "\n"
  
              input_vars = ",".join(
                  [i.name + "_ap" for i in model_inputs]
              )
              bram_vars = ",".join([b.name for b in model_brams])
              output_vars = ",".join(
                  [o.name + "_ap" for o in model_outputs]
              )
  
              # Concatenate the input, output, and bram variables. Filter out empty/null values
              all_vars = ",".join(
                  filter(None, [input_vars, output_vars, bram_vars])
              )
  
              top_level = (
                  indent
                  + f"{model.config.get_project_name()}({all_vars});\n"
              )
              newline += top_level
  
              newline += "\n"
  
              for o in model_outputs:
                  newline += (
                      indent
                      + "nnet::convert_data<{}, {}, {}>({}_ap, {});\n".format(
                          o.type.name,
                          dtype,
                          o.size_cpp(),
                          o.name,
                          o.name,
                      )
                  )
          elif (
              "// hls-fpga-machine-learning insert trace_outputs"
              in line
          ):
              newline = ""
              for layer in model.get_layers():
                  func = layer.get_attr("function_cpp", None)
                  if (
                      func
                      and model.config.trace_output
                      and layer.get_attr("trace", False)
                  ):
                      vars = layer.get_variables()
                      for var in vars:
                          newline += (
                              indent
                              + "nnet::trace_outputs->insert(std::pair<std::string, void *>("
                              + f'"{layer.name}", (void *) malloc({var.size_cpp()} * element_size)));\n'
                          )
  
          else:
              newline = line
          fout.write(newline)
  
      f.close()
      fout.close()
  
imports: import glob
  import os
  import tarfile
  from collections import OrderedDict
  from shutil import copyfile, copytree, rmtree
  import numpy
  import yaml
  from hls4ml.writer.writers import Writer
label_desc: Use image node_id 11 for calling the VivadoWriter obj's underlying member method code with example usage: obj.write_bridge(model) without return types