|
| 1 | +package wasmer |
| 2 | + |
| 3 | +// #include <wasmer_wasm.h> |
| 4 | +import "C" |
| 5 | +import "runtime" |
| 6 | + |
| 7 | +type Target struct { |
| 8 | + _inner *C.wasm_target_t |
| 9 | +} |
| 10 | + |
| 11 | +func newTarget(target *C.wasm_target_t) *Target { |
| 12 | + self := &Target{ |
| 13 | + _inner: target, |
| 14 | + } |
| 15 | + |
| 16 | + runtime.SetFinalizer(self, func(self *Target) { |
| 17 | + C.wasm_target_delete(self.inner()) |
| 18 | + }) |
| 19 | + |
| 20 | + return self |
| 21 | +} |
| 22 | + |
| 23 | +func NewTarget(triple *Triple, cpuFeatures *CpuFeatures) *Target { |
| 24 | + return newTarget(C.wasm_target_new(triple.inner(), cpuFeatures.inner())) |
| 25 | +} |
| 26 | + |
| 27 | +func (self *Target) inner() *C.wasm_target_t { |
| 28 | + return self._inner |
| 29 | +} |
| 30 | + |
| 31 | +type Triple struct { |
| 32 | + _inner *C.wasm_triple_t |
| 33 | +} |
| 34 | + |
| 35 | +func newTriple(triple *C.wasm_triple_t) *Triple { |
| 36 | + self := &Triple{ |
| 37 | + _inner: triple, |
| 38 | + } |
| 39 | + |
| 40 | + runtime.SetFinalizer(self, func(self *Triple) { |
| 41 | + C.wasm_triple_delete(self.inner()) |
| 42 | + }) |
| 43 | + |
| 44 | + return self |
| 45 | +} |
| 46 | + |
| 47 | +func NewTriple(triple string) (*Triple, error) { |
| 48 | + cTripleName := newName(triple) |
| 49 | + defer C.wasm_name_delete(&cTripleName) |
| 50 | + |
| 51 | + cTriple := C.wasm_triple_new(&cTripleName) |
| 52 | + |
| 53 | + if cTriple == nil { |
| 54 | + return nil, newErrorFromWasmer() |
| 55 | + } |
| 56 | + |
| 57 | + return newTriple(cTriple), nil |
| 58 | +} |
| 59 | + |
| 60 | +func NewTripleFromHost() *Triple { |
| 61 | + return newTriple(C.wasm_triple_new_from_host()) |
| 62 | +} |
| 63 | + |
| 64 | +func (self *Triple) inner() *C.wasm_triple_t { |
| 65 | + return self._inner |
| 66 | +} |
| 67 | + |
| 68 | +type CpuFeatures struct { |
| 69 | + _inner *C.wasm_cpu_features_t |
| 70 | +} |
| 71 | + |
| 72 | +func newCpuFeatures(cpu_features *C.wasm_cpu_features_t) *CpuFeatures { |
| 73 | + self := &CpuFeatures{ |
| 74 | + _inner: cpu_features, |
| 75 | + } |
| 76 | + |
| 77 | + runtime.SetFinalizer(self, func(self *CpuFeatures) { |
| 78 | + C.wasm_cpu_features_delete(self.inner()) |
| 79 | + }) |
| 80 | + |
| 81 | + return self |
| 82 | +} |
| 83 | + |
| 84 | +func NewCpuFeatures() *CpuFeatures { |
| 85 | + return newCpuFeatures(C.wasm_cpu_features_new()) |
| 86 | +} |
| 87 | + |
| 88 | +func (self *CpuFeatures) Add(feature string) error { |
| 89 | + cFeature := newName(feature) |
| 90 | + defer C.wasm_name_delete(&cFeature) |
| 91 | + |
| 92 | + if !C.wasm_cpu_features_add(self.inner(), &cFeature) { |
| 93 | + return newErrorFromWasmer() |
| 94 | + } |
| 95 | + |
| 96 | + return nil |
| 97 | +} |
| 98 | + |
| 99 | +func (self *CpuFeatures) inner() *C.wasm_cpu_features_t { |
| 100 | + return self._inner |
| 101 | +} |
0 commit comments