Questions tagged [compilation]

Compilation is the transformation of source text into some other form or representation. The most common usage of this tag is for questions concerning transformation of a programming language into machine code. This tag is normally used with another tag indicating the type of the source text such as a programming language tag (C, C++, Go, etc.) and a tag indicating the tool or compiler being used for the transformation (gcc, Visual Studio, etc.).

Compilation is the transformation of source text into some other form or representation. The software tool used is called a compiler. Most compilers process the source text to generate some sort of machine code for a target hardware machine. Some compilers generate the "machine code" for a target virtual machine (e.g. bytecode for a Java Virtual Machine).

In all of these cases the compiler creates new files of the transformed source text and these new files are used in some other processing step up to and including executing directly on hardware or virtual hardware.

Interpretation is the processing of source text by a software tool called an interpreter. Interpreters immediately execute the sense of the source text without generating a new, externally visible form of the source text. Compilers generate a new, externally visible form of the source text which is then executed by some other device whether actual hardware or virtual machine.

The lines between interpreters and compilers have blurred somewhat with the introduction of languages whose tools generate an intermediate language which is then executed on an internal virtual machine. The traditional compiler generates machine code files which are then further processed into an application to execute. The traditional interpreter parses the source text line by line performing some action indicated by the line of source text at the time the line of source is read.

A C or C++ compiler generates object files containing binary code which are then processed by a linker into an application and executed. A Java compiler generates class files containing Java Virtual Machine byte code which are then combined into a Java application and executed.

Engines for scripting languages such as Php and JavaScript may use an internal compiler to generate an intermediate form of the source text which is then executed by an internal virtual machine. For some types of applications the intermediate form is temporarily stored or cached so that if the same script is being used by multiple threads or multiple repetions in a short time span, the overhead of rescaning the source text is reduced to improve efficiency. However these are not considered to be compilers.

Compilation usually involves the following steps:

  • Scanning - The scanner is responsible of tokenizing the source code into the smallest chunks of information (keywords, operators, brackets, variables, literals etc.).
  • Parsing - The parser is responsible with creating the Abstract Syntax Tree (AST) which is a tree representation of the code according to the source language definition.
  • Optimization - The AST representing the code is sent through various optimizers in order to optimize for speed or space (this part is optional).
  • Code generation - The code generator creates a linear translated document from the AST and the output language definition.

In many languages and compilers there are additional steps added to the process (like pre-processing), but these are language and compiler specific.

In most cases, where compilation is a part of the build/make/publish process, the output of the compiler will be sent to the linker which will produce the ready-to-use files.

Questions using this tag should be about the compilation process, not about how to write compilers for example (use the compiler tag for that).

17181 questions
35
votes
7 answers

Running :make from gVim in Background

I use gVim in windows to edit my code (mostly C++). I use :make in gVim to compile the project, but this is a blocking operation, that prevents me from using gVim until the compilation is complete. How can I do :make asynchronously and still get the…
Amjith
  • 22,626
  • 14
  • 43
  • 38
35
votes
10 answers

How to speed up Linux kernel compilation?

I have core i5 with 8gb RAM. I have VMware workstation 10.0.1 installed on my machine. I have fedora 20 Desktop Edition installed on VMware as guest OS. I am working on Linux kernel source code v 3.14.1. I am developing an I/O scheduler for Linux…
momersaleem
  • 451
  • 1
  • 4
  • 7
35
votes
2 answers

What are the benefits of a directive template function in Angularjs?

According to the documentation a template can be a function which takes two parameters, an element and attributes and returns a string value representing the template. It replaces the current element with the contents of the HTML. The replacement…
35
votes
5 answers

How to make Visual Studio use the native amd64 toolchain

How can I get Visual Studio 2012 to use the native amd64 toolchain, rather than the default x86_amd64 cross-compiler? I am building a large library that causes the linker to run out of memory when doing whole program optimization and link-time code…
Ky Waegel
  • 353
  • 1
  • 3
  • 8
35
votes
2 answers

Compile PyPy to Exe

I know how to compile CPython file to exe using cx_freeze but is it possible to compile a simple program using PyPy to Exe ?
Nuncjo
  • 1,290
  • 3
  • 15
  • 16
35
votes
2 answers

What does the g++ -D flag do?

I am looking at a CFLAGS of - CFLAGS=-g -w -D LINUX -O3 -fpermissive in a Makefile. What does the -D flag do? I see on the man page that -D name Predefine name as a macro, with definition 1. but I don't know how to interpret that. My…
Sterling
  • 3,835
  • 14
  • 48
  • 73
34
votes
3 answers

Is there a way to precompile a regex in Perl?

Is there a way to precompile a regex in Perl? I have one that I use many times in a program and it does not change between uses.
Sam Lee
  • 9,913
  • 15
  • 48
  • 56
34
votes
4 answers

Why does division by 3 require a rightshift (and other oddities) on x86?

I have the following C/C++ function: unsigned div3(unsigned x) { return x / 3; } When compiled using clang 10 at -O3, this results in: div3(unsigned int): mov ecx, edi # tmp = x mov eax, 2863311531 # result =…
Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
34
votes
5 answers

Can Elixir or Erlang programs be compiled to a standalone binary?

It says that Elixir has a tool called elixirc and Erlang has a tool called erlc to compile modules for use. It says immediately after this that you can then run code with the elixir command line tool. Is there a way to compile a binary executable…
Mike H-R
  • 7,726
  • 5
  • 43
  • 65
34
votes
4 answers

How does Eclipse compile classes with only a JRE?

I need to batch a compilation with a special JRE which has been "customized". Eclipse is able to compile the classes with this JRE, but I need to make a build script outside of Eclipse. What is the method used by Eclipse to generate the .class files…
glmxndr
  • 45,516
  • 29
  • 93
  • 118
34
votes
2 answers

Why am I getting "undefined reference to `dladdr'" even with -ldl for this simple program?

I'm working through an LLVM Tutorial, but I'm having trouble compiling. I've written a minimal example that reproduces the issue: #include "llvm/Module.h" #include "llvm/LLVMContext.h" int main(int argc, char **argv) { llvm::Module *module =…
Matthew
  • 28,056
  • 26
  • 104
  • 170
34
votes
2 answers

How to compile openmp using g++

I have a problem about the openmp compiling. Like the following code: #include #include #include #include #include using namespace std; sem_t empty,full; stack stk; void produce(int i) { …
Gang.Wang
  • 381
  • 1
  • 4
  • 6
33
votes
4 answers

cmake: compilation statistics per transation unit

I need to figure out which translation units need to be restructured to improve compile times, How do I get hold of the compilation time, using cmake, for my translation units ?
Hassan Syed
  • 20,075
  • 11
  • 87
  • 171
33
votes
8 answers

How to compile Ruby?

Is there a tool that can allow me to compile Ruby code so that it runs somewhat faster? For example, I have heard that there is a tool for Python called "pyc" that allows us to compile the code, so that it runs 10 times faster.
Flethuseo
  • 5,969
  • 11
  • 47
  • 71
33
votes
5 answers

Can I somehow "compile" a python script to work on PC without Python installed?

So I have a Python script: myscript.py I am executing it like this: python D:\myscript.py However, I must have Python installed and included in the PATH environment variable for that to work. Is it somehow possible to "bundle" Python executable…
Richard Knop
  • 81,041
  • 149
  • 392
  • 552