This is an archive of the discontinued LLVM Phabricator instance.

subtypes for C and OCaml API
ClosedPublic

Authored by TyanNN on May 30 2017, 7:42 AM.

Details

Summary

This patch provides LLVMGetSubtypes & LLVMGetNumContainedTypes + subtypes (for ocaml) functions, which are bindings to llvm::Type::subtypes & llvm::Type::getNumContainedTypes

Diff Detail

Repository
rL LLVM

Event Timeline

TyanNN created this revision.May 30 2017, 7:42 AM
TyanNN removed rL LLVM as the repository for this revision.May 30 2017, 7:44 AM
TyanNN added a subscriber: llvm-commits.
deadalnix edited edge metadata.May 30 2017, 7:47 AM

What's the difference betwenn this and LLVMStructGetTypeAtIndex ?

whitequark accepted this revision.May 30 2017, 7:47 AM
This revision is now accepted and ready to land.May 30 2017, 7:47 AM
TyanNN added a comment.EditedMay 30 2017, 7:53 AM

What's the difference betwenn this and LLVMStructGetTypeAtIndex ?

Well, it's only for structures (possibly packed), this method extracts type from, for example, pointers

I think i'm not allowed to commit by myself, please commit this patch when everything's good

There is also facilities to do it for pointers and alike, and I assume you need to check what kind of type you are iterating on, because you have no way to know if the index is valid or not when you don't, so I'm not sure what is the use case here. The C++ code seems to use that to do an iterator interface, but there are no iterators in C.

TyanNN added a comment.EditedMay 30 2017, 8:11 AM

Hmm, should I add getNumContainedTypes too, so one could check if there are any contained types then? (Because i think it's not possible in C API)

TyanNN updated this revision to Diff 100727.May 30 2017, 10:03 AM

Added LLVMGetNumContainedTypes and num_contained_types

TyanNN edited the summary of this revision. (Show Details)May 30 2017, 11:03 AM
whitequark requested changes to this revision.May 30 2017, 11:09 AM

On second thought I would prefer the OCaml interface to have a single function returning an array, since this is safer and easier to use.

This revision now requires changes to proceed.May 30 2017, 11:09 AM

@whitequark can you explain the use case here ?
@TyanNN what you need to do depends on the use case.

@deadalnix The use case is the same. The current API can assert, the one I suggest can not.

There is an assert within getContainedType so I'm not sure how that's different.

TyanNN added a comment.EditedMay 30 2017, 12:07 PM

Array is generally safer, but I (personally) use getContainedType just to get contained type of a pointer (it has only 1). We can do both, like in C++ API

@TyanNN What's wrong with using element_type then?

@whitequark Hm.. makes sense, i guess. But why are there both in C++ api then...?
Anyway, it seems that there are already all functions provided, they just don't cover whole C++ API..?

I don't think anyone ever had a goal of covering the entire C++ API, the binding is produced demand-side.

@whitequark altighty, i'm closing this review then?

Sure, unless you want to get all contained types as an array.

@whitequark actually i do.. Well, off to write it

TyanNN updated this revision to Diff 100768.May 30 2017, 2:16 PM
TyanNN edited edge metadata.
TyanNN retitled this revision from getContainedType for C and OCaml API to subtypes for C and OCaml API.
TyanNN edited the summary of this revision. (Show Details)

Subtypes list

whitequark added inline comments.May 30 2017, 2:32 PM
bindings/ocaml/llvm/llvm.mli
665 ↗(On Diff #100768)

This shouldn't be exposed in the public interface, I think.

TyanNN updated this revision to Diff 100776.May 30 2017, 2:44 PM
TyanNN edited the summary of this revision. (Show Details)

Don't expose getNumContainedTypes in ocaml api

TyanNN updated this revision to Diff 100778.May 30 2017, 2:46 PM

Fix, remove in llvm.ml too

TyanNN updated this revision to Diff 100780.May 30 2017, 2:48 PM

Remove num_contained_types from llvm_ocaml.c too

whitequark accepted this revision.May 30 2017, 2:56 PM
This revision is now accepted and ready to land.May 30 2017, 2:56 PM

@whitequark please commit this patch when you can, because i do not have commit access

This revision was automatically updated to reflect the committed changes.