[LLVMdev] How to implement list in llvm

B B blackbox.dev.ml at gmail.com
Tue Apr 16 00:22:04 PDT 2013


Thank you for your answer!

You are right, but I still don't know how to build such a list dynamically
using LLVM API with user type inside (I don't know this type yet ofc).


2013/4/15 Cristianno Martins <cristiannomartins at gmail.com>

> Hi,
>
> I guess you could use a template with a std::vector: you don't need to
> define right away the type, if you create a template of it.
>
> It should look something like that:
>
> template<class B> class List {
> std::vector<B> myList;
> void insert (int pos, B elem);
> }
>
> template <class B>
> void List::add (int pos, B elem) {
>   myList.insert(myList.begin()+pos, elem);
> }
>
> Then, wherever you'll use this class, you should define for which class B
> your class List should match (such as "List<int> intList;" or "List<
> std::vector<long> > longVectors;").
>
> --
> Cristianno Martins
>
> On Monday, 15 de April de 2013 at 07:13, B B wrote:
>
> Hi!
> I want to implement a list (which operates like ArrayList in Java).
>
> I can use ArrayType from llvm, but at creation time I have to specify
> size so there is a problem when I want to extend it (I can reallocate
> it ofc). Moreover I need to implement all the operations (inserting,
> removing etc.) manually.
>
> I though that maybe I can use std::vector, but there is another
> problem - std::vector is a template class, so I have to specify type
> before compiling it to llvm bytecode. Is there some solution to
> specify that type dynamically?
>
> What is the best method to implement such things in llvm?
>
> I would be grateful for any solutions or tips.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130416/4f50d244/attachment.html>


More information about the llvm-dev mailing list