Skip to content

Commit

Permalink
Merge pull request #2164 from Shaikh-Ubaid/llvm_global_unsigned_ints
Browse files Browse the repository at this point in the history
LLVM: Support global unsigned integer variable
  • Loading branch information
certik authored Jul 17, 2023
2 parents f8f58d0 + b4f1bb0 commit 71d654a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ RUN(NAME expr_20 LABELS cpython llvm c)
RUN(NAME expr_01u LABELS cpython llvm c NOFAST)
RUN(NAME expr_02u LABELS cpython llvm c NOFAST)
RUN(NAME expr_03u LABELS cpython llvm c NOFAST)
RUN(NAME expr_04u LABELS cpython llvm c)

RUN(NAME loop_01 LABELS cpython llvm c)
RUN(NAME loop_02 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
Expand Down
12 changes: 12 additions & 0 deletions integration_tests/expr_04u.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from lpython import u8, u16, u32, u64

FLAG1 : u8 = u8(1) << u8(4)
FLAG2 : u16 = u16(1) << u16(4)
FLAG3: u32 = u32(1) << u32(4)
FLAG4: u64 = u64(1) << u64(4)

print(FLAG1, FLAG2, FLAG3, FLAG4)
assert FLAG1 == u8(16)
assert FLAG2 == u16(16)
assert FLAG3 == u32(16)
assert FLAG4 == u64(16)
5 changes: 3 additions & 2 deletions src/libasr/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2353,8 +2353,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
this->visit_expr_wrapper(x.m_symbolic_value, true);
init_value = llvm::dyn_cast<llvm::Constant>(tmp);
}
if (x.m_type->type == ASR::ttypeType::Integer) {
int a_kind = down_cast<ASR::Integer_t>(x.m_type)->m_kind;
if (x.m_type->type == ASR::ttypeType::Integer
|| x.m_type->type == ASR::ttypeType::UnsignedInteger) {
int a_kind = ASRUtils::extract_kind_from_ttype_t(x.m_type);
llvm::Type *type;
int init_value_bits = 8*a_kind;
type = llvm_utils->getIntType(a_kind);
Expand Down

0 comments on commit 71d654a

Please sign in to comment.