// globalStringPtr returns a *string with the specified value. func (tm *TypeMap) globalStringPtr(value string) llvm.Value { strval := llvm.ConstString(value, false) strglobal := llvm.AddGlobal(tm.module, strval.Type(), "") strglobal.SetInitializer(strval) strglobal = llvm.ConstBitCast(strglobal, llvm.PointerType(llvm.Int8Type(), 0)) strlen := llvm.ConstInt(tm.inttype, uint64(len(value)), false) str := llvm.ConstStruct([]llvm.Value{strglobal, strlen}, false) g := llvm.AddGlobal(tm.module, str.Type(), "") g.SetInitializer(str) return g }
func (tm *TypeMap) makeAlgorithmTable(t types.Type) llvm.Value { // TODO set these to actual functions. hashAlg := llvm.ConstNull(llvm.PointerType(tm.alg.hashAlgFunctionType, 0)) printAlg := llvm.ConstNull(llvm.PointerType(tm.alg.printAlgFunctionType, 0)) copyAlg := llvm.ConstNull(llvm.PointerType(tm.alg.copyAlgFunctionType, 0)) equalAlg := tm.alg.eqalg(t) elems := []llvm.Value{ AlgorithmHash: hashAlg, AlgorithmEqual: equalAlg, AlgorithmPrint: printAlg, AlgorithmCopy: copyAlg, } return llvm.ConstStruct(elems, false) }