diff options
author | Ayke van Laethem <[email protected]> | 2020-03-19 13:59:37 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2020-03-20 22:22:24 +0100 |
commit | 9222bda9c665daf64e16ac0e724946582ffc6860 (patch) | |
tree | ed56c005ccb1c534d48cc385467c2e2cfe9c8ee5 /interp/testdata | |
parent | 213a6240a17870dea2603e7fd01ff163468e50c9 (diff) | |
download | tinygo-9222bda9c665daf64e16ac0e724946582ffc6860.tar.gz tinygo-9222bda9c665daf64e16ac0e724946582ffc6860.zip |
interp: add support for constant type asserts
Non-constant type asserts are not yet implemented, but should be
relatively easy to add at a later time. They should result in a clear
error message for now.
Diffstat (limited to 'interp/testdata')
-rw-r--r-- | interp/testdata/interface.ll | 28 | ||||
-rw-r--r-- | interp/testdata/interface.out.ll | 9 |
2 files changed, 37 insertions, 0 deletions
diff --git a/interp/testdata/interface.ll b/interp/testdata/interface.ll new file mode 100644 index 000000000..22378b690 --- /dev/null +++ b/interp/testdata/interface.ll @@ -0,0 +1,28 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64--linux" + +%runtime.typecodeID = type { %runtime.typecodeID*, i64 } +%runtime.interfaceMethodInfo = type { i8*, i64 } +%runtime.typeInInterface = type { %runtime.typecodeID*, %runtime.interfaceMethodInfo* } + [email protected] = global i1 0 +@"reflect/types.type:named:main.foo" = private constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:int", i64 0 } +@"reflect/types.type:basic:int" = external constant %runtime.typecodeID +@"typeInInterface:reflect/types.type:named:main.foo" = private constant %runtime.typeInInterface { %runtime.typecodeID* @"reflect/types.type:named:main.foo", %runtime.interfaceMethodInfo* null } + + +declare i1 @runtime.typeAssert(i64, %runtime.typecodeID*, i8*, i8*) + +define void @runtime.initAll() unnamed_addr { +entry: + call void @main.init() + ret void +} + +define internal void @main.init() unnamed_addr { +entry: + ; Test type asserts. + %typecode = call i1 @runtime.typeAssert(i64 ptrtoint (%runtime.typeInInterface* @"typeInInterface:reflect/types.type:named:main.foo" to i64), %runtime.typecodeID* @"reflect/types.type:named:main.foo", i8* undef, i8* null) + store i1 %typecode, i1* @main.v1 + ret void +} diff --git a/interp/testdata/interface.out.ll b/interp/testdata/interface.out.ll new file mode 100644 index 000000000..2d2467b67 --- /dev/null +++ b/interp/testdata/interface.out.ll @@ -0,0 +1,9 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64--linux" + [email protected] = local_unnamed_addr global i1 true + +define void @runtime.initAll() unnamed_addr { +entry: + ret void +} |