adds skeleton of FST plugin

This commit is contained in:
2023-02-26 10:53:39 +01:00
parent 85d9c92f21
commit bba4349e1e
31 changed files with 10960 additions and 3 deletions

View File

@@ -0,0 +1,215 @@
/*******************************************************************************
* Copyright (c) 2015-2021 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.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.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;
/**
* The Class VCDDb.
*/
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;
/** The max time. */
private long maxTime;
/** The pcs. */
protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);
/* (non-Javadoc)
* @see com.minres.scviewer.database.ITrDb#load(java.io.File)
*/
@SuppressWarnings("unchecked")
@Override
public void load(IWaveformDb db, File file) throws InputFormatException {
dispose();
this.maxTime=0;
boolean res = false;
signals = new Vector<>();
moduleStack= new ArrayDeque<>();
res = new FstFileParser(file).load(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() {
moduleStack=null;
signals=null;
}
/* (non-Javadoc)
* @see com.minres.scviewer.database.ITrDb#getMaxTime()
*/
@Override
public long getMaxTime() {
return maxTime;
}
/* (non-Javadoc)
* @see com.minres.scviewer.database.ITrDb#getAllWaves()
*/
@Override
public Collection<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()) {
if("SystemC".compareTo(tokenString)!=0)
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)
*/
@SuppressWarnings("unchecked")
@Override
public Integer newNet(String name, int i, int width) {
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));
}
pcs.firePropertyChange(IWaveformDbLoader.SIGNAL_ADDED, null, Iterables.getLast(signals));
return id;
}
/* (non-Javadoc)
* @see com.minres.scviewer.database.vcd.ITraceBuilder#getNetWidth(int)
*/
@Override
public int getNetWidth(int intValue) {
FstSignal<?> signal = (FstSignal<?>) signals.get(intValue);
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));
}
/* (non-Javadoc)
* @see com.minres.scviewer.database.IWaveformDbLoader#getAllRelationTypes()
*/
@Override
public Collection<RelationType> getAllRelationTypes(){
return Collections.emptyList();
}
/**
* Adds the property change listener.
*
* @param l the l
*/
@Override
public void addPropertyChangeListener(PropertyChangeListener l) {
pcs.addPropertyChangeListener(l);
}
/**
* Removes the property change listener.
*
* @param l the l
*/
@Override
public void removePropertyChangeListener(PropertyChangeListener l) {
pcs.removePropertyChangeListener(l);
}
}

View File

@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2015-2021 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.fst;
import java.io.File;
import com.minres.scviewer.database.IWaveformDbLoader;
import com.minres.scviewer.database.IWaveformDbLoaderFactory;
/**
* The Class VCDDb.
*/
public class FstDbLoaderFactory implements IWaveformDbLoaderFactory {
/**
* Can load.
*
* @param inputFile the input file
* @return true, if successful
*/
@Override
public boolean canLoad(File inputFile) {
if(!inputFile.isDirectory() || inputFile.exists()) {
String name = inputFile.getName();
return name.endsWith(".fst");
}
return false;
}
@Override
public IWaveformDbLoader getLoader() {
return new FstDbLoader();
}
}

View File

@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2015-2021 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.fst;
import java.io.*;
import java.text.ParseException;
import java.util.*;
import com.minres.scviewer.database.BitValue;
import com.minres.scviewer.database.BitVector;
import com.sun.jna.Pointer;
class FstFileParser {
long currentTime;
final File file;
public FstFileParser(File file) {
this.file=file;
}
public boolean load(IFstDatabaseBuilder builder) {
Pointer ctx = FstLibrary.fstReaderOpen(file.getAbsolutePath());
if(!ctx.equals(Pointer.NULL)) {
String version = FstLibrary.fstReaderGetVersionString(ctx);
System.out.println(version);
FstLibrary.fstReaderClose(ctx);
}
return false;
}
}

View File

