Example #1
0
func (v *Codegen) arrayTypeToLLVMType(typ ast.ArrayType, gcon *ast.GenericContext) llvm.Type {
	memType := v.typeRefToLLVMTypeWithOuter(typ.MemberType, gcon)

	if typ.IsFixedLength {
		return llvm.ArrayType(memType, typ.Length)
	} else {
		fields := []llvm.Type{v.primitiveTypeToLLVMType(ast.PRIMITIVE_uint), llvm.PointerType(memType, 0)}
		return llvm.StructType(fields, false)
	}
}
Example #2
0
func (v *Codegen) enumTypeToLLVMTypeFields(typ ast.EnumType, gcon *ast.GenericContext) []llvm.Type {
	longestLength := uint64(0)
	for _, member := range typ.Members {
		memLength := v.targetData.TypeAllocSize(v.typeToLLVMType(member.Type, gcon))
		if memLength > longestLength {
			longestLength = memLength
		}
	}

	// TODO: verify no overflow
	return []llvm.Type{enumTagType, llvm.ArrayType(llvm.IntType(8), int(longestLength))}
}
Example #3
0
func (v *Codegen) enumMemberTypeToPaddedLLVMType(enumType ast.EnumType, memberIdx int, gcon *ast.GenericContext) llvm.Type {
	longestLength := uint64(0)
	for _, member := range enumType.Members {
		memLength := v.targetData.TypeAllocSize(v.typeToLLVMType(member.Type, gcon))
		if memLength > longestLength {
			longestLength = memLength
		}
	}

	member := enumType.Members[memberIdx]
	actualType := v.typeToLLVMType(member.Type, gcon)
	amountPad := longestLength - v.targetData.TypeAllocSize(actualType)

	if amountPad > 0 {
		types := make([]llvm.Type, actualType.StructElementTypesCount()+1)
		copy(types, actualType.StructElementTypes())
		types[len(types)-1] = llvm.ArrayType(llvm.IntType(8), int(amountPad))
		return llvm.StructType(types, false)
	} else {
		return actualType
	}
}