mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
samples: add Terra samples
source: https://github.com/zdevito/terra/tree/master/tests
This commit is contained in:
28
samples/Terra/asm.t
Normal file
28
samples/Terra/asm.t
Normal 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)
|
||||
Reference in New Issue
Block a user