Skip to content

Commit

Permalink
Cleanup CliInterface (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcauberer authored Sep 17, 2023
1 parent 27bf776 commit fecd345
Show file tree
Hide file tree
Showing 28 changed files with 266 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .run/spice.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="spice" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="run -d -O0 -ir ../../media/test-project/test.spice" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Spice" TARGET_NAME="spice" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Spice" RUN_TARGET_NAME="spice">
<configuration default="false" name="spice" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="run -d -O0 ../../media/test-project/test.spice" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Spice" TARGET_NAME="spice" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Spice" RUN_TARGET_NAME="spice">
<envs>
<env name="SPICE_STD_DIR" value="$PROJECT_DIR$/std" />
</envs>
Expand Down
3 changes: 3 additions & 0 deletions docs/docs/cli/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ You can apply following options to the `build` command:
| `-symtab` | `--dump-symtab` | Dump serialized symbol tables |
| `-ir` | `--dump-ir` | Dump LLVM-IR |
| `-s`, `-asm` | `--dump-assembly` | Dump Assembly code |
| `-b`, `-obj` | `--dump-object-file` | Dump object files |
| - | `--dump-to-files` | Redirect all dumps to files instead of printing them to the screen |
| `-j <n>` | `--jobs <n>` | Set number of jobs to parallelize compilation (default is auto) |
| `-t` | `--target` | Target triple for the emitted executable (for cross-compiling). <br> Format: `<arch><sub>-<vendor>-<sys>-<abi>` |
| `-o` | `--output` | Set path for executable output. |
| `-O<n>` | - | Set optimization level. <br> Valid options: `-O0`, `-O1`, `-O2`, `-O3`, `-Os`, `-Oz` |
| `-m` | `--build-mode` | Controls the build mode. Valid values are `debug` and `release` |
| `-lto` | - | Enable link-time-optimization |
| `-g` | `--debug-info` | Generate debug info to debug the executable in GDB, etc. |
| - | `--static` | Produce stand-alone executable by linking statically |
Expand Down
31 changes: 17 additions & 14 deletions docs/docs/cli/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ The `install` command can be used to compile your Spice project to an executable
## Options
You can apply following options to the `install` command:

| Option | Long | Description |
|--------------|---------------------|--------------------------------------------------------------------------------------|
| `-d` | `--debug-output` | Print compiler output for debugging. |
| `-cst` | `--dump-cst` | Dump CST as serialized string and SVG image |
| `-ast` | `--dump-ast` | Dump AST as serialized string and SVG image |
| `-symtab` | `--dump-symtab` | Dump serialized symbol tables |
| `-ir` | `--dump-ir` | Dump LLVM-IR |
| `-s`, `-asm` | `--dump-assembly` | Dump Assembly code |
| `-d` | `--debug-output` | Print compiler output for debugging. |
| `-j <n>` | `--jobs <n>` | Set number of jobs to parallelize compilation (Default is auto) |
| `-o` | `--output` | Set path for executable output. |
| `-O<n>` | - | Set optimization level. <br> Valid options: `-O0`, `-O1`, `-O2`, `-O3`, `-Os`, `-Oz` |
| - | `--ignore-cache` | Compile always and ignore the compile cache |
| - | `--disable-ast-opt` | Disable AST optimization (recommended for debugging the compiler) |
| Option | Long | Description |
|--------------|-----------------------|--------------------------------------------------------------------------------------|
| `-d` | `--debug-output` | Print compiler output for debugging. |
| `-cst` | `--dump-cst` | Dump CST as serialized string and SVG image |
| `-ast` | `--dump-ast` | Dump AST as serialized string and SVG image |
| `-symtab` | `--dump-symtab` | Dump serialized symbol tables |
| `-ir` | `--dump-ir` | Dump LLVM-IR |
| `-s`, `-asm` | `--dump-assembly` | Dump Assembly code |
| `-b`, `-obj` | `--dump-object-file` | Dump object files |
| - | `--dump-to-files` | Redirect all dumps to files instead of printing them to the screen |
| `-d` | `--debug-output` | Print compiler output for debugging. |
| `-j <n>` | `--jobs <n>` | Set number of jobs to parallelize compilation (Default is auto) |
| `-o` | `--output` | Set path for executable output. |
| `-O<n>` | - | Set optimization level. <br> Valid options: `-O0`, `-O1`, `-O2`, `-O3`, `-Os`, `-Oz` |
| `-m` | `--build-mode` | Controls the build mode. Valid values are `debug` and `release` |
| - | `--ignore-cache` | Compile always and ignore the compile cache |
| - | `--disable-ast-opt` | Disable AST optimization (recommended for debugging the compiler) |
3 changes: 3 additions & 0 deletions docs/docs/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ You can apply following options to the `run` command:
| `-symtab` | `--dump-symtab` | Dump serialized symbol tables |
| `-ir` | `--dump-ir` | Dump LLVM-IR |
| `-s`, `-asm` | `--dump-assembly` | Dump Assembly code |
| `-b`, `-obj` | `--dump-object-file` | Dump object files |
| - | `--dump-to-files` | Redirect all dumps to files instead of printing them to the screen |
| `-j <n>` | `--jobs <n>` | Set number of jobs to parallelize compilation (default is auto) |
| `-o` | `--output` | Set path for executable output. |
| `-O<x>` | - | Set optimization level. <br> Valid options: `-O0`, `-O1`, `-O2`, `-O3`, `-Os`, `-Oz` |
| `-m` | `--build-mode` | Controls the build mode. Valid values are `debug` and `release` |
| `-g` | `--debug-info` | Generate debug info to debug the executable in GDB, etc. |
| - | `--disable-verifier` | Disable LLVM module and function verification (only recommended for debugging the compiler) |
| - | `--ignore-cache` | Compile always and ignore the compile cache |
Expand Down
Binary file modified docs/docs/static/card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/logo-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed media/logo-large.xcf
Binary file not shown.
Binary file added media/logo-small-500x500.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/logo-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed media/logo-small.xcf
Binary file not shown.
Binary file removed media/logo.png
Binary file not shown.
Binary file removed media/logo.xcf
Binary file not shown.
30 changes: 24 additions & 6 deletions media/test-project/test.spice
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
type TestStruct struct {
long f1
int f2
TestStruct* f3
import "std/io/cli-parser";
import "std/io/cli-subcommand";

type CliOptions struct {
string greetName = ""
}

f<int> main() {
TestStruct ts;
p callback(bool& value) {
printf("Callback called with value %d\n", value);
}

f<int> main(int argc, string[] argv) {
CliParser parser = CliParser("Test Program", "This is a simple test program");
parser.setVersion("v0.1.0");
parser.setFooter("Copyright (c) Marc Auberer 2021-2023");

CliOptions options;
CliSubcommand& greet = parser.addSubcommand("greet", "Greet someone");
greet.addOption("--name", options.greetName, "Name of the person to greet");

parser.parse(argc, argv);

// Greet persion if requested
if options.greetName != "" {
printf("Hello %s!\n", options.greetName);
}
}

/*type TestStruct struct {
Expand Down
6 changes: 3 additions & 3 deletions src-bootstrap/CliInterface.spice
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public type CliOptions struct {
public bool dumpAST = false
public bool dumpIR = false
public bool dumpAssembly = false
public bool dumpSymbolTables = false
public bool dumpSymbolTable = false
public bool disableAstOpt = false
public short optLevel = 2s // -O0 = 0, -O1 = 1, -O2 = 2, -O3 = 3, -Os = 4, -Oz = 5
public bool generateDebugInfo = false
Expand Down Expand Up @@ -74,7 +74,7 @@ public p CliInterface.enrich() {
if this.cliOptions.printDebugOutput {
this.cliOptions.dumpAST = true;
this.cliOptions.dumpIR = true;
this.cliOptions.dumpSymbolTables = true;
this.cliOptions.dumpSymbolTable = true;
}
}

Expand Down Expand Up @@ -162,7 +162,7 @@ p CliInterface.addCompileSubcommandOptions(CliSubcommand& subCmd) {
CliOption<bool>& dumpAstFlag = subCmd.addFlag("--dump-ast", this.cliOptions.dumpAST, "Dump ASTs as serialized string and SVG image");
dumpAstFlag.addAlias("-ast");
// --dump-symtab
CliOption<bool>& dumpSymtabFlag = subCmd.addFlag("--dump-symtab", this.cliOptions.dumpSymbolTables, "Dump serialized symbol tables");
CliOption<bool>& dumpSymtabFlag = subCmd.addFlag("--dump-symtab", this.cliOptions.dumpSymbolTable, "Dump serialized symbol tables");
dumpSymtabFlag.addAlias("-symtab");
// --dump-ir
CliOption<bool>& dumpIrFlag = subCmd.addFlag("--dump-ir", this.cliOptions.dumpIR, "Dump LLVM-IR");
Expand Down
Loading

0 comments on commit fecd345

Please sign in to comment.