In this Topic Hide
Generally speaking, building is a process of converting the source code into a standalone software that can be run on a machine. It includes two compilation stages and linking.
Lycia 3 incorporates two compilers which translate two programming languages:
4GL → IR (intermediate representation, a low level programming language);
IR → object code.
The first translation is performed during the stage we call here compilation proper, and the second translation is performed during the stage AOT compilation.
Below you can see the diagram graphically demonstrating how a source code is converted into an executable program, or, in another words, how an application is being build and compiled by Lycia.
The diagram shows that building starts from a single file or a number of files containing a source code (the files with the .4gl extension) and ends in an executable program (e.g., app_name.exe). The latter always comprises the IR code, and a runner required to translate this IR code into a native code. Provided that the ahead-of-time (AOT) compilation is performed, the native code is cached on the application server into an object_cache folder.
At the compilation and linking stages, Lycia 3 compiler produces an intermediate output data in the form of IR code stored in .4o files. Each source file is converted into a separate IR module during the compilation proper stage. These IR modules together with external libraries (*.4a) become the input data for the linker. Once linking has been performed, the assembled IR code module is further translated into the native code at the stage of the AOT compilation.
Compilation proper is a process of translating 4GL source code into IR.
This stage includes the following operations:
Preprocessing
Lexical Analysis
Parsing or Syntax Analysis
Semantic Analysis
Code Generation
Preprocessing is an initial phase of a source code transformation during which the source code is processed, and the data for further analysis is produced.
Preprocessing is followed by Lexical, Syntax, and Semantic data analyses. During this phase, Lycia 3 checks the source code for its correspondence to the syntactic, lexical, and semantic rules predefined by the source language. If any of these rules is broken, the compiler produces error messages in order to inform the 4gl developer about it.
The compiler reports syntax errors if invalid grammatical structures are used or expression types do not correspond to the expected ones. For example, a syntax error will be reported on compiling the following source code as the END IF statement is missing:
MAIN
DEFINE a INTEGER
IF a <> 0 THEN LET a = 100
END MAIN
You can find the list of the most common compilation errors in the corresponding section of this document.
Code generation is the last stage of the compilation proper during which the code-generator converts a well-formed source code into an intermediate representation that can be either executed by the interpreter without being previously translated into an object code or further compiled into the native code. During this phase, certain primarily machine-dependent code optimization processes also take place.
Linking is a process of binding IR modules and generating a single IR module.
The number of the IR modules depends on the number of the source files compiled:
However, even if several IR modules are involved in the linking process, a single output module is always created:
The linker is also able to extract object files from external sources (libraries): If any symbol is not defined (but is referred to), the linker looks in external libraries for its definition and includes the corresponding file to the executable module.
Actually, the key task of the linker is to define and to link such references. There is a definition for every imported symbol in other modules, and the linker substitutes references to symbols by their storage locations.
At the AOT compilation stage, IR modules are translated into the native code.
AOT (ahead-of-time) compilation is performed either at the deployment or during the very first execution of the program.
Lycia 3 performs AOT compilation, as it allows reducing execution time and performing certain code optimization operations.
Related articles: