Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 74 additions & 43 deletions chc/cmdline/ParseManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import shlex
import shutil

from pathlib import Path

import xml.etree.ElementTree as ET

from typing import Any, Dict, List, Optional, Tuple
Expand Down Expand Up @@ -77,6 +79,7 @@ def __init__(
verbose: bool = True,
keepUnused: bool = False,
tgtplatform: str = "-m64",
preprocessed_path: str = "",
) -> None:
"""Initialize paths to code, results, and parser executable.

Expand Down Expand Up @@ -109,6 +112,7 @@ def __init__(
+ ". Target platform is set to -m64"
)
self._tgtplatform = "-m64"
self._preprocessed_path = preprocessed_path
self.config = Config()

@property
Expand Down Expand Up @@ -261,22 +265,36 @@ def preprocess_file_with_cc(
if mac:
cmd = cmd[:1] + macoptions + cmd[1:]
cmd = cmd[:1] + moreoptions + cmd[1:]

real_ifile = None
if self._preprocessed_path:
path = Path(self._preprocessed_path) / ifilename
path = path.resolve()
if path.is_file():
real_ifile = path

chklogger.logger.info("Changing directory to %s", self.projectpath)
os.chdir(self.projectpath)
if self.verbose:
chklogger.logger.info("Preprocess file: " + str(cmd))
p = subprocess.call(
cmd, cwd=self.projectpath, stderr=subprocess.STDOUT)
if p != 0:
chklogger.logger.warning("Result of preprocessing: " + str(p))
if real_ifile:
try:
shutil.copy(real_ifile, ifilename)
except shutil.SameFileError:
pass
else:
chklogger.logger.info("Preprocess file: " + str(cmd))
subprocess.call(
cmd,
cwd=self.projectpath,
stdout=open(os.devnull, "w"),
stderr=subprocess.STDOUT,
)
if self.verbose:
chklogger.logger.info("Preprocess file: " + str(cmd))
p = subprocess.call(
cmd, cwd=self.projectpath, stderr=subprocess.STDOUT)
if p != 0:
chklogger.logger.warning("Result of preprocessing: " + str(p))
else:
chklogger.logger.info("Preprocess file: " + str(cmd))
subprocess.call(
cmd,
cwd=self.projectpath,
stdout=open(os.devnull, "w"),
stderr=subprocess.STDOUT,
)
if copyfiles:
tgtcfilename = os.path.join(self.savedsourcepath, cfilename)
tgtifilename = os.path.join(self.savedsourcepath, ifilename)
Expand Down Expand Up @@ -367,37 +385,50 @@ def preprocess(
ecommand.append("-fno-asm")
self.set_platform(ecommand)

# issue modified command to produce i files
if self.verbose:
print("\nIssue command: " + str(ecommand) + "\n")
resultcode = subprocess.call(
ecommand,
cwd=ccommand["directory"],
stderr=subprocess.STDOUT
)
print("result: " + str(resultcode))
real_ifile = None
if self._preprocessed_path:
path = Path(self._preprocessed_path) / ifilename
path = path.resolve()
if path.is_file():
real_ifile = path

if real_ifile:
try:
shutil.copy(real_ifile, ifilename)
except shutil.SameFileError:
pass
else:
subprocess.call(
ecommand,
cwd=ccommand["directory"],
stdout=open(os.devnull, "w"),
stderr=subprocess.STDOUT,
)

# issue original command
if self.verbose:
print("\nIssue original command: " + str(command) + "\n")
resultcode = subprocess.call(
command, cwd=ccommand["directory"], stderr=subprocess.STDOUT
)
print("result: " + str(resultcode))
else:
subprocess.call(
command,
cwd=ccommand["directory"],
stdout=open(os.devnull, "w"),
stderr=subprocess.STDOUT,
)
# issue modified command to produce i files
if self.verbose:
print("\nIssue command: " + str(ecommand) + "\n")
resultcode = subprocess.call(
ecommand,
cwd=ccommand["directory"],
stderr=subprocess.STDOUT
)
print("result: " + str(resultcode))
else:
subprocess.call(
ecommand,
cwd=ccommand["directory"],
stdout=open(os.devnull, "w"),
stderr=subprocess.STDOUT,
)

# issue original command
if self.verbose:
print("\nIssue original command: " + str(command) + "\n")
resultcode = subprocess.call(
command, cwd=ccommand["directory"], stderr=subprocess.STDOUT
)
print("result: " + str(resultcode))
else:
subprocess.call(
command,
cwd=ccommand["directory"],
stdout=open(os.devnull, "w"),
stderr=subprocess.STDOUT,
)

if copyfiles:
tgtcfilename = os.path.join(
Expand Down
4 changes: 3 additions & 1 deletion chc/cmdline/c_file/cfileutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def cfile_parse_file(args: argparse.Namespace) -> NoReturn:
loglevel: str = args.loglevel
logfilename: Optional[str] = args.logfilename
logfilemode: str = args.logfilemode
preprocessed_path: str = args.preprocessed_path

try:
UF.check_parser()
Expand Down Expand Up @@ -159,7 +160,8 @@ def cfile_parse_file(args: argparse.Namespace) -> NoReturn:
chklogger.logger.info("Target path: %s", targetpath)

parsemanager = ParseManager(
projectpath, projectname, targetpath, keep_system_includes=keep_system_includes)
projectpath, projectname, targetpath, keep_system_includes=keep_system_includes,
preprocessed_path=preprocessed_path)
parsemanager.remove_semantics()
parsemanager.initialize_paths()

Expand Down
4 changes: 3 additions & 1 deletion chc/cmdline/c_project/cprojectutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def cproject_parse_project(args: argparse.Namespace) -> NoReturn:
loglevel: str = args.loglevel
logfilename: Optional[str] = args.logfilename
logfilemode: str = args.logfilemode
preprocessed_path: str = args.preprocessed_path

try:
UF.check_parser()
Expand Down Expand Up @@ -168,7 +169,8 @@ def cproject_parse_project(args: argparse.Namespace) -> NoReturn:
projectpath,
projectname,
targetpath,
keep_system_includes=keep_system_includes)
keep_system_includes=keep_system_includes,
preprocessed_path=preprocessed_path)
parsemanager.remove_semantics()
parsemanager.initialize_paths()
exitcode = parsemanager.parse_with_ccommands(compilecommands, copyfiles=True)
Expand Down
6 changes: 6 additions & 0 deletions chc/cmdline/chkc
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,9 @@ def parse() -> argparse.Namespace:
"--keep-system-includes",
action="store_true",
help="do not filter out functions from files with absolute file names")
cfileparse.add_argument(
"--preprocessed-path",
help="directory that contains preprocessed source files")
cfileparse.add_argument(
"--loglevel", "-log",
choices=UL.LogLevel.options(),
Expand Down Expand Up @@ -1491,6 +1494,9 @@ def parse() -> argparse.Namespace:
"--keep-system-includes",
action="store_true",
help="don't filter out functions from files with absolute filenames")
cprojectparse.add_argument(
"--preprocessed-path",
help="directory that contains preprocessed source files")
cprojectparse.add_argument(
"--loglevel", "-log",
choices=UL.LogLevel.options(),
Expand Down