Skip to content

Commit

Permalink
Merge pull request #3 from V0ldek/code-generation
Browse files Browse the repository at this point in the history
Fixed redundant local saves.
  • Loading branch information
V0ldek authored Jan 10, 2021
2 parents 6ee22b5 + 1359e7c commit 9a76b40
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
- Added the intermediate representation language, Espresso, with its own lexer and parser.
- Added IR generation.
- Added Control Flow Graph and variable liveness analysis.
- Added x86_64 assembler code generation for the core of the language.
- Added x86_64 assembler code generation for the core of the language.

## 0.9.1

- Fixed an issue where locals were unnecessarily moved out of stack and back again at end of a basic block when they were not alived in the preceding block.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Latte v0.9
# Latte v0.9.1

Compiler of the [Latte programming language](https://www.mimuw.edu.pl/~ben/Zajecia/Mrj2020/Latte/description.html) written in Haskell.

Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Latte
version: 0.9.0.0
version: 0.9.1.0
github: "githubuser/Latte"
license: MIT
author: "Mateusz Gienieczko"
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ run opt = do
genStep opt (espressoWithLivenessFile directory fileName) espressoWithLiveness
printStringV v "Generating x86_64 assembly..."
let assembly = generate cfgsWithLiveness
genOutput opt (unoptAssemblyFile directory fileName) assembly
genStep opt (unoptAssemblyFile directory fileName) assembly
let optAssembly = unlines $ Peephole.optimise (lines assembly)
genOutput opt (assemblyFile directory fileName) optAssembly

Expand Down
7 changes: 6 additions & 1 deletion src/X86_64/CodeGen/Generator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,21 @@ resetStack = do
Emit.decrStack n
setStack s'

-- Set stack and descriptions to a state where all locals are saved on stack
-- and nothing else is stored anywhere.
endBlock :: GenM ()
endBlock = do
locals <- gets (stackReservedSlots . stack)
s <- gets stack
let locals = stackReservedSlots s
varSs <- gets vars
let varSs' = Map.mapWithKey (\vi slot -> VarS {
varName = vi,
varType = varType $ varSs Map.! vi,
varLocs = [slotToLoc slot],
varAliases = [vi]}) locals
s' = foldr (\vi x -> snd $ stackInsertReserved vi x) s (Map.keys locals)
modify (\st -> st {allCode = bbCode st ++ allCode st,
bbCode = [],
regs = initialRegs,
stack = s',
vars = varSs'})

0 comments on commit 9a76b40

Please sign in to comment.