Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Barthelmann V.VBCC compiler system.2004.pdf
Скачиваний:
12
Добавлен:
23.08.2013
Размер:
390.02 Кб
Скачать

Chapter 3: The Compiler

35

3.5.7 __alignof

__alignof is syntactically equivalent to sizeof, but its result is of type int and is the alignment in bytes of the type of the argument. This may be necessary for implementing

‘stdarg.h’.

3.5.8 __offsetof

__offsetof is a builtin version of the offsetof-macro as defined in the C language. The first argument is a structure type and the second a member of the structure type. The result will be a constant expression representing the o set of the specified member in the structure.

3.5.9 Specifying side-e ects

Only use if you know what you are doing!

When optimizing and generating code, vbcc often has to take into account side-e ects of function-calls, e.g. which registers might be modified by this function and what variables are read or modified.

A rather imprecise way to make assumptions on side-e ects is given by the ABI of a certain system (that defines which registers have to be preserved by functions) or rules derived from the language (e.g. local variables whose address has not been taken cannot be accessed by another function).

On higher optimization levels (see Section 3.4.15 [Inter-Procedural Analysis], page 29 and see Section 3.4.16 [Cross-Module Optimizations], page 29)) vbcc will try to analyse functions and often gets much more precise informations regarding side-e ects.

However, if the source code of functions is not visible to vbcc, e.g. because the functions are from libraries or they are written in assembly (see Section 3.5.3 [Inline-Assembly Functions], page 33), it is obviously not possible to analyze the code. In this case, it is possible to specify these side-e ects using the following special variable-attributes (see Section 3.5.4 [Variable Attributes], page 34).

The __regsused(<register-list>) attribute specifies the registers used or modified by a function. The register list is a list of register names (as defined in the backend-documentation) separated by slashes and enclosed in double-quotes, e.g.

__regsused("d0/d1") int abs();

declares a function abs which only uses registers d0 and d1.

__varsmodified(<variable-list>) specifies a list of variables with external linkage which are modified by the function. __varsused is similar, but specifies the external variables read by the function. If a variable is read and written, both attributes have to be specified. The variable-list ist a list of identifiers, separated by slashes and enclosed in double quotes.

The attribute __writesmem(<type>) is used to specify that the function accesses memory using a certain type. This is necessary if the function modifies memory accessible to the calling function which cannot be specified using __varsmodified (e.g. because it is accessed via pointers). __readsmem is similar, but specifies memory which is read.