Skip to content

Commit

Permalink
fixed cpp version issues and got cli library working
Browse files Browse the repository at this point in the history
  • Loading branch information
OjasTalgaonkar committed Jul 5, 2024
1 parent 4f6256a commit de5dc20
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .clangd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CompileFlags:
CompileCommandsDir: .
Add:
- "-std=c++2b"
- "-std=c++23"
144 changes: 143 additions & 1 deletion source/cli/include/cli.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,148 @@
/**
* @author Ojas Talgaonkar
* @copyright Copyright (c) 2024 (CC BY 4.0)
*
* @note This code is part of the Helix Language Project and is licensed under the Attribution 4.0
* International license (CC BY 4.0). You are allowed to use, modify, redistribute, and create
* derivative works, even for commercial purposes, provided that you give appropriate credit,
* provide a link to the license, and indicate if changes were made. For more information, please
* visit: https://creativecommons.org/licenses/by/4.0/ SPDX-License-Identifier: CC-BY-4.0
*
* @note This code is provided by the creators of Helix. Visit our website at:
* https://helix-lang.com/ for more information.
*/
#include <array>
#include <cstddef>
#include <iostream>
#include <optional>
#include <string>

#include "cli/include/args.hh"
#include "cli/include/args.hh"
#include "core/types/hx_ints"

/*
Helios - package manager / build system
Usage:
helios create <project> Create a new Helix project.
helios build Build the current project.
helios run [-r] -- <args> Run the current project with optional arguments.
helios test Run tests for the current project.
helios clean Clean build artifacts.
helios install <package> Install a package.
helios uninstall <package> Uninstall a package.
helios update Update all installed packages.
helios search <package> Search for a package.
helios list List all installed packages.
helios info <package> Show information about a specific package.
helios help Show help information.
helios version Show the version of Helios.
helios license Show the license of Helios.
helios doc-gen Generate documentation.
*/

/*
helix - command line interface
Usage:
helix [options] <file> [options-2]
helix (-h | --help)
helix --version
helix --license
options:
-O1 --optimize1 Optimization level 1.
-O2 --optimize2 Optimization level 2.
-O3 --optimize3 Optimization level 3.
-O4 --optimize4 Optimization level 4.
-O5 --optimize5 Optimization level 5.
-h --help Show this screen.
-v --version Show version.
-l --license Show license information.
--verbose Show verbose output.
--quiet Show no output.
--emit-tokens Show tokens.
--emit-llvm Show LLVM IR.
--emit-asm Show assembly.
--emit-ast Show AST in json format
--emit-ir Show intermediate representation. (C++)
--emit-doc Only extract doc-comments along with signatures in json format.
--toolchain <options-3> Set the toolchain to use
--config <file> Specify configuration file.
-r --release Build in release mode.
-d --debug Build in debug mode with symbols.
options-2:
--lib [abi-options] Compile as library.
-o <file> Output file.
-I <dir> Include directory.
-L <dir> Library directory.
-l <lib> Link library.
-m <mod> Helix Modules directory.
options-3:
--target <triple> Target triple.
--arch <arch> Target architecture.
--os <os> Target operating system.
--sdk <sdk-path> Optional Path to a sdk.
abi-options:
-py --python Python stub files gen and pylib compile
-rs --rust Rust source files gen and a rust compiler lib
-cxx --cxx C++ header files gen and linkable object file
-hlx --helix Helix ABI compatable libary
*/

namespace command_line {
class CLIArgs {
public:
enum class OPTIMIZATION : u8 { O1 = 1, O2 = 2, O3 = 3, O4 = 4, O5 = 5 };
enum class MODE : char { RELEASE = 'r', DEBUG_= 'd' };
enum class ABI : char { PYTHON = 'p', RUST = 'r', CXX = 'c', HELIX = 'h' };

std::string file;
std::optional<std::string> output_file;

// Options
OPTIMIZATION optimize;

bool help = false;

bool verbose = false;
bool quiet = false;

bool emit_tokens = false;
bool emit_llvm = false;
bool emit_asm = false;
bool emit_ast = false;
bool emit_ir = false;
bool emit_doc = false;

struct tool_chain {
std::string target;
std::string arch;
std::string os;
std::string sdk;
};

tool_chain toolchain;

std::string config_file;

MODE build_mode;

ABI build_lib; // if --lib is passed without [-py, -rs, -cx, -hlx] then asumme -hlx

std::vector<std::string> include_dirs;
std::vector<std::string> library_dirs;
std::vector<std::string> link_libraries;
std::vector<std::string> module_dirs;

explicit CLIArgs(int argc, char **argv);
};
} // end namespace command_line
122 changes: 37 additions & 85 deletions source/cli/source/cli.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/**
* @author Ojas Talgaonkar
* @copyright Copyright (c) 2024 (CC BY 4.0)
*
* @note This code is part of the Helix Language Project and is licensed under the Attribution 4.0
* International license (CC BY 4.0). You are allowed to use, modify, redistribute, and create
* derivative works, even for commercial purposes, provided that you give appropriate credit,
* provide a link to the license, and indicate if changes were made. For more information, please
* visit: https://creativecommons.org/licenses/by/4.0/ SPDX-License-Identifier: CC-BY-4.0
*
* @note This code is provided by the creators of Helix. Visit our website at:
* https://helix-lang.com/ for more information.
*/
/*
Helios - package manager / build system
Expand Down Expand Up @@ -61,12 +74,13 @@ options-2:
-I <dir> Include directory.
-L <dir> Library directory.
-l <lib> Link library.
-m <mod> Helix Modules directory.
options-3:
--target <triple> Target triple.
--arch <arch> Target architecture.
--os <os> Target operating system.
--sdk <sdk-path> Optional Path to a sdk.
abi-options:
-py --python Python stub files gen and pylib compile
Expand All @@ -75,98 +89,36 @@ abi-options:
-hlx --helix Helix ABI compatable libary
*/

