Unified databases so that signals and transactions can be loaded into
same database
This commit is contained in:
@ -5,7 +5,6 @@ Bundle-SymbolicName: com.minres.scviewer.database
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Vendor: MINRES Technologies GmbH
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Export-Package: com.minres.scviewer.database,
|
||||
com.minres.scviewer.database.vcd
|
||||
Service-Component: OSGI-INF/component.xml
|
||||
Export-Package: com.minres.scviewer.database
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Service-Component: OSGI-INF/component.xml
|
||||
|
@ -1,7 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="VCDDbFactory">
|
||||
<implementation class="com.minres.scviewer.database.vcd.VCDDbFactory"/>
|
||||
<service>
|
||||
<provide interface="com.minres.scviewer.database.IWaveformDbFactory"/>
|
||||
</service>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.minres.scviewer.database">
|
||||
<implementation class="com.minres.scviewer.database.WaveformDb"/>
|
||||
<reference bind="bind" cardinality="0..n" interface="com.minres.scviewer.database.IWaveformDbLoader" name="IWaveformDbLoader" policy="dynamic" unbind="unbind"/>
|
||||
</scr:component>
|
||||
|
@ -1,5 +1,6 @@
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
OSGI-INF/component.xml,\
|
||||
OSGI-INF/component.xml
|
||||
source.. = src/
|
||||
|
@ -28,7 +28,13 @@ public class EventTime implements Comparable<EventTime>{
|
||||
}
|
||||
}
|
||||
|
||||
static final double[] scales = {1,1000.0,1000000.0,1000000000.0,1000000000000.0};
|
||||
static final double[] scales = {
|
||||
1,
|
||||
1000.0,
|
||||
1000000.0,
|
||||
1000000000.0,
|
||||
1000000000000.0,
|
||||
1000000000000000.0};
|
||||
|
||||
public static final EventTime ZERO = new EventTime(0L);
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class HierNode implements IHierNode {
|
||||
@ -10,19 +12,29 @@ public class HierNode implements IHierNode {
|
||||
|
||||
protected ArrayList<IHierNode> childs;
|
||||
|
||||
public HierNode(String name) {
|
||||
this.name=name;
|
||||
protected PropertyChangeSupport pcs;
|
||||
|
||||
public HierNode() {
|
||||
childs = new ArrayList<IHierNode>();
|
||||
pcs=new PropertyChangeSupport(this);
|
||||
}
|
||||
|
||||
public HierNode(String name) {
|
||||
this();
|
||||
this.name=name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
pcs.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
pcs.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getFullName() {
|
||||
return name;
|
||||
@ -43,4 +55,9 @@ public class HierNode implements IHierNode {
|
||||
return childs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IHierNode o) {
|
||||
return name.compareTo(o.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ package com.minres.scviewer.database;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.List;
|
||||
|
||||
public interface IHierNode {
|
||||
public interface IHierNode extends Comparable<IHierNode>{
|
||||
|
||||
/**
|
||||
* Attach a non-null PropertyChangeListener to this object.
|
||||
|
@ -22,7 +22,7 @@ public interface IWaveformDb extends IHierNode {
|
||||
|
||||
public List<IWaveform> getAllWaves();
|
||||
|
||||
public void load(File inp) throws Exception;
|
||||
public boolean load(File inp) throws Exception;
|
||||
|
||||
public void clear();
|
||||
|
||||
|
@ -1,9 +0,0 @@
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface IWaveformDbFactory {
|
||||
|
||||
IWaveformDb createDatabase(File file);
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public interface IWaveformDbLoader {
|
||||
|
||||
public boolean load(IWaveformDb db, File inp) throws Exception;
|
||||
|
||||
public EventTime getMaxTime();
|
||||
|
||||
public List<IWaveform> getAllWaves() ;
|
||||
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class WaveformDb extends HierNode implements IWaveformDb {
|
||||
|
||||
private static List<IWaveformDbLoader> loaders=new LinkedList<IWaveformDbLoader>();
|
||||
|
||||
private List<IHierNode> childNodes;
|
||||
|
||||
private Map<String, IWaveform> waveforms;
|
||||
|
||||
private EventTime maxTime;
|
||||
|
||||
|
||||
public void bind(IWaveformDbLoader loader){
|
||||
loaders.add(loader);
|
||||
}
|
||||
|
||||
public void unbind(IWaveformDbLoader loader){
|
||||
loaders.remove(loader);
|
||||
}
|
||||
|
||||
|
||||
public static List<IWaveformDbLoader> getLoaders() {
|
||||
return Collections.unmodifiableList(loaders);
|
||||
}
|
||||
|
||||
public WaveformDb() {
|
||||
super();
|
||||
waveforms = new HashMap<String, IWaveform>();
|
||||
maxTime=EventTime.ZERO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventTime getMaxTime() {
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveform getStreamByName(String name) {
|
||||
return waveforms.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IWaveform> getAllWaves() {
|
||||
return new ArrayList<IWaveform>(waveforms.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean load(File inp) throws Exception {
|
||||
for(IWaveformDbLoader loader:loaders){
|
||||
if(loader.load(this, inp)){
|
||||
for(IWaveform w:loader.getAllWaves())
|
||||
waveforms.put(w.getFullName(),w);
|
||||
buildHierarchyNodes() ;
|
||||
if(name==null) name=getFileBasename(inp.getName());
|
||||
pcs.firePropertyChange("WAVEFORMS", null, waveforms);
|
||||
pcs.firePropertyChange("CHILDS", null, childNodes);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static String getFileBasename(String f) {
|
||||
String ext = "";
|
||||
int i = f.lastIndexOf('.');
|
||||
if (i > 0 && i < f.length() - 1) {
|
||||
ext = f.substring(0, i);
|
||||
}
|
||||
return ext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
waveforms.clear();
|
||||
childNodes.clear();
|
||||
}
|
||||
|
||||
private void buildHierarchyNodes() throws InputFormatException{
|
||||
childNodes= new ArrayList<IHierNode>();
|
||||
for(IWaveform stream:getAllWaves()){
|
||||
updateMaxTime(stream);
|
||||
String[] hier = stream.getFullName().split("\\.");
|
||||
IHierNode node = this;
|
||||
for(String name:hier){
|
||||
IHierNode n1 = null;
|
||||
for (IHierNode n : node.getChildNodes()) {
|
||||
if (n.getName().equals(name)) {
|
||||
n1=n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(name == hier[hier.length-1]){ //leaf
|
||||
if(n1!=null) {
|
||||
if(n1 instanceof HierNode){
|
||||
node.getChildNodes().remove(n1);
|
||||
stream.getChildNodes().addAll(n1.getChildNodes());
|
||||
Collections.sort(stream.getChildNodes());
|
||||
} else {
|
||||
throw new InputFormatException();
|
||||
}
|
||||
}
|
||||
stream.setName(name);
|
||||
node.getChildNodes().add(stream);
|
||||
Collections.sort(node.getChildNodes());
|
||||
node=stream;
|
||||
} else { // intermediate
|
||||
if(n1 != null) {
|
||||
node=n1;
|
||||
} else {
|
||||
HierNode newNode = new HierNode(name);
|
||||
node.getChildNodes().add(newNode);
|
||||
Collections.sort(node.getChildNodes());
|
||||
node=newNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMaxTime(IWaveform stream) {
|
||||
EventTime last=null;
|
||||
if(stream instanceof ITxStream){
|
||||
last=((ITxStream)stream).getTransactions().last().getEndTime();
|
||||
} else if(stream instanceof ISignal<?>){
|
||||
last=((ISignal<ISignalChange>)stream).getSignalChanges().last().getTime();
|
||||
}
|
||||
if(last.getValue()>maxTime.getValue())
|
||||
maxTime=last;
|
||||
}
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package com.minres.scviewer.database.vcd;
|
||||
|
||||
import com.minres.scviewer.database.BitVector;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Interface ITraceBuilder.
|
||||
*/
|
||||
public interface IVCDDatabaseBuilder {
|
||||
|
||||
/**
|
||||
* Enter module.
|
||||
*
|
||||
* @param tokenString the token string
|
||||
*/
|
||||
public void enterModule(String tokenString);
|
||||
|
||||
/**
|
||||
* Exit module.
|
||||
*/
|
||||
public void exitModule();
|
||||
|
||||
/**
|
||||
* New net.
|
||||
*
|
||||
* @param netName the net name
|
||||
* @param i the index of the net, -1 if a new one, otherwise the id if the referenced
|
||||
* @param width the width
|
||||
* @return the integer
|
||||
*/
|
||||
public Integer newNet(String netName, int i, int width) ;
|
||||
|
||||
/**
|
||||
* Gets the net width.
|
||||
*
|
||||
* @param intValue the int value
|
||||
* @return the net width
|
||||
*/
|
||||
public int getNetWidth(int intValue);
|
||||
|
||||
/**
|
||||
* Append transition.
|
||||
*
|
||||
* @param intValue the int value
|
||||
* @param fCurrentTime the f current time
|
||||
* @param decodedValues the decoded values
|
||||
*/
|
||||
public void appendTransition(int intValue, long fCurrentTime, BitVector decodedValues);
|
||||
|
||||
}
|
@ -1,212 +0,0 @@
|
||||
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;
|
||||
|
||||
import com.minres.scviewer.database.BitVector;
|
||||
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;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.SignalChange;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class VCDDb.
|
||||
*/
|
||||
public class VCDDb extends HierNode implements IWaveformDb, IVCDDatabaseBuilder {
|
||||
|
||||
|
||||
private static final EventTime.Unit TIME_RES = EventTime.Unit.PS;
|
||||
|
||||
/** The module stack. */
|
||||
private Stack<String> moduleStack;
|
||||
|
||||
/** The signals. */
|
||||
private List<IWaveform> signals;
|
||||
|
||||
private HashMap<String, IWaveform> waveformLookup;
|
||||
|
||||
private long maxTime;
|
||||
|
||||
/**
|
||||
* Instantiates a new VCD db.
|
||||
*
|
||||
* @param netName the net name
|
||||
*/
|
||||
public VCDDb() {
|
||||
super("VCDDb");
|
||||
signals = new Vector<IWaveform>();
|
||||
waveformLookup = new HashMap<String, IWaveform>();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.minres.scviewer.database.ITrDb#getStreamByName(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public IWaveform getStreamByName(String name) {
|
||||
return waveformLookup.get(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.minres.scviewer.database.ITrDb#load(java.io.File)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void load(File inp) throws Exception {
|
||||
moduleStack= new Stack<String>();
|
||||
boolean res = new VCDFileParser(false).load(new FileInputStream(inp), this);
|
||||
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);
|
||||
}
|
||||
}
|
||||
buildHierarchyNodes();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.minres.scviewer.database.ITrDb#clear()
|
||||
*/
|
||||
@Override
|
||||
public void clear() {
|
||||
signals.clear();
|
||||
}
|
||||
|
||||
/* (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){
|
||||
signal = i<0 ? new VCDSignal<ISignalChangeSingle>(id, netName) :
|
||||
new VCDSignal<ISignalChangeSingle>(signals.get(i), id, netName);
|
||||
} else {
|
||||
signal = i<0 ? new VCDSignal<ISignalChangeMulti>(id, netName, width) :
|
||||
new VCDSignal<ISignalChangeMulti>(signals.get(i), id, netName);
|
||||
};
|
||||
signals.add(signal);
|
||||
return id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.minres.scviewer.database.vcd.ITraceBuilder#getNetWidth(int)
|
||||
*/
|
||||
@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 {
|
||||
VCDSignalChangeMulti change = new VCDSignalChangeMulti(time, decodedValues);
|
||||
((VCDSignal<VCDSignalChangeMulti>)signal).addSignalChange(change);
|
||||
}
|
||||
maxTime= Math.max(maxTime, fCurrentTime);
|
||||
}
|
||||
|
||||
private void buildHierarchyNodes() throws InputFormatException{
|
||||
for(IWaveform stream:getAllWaves()){
|
||||
waveformLookup.put(stream.getFullName(), stream);
|
||||
String[] hier = stream.getFullName().split("\\.");
|
||||
IHierNode node = this;
|
||||
for(String name:hier){
|
||||
IHierNode n1 = null;
|
||||
for (IHierNode n : node.getChildNodes()) {
|
||||
if (n.getName().equals(name)) {
|
||||
n1=n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(name == hier[hier.length-1]){ //leaf
|
||||
if(n1!=null) {
|
||||
if(n1 instanceof HierNode){
|
||||
node.getChildNodes().remove(n1);
|
||||
stream.getChildNodes().addAll(n1.getChildNodes());
|
||||
} else {
|
||||
throw new InputFormatException();
|
||||
}
|
||||
}
|
||||
stream.setName(name);
|
||||
node.getChildNodes().add(stream);
|
||||
node=stream;
|
||||
} else { // intermediate
|
||||
if(n1 != null) {
|
||||
node=n1;
|
||||
} else {
|
||||
HierNode newNode = new HierNode(name);
|
||||
node.getChildNodes().add(newNode);
|
||||
node=newNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.minres.scviewer.database.vcd;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbFactory;
|
||||
|
||||
public class VCDDbFactory implements IWaveformDbFactory {
|
||||
|
||||
private byte[] x = "$date".getBytes();
|
||||
|
||||
public VCDDbFactory(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveformDb createDatabase(File 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 null;
|
||||
VCDDb db = new VCDDb();
|
||||
db.load(file);
|
||||
return db;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,214 +0,0 @@
|
||||
package com.minres.scviewer.database.vcd;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import com.minres.scviewer.database.BitVector;
|
||||
|
||||
class VCDFileParser {
|
||||
private StreamTokenizer tokenizer;
|
||||
private IVCDDatabaseBuilder traceBuilder;
|
||||
private HashMap<String, Integer> nameToNetMap = new HashMap<String, Integer>();
|
||||
private long picoSecondsPerIncrement;
|
||||
private boolean stripNetWidth;
|
||||
long currentTime;
|
||||
|
||||
public VCDFileParser(boolean stripNetWidth) {
|
||||
this.stripNetWidth=stripNetWidth;
|
||||
}
|
||||
|
||||
public boolean load(InputStream is, IVCDDatabaseBuilder builder) {
|
||||
tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
|
||||
tokenizer.resetSyntax();
|
||||
tokenizer.wordChars(33, 126);
|
||||
tokenizer.whitespaceChars('\r', '\r');
|
||||
tokenizer.whitespaceChars('\n', '\n');
|
||||
tokenizer.whitespaceChars(' ', ' ');
|
||||
tokenizer.whitespaceChars('\t', '\t');
|
||||
try {
|
||||
traceBuilder = builder;
|
||||
currentTime=0;
|
||||
while (parseDefinition());
|
||||
while (parseTransition());
|
||||
return true;
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void parseScope() throws Exception {
|
||||
nextToken(); // Scope type (ignore)
|
||||
nextToken();
|
||||
traceBuilder.enterModule(tokenizer.sval);
|
||||
match("$end");
|
||||
}
|
||||
|
||||
private void parseUpscope() throws Exception {
|
||||
match("$end");
|
||||
traceBuilder.exitModule();
|
||||
}
|
||||
|
||||
private void parseVar() throws Exception {
|
||||
nextToken(); // type
|
||||
nextToken(); // size
|
||||
int width = Integer.parseInt(tokenizer.sval);
|
||||
|
||||
nextToken();
|
||||
String id = tokenizer.sval;
|
||||
nextToken();
|
||||
String netName = tokenizer.sval;
|
||||
while (nextToken() && !tokenizer.sval.equals("$end")) {
|
||||
netName+=tokenizer.sval;
|
||||
}
|
||||
|
||||
Integer net = nameToNetMap.get(id);
|
||||
if (net == null) {
|
||||
// We've never seen this net before
|
||||
if(stripNetWidth){
|
||||
int openBracket = netName.indexOf('[');
|
||||
if (openBracket != -1) netName = netName.substring(0, openBracket);
|
||||
}
|
||||
nameToNetMap.put(id, traceBuilder.newNet(netName, -1, width));
|
||||
} else {
|
||||
// Shares data with existing net. Add as clone.
|
||||
traceBuilder.newNet(netName, net, width);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseTimescale() throws Exception {
|
||||
nextToken();
|
||||
String s = tokenizer.sval;
|
||||
nextToken();
|
||||
while(!tokenizer.sval.equals("$end")){
|
||||
s+=" "+tokenizer.sval;
|
||||
nextToken();
|
||||
}
|
||||
switch (s.charAt(s.length() - 2)){
|
||||
case 'p': // Nano-seconds
|
||||
picoSecondsPerIncrement = 1;
|
||||
s = s.substring(0, s.length() - 2).trim();
|
||||
break;
|
||||
case 'n': // Nano-seconds
|
||||
picoSecondsPerIncrement = 1000;
|
||||
s = s.substring(0, s.length() - 2).trim();
|
||||
break;
|
||||
case 'u': // Microseconds
|
||||
picoSecondsPerIncrement = 1000000;
|
||||
s = s.substring(0, s.length() - 2).trim();
|
||||
break;
|
||||
case 'm': // Microseconds
|
||||
picoSecondsPerIncrement = 1000000000;
|
||||
s = s.substring(0, s.length() - 2).trim();
|
||||
break;
|
||||
default: // Seconds
|
||||
picoSecondsPerIncrement = 1000000000000L;
|
||||
s = s.substring(0, s.length() - 1);
|
||||
break;
|
||||
}
|
||||
picoSecondsPerIncrement *= Long.parseLong(s);
|
||||
}
|
||||
|
||||
private boolean parseDefinition() throws Exception {
|
||||
nextToken();
|
||||
if (tokenizer.sval.equals("$scope"))
|
||||
parseScope();
|
||||
else if (tokenizer.sval.equals("$var"))
|
||||
parseVar();
|
||||
else if (tokenizer.sval.equals("$upscope"))
|
||||
parseUpscope();
|
||||
else if (tokenizer.sval.equals("$timescale"))
|
||||
parseTimescale();
|
||||
else if (tokenizer.sval.equals("$enddefinitions")) {
|
||||
match("$end");
|
||||
return false;
|
||||
} else {
|
||||
// Ignore this defintion
|
||||
do {
|
||||
if (!nextToken()) return false;
|
||||
} while (!tokenizer.sval.equals("$end"));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean parseTransition() throws Exception {
|
||||
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;
|
||||
} else {
|
||||
if(tokenizer.sval.equals("$comment")){
|
||||
do {
|
||||
if (!nextToken()) return false;
|
||||
} while (!tokenizer.sval.equals("$end"));
|
||||
return true;
|
||||
}
|
||||
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 {
|
||||
// Single value net. identifier first, then value, no space.
|
||||
value = tokenizer.sval.substring(0, 1);
|
||||
id = tokenizer.sval.substring(1);
|
||||
}
|
||||
|
||||
Integer net = nameToNetMap.get(id);
|
||||
if (net == null) {
|
||||
System.out.println("unknown net " + id + " value " + value);
|
||||
return true;
|
||||
}
|
||||
|
||||
int netWidth = traceBuilder.getNetWidth(net);
|
||||
BitVector decodedValues = new BitVector(netWidth);
|
||||
if (value.equals("z") && netWidth > 1) {
|
||||
for (int i = 0; i < netWidth; i++)
|
||||
decodedValues.setValue(i, BitVector.VALUE_Z);
|
||||
} else if (value.equals("x") && netWidth > 1) {
|
||||
for (int i = 0; i < netWidth; i++)
|
||||
decodedValues.setValue(i, BitVector.VALUE_X);
|
||||
} else {
|
||||
int stringIndex = 0;
|
||||
for (int convertedIndex = netWidth - value.length(); convertedIndex < netWidth; convertedIndex++) {
|
||||
switch (value.charAt(stringIndex++)) {
|
||||
case 'z':
|
||||
decodedValues.setValue(convertedIndex, BitVector.VALUE_Z);
|
||||
break;
|
||||
|
||||
case '1':
|
||||
decodedValues.setValue(convertedIndex, BitVector.VALUE_1);
|
||||
break;
|
||||
|
||||
case '0':
|
||||
decodedValues.setValue(convertedIndex, BitVector.VALUE_0);
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
decodedValues.setValue(convertedIndex, BitVector.VALUE_X);
|
||||
break;
|
||||
|
||||
default:
|
||||
decodedValues.setValue(convertedIndex, BitVector.VALUE_X);
|
||||
}
|
||||
}
|
||||
}
|
||||
traceBuilder.appendTransition(net, currentTime, decodedValues);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void match(String value) throws Exception {
|
||||
nextToken();
|
||||
if (!tokenizer.sval.equals(value))
|
||||
throw new Exception("Line "+tokenizer.lineno()+": parse error, expected "+value+" got "+tokenizer.sval);
|
||||
}
|
||||
|
||||
private boolean nextToken() throws IOException {
|
||||
return tokenizer.nextToken() != StreamTokenizer.TT_EOF;
|
||||
}
|
||||
|
||||
};
|
@ -1,108 +0,0 @@
|
||||
package com.minres.scviewer.database.vcd;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.NavigableSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
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.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.SignalChange;
|
||||
|
||||
public class VCDSignal<T extends ISignalChange> extends HierNode implements ISignal<T> {
|
||||
|
||||
private long id;
|
||||
|
||||
private String fullName;
|
||||
|
||||
private final String kind = "signal";
|
||||
|
||||
private final int width;
|
||||
|
||||
private VCDDb db;
|
||||
|
||||
TreeSet<ISignalChange> values;
|
||||
|
||||
public VCDSignal(String name) {
|
||||
this(0, name, 1);
|
||||
}
|
||||
|
||||
public VCDSignal(int id, String name) {
|
||||
this(id,name,1);
|
||||
}
|
||||
|
||||
public VCDSignal(int id, String name, int width) {
|
||||
super(name);
|
||||
fullName=name;
|
||||
this.id=id;
|
||||
this.width=width;
|
||||
this.values=new TreeSet<ISignalChange>();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public VCDSignal(IWaveform other, int id, String name) {
|
||||
super(name);
|
||||
fullName=name;
|
||||
this.id=id;
|
||||
assert(other instanceof VCDSignal<?>);
|
||||
this.width=((VCDSignal<? extends ISignalChange>)other).width;
|
||||
this.values=((VCDSignal<T>)other).values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id=id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveformDb getDb() {
|
||||
return db;
|
||||
}
|
||||
|
||||
public void addSignalChange(T change){
|
||||
values.add(change);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NavigableSet<ISignalChange> getSignalChanges() {
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getSignalChangeByTime(EventTime time) {
|
||||
return (T) values.floor(new SignalChange(time));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NavigableSet<ISignalChange> getSignalChangesByTimes(EventTime start, EventTime end) {
|
||||
ISignalChange low = values.floor(new SignalChange(start));
|
||||
ISignalChange high = values.ceiling(new SignalChange(end));
|
||||
if(high!=null)
|
||||
return values.subSet(low, true, high, true);
|
||||
else
|
||||
return values.subSet(low, true, values.last(), true);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.minres.scviewer.database.vcd;
|
||||
|
||||
import com.minres.scviewer.database.BitVector;
|
||||
import com.minres.scviewer.database.EventTime;
|
||||
import com.minres.scviewer.database.ISignalChangeMulti;
|
||||
import com.minres.scviewer.database.SignalChange;
|
||||
|
||||
public class VCDSignalChangeMulti extends SignalChange implements ISignalChangeMulti, Cloneable {
|
||||
|
||||
private BitVector value;
|
||||
|
||||
public VCDSignalChangeMulti(EventTime time) {
|
||||
super(time);
|
||||
}
|
||||
|
||||
public VCDSignalChangeMulti(EventTime time, BitVector decodedValues) {
|
||||
super(time);
|
||||
this.value=decodedValues;
|
||||
}
|
||||
|
||||
public BitVector getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(BitVector value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package com.minres.scviewer.database.vcd;
|
||||
|
||||
import com.minres.scviewer.database.EventTime;
|
||||
import com.minres.scviewer.database.ISignalChangeSingle;
|
||||
import com.minres.scviewer.database.SignalChange;
|
||||
|
||||
public class VCDSignalChangeSingle extends SignalChange implements ISignalChangeSingle, Cloneable {
|
||||
|
||||
private char value;
|
||||
|
||||
public VCDSignalChangeSingle(EventTime time, char value) {
|
||||
super(time);
|
||||
this.value=value;
|
||||
}
|
||||
|
||||
public char getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(char value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user