Этот коммит содержится в:
Ayke van Laethem 2018-04-20 14:52:07 +02:00
родитель f5f64782ce
коммит e436ca7c8d

15
tgo.go
Просмотреть файл

@ -666,7 +666,16 @@ func (c *Compiler) parseConst(expr *ssa.Const) (llvm.Value, error) {
strObj := llvm.ConstStruct([]llvm.Value{strLen, strPtr}, false) strObj := llvm.ConstStruct([]llvm.Value{strLen, strPtr}, false)
return strObj, nil return strObj, nil
case constant.Int: case constant.Int:
switch expr.Type().(*types.Basic).Kind() { return c.parseConstInt(expr, expr.Type())
default:
return llvm.Value{}, errors.New("todo: unknown constant")
}
}
func (c *Compiler) parseConstInt(expr *ssa.Const, typ types.Type) (llvm.Value, error) {
switch typ := typ.(type) {
case *types.Basic:
switch typ.Kind() {
case types.Bool: case types.Bool:
n, _ := constant.Int64Val(expr.Value) n, _ := constant.Int64Val(expr.Value)
return llvm.ConstInt(llvm.Int1Type(), uint64(n), false), nil return llvm.ConstInt(llvm.Int1Type(), uint64(n), false), nil
@ -694,8 +703,10 @@ func (c *Compiler) parseConst(expr *ssa.Const) (llvm.Value, error) {
default: default:
return llvm.Value{}, errors.New("todo: unknown integer constant") return llvm.Value{}, errors.New("todo: unknown integer constant")
} }
case *types.Named:
return c.parseConstInt(expr, typ.Underlying())
default: default:
return llvm.Value{}, errors.New("todo: unknown constant") return llvm.Value{}, errors.New("todo: unknown constant: " + fmt.Sprintf("%#v", typ))
} }
} }