#include "cli/include/cli.hh"

#include <array>
#include <cstddef>
#include <iostream>
#include <optional>
#include <string>

#include "cli/include/args.hh"
#include "core/types/hx_ints"

namespace command_line {
class CLIArgs {
template <size_t arr_size>
explicit CLIArgs(int argc, char **argv) {
args::ArgumentParser parser(
"This is a test program with a really long description that is probably going to have "
"to be wrapped across multiple different lines. This is a test to see how the line "
"wrapping works",
"This goes after the options. This epilog is also long enough that it will have to be "
"properly wrapped to display correctly on the screen");

args::HelpFlag help(parser, "HELP", "Show this help menu.", {'h', "help"});

args::ValueFlag<std::string> foo(parser, "FOO", "The foo flag.",
{'a', 'b', 'c', "a", "b", "c", "the-foo-flag"});

args::ValueFlag<std::string> bar(
parser, "BAR",
"The bar flag. This one has a lot of options, and will need wrapping in the "
"description, along with its long flag list.",
{'d', 'e', 'f', "d", "e", "f"});

args::ValueFlag<std::string> baz(
parser, "FOO",
"The baz flag. This one has a lot of options, and will need wrapping in the "
"description, even with its short flag list.",
{"baz"});

args::Positional<std::string> pos1(parser, "POS1", "The pos1 argument.");
args::PositionalList<std::string> poslist1(parser, "POSLIST1", "The poslist1 argument.");

try {
parser.ParseCLI(argc, argv);
} catch (args::Help) {
std::cout << parser;
return;
} catch (args::ParseError e) {
std::cerr << e.what() << std::endl;
std::cerr << parser;
return;
} catch (args::ValidationError e) {
std::cerr << e.what() << std::endl;
std::cerr << parser;
return;
CLIArgs::CLIArgs(int argc, char **argv) {
// Parse command line arguments
args::ArgumentParser parser("helix parser");
args::Group commands(parser, "commands");
args::Command version(commands, {"-v", "--version"}, "displays version");
args::Command lisence(commands, "--lisence", "displays lisence");

try {
parser.ParseCLI(argc, argv);
if (version) {
std::cout << "current_version";
} else if (lisence) {
std::cout << "lisence";
}

} catch (args::Help) { std::cout << parser; } catch (args::Error &e) {
std::cerr << e.what() << std::endl << parser;
return;
}
};

struct HelixArguments {
// File and optional output file
std::string file;
std::optional<std::string> output_file;

// Options
bool optimize1 = false;
bool optimize2 = false;
bool optimize3 = false;
bool optimize4 = false;

bool help = false;
bool version = false;
bool license = false;

bool verbose = false;
bool quiet = false;

bool show_ast = false;
bool show_tokens = false;
bool emit_llvm = false;
bool emit_asm = false;
bool emit_ir = false;
bool emit_doc = false;

std::optional<std::string> target_triple;
std::optional<std::string> target_arch;
std::optional<std::string> target_os;

std::optional<std::string> config_file;
bool release = false;
bool debug = false;

// Options-2
bool compile_as_library = false;
std::vector<std::string> include_dirs;
std::vector<std::string> library_dirs;
std::vector<std::string> link_libraries;
};
}
} // end namespace command_line
4 changes: 3 additions & 1 deletion source/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
#include "cli/include/cli.hh"
#include "controllers/include/file_system.hh"
#include "core/utils/hx_print"
#include "lexer/include/lexer.hh"
#include "parser/cst/include/cst.hh"
#include "parser/cst/include/nodes.hh"
#include "parser/preprocessor/include/preprocessor.hh"
#include "lexer/include/lexer.hh"

int main(int argc, char **argv) {
using namespace token;
Expand All @@ -34,6 +34,8 @@ int main(int argc, char **argv) {
// "D:\projects\helix-lang\tests\main.hlx"
// std::string file_name = "/Volumes/Container/Projects/Helix/helix-lang/tests/main.hlx"; //
// relative to current working dir in POSIX shell (cmd/bash)
command_line::CLIArgs(argc, argv);

std::string file_name =
"tests/main.hlx"; // relative to current working dir in Windows shell (cmd/powershell)
// read the file and tokenize its contents : stage 0
Expand Down
4 changes: 2 additions & 2 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ target("helix")

add_headerfiles("source/**.hh") -- add all headers in the source directory
add_includedirs("source")
set_languages("c++2b") -- set the standard C++ version to C++23
set_languages("c++23") -- set the standard C++ version to C++23

if is_mode("debug") then
set_symbols("debug") -- Generate debug symbols
Expand All @@ -36,7 +36,7 @@ target("tests")

add_includedirs("source")
add_includedirs("tests/lib")
set_languages("c++latest") -- set the standard C++ version to C++23
set_languages("c++23") -- set the standard C++ version to C++23

set_symbols("debug") -- Generate debug symbols
set_optimize("none") -- Disable optimization
Expand Down

0 comments on commit de5dc20

Please sign in to comment.