From d8f82e17de29669028794f6ddeb45e4b6ae24506 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Tue, 1 Jun 2021 15:18:21 +0200 Subject: [PATCH] Added plumbing for testing D (not final, we shall use LLVM) code generation --- source/tlang/compiler/codegen/dgen.d | 35 ++++++++++++++++++++++++++++ source/tlang/compiler/compiler.d | 3 +++ 2 files changed, 38 insertions(+) create mode 100644 source/tlang/compiler/codegen/dgen.d diff --git a/source/tlang/compiler/codegen/dgen.d b/source/tlang/compiler/codegen/dgen.d new file mode 100644 index 0000000..3df0332 --- /dev/null +++ b/source/tlang/compiler/codegen/dgen.d @@ -0,0 +1,35 @@ +module compiler.codegen.dgen; + +import compiler.symbols.data; +import compiler.codegen.core; +import gogga; + +/** +* This is only for testing, we will definately be using LLVM +* as we want control and no dmd runtime +*/ +public class DCodeGenerator : CodeGenerator +{ + this(Module modulle) + { + super(modulle); + } + + public void build() + { + Statement[] statements = modulle.getStatements(); + + foreach(Statement statement; statements) + { + /* Only for emiitables */ + Emittable emitter = cast(Emittable)statement; + + if(emitter) + { + string emittedCode = emitter.emit(); + gprintln("Emitted: "~emittedCode); + } + + } + } +} \ No newline at end of file diff --git a/source/tlang/compiler/compiler.d b/source/tlang/compiler/compiler.d index 4c20e97..f0e06de 100644 --- a/source/tlang/compiler/compiler.d +++ b/source/tlang/compiler/compiler.d @@ -62,6 +62,9 @@ void beginCompilation(string[] sourceFiles) { gprintln(e.msg, DebugType.ERROR); } + + import compiler.codegen.core; + CodeGenerator codegen = new CodeGenerator(modulle); // typeChecker.check(); }