Skip to content

Commit a5d94fb

Browse files
committed
Adds llvm code gen pass
1 parent c7eb287 commit a5d94fb

9 files changed

+2283
-1811
lines changed

compiler/smmllvmcodegen.c

+446
Large diffs are not rendered by default.

compiler/smmllvmcodegen.h

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef SMM_LLVM_CODE_GEN_H
2+
#define SMM_LLVM_CODE_GEN_H
3+
4+
#include "ibscommon.h"
5+
#include "ibsallocator.h"
6+
#include "smmparser.h"
7+
8+
void smmExecuteLLVMCodeGenPass(PSmmAstNode module, PIbsAllocator a);
9+
10+
#endif

compiler/smmsempass.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static void processExpression(
219219

220220
static void processLocalSymbols(PSmmAstDeclNode decl, PSmmMsgs msgs, PIbsAllocator a) {
221221
while (decl) {
222-
if (decl->left->kind == nkSmmConst) {
222+
if (decl->left->left->kind == nkSmmConst) {
223223
processExpression(&decl->left->right, decl->left->type, false, msgs, a);
224224
}
225225
decl = decl->nextDecl;

compiler/smmtypeinference.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ static PSmmAstDeclNode processGlobalSymbols(PSmmAstDeclNode decl, PTIData tidata
627627
if (decl->left->kind == nkSmmFunc) {
628628
*funcDeclField = decl;
629629
funcDeclField = &decl->nextDecl;
630+
PSmmAstFuncDefNode funcNode = &decl->left->asFunc;
631+
funcNode->token->stringVal = getMangledName(funcNode, a);
630632
} else {
631633
*varDeclField = decl;
632634
varDeclField = &decl->nextDecl;
@@ -666,7 +668,6 @@ void processFuncDecls(PTIData tidata, PIbsAllocator a) {
666668
tidata->isInMainCode = false;
667669
while (decl) {
668670
PSmmAstFuncDefNode funcNode = &decl->left->asFunc;
669-
funcNode->token->stringVal = getMangledName(funcNode, a);
670671
if (funcNode->body) {
671672
PSmmAstParamNode param = funcNode->params;
672673
while (param) {

compiler/summus.c

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "smmparser.h"
77
#include "smmtypeinference.h"
88
#include "smmsempass.h"
9+
#include "smmllvmcodegen.h"
910
#include "../utility/smmgvpass.h"
1011

1112
#include <assert.h>
@@ -60,10 +61,15 @@ int main(int argc, char* argv[]) {
6061

6162
if (!pp[0] && !pp[1] && !pp[2]) {
6263
smmFlushMessages(&msgs);
64+
} else {
65+
return EXIT_SUCCESS;
6366
}
6467

6568
if (smmHadErrors(&msgs)) {
6669
return EXIT_FAILURE;
6770
}
71+
72+
smmExecuteLLVMCodeGenPass(module, a);
73+
6874
return EXIT_SUCCESS;
6975
}

summus.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
<ClInclude Include="compiler\ibscommon.h" />
184184
<ClInclude Include="compiler\ibsdictionary.h" />
185185
<ClInclude Include="compiler\smmlexer.h" />
186+
<ClInclude Include="compiler\smmllvmcodegen.h" />
186187
<ClInclude Include="compiler\smmmsgs.h" />
187188
<ClInclude Include="compiler\smmparser.h" />
188189
<ClInclude Include="compiler\smmsempass.h" />
@@ -209,6 +210,7 @@
209210
<ClCompile Include="compiler\ibsallocator.c" />
210211
<ClCompile Include="compiler\ibsdictionary.c" />
211212
<ClCompile Include="compiler\smmlexer.c" />
213+
<ClCompile Include="compiler\smmllvmcodegen.c" />
212214
<ClCompile Include="compiler\smmmsgs.c" />
213215
<ClCompile Include="compiler\smmparser.c" />
214216
<ClCompile Include="compiler\smmsempass.c" />

summus.vcxproj.filters

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
<ClInclude Include="compiler\smmsempass.h">
6161
<Filter>Header Files</Filter>
6262
</ClInclude>
63+
<ClInclude Include="compiler\smmllvmcodegen.h">
64+
<Filter>Header Files</Filter>
65+
</ClInclude>
6366
</ItemGroup>
6467
<ItemGroup>
6568
<None Include="tests\test.smm">
@@ -118,5 +121,8 @@
118121
<ClCompile Include="compiler\smmsempass.c">
119122
<Filter>Source Files</Filter>
120123
</ClCompile>
124+
<ClCompile Include="compiler\smmllvmcodegen.c">
125+
<Filter>Source Files</Filter>
126+
</ClCompile>
121127
</ItemGroup>
122128
</Project>

tests/ast.svg

+1,796-1,796
Loading

tests/test.ll

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; ModuleID = 'test.smm'
2+
source_filename = "test.smm"
23
target triple = "x86_64-pc-windows-msvc"
34

45
@ui32 = global i32 100
@@ -65,12 +66,12 @@ entry:
6566
%28 = icmp sgt i64 %25, %27
6667
br i1 %28, label %29, label %32
6768

68-
; <label>:29 ; preds = %entry
69+
; <label>:29: ; preds = %entry
6970
%30 = load i8, i8* %z, align 1
7071
%31 = icmp ne i8 %30, 0
7172
br label %32
7273

73-
; <label>:32 ; preds = %29, %entry
74+
; <label>:32: ; preds = %29, %entry
7475
%33 = phi i1 [ false, %entry ], [ %31, %29 ]
7576
store i1 %33, i1* %a, align 1
7677
%34 = load double, double* %f64, align 8
@@ -79,12 +80,12 @@ entry:
7980
%37 = fcmp olt double %34, %36
8081
br i1 %37, label %41, label %38
8182

82-
; <label>:38 ; preds = %32
83+
; <label>:38: ; preds = %32
8384
%39 = load float, float* %f32, align 4
8485
%40 = fcmp ogt float %39, 0xC2E5897900000000
8586
br label %41
8687

87-
; <label>:41 ; preds = %38, %32
88+
; <label>:41: ; preds = %38, %32
8889
%42 = phi i1 [ true, %32 ], [ %40, %38 ]
8990
store i1 %42, i1* %b, align 1
9091
store i1 false, i1* %c, align 1
@@ -96,41 +97,41 @@ entry:
9697
%43 = load i1, i1* %a, align 1
9798
br i1 %43, label %46, label %44
9899

99-
; <label>:44 ; preds = %41
100+
; <label>:44: ; preds = %41
100101
%45 = load i1, i1* %b, align 1
101102
br i1 %45, label %46, label %53
102103

103-
; <label>:46 ; preds = %44, %41
104+
; <label>:46: ; preds = %44, %41
104105
%47 = load i1, i1* %c, align 1
105106
br i1 %47, label %50, label %48
106107

107-
; <label>:48 ; preds = %46
108+
; <label>:48: ; preds = %46
108109
%49 = load i1, i1* %d, align 1
109110
br label %50
110111

111-
; <label>:50 ; preds = %48, %46
112+
; <label>:50: ; preds = %48, %46
112113
%51 = phi i1 [ true, %46 ], [ %49, %48 ]
113114
%52 = xor i1 %51, true
114115
br label %53
115116

116-
; <label>:53 ; preds = %50, %44
117+
; <label>:53: ; preds = %50, %44
117118
%54 = phi i1 [ false, %44 ], [ %52, %50 ]
118119
%55 = load i1, i1* %e, align 1
119120
br i1 %55, label %62, label %56
120121

121-
; <label>:56 ; preds = %53
122+
; <label>:56: ; preds = %53
122123
%57 = load i1, i1* %f, align 1
123124
br i1 %57, label %62, label %58
124125

125-
; <label>:58 ; preds = %56
126+
; <label>:58: ; preds = %56
126127
%59 = load i1, i1* %g, align 1
127128
br i1 %59, label %60, label %62
128129

129-
; <label>:60 ; preds = %58
130+
; <label>:60: ; preds = %58
130131
%61 = load i1, i1* %h, align 1
131132
br label %62
132133

133-
; <label>:62 ; preds = %60, %58, %56, %53
134+
; <label>:62: ; preds = %60, %58, %56, %53
134135
%63 = phi i1 [ true, %53 ], [ true, %56 ], [ false, %58 ], [ %61, %60 ]
135136
%64 = icmp ne i1 %54, %63
136137
%65 = zext i1 %64 to i32

0 commit comments

Comments
 (0)