2015-01-06 17:14:16 +01:00
|
|
|
package com.minres.scviewer.database.vcd;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Stack;
|
|
|
|
import java.util.Vector;
|
|
|
|
|
2015-01-09 09:16:40 +01:00
|
|
|
import com.minres.scviewer.database.BitVector;
|
2015-01-06 17:14:16 +01:00
|
|
|
import com.minres.scviewer.database.EventTime;
|
|
|
|
import com.minres.scviewer.database.HierNode;
|
|
|
|
import com.minres.scviewer.database.ISignal;
|
|
|
|
import com.minres.scviewer.database.ISignalChange;
|
|
|
|
import com.minres.scviewer.database.ISignalChangeMulti;
|
|
|
|
import com.minres.scviewer.database.ISignalChangeSingle;
|
|
|
|
import com.minres.scviewer.database.IWaveformDb;
|
|
|
|
import com.minres.scviewer.database.IHierNode;
|
|
|
|
import com.minres.scviewer.database.ITxStream;
|
|
|
|
import com.minres.scviewer.database.IWaveform;
|
2015-01-10 00:23:46 +01:00
|
|
|
import com.minres.scviewer.database.IWaveformDbLoader;
|
2015-01-06 17:14:16 +01:00
|
|
|
import com.minres.scviewer.database.InputFormatException;
|
|
|
|
import com.minres.scviewer.database.SignalChange;
|
|
|
|
|
|
|
|
// TODO: Auto-generated Javadoc
|
|
|
|
/**
|
|
|
|
* The Class VCDDb.
|
|
|
|
*/
|
2015-01-10 00:23:46 +01:00
|
|
|
public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
2015-01-06 17:14:16 +01:00
|
|
|
|
|
|
|
|
2015-01-09 14:17:29 +01:00
|
|
|
private static final EventTime.Unit TIME_RES = EventTime.Unit.PS;
|
2015-01-06 17:14:16 +01:00
|
|
|
|
2015-01-10 00:23:46 +01:00
|
|
|
private IWaveformDb db;
|
|
|
|
|
2015-01-06 17:14:16 +01:00
|
|
|
/** The module stack. */
|
|
|
|
private Stack<String> moduleStack;
|
|
|
|
|
|
|
|
/** The signals. */
|
|
|
|
private List<IWaveform> signals;
|
|
|
|
|
|
|
|
private long maxTime;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new VCD db.
|
|
|
|
*
|
|
|
|
* @param netName the net name
|
|
|
|
*/
|
2015-01-10 00:23:46 +01:00
|
|
|
public VCDDbLoader() {
|
2015-01-06 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
2015-01-10 00:23:46 +01:00
|
|
|
private byte[] x = "$date".getBytes();
|
2015-01-06 17:14:16 +01:00
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see com.minres.scviewer.database.ITrDb#load(java.io.File)
|
|
|
|
*/
|
|
|
|
@Override
|
2015-01-10 00:23:46 +01:00
|
|
|
public boolean load(IWaveformDb db, File file) throws Exception {
|
|
|
|
this.db=db;
|
|
|
|
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;
|
|
|
|
|
|
|
|
signals = new Vector<IWaveform>();
|
2015-01-06 17:14:16 +01:00
|
|
|
moduleStack= new Stack<String>();
|
2015-01-10 00:23:46 +01:00
|
|
|
boolean res = new VCDFileParser(false).load(new FileInputStream(file), this);
|
2015-01-06 17:14:16 +01:00
|
|
|
moduleStack=null;
|
|
|
|
if(!res) throw new InputFormatException();
|
|
|
|
EventTime lastTime=new EventTime(maxTime, TIME_RES);
|
|
|
|
for(IWaveform signal:signals){
|
|
|
|
ISignalChange change = ((ISignal<ISignalChange>)signal).getSignalChanges().last();
|
|
|
|
if(lastTime.compareTo(change.getTime())>0){
|
|
|
|
ISignalChange lastChange = change.duplicate();
|
|
|
|
((SignalChange)lastChange).setTime(lastTime);
|
|
|
|
((ISignal<ISignalChange>)signal).getSignalChanges().add(lastChange);
|
|
|
|
}
|
|
|
|
}
|
2015-01-10 00:23:46 +01:00
|
|
|
return true;
|
2015-01-06 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see com.minres.scviewer.database.ITrDb#getMaxTime()
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public EventTime getMaxTime() {
|
|
|
|
return new EventTime(maxTime, TIME_RES);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see com.minres.scviewer.database.ITrDb#getAllWaves()
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public List<IWaveform> getAllWaves() {
|
|
|
|
return signals;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see com.minres.scviewer.database.vcd.ITraceBuilder#enterModule(java.lang.String)
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void enterModule(String tokenString) {
|
|
|
|
if(moduleStack.isEmpty())
|
|
|
|
moduleStack.push(tokenString);
|
|
|
|
else
|
|
|
|
moduleStack.push(moduleStack.peek()+"."+tokenString);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see com.minres.scviewer.database.vcd.ITraceBuilder#exitModule()
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void exitModule() {
|
|
|
|
if(!moduleStack.isEmpty()) moduleStack.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see com.minres.scviewer.database.vcd.ITraceBuilder#newNet(java.lang.String, int, int)
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public Integer newNet(String netName, int i, int width) {
|
|
|
|
int id = signals.size();
|
|
|
|
VCDSignal<? extends ISignalChange> signal;
|
|
|
|
if(width==1){
|
2015-01-10 00:23:46 +01:00
|
|
|
signal = i<0 ? new VCDSignal<ISignalChangeSingle>(db, id, netName) :
|
2015-01-06 17:14:16 +01:00
|
|
|
new VCDSignal<ISignalChangeSingle>(signals.get(i), id, netName);
|
|
|
|
} else {
|
2015-01-10 00:23:46 +01:00
|
|
|
signal = i<0 ? new VCDSignal<ISignalChangeMulti>(db, id, netName, width) :
|
2015-01-06 17:14:16 +01:00
|
|
|
new VCDSignal<ISignalChangeMulti>(signals.get(i), id, netName);
|
|
|
|
};
|
|
|
|
signals.add(signal);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see com.minres.scviewer.database.vcd.ITraceBuilder#getNetWidth(int)
|
|
|
|
*/
|
2015-01-10 00:23:46 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2015-01-06 17:14:16 +01:00
|
|
|
@Override
|
|
|
|
public int getNetWidth(int intValue) {
|
|
|
|
VCDSignal<? extends ISignalChange> signal = (VCDSignal<? extends ISignalChange>) signals.get(intValue);
|
|
|
|
return signal.getWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (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 intValue, long fCurrentTime, BitVector decodedValues) {
|
|
|
|
VCDSignal<? extends ISignalChange> signal = (VCDSignal<? extends ISignalChange>) signals.get(intValue);
|
|
|
|
EventTime time = new EventTime(fCurrentTime, TIME_RES);
|
|
|
|
if(signal.getWidth()==1){
|
|
|
|
VCDSignalChangeSingle change = new VCDSignalChangeSingle(time, decodedValues.getValue()[0]);
|
|
|
|
((VCDSignal<ISignalChangeSingle>)signal).addSignalChange(change);
|
|
|
|
} else {
|
2015-01-09 09:16:40 +01:00
|
|
|
VCDSignalChangeMulti change = new VCDSignalChangeMulti(time, decodedValues);
|
2015-01-06 17:14:16 +01:00
|
|
|
((VCDSignal<VCDSignalChangeMulti>)signal).addSignalChange(change);
|
|
|
|
}
|
|
|
|
maxTime= Math.max(maxTime, fCurrentTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|