Line data Source code
1 : #ifndef OPTIONS_H
2 : #define OPTIONS_H
3 :
4 : #include <filesystem>
5 : #include <iostream>
6 :
7 : namespace nicole {
8 :
9 : class Options final {
10 : private:
11 : bool help_;
12 : bool optimize_;
13 : bool printTree_;
14 : bool printIR_;
15 : bool validateTree_;
16 : std::string binaryName_;
17 : std::filesystem::path entryFilePath_;
18 :
19 : public:
20 : explicit Options(const bool help, const bool optimize, const bool printTree,
21 : const bool printIR, const bool validateTree,
22 : const std::string &binaryName,
23 : const std::filesystem::path &entryFilePath) noexcept
24 243 : : help_{help}, optimize_{optimize}, printTree_{printTree},
25 243 : printIR_{printIR}, validateTree_{validateTree}, binaryName_{binaryName},
26 243 : entryFilePath_{entryFilePath} {}
27 :
28 243 : [[nodiscard]] bool help() const noexcept { return help_; }
29 :
30 243 : [[nodiscard]] bool optimize() const noexcept { return optimize_; }
31 :
32 45 : [[nodiscard]] bool printTree() const noexcept { return printTree_; }
33 :
34 45 : [[nodiscard]] bool printIR() const noexcept { return printIR_; }
35 :
36 9 : [[nodiscard]] bool validateTree() const noexcept { return validateTree_; }
37 :
38 243 : [[nodiscard]] const std::string &binaryName() const noexcept {
39 243 : return binaryName_;
40 243 : }
41 :
42 243 : [[nodiscard]] const std::filesystem::path &entryFilePath() const noexcept {
43 243 : return entryFilePath_;
44 243 : }
45 :
46 0 : void helper() noexcept {
47 0 : std::cout
48 0 : << "Usage \n"
49 0 : "From the parent directory, run:\n"
50 0 : "\t./nicole.sh [[options] input_file] | "
51 0 : "-t Where input_file is the main program file with the "
52 0 : ".nc extension(e.g., helloWorld.nc).\n\n"
53 0 : "Options can appear in any position except -n, "
54 0 : "which must be followed by the output file name.\n\n"
55 0 : "\t-h | --help --> Displays a brief description of how to use the "
56 0 : "compiler.\n\n"
57 0 : "\t-v | --validate --> Forces the program to follow certain "
58 0 : "validation "
59 0 : "rules (recommended).\n\n"
60 0 : "\t-o | --optimize --> Performs optimizations on the generated "
61 0 : "code.\n\n"
62 0 : "\t-n | --name output_file --> Allows specifying the name of the "
63 0 : "output "
64 0 : "file (default is a.out).\n\n"
65 0 : "\t-p | --printTree --> Prints the Abstract Syntax Tree (AST) in a "
66 0 : "directory-like structure.\n\n"
67 0 : "\t-i | --printIR --> Prints the generated Intermediate "
68 0 : "Representation "
69 0 : "(IR) code.\n\n"
70 0 : "\t-t --> Executes the tests of the compiler, also to run the tests "
71 0 : "no "
72 0 : "other argument but -t can be passed to the script.\n\n"
73 0 : "Usage Examples:\n"
74 0 : "\t- Compile a file with optimization and validation, specifying "
75 0 : "the "
76 0 : "output executable name:\n"
77 0 : " ./nicole.sh -v -o -n program_out helloWorld.nc\n\n"
78 0 : "\t- Generate the AST and intermediate code without optimization :\n"
79 0 : " ./nicole.sh -p -i helloWorld.nc\n";
80 0 : }
81 : };
82 :
83 : } // namespace nicole
84 :
85 : #endif
|