FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

LLVM: Support Unsigned Int in visit_Variable by Smit-create · Pull Request #2171 · lcompilers/lpython · GitHub

LLVM: Support Unsigned Int in visit_Variable - #2171

Merged
certik merged 2 commits into
lcompilers:mainfrom
Smit-create:i-2170
Jul 17, 2023
Merged

LLVM: Support Unsigned Int in visit_Variable#2171
certik merged 2 commits into
lcompilers:mainfrom
Smit-create:i-2170

Conversation

Copy link
Copy Markdown
Collaborator

Fixes #2170

certik left a comment
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is fine, but after merging let's add tests for all unsigned kinds as well as checking that the value is present in the variable correctly.

What exactly was the problem --- that this is using global variables?

certik marked this pull request as ready for review July 17, 2023 14:58
certik enabled auto-merge July 17, 2023 14:59
certik merged commit ea9715b into lcompilers:main Jul 17, 2023

ubaidsk commented Jul 17, 2023

Copy link
Copy Markdown
Collaborator

Please see #2170 (comment). I think the else if condition added in this PR would never be executed since the first if in the visit_Variable() would be executed for Integers as well as UnsingedIntegers. Thus, it seems the else if condition is more like a dead code.

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);
llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name,
type);
if (!external) {
if (ASRUtils::is_array(x.m_type)) {
throw CodeGenError("Arrays are not supported by visit_Variable");
}
if (init_value) {
module->getNamedGlobal(x.m_name)->setInitializer(
init_value);
} else {
module->getNamedGlobal(x.m_name)->setInitializer(
llvm::ConstantInt::get(context,
llvm::APInt(init_value_bits, 0)));
}
}
llvm_symtab[h] = ptr;
} else if (x.m_type->type == ASR::ttypeType::UnsignedInteger) {

ubaidsk commented Jul 17, 2023

Copy link
Copy Markdown
Collaborator

This is fine, but after merging let's add tests for all unsigned kinds as well as checking that the value is present in the variable correctly.

Yes, I tested different unsigned kinds in https://github.com/lcompilers/lpython/pull/2164/files#diff-b6a08444f0697e1ea781c919bcdf3b29eba7b542bddef56ce0125f3c2997c973.

x : i32

for i in range(i32(u)):
x = i * 2

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If in case we update the changes in this PR, I suggest we add an assert in this test case (and also possibly a print statement before the assert).

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

type casting between u16 and i32 needed

3 participants


Back | FazBrowse Home | New Git URL