예제 #1
0
파일: llvmtypes.go 프로젝트: spate/llgo
func (tm *LLVMTypeMap) structLLVMType(s *types.Struct) llvm.Type {
	// Types may be circular, so we need to first create an empty
	// struct type, then fill in its body after visiting its
	// members.
	sstr := s.String()
	typ, ok := tm.types[sstr]
	if !ok {
		typ = llvm.GlobalContext().StructCreateNamed("")
		tm.types[sstr] = typ
		elements := make([]llvm.Type, len(s.Fields))
		for i, f := range s.Fields {
			ft := f.Type.(types.Type)
			elements[i] = tm.ToLLVM(ft)
		}
		typ.StructSetBody(elements, false)
	}
	return typ
}