Пример #1
0
func (v *Codegen) enumTypeToLLVMType(typ ast.EnumType, gcon *ast.GenericContext) llvm.Type {
	if typ.Simple {
		// TODO: Handle other integer size, maybe dynamic depending on max value? (1 / 2)
		return llvm.IntType(32)
	}

	return llvm.StructType(v.enumTypeToLLVMTypeFields(typ, gcon), true)
}
Пример #2
0
func (v *Codegen) tupleTypeToLLVMType(typ ast.TupleType, gcon *ast.GenericContext) llvm.Type {
	fields := make([]llvm.Type, len(typ.Members))
	for idx, mem := range typ.Members {
		fields[idx] = v.typeRefToLLVMTypeWithOuter(mem, gcon)
	}

	return llvm.StructType(fields, false)
}
Пример #3
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)
	}
}
Пример #4
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
	}
}
Пример #5
0
func (v *Codegen) llvmEnumTypeForMember(enumType ast.EnumType, memberIdx int, gcon *ast.GenericContext) llvm.Type {
	return llvm.StructType([]llvm.Type{enumTagType, v.enumMemberTypeToPaddedLLVMType(enumType, memberIdx, gcon)}, true)
}
Пример #6
0
func (v *Codegen) structTypeToLLVMType(typ ast.StructType, gcon *ast.GenericContext) llvm.Type {
	return llvm.StructType(v.structTypeToLLVMTypeFields(typ, gcon), typ.Attrs().Contains("packed"))
}