Skip to content
This repository has been archived by the owner on Jun 1, 2020. It is now read-only.

Use C++ implement llvm compiler #5

Closed
dannypsnl opened this issue Nov 24, 2017 · 4 comments
Closed

Use C++ implement llvm compiler #5

dannypsnl opened this issue Nov 24, 2017 · 4 comments

Comments

@dannypsnl
Copy link
Owner

Unfortunately, llir/llvm can not do something I want, and go-llvm binding has poor document.
I think should use C++ to write the translate part, but we can use Go write the remain part.

@dannypsnl dannypsnl added the TODO label Nov 24, 2017
@dannypsnl
Copy link
Owner Author

Ok

@mewmew
Copy link

mewmew commented Nov 25, 2018

Hi @dannypsnl!

I just came across your project the other day and have started to learn more about it.

I'd be curious to know what parts were missing in llir/llvm that made it not possible to use. We are preparing for the v0.3.0 release of llir/llvm so it would be great to get some feedback!

Cheerful regards,
Robin

@dannypsnl
Copy link
Owner Author

Hi @mewmew, think for your work, llir/llvm is a great project, last time I give up is because some API is confusing me, e.g. module.AppendFunction, module.NewFunction. And the implementation of my code is transferred context between AST, it makes the code be hard to control(not llir issue actually).
Now I would need a stable API for developing this project, so I would use llvm.org provided c-binding for Go. But I also would like to help you test the use case of llir, I'm writing a little c compiler by participle since I already testing participle, why not with llir?
And I also would like to help to develop llir if I have time, appreciate your comment here!

@mewmew
Copy link

mewmew commented Nov 27, 2018

Ah, @alecthomas's participle is great! I've been playing with it too!

last time I give up is because some API is confusing me, e.g. module.AppendFunction, module.NewFunction

That's good feedback. In v0.3.0, AppendFunction is removed.

Now to create functions, use ir.NewFunc, this returns a function that you can add to a module using regular Go append; e.g.

m := ir.NewModule()
f := ir.NewFunc("foo", types.I32)
m.Funcs = append(m.Funcs, f)

There is also a shorthand to do the exact same thing in one step instead of two:

m := ir.NewModule()
f := m.NewFunc("foo", types.I32)

Using the NewFunc method on a module creates a new function, adds it to the module, and returns it for later use. Essentially, the ir.Module.NewFunc method calls append internally.

From https://github.com/llir/llvm/blob/master/ir/module_function.go#L9:

func (m *Module) NewFunc(name string, retType types.Type, params ...*Param) *Function {
	f := NewFunc(name, retType, params...)
	m.Funcs = append(m.Funcs, f)
	return f
}

Cheers,
Robin

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants