@@ -6,7 +6,7 @@ import org.parboiled2.ParseError
66import tip .analysis .FlowSensitiveAnalysis .{Analysis => dfa , AnalysisOption => dfo }
77import tip .analysis ._
88import tip .ast .AstNodeData ._
9- import tip .ast .AProgram
9+ import tip .ast .{ AProgram , NoNormalizer }
1010import tip .concolic .ConcolicEngine
1111import tip .cfg ._
1212import tip .interpreter .ConcreteInterpreter
@@ -20,7 +20,6 @@ import scala.util.{Failure, Success}
2020 * Options for running the TIP system.
2121 */
2222class RunOption {
23- val log = Log .logger[this .type ]()
2423
2524 /**
2625 * If set, construct the (intraprocedural) control-flow graph after parsing.
@@ -82,7 +81,7 @@ class RunOption {
8281 */
8382 def check (): Boolean =
8483 if (source == null ) {
85- log.error(s " Source file/directory missing " )
84+ Tip . log.error(s " Source file/directory missing " )
8685 false
8786 } else
8887 true
@@ -158,9 +157,17 @@ object Tip extends App {
158157 */
159158 def processFile (file : File , options : RunOption ) = {
160159 try {
161- val program = Source .fromFile(file).mkString
160+ val program = {
161+ val bs = Source .fromFile(file)
162+ try {
163+ bs.mkString
164+ } finally {
165+ bs.close()
166+ }
167+ }
162168
163169 // parse the program
170+ log.verb(" Parsing" )
164171 val tipParser = new TipParser (program)
165172 val res = tipParser.InputLine .run()
166173
@@ -173,17 +180,21 @@ object Tip extends App {
173180 sys.exit(1 )
174181 case Success (parsedNode : AProgram ) =>
175182 // run normalizer
183+ log.verb(" Normalizing" )
176184 val programNode = options.normalizer.normalizeProgram(parsedNode)
177- Output .output(file, OtherOutput (OutputKindE .normalized), programNode.toString, options.out)
185+ if (options.normalizer != NoNormalizer )
186+ Output .output(file, OtherOutput (OutputKindE .normalized), programNode.toString, options.out)
178187
179188 // run declaration analysis
180189 // (for information about the use of 'implicit', see [[tip.analysis.TypeAnalysis]])
190+ log.verb(" Declaration analysis" )
181191 implicit val declData : DeclarationData = new DeclarationAnalysis (programNode).analyze()
182192
183193 // run selected intraprocedural flow-sensitive analyses
184194 if (options.cfg | options.dfAnalysis.exists(p => p._2 != dfo.Disabled && ! dfo.interprocedural(p._2))) {
185195
186196 // generate control-flow graph
197+ log.verb(" Building intraprocedural control flow graphs" )
187198 val wcfg = IntraproceduralProgramCfg .generateFromProgram(programNode)
188199 if (options.cfg)
189200 Output .output(file, OtherOutput (OutputKindE .cfg), wcfg.toDot({ x =>
@@ -195,6 +206,7 @@ object Tip extends App {
195206 if (! dfo.interprocedural(v)) {
196207 FlowSensitiveAnalysis .select(s, v, wcfg).foreach { an =>
197208 // run the analysis
209+ log.verb(s " Performing ${an.getClass.getSimpleName}" )
198210 val res = an.analyze().asInstanceOf [Map [CfgNode , _]]
199211 Output .output(file, DataFlowOutput (s), wcfg.toDot(Output .labeler(res), Output .dotIder), options.out)
200212 }
@@ -207,8 +219,10 @@ object Tip extends App {
207219
208220 // generate control-flow graph
209221 val wcfg = if (options.cfa) {
222+ log.verb(" Building interprocedural control flow graph using control flow analysis" )
210223 InterproceduralProgramCfg .generateFromProgramWithCfa(programNode)
211224 } else {
225+ log.verb(" Building interprocedural control flow graph" )
212226 InterproceduralProgramCfg .generateFromProgram(programNode)
213227 }
214228
@@ -223,6 +237,7 @@ object Tip extends App {
223237 if (dfo.interprocedural(v)) {
224238 FlowSensitiveAnalysis .select(s, v, wcfg).foreach { an =>
225239 // run the analysis
240+ log.verb(s " Starting ${an.getClass.getSimpleName}" )
226241 val res = an.analyze()
227242 val res2 =
228243 if (dfo.contextsensitive(v))
@@ -238,19 +253,22 @@ object Tip extends App {
238253 // run type analysis, if selected
239254 if (options.types) {
240255 // (for information about the use of 'implicit', see [[tip.analysis.TypeAnalysis]])
256+ log.verb(" Starting TypeAnalysis" )
241257 implicit val typeData : TypeData = new TypeAnalysis (programNode).analyze()
242258 Output .output(file, OtherOutput (OutputKindE .types), programNode.toTypedString, options.out)
243259 }
244260
245261 // run Andersen analysis, if selected
246262 if (options.andersen) {
263+ log.verb(" Starting AndersenAnalysis" )
247264 val s = new AndersenAnalysis (programNode)
248265 s.analyze()
249266 s.pointsTo()
250267 }
251268
252269 // run Steensgaard analysis, if selected
253270 if (options.steensgaard) {
271+ log.verb(" Starting SteensgaardAnalysis" )
254272 val s = new SteensgaardAnalysis (programNode)
255273 s.analyze()
256274 s.pointsTo()
@@ -259,31 +277,34 @@ object Tip extends App {
259277 // run control-flow analysis, if selected
260278 if (options.cfa) { // TODO: skip if InterproceduralProgramCfg.generateFromProgramWithCfa has been executed above
261279 val s = new ControlFlowAnalysis (programNode)
280+ log.verb(" Starting ControlFlowAnalysis" )
262281 s.analyze()
263282 }
264283
265284 // execute the program, if selected
266285 if (options.run) {
286+ log.verb(" Starting ConcreteInterpreter" )
267287 val intp = new ConcreteInterpreter (programNode)
268288 intp.semp()
269289 }
270290
271291 // concolically execute the program, if selected
272292 if (options.concolic) {
293+ log.verb(" Starting ConcolicEngine" )
273294 new ConcolicEngine (programNode).test()
274295 }
275-
276- log.info(" Success" )
277296 }
278297 } catch {
298+ case e : TipProgramException =>
299+ log.error(e.getMessage)
300+ sys.exit(1 )
279301 case e : Exception =>
280- log.error(s " Error : ${e.getMessage}" , e)
302+ log.error(s " Internal error : ${e.getMessage}" , e)
281303 sys.exit(1 )
282304 }
283305 }
284306
285307 // parse options
286- Log .defaultLevel = Log .Level .Info
287308 val options = new RunOption ()
288309 var i = 0
289310 while (i < args.length) {
@@ -322,6 +343,7 @@ object Tip extends App {
322343 options.concolic = true
323344 case " -verbose" =>
324345 Log .defaultLevel = Log .Level .Verbose
346+ log.level = Log .Level .Verbose
325347 case _ =>
326348 log.error(s " Unrecognized option $s" )
327349 printUsage()
0 commit comments