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 data types. These new data types are generally called aggregate or composite types.
Arrays are a sequence of elements of the same type. In LLVM, arrays are always static: the number of elements is constant. The tinylang
type of ARRAY [10] OF INTEGER
, or the C type of 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, y: REAL; color: INTEGER; END;
and the same structure in C is struct { float x, y; long color; };
. In LLVM IR, only the type names are listed:
{ float, float, i64 }
To access a member, a numerical index is used. Like arrays,...