samples: add Terra samples

source: https://github.com/zdevito/terra/tree/master/tests
This commit is contained in:
Bayu Aldi Yansyah
2016-01-28 11:22:27 +07:00
parent e32a837fb2
commit 9b8b39f444
370 changed files with 11921 additions and 0 deletions

28
samples/Terra/asm.t Normal file
View File

@@ -0,0 +1,28 @@
local a = ...
if not a then
--force MCJIT
os.execute("../terra -m asm.t true")
return
end
C = terralib.includec("stdio.h")
struct Vendor {
maxV : int;
b : int;
c : int;
d : int;
}
terra foo()
var r = terralib.asm(Vendor,"cpuid","={eax},={ebx},={ecx},={edx},{eax},~{dirflag},~{fpsr},~{flags}",false,0)
r.c,r.d = r.d,r.c
C.printf("%.12s\n", &r.b)
end
foo()
terra addone(a : int)
return terralib.asm(int,"addl $$1,$1","=r,0",true,a)
end
assert(addone(3) == 4)