Comments (6)
I don't know if this answers your question, but:
I've been using the glibc malloc like this in tre. I'm then able to use the malloc function like this.
mallocFunc := module.NewFunc("malloc",
types.NewPointer(types.I8),
ir.NewParam("", types.I64),
)
mallocatedSpaceRaw := block.NewCall(mallocFunc, constant.NewInt(types.I64, structType.Size()))
alloc := block.NewBitCast(mallocatedSpaceRaw, types.NewPointer(structType.LLVM()))
from llvm.
I'm afraid the answer is likely not what you're looking for, but at the moment to the best of my knowledge you need to implement something like this, which is effectively what happens in the bindings you linked to. That's what's going on under the hood:
The llir/llvm
package doesn't have much notion of 'runtime' at the moment, and malloc
is essentially a runtime function call.
I can imagine that at some point llir
may have an IR building package somewhere that would help you do this sort of thing. I'm unsure at this point where it would live. @mewmew may also have some opinions on this.
from llvm.
Thanks @zegl and @pwaller, I think use glibc can solve my problem currently
from llvm.
Perfect! It's brilliant to have a quick answer to this. I didn't know it myself. Closing this issue as it seem to have been resolved.
Cheers,
/u
from llvm.
I can imagine that at some point llir may have an IR building package somewhere that would help you do this sort of thing. I'm unsure at this point where it would live. @mewmew may also have some opinions on this.
Indeed. A package with IR builder like functionality will most likely live somewhere in llir
in the future. Currently we focus on getting the core just right, giving full support for the various language constructs of LLVM IR.
When it comes to the IR builder package, we are essentially collecting experiences from any Gopher playing with LLVM IR to build compilers and other tools and libraries. It may very well be that common practices emerge that are similar but also unlike those used in the C++ builder API, and that is what we want. To see what such an API may look, if re-designed for the Go ecosystem.
The predominant approach today, seem to be to create a structure which tracks the context of the IR generator/builder (i.e. current function being generated, current basic block, etc); e.g. as is done by the Compiler type of tre:
type Compiler struct {
module *ir.Module
...
contextBlock *ir.BasicBlock
...
}
A similar approach it taken by uc, which uses irgen.Function to keep the context of functions being generated:
From https://github.com/mewmew/uc/blob/0c45fe07f88905b95c012dba4acd700a258d674d/irgen/irgen.go#L49:
// A Function represents an LLVM IR function generator.
type Function struct {
// Function being generated.
*ir.Function
// Current basic block being generated.
curBlock *BasicBlock
...
As we gain more experience using llir to develop compilers and analysis tools, we will also see what approaches for IR generation look clean, are general and powerful. We'll probably iterate a few times before declaring an "official" llir irgen
/ builder
package, but we'll definitely look for good examples to point to and learn from.
At least, those are the thoughts on the top of my head. Something similar would probably happen for runtime
specific functionality, e.g. interaction with garbage collection, etc; as further tracked by #18.
from llvm.
@zegl Cool, didn't know tre had escape analysis :)
from llvm.
Related Issues (20)
- ast parse error HOT 10
- `SRet` struct location HOT 3
- How to use Function Pointers? HOT 3
- Wrong function pointer type HOT 1
- indirect br only takes constant addr HOT 1
- Returning void as a value HOT 3
- update llir/llvm to support 14.0 HOT 2
- update llir/llvm to support LLVM 15.0 HOT 7
- How to have two structs referencing eachother HOT 4
- How to convert to exe? HOT 3
- `module.NewTypeDef` has unexpected side effects HOT 17
- Provide working Hello, World example HOT 1
- support llvm 16.0.0 HOT 2
- incorrect cmpxchg signature HOT 4
- How to generate ir for embedded struct? HOT 6
- Convert to string HOT 1
- Hello 10 instead of Hello world. Passing a IntPtr to printf (go - LLIR/LLVM) HOT 3
- malloc and strcpy in LLVM HOT 1
- unable to generate LLVM: structure, external , noundef and ptr HOT 1
- No way to find underlying type of pointer or array HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from llvm.