Giter Site home page Giter Site logo

sword-smith / hfasto Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 2.0 42 KB

Implementing a compiler for the fuctional programming language fasto in Haskell

License: MIT License

Haskell 100.00%
compiler calling-conventions mips-assembly functional-programming register-allocation

hfasto's People

Contributors

athas avatar sword-smith avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

athas

hfasto's Issues

Create folder structure appropriate for testing

Troels: Can you make a folder structure which is appropriate for testing? I would like to run unit tests on various function in the different modules located in src/ but when I create test modules in T/, I cannot get those modules to import the modules found in src/

Loading of 4+ registers and register allocation

When a function is called with more than four arguments the arguments are loaded from the stack. Currently, the instructions to load these arguments is located in the function loadRegistersH in MipsCodeGenerator.hs. But spilling, which is handled in the MipsRegAlloc, may wrap the entire body in instructions that move the stack pointer and the code generated by loadRegistersH is considered part of the body.

The solution is probably to give the code generated by the loadRegisters function a special place in the mipsFunction record and then rewrite all the load instructions when it is known how much the register allocator moves the stack pointer before the loadRegisters code is executed.

Some of the relevant parts of the code are presented below

saveArgRegs :: [] String -> [] Mips.Instruction
saveArgRegs args = saveArgRegsH 0 args

saveArgRegsH :: Int -> [] String -> [] Mips.Instruction
saveArgRegsH _ []         = []
saveArgRegsH i (arg:args) = if i < 4
                            then Mips.XOR ("$a" ++ show i) arg zero :
                                 Mips.SW arg "$sp" (show (i*4)) :
                                 saveArgRegsH (i+1) args
                            else Mips.SW arg "$sp" (show (i*4)) :
                                 saveArgRegsH (i+1) args

-- Atm, no proper liveness analysis is done with these "string:strings"
loadRegisters :: [] String -> [] Mips.Instruction
loadRegisters args = loadRegistersH 0 args

-- The "8" in the below function cannot be hardcoded since the register allocator
-- may invalidate that number.
-- The solution may be to introduce a loadRegisters value with which the
-- register allocator may shift all the special, symbolic lw operations?
-- They can also just be rewritten if the are part of the loadArgs part of the
-- MipsFunction struct.
loadRegistersH :: Int -> [] String -> [] Mips.Instruction
loadRegistersH _ []         = []
loadRegistersH i (arg:args) = if i < 4
                              then Mips.XOR arg ("$a" ++ (show i)) zero :
                                   loadRegistersH (i + 1) args
                              else Mips.LW arg "$sp" (show (i*4 + 8)) :
                                   loadRegistersH (i + 1) args

regAllocInst spillingRewrite vtable (Mips.JAL l) = do-- Here the store and load stuff should be handled. Potentially in a monade?
  regEnv <- get
  i <- incr
  let sliveRegs = S.toList $ (livenessInSets regEnv !! i)
  rliveRegs <- mapM (mapReg vtable) sliveRegs
  store <- storeLive (rliveRegs ++ ["$ra"])
  load  <- loadLive $ rliveRegs  ++ ["$ra"]
  if spillingRewrite
    then return [Mips.JAL l]
    else return $ store ++ [Mips.JAL l] ++ load

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.