Add command-line parser and some debug options #318

Merged
sb10q merged 1 commits from cmdline-parser into master 2024-08-17 17:37:20 +08:00
Collaborator

Clap is used for the implementation of the parser. After the refactoring, the argument order of <FILE> <THREADS> is currently preserved, with additional configuration implemented as options.

New Options:

  • -O<n>: Sets the optimization level of LLVM IR; -O0 corresponds to OptimizationLevel::None, whereas -O2 corresponds to OptimizationLevel::Default (which has also been the default).
  • -emit-llvm: Outputs the LLVM IR of each module after compilation to stdout

Feedback is welcome on alternative behavior, as our current behavior does not match with Clang's behavior, which is:

  • -emit-llvm outputs a bitcode file
  • -S -emit-llvm outputs the human-readable IR into <filename>.ll.
    • -S refers to only running C preprocessor and compilation without assembling
[Clap](https://github.com/clap-rs/clap) is used for the implementation of the parser. After the refactoring, the argument order of `<FILE> <THREADS>` is currently preserved, with additional configuration implemented as options. New Options: - `-O<n>`: Sets the optimization level of LLVM IR; `-O0` corresponds to `OptimizationLevel::None`, whereas `-O2` corresponds to `OptimizationLevel::Default` (which has also been the default). - `-emit-llvm`: Outputs the LLVM IR of each module after compilation to stdout Feedback is welcome on alternative behavior, as our current behavior does not match with Clang's behavior, which is: - `-emit-llvm` outputs a bitcode file - `-S -emit-llvm` outputs the human-readable IR into `<filename>.ll`. - `-S` refers to only running C preprocessor and compilation without assembling
derppening requested review from sb10q 2023-09-06 21:27:03 +08:00
derppening force-pushed cmdline-parser from 1d0356e3c4 to 5668fd9254 2023-09-08 15:25:41 +08:00 Compare
Author
Collaborator

v2: Added CodeGenLLVMOptions struct, fixed missing changes to nac3artiq and test sources.

v2: Added `CodeGenLLVMOptions` struct, fixed missing changes to `nac3artiq` and test sources.
derppening force-pushed cmdline-parser from 5668fd9254 to a1a455d752 2023-09-08 18:00:11 +08:00 Compare
Author
Collaborator

v3: Replaced argument for one more level where OptimizationLevel is needed.

v3: Replaced argument for one more level where `OptimizationLevel` is needed.
derppening added 10 commits 2023-09-12 11:00:23 +08:00
e0de82993f core: Preserve value of variable shadowed by for loop
Previously, the final value of the target expression would be one after
the last element of the loop, which does not match Python's behavior.

This commit fixes this problem while also preserving the last assigned
value of the loop beyond the loop, matching Python's behavior.
b4983526bd core: Remove redundant for.cond BB for iterable loops
Simplifies logic for creating basic blocks.
4481d48709 core: Use C-style for loop logic for iterables
Index increment is now performed at the end of the loop body.
e4940247f3 standalone: Implement command-line parser using clap
In preparation for adding more command-line options.
39724de598 core: Add CodeGenLLVMOptions
For specifying LLVM options during code generation.
Author
Collaborator

v4: Rebased on master and refactored to pass CodeGenLLVMOptions via WorkerRegistry.

v4: Rebased on `master` and refactored to pass `CodeGenLLVMOptions` via `WorkerRegistry`.
derppening force-pushed cmdline-parser from 4613e9e54d to 3d7ccd0b69 2023-09-12 11:04:09 +08:00 Compare
derppening changed title from WIP: Add command-line parser and some debug options to Add command-line parser and some debug options 2023-09-12 11:04:19 +08:00
Author
Collaborator

This merge request should be ready for re-review.

This merge request should be ready for re-review.
sb10q reviewed 2023-09-12 12:31:10 +08:00
@ -16,4 +16,2 @@
rm -f *.o
$nac3standalone $1
rustc -o demo demo.rs -Crelocation-model=static -Clink-arg=./module.o
Owner

The script has set -e above. I suspect these || exit changes are not necessary?

The script has ``set -e`` above. I suspect these ``|| exit`` changes are not necessary?
Author
Collaborator

I didn't notice that it was there. Removed the || exit changes.

I didn't notice that it was there. Removed the `|| exit` changes.
sb10q reviewed 2023-09-12 16:13:43 +08:00
@ -159,1 +179,3 @@
let threads: u32 = env::args().nth(2).map(|s| str::parse(&s).unwrap()).unwrap_or(1);
let cli = CommandLineArgs::parse();
let CommandLineArgs { file_name, threads, opt_level, emit_llvm } = cli;
let opt_level: OptimizationLevel = unsafe { transmute(opt_level) };
Owner

Can we avoid unsafe and transmute here?

Can we avoid unsafe and transmute here?
Author
Collaborator

Changed to use match expression.

Changed to use `match` expression.
derppening marked this conversation as resolved
derppening added 2 commits 2023-09-12 16:20:57 +08:00
008d50995c meta: Update run_demo.sh
- Allow more than one argument to nac3standalone executable
sb10q merged commit 008d50995c into master 2023-09-12 16:22:38 +08:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#318
No description provided.