Skip to content

Commit

Permalink
Bus access changes
Browse files Browse the repository at this point in the history
  • Loading branch information
donn committed Jan 11, 2024
1 parent 9654cd9 commit 308bca8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMajor(from: "1.0.0")),
.package(url: "https://github.com/pvieito/PythonKit", .branch("master")),
.package(url: "https://github.com/pvieito/CommandLineKit", .branch("master")),
Expand Down
16 changes: 10 additions & 6 deletions Sources/Fault/Entries/asm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import BigInt
import CommandLineKit
import Defile
import Foundation
import PythonKit

func assemble(arguments: [String]) -> Int32 {
let cli = CommandLineKit.CommandLine(arguments: arguments)
Expand Down Expand Up @@ -75,16 +74,22 @@ func assemble(arguments: [String]) -> Int32 {
let vectorOutput = filePath.value ?? "\(json).vec.bin"
let goldenOutput = goldenFilePath.value ?? "\(json).out.bin"

guard let jsonString = File.read(json) else {
Stderr.print("Could not read file '\(json)'")
return EX_NOINPUT
print("Loading JSON data…")
let start = DispatchTime.now()
guard let data = try? Data(contentsOf: URL(fileURLWithPath: json)) else {
Stderr.print("Failed to open test vector JSON file.")
return EX_DATAERR
}

let decoder = JSONDecoder()
guard let tvinfo = try? decoder.decode(TVInfo.self, from: jsonString.data(using: .utf8)!) else {
guard let tvinfo = try? decoder.decode(TVInfo.self, from: data) else {
Stderr.print("Test vector json file is invalid.")
return EX_DATAERR
}
let end = DispatchTime.now()
let nanoTime = end.uptimeNanoseconds - start.uptimeNanoseconds
let timeInterval = Double(nanoTime) / 1_000_000_000
print("Loaded JSON data in \(timeInterval)s.")

let (chain, _, _) = ChainMetadata.extract(file: netlist)

Expand Down Expand Up @@ -193,7 +198,6 @@ func assemble(arguments: [String]) -> Int32 {
} else {
if element.kind == .bypassOutput {
outputBinary += String(repeating: "x", count: element.width)
print("Output is same as the loaded TV")
} else {
print("[Error]: Mismatch between output port \(element.name) and chained netlist.")
return EX_DATAERR
Expand Down
10 changes: 5 additions & 5 deletions Sources/Fault/Entries/cut.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ func cut(arguments: [String]) -> Int32 {
let instanceName = "\(instance.name)"
if let dffinfo = getMatchingDFFInfo(from: sclConfig.dffMatches, for: moduleName, fnmatch: fnmatch) {
yank = true

let moduleName = String(describing: instance.name)
let outputName = "\\" + moduleName + ".q"

let inputIdentifier = Node.Identifier(moduleName)
let outputIdentifier = Node.Identifier(outputName)

var dArg: PythonObject?
var qArg: PythonObject?

Expand Down Expand Up @@ -214,13 +214,13 @@ func cut(arguments: [String]) -> Int32 {

for hook in instance.portlist {
let portName = String(describing: hook.portname)

if ignoredInputs.contains(portName) {
continue
}

let portInfo = blackboxModule.portsByName[portName]!

let ioDeclaration: PythonObject
let assignStatement: PythonObject
var ioName: String = "\\\(instanceName).\(portName)"
Expand Down
2 changes: 1 addition & 1 deletion Sources/Fault/Entries/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func main(arguments: [String]) -> Int32 {
let minimum = min(port.from, port.to)
let maximum = max(port.from, port.to)
for i in minimum ... maximum {
faultPoints.insert("\(port.name)[\(i)]")
faultPoints.insert("\(port.name) [\(i)]")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Fault/Module.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Collections
// Copyright (C) 2019 The American University in Cairo
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,10 +11,11 @@ import Collections
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Collections
import Defile
import Foundation
import PythonKit
import Collections

struct Port: Codable {
enum Polarity: String, Codable {
Expand Down
14 changes: 6 additions & 8 deletions Sources/Fault/Simulation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ enum Simulator {
outputComparison += " ( \(name) != \(name).gm ) || "
if output.width > 1 {
for i in 0 ..< output.width {
outputAssignment += " assign goldenOutput[\(outputCount)] = gm.\(output.name)[\(i)] ; \n"
outputAssignment += " assign goldenOutput[\(outputCount)] = gm.\(output.name) [\(i)] ; \n"
outputCount += 1
}
} else {
Expand Down Expand Up @@ -838,10 +838,10 @@ enum Simulator {
try File.open(output, mode: .write) {
try $0.print(bench)
}

let outputLog = "\(output).log"
print("Starting simulation steps (log: \(outputLog))…")

guard let outputFile = File.open(outputLog, mode: .write) else {
throw RuntimeError("Failed to open log file.")
}
Expand All @@ -852,24 +852,22 @@ enum Simulator {
let _ = "rm \(aoutName)".sh()
}
}
let iverilogCmd = "'\(iverilogExecutable)' -B '\(iverilogBase)' \(define) -Ttyp -o \(aoutName) \(output) 2>&1";
let iverilogCmd = "'\(iverilogExecutable)' -B '\(iverilogBase)' \(define) -Ttyp -o \(aoutName) \(output) 2>&1"
try outputFile.write(string: "$ \(iverilogCmd)\n")

let iverilogResult =
"'\(iverilogExecutable)' -B '\(iverilogBase)' \(define) -Ttyp -o \(aoutName) \(output) 2>&1".shOutput()
try outputFile.write(string: iverilogResult.output)


if iverilogResult.terminationStatus != EX_OK {
throw RuntimeError("Failed to run iverilog.")
}

let vvpCmd = "'\(vvpExecutable)' \(aoutName)"
try outputFile.write(string: "$ \(vvpCmd)\n")
let vvpResult = vvpCmd.shOutput()
try outputFile.write(string: vvpResult.output)


if iverilogResult.terminationStatus != EX_OK {
throw RuntimeError("Failed to run vvp.")
}
Expand Down

0 comments on commit 308bca8

Please sign in to comment.