Why is TargetInfo.TargetOpts private?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Why is TargetInfo.TargetOpts private?

Tom Stellard via cfe-dev
Hi everybody,

I plan to use clang for some code analysis. Because of that, I was looking on how one can make clang use a custom ABI (overwrite some sizes, keep reasonable defaults for everything else).
But then I found Targets.cpp and now I got stuck.

The issue is as follows:
To get some instance of TargetInfo in which I can change things (lets say IntWidth), I need to derive from it. But then, I still cannot set the private member TargetOpts which is only set in CreateTargetInfo(). But this function I cannot use because I want to access protected fields. Not settings the pointer at all doesn't seem to be an option as well (asserts).

Is this intended and I am overseeing something? Or is there a way to do this?
Why is the TargetInfo stuff encapsulated that much anyway?

Thanks
Thomas

--------------------------------------------------------------------
Thomas Karos
AbsInt Angewandte Informatik GmbH
Science Park 1                  
66123 Saarbrücken                
GERMANY                          
--------------------------------------------------------------------
Geschäftsführung: Dr.-Ing. Christian Ferdinand
Eingetragen im Handelsregister des Amtsgerichts Saarbrücken, HRB 11234
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why is TargetInfo.TargetOpts private?

Tom Stellard via cfe-dev
You are supposed to pass the target options to CreateTargetInfo. If you want the target info to have different option different, create a new one, with the "right" values for your types.

You can get a reference to  target options with getTargetOpts to, and I do believe your can even modify the members of that and get the desired effect, but it's not, as far as I understand, how it's meant to work.

However, I have only worked on code dealing with targets and target options a tiny bit, so I could be wrong.

--
Mats

On 18 April 2017 at 15:42, Thomas Karos via cfe-dev <[hidden email]> wrote:
Hi everybody,

I plan to use clang for some code analysis. Because of that, I was looking on how one can make clang use a custom ABI (overwrite some sizes, keep reasonable defaults for everything else).
But then I found Targets.cpp and now I got stuck.

The issue is as follows:
To get some instance of TargetInfo in which I can change things (lets say IntWidth), I need to derive from it. But then, I still cannot set the private member TargetOpts which is only set in CreateTargetInfo(). But this function I cannot use because I want to access protected fields. Not settings the pointer at all doesn't seem to be an option as well (asserts).

Is this intended and I am overseeing something? Or is there a way to do this?
Why is the TargetInfo stuff encapsulated that much anyway?

Thanks
Thomas

--------------------------------------------------------------------
Thomas Karos
AbsInt Angewandte Informatik GmbH
Science Park 1
66123 Saarbrücken
GERMANY
--------------------------------------------------------------------
Geschäftsführung: Dr.-Ing. Christian Ferdinand
Eingetragen im Handelsregister des Amtsgerichts Saarbrücken, HRB 11234
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why is TargetInfo.TargetOpts private?

Tom Stellard via cfe-dev
I get that this is the way its meant to be used. But still I wonder why its the only one.

What I get from CreateTargetInfo I cannot alter since the respective fields are protected. And in the TargetOpts I also can reference a certain ABI by name if clang provides it.

But since there are private fields in TargetInfo that cannot be set, I can't even create a working TargetInfo subclass.

--
Thomas Karos
AbsInt Angewandte Informatik GmbH, Science Park 1, 66123 Saarbrücken, GERMANY
--------------------------------------------------------------------
Geschäftsführung: Dr.-Ing. Christian Ferdinand
Eingetragen im Handelsregister des Amtsgerichts Saarbrücken, HRB 11234

----- Ursprüngliche Mail -----
Von: "mats petersson" <[hidden email]>
An: "Thomas Karos" <[hidden email]>
CC: "cfe-dev" <[hidden email]>
Gesendet: Mittwoch, 19. April 2017 14:51:05
Betreff: Re: [cfe-dev] Why is TargetInfo.TargetOpts private?

You are supposed to pass the target options to CreateTargetInfo. If you
want the target info to have different option different, create a new one,
with the "right" values for your types.

You can get a reference to  target options with getTargetOpts
<https://clang.llvm.org/doxygen/classclang_1_1TargetInfo.html#af46e41c7c724fb238952a87f92eb0557>
to, and I do believe your can even modify the members of that and get the
desired effect, but it's not, as far as I understand, how it's meant to
work.

However, I have only worked on code dealing with targets and target options
a tiny bit, so I could be wrong.

--
Mats
<https://clang.llvm.org/doxygen/classclang_1_1TargetInfo.html#af46e41c7c724fb238952a87f92eb0557>

On 18 April 2017 at 15:42, Thomas Karos via cfe-dev <[hidden email]>
wrote:

> Hi everybody,
>
> I plan to use clang for some code analysis. Because of that, I was looking
> on how one can make clang use a custom ABI (overwrite some sizes, keep
> reasonable defaults for everything else).
> But then I found Targets.cpp and now I got stuck.
>
> The issue is as follows:
> To get some instance of TargetInfo in which I can change things (lets say
> IntWidth), I need to derive from it. But then, I still cannot set the
> private member TargetOpts which is only set in CreateTargetInfo(). But this
> function I cannot use because I want to access protected fields. Not
> settings the pointer at all doesn't seem to be an option as well (asserts).
>
> Is this intended and I am overseeing something? Or is there a way to do
> this?
> Why is the TargetInfo stuff encapsulated that much anyway?
>
> Thanks
> Thomas
>
> --------------------------------------------------------------------
> Thomas Karos
> AbsInt Angewandte Informatik GmbH
> Science Park 1
> 66123 Saarbrücken
> GERMANY
> --------------------------------------------------------------------
> Geschäftsführung: Dr.-Ing. Christian Ferdinand
> Eingetragen im Handelsregister des Amtsgerichts Saarbrücken, HRB 11234
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...