This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fwd: The AST tree modification. Edited.


Thanks Andi, thanksÂBalaji.

2011/10/7 Andi Hellmund <andi@mail.lxgcc.net>
>
> Hi,
>
> as an addition to Balaji's answer. Please find attached an extract of a sample front-end generating various types of tree nodes (e.g. arrays, structs, ...). This used to work with an older version of GCC, but I'm not sure if this still works with the most recent version. Anyway, it should give you some pointers for further investigations ...
>
> Best regards,
> Andi
>
>
>> Hello,
>> Â Â Â ÂFor most of the things you are looking for, please look for a function called build_decl. It is used in several places inside GCC. Let me give you a small example,
>>
>> If you do the following:
>>
>> tree x = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifer("ii"), integer_type_node)
>>
>> you will declare a variable called "ii" of type "integer."
>>
>> Similarly, to create a new internal structure, if do something like this:
>>
>> tree struct_frame = lang_hooks.make_type (RECORD_TYPE);
>> tree struct_field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, get_identifier("variable"), integer_type_node)
>> TREE_CHAIN(struct_field) = struct_frame
>>
>> You will create the following internal structure
>>
>> struct {
>> Â Âint variable;
>> }
>>
>> I hope this helps you get started.
>>
>> Thanks,
>>
>> Balaji V .Iyer.
>>
>> -----Original Message-----
>> From: niXman [mailto:i.nixman@gmail.com]
>> Sent: Monday, October 03, 2011 6:51 PM
>> To: gcc@gcc.gnu.org
>> Subject: The AST tree modification. Edited.
>>
>> Hi everybody!
>> It is necessary to implement a plug-in for GCC designed to collect the information on types of translation unit, and generate static const array of types rtti_ex _ on its base; Â//////////////////////////////////////
>> enum class type_ {
>> Â Âchar_, uchar_, short_, ushort_, int_, uint_, long_, ulong_,
>> Â Âint64_, uint64_, array_, pointer_, double_, long_double_, float_,
>> Â Âclass_
>> };
>>
>> struct rtti_ex_ { //<<<<<<<<<<<<<<<<<<<<<<<<<
>> Â Âconst char* name;
>> Â Âconst type_ type;
>> Â Âconst size_t size;
>> Â Âconst size_t align;
>> Â Âconst size_t offset;
>> };
>>
>> // generated from plugin.
>> static const rtti_ex_ rtti_ex_array_[] = {
>> Â Â{...},
>> Â Â{...},
>> Â Â{...}
>> };
>> /////////////////////////////////////
>>
>> There aren't any problems with information collection from AST. There is a complexity with AST modification:
>> 1. How to declare a variable?
>> 2. How to declare the typedef?
>> 3. How to declare a structure?
>> 4. How to declare an array of structures?
>> I suppose that there should be a function like: tree make_subtree (const char* source); which result I could insert in the corresponding node. But I haven't found it.
>>
>> Please, give me some links on this subject. It is very desirable, if you could give some links with examples.
>>
>> Thanks.
>>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]