|
Assembler code:
|
|
Assembler code:
movw r0, #:lower16:y movw r0, #:upper16:y ldr r0, [r0] ??? |
Is this translation to ARM assembler code always correct ???
|
No, if the data type of the variable y was byte, we must use:
movw r0, #:lower16:y
movw r0, #:upper16:y
ldrsb r0, [r0] !!!
|
Otherwise, we will get a runtime error !!!
|
And if the data type of the variable y was short, we must use:
movw r0, #:lower16:y
movw r0, #:upper16:y
ldrsh r0, [r0] !!!
|
Otherwise, we will get a runtime error !!!
|
Answer:
|
Two-pass compilers:
|
|
Evidence: the Java compiler can compile this code:
public class demo { public static void main(String[] args) { System.out.println(x); // How can Java compiler // know the data type of x ? } // Answer: read input file twice ! static int x = 1234; } |
DEMO: /home/cs255001/demo/tmp/demo.java
One-pass compilers:
|
Notable fact about 1 pass compilers:
|
|
Evidence: the C compiler can compile this code:
#include <stdio.h>
int x = 1234;
int main( )
{
printf("%d\n", x);
}
|
DEMO: /home/cs255001/demo/tmp/demo.c
|
Evidence: the C compiler can not compile this code:
#include <stdio.h>
int main( )
{
printf("%d\n", x); // <-- error !
}
int x = 1234;
|
Reason: the data type of x is not (yet) known when the C compiler processes the highlight line !!
|