I followed the docs and compiled with nim compileToC helloworld.nim
but it just spit out an executable. How can I see the intermediate C representation?
The Nim compiler supports mainly two backend families: the C, C++ and Objective-C targets and the JavaScript target. The C like targets creates source files that can be compiled into a library or a final executable.
To see all compiler options, type nim --help in your terminal. If you're using VSCode with the Code Runner extension mentioned before, you'll just have to press Ctrl+Alt+N and your file will be compiled and run.
Nim uses the classic compiler architecture: A lexer/scanner feeds tokens to a parser. The parser builds a syntax tree that is used by the code generators. This syntax tree is the interface between the parser and the code generator. It is essential to understand most of the compiler's code.
On the command line, nlvm is mostly compatible with nim .
nim -c -d:release c helloworld.nim
just creates the C files in nimcache
, without compiling and linking them. -d:release
makes the code easier to read.
The default nimcache directory has changed from the current working directory to:
$HOME/.cache/nim/<project_name>
for Linux and MacOS$HOME/nimcache/<project_name>
for WindowsSee the relevant nim compiler documentation article for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With