| | 39 | When a label is referenced by an expression, the compiler needs to |
| | 40 | know whether to declare the label first, and if so, at what type. |
| | 41 | |
| | 42 | * all labels referenced as a result of an FFI declaration |
| | 43 | are declared as `extern StgWord[]`, including funciton labels. |
| | 44 | If the label is called, it is first cast to the correct |
| | 45 | function type. This is because the same label might be |
| | 46 | referred to both as a function and an untyped data label in |
| | 47 | the same module (e.g. Foreign.Marsal.Alloc refers to "free" |
| | 48 | this way). |
| | 49 | |
| | 50 | * all RTS symbols already have declarations (mostly with the correct |
| | 51 | type) in [[GhcFile(includes/StgMiscClosures.h)]], so no declarations are generated. |
| | 52 | |
| | 53 | * certain labels are known to have been defined earlier in the same file, |
| | 54 | so a declaration can be omitted (e.g. SRT labels) |
| | 55 | |
| | 56 | * certain math functions (`sin()`, `cos()` etc.) are already declared because |
| | 57 | we #include math.h, so we don't emit declarations for these. We need |
| | 58 | to #include math.h because some of these fuctions have inline |
| | 59 | definitions, and we get terrible code otherwise. |
| | 60 | |
| | 61 | When compiling the RTS cmm code, we have almost no information about |
| | 62 | labels referenced in the code. The only information we have is |
| | 63 | whether the label is defined in the RTS or in another package: a label |
| | 64 | that is declared with an import statement in the .cmm file is assumed |
| | 65 | to be defined in another package (this is for dynamic linking, where |
| | 66 | we need to emit special code to reference these labels). |
| | 67 | |
| | 68 | For all other labels referenced by RTS .cmm code, we assume they are |
| | 69 | RTS labels, and hence already declared in [[GhcFile(includes/StgMiscClosures.h)]]. This is |
| | 70 | the only choice here: since we don't know the type of the label (info, |
| | 71 | entry etc.), we can't generate a correct declaration. |
| | 72 | |