Skip to content

Commit

Permalink
[SpecsHwUtils] added small lib taken from old specs-hw repo
Browse files Browse the repository at this point in the history
  • Loading branch information
nmcp88 committed Sep 23, 2024
1 parent 095693b commit d8e648d
Show file tree
Hide file tree
Showing 17 changed files with 751 additions and 0 deletions.
38 changes: 38 additions & 0 deletions SpecsHWUtils/resources/pt/up/fe/specs/specshw/SpecsHwResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright 2021 SPeCS.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, 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. under the License.
*/

package pt.up.fe.specs.specshw;

import pt.up.fe.specs.util.providers.ResourceProvider;

public enum SpecsHwResource implements ResourceProvider {

// DOTTY_BINARY("dot"),
GRAPH_HTML_TEMPLATE("pt/up/fe/specs/specshw/graph/graph_template.html"),
VERILATOR_TEMPLATE("pt/up/fe/specs/specshw/hardware/verilator/verilator_testbench_template.cpp"),
VIVADO_TCL_TIMING_VERIFICATION_TEMPLATE(
"pt/up/fe/specs/specshw/hardware/vivado_timing_verification/vivado_tcl_timing_verification_template.tcl"),
SPECS_COPYRIGHT_TEXT("pt/up/fe/specs/specshw/specs_cr_text.txt"),
nullResource(null);

private final String resource;

private SpecsHwResource(String resource) {
this.resource = resource;
}

@Override
public String getResource() {
return resource;
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0; url=<INSERTURL>">
<script type="text/javascript">
window.location.href = "<INSERTURL>"
</script>
<title>Page Redirection</title>
</head>
<body>
<!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->
If you are not redirected automatically, follow this <a href='<INSERTURL>'>link to example</a>.
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html><head><style>
.box {background-color:lightgrey; width:50%;}
</style></head><body>

<h1>Binary Segment Graph Information</h1>

<div class=box><h2>Summary</h2>
Segment type: <SEGMENTTYPE><br>
Number of nodes: <NUMNODES><br>
Number of memory reads: <NUMREADS><br>
Number of memory writes: <NUMWRITES><br>
Maximum ILP of graph (widest row): <MAXILP><br>
Critical Path Length: <CPL><br>
Static Coverage: <STATICCOVERAGE><br>
Dynamic Coverage: <DYNAMICCOVERAGE><br>
Initiation Interval: <INITIATIONINTERVAL><br>
Instructions per clock cycle (ideal): <IPC><br>
Context Count: <NUMCONTEXTS><br>
Total Ocurrences: <OCURRENCES><br>
</div>

<div class=box><h2>Program information</h2>Program name: <APPNAME><br></div>
<div class=box><h3>Compilation information:</h3><COMPILEINFO><br></div>
<div class=box><h2>Segment:</h2><SEGMENT><br></div>
<div class=box><h3>Segment Contexts</h3><CONTEXTS></div>
<div class=box><h2>Segment Graph:</h2><img src="<IMAGEFILE>"><br></div>
</body>

</html>
<br><footer>&copy; Copyright <THEYEAR> SPeCS<br>Generated by Binary Translation Framework, <GITDESCRIPTION><br>Generation date: <GENERATIONDATE><br>Find the repository at <a href="https://github.com/specs-feup/specs-hw">SPeCS Hardware</a><br>Binary Translation Framework developed at <a href="https://www.inesctec.pt/">INESC TEC</a> (CTM and CSIG) in the <a href="http://specs.fe.up.pt/">SPeCS LabC</a> at UP/FEUP <br><br>Contact the developers:<br><a href="mailto:[email protected]">Dr. Nuno Paulino</a><br><a href="mailto:[email protected]">Dr. João Bispo</a></footer>

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <stdlib.h>
#include <iostream>
#include <verilated.h>
#include <verilated_vcd_c.h>

#include "V<TESTBENCHNAME>.h"

#define VALIDATION_SAMPLES <NUMBEROFSAMPLES>
#define VERIFICATION_FAIL 0
#define VERIFICATION_OK 1

int main(int argc, char **argv)
{
V<TESTBENCHNAME> *tb = new V<TESTBENCHNAME>;

for(int i = VALIDATION_SAMPLES; i > 0; i--){

tb->verify = 1;

for(int w = 0; w < 100; w++)
tb->eval();

tb->verify = 0;
tb->eval();

if(tb->verifyResults == VERIFICATION_FAIL) {
delete tb;
std::cout << "FAILED\n";
exit(EXIT_SUCCESS);
}

}

delete tb;
std::cout << "PASSED\n";

exit(EXIT_SUCCESS);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set outputDir ../reports
set moduleName <MODULE_NAME>

read_verilog [glob ../hdl/*.sv]

set device2test xcau25p-ffvb676-1-e
synth_design -top $moduleName -name $moduleName -part $device2test
report_timing -file $outputDir/timing_$device2test.rpt
report_power -file $outputDir/power_$device2test.rpt
report_utilization -file $outputDir/utilization_$device2test.rpt

set device2test xc7s6cpga196-1
synth_design -top $moduleName -name $moduleName -part $device2test
report_timing -file $outputDir/timing_$device2test.rpt
report_power -file $outputDir/power_$device2test.rpt
report_utilization -file $outputDir/utilization_$device2test.rpt

exit
12 changes: 12 additions & 0 deletions SpecsHWUtils/resources/pt/up/fe/specs/specshw/specs_cr_text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright <THEYEAR> SPeCS.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, 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. under the License.
*/
154 changes: 154 additions & 0 deletions SpecsHWUtils/src/pt/up/fe/specs/specshw/SpecsHwUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/**
* Copyright 2021 SPeCS.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, 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. under the License.
*/

package pt.up.fe.specs.specshw;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.time.LocalDateTime;
import java.util.Arrays;

import pt.up.fe.specs.util.utilities.Replacer;

public class SpecsHwUtils {

/*
*
*/
public static Process newProcess(ProcessBuilder builder) {

// start gdb
Process proc = null;
try {
builder.directory(new File("."));
builder.redirectErrorStream(true); // redirects stderr to stdout
proc = builder.start();

} catch (IOException e) {
throw new RuntimeException("Could not run process: " + builder.command());
}

return proc;
}

/*
*
*/
private static BufferedReader getOutputStreamReader(ProcessBuilder pb) {

// call program
Process proc = null;
try {
pb.directory(new File("."));
pb.redirectErrorStream(true); // redirects stderr to stdout
proc = pb.start();

} catch (IOException e) {
throw new RuntimeException("Could not run process bin with name: " + pb.command());
}

try {
proc.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
return reader;
}

/*
*
*/
private static String getSingleOutputLine(ProcessBuilder pb) {

String output = null;
BufferedReader reader = getOutputStreamReader(pb);
try {
output = reader.readLine();
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return output;
}

/*
*
*/
private static String getAllOutput(ProcessBuilder pb) {

String output = "";
BufferedReader reader = getOutputStreamReader(pb);
try {
while (reader.ready())
output += reader.readLine() + "\n";
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return output;
}

/*
* Gets "git describe" result for .. which project?? (could be BinaryTranslation, MicroBlaze...)
*/
public static String getCommitDescription() {

// call git describe
var arguments = Arrays.asList("git", "describe");
var pb = new ProcessBuilder(arguments);
return SpecsHwUtils.getSingleOutputLine(pb);
}

/*
* Get contact info and github repo stuff
*/
public static String getContactInfo() {
var info = new StringBuilder();
info.append("Available on GitHub at https://github.com/specs-feup/specs-hw\n");
info.append("Contacts:\n\tNuno Paulino ([email protected])\n\tJoão Bispo ([email protected])");
return info.toString();
}

/*
* Get SPeCS copyright text with current year
*/
public static String getSPeCSCopyright() {
var crtext = SpecsHwResource.SPECS_COPYRIGHT_TEXT;
var crreplacer = new Replacer(crtext);
crreplacer.replace("<THEYEAR>", LocalDateTime.now().getYear());
return crreplacer.toString();
}

/*
* Helper
*/
public static String generateFileHeader() {

var commentText = new StringBuilder();
commentText.append(SpecsHwUtils.getSPeCSCopyright() + "\n\n");
commentText.append("Generated using CrispyHDL "
+ "(a part of the specs-hw GitHub Repo " + SpecsHwUtils.getCommitDescription() + ")\n");
commentText.append(SpecsHwUtils.getContactInfo());
return commentText.toString();

}
}
Loading

0 comments on commit d8e648d

Please sign in to comment.