-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Other Examples #2
Comments
The last three seem to me like they are the most interesting and useful ones, probably in the order you listed them. |
I'm pretty new to Also, what do you guys think about having a gitter channel ? Or a mailing list perhaps ? @sdiehl, thanks for the blog-post! It helped me a lot. But other than that, there aren't many resources available I guess. I mean, besides the Hackage documentation. |
I found a workaround, sort of. I'm just creating a "library" of functions like |
@cskksc One easy way to figure out how something is represented in LLVM is to take a look at the output of A simplified example of this output can be seen in https://gist.github.com/cocreature/93625b5afac68eb7de8b2eaa44561ab6. This works fine if you just want to generate LLVM IR. You need to link against |
@cocreature Thanks a lot! Right now I'm just generating the IR file and compiling it by hand using |
I'll make an example for compiling variadic functions like printf. It's a little tricky with LLVM and probably worthy of an example. |
@sdiehl Thanks! |
It would be great to have an example of conditional branch where a symbol table is also kept. I am confused how to use the recursive do with StateT wrapped around IRBuilder. |
Ok, I'll add some more IRBuilder examples. I was planning on just rewriting the Kaleidoscope tutorial to use it which should hit all the features. |
Thanks, as a matter of fact I am working through the Kaleidoscope tutorial. What I am stuck at is how to keep environment, for example in entry block there is a new variable, and you want to refer to it in the if/else blocks. I looked at StateT, but it has no instance of MonadFix. |
@pavolzetor I don’t quite understand what problem you are running into, maybe you just need a phi node? Could you provide an example of the code you are trying to generate? Also |
@cocreature This is actually an issue I'm hitting as well, I might need to add a function to forward declare references to blocks. The https://github.com/sdiehl/kaleidoscope/blob/master/src/chapter7/Emit.hs#L122 |
@sdiehl Sorry I still don’t get it, why does the following example not work for your usecase? I feel like I’m missing something obvious here :) simple :: Module
simple = buildModule "exampleModule" $ mdo
function "f" [(AST.i32, "a")] AST.i32 $ \[a] -> mdo
entry <- block `named` "entry"
cond <- icmp P.EQ a (ConstantOperand (C.Int 32 0))
condBr cond ifThen ifElse
ifThen <- block
trVal <- add a (ConstantOperand (C.Int 32 0))
br ifExit
ifElse <- block `named` "if.else"
flVal <- add a (ConstantOperand (C.Int 32 0))
br ifElse
ifExit <- block `named` "if.exit"
r <- phi [(trVal, ifThen), (flVal, ifElse)]
ret r |
@cocreature it should be
Code from Clang:
The issue I am having is that I want to populate environment with declarations as I go and refer to them using that environment. |
If you're using an alternative prelude that doesn't include |
Until |
Thanks, that worked. I reported the issue and will think if there is a better way to solve the problem then rely on Here is a link to a subset of kaleidoscope https://github.com/pavolzetor/kaleidoscope-compiler. I may add custom operators and JIT later. |
What exactly is bothering you about |
Higher bar for beginners. I agree using In general, if a feature is not that commonly used, it is very important to document the tought process so it is clear why it is necessary/useful. It took me while to understand why it was useful in this particular case :). |
Any ideas on what other simple use case examples I should make for the bindings. Was thinking about some of these:
The text was updated successfully, but these errors were encountered: