adds working FST reader implementation
This commit is contained in:
+36
-64
@@ -13,22 +13,18 @@ package com.minres.scviewer.database.fst;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
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.Vector;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.minres.scviewer.database.BitVector;
|
||||
import com.minres.scviewer.database.DoubleVal;
|
||||
import com.minres.scviewer.database.EventList;
|
||||
import com.minres.scviewer.database.IEventList;
|
||||
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;
|
||||
@@ -39,59 +35,56 @@ import com.minres.scviewer.database.RelationType;
|
||||
public class FstDbLoader implements IWaveformDbLoader, IFstDatabaseBuilder {
|
||||
|
||||
|
||||
/** The Constant TIME_RES. */
|
||||
private static final Long TIME_RES = 1000L; // ps
|
||||
|
||||
/** The module stack. */
|
||||
private ArrayDeque<String> moduleStack;
|
||||
|
||||
/** The signals. */
|
||||
private List<IWaveform> signals;
|
||||
|
||||
FstFileParser parser;
|
||||
/** The max time. */
|
||||
private long maxTime;
|
||||
|
||||
private int timeScale;
|
||||
|
||||
/** The pcs. */
|
||||
protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
||||
|
||||
static int calculateTimescaleMultipierPower(int power){
|
||||
int answer = 1;
|
||||
if(power<=0){
|
||||
return answer;
|
||||
} else{
|
||||
for(int i = 1; i<= power; i++)
|
||||
answer *= 10;
|
||||
return answer;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.minres.scviewer.database.ITrDb#load(java.io.File)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void load(IWaveformDb db, File file) throws InputFormatException {
|
||||
public void load(File file) throws InputFormatException {
|
||||
dispose();
|
||||
this.maxTime=0;
|
||||
boolean res = false;
|
||||
signals = new Vector<>();
|
||||
moduleStack= new ArrayDeque<>();
|
||||
res = new FstFileParser(file).load(this);
|
||||
parser = new FstFileParser(file);
|
||||
res = parser.open(this);
|
||||
moduleStack=null;
|
||||
if(!res)
|
||||
throw new InputFormatException("Could not parse VCD file");
|
||||
// calculate max time of this database
|
||||
for(IWaveform waveform:signals) {
|
||||
IEventList events =waveform.getEvents();
|
||||
if(!events.isEmpty())
|
||||
maxTime= Math.max(maxTime, events.lastKey());
|
||||
}
|
||||
// extend signals to have a last value set at max time
|
||||
for(IWaveform s:signals){
|
||||
if(s instanceof FstSignal<?>) {
|
||||
IEventList events = ((FstSignal<?>)s).getEvents();
|
||||
if(events.size()>0 && events.lastKey()<maxTime){
|
||||
Object val = events.lastEntry().events[0];
|
||||
if(val instanceof BitVector) {
|
||||
((FstSignal<BitVector>)s).addSignalChange(maxTime, (BitVector) val);
|
||||
} else if(val instanceof DoubleVal)
|
||||
((FstSignal<DoubleVal>)s).addSignalChange(maxTime, (DoubleVal) val);
|
||||
}
|
||||
}
|
||||
}
|
||||
pcs.firePropertyChange(IWaveformDbLoader.LOADING_FINISHED, null, null);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if(parser!=null) {
|
||||
parser.close();
|
||||
parser=null;
|
||||
}
|
||||
moduleStack=null;
|
||||
signals=null;
|
||||
}
|
||||
@@ -101,7 +94,7 @@ public class FstDbLoader implements IWaveformDbLoader, IFstDatabaseBuilder {
|
||||
*/
|
||||
@Override
|
||||
public long getMaxTime() {
|
||||
return maxTime;
|
||||
return maxTime*calculateTimescaleMultipierPower(15+timeScale); // timescape is 1e(timeScale), we calculate in fs
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -136,20 +129,14 @@ public class FstDbLoader implements IWaveformDbLoader, IFstDatabaseBuilder {
|
||||
/* (non-Javadoc)
|
||||
* @see com.minres.scviewer.database.vcd.ITraceBuilder#newNet(java.lang.String, int, int)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Integer newNet(String name, int i, int width) {
|
||||
public void newNet(String name, int handle, int width, boolean alias) {
|
||||
String netName = moduleStack.isEmpty()? name: moduleStack.peek()+"."+name;
|
||||
int id = signals.size();
|
||||
if(width==0) {
|
||||
signals.add( i<0 ? new FstSignal<DoubleVal>(id, netName, width) :
|
||||
new FstSignal<DoubleVal>((FstSignal<DoubleVal>)signals.get(i), id, netName));
|
||||
} else if(width>0){
|
||||
signals.add( i<0 ? new FstSignal<BitVector>(id, netName, width) :
|
||||
new FstSignal<BitVector>((FstSignal<BitVector>)signals.get(i), id, netName));
|
||||
}
|
||||
IWaveform signal = width==0?
|
||||
new FstSignal<DoubleVal>(this, handle, netName, width):
|
||||
new FstSignal<BitVector>(this, handle, netName, width);
|
||||
signals.add(signal);
|
||||
pcs.firePropertyChange(IWaveformDbLoader.SIGNAL_ADDED, null, Iterables.getLast(signals));
|
||||
return id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -161,28 +148,10 @@ public class FstDbLoader implements IWaveformDbLoader, IFstDatabaseBuilder {
|
||||
return signal.getRowCount();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.minres.scviewer.database.vcd.ITraceBuilder#appendTransition(int, long, com.minres.scviewer.database.vcd.BitVector)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void appendTransition(int signalId, long currentTime, BitVector value) {
|
||||
FstSignal<BitVector> signal = (FstSignal<BitVector>) signals.get(signalId);
|
||||
Long time = currentTime* TIME_RES;
|
||||
signal.addSignalChange(time, value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.minres.scviewer.database.vcd.ITraceBuilder#appendTransition(int, long, com.minres.scviewer.database.vcd.BitVector)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void appendTransition(int signalId, long currentTime, double value) {
|
||||
FstSignal<DoubleVal> signal = (FstSignal<DoubleVal>) signals.get(signalId);
|
||||
Long time = currentTime* TIME_RES;
|
||||
signal.addSignalChange(time, new DoubleVal(value));
|
||||
}
|
||||
|
||||
public void setMaxTime(long maxTime, int timeScale) {
|
||||
this.maxTime = maxTime;
|
||||
this.timeScale=timeScale;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.minres.scviewer.database.IWaveformDbLoader#getAllRelationTypes()
|
||||
*/
|
||||
@@ -211,5 +180,8 @@ public class FstDbLoader implements IWaveformDbLoader, IFstDatabaseBuilder {
|
||||
pcs.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
|
||||
public void getEvents(int id, int width, IEventList values) {
|
||||
if(values instanceof EventList)
|
||||
parser.getValueChanges(id, width, calculateTimescaleMultipierPower(15+timeScale), (EventList) values);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user