aboutsummaryrefslogtreecommitdiff
path: root/tools/driver
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-22 03:22:32 +0000
committer_ov4 <ov4@ov4.org>2026-10-22 03:58:36 +0000
commit9f5e00104dfdd59a9ff8727dc7ee03f7f0db49ef (patch)
treeebe38d47a972e641f7aa7a4b924bd1a839d98730 /tools/driver
parent66e3faae23e6458d0bb59af7eb0fe60d5ee107ed (diff)
refactor(driver): share INCLUDE and INCLUDE_OBJ path resolution
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/driver')
-rw-r--r--tools/driver/main.cc23
1 files changed, 13 insertions, 10 deletions
diff --git a/tools/driver/main.cc b/tools/driver/main.cc
index df551a2..681bf1c 100644
--- a/tools/driver/main.cc
+++ b/tools/driver/main.cc
@@ -63,6 +63,17 @@ bool colorTerminal() {
#endif
}
+// INCLUDE and INCLUDE_OBJ paths are absolute or relative to the including
+// unit's directory.
+llvm::SmallString<256> relativeToUnit(llvm::StringRef UnitPath, llvm::StringRef Path) {
+ llvm::SmallString<256> Result(Path);
+ if (!llvm::sys::path::is_absolute(Result)) {
+ Result = llvm::sys::path::parent_path(UnitPath);
+ llvm::sys::path::append(Result, Path);
+ }
+ return Result;
+}
+
#ifdef CPSC_RUN_PATH
bool checkLliVersion(llvm::StringRef LliPath) {
llvm::SmallString<256> VersionPath;
@@ -243,11 +254,7 @@ int main(int argc, char **argv) {
for (const auto &Stmt : Units[I].Statements) {
auto *Include = dynamic_cast<cps::IncludeStmtAST*>(Stmt.get());
if (!Include) continue;
- llvm::SmallString<256> Path(Include->getPath());
- if (!llvm::sys::path::is_absolute(Path)) {
- Path = llvm::sys::path::parent_path(Units[I].Path);
- llvm::sys::path::append(Path, Include->getPath());
- }
+ llvm::SmallString<256> Path = relativeToUnit(Units[I].Path, Include->getPath());
bool Found = false;
for (size_t J = 0; J < Units.size(); ++J) {
if (llvm::sys::fs::equivalent(Path, Units[J].Path)) {
@@ -284,11 +291,7 @@ int main(int argc, char **argv) {
LibcLoaded = true;
continue;
}
- llvm::SmallString<256> Path(Object->getPath());
- if (!llvm::sys::path::is_absolute(Path)) {
- Path = llvm::sys::path::parent_path(Units[I].Path);
- llvm::sys::path::append(Path, Object->getPath());
- }
+ llvm::SmallString<256> Path = relativeToUnit(Units[I].Path, Object->getPath());
if (llvm::sys::path::extension(Path) != ".o") {
cps::sourceError(Stmt->getLine(),
"INCLUDE_OBJ '%s' must name a .o object file or \"__libc\"",