I am writing a compiler for a makeshift language that can only process int values, i.e. i32
. Conditions and expressions are similar to C. Thus, I consider conditional expressions as expressions, that is, they return an int value. They can also be used in expressions, such as (2 > 1) + (3 > 2)
returns 2
. But LLVM conditions infer the meaning i1
.
- Now I want to
i1
convert to after each conditional statement i32
so that I can perform binary operations - In addition, I want to use the variables and results of the expression as a condition, for example.
if(variable)
or if(a + b)
. For this I need to convert i32
toi1
In the end, I need a way to typecast from i1
to i32
and from i32
to i1
. My code gives such errors at the moment:
For an operator like if(variable)
:
error: branch condition must have 'i1' type
br i32 %0, label %ifb, label %else
^
For type operator a = b > 3
error: stored value and pointer type do not match
store i1 %gttmp, i32* @a
^
Any suggestion on how to do this?
source
share