Closed GlowingScrewdriver closed 5 months ago
Can you check how pykaleidoscope folks deal with this? Or see other documentation
If the type is new, may be create new alloca? Check what C is doing.
Can you check how pykaleidoscope folks deal with this? Or see other documentation
Kaleidoscope has only one type, which is double
. So no issue there.
If the type is new, may be create new alloca? Check what C is doing.
C spec doesn't allow redeclaration at all (regardless of type). The following code won't compile:
int main () {
int a = 5;
int a = 6; // error: redefinition of ‘a’
char a = '5'; // error: conflicting types for ‘a’; have ‘char’
return a;
}
If the type is new, may be create new alloca? Check what C is doing.
I suppose we can create a new alloca and number the variable name.
One solution is to overwrite the symbol table entry with the new pointer, while letting LLVMLite handle numbering
Currently,
llvm.py
creates analloca
instruction the first time it encounters every variable, and stores a pointer to the allocated memory in the symbol table. This means that if a variable is re-declared with a different type, the compiler runs into an error since the variable's type doesn't get updated in the symbol table.For example, consider the following bril program:
This will cause a error since the symbol entry for variable
tmp
is never updated to hold an integer pointer (i32*
in LLVM), and the following error is thrown by the LLVMLite IR builder: