Skip to content

Commit

Permalink
initial progress on compiling quotations
Browse files Browse the repository at this point in the history
  • Loading branch information
keithshep committed Nov 27, 2012
1 parent 39e65d8 commit abb597b
Show file tree
Hide file tree
Showing 6 changed files with 669 additions and 7 deletions.
54 changes: 54 additions & 0 deletions LLVMFSharp.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,11 @@ namespace LLVM
phi:Generated.Core.ValueRef ->
incoming:(Generated.Core.ValueRef * Generated.Core.BasicBlockRef) array ->
unit
val buildPhiWithIncoming :
bldr:Generated.Core.BuilderRef ->
ty:Generated.Core.TypeRef ->
incoming:(Generated.Core.ValueRef * Generated.Core.BasicBlockRef) array ->
name:string -> Generated.Core.ValueRef
val getNamedFunction :
modRef:Generated.Core.ModuleRef -> name:string -> Generated.Core.ValueRef
val optValueRef :
Expand Down Expand Up @@ -1858,3 +1863,52 @@ namespace LLVM
val initializeX86Target : unit -> unit
end

namespace LLVM
module Quote = begin
type Def =
{funVar: Quotations.Var;
funParams: Quotations.Var list;
body: Quotations.Expr;}
type LetDef =
| LetDef of Def
| LetRecDefs of Def list
val lambdas : expr:Quotations.Expr -> Quotations.Var list * Quotations.Expr
val allLetFuncDefs : expr:Quotations.Expr -> LetDef list * Quotations.Expr
val uInt32Ty : System.Type
val int32Ty : System.Type
val uInt16Ty : System.Type
val int16Ty : System.Type
val uInt8Ty : System.Type
val int8Ty : System.Type
val ( |UnitTy|_| ) : ty:System.Type -> unit option
val ( |BoolTy|_| ) : ty:System.Type -> unit option
val ( |SingleTy|_| ) : ty:System.Type -> unit option
val ( |DoubleTy|_| ) : ty:System.Type -> unit option
val ( |Int8Ty|_| ) : ty:System.Type -> unit option
val ( |UInt8Ty|_| ) : ty:System.Type -> unit option
val ( |Int16Ty|_| ) : ty:System.Type -> unit option
val ( |UInt16Ty|_| ) : ty:System.Type -> unit option
val ( |Int32Ty|_| ) : ty:System.Type -> unit option
val ( |UInt32Ty|_| ) : ty:System.Type -> unit option
val ( |Int64Ty|_| ) : ty:System.Type -> unit option
val ( |UInt64Ty|_| ) : ty:System.Type -> unit option
val ( |AnySIntTy|_| ) : ty:System.Type -> unit option
val ( |AnyUIntTy|_| ) : ty:System.Type -> unit option
val ( |AnyIntTy|_| ) : ty:System.Type -> unit option
val ( |AnyFloatTy|_| ) : ty:System.Type -> unit option
val llvmTyOf : ty:System.Type -> Generated.Core.TypeRef
val llvmTyOfVar : var:Quotations.Var -> Generated.Core.TypeRef
val llvmTyOfExpr : expr:Quotations.Expr -> Generated.Core.TypeRef
val isUnitExpr : expr:Quotations.Expr -> bool
val declareFunction :
moduleRef:Generated.Core.ModuleRef -> def:Def -> Generated.Core.ValueRef
val ( |FullAppl|_| ) :
expr:Quotations.Expr -> (Quotations.Expr * Quotations.Expr list) option
val implementFunction :
valMap:Map<string,Generated.Core.ValueRef> ->
fnVal:Generated.Core.ValueRef -> fnDef:Def -> unit
val compileQuote :
moduleRef:Generated.Core.ModuleRef -> expr:Quotations.Expr -> unit
val testQuote : Quotations.Expr<unit>
end

13 changes: 9 additions & 4 deletions build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ fsc --nologo --debug --sig:LLVMFSharp.fsi --target:library --out:LLVMFSharp.dll
src/LLVM/BitReader.fs \
src/LLVM/ExecutionEngine.fs \
src/LLVM/Extra.fs \
src/LLVM/Target.fs
src/LLVM/Target.fs \
src/LLVM/Quote.fs

# uncomment the following to build and run the tests

Expand All @@ -35,8 +36,12 @@ fsc --nologo --debug --sig:LLVMFSharp.fsi --target:library --out:LLVMFSharp.dll
#echo "test that the API works with C#"
#dmcs -out:CSSimpleTest2.exe -r:LLVMFSharp.dll test/CSSimpleTest2.cs
#mono CSSimpleTest2.exe
#
#echo "metadata test"
#fsc --nologo -r LLVMFSharp.dll test/metadatatest.fs
#mono metadatatest.exe

echo "metadata test"
fsc --nologo -r LLVMFSharp.dll test/metadatatest.fs
mono metadatatest.exe
echo "quote test"
fsc --nologo -r LLVMFSharp.dll test/quotetest.fs
mono quotetest.exe

3 changes: 3 additions & 0 deletions llvm-fs.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<Compile Include="src\LLVM\Target.fs">
<Link>Target.fs</Link>
</Compile>
<Compile Include="src\LLVM\Quote.fs">
<Link>Quote.fs</Link>
</Compile>
</ItemGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
Expand Down
16 changes: 13 additions & 3 deletions src/LLVM/Core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,24 @@ let buildCall (bld : BuilderRef) (func : ValueRef) (args : ValueRef array) (name

ValueRef (buildCallNative (bld.Ptr, func.Ptr, argPtrs.Ptrs, argCount, name))

let addIncoming (phi : ValueRef) (incoming : (ValueRef * BasicBlockRef) array) =
let (incVals, incBlocks) = Array.unzip incoming
let addIncoming (phi : ValueRef) (incoming : array<ValueRef * BasicBlockRef>) =
let incVals, incBlocks = Array.unzip incoming
use incValPtrs = new NativePtrs([|for vr in incVals -> vr.Ptr|])
use incBlockPtrs = new NativePtrs([|for br in incBlocks -> br.Ptr|])
let incCount = uint32 incoming.Length

addIncomingNative (phi.Ptr, incValPtrs.Ptrs, incBlockPtrs.Ptrs, incCount)

let buildPhiWithIncoming
(bldr:BuilderRef)
(ty:TypeRef)
(incoming:array<ValueRef * BasicBlockRef>)
(name:string) =

let phi = buildPhi bldr ty name
addIncoming phi incoming
phi

let getNamedFunction (modRef : ModuleRef) (name : string) =
ValueRef (getNamedFunctionNative (modRef.Ptr, name))

Expand Down Expand Up @@ -183,4 +193,4 @@ let constStructInContext (c:ContextRef) (constVals:ValueRef array) (packed:bool)
let constNamedStruct (structTy:TypeRef) (constVals:ValueRef array) =
use constPtrs = new NativePtrs([|for constVal in constVals -> constVal.Ptr|])
let valCount = uint32 constVals.Length
ValueRef(constNamedStructNative(structTy.Ptr, constPtrs.Ptrs, valCount))
ValueRef(constNamedStructNative(structTy.Ptr, constPtrs.Ptrs, valCount))
Loading

0 comments on commit abb597b

Please sign in to comment.