1 module sdc.sdc; 2 3 final class SDC { 4 import source.context; 5 Context context; 6 7 import d.semantic.semantic; 8 SemanticPass semantic; 9 10 import d.llvm.backend; 11 LLVMBackend backend; 12 13 import d.ir.symbol; 14 Module[] modules; 15 16 import sdc.config; 17 this(Context context, string name, Config config) { 18 this.context = context; 19 20 import std.algorithm, std.array, std.conv, std.path; 21 auto includePaths = config 22 .includePaths 23 .map!( 24 p => expandTilde(p).asAbsolutePath.asNormalizedPath.to!string()) 25 .array(); 26 27 LLVMBackend evBackend; 28 29 import d.semantic.evaluator; 30 Evaluator evb(SemanticPass pass) { 31 if (evBackend is null) { 32 evBackend = new LLVMBackend(pass, name, config.optLevel, 33 config.linkerPaths); 34 } 35 36 return evBackend.getEvaluator(); 37 } 38 39 import d.semantic.datalayout, d.object; 40 DataLayout dlb(ObjectReference) { 41 assert(evBackend !is null); 42 return evBackend.getDataLayout(); 43 } 44 45 semantic = new SemanticPass(context, includePaths, 46 config.enableUnittest, &evb, &dlb); 47 backend = new LLVMBackend(semantic, name, config.optLevel, 48 config.linkerPaths); 49 } 50 51 void compile(string filename) { 52 modules ~= semantic.add(filename); 53 } 54 55 void buildMain() { 56 semantic.terminate(); 57 backend.visit(semantic.buildMain(modules[0])); 58 } 59 60 void outputLLVMAsm(string filename) { 61 semantic.terminate(); 62 backend.emitLLVMAsm(modules, filename); 63 } 64 65 void outputLLVMBitcode(string filename) { 66 semantic.terminate(); 67 backend.emitLLVMBitcode(modules, filename); 68 } 69 70 void outputAsm(string filename) { 71 semantic.terminate(); 72 backend.emitAsm(modules, filename); 73 } 74 75 void outputObj(string objFile) { 76 semantic.terminate(); 77 backend.emitObject(modules, objFile); 78 } 79 80 void linkExecutable(string objFile, string executable) { 81 backend.link(objFile, executable); 82 } 83 84 auto runUnittests() { 85 semantic.terminate(); 86 return backend.runUnittests(modules); 87 } 88 }