Mercurial > projects > dang
diff dang/compiler.d @ 136:2be29b296081
Lots of changes:
- Parsing classes and interfaces
- Fixed some seg faults in sema
- Supporting "private" to some extend
- And a lot of other small fixes
author | johnsen@johnsen-laptop |
---|---|
date | Fri, 11 Jul 2008 21:47:57 +0200 |
parents | 3a0cd42de9cc |
children | 6c5a3c0bb4fb |
line wrap: on
line diff
--- a/dang/compiler.d Wed Jul 09 13:38:11 2008 +0200 +++ b/dang/compiler.d Fri Jul 11 21:47:57 2008 +0200 @@ -5,6 +5,7 @@ tango.core.Memory, tango.sys.Process, tango.time.StopWatch, + tango.text.Util, tango.io.FileConduit, tango.io.FilePath; @@ -30,8 +31,13 @@ sema.TypeCheck; import tango.stdc.posix.unistd; +import tango.stdc.stdlib; import Opt = dang.OptParse; + +class NullAction : Action +{ +} void checkFiles(char[][] *files) { @@ -64,7 +70,7 @@ if (fileInStack) continue; - validFiles ~= file; + validFiles ~= path.toString(); } *files = validFiles; @@ -86,6 +92,7 @@ Signal!(Lexer) preParse; Signal!(Module[], SourceManager) postParse; + Signal!(Module[], SourceManager) postSema; preStart.attach(&checkFiles); @@ -113,6 +120,9 @@ argParse.addOption(["-c"], "what-to-do", Opt.Action.StoreConst, "compile") .help("Compile to .o or executeable"); + argParse.addOption(["--syntax-only"], + "what-to-do", Opt.Action.StoreConst, "parse") + .help("Only parse the file(s) and output parseing errors."); argParse.addOption( ["-O","--optimize"], { @@ -142,10 +152,12 @@ auto what = options["what-to-do"]; if (what == "" || what == "gen-llvm") - postParse.attach( + postSema.attach( (Module[] modules, SourceManager sm) { foreach(m ; modules) { + if (!m.outputModule) + continue; StopWatch w; w.start; auto llvmGen = new CodeGen(); auto file = new FileConduit(m.moduleName~".bc", FileConduit.WriteCreate); @@ -154,14 +166,16 @@ } }); else if (what == "compile") - postParse.attach( + postSema.attach( (Module[] modules, SourceManager sm) { foreach(m ; modules) { + if (!m.outputModule) + continue; StopWatch w; w.start; auto llvmGen = new CodeGen(); auto llc = new Process("llc","-o=-"); - auto gcc = new Process("gcc","-c","-o","out.o","-x","assembler","-"); + auto gcc = new Process("gcc","-c","-o",m.moduleName~".o","-x","assembler","-"); llc.execute(); int i = dup(llc.stdin.fileHandle); llc.stdin.detach; @@ -175,8 +189,17 @@ } }); + else if (what == "parse") + preParse.attach( + (Lexer lexer) { + auto parser = new Parser(messages); + auto action = new NullAction(); + parser.parse(src_mgr, lexer, action); + messages.checkErrors(ExitLevel.Parser); + exit(0); + }); else if (what == "dot") - postParse.attach( + postSema.attach( (Module[] m, SourceManager sm) { StopWatch w; w.start; // auto print = new DotPrinter(); @@ -184,12 +207,13 @@ timings ~= Measurement("Generating dot output", w.stop); }); else if (what == "code") - postParse.attach( + postSema.attach( (Module[] modules, SourceManager sm) { StopWatch w; w.start; auto print = new AstPrinter(sm); foreach ( m ; modules ) - print.print(m); + if (m.outputModule) + print.print(m); timings ~= Measurement("Converting AST to text", w.stop); }); StopWatch total; @@ -242,6 +266,44 @@ } (new LiteralInterpreter(messages)).visit(modules); + messages.checkErrors; + postParse(modules, src_mgr); + + class ModuleLoader : Visitor!(void) + { + Module[] visit(Module[] modules, MessageHandler messages, SourceManager src_mgr) + { + this.modules = modules; + this.messages = messages; + this.src_mgr = src_mgr; + super.visit(modules); + return this.modules; + } + + override void visitImportDecl(ImportDecl decl) + { + char[] path = replace!(char)(decl.get,'.','/')~".d"; + + auto start = src_mgr.addFile(path); + auto lexer = new Lexer(start, src_mgr, messages); + + auto parser = new Parser(messages); + auto action = new AstAction(src_mgr); + + Module m = cast(Module)parser.parse(src_mgr, lexer, action); + modules ~= m; + m.outputModule = false; + // decl.env.mHandle.add(m); + messages.checkErrors(ExitLevel.Parser); + } + + Module[] modules; + SourceManager src_mgr; + MessageHandler messages; + } + + modules = (new ModuleLoader()).visit(modules, messages, src_mgr); + messages.checkErrors; (new ScopeBuilder).visit(modules); StopWatch watch2; @@ -261,7 +323,7 @@ decl.simplify(); timings ~= Measurement("Total", total.stop); - postParse(modules, src_mgr); + postSema(modules, src_mgr); if (options.flag("time")) foreach (m; timings)