Allow for multiple functions in a sysir "context".

Allows for in memory linking.
This commit is contained in:
Calvin Rose 2023-10-22 15:42:03 -05:00
parent f08874e65e
commit 3a782d27b1
7 changed files with 620 additions and 480 deletions

View File

@ -1,18 +1,28 @@
(def ir-asm
@{:instructions
'(
# Types
(type-prim Double f64)
(type-array BigVec Double 100)
(def types-asm
'((type-prim Double f64)
(type-array BigVec Double 100)))
# Declarations
(bind 0 BigVec)
(bind 1 BigVec)
(bind 2 BigVec)
(add 2 0 1)
(return 2))
:parameter-count 2
:link-name "add_vector"})
(def add-asm
'((link-name "add_vector")
(parameter-count 2)
# Declarations
(bind a BigVec)
(bind b BigVec)
(bind c BigVec)
(add c a b)
(return c)))
(def as (sysir/asm ir-asm))
(print (sysir/to-c as))
(def sub-asm
'((link-name "sub_vector")
(parameter-count 2)
(bind a BigVec)
(bind b BigVec)
(bind c BigVec)
(subtract c a b)
(return c)))
(def ctx (sysir/context))
(sysir/asm ctx types-asm)
(sysir/asm ctx add-asm)
(sysir/asm ctx sub-asm)
(print (sysir/to-c ctx))

View File

@ -1,20 +1,19 @@
(def ir-asm
@{:instructions
'(
# Types
(type-prim Double f64)
(type-array BigVec Double 100)
(type-pointer BigVecP BigVec)
'((link-name "add_vectorp")
(parameter-count 2)
# Declarations
(bind 0 BigVecP)
(bind 1 BigVecP)
(bind 2 BigVecP)
(add 2 0 1)
(return 2))
:parameter-count 2
:link-name "add_vectorp"})
# Types
(type-prim Double f64)
(type-array BigVec Double 100)
(type-pointer BigVecP BigVec)
(def as (sysir/asm ir-asm))
(print (sysir/to-c as))
# Declarations
(bind 0 BigVecP)
(bind 1 BigVecP)
(bind 2 BigVecP)
(add 2 0 1)
(return 2)))
(def ctx (sysir/context))
(sysir/asm ctx ir-asm)
(print (sysir/to-c ctx))

View File

@ -1,36 +1,35 @@
(def ir-asm
@{:instructions
'(
# Types
(type-prim Int s32)
(type-prim Double f64)
(type-struct MyPair 0 1)
(type-pointer PInt 0)
(type-array DoubleArray 1 1024)
'((link-name "test_function")
# Declarations
(bind 0 Int)
(bind 1 Int)
(bind 2 Int)
(bind 3 Double)
(bind bob Double)
(bind 5 Double)
(bind 6 MyPair)
# Types
(type-prim Int s32)
(type-prim Double f64)
(type-struct MyPair 0 1)
(type-pointer PInt 0)
(type-array DoubleArray 1 1024)
# Code
(constant 0 10)
(constant 0 21)
:location
(add 2 1 0)
(constant 3 1.77)
(call 3 sin 3)
(cast bob 2)
(call bob test_function)
(add 5 bob 3)
(jump :location)
(return 5))
:parameter-count 0
:link-name "test_function"})
# Declarations
(bind 0 Int)
(bind 1 Int)
(bind 2 Int)
(bind 3 Double)
(bind bob Double)
(bind 5 Double)
(bind 6 MyPair)
(def as (sysir/asm ir-asm))
(print (sysir/to-c as))
# Code
(constant 0 10)
(constant 0 21)
:location
(add 2 1 0)
(constant 3 1.77)
(call 3 sin 3)
(cast bob 2)
(call bob test_function)
(add 5 bob 3)
(jump :location)
(return 5)))
(def ctx (sysir/context))
(sysir/asm ctx ir-asm)
(print (sysir/to-c ctx))

View File

