Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the c code of a nim program?

Tags:

gcc

nim-lang

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?

like image 558
Elliot Gorokhovsky Avatar asked Apr 30 '15 00:04

Elliot Gorokhovsky


People also ask

Does Nim compile to C?

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.

How do I run a NIM code?

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.

How does Nim compiler work?

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.

Does Nim use LLVM?

On the command line, nlvm is mostly compatible with nim .


2 Answers

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.

like image 51
def- Avatar answered Sep 25 '22 21:09

def-


2019 Update (Nim 0.19.2)

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 Windows

See the relevant nim compiler documentation article for details.

like image 25
jkwill87 Avatar answered Sep 22 '22 21:09

jkwill87