Working with arrays, structs, and pointers
For almost all applications, basic types such as INTEGER
are not sufficient. For example, to represent mathematical objects such as a matrix or a complex number, you must construct new data types based on existing ones. These new data types are generally known as aggregate or composite.
Arrays are a sequence of elements of the same type. In LLVM, arrays are always static, which means that the number of elements is constant. The tinylang
type ARRAY [10] OF INTEGER
or the C type long[10]
is expressed in IR as follows:
[10 x i64]
Structures are composites of different types. In programming languages, they are often expressed with named members. For example, in tinylang
, a structure is written as RECORD x: REAL; color: INTEGER; y: REAL; END;
and the same structure in C is struct { float x; long color; float y; };
. In LLVM IR, only the type names are listed:
{ float, i64, float }
To access a member, a numerical index is used. Like...