@@ -0,0 +1,105 @@
package com.minres.scviewer.database.fst;
import com.sun.jna.Native;
import com.sun.jna.Platform;
import com.sun.jna.Pointer;
public class FstLibrary {
public enum FstScopeType {
MIN(0),
VCD_MODULE(0),
VCD_TASK(1),
VCD_FUNCTION(2),
VCD_BEGIN(3),
VCD_FORK(4),
VCD_GENERATE(5),
VCD_STRUCT(6),
VCD_UNION(7),
VCD_CLASS(8),
VCD_INTERFACE(9),
VCD_PACKAGE(10),
VCD_PROGRAM(11),
VHDL_ARCHITECTURE(12),
VHDL_PROCEDURE(13),
VHDL_FUNCTION(14),
VHDL_RECORD(15),
VHDL_PROCESS(16),
VHDL_BLOCK(17),
VHDL_FOR_GENERATE(18),
VHDL_IF_GENERATE(19),
VHDL_GENERATE(20),
VHDL_PACKAGE(21),
MAX(21),
FST_ST_GEN_ATTRBEGIN(252),
FST_ST_GEN_ATTREND(253),
FST_ST_VCD_SCOPE(254),
FST_ST_VCD_UPSCOPE(255);
public final int label;
private FstScopeType(int label) {
this.label = label;
}
};
public static native Pointer fstReaderOpen(String name);
public static native void fstReaderClose(Pointer ctx);
public static native String fstReaderGetVersionString(Pointer ctx);
public static native String fstReaderGetDateString(Pointer ctx);
public static native int fstReaderGetFileType(Pointer ctx);
public static native long fstReaderGetVarCount(Pointer ctx);
public static native long fstReaderGetScopeCount(Pointer ctx);
public static native long fstReaderGetAliasCount(Pointer ctx);
public static native long fstReaderGetValueChangeSectionCount(Pointer ctx);
public static native long fstReaderGetStartTime(Pointer ctx);
public static native long fstReaderGetEndTime(Pointer ctx);
public static native byte fstReaderGetTimescale(Pointer ctx);
public static native long fstReaderGetTimezero(Pointer ctx);
public static native void fstReaderResetScope(Pointer ctx);
public static native String fstReaderPushScope(Pointer ctx, String nam, Pointer user_info);
public static native String fstReaderPopScope(Pointer ctx);
public static native int fstReaderGetCurrentScopeLen(Pointer ctx);
/*
void fstReaderClrFacProcessMask(Pointer ctx, fstHandle facidx);
void fstReaderClrFacProcessMaskAll(Pointer ctx);
String fstReaderGetCurrentFlatScope(Pointer ctx);
Pointer fstReaderGetCurrentScopeUserInfo(Pointer ctx);
int fstReaderGetDoubleEndianMatchState(Pointer ctx);
long fstReaderGetDumpActivityChangeTime(Pointer ctx, int idx);
byte fstReaderGetDumpActivityChangeValue(Pointer ctx, int idx);
int fstReaderGetFacProcessMask(Pointer ctx, fstHandle facidx);
int fstReaderGetFseekFailed(Pointer ctx);
fstHandle fstReaderGetMaxHandle(Pointer ctx);
long fstReaderGetMemoryUsedByWriter(Pointer ctx);
int fstReaderGetNumberDumpActivityChanges(Pointer ctx);
String fstReaderGetValueFromHandleAtTime(Pointer ctx, long tim, fstHandle facidx, Stringbuf);
struct fstHier *fstReaderIterateHier(Pointer ctx);
int fstReaderIterateHierRewind(Pointer ctx);
int fstReaderIterBlocks(Pointer ctx,
void (*value_change_callback)(Pointer user_callback_data_pointer, long time, fstHandle facidx, const unsigned Stringvalue),
Pointer user_callback_data_pointer, FILE *vcdhandle);
int fstReaderIterBlocks2(Pointer ctx,
void (*value_change_callback)(Pointer user_callback_data_pointer, long time, fstHandle facidx, const unsigned Stringvalue),
void (*value_change_callback_varlen)(Pointer user_callback_data_pointer, long time, fstHandle facidx, const unsigned Stringvalue, int len),
Pointer user_callback_data_pointer, FILE *vcdhandle);
void fstReaderIterBlocksSetNativeDoublesOnCallback(Pointer ctx, int enable);
Pointer fstReaderOpenForUtilitiesOnly(void);
int fstReaderProcessHier(Pointer ctx, FILE *vcdhandle);
void fstReaderSetFacProcessMask(Pointer ctx, fstHandle facidx);
void fstReaderSetFacProcessMaskAll(Pointer ctx);
void fstReaderSetLimitTimeRange(Pointer ctx, long start_time, long end_time);
void fstReaderSetUnlimitedTimeRange(Pointer ctx);
void fstReaderSetVcdExtensions(Pointer ctx, int enable);
*/
static {
System.setProperty("jna.debug_load", "true");
// System.out.println(System.getProperty("jna.library.path", "UNKNOWN"));
Native.register("fstapi");
}
}

