| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | // Copyright 2009 The Go Authors.  All rights reserved. | 
					
						
							|  |  |  | // Use of this source code is governed by a BSD-style | 
					
						
							|  |  |  | // license that can be found in the LICENSE file. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package Compilation | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | import Utils "utils" | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | import Globals "globals" | 
					
						
							|  |  |  | import Object "object" | 
					
						
							|  |  |  | import Type "type" | 
					
						
							| 
									
										
										
										
											2008-07-15 19:59:00 -07:00
										 |  |  | import Universe "universe" | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | import Scanner "scanner" | 
					
						
							| 
									
										
										
										
											2008-07-18 17:18:29 -07:00
										 |  |  | import AST "ast" | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | import Parser "parser" | 
					
						
							| 
									
										
										
										
											2008-07-16 17:00:48 -07:00
										 |  |  | import Export "export" | 
					
						
							| 
									
										
										
										
											2008-07-30 13:01:28 -07:00
										 |  |  | import Printer "printer" | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | import Verifier "verifier" | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export Compile | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | func Compile(comp *Globals.Compilation, file_name string) { | 
					
						
							| 
									
										
										
										
											2008-07-17 18:02:10 -07:00
										 |  |  | 	src, ok := sys.readfile(file_name); | 
					
						
							| 
									
										
										
										
											2008-07-15 19:59:00 -07:00
										 |  |  | 	if !ok { | 
					
						
							| 
									
										
										
										
											2008-07-17 18:02:10 -07:00
										 |  |  | 		print "cannot open ", file_name, "\n" | 
					
						
							| 
									
										
										
										
											2008-07-15 19:59:00 -07:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-07-17 18:02:10 -07:00
										 |  |  | 	scanner := new(Scanner.Scanner); | 
					
						
							|  |  |  | 	scanner.Open(file_name, src); | 
					
						
							| 
									
										
										
										
											2008-07-15 19:59:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-17 18:02:10 -07:00
										 |  |  | 	parser := new(Parser.Parser); | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 	parser.Open(comp, scanner); | 
					
						
							| 
									
										
										
										
											2008-07-17 18:02:10 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	print "parsing ", file_name, "\n"; | 
					
						
							|  |  |  | 	parser.ParseProgram(); | 
					
						
							|  |  |  | 	if parser.S.nerrors > 0 { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-15 19:59:00 -07:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	if !comp.flags.semantic_checks { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	Verifier.Verify(comp); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if comp.flags.print_export { | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 		Printer.PrintObject(comp, comp.pkgs[0].obj, false); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	Export.Export(comp, file_name); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | } |