stupid-stats | Tutorial and demo of rust compiler replacement tooling | Compiler library
kandi X-RAY | stupid-stats Summary
kandi X-RAY | stupid-stats Summary
Compilation using rustc happens in several phases. We start with parsing, this includes lexing. The output of this phase is an AST (abstract syntax tree). There is a single AST for each crate (indeed, the entire compilation process operates over a single crate). Parsing abstracts away details about individual files which will all have been read in to the AST in this phase. At this stage the AST includes all macro uses, attributes will still be present, and nothing will have been eliminated due to cfgs. The next phase is configuration and macro expansion. This can be thought of as a function over the AST. The unexpanded AST goes in and an expanded AST comes out. Macros and syntax extensions are expanded, and cfg attributes will cause some code to disappear. The resulting AST won't have any macros or macro uses left in. The code for these first two phases is in libsyntax. After this phase, the compiler allocates ids to each node in the AST (technically not every node, but most of them). If we are writing out dependencies, that happens now. The next big phase is analysis. This is the most complex phase and uses the bulk of the code in rustc. This includes name resolution, type checking, borrow checking, type and lifetime inference, trait selection, method selection, linting, and so forth. Most error detection is done in this phase (although parse errors are found during parsing). The 'output' of this phase is a bunch of side tables containing semantic information about the source program. The analysis code is in librustc and a bunch of other crates with the 'librustc_' prefix. Next is translation, this translates the AST (and all those side tables) into LLVM IR (intermediate representation). We do this by calling into the LLVM libraries, rather than actually writing IR directly to a file. The code for this is in librustc_trans. The next phase is running the LLVM backend. This runs LLVM's optimisation passes on the generated IR and then generates machine code. The result is object files. This phase is all done by LLVM, it is not really part of the rust compiler. The interface between LLVM and rustc is in librustc_llvm. Finally, we link the object files into an executable. Again we outsource this to other programs and it's not really part of the rust compiler. The interface is in librustc_back (which also contains some things used primarily during translation). All these phases are coordinated by the driver. To see the exact sequence, look at the compile_input function in librustc_driver/driver.rs. The driver (which is found in librust_driver) handles all the highest level coordination of compilation - handling command line arguments, maintaining compilation state (primarily in the Session), and calling the appropriate code to run each phase of compilation. It also handles high level coordination of pretty printing and testing. To create a drop-in compiler replacement or a compiler replacement, we leave most of compilation alone and customise the driver using its APIs.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of stupid-stats
stupid-stats Key Features
stupid-stats Examples and Code Snippets
Community Discussions
Trending Discussions on stupid-stats
QUESTION
I am trying to make a drop-in compiler replacement. Here's my source code.
...ANSWER
Answered 2018-May-22 at 07:09Just a guess here, but I think your tool1
is not installed in the same folder as rustc
. Note that you may have an executable called rustc
in your cargo bin folder alongside your tool1
, but this rustc
is probably a rustup
wrapper that redirects to the real compiler somewhere in your toolchain folder (probably $HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc
).
You will need to either install your tool1
inside the toolchain folder or call it with a -L
argument pointing to the toolchain libraries (probably $HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib
).
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install stupid-stats
Rust is installed and managed by the rustup tool. Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time. Please refer rust-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page