Project stage 1 navigate GCC codebase

Continues from the previous build GCC, this involves navigating the GCC codebase to understand and modify specific components such as compilation passes, argument parsing, and producing dumps during compilation passes.

1. Compilation passes:
The code for compilation passes is in the gcc/passes.c file. Compilation passes are managed using the pass_data structure.

To add a new pass, we will create a new file gcc/my_pass.c:
#include "gcc-plugin.h"
#include "tree-pass.h"

static unsigned int my_pass_execute(void) {
    return 0;
}

struct opt_pass my_pass = {
    .type = GIMPLE_PASS,
    .name = "my_pass",
    .gate = NULL,
    .execute = my_pass_execute,
};

int plugin_init(struct plugin_name_args *plugin_info,
                struct plugin_gcc_version *version) {
    return 0;
}

To test the new pass we will add the pass to the pass manager in gcc/passes.c and recompile GCC.


2. Argument Parsing
Argument parsing is managed in the gcc/opts.c file. Arguments are defined in gcc/common.opt

Adding a dummy argument to gcc/common.opt:
dummy-arg
Common Report Var(flag_dummy_arg) Init(0)

Handling the arugment in code:
if (flag_dummy_arg) {
    printf("Dummy argument is set\n");
}

3. Producing dumps during compilation passes
dumps are produced using the dump_* functions in gcc/tree-dump.c

Pass to produce a dump:
static unsigned int my_pass_execute(void) {
    dump_printf_loc(dump_file, "My pass is running\n");
    return 0;
}
Then recompile GCC and run it with the -fdump-tree-all option to produce dumps.

While working on this project, I have learned the GCC build process and the structure of its codebase, how GCC manages compilation passes, arugument parsing, and dump production. 
The most interesting part was understanding how different components of the compiler interact and how changes in one part can affect the overall compilation process. 
The most challenging part was navigating the complex codebase, it required a deep dive into the documentation and experimenting with different approaches to achieve the desired outcomes. 
I identified my gaps in my knowledge are cross compilation and optimizing build times, I plan to adress through further study and more practice. 
I found myself most attracted to tasks involving writing and debugging code. 

Comments

Popular posts from this blog

Project stage 3 Integrate, Tidy, & Wrap

Project stage 1 GCC build

lab 1 mob programming