Compilation basics

Lycia compiler reads the source code written in 4GL and translates it into the native code that can be directly executed by the operating system.

As a process of converting the source code into a machine-runnable standalone software, building includes three stages - two compilation stages and linking.

Lycia incorporates two compilers which translate two programming languages:

  1. 4GL → IR (intermediate representation, a low level programming language);

  2. 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 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

Compilation proper is a process of translating 4GL source code into IR.

This stage includes these operations:

Pre-processing is an initial phase of a source code transformation during which the source code is processed, and the data for further analysis is produced.

Pre-processing is followed by lexical, syntax, and semantic data analyses. During this phase, Lycia 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 this 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 here.

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

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.

AOT Compilation

At the AOT compilation stage, IR modules are translated into the native code.

Ahead-of-time (AOT) compilation is performed either at the deployment or during the very first execution of the program.

Lycia performs AOT compilation, as it allows reducing execution time and performing certain code optimization operations.

 

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.