View File

@@ -0,0 +1,112 @@
/*******************************************************************************
* Copyright (c) 2015-2021 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.fst;
import com.minres.scviewer.database.EventEntry;
import com.minres.scviewer.database.EventList;
import com.minres.scviewer.database.HierNode;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IEventList;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.WaveformType;
public class FstSignal<T extends IEvent> extends HierNode implements IWaveform {
private long id;
private String fullName;
private final int width;
private IEventList values;
public FstSignal(String name) {
this(0, name, 1);
}
public FstSignal(int id, String name) {
this(id,name,1);
}
public FstSignal(int id, String name, int width) {
super(name);
fullName=name;
this.id=id;
this.width=width;
this.values=new EventList();
}
public FstSignal(FstSignal<T> o, int id, String name) {
super(name);
fullName=name;
this.id=id;
this.width=o.width;
this.values=o.values;
}
@Override
public String getFullName() {
return fullName;
}
public void setId(int id) {
this.id=id;
}
@Override
public long getId() {
return id;
}
public void addSignalChange(Long time, T value){
values.put(time, value);
}
@Override
public IEventList getEvents() {
return values;
}
@Override
public IEvent[] getEventsAtTime(long time) {
return values.get(time);
}
@Override
public IEvent[] getEventsBeforeTime(long time) {
EventEntry e = values.floorEntry(time);
if(e==null)
return new IEvent[] {};
else
return values.floorEntry(time).events;
}
@Override
public boolean isSame(IWaveform other) {
return( other instanceof FstSignal<?> && this.getId() == other.getId());
}
@Override
public WaveformType getType() {
return WaveformType.SIGNAL;
}
@Override
public int getRowCount() {
return width;
}
@Override
public String getKind() {
return "signal";
}
}

View File

@@ -0,0 +1,27 @@
package com.minres.scviewer.database.fst;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
/** Simple example of JNA interface mapping and usage. */
public class HelloWorld {
// This is the standard, stable way of mapping, which supports extensive
// customization and mapping of Java to native types.
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)
Native.load((Platform.isWindows() ? "msvcrt" : "c"),
CLibrary.class);
void printf(String format, Object... args);
}
public static void main(String[] args) {
CLibrary.INSTANCE.printf("Hello, World\n");
for (int i=0;i < args.length;i++) {
CLibrary.INSTANCE.printf("Argument %d: %s\n", i, args[i]);
}
}
}

View File

@@ -0,0 +1,68 @@
/*******************************************************************************
* Copyright (c) 2015-2021 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.fst;
import com.minres.scviewer.database.BitVector;
/**
* The Interface IVCDDatabaseBuilder. It allows to add VCD events into the database
*/
public interface IFstDatabaseBuilder {
/**
* 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, -1 equals real, 0... is a bit vector
* @return the net id
*/
public Integer newNet(String netName, int i, int width) ;
/**
* Gets the net width.
*
* @param intValue the net id
* @return the net width, -1 means a real-valued net
*/
public int getNetWidth(int netId);
/**
* Append transition.
*
* @param netId the int value
* @param currentTime the current time in ps
* @param decodedValues the decoded values
*/
public void appendTransition(int netId, long currentTime, BitVector decodedValue);
/**
* Append transition.
*
* @param netId the int value
* @param currentTime the current time in ps
* @param decodedValue the decoded values
*/
public void appendTransition(int netId, long currentTime, double decodedValue);
}