2009-01-09 02:52:56 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* 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:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*****************************************************************************/
|
|
|
|
package com.ibm.wala.cast.java.translator.polyglot;
|
|
|
|
|
2011-04-27 14:55:30 +00:00
|
|
|
import polyglot.frontend.ExtensionInfo;
|
2009-01-09 02:52:56 +00:00
|
|
|
import polyglot.frontend.Job;
|
|
|
|
import polyglot.frontend.Scheduler;
|
2011-04-27 14:55:30 +00:00
|
|
|
import polyglot.frontend.SourceGoal_c;
|
2009-01-09 02:52:56 +00:00
|
|
|
|
|
|
|
import com.ibm.wala.cast.java.loader.JavaSourceLoaderImpl;
|
|
|
|
import com.ibm.wala.cast.java.translator.Java2IRTranslator;
|
|
|
|
|
|
|
|
/**
|
2011-04-27 14:55:30 +00:00
|
|
|
* A kind of EndGoal that indicates that WALA IR has been generated for the given compilation unit.
|
2009-01-09 02:52:56 +00:00
|
|
|
* @author rfuhrer
|
|
|
|
*/
|
2011-04-27 16:20:21 +00:00
|
|
|
public class IRGoal extends SourceGoal_c /* PORT1.7 removed 'implements EndGoal' */ {
|
2011-04-27 16:46:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private static final long serialVersionUID = -8023929848709826817L;
|
|
|
|
|
2009-04-13 19:39:48 +00:00
|
|
|
private JavaSourceLoaderImpl fSourceLoader;
|
2009-01-09 02:52:56 +00:00
|
|
|
|
2011-04-27 16:20:21 +00:00
|
|
|
protected Java2IRTranslator fTranslator;
|
|
|
|
|
2009-04-13 19:39:48 +00:00
|
|
|
public IRGoal(Job job, JavaSourceLoaderImpl sourceLoader) {
|
|
|
|
super(job);
|
|
|
|
fSourceLoader = sourceLoader;
|
2011-04-27 16:20:21 +00:00
|
|
|
|
|
|
|
Scheduler scheduler= job.extensionInfo().scheduler();
|
|
|
|
|
|
|
|
addPrereq(scheduler.TypeChecked(job));
|
|
|
|
// PORT1.7 - TypeChecked will suffice for what used to require ConstantsChecked.
|
|
|
|
// Need ConstantsChecked in order to make sure that case statements have non-zero labels.
|
|
|
|
// addPrereq(scheduler.ConstantsChecked(job));
|
|
|
|
// Need to add an AscriptionGoal as a prereq to make sure that empty array initializers get a type ascribed.
|
|
|
|
addPrereq(new AscriptionGoal(job));
|
2009-04-13 19:39:48 +00:00
|
|
|
}
|
2009-01-09 02:52:56 +00:00
|
|
|
|
2011-04-27 16:20:21 +00:00
|
|
|
@Override
|
|
|
|
public boolean runTask() {
|
|
|
|
ExtensionInfo extInfo= job.extensionInfo();
|
|
|
|
|
|
|
|
fTranslator= new Java2IRTranslator(
|
2012-01-27 20:15:33 +00:00
|
|
|
fSourceLoader,
|
|
|
|
((IRTranslatorExtension)extInfo).getCAstRewriterFactory());
|
|
|
|
ModuleSource src = (ModuleSource) job.source();
|
|
|
|
fTranslator.translate(
|
|
|
|
src.getModule(),
|
2011-04-27 16:20:21 +00:00
|
|
|
new PolyglotJava2CAstTranslator(
|
2012-01-27 20:15:33 +00:00
|
|
|
job.ast(),
|
2011-04-27 16:20:21 +00:00
|
|
|
fSourceLoader.getReference(),
|
|
|
|
extInfo.nodeFactory(),
|
|
|
|
extInfo.typeSystem(),
|
|
|
|
new PolyglotIdentityMapper(fSourceLoader.getReference()),
|
2012-01-27 20:15:33 +00:00
|
|
|
((IRTranslatorExtension)extInfo).getReplicateForDoLoops()).translateToCAst());
|
2011-04-27 16:20:21 +00:00
|
|
|
return true;
|
2009-04-13 19:39:48 +00:00
|
|
|
}
|
2009-01-09 02:52:56 +00:00
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2009-04-13 19:39:48 +00:00
|
|
|
public String name() {
|
2011-04-27 16:20:21 +00:00
|
|
|
return "<WALA IR goal for " + job.source().path() + ">";
|
2009-04-13 19:39:48 +00:00
|
|
|
}
|
2009-01-09 02:52:56 +00:00
|
|
|
}
|