GCC driver separates `find_a_program` from `find_a_file`
GCC refactors its driver by creating separate functions for locating programs and files, improving code organization.
This commit refactors the GCC driver by separating the find_a_program functionality from find_a_file. Previously, find_a_program was an overloaded version of find_a_file, leading to intertwined logic for finding executables versus general files. This change inlines a copy of find_a_file into find_a_program, creating two distinct functions. This improves the clarity and maintainability of the driver’s code by providing a cleaner separation of concerns.
In Details
The GCC driver, implemented primarily in gcc.cc, is responsible for orchestrating the various compilation stages, including locating external tools and input files. Historically, the find_a_program and find_a_file functionalities were tightly coupled, with find_a_program acting as a specialized caller of find_a_file. This commit establishes a clearer separation by inlining the relevant logic of find_a_file directly into find_a_program. This disentangles the complexities of path searching for executables (e.g., specific executable suffixes, PATH environment variable consideration…
For Context
When you compile a program using GCC, the 'driver' component is like the control center. It needs to find various things: the actual compiler, the assembler, the linker (these are 'programs'), and also input files like header files or source code (these are 'files'). Before this change, the driver used a single, somewhat complex function to find both programs and files, which made the code harder to understand because it had to handle all the different rules for both. This update separates that complex function into two simpler, dedicated functions: one specifically for finding programs and another for finding files. This makes the driver's code much cleaner and easier to maintain, as each function now focuses on a single, clear task.