-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
149 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
int glb = 39; | ||
int other = 9; | ||
|
||
int main() { | ||
other = 3; | ||
return glb+other; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
; ModuleID = '003_global.c' | ||
source_filename = "003_global.c" | ||
target datalayout = "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16" | ||
target triple = "msp430-unknown-unknown-elf" | ||
|
||
@glb = dso_local global i16 39, align 2 | ||
@other = dso_local global i16 9, align 2 | ||
|
||
; Function Attrs: noinline nounwind optnone | ||
define dso_local i16 @main() #0 { | ||
%1 = alloca i16, align 2 | ||
store i16 0, i16* %1, align 2 | ||
store i16 3, i16* @other, align 2 | ||
%2 = load i16, i16* @glb, align 2 | ||
%3 = load i16, i16* @other, align 2 | ||
%4 = add nsw i16 %2, %3 | ||
ret i16 %4 | ||
} | ||
|
||
attributes #0 = { noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
|
||
!llvm.module.flags = !{!0} | ||
!llvm.ident = !{!1} | ||
|
||
!0 = !{i32 1, !"wchar_size", i32 2} | ||
!1 = !{!"Apple clang version 14.0.3 (clang-1403.0.22.14.1)"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
TESTS = 000_simple.ll 001_add.ll 002_fib.ll | ||
TESTS = 000_simple.ll 001_add.ll 002_fib.ll 003_global.ll | ||
|
||
all: $(TESTS) | ||
|
||
%.ll: %.c | ||
clang --target=msp430-unknown-elf -march=msp430 -ffreestanding -fno-builtin -nostdlib -emit-llvm -S $< | ||
clang --target=msp430-unknown-elf -march=msp430 -nostdlib -emit-llvm -S $< | ||
|
||
clean: | ||
rm -rf $(TESTS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package elaboration | ||
|
||
import ( | ||
"github.com/rj45/llir2asm/ir" | ||
"github.com/rj45/llir2asm/ir/op" | ||
"github.com/rj45/llir2asm/ir/reg" | ||
"github.com/rj45/llir2asm/xform" | ||
) | ||
|
||
var _ = xform.Register(loadGPRelGlobals, | ||
xform.OnlyPass(xform.Elaboration), | ||
xform.OnOp(op.Load), | ||
) | ||
|
||
var _ = xform.Register(storeGPRelGlobals, | ||
xform.OnlyPass(xform.Elaboration), | ||
xform.OnOp(op.Store), | ||
) | ||
|
||
func loadGPRelGlobals(it ir.Iter) { | ||
instr := it.Instr() | ||
|
||
if instr.Arg(0).IsConst() { | ||
instr.InsertArg(0, instr.Func().ValueFor(0, reg.GP)) | ||
} | ||
} | ||
|
||
func storeGPRelGlobals(it ir.Iter) { | ||
instr := it.Instr() | ||
|
||
if instr.Arg(1).IsConst() { | ||
instr.InsertArg(1, instr.Func().ValueFor(0, reg.GP)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package elaboration | ||
|
||
import ( | ||
"github.com/rj45/llir2asm/ir" | ||
"github.com/rj45/llir2asm/ir/op" | ||
"github.com/rj45/llir2asm/xform" | ||
) | ||
|
||
var _ = xform.Register(addStoreConstCopies, | ||
xform.OnlyPass(xform.Elaboration), | ||
xform.OnOp(op.Store), | ||
) | ||
|
||
func addStoreConstCopies(it ir.Iter) { | ||
instr := it.Instr() | ||
|
||
if instr.Arg(0).IsConst() { | ||
cp := it.Insert(op.Copy, instr.Arg(0).Type, instr.Arg(0)) | ||
instr.ReplaceArg(0, cp.Def(0)) | ||
} | ||
} |