@ -11,52 +11,52 @@
# Use fgetp for code gen
(def ir-asm
@{:instructions
'(
# Types
(type-prim Real f32)
(type-struct Vec3 Real Real Real)
(type-pointer PReal Real)
'((link-name "addv")
(parameter-count 2)
# Declarations
(bind position Vec3)
(bind velocity Vec3)
(bind next-position Vec3)
(bind dest Real)
(bind lhs Real)
(bind rhs Real)
(bind pdest PReal)
(bind plhs PReal)
(bind prhs PReal)
# Types
(type-prim Real f32)
(type-struct Vec3 Real Real Real)
(type-pointer PReal Real)
# Code
(fgetp pdest next-position 0)
(fgetp plhs position 0)
(fgetp prhs velocity 0)
(load lhs plhs)
(load rhs prhs)
(add dest lhs rhs)
(store pdest dest)
# Declarations
(bind position Vec3)
(bind velocity Vec3)
(bind next-position Vec3)
(bind dest Real)
(bind lhs Real)
(bind rhs Real)
(bind pdest PReal)
(bind plhs PReal)
(bind prhs PReal)
(fgetp pdest next-position 1)
(fgetp plhs position 1)
(fgetp prhs velocity 1)
(load lhs plhs)
(load rhs prhs)
(add dest lhs rhs)
(store pdest dest)
# Code
(fgetp pdest next-position 0)
(fgetp plhs position 0)
(fgetp prhs velocity 0)
(load lhs plhs)
(load rhs prhs)
(add dest lhs rhs)
(store pdest dest)
(fgetp pdest next-position 2)
(fgetp plhs position 2)
(fgetp prhs velocity 2)
(load lhs plhs)
(load rhs prhs)
(add dest lhs rhs)
(store pdest dest)
(fgetp pdest next-position 1)
(fgetp plhs position 1)
(fgetp prhs velocity 1)
(load lhs plhs)
(load rhs prhs)
(add dest lhs rhs)
(store pdest dest)
(return next-position))
:parameter-count 2
:link-name "addv"})
(fgetp pdest next-position 2)
(fgetp plhs position 2)
(fgetp prhs velocity 2)
(load lhs plhs)
(load rhs prhs)
(add dest lhs rhs)
(store pdest dest)
(def as (sysir/asm ir-asm))
(print (sysir/to-c as))
(return next-position)))
(def ctx (sysir/context))
(sysir/asm ctx ir-asm)
(print (sysir/to-c ctx))

View File

@ -9,48 +9,47 @@
### }
(def ir-asm
@{:instructions
'(
# Types
(type-prim Real f32)
(type-struct Vec3 Real Real Real)
(type-pointer PReal Real)
'((link-name "addv_with_err")
(parameter-count 2)
# Types
(type-prim Real f32)
(type-struct Vec3 Real Real Real)
(type-pointer PReal Real)
# Declarations
(bind position Vec3)
(bind velocity Vec3)
(bind next-position Vec3)
(bind dest Real)
(bind lhs Real)
(bind rhs Real)
(bind pdest PReal)
(bind plhs PReal)
(bind prhs PReal)
# Declarations
(bind position Vec3)
(bind velocity Vec3)
(bind next-position Vec3)
(bind dest Real)
(bind lhs Real)
(bind rhs Real)
(bind pdest PReal)
(bind plhs PReal)
(bind prhs PReal)
# Code (has type errors)
(fgetp pdest next-position 0)
(fgetp plhs position 0)
(fgetp prhs velocity 0)
(add dest plhs prhs)
(store pdest dest)
# Code (has type errors)
(fgetp pdest next-position 0)
(fgetp plhs position 0)
(fgetp prhs velocity 0)
(add dest plhs prhs)
(store pdest dest)
(fgetp pdest next-position 1)
(fgetp plhs position 1)
(fgetp prhs velocity 1)
(add dest lhs rhs)
(load lhs plhs)
(load rhs prhs)
(store pdest dest)
(fgetp pdest next-position 1)
(fgetp plhs position 1)
(fgetp prhs velocity 1)
(add dest lhs rhs)
(load lhs plhs)
(load rhs prhs)
(store pdest dest)
(fgetp pdest next-position 2)
(fgetp plhs position 2)
(fgetp prhs velocity 2)
(add dest plhs prhs)
(store pdest dest)
(fgetp pdest next-position 2)
(fgetp plhs position 2)
(fgetp prhs velocity 2)
(add dest plhs prhs)
(store pdest dest)
(return next-position))
:parameter-count 2
:link-name "addv_with_err"})
(return next-position)))
(def as (sysir/asm ir-asm))
(print (sysir/to-c as))
(def ctx (sysir/context))
(sysir/asm ctx ir-asm)
(print (sysir/to-c ctx))

View File

@ -1,15 +1,10 @@
(def ir-asm
@{:instructions
'(
# Types
(type-prim Real f32)
(type-prim 1 s32)
'((link-name "redefine_type_fail")
(type-prim Real f32)
(type-prim 1 s32)
(bind bob Real)
(return bob)))
(bind bob Real)
(return bob))
:parameter-count 0
:link-name "redefine_type_fail"})
(def as (sysir/asm ir-asm))
(print (sysir/to-c as))
(def ctx (sysir/context))
(sysir/asm ctx ir-asm)
(print (sysir/to-c ctx))

File diff suppressed because it is too large Load Diff