Skip to content

Commit

Permalink
Exploring Interesting Avenues
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyus committed Aug 12, 2017
1 parent ee60491 commit eb647be
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Swiftlog/Procedure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class Procedure
let pointers = self.name.cPointer
self.cNameSize = pointers.elementCount
self.cNamePointer = pointers.mutable
self.store.tfname = pointers.literal
self.store.tfname = pointers.cLiteral

self.store.type = PLI_INT32(self.type.rawValue)
self.store.compiletf = {
Expand Down
7 changes: 4 additions & 3 deletions Swiftlog/Swiftlog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ func startup()
//Register Function "$hello_world"
var helloWorld = s_vpi_systf_data()
helloWorld.type = vpiSysTask
helloWorld.tfname = "$hello_world".cPointer.literal
helloWorld.tfname = "$hello_world".cPointer.cLiteral
helloWorld.calltf = {
(user_data: UnsafeMutablePointer<Int8>?) -> Int32 in
print(user_data?.pointee)
print("...and Hello from Swift!")
return 0
}
Expand All @@ -23,13 +24,13 @@ func startup()
return 0
}
helloWorld.sizetf = nil
helloWorld.user_data = nil
helloWorld.user_data = "scrambld, egge".cPointer.cMutable
vpi_register_systf(&helloWorld);

//Register Function "$hello_world"
var showResult = s_vpi_systf_data();
showResult.type = vpiSysTask
showResult.tfname = "$show_result".cPointer.literal
showResult.tfname = "$show_result".cPointer.cLiteral
showResult.compiletf =
{
(user_data: UnsafeMutablePointer<Int8>?) -> Int32 in
Expand Down
5 changes: 3 additions & 2 deletions Swiftlog/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ class Control

extension String
{
var cPointer: (literal: UnsafePointer<CChar>, mutable: UnsafeMutablePointer<UInt8>, elementCount: Int)
var cPointer: (cLiteral: UnsafePointer<CChar>, cMutable: UnsafeMutablePointer<CChar>, mutable: UnsafeMutablePointer<UInt8>, elementCount: Int)
{
let utf8Representation = Array(self.utf8)
let mutablePointer = UnsafeMutablePointer<UInt8>.allocate(capacity: utf8Representation.count)
let cMutablePointer = UnsafeMutableRawPointer(mutablePointer).bindMemory(to: CChar.self, capacity: utf8Representation.count)
let immutablePointer = UnsafeRawPointer(mutablePointer).bindMemory(to: CChar.self, capacity: utf8Representation.count)
let _ = UnsafeMutableBufferPointer<UInt8>(start: mutablePointer, count: utf8Representation.count).initialize(from: utf8Representation)
return (literal: immutablePointer, mutable: mutablePointer, elementCount: utf8Representation.count)
return (cLiteral: immutablePointer, cMutable: cMutablePointer, mutable: mutablePointer, elementCount: utf8Representation.count)
}
}

0 comments on commit eb647be

Please sign in to comment.