63        self, systemc_clang_build_dir=None, llvm_install_path=None, systemc_path=None
 
   65        if systemc_clang_build_dir:
 
   66            self._systemc_clang_build_dir = systemc_clang_build_dir
 
   68            self._systemc_clang_build_dir = os.environ["SYSTEMC_CLANG_BUILD_DIR"]
 
   71            self._llvm_install_path = llvm_install_path
 
   73            self._llvm_install_path = os.environ["LLVM_INSTALL_DIR"]
 
   76            self._systemc_path = systemc_path
 
   78            self._systemc_path = os.environ["SYSTEMC"]
 
   80        self.__check_systemc_clang_executable_exists()
 
 
   96    def llvm_inc_dir(self):
 
   98        returns the include directory necessary for systemc-clang to locate headers.
 
   99        Currently, it only supports version 12.0.0
 
  101        # TDOO: dynamically determines clang version
 
  102        return os.path.join(self.llvm_install_path, "lib/clang/12.0.0/include")
 
 
  112    def execute(self, args, target_name=None):
 
  114        executes systemc-clang as if it is on the commandline
 
  116        bin_path = self.systemc_clang_binary
 
  118        cmd = [bin_path, *args_to_sysc]
 
  119        result = subprocess.run(
 
  120            cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
 
  121        )  # in case the command fail, an exception will be raised
 
  123        err = result.stderr.decode("utf-8")
 
  124        res = list(re.finditer(r"^.*fatal error.*$", err, re.MULTILINE))
 
  125        if result.returncode != 0:
 
  126            raise SystemCClangFatalError('systemc-clang binary exits with non-zero return code: \n{}'.format(err))
 
  128            msg = "\n".join(x.group() for x in res)
 
  129            raise SystemCClangFatalError(
 
  130                """Fatal error captured in systemc-clang stderr, try run systemc-clang separately to identify the error:\n"""
 
  134        result = SystemCClang.__get_systemc_clang_output_files(args)
 
  136            if not Path(t).exists():
 
  137                raise SystemCClangFatalError('Target file: {} is not generated by systemc-clang binary'.format(t))
 
 
  141    def __get_systemc_clang_output_files(argv):
 
  142        sources = SystemCClang.__get_sources_from_args(argv)
 
  143        target = SystemCClang.__get_hdl_file_out(argv)
 
  145            target = [x.replace(".cpp", "_hdl.txt") for x in sources]
 
  147            target = [str(Path(target).absolute()) + '.txt']
 
 
  151    def __get_hdl_file_out(argv):
 
  154        for idx, arg in enumerate(argv):
 
  155            if arg == '-hdl-file-out':
 
  156                if idx + 1 >= len(argv):
 
  157                    raise ValueError('-hdl-file-out option is specified but no output file is specified')
 
 
  162    def __get_sources_from_args(argv):
 
  165            sources.append(argv[0])
 
  167            for idx, arg in enumerate(argv):
 
  169                    if arg != '-hdl-file-out':
 
  171                elif not arg.startswith('--'):
 
  172                    if argv[idx - 1] != '-hdl-file-out':