Exemple #1
0
func (v *Codegen) structTypeToLLVMType(typ *parser.StructType) llvm.Type {
	if t, ok := v.structLookup_UseHelperFunction[typ]; ok {
		return t
	}

	return llvm.StructType(v.structTypeToLLVMTypeFields(typ), typ.Attrs().Contains("packed"))
}
Exemple #2
0
func (v *Codegen) addStructType(typ *parser.StructType) {
	if _, ok := v.structLookup_UseHelperFunction[typ]; ok {
		return
	}

	for _, field := range typ.Variables {
		if struc, ok := field.Variable.Type.(*parser.StructType); ok {
			v.addStructType(struc) // TODO check recursive loop
		}
	}

	numOfFields := len(typ.Variables)
	fields := make([]llvm.Type, numOfFields)
	packed := false

	for i, member := range typ.Variables {
		memberType := v.typeToLLVMType(member.Variable.Type)
		fields[i] = memberType
	}

	structure := llvm.StructType(fields, packed)
	llvm.AddGlobal(v.curFile.Module, structure, typ.MangledName(parser.MANGLE_ARK_UNSTABLE))
	v.structLookup_UseHelperFunction[typ] = structure

}
Exemple #3
0
func (v *AttributeCheck) CheckStructType(s *SemanticAnalyzer, n parser.StructType) {
	for _, attr := range n.Attrs() {
		switch attr.Key {
		case "packed":
			if attr.Value != "" {
				s.Err(attr, "Struct attribute `%s` doesn't expect value", attr.Key)
			}
		case "deprecated":
			// value is optional, nothing to check
		default:
			s.Err(attr, "Invalid struct attribute key `%s`", attr.Key)
		}
	}
}
Exemple #4
0
func (v *Codegen) addStructType(typ parser.StructType, name string) {
	if _, ok := v.namedTypeLookup[name]; ok {
		return
	}

	structure := v.curFile.LlvmModule.Context().StructCreateNamed(name)

	v.namedTypeLookup[name] = structure

	for _, field := range typ.Variables {
		if named, ok := field.Variable.Type.(*parser.NamedType); ok {
			v.addNamedType(named)
		}
	}

	structure.StructSetBody(v.structTypeToLLVMTypeFields(typ), typ.Attrs().Contains("packed"))
}
Exemple #5
0
Fichier : type.go Projet : vnev/ark
func (v *Codegen) structTypeToLLVMType(typ parser.StructType) llvm.Type {
	return llvm.StructType(v.structTypeToLLVMTypeFields(typ), typ.Attrs().Contains("packed"))
}