From: "Li, Yicheng" <yli137@vols.utk.edu>
To: Basile Starynkevitch <basile@starynkevitch.net>,
"jit@gcc.gnu.org" <jit@gcc.gnu.org>
Subject: Re: Question on libgccjit
Date: Mon, 20 Mar 2023 19:38:35 +0000 [thread overview]
Message-ID: <07AE3E1A-1B09-4BC2-A654-1417C833EA92@vols.utk.edu> (raw)
In-Reply-To: <f942f395-42b5-18cd-45a8-433437fcf752@starynkevitch.net>
[-- Attachment #1: Type: text/plain, Size: 5635 bytes --]
Hi,
Here’s the question for libgccjit on pointer arithmetic.
There’s error for type mismatching with char* and int.
Please see full code at https://github.com/yli137/libgccjit_test
Thank you
Yicheng Li
On Mar 20, 2023, at 3:32 PM, Basile Starynkevitch <basile@starynkevitch.net> wrote:
You don't often get email from basile@starynkevitch.net. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>
Improve your C code to have a full routine or program, then post it on the mailing list
(better yet, make your code open source on https://github.com/<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2F&data=05%7C01%7Cyli137%40vols.utk.edu%7C56c5ed9bacfc42fcb34f08db2979e24b%7C515813d9717d45dd9eca9aa19c09d6f9%7C0%7C0%7C638149375644128233%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=aRcP%2BN%2Bldsmdob1Y%2B9c2I7nZ431o64M71CUa88Z3aAE%3D&reserved=0> ....)
On 20/03/2023 20:30, Li, Yicheng wrote:
Hi,
Here’s the code in C.
Basically, I have two params, both in char *.
And I want to do pointer arithmetic on them.
gcc_jit_type *char_type, *char_ptr_type,, *sizet_type, *int_type;
char_type = gcc_jit_context_get_type( ctxt, GCC_JIT_TYPE_CHAR );
sizet_type = gcc_jit_context_get_type( ctxt, GCC_JIT_TYPE_SIZE_T );
int_type = gcc_jit_context_get_type( ctxt, GCC_JIT_TYPE_INT );
char_ptr_type = gcc_jit_type_get_pointer( char_type );
gcc_jit_lvalue *dst_val = gcc_jit_function_new_local( func, NULL, char_ptr_type, "dst_val" ),
*src_val = gcc_jit_function_new_local( func, NULL, char_ptr_type, "src_val” );
gcc_jit_block_add_assignment( block, NULL, dst_val, gcc_jit_param_as_rvalue( param[0] ) );
gcc_jit_block_add_assignment( block, NULL, src_val, gcc_jit_param_as_rvalue( param[1] ) );
gcc_jit_context_new_binary_op( ctxt, NULL,
GCC_JIT_BINARY_OP_PLUS,
char_ptr_type,
gcc_jit_lvalue_as_rvalue( dst_val ),
gcc_jit_context_new_rvalue_from_long( ctxt, sizet_type, 10 ) );
gcc_jit_context_new_binary_op( ctxt, NULL,
GCC_JIT_BINARY_OP_PLUS,
char_ptr_type,
gcc_jit_lvalue_as_rvalue( src_val ),
gcc_jit_context_new_rvalue_from_long( ctxt, sizet_type, 10 ) );
The error is follows:
libgccjit.so: error: gcc_jit_context_new_binary_op: mismatching types for binary op: a: dst_val (type: char *) b: (size_t)0 (type: size_t)
libgccjit.so: error: gcc_jit_context_new_binary_op: mismatching types for binary op: a: src_val (type: char *) b: (size_t)0 (type: size_t)
Thank you
Yicheng Li
On Mar 20, 2023, at 3:24 PM, Basile Starynkevitch <basile@starynkevitch.net><mailto:basile@starynkevitch.net> wrote:
You don't often get email from basile@starynkevitch.net<mailto:basile@starynkevitch.net>. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>
You asked
> > How to do pointer arithmetic in libgccjit? I created a pointer type > (char *) and an integer type (int or size_t or long). When I use > gcc_jit_context_binary_op with GCC_JIT_BINARY_OP_PLUS, it’s giving me > error as mismatching types of (char*) and (int). Is pointer > arithmetic viable in libgccjit?
but I recommend to show some real C++ code in your question.... And the warnings you obtained.
BTW, you can construct pointer types in GCCJIT.
gcc_jit_type_get_pointer
Alternatively, generate some temporary C code and use GCC to compile it as a plugin
(see https://arxiv.org/abs/1109.0779v1<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Farxiv.org%2Fabs%2F1109.0779v1&data=05%7C01%7Cyli137%40vols.utk.edu%7C56c5ed9bacfc42fcb34f08db2979e24b%7C515813d9717d45dd9eca9aa19c09d6f9%7C0%7C0%7C638149375644128233%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=LhxvKqPpyX8SdNHWd4IJpMRIfvW2EO4VQEEnmDxC8iM%3D&reserved=0> - it used to work)
My pet open source project is http://refpersys.org/<https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Frefpersys.org%2F&data=05%7C01%7Cyli137%40vols.utk.edu%7C56c5ed9bacfc42fcb34f08db2979e24b%7C515813d9717d45dd9eca9aa19c09d6f9%7C0%7C0%7C638149375644128233%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=b4zkXama7Lom4T7HUQxBlUZsu%2FHmu1QQqTofi51SLM0%3D&reserved=0> (inference engine) and we hope to generate code from higher level rules, like explained in Jacques Pitrat(s last book.
https://en.wikipedia.org/wiki/Jacques_Pitrat<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FJacques_Pitrat&data=05%7C01%7Cyli137%40vols.utk.edu%7C56c5ed9bacfc42fcb34f08db2979e24b%7C515813d9717d45dd9eca9aa19c09d6f9%7C0%7C0%7C638149375644284457%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=aJ%2F%2BYj7SYHSW2iA0ZJMq9JHbh2dujbUYHqRbT6j7YhY%3D&reserved=0>
Regards
--
Basile Starynkevitch <basile@starynkevitch.net><mailto:basile@starynkevitch.net>
(only mine opinions / les opinions sont miennes uniquement)
92340 Bourg-la-Reine, France
web page: starynkevitch.net/Basile/ & refpersys.org
--
Basile Starynkevitch <basile@starynkevitch.net><mailto:basile@starynkevitch.net>
(only mine opinions / les opinions sont miennes uniquement)
92340 Bourg-la-Reine, France
web page: starynkevitch.net/Basile/ & refpersys.org
next parent reply other threads:[~2023-03-20 19:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4895236c-a56f-a8aa-d581-476e3072f72c@starynkevitch.net>
[not found] ` <AFDF0F71-5CB3-47A0-95FF-2E23877F3DE7@vols.utk.edu>
[not found] ` <f942f395-42b5-18cd-45a8-433437fcf752@starynkevitch.net>
2023-03-20 19:38 ` Li, Yicheng [this message]
2023-03-20 23:23 ` David Malcolm
2023-03-20 19:16 Li, Yicheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=07AE3E1A-1B09-4BC2-A654-1417C833EA92@vols.utk.edu \
--to=yli137@vols.utk.edu \
--cc=basile@starynkevitch.net \
--cc=jit@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).