fix sonarlint issues, add IDerivedWaveform interface
This commit is contained in:
parent
b2e269b67c
commit
6c5032da10
|
@ -13,7 +13,6 @@ package com.minres.scviewer.database.sqlite;
|
|||
import java.beans.IntrospectionException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.SQLException;
|
||||
|
@ -24,6 +23,7 @@ import java.util.List;
|
|||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.sqlite.db.IDatabase;
|
||||
import com.minres.scviewer.database.sqlite.db.SQLiteDatabase;
|
||||
|
@ -42,16 +42,13 @@ public class SQLiteDbLoader implements IWaveformDbLoader {
|
|||
|
||||
private ScvSimProps scvSimProps;
|
||||
|
||||
public SQLiteDbLoader() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getMaxTime() {
|
||||
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<ScvTxEvent>(ScvTxEvent.class,
|
||||
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<>(ScvTxEvent.class,
|
||||
database, "time = (SELECT MAX(time) FROM ScvTxEvent)");
|
||||
try {
|
||||
List<ScvTxEvent> event = handler.selectObjects();
|
||||
if(event.size()>0)
|
||||
if(!event.isEmpty())
|
||||
return event.get(0).getTime()*scvSimProps.getTime_resolution();
|
||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||
|
@ -62,8 +59,8 @@ public class SQLiteDbLoader implements IWaveformDbLoader {
|
|||
|
||||
@Override
|
||||
public Collection<IWaveform> getAllWaves() {
|
||||
SQLiteDatabaseSelectHandler<ScvStream> handler = new SQLiteDatabaseSelectHandler<ScvStream>(ScvStream.class, database);
|
||||
List<IWaveform> streams=new ArrayList<IWaveform>();
|
||||
SQLiteDatabaseSelectHandler<ScvStream> handler = new SQLiteDatabaseSelectHandler<>(ScvStream.class, database);
|
||||
List<IWaveform> streams=new ArrayList<>();
|
||||
try {
|
||||
for(ScvStream scvStream:handler.selectObjects()){
|
||||
TxStream stream = new TxStream(database, db, scvStream);
|
||||
|
@ -72,7 +69,6 @@ public class SQLiteDbLoader implements IWaveformDbLoader {
|
|||
}
|
||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
return streams;
|
||||
}
|
||||
|
@ -80,25 +76,21 @@ public class SQLiteDbLoader implements IWaveformDbLoader {
|
|||
private byte[] x = "SQLite format 3".getBytes();
|
||||
|
||||
@Override
|
||||
public boolean load(IWaveformDb db, File file) throws Exception {
|
||||
public boolean load(IWaveformDb db, File file) throws InputFormatException {
|
||||
if(file.isDirectory() || !file.exists()) return false;
|
||||
this.db=db;
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
try(FileInputStream fis = new FileInputStream(file)) {
|
||||
byte[] buffer = new byte[x.length];
|
||||
int read = fis.read(buffer, 0, x.length);
|
||||
fis.close();
|
||||
if (read == x.length)
|
||||
for (int i = 0; i < x.length; i++)
|
||||
if (buffer[i] != x[i]) return false;
|
||||
} catch(FileNotFoundException e) {
|
||||
return false;
|
||||
} catch(IOException e) { //if an I/O error occurs
|
||||
} catch(IOException e) {
|
||||
return false;
|
||||
}
|
||||
database=new SQLiteDatabase(file.getAbsolutePath());
|
||||
database.setData("TIMERESOLUTION", 1L);
|
||||
SQLiteDatabaseSelectHandler<ScvSimProps> handler = new SQLiteDatabaseSelectHandler<ScvSimProps>(ScvSimProps.class, database);
|
||||
SQLiteDatabaseSelectHandler<ScvSimProps> handler = new SQLiteDatabaseSelectHandler<>(ScvSimProps.class, database);
|
||||
try {
|
||||
for(ScvSimProps simProps:handler.selectObjects()){
|
||||
scvSimProps=simProps;
|
||||
|
|
|
@ -38,8 +38,10 @@ public class Tx implements ITx {
|
|||
private TxGenerator trGenerator;
|
||||
private ScvTx scvTx;
|
||||
private List<ITxAttribute> attributes;
|
||||
private Long begin, end;
|
||||
private List<ITxRelation> incoming, outgoing;
|
||||
private Long begin;
|
||||
private Long end;
|
||||
private List<ITxRelation> incoming;
|
||||
private List<ITxRelation> outgoing;
|
||||
|
||||
public Tx(IDatabase database, TxStream trStream, TxGenerator trGenerator, ScvTx scvTx) {
|
||||
this.database=database;
|
||||
|
@ -71,7 +73,7 @@ public class Tx implements ITx {
|
|||
@Override
|
||||
public Long getBeginTime() {
|
||||
if(begin==null){
|
||||
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<ScvTxEvent>(ScvTxEvent.class,
|
||||
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<>(ScvTxEvent.class,
|
||||
database, "tx="+scvTx.getId()+" AND type="+ AssociationType.BEGIN.ordinal());
|
||||
try {
|
||||
for(ScvTxEvent scvEvent:handler.selectObjects()){
|
||||
|
@ -87,7 +89,7 @@ public class Tx implements ITx {
|
|||
@Override
|
||||
public Long getEndTime() {
|
||||
if(end==null){
|
||||
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<ScvTxEvent>(ScvTxEvent.class,
|
||||
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<>(ScvTxEvent.class,
|
||||
database, "tx="+scvTx.getId()+" AND type="+ AssociationType.END.ordinal());
|
||||
try {
|
||||
for(ScvTxEvent scvEvent:handler.selectObjects()){
|
||||
|
@ -103,10 +105,10 @@ public class Tx implements ITx {
|
|||
@Override
|
||||
public List<ITxAttribute> getAttributes() {
|
||||
if(attributes==null){
|
||||
SQLiteDatabaseSelectHandler<ScvTxAttribute> handler = new SQLiteDatabaseSelectHandler<ScvTxAttribute>(
|
||||
SQLiteDatabaseSelectHandler<ScvTxAttribute> handler = new SQLiteDatabaseSelectHandler<>(
|
||||
ScvTxAttribute.class, database, "tx="+scvTx.getId());
|
||||
try {
|
||||
attributes = new ArrayList<ITxAttribute>();
|
||||
attributes = new ArrayList<>();
|
||||
for(ScvTxAttribute scvAttribute:handler.selectObjects()){
|
||||
attributes.add(new TxAttribute(this, scvAttribute));
|
||||
|
||||
|
@ -121,10 +123,10 @@ public class Tx implements ITx {
|
|||
@Override
|
||||
public Collection<ITxRelation> getIncomingRelations() {
|
||||
if(incoming==null){
|
||||
SQLiteDatabaseSelectHandler<ScvTxRelation> handler = new SQLiteDatabaseSelectHandler<ScvTxRelation>(
|
||||
SQLiteDatabaseSelectHandler<ScvTxRelation> handler = new SQLiteDatabaseSelectHandler<>(
|
||||
ScvTxRelation.class, database, "sink="+scvTx.getId());
|
||||
try {
|
||||
incoming = new ArrayList<ITxRelation>();
|
||||
incoming = new ArrayList<>();
|
||||
for(ScvTxRelation scvRelation:handler.selectObjects()){
|
||||
incoming.add(createRelation(scvRelation, false));
|
||||
}
|
||||
|
@ -138,10 +140,10 @@ public class Tx implements ITx {
|
|||
@Override
|
||||
public Collection<ITxRelation> getOutgoingRelations() {
|
||||
if(outgoing==null){
|
||||
SQLiteDatabaseSelectHandler<ScvTxRelation> handler = new SQLiteDatabaseSelectHandler<ScvTxRelation>(
|
||||
SQLiteDatabaseSelectHandler<ScvTxRelation> handler = new SQLiteDatabaseSelectHandler<>(
|
||||
ScvTxRelation.class, database, "src="+scvTx.getId());
|
||||
try {
|
||||
outgoing = new ArrayList<ITxRelation>();
|
||||
outgoing = new ArrayList<>();
|
||||
for(ScvTxRelation scvRelation:handler.selectObjects()){
|
||||
outgoing.add(createRelation(scvRelation, true));
|
||||
}
|
||||
|
@ -154,7 +156,7 @@ public class Tx implements ITx {
|
|||
|
||||
private ITxRelation createRelation(ScvTxRelation rel, boolean outgoing) {
|
||||
int otherId = outgoing?rel.getSink():rel.getSrc();
|
||||
SQLiteDatabaseSelectHandler<ScvTx> handler = new SQLiteDatabaseSelectHandler<ScvTx>(ScvTx.class, database,
|
||||
SQLiteDatabaseSelectHandler<ScvTx> handler = new SQLiteDatabaseSelectHandler<>(ScvTx.class, database,
|
||||
"id="+otherId);
|
||||
try {
|
||||
List<ScvTx> res = handler.selectObjects();
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.sqlite;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
|
@ -45,7 +46,7 @@ public class TxGenerator implements ITxGenerator {
|
|||
|
||||
@Override
|
||||
public List<ITx> getTransactions() {
|
||||
return null;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,8 @@ import com.minres.scviewer.database.tx.ITxRelation;
|
|||
public class TxRelation implements ITxRelation {
|
||||
|
||||
RelationType relationType;
|
||||
Tx source, target;
|
||||
Tx source;
|
||||
Tx target;
|
||||
|
||||
public TxRelation(RelationType relationType, Tx source, Tx target) {
|
||||
this.source = source;
|
||||
|
|
|
@ -80,9 +80,9 @@ public class TxStream extends HierNode implements IWaveform {
|
|||
|
||||
public List<ITxGenerator> getGenerators() {
|
||||
if(generators==null){
|
||||
SQLiteDatabaseSelectHandler<ScvGenerator> handler = new SQLiteDatabaseSelectHandler<ScvGenerator>(
|
||||
SQLiteDatabaseSelectHandler<ScvGenerator> handler = new SQLiteDatabaseSelectHandler<>(
|
||||
ScvGenerator.class, database, "stream="+scvStream.getId());
|
||||
generators=new TreeMap<Integer, TxGenerator>();
|
||||
generators=new TreeMap<>();
|
||||
try {
|
||||
for(ScvGenerator scvGenerator:handler.selectObjects()){
|
||||
generators.put(scvGenerator.getId(), new TxGenerator(this, scvGenerator));
|
||||
|
@ -92,22 +92,20 @@ public class TxStream extends HierNode implements IWaveform {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return new ArrayList<ITxGenerator>(generators.values());
|
||||
return new ArrayList<>(generators.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
if(maxConcurrency==null){
|
||||
java.sql.Connection connection=null;
|
||||
java.sql.Statement statement=null;
|
||||
java.sql.ResultSet resultSet=null;
|
||||
try {
|
||||
connection = database.createConnection();
|
||||
statement = connection.createStatement();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("SELECT MAX(concurrencyLevel) as concurrencyLevel FROM ScvTx where stream=");
|
||||
sb.append(scvStream.getId());
|
||||
resultSet = statement.executeQuery(sb.toString());
|
||||
try(
|
||||
java.sql.Connection connection = database.createConnection();
|
||||
java.sql.Statement statement = connection.createStatement();
|
||||
java.sql.ResultSet resultSet = statement.executeQuery(sb.toString());
|
||||
) {
|
||||
while (resultSet.next()) {
|
||||
if(maxConcurrency==null) maxConcurrency=0;
|
||||
Object value = resultSet.getObject("concurrencyLevel");
|
||||
|
@ -116,12 +114,6 @@ public class TxStream extends HierNode implements IWaveform {
|
|||
}
|
||||
} catch (SQLException e) {
|
||||
if(maxConcurrency==null) maxConcurrency=0;
|
||||
} finally {
|
||||
try{
|
||||
if(resultSet!=null) resultSet.close();
|
||||
if(statement!=null) statement.close();
|
||||
if(connection!=null) connection.close();
|
||||
} catch (SQLException e) { }
|
||||
}
|
||||
maxConcurrency+=1;
|
||||
}
|
||||
|
@ -131,7 +123,7 @@ public class TxStream extends HierNode implements IWaveform {
|
|||
@Override
|
||||
public NavigableMap<Long, IEvent[]> getEvents(){
|
||||
if(events==null){
|
||||
events=new TreeMap<Long, IEvent[]>();
|
||||
events=new TreeMap<>();
|
||||
for(Entry<Integer, ITx> entry:getTransactions().entrySet()){
|
||||
putEvent(new TxEvent(EventKind.BEGIN, entry.getValue()));
|
||||
putEvent(new TxEvent(EventKind.END, entry.getValue()));
|
||||
|
@ -156,8 +148,8 @@ public class TxStream extends HierNode implements IWaveform {
|
|||
protected Map<Integer, ITx> getTransactions() {
|
||||
if(transactions==null){
|
||||
if(generators==null) getGenerators();
|
||||
transactions = new TreeMap<Integer, ITx>();
|
||||
SQLiteDatabaseSelectHandler<ScvTx> handler = new SQLiteDatabaseSelectHandler<ScvTx>(ScvTx.class, database,
|
||||
transactions = new TreeMap<>();
|
||||
SQLiteDatabaseSelectHandler<ScvTx> handler = new SQLiteDatabaseSelectHandler<>(ScvTx.class, database,
|
||||
"stream="+scvStream.getId());
|
||||
try {
|
||||
for(ScvTx scvTx:handler.selectObjects()){
|
||||
|
@ -187,7 +179,7 @@ public class TxStream extends HierNode implements IWaveform {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean equals(IWaveform other) {
|
||||
public boolean isSame(IWaveform other) {
|
||||
return(other instanceof TxStream && this.getId().equals(other.getId()));
|
||||
}
|
||||
|
||||
|
@ -195,7 +187,7 @@ public class TxStream extends HierNode implements IWaveform {
|
|||
public IEvent[] getEventsBeforeTime(Long time) {
|
||||
Entry<Long, IEvent[]> e = events.floorEntry(time);
|
||||
if(e==null)
|
||||
return null;
|
||||
return new IEvent[]{};
|
||||
else
|
||||
return events.floorEntry(time).getValue();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.minres.scviewer.database.DataType
|
|||
import com.minres.scviewer.database.IWaveform
|
||||
import com.minres.scviewer.database.IWaveformDb
|
||||
import com.minres.scviewer.database.IWaveformDbLoader
|
||||
import com.minres.scviewer.database.InputFormatException
|
||||
import com.minres.scviewer.database.RelationType
|
||||
import com.minres.scviewer.database.tx.ITxGenerator
|
||||
|
||||
|
@ -62,7 +63,7 @@ public class TextDbLoader implements IWaveformDbLoader{
|
|||
static final byte[] x = "scv_tr_stream".bytes
|
||||
|
||||
@Override
|
||||
boolean load(IWaveformDb db, File file) throws Exception {
|
||||
boolean load(IWaveformDb db, File file) throws InputFormatException {
|
||||
if(file.isDirectory() || !file.exists()) return false;
|
||||
this.db=db
|
||||
this.streams=[]
|
||||
|
|
|
@ -33,11 +33,6 @@ class TxEvent implements ITxEvent {
|
|||
return new TxEvent(kind, transaction, time);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// int compareTo(IWaveformEvent o) {
|
||||
// time.compareTo(o.time)
|
||||
// }
|
||||
|
||||
@Override
|
||||
public
|
||||
String toString() {
|
||||
|
|
|
@ -114,7 +114,7 @@ class TxStream extends HierNode implements IWaveform {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean equals(IWaveform other) {
|
||||
public boolean isSame(IWaveform other) {
|
||||
return(other instanceof TxStream && this.getId()==other.getId());
|
||||
}
|
||||
|
||||
|
|
|
@ -1184,7 +1184,7 @@ public class WaveformView implements IWaveformView {
|
|||
|
||||
public TrackEntry getEntryForStream(IWaveform source) {
|
||||
for(TrackEntry trackEntry:streams)
|
||||
if(trackEntry.waveform.equals(source)) return trackEntry;
|
||||
if(trackEntry.waveform.isSame(source)) return trackEntry;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,11 +14,11 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.Stack;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Vector;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
@ -39,13 +39,13 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
|||
|
||||
|
||||
/** The Constant TIME_RES. */
|
||||
private static final Long TIME_RES = 1000L; // ps;
|
||||
private static final Long TIME_RES = 1000L; // ps
|
||||
|
||||
/** The db. */
|
||||
private IWaveformDb db;
|
||||
|
||||
/** The module stack. */
|
||||
private Stack<String> moduleStack;
|
||||
private ArrayDeque<String> moduleStack;
|
||||
|
||||
/** The signals. */
|
||||
private List<IWaveform> signals;
|
||||
|
@ -53,23 +53,14 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
|||
/** The max time. */
|
||||
private long maxTime;
|
||||
|
||||
/**
|
||||
* Instantiates a new VCD db.
|
||||
*/
|
||||
public VCDDbLoader() {
|
||||
}
|
||||
|
||||
private static boolean isGzipped(File f) {
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(f);
|
||||
try (InputStream is = new FileInputStream(f)) {
|
||||
byte [] signature = new byte[2];
|
||||
int nread = is.read( signature ); //read the gzip signature
|
||||
return nread == 2 && signature[ 0 ] == (byte) 0x1f && signature[ 1 ] == (byte) 0x8b;
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e) {
|
||||
return false;
|
||||
} finally {
|
||||
try { is.close();} catch (IOException e) { }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,21 +70,27 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean load(IWaveformDb db, File file) throws Exception {
|
||||
public boolean load(IWaveformDb db, File file) throws InputFormatException {
|
||||
if(file.isDirectory() || !file.exists()) return false;
|
||||
this.db=db;
|
||||
this.maxTime=0;
|
||||
boolean res = false;
|
||||
try {
|
||||
String name = file.getCanonicalFile().getName();
|
||||
if(!(name.endsWith(".vcd") ||
|
||||
name.endsWith(".vcdz") ||
|
||||
name.endsWith(".vcdgz") ||
|
||||
name.endsWith(".vcd.gz")) )
|
||||
return false;
|
||||
signals = new Vector<IWaveform>();
|
||||
moduleStack= new Stack<String>();
|
||||
signals = new Vector<>();
|
||||
moduleStack= new ArrayDeque<>();
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
boolean res = new VCDFileParser(false).load(isGzipped(file)?new GZIPInputStream(fis):fis, this);
|
||||
res = new VCDFileParser(false).load(isGzipped(file)?new GZIPInputStream(fis):fis, this);
|
||||
moduleStack=null;
|
||||
} catch(IOException e) {
|
||||
moduleStack=null;
|
||||
throw new InputFormatException();
|
||||
}
|
||||
if(!res) throw new InputFormatException();
|
||||
// calculate max time of database
|
||||
for(IWaveform waveform:signals) {
|
||||
|
@ -159,9 +156,8 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Integer newNet(String name, int i, int width) {
|
||||
String netName = moduleStack.empty()? name: moduleStack.lastElement()+"."+name;
|
||||
String netName = moduleStack.isEmpty()? name: moduleStack.peek()+"."+name;
|
||||
int id = signals.size();
|
||||
assert(width>=0);
|
||||
if(width==0) {
|
||||
signals.add( i<0 ? new VCDSignal<DoubleVal>(db, id, netName, width) :
|
||||
new VCDSignal<DoubleVal>((VCDSignal<DoubleVal>)signals.get(i), id, netName));
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package com.minres.scviewer.database.vcd;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
|
||||
import com.minres.scviewer.database.BitValue;
|
||||
|
@ -19,7 +20,7 @@ import com.minres.scviewer.database.BitVector;
|
|||
class VCDFileParser {
|
||||
private StreamTokenizer tokenizer;
|
||||
private IVCDDatabaseBuilder traceBuilder;
|
||||
private HashMap<String, Integer> nameToNetMap = new HashMap<String, Integer>();
|
||||
private HashMap<String, Integer> nameToNetMap = new HashMap<>();
|
||||
private long picoSecondsPerIncrement;
|
||||
private boolean stripNetWidth;
|
||||
private boolean replaceColon;
|
||||
|
@ -50,19 +51,19 @@ class VCDFileParser {
|
|||
}
|
||||
}
|
||||
|
||||
private void parseScope() throws Exception {
|
||||
private void parseScope() throws IOException, ParseException {
|
||||
nextToken(); // Scope type (ignore)
|
||||
nextToken();
|
||||
traceBuilder.enterModule(tokenizer.sval);
|
||||
match("$end");
|
||||
}
|
||||
|
||||
private void parseUpscope() throws Exception {
|
||||
private void parseUpscope() throws IOException, ParseException {
|
||||
match("$end");
|
||||
traceBuilder.exitModule();
|
||||
}
|
||||
|
||||
private void parseVar() throws Exception {
|
||||
private void parseVar() throws IOException {
|
||||
nextToken(); // type
|
||||
String type = tokenizer.sval;
|
||||
nextToken(); // size
|
||||
|
@ -72,11 +73,12 @@ class VCDFileParser {
|
|||
nextToken();
|
||||
String id = tokenizer.sval;
|
||||
nextToken();
|
||||
String netName = tokenizer.sval;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(tokenizer.sval);
|
||||
while (nextToken() && !tokenizer.sval.equals("$end")) {
|
||||
netName+=tokenizer.sval;
|
||||
sb.append(tokenizer.sval);
|
||||
}
|
||||
|
||||
String netName = sb.toString();
|
||||
Integer net = nameToNetMap.get(id);
|
||||
if (net == null) { // We've never seen this net before
|
||||
int openBracket = netName.indexOf('[');
|
||||
|
@ -86,9 +88,9 @@ class VCDFileParser {
|
|||
}
|
||||
if(replaceColon) {
|
||||
if (openBracket != -1) {
|
||||
netName = netName.substring(0, openBracket).replaceAll(":", ".")+netName.substring(openBracket);
|
||||
netName = netName.substring(0, openBracket).replace(":", ".")+netName.substring(openBracket);
|
||||
} else
|
||||
netName=netName.replaceAll(":", ".");
|
||||
netName=netName.replace(":", ".");
|
||||
}
|
||||
nameToNetMap.put(id, traceBuilder.newNet(netName, -1, width));
|
||||
} else {
|
||||
|
@ -97,25 +99,28 @@ class VCDFileParser {
|
|||
}
|
||||
}
|
||||
|
||||
private void parseComment() throws Exception {
|
||||
private void parseComment() throws IOException {
|
||||
nextToken();
|
||||
String s = tokenizer.sval;
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(tokenizer.sval);
|
||||
nextToken();
|
||||
while(!tokenizer.sval.equals("$end")){
|
||||
s+=" "+tokenizer.sval;
|
||||
s.append(" ").append(tokenizer.sval);
|
||||
nextToken();
|
||||
}
|
||||
replaceColon|=s.contains("ARTERIS Architecture");
|
||||
replaceColon|=s.toString().contains("ARTERIS Architecture");
|
||||
}
|
||||
|
||||
private void parseTimescale() throws Exception {
|
||||
private void parseTimescale() throws IOException {
|
||||
nextToken();
|
||||
String s = tokenizer.sval;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(tokenizer.sval);
|
||||
nextToken();
|
||||
while(!tokenizer.sval.equals("$end")){
|
||||
s+=" "+tokenizer.sval;
|
||||
sb.append(" ").append(tokenizer.sval);
|
||||
nextToken();
|
||||
}
|
||||
String s = sb.toString();
|
||||
switch (s.charAt(s.length() - 2)){
|
||||
case 'p': // Nano-seconds
|
||||
picoSecondsPerIncrement = 1;
|
||||
|
@ -141,7 +146,7 @@ class VCDFileParser {
|
|||
picoSecondsPerIncrement *= Long.parseLong(s);
|
||||
}
|
||||
|
||||
private boolean parseDefinition() throws Exception {
|
||||
private boolean parseDefinition() throws IOException, ParseException {
|
||||
nextToken();
|
||||
if (tokenizer.sval.equals("$scope"))
|
||||
parseScope();
|
||||
|
@ -166,7 +171,7 @@ class VCDFileParser {
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean parseTransition() throws Exception {
|
||||
private boolean parseTransition() throws IOException {
|
||||
if (!nextToken()) return false;
|
||||
if (tokenizer.sval.charAt(0) == '#') { // If the line begins with a #, this is a timestamp.
|
||||
currentTime = Long.parseLong(tokenizer.sval.substring(1)) * picoSecondsPerIncrement;
|
||||
|
@ -179,16 +184,10 @@ class VCDFileParser {
|
|||
}
|
||||
if (tokenizer.sval.equals("$dumpvars") || tokenizer.sval.equals("$end"))
|
||||
return true;
|
||||
String value, id;
|
||||
if (tokenizer.sval.charAt(0) == 'b') {
|
||||
// Multiple value net. Value appears first, followed by space,
|
||||
// then identifier
|
||||
value = tokenizer.sval.substring(1);
|
||||
nextToken();
|
||||
id = tokenizer.sval;
|
||||
}else if (tokenizer.sval.charAt(0) == 'r') {
|
||||
// Multiple value net. Value appears first, followed by space,
|
||||
// then identifier
|
||||
String value;
|
||||
String id;
|
||||
if (tokenizer.sval.charAt(0) == 'b' || tokenizer.sval.charAt(0) == 'r') {
|
||||
// Multiple value net. Value appears first, followed by space, then identifier
|
||||
value = tokenizer.sval.substring(1);
|
||||
nextToken();
|
||||
id = tokenizer.sval;
|
||||
|
@ -199,10 +198,8 @@ class VCDFileParser {
|
|||
}
|
||||
|
||||
Integer net = nameToNetMap.get(id);
|
||||
if (net == null) {
|
||||
System.out.println("unknown net " + id + " value " + value);
|
||||
if (net == null)
|
||||
return true;
|
||||
}
|
||||
|
||||
int netWidth = traceBuilder.getNetWidth(net);
|
||||
if(netWidth==0) {
|
||||
|
@ -253,14 +250,14 @@ class VCDFileParser {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void match(String value) throws Exception {
|
||||
private void match(String value) throws ParseException, IOException {
|
||||
nextToken();
|
||||
if (!tokenizer.sval.equals(value))
|
||||
throw new Exception("Line "+tokenizer.lineno()+": parse error, expected "+value+" got "+tokenizer.sval);
|
||||
throw new ParseException("Line "+tokenizer.lineno()+": parse error, expected "+value+" got "+tokenizer.sval, tokenizer.lineno());
|
||||
}
|
||||
|
||||
private boolean nextToken() throws IOException {
|
||||
return tokenizer.nextToken() != StreamTokenizer.TT_EOF;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -46,18 +46,16 @@ public class VCDSignal<T extends IEvent> extends HierNode implements IWaveform {
|
|||
fullName=name;
|
||||
this.id=id;
|
||||
this.width=width;
|
||||
this.values=new TreeMap<Long, IEvent[]>();
|
||||
this.values=new TreeMap<>();
|
||||
}
|
||||
|
||||
public VCDSignal(VCDSignal<T> other, int id, String name) {
|
||||
public VCDSignal(VCDSignal<T> o, int id, String name) {
|
||||
super(name);
|
||||
fullName=name;
|
||||
this.id=id;
|
||||
assert(other instanceof VCDSignal<?>);
|
||||
VCDSignal<T> o = (VCDSignal<T>)other;
|
||||
this.width=o.width;
|
||||
this.values=o.values;
|
||||
this.db=other.getDb();
|
||||
this.db=o.getDb();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -105,13 +103,13 @@ public class VCDSignal<T extends IEvent> extends HierNode implements IWaveform {
|
|||
public IEvent[] getEventsBeforeTime(Long time) {
|
||||
Entry<Long, IEvent[]> e = values.floorEntry(time);
|
||||
if(e==null)
|
||||
return null;
|
||||
return new IEvent[] {};
|
||||
else
|
||||
return values.floorEntry(time).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean equals(IWaveform other) {
|
||||
public boolean isSame(IWaveform other) {
|
||||
return( other instanceof VCDSignal<?> && this.getId().equals(other.getId()));
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ public class BitVector implements IEvent {
|
|||
for(int i=resWidth-1; i>=0; i--){
|
||||
int digit=0;
|
||||
for(int j=3; j>=0; j--){
|
||||
if((4*i+j)>=value.length) continue;
|
||||
if((4*i+j)<value.length) {
|
||||
BitValue val = BitValue.fromChar(value[4*i+j]);
|
||||
switch(val) {
|
||||
case X:
|
||||
|
@ -90,6 +90,7 @@ public class BitVector implements IEvent {
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
res[i]=Character.forDigit(digit, 16); //((digit < 10) ? '0' + digit : 'a' + digit -10)
|
||||
}
|
||||
return new String(res);
|
||||
|
|
|
@ -25,4 +25,4 @@ public enum DataType {
|
|||
POINTER, // T*
|
||||
ARRAY, // T[N]
|
||||
STRING // string, std::string
|
||||
};
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class HierNode implements IHierNode {
|
|||
protected PropertyChangeSupport pcs;
|
||||
|
||||
public HierNode() {
|
||||
childs = new ArrayList<IHierNode>();
|
||||
childs = new ArrayList<>();
|
||||
pcs=new PropertyChangeSupport(this);
|
||||
}
|
||||
|
||||
|
@ -85,4 +85,9 @@ public class HierNode implements IHierNode {
|
|||
return getFullName().compareTo(o.getFullName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDerivedWaveform deriveWaveform() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2020 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
/**
|
||||
* The Interface IDerivedWaveform.
|
||||
*/
|
||||
public interface IDerivedWaveform extends IWaveform {
|
||||
|
||||
void addSourceWaveform(IWaveform waveform);
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 MINRES Technologies GmbH and others.
|
||||
* Copyright (c) 2015, 2020 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -13,6 +13,9 @@ package com.minres.scviewer.database;
|
|||
import java.beans.PropertyChangeListener;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The Interface IHierNode.
|
||||
*/
|
||||
public interface IHierNode extends Comparable<IHierNode>{
|
||||
|
||||
/**
|
||||
|
@ -33,14 +36,46 @@ public interface IHierNode extends Comparable<IHierNode>{
|
|||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) ;
|
||||
|
||||
/**
|
||||
* Gets the full name.
|
||||
*
|
||||
* @return the full name
|
||||
*/
|
||||
public String getFullName();
|
||||
|
||||
/**
|
||||
* Gets the name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Sets the name.
|
||||
*
|
||||
* @param name the new name
|
||||
*/
|
||||
public void setName(String name);
|
||||
|
||||
/**
|
||||
* Sets the parent.
|
||||
*
|
||||
* @param parent the new parent
|
||||
*/
|
||||
public void setParent(IHierNode parent);
|
||||
|
||||
/**
|
||||
* Gets the child nodes.
|
||||
*
|
||||
* @return the child nodes
|
||||
*/
|
||||
public List<IHierNode> getChildNodes();
|
||||
|
||||
/**
|
||||
* Derive waveform.
|
||||
*
|
||||
* @return the i derived waveform or null if none could be created
|
||||
*/
|
||||
public IDerivedWaveform deriveWaveform();
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public interface IWaveform extends IHierNode {
|
|||
|
||||
public IWaveformDb getDb();
|
||||
|
||||
public Boolean equals(IWaveform other);
|
||||
public boolean isSame(IWaveform other);
|
||||
|
||||
public NavigableMap<Long, IEvent[]> getEvents();
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import java.util.Collection;
|
|||
|
||||
public interface IWaveformDbLoader {
|
||||
|
||||
public boolean load(IWaveformDb db, File inp) throws Exception;
|
||||
public boolean load(IWaveformDb db, File inp) throws InputFormatException;
|
||||
|
||||
public Long getMaxTime();
|
||||
|
||||
|
|
|
@ -50,4 +50,9 @@ public class RelationType {
|
|||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return name.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ package com.minres.scviewer.database.internal;
|
|||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -24,12 +23,11 @@ import com.minres.scviewer.database.IHierNode;
|
|||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
|
||||
public class WaveformDb extends HierNode implements IWaveformDb {
|
||||
|
||||
private static List<IWaveformDbLoader> loaders=new LinkedList<IWaveformDbLoader>();
|
||||
private static List<IWaveformDbLoader> loaders=new LinkedList<>();
|
||||
|
||||
private boolean loaded;
|
||||
|
||||
|
@ -55,7 +53,7 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
|||
|
||||
public WaveformDb() {
|
||||
super();
|
||||
waveforms = new HashMap<String, IWaveform>();
|
||||
waveforms = new HashMap<>();
|
||||
relationTypes=new ArrayList<>();
|
||||
maxTime=0L;
|
||||
}
|
||||
|
@ -72,7 +70,7 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
|||
|
||||
@Override
|
||||
public List<IWaveform> getAllWaves() {
|
||||
return new ArrayList<IWaveform>(waveforms.values());
|
||||
return new ArrayList<>(waveforms.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -121,9 +119,8 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
|||
return loaded;
|
||||
}
|
||||
|
||||
private void buildHierarchyNodes() throws InputFormatException{
|
||||
private void buildHierarchyNodes() {
|
||||
for(IWaveform stream:getAllWaves()){
|
||||
//updateMaxTime(stream);
|
||||
String[] hier = stream.getName().split("\\.");
|
||||
IHierNode node = this;
|
||||
for(int i=0; i<hier.length-1; ++i){
|
||||
|
@ -152,14 +149,9 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
|||
}
|
||||
|
||||
private void sortRecursive(IHierNode node) {
|
||||
Collections.sort(node.getChildNodes(), new Comparator<IHierNode>() {
|
||||
@Override
|
||||
public int compare(IHierNode o1, IHierNode o2) {
|
||||
return o1.getName().compareTo(o2.getName()); }
|
||||
|
||||
});
|
||||
Collections.sort(node.getChildNodes(), (IHierNode o1, IHierNode o2) -> o1.getName().compareTo(o2.getName()));
|
||||
for(IHierNode n:node.getChildNodes()) {
|
||||
if(n.getChildNodes().size()>0)
|
||||
if(!n.getChildNodes().isEmpty())
|
||||
sortRecursive(n);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.io.File;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.IDerivedWaveform;
|
||||
import com.minres.scviewer.database.IHierNode;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
|
@ -85,4 +86,9 @@ public class LoadingWaveformDb implements IWaveformDb {
|
|||
public void clear() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDerivedWaveform deriveWaveform() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue