Program Listing for File EmitHLSToHLSBuildScript.cpp

↰ Return to documentation for file (lib/Target/EmitHLSToHLSBuildScript/EmitHLSToHLSBuildScript.cpp)

// Implementation of translation EmitHLSToHLSBuildScript
//
// @file
// @author     Jiahong Bi (jiahong.bi@tu-dresden.de)

#include "laksa-mlir/Target/EmitHLSToHLSBuildScript/HLSBuildScriptEmitter.h"
#include "laksa-mlir/Target/LaksaCommon/BufferInfo.h"

#include "llvm/Support/CommandLine.h"

using namespace mlir;
using namespace mlir::emithls;

namespace {

llvm::cl::opt<std::string> clHLSBuildHLSTcl(
    "hls-build-hls-tcl",
    llvm::cl::desc(
        "Vitis HLS script the generated shell script runs, as produced by the "
        "emithls-to-hls-tcl translation"),
    llvm::cl::init("run_hls.tcl"));

llvm::cl::opt<std::string> clHLSBuildVivadoTcl(
    "hls-build-vivado-tcl",
    llvm::cl::desc(
        "Vivado script the generated shell script runs, as produced by the "
        "emithls-to-vivado-tcl translation"),
    llvm::cl::init("run_vivado.tcl"));

} // namespace

//===----------------------------------------------------------------------===//
// Translation entry point
//===----------------------------------------------------------------------===//

LogicalResult
emithls::translateEmitHLSToHLSBuildScript(ModuleOp op, raw_ostream &os)
{
    FailureOr<FuncOp> topFunc = findLaksaTopFunc(op);
    if (failed(topFunc)) return failure();

    StringRef designName = topFunc->getSymName();

    os << "#!/bin/sh\n"
          "\n"
          "# Generated by ladle -t emithls-to-hls-build-script.\n"
          "# Assumes the Vitis and Vivado environment is already sourced.\n"
          "\n"
          "set -eu\n"
          "\n"
          "cd \"$(dirname \"$0\")\"\n"
          "\n"
          "echo \"INFO: Running Vitis HLS through "
       << clHLSBuildHLSTcl
       << "...\"\n"
          "vitis-run --mode hls --tcl "
       << clHLSBuildHLSTcl
       << "\n"
          "\n"
          "echo \"INFO: Running Vivado through "
       << clHLSBuildVivadoTcl
       << "...\"\n"
          "vivado -mode batch -source "
       << clHLSBuildVivadoTcl
       << "\n"
          "\n"
          "echo \"INFO: Extracting the bitstream from the exported XSA...\"\n"
          "unzip -p vivado_project/"
       << designName << "_bd.xsa " << designName << "_bd.bit > " << designName
       << ".bit\n"
          "\n"
          "echo \"INFO: Done, copy "
       << designName << ".bit next to app.c on the board\"\n";

    return success();
}