예제 #1
0
파일: typemap.go 프로젝트: minux/llgo
func (tm *llvmTypeMap) basicLLVMType(b *types.Basic) llvm.Type {
	switch b.Kind() {
	case types.Bool:
		return llvm.Int1Type()
	case types.Int8, types.Uint8:
		return llvm.Int8Type()
	case types.Int16, types.Uint16:
		return llvm.Int16Type()
	case types.Int32, types.Uint32:
		return llvm.Int32Type()
	case types.Uint, types.Int:
		return tm.inttype
	case types.Int64, types.Uint64:
		return llvm.Int64Type()
	case types.Float32:
		return llvm.FloatType()
	case types.Float64:
		return llvm.DoubleType()
	case types.UnsafePointer, types.Uintptr:
		return tm.target.IntPtrType()
	case types.Complex64:
		f32 := llvm.FloatType()
		elements := []llvm.Type{f32, f32}
		return llvm.StructType(elements, false)
	case types.Complex128:
		f64 := llvm.DoubleType()
		elements := []llvm.Type{f64, f64}
		return llvm.StructType(elements, false)
	case types.String:
		i8ptr := llvm.PointerType(llvm.Int8Type(), 0)
		elements := []llvm.Type{i8ptr, tm.inttype}
		return llvm.StructType(elements, false)
	}
	panic(fmt.Sprint("unhandled kind: ", b.Kind))
}
예제 #2
0
파일: package.go 프로젝트: umisama/gopherjs
func toJavaScriptType(t *types.Basic) string {
	switch t.Kind() {
	case types.UntypedInt:
		return "Int"
	default:
		name := t.String()
		return strings.ToUpper(name[:1]) + name[1:]
	}
}
예제 #3
0
파일: utils.go 프로젝트: nvdnkpr/gopherjs
func toJavaScriptType(t *types.Basic) string {
	switch t.Kind() {
	case types.UntypedInt:
		return "Int"
	case types.Byte:
		return "Uint8"
	case types.Rune:
		return "Int32"
	case types.UnsafePointer:
		return "UnsafePointer"
	default:
		name := t.String()
		return strings.ToUpper(name[:1]) + name[1:]
	}
}
예제 #4
0
func fixNumber(value string, basic *types.Basic) string {
	switch basic.Kind() {
	case types.Int8:
		return "(" + value + " << 24 >> 24)"
	case types.Uint8:
		return "(" + value + " << 24 >>> 24)"
	case types.Int16:
		return "(" + value + " << 16 >> 16)"
	case types.Uint16:
		return "(" + value + " << 16 >>> 16)"
	case types.Int32:
		return "(" + value + " >> 0)"
	case types.Uint32, types.Uintptr:
		return "(" + value + " >>> 0)"
	}
	return "(" + value + ")"
}
예제 #5
0
func (c *funcContext) fixNumber(value *expression, basic *types.Basic) *expression {
	switch basic.Kind() {
	case types.Int8:
		return c.formatParenExpr("%s << 24 >> 24", value)
	case types.Uint8:
		return c.formatParenExpr("%s << 24 >>> 24", value)
	case types.Int16:
		return c.formatParenExpr("%s << 16 >> 16", value)
	case types.Uint16:
		return c.formatParenExpr("%s << 16 >>> 16", value)
	case types.Int32, types.Int:
		return c.formatParenExpr("%s >> 0", value)
	case types.Uint32, types.Uint, types.Uintptr:
		return c.formatParenExpr("%s >>> 0", value)
	default:
		panic(int(basic.Kind()))
	}
}
예제 #6
0
파일: typemap.go 프로젝트: quarnster/llgo
// basicRuntimeType creates the runtime type structure for
// a basic type. If underlying is true, then a new global
// is always created.
func (tm *TypeMap) basicRuntimeType(b *types.Basic, underlying bool) (global, ptr llvm.Value) {
	var globalname string
	if !underlying {
		globalname = "__llgo.type.runtime." + tm.TypeString(b)
		if tm.pkgpath != "runtime" {
			global := llvm.AddGlobal(tm.module, tm.runtimeType, globalname)
			global.SetInitializer(llvm.ConstNull(tm.runtimeType))
			global.SetLinkage(llvm.CommonLinkage)
			return global, global
		}
	}
	rtype := tm.makeRtype(b, basicReflectKinds[b.Kind()])
	global, ptr = tm.makeRuntimeTypeGlobal(rtype)
	if globalname != "" {
		global.SetName(globalname)
	}
	return global, ptr
}
예제 #7
0
파일: types.go 프로젝트: minux/llgo
func (m *TypeMap) descriptorBasic(t *types.Basic, name string) TypeDebugDescriptor {
	switch t.Kind() {
	case types.String:
		return m.descriptorStruct(types.NewStruct([]*types.Var{
			types.NewVar(0, nil, "ptr", types.NewPointer(types.Typ[types.Uint8])),
			types.NewVar(0, nil, "len", types.Typ[types.Int]),
		}, nil), name)
	case types.UnsafePointer:
		return &BasicTypeDescriptor{
			TypeDescriptorCommon: TypeDescriptorCommon{
				Name:      name,
				Size:      uint64(m.Sizes.Sizeof(t) * 8),
				Alignment: uint64(m.Sizes.Alignof(t) * 8),
			},
			TypeEncoding: DW_ATE_unsigned,
		}
	default:
		bt := &BasicTypeDescriptor{
			TypeDescriptorCommon: TypeDescriptorCommon{
				Name:      t.String(),
				Size:      uint64(m.Sizes.Sizeof(t) * 8),
				Alignment: uint64(m.Sizes.Alignof(t) * 8),
			},
		}
		switch bi := t.Info(); {
		case bi&types.IsBoolean != 0:
			bt.TypeEncoding = DW_ATE_boolean
		case bi&types.IsUnsigned != 0:
			bt.TypeEncoding = DW_ATE_unsigned
		case bi&types.IsInteger != 0:
			bt.TypeEncoding = DW_ATE_signed
		case bi&types.IsFloat != 0:
			bt.TypeEncoding = DW_ATE_float
		case bi&types.IsComplex != 0:
			bt.TypeEncoding = DW_ATE_imaginary_float
		case bi&types.IsUnsigned != 0:
			bt.TypeEncoding = DW_ATE_unsigned
		default:
			panic(fmt.Sprintf("unhandled: %#v", t))
		}
		return bt
	}
}
예제 #8
0
파일: typemap.go 프로젝트: minux/llgo
// basicRuntimeType creates the runtime type structure for
// a basic type. If underlying is true, then a new global
// is always created.
func (tm *TypeMap) basicRuntimeType(b *types.Basic, underlying bool) (global, ptr llvm.Value) {
	b = types.Typ[b.Kind()] // unalias
	var name string
	if !underlying {
		name = typeString(b)
		if tm.pkgpath != "runtime" {
			global := llvm.AddGlobal(tm.module, tm.runtime.rtype.llvm, typeSymbol(name))
			global.SetInitializer(llvm.ConstNull(tm.runtime.rtype.llvm))
			global.SetLinkage(llvm.CommonLinkage)
			return global, global
		}
	}
	rtype := tm.makeRtype(b, basicReflectKinds[b.Kind()])
	global, ptr = tm.makeRuntimeTypeGlobal(rtype, name)
	global.SetLinkage(llvm.ExternalLinkage)
	if !underlying {
		switch b.Kind() {
		case types.Int32:
			llvm.AddAlias(tm.module, global.Type(), global, typeSymbol("rune"))
		case types.Uint8:
			llvm.AddAlias(tm.module, global.Type(), global, typeSymbol("byte"))
		}
	}
	return global, ptr
}
예제 #9
0
파일: utils.go 프로젝트: nvdnkpr/gopherjs
func isComplex(t *types.Basic) bool {
	return t.Kind() == types.Complex64 || t.Kind() == types.Complex128
}
예제 #10
0
파일: utils.go 프로젝트: nvdnkpr/gopherjs
func is64Bit(t *types.Basic) bool {
	return t.Kind() == types.Int64 || t.Kind() == types.Uint64
}
예제 #11
0
파일: typemap.go 프로젝트: hzmangel/llgo
func (tm *TypeMap) basicRuntimeType(b *types.Basic) (global, ptr llvm.Value) {
	rtype := tm.makeRtype(b, basicReflectKinds[b.Kind()])
	return tm.makeRuntimeTypeGlobal(rtype)
}