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
6
votes
1 answer

Compile DLL from python code

Hi does anyone know if you can compile Python code into a Windows DLL file? How would you go about doing this?
Martin
  • 10,294
  • 11
  • 63
  • 83
6
votes
2 answers

java IntStream cannot use collect(Collectors.toList()), compilation error, why?

As below: IntStream iStream = IntStream.range(1,4); iStream.forEach(System.out::print); List list1 = iStream.collect(Collectors.toList());//error! Java 1.8 compiler gives type deduction error. Similar code could work for String type: …
Hind Forsum
  • 9,717
  • 13
  • 63
  • 119
6
votes
0 answers

Nmake can't locate files within a docker mount

I have a docker container I use to compile a project, build a setup and export it out of the container. For this I mount the checked out sources (using $(Build.SourcesDirectory):C:/git/ in the volumes section of the TFS docker run task) and an…
jaaq
  • 1,188
  • 11
  • 29
6
votes
3 answers

How do I compile Forth code for the J1 CPU?

I am interested in using the J1 CPU in an FPGA project. I understand that to use the J1 CPU itself, I need to synthesise (etc.) the Verilog code, and load the bitstream into my FPGA. I can do this using IceStorm, or the FPGA vendor's own tools. No…
Rocketmagnet
  • 5,656
  • 8
  • 36
  • 47
6
votes
2 answers

Adding global compile flags in CMake

I am editing a CMakeLists.txt file made by someone else. I'm trying to get rid of some of the warnings generated when compiling the project. Normally I just add set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MY_FLAGS}") with whatever flags I need to…
Sean Bone
  • 3,368
  • 7
  • 31
  • 47
6
votes
1 answer

How to modify the .te file generated by audit2allow and recompile it into .pp file

I used below command to generate a policy file: ausearch -ts today |audit2allow -M sample it will generate two files: sample.te and sample.pp the sampel.te contains lines such as: allow container_t unlabeled_t:dir { add_name create remove_name…
Michael.Sun
  • 387
  • 5
  • 13
6
votes
1 answer

Dynamic Code Compilation in .Net Core 2.1

Has anyone managed to find a workaround/way to dynamically compile a file, or files, or text, into a .dll in .Net Core (2.1)? var csProvider = CodeDomProvider.CreateProvider("CSharp"); CompilerResults compilerResults =…
monty
  • 1,543
  • 14
  • 30
6
votes
2 answers

Error Compiling Tensorflow From Source - No module named 'keras_applications'

I am attempting to build tensorflow from source with MKL optimizations on an Intel CPU setup. I have followed the official instructions here up until the command bazel build --config=mkl --config=opt //tensorflow/tools/pip_package:build_pip_package.…
jonathanking
  • 642
  • 2
  • 6
  • 12
6
votes
1 answer

How to compile Swift from command line

I have these 3 files: index.swift import Cocoa print("Init") let app = NSApplication.shared() let delegate = AppDelegate() // alloc main app's delegate class app.delegate = delegate // set as app's…
Lance
  • 75,200
  • 93
  • 289
  • 503
6
votes
1 answer

java compilation : source, target and release supported versions

I may do some cross-compilations for legacy projects and I noticed with recent JDKs that we are limited to some specific versions for the source, target and release JVM arguments. How to get the supported versions for these arguments ?
davidxxx
  • 125,838
  • 23
  • 214
  • 215
6
votes
1 answer

What is the difference between build dependency and runtime dependency

I was told that build dependency and runtime dependency are different. But I don't know why. If some dependency is necessary while building, can't we also say that it is necessary for running? If some dependency is necessary while running, can't we…
Yves
  • 11,597
  • 17
  • 83
  • 180
6
votes
1 answer

Does a Symbol Table store AST (Declaration)Nodes or are the "Symbols" different objects/classes?

I have a few things about the AST / Symbol Table relation that i don't understand. I currently have a AST implemented in C# which has nodes for variable declarations (these contain informations about the name, type, source position, a possible…
6
votes
3 answers

How do I translate CIL to LLVM IR?

I want to compile C# to LLVM IR. So I think translate compiled CIL to LLVM IR is one way I can try. There are some tools I can use such as vmkit and mono-llvm. Is anybody using this tools? Or how can I translate CIL to LLVM?
user624939
  • 61
  • 1
  • 2
6
votes
3 answers

Change a constant variable without rebuilding C++

I've developed a c++ project with visual studio 2015. The output of my project is a single executable that must have a unique ID for every client and this ID must be accessible inside the code. A simple approach is to just define a constant variable…
Masoud Rahimi
  • 5,785
  • 15
  • 39
  • 67
6
votes
1 answer

How to make JavaCompiler.CompilationTask use custom ClassLoader or use .class files for missin .java files?

More spicific: I havewritten my own ClassLoader, that loads .jar files from global library path .jar files from project specific path compiles .java files in project specific path loads all .class files in project specific path So far, this…
JayC667
  • 2,418
  • 2
  • 17
  • 31