|
Message
From: cvs at opencores.org<cvs@o...>
Date: Tue Jul 24 15:01:28 CEST 2007
Subject: [cvs-checkins] MODIFIED: jop ...
Date: 00/07/07 24:15:01 Added: jop/java/tools/src/wcet/framework/general AbstractAnalyser.java AbstractDataStore.java AnalyserMain.java SimpleDataStore.java Log: Revision Changes Path 1.1 jop/java/tools/src/wcet/framework/general/AbstractAnalyser.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/framework/general/AbstractAnalyser.java?rev=1.1&content-type=text/x-cvsweb-markup Index: AbstractAnalyser.java =================================================================== /** * */ package wcet.framework.general; import wcet.framework.exceptions.SurplusComponentException; import wcet.framework.exceptions.TaskExecutionException; import wcet.framework.interfaces.general.IAnalyser; import wcet.framework.interfaces.general.IAnalyserComponent; import wcet.framework.interfaces.general.IDataStore; import wcet.framework.interfaces.util.IComponentRunner; import wcet.framework.util.ComponentRunner; /** * @author Elena * @version 0.1 */ public abstract class AbstractAnalyser implements IAnalyser { protected IComponentRunner componentRunner; protected IDataStore dataStore; protected AbstractAnalyser(){ this.componentRunner = new ComponentRunner(); } public void analyse() throws TaskExecutionException{ this.componentRunner.startComponents(); } protected void addComponent(IAnalyserComponent component) throws SurplusComponentException { if (component.getOrder()>0){ this.componentRunner.registerComponent(component); } } protected boolean removeComponent(IAnalyserComponent component) { return this.componentRunner.removeComponent(component); } } 1.1 jop/java/tools/src/wcet/framework/general/AbstractDataStore.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/framework/general/AbstractDataStore.java?rev=1.1&content-type=text/x-cvsweb-markup Index: AbstractDataStore.java =================================================================== /** * */ package wcet.framework.general; import java.io.PrintStream; import java.util.Hashtable; import java.util.List; import java.util.Vector; import wcet.framework.interfaces.cfg.IControlFlowGraph; import wcet.framework.interfaces.constraints.IConstraint; import wcet.framework.interfaces.general.IDataStore; import wcet.framework.interfaces.general.IDataStoreKeys; /** * @author Elena * @version 0.2 */ public abstract class AbstractDataStore implements IDataStore { PrintStream output; Vector<IConstraint> constraints; IControlFlowGraph graph; Hashtable<String, Object> otherObjects; public boolean setClasspath(String cp){ if(cp==null)return false; if (this.otherObjects.containsKey(IDataStoreKeys.CLASSPATH_KEY)){ return false; } else { this.otherObjects.put(IDataStoreKeys.CLASSPATH_KEY, cp); return true; } } public boolean setSourcepath(String sp){
if(sp==null)return false;
if (this.otherObjects.containsKey(IDataStoreKeys.SOURCEPATH_KEY)){
return false;
} else {
this.otherObjects.put(IDataStoreKeys.SOURCEPATH_KEY, sp);
return true;
}
}
public boolean setOutput(PrintStream os){
if(os==null)return false;
if (this.output == null){
this.output = os;
return true;
} else {
return false;
}
}
/* (non-Javadoc)
* @see wcet.interfaces.general.IDataStore#addConstraint(wcet.framework.interfaces.constraints.IConstraint)
*/
public void addConstraint(IConstraint constraint) {
this.constraints.add(constraint);
}
/* (non-Javadoc)
* @see wcet.interfaces.general.IDataStore#addConstraints(java.util.List)
*/
public void addConstraints(List<IConstraint> constraints) {
this.constraints.addAll(constraints);
}
/* (non-Javadoc)
* @see wcet.interfaces.general.IDataStore#getAllConstraints()
*/
public List<IConstraint> getAllConstraints() {
return this.constraints;
}
/* (non-Javadoc)
* @see wcet.interfaces.general.IDataStore#getClasspath()
*/
public String getClasspath() {
return (String)this.otherObjects.get(IDataStoreKeys.CLASSPATH_KEY);
}
/* (non-Javadoc)
* @see wcet.interfaces.general.IDataStore#getSourcepath()
*/
public String getSourcepath() {
return (String)this.otherObjects.get(IDataStoreKeys.SOURCEPATH_KEY);
}
public String getMainMethodDescriptor() {
return (String)this.otherObjects.get(IDataStoreKeys.MAINMETHOD_DESCRIPTOR_KEY);
}
public String getMainMethodName() {
return (String)this.otherObjects.get(IDataStoreKeys.MAINMETHOD_NAME_KEY);
}
public boolean setMainMethodDescriptor(String descriptor) {
if(descriptor==null)return false;
if (this.otherObjects.containsKey(IDataStoreKeys.MAINMETHOD_DESCRIPTOR_KEY)){
return false;
} else {
this.otherObjects.put(IDataStoreKeys.MAINMETHOD_DESCRIPTOR_KEY, descriptor);
return true;
}
}
public boolean setMainMethodName(String name) {
if(name==null)return false;
if (this.otherObjects.containsKey(IDataStoreKeys.MAINMETHOD_NAME_KEY)){
return false;
} else {
this.otherObjects.put(IDataStoreKeys.MAINMETHOD_NAME_KEY, name);
return true;
}
}
/* (non-Javadoc)
* @see wcet.interfaces.general.IDataStore#getGraph()
*/
public IControlFlowGraph getGraph() {
return this.graph;
}
/* (non-Javadoc)
* @see wcet.interfaces.general.IDataStore#getObject(java.lang.String)
*/
public Object getObject(String key) {
return this.otherObjects.get(key);
}
/* (non-Javadoc)
* @see wcet.interfaces.general.IDataStore#getOutput()
*/
public PrintStream getOutput() {
return this.output;
}
/* (non-Javadoc)
* @see wcet.interfaces.general.IDataStore#removeObject(java.lang.String)
*/
public Object removeObject(String key) {
return this.removeObject(key);
}
/* (non-Javadoc)
* @see wcet.interfaces.general.IDataStore#setGraph(wcet.interfaces.graph.IFlowGraph)
*/
public void setGraph(IControlFlowGraph graph) {
this.graph = graph;
}
/* (non-Javadoc)
* @see wcet.interfaces.general.IDataStore#storeObject(java.lang.String, java.lang.Object)
*/
public boolean storeObject(String key, Object obj) {
if(key==null) return false;
this.otherObjects.put(key, obj);
return true;
}
/* (non-Javadoc)
* @see wcet.interfaces.general.IDataStore#isGraphSet()
*/
public boolean isGraphSet() {
return (this.graph==null);
}
public String getTask() {
return (String)this.otherObjects.get(IDataStoreKeys.TASK_KEY);
}
public boolean setTask(String ts) {
if(ts==null) return false;
this.otherObjects.put(IDataStoreKeys.TASK_KEY, ts);
return true;
}
}
1.1 jop/java/tools/src/wcet/framework/general/AnalyserMain.java
http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/framework/general/AnalyserMain.java?rev=1.1&content-type=text/x-cvsweb-markup
Index: AnalyserMain.java
===================================================================
package wcet.framework.general;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;
import java.util.StringTokenizer;
import wcet.framework.exceptions.InitException;
import wcet.framework.exceptions.TaskException;
import wcet.framework.interfaces.general.IAnalyser;
import wcet.framework.interfaces.general.IDataStoreKeys;
import wcet.framework.util.ClassLoaderSingleton;
/**
* Defines some usefull functions needed in most analyser executions.
*
* @author Elena Axamitova
* @version 0.3
*/
public final class AnalyserMain{
/**
* the analyser to run
*/
private IAnalyser analyser = null;
/**
* list of application's entry points
*/
private ArrayList<String> classes = new ArrayList<String>();
/**
* the name of the file where the application should be witten
*/
private String output = null;
/**
* the full path to jars/directories of the analyser, when not already in
* the java classpath
*/
private String librarypath = null;
/**
* the full path to jars/directories containing class files of the
* application
*/
private String classpath = null;
/**
* the full path to jars/directories containing source files of the
* application
*/
private String sourcepath = null;
/**
* the name of the main method of the application
*/
private String mainMethodName = null;
/**
* the description of the main method of the application
*/
private String mainMethodDescriptor = null;
/**
* the path to the property file containing arguments and settings for the
* analyser. If an argument is specified both in the property file and in the
* command line, command line value is used.
*/
private String propertyFile = null;
/**
* arguments specified either in command line or in the property file
*/
private Properties arguments = null;
private String analyserClass;
/**
* Process the command line arguments
*
* @param args -
* the command line arguments
*/
private void parseArguments(String[] args) {
for (int i = 1; i < args.length; i++) {
if (args[i].equals("-lp")) {
this.librarypath = args[++i];
} else if (args[i].equals("-cp")) {
this.classpath = args[++i];
} else if (args[i].equals("-sp")) {
this.sourcepath = args[++i];
} else if (args[i].equals("-o")) {
this.output = args[++i];
} else if (args[i].equals("-mn")) {
this.mainMethodName = args[++i];
} else if (args[i].equals("-md")) {
this.mainMethodDescriptor = args[++i];
} else if (args[i].equals("-pf")) {
this.propertyFile = args[++i];
} else {
this.classes.add(args[i]);
}
}
}
/**
* Start the analyser for all given application's entry points (the class
* command line arguments).
*/
private void processTasks() {
try {
this.init(this.arguments);
Iterator<String> iterator = this.classes.iterator();
while (iterator.hasNext()) {
this.analyser.setTask(iterator.next());
this.analyser.analyse();
}
} catch (InitException e) {
System.err.println("Problems occurred during init of "
+ this.analyser.getClass().getCanonicalName() + ":");
e.printStackTrace();
} catch (TaskException e) {
System.err.println("Problems occurred during execution of "
+ this.analyser.getClass().getCanonicalName() + ":");
e.printStackTrace();
}
}
private void getAllArguments(){
this.arguments = new Properties ();
if (this.propertyFile != null) {
try {
this.arguments.loadFromXML(new FileInputStream(propertyFile));
} catch (Exception e) {
System.err.println("Bad property file specified:");
e.printStackTrace();
}
}
if (this.classpath != null) {
this.arguments.put(IDataStoreKeys.CLASSPATH_KEY, this.classpath);
}
if (this.sourcepath != null) {
this.arguments.put(IDataStoreKeys.SOURCEPATH_KEY, this.sourcepath);
}
if (this.output != null) {
this.arguments.put(IDataStoreKeys.OUTPUT_KEY, this.output);
}
if (this.mainMethodName != null) {
this.arguments.put(IDataStoreKeys.MAINMETHOD_NAME_KEY, this.mainMethodName);
}
if (this.mainMethodDescriptor!= null) {
this.arguments.put(IDataStoreKeys.MAINMETHOD_DESCRIPTOR_KEY, this.mainMethodDescriptor);
}
if (this.librarypath != null) {
this.arguments.put(IDataStoreKeys.LIBRARYPATH_KEY, librarypath);
}
}
/**
* @param args -
* Arguments passed to the analyser. Call without any arguments
* to get the usage.
*/
public static void main(String[] args) {
if (args.length < 2) {
System.err
.println("Usage: <analyser class> [-cp classpath] [-sp sourcepath] [-o <output file>] [-mn <main method name>] [-md <main method descriptor>] [-pf <property file path>] class [class]*");
} else {
AnalyserMain mainObject = new AnalyserMain();
mainObject.parseArguments(args);
mainObject.getAllArguments();
mainObject.analyserClass= args[0];
mainObject.processTasks();
}
}
private void init(Properties arguments) throws InitException {
try {
if(this.librarypath!=null)
this.loadJars();
Class clazz = ClassLoaderSingleton.getInstance().loadClass(
this.analyserClass);
this.analyser = (IAnalyser) clazz.newInstance();
this.analyser.init(arguments);
} catch (Exception e) {
throw new InitException(e);
}
}
private void loadJars() throws InitException {
StringTokenizer strtok = new StringTokenizer(this.librarypath, File.pathSeparator);
while(strtok.hasMoreTokens()){
ClassLoaderSingleton.addLibrary(strtok.nextToken());
}
}
}
1.1 jop/java/tools/src/wcet/framework/general/SimpleDataStore.java
http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/framework/general/SimpleDataStore.java?rev=1.1&content-type=text/x-cvsweb-markup
Index: SimpleDataStore.java
===================================================================
/**
*
*/
package wcet.framework.general;
import java.util.Hashtable;
import java.util.Vector;
import wcet.framework.interfaces.constraints.IConstraint;
/**
* @author Elena
* @version 0.1
*/
public final class SimpleDataStore extends AbstractDataStore {
public SimpleDataStore(){
this.output = null;
this.graph = null;
this.constraints = new Vector<IConstraint>();
this.otherObjects = new Hashtable<String, Object>();
}
}
|
 |