Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

irgen: Implicit type conversion #69

Closed
20 tasks done
mewmew opened this issue Jun 17, 2016 · 6 comments
Closed
20 tasks done

irgen: Implicit type conversion #69

mewmew opened this issue Jun 17, 2016 · 6 comments
Labels
Milestone

Comments

@mewmew
Copy link
Owner

mewmew commented Jun 17, 2016

Add support for implicit type conversion. This feature affects the following test cases.

  • testdata/quiet/semantic/s01.c
  • testdata/quiet/semantic/s05.c
  • testdata/quiet/semantic/s06.c
  • testdata/quiet/rtl/r01.c
  • testdata/quiet/rtl/r03.c
  • testdata/quiet/mips/m01.c
  • testdata/noisy/simple/sim04.c
  • testdata/noisy/simple/sim05.c
  • testdata/noisy/simple/sim06.c
  • testdata/noisy/simple/sim07.c
  • testdata/noisy/simple/sim08.c
  • testdata/noisy/simple/sim09.c
  • testdata/noisy/simple/sim10.c
  • testdata/noisy/simple/sim11.c
  • testdata/noisy/medium/circle.c
  • testdata/noisy/medium/fib.c
  • testdata/noisy/advanced/bubble.c
  • testdata/noisy/advanced/eval.c
  • testdata/noisy/advanced/primes.c
  • testdata/noisy/advanced/quick.c

Type mismatch

testdata/quiet/semantic/s01.c

uclang testdata/quiet/semantic/s01.c
panic: unable to create add instruction; github.com/llir/llvm/ir/instruction.NewAdd (binary.go:32): error: type mismatch between x (i32) and y (i8)

github.com/mewmew/uc/irgen.(*Module).binaryExpr(0xc4200a1cc0, 0xc42000a840, 0xc420012480, 0x8e, 0x8d)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:426 +0xbf8

testdata/quiet/semantic/s05.c

uclang testdata/quiet/semantic/s05.c
panic: unable to create add instruction; github.com/llir/llvm/ir/instruction.NewAdd (binary.go:32): error: type mismatch between x (i32) and y (i8)

github.com/mewmew/uc/irgen.(*Module).binaryExpr(0xc420081cc0, 0xc42000a6e0, 0xc4200125d0, 0x40, 0xc42008a240)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:426 +0xbf8

testdata/quiet/semantic/s06.c

uclang testdata/quiet/semantic/s06.c
panic: unable to create store instruction; github.com/llir/llvm/ir/instruction.NewStore (memory.go:111): error: type mismatch between i32 and i8

github.com/mewmew/uc/irgen.(*Module).identDef(0xc420081cc0, 0xc42000a600, 0xc420012510, 0x61cdc0, 0xc42000a7a0)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:690 +0x272

testdata/quiet/rtl/r01.c

uclang testdata/quiet/rtl/r01.c
panic: unable to create store instruction; github.com/llir/llvm/ir/instruction.NewStore (memory.go:111): error: type mismatch between i32 and i8

github.com/mewmew/uc/irgen.(*Module).identDef(0xc420081cc0, 0xc42000a820, 0xc420012690, 0x61cd40, 0xc420085480)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:690 +0x272

testdata/quiet/rtl/r03.c

uclang testdata/quiet/rtl/r03.c
panic: unable to create add instruction; github.com/llir/llvm/ir/instruction.NewAdd (binary.go:32): error: type mismatch between x (i8) and y (i32)

github.com/mewmew/uc/irgen.(*Module).binaryExpr(0xc420081cc0, 0xc42000a9a0, 0xc420012750, 0x61cdc0, 0xc42000ac80)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:426 +0xbf8

testdata/quiet/mips/m01.c

uclang testdata/quiet/mips/m01.c 
panic: unable to create mul instruction; github.com/llir/llvm/ir/instruction.NewMul (binary.go:148): error: type mismatch between x (i32) and y (i8)

github.com/mewmew/uc/irgen.(*Module).binaryExpr(0xc4200a1cc0, 0xc420068960, 0xc4200725a0, 0x0, 0xc42006a2d0)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:446 +0x3fa

testdata/noisy/simple/sim04.c

uclang testdata/noisy/simple/sim04.c 
panic: unable to create store instruction; github.com/llir/llvm/ir/instruction.NewStore (memory.go:111): error: type mismatch between i32 and i8

github.com/mewmew/uc/irgen.(*Module).indexExprDef(0xc420095cc0, 0xc42000b820, 0xc4200126c0, 0x61cd40, 0xc420099f20)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:747 +0x272

testdata/noisy/simple/sim05.c

uclang testdata/noisy/simple/sim05.c 
panic: unable to create store instruction; github.com/llir/llvm/ir/instruction.NewStore (memory.go:111): error: type mismatch between i32 and i8

github.com/mewmew/uc/irgen.(*Module).indexExprDef(0xc420081cc0, 0xc4200af000, 0xc420012810, 0x61cd40, 0xc42009df50)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:747 +0x272

testdata/noisy/simple/sim06.c

uclang testdata/noisy/simple/sim06.c
panic: unable to create store instruction; github.com/llir/llvm/ir/instruction.NewStore (memory.go:111): error: type mismatch between i32 and i8

github.com/mewmew/uc/irgen.(*Module).indexExprDef(0xc420095cc0, 0xc42000af80, 0xc4200127e0, 0x61cd40, 0xc420099940)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:747 +0x272

testdata/noisy/simple/sim07.c

uclang testdata/noisy/simple/sim07.c 
panic: unable to create store instruction; github.com/llir/llvm/ir/instruction.NewStore (memory.go:111): error: type mismatch between i32 and i8

github.com/mewmew/uc/irgen.(*Module).indexExprDef(0xc420095cc0, 0xc42000bb80, 0xc420012a80, 0x61cd40, 0xc4200da420)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:747 +0x272

testdata/noisy/simple/sim08.c

uclang testdata/noisy/simple/sim08.c 
panic: unable to create sub instruction; github.com/llir/llvm/ir/instruction.NewSub (binary.go:90): error: type mismatch between x (i8) and y (i32)

github.com/mewmew/uc/irgen.(*Module).binaryExpr(0xc4200a1cc0, 0xc4200dd1a0, 0xc42006ec90, 0xc42007c008, 0x57ff6a)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:436 +0x86c

testdata/noisy/simple/sim09.c

uclang testdata/noisy/simple/sim09.c
panic: unable to create store instruction; github.com/llir/llvm/ir/instruction.NewStore (memory.go:111): error: type mismatch between i32 and i8

github.com/mewmew/uc/irgen.(*Module).indexExprDef(0xc420081cc0, 0xc4200bd4a0, 0xc420013560, 0x61cd40, 0xc4200bb140)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:747 +0x272

testdata/noisy/simple/sim10.c

uclang testdata/noisy/simple/sim10.c 
panic: unable to create store instruction; github.com/llir/llvm/ir/instruction.NewStore (memory.go:111): error: type mismatch between i32 and i8

github.com/mewmew/uc/irgen.(*Module).indexExprDef(0xc420095cc0, 0xc4200d72a0, 0xc420012c60, 0x61cd40, 0xc4200bb330)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:747 +0x272

testdata/noisy/simple/sim11.c

uclang testdata/noisy/simple/sim11.c 
panic: unable to create store instruction; github.com/llir/llvm/ir/instruction.NewStore (memory.go:111): error: type mismatch between i32 and i8

github.com/mewmew/uc/irgen.(*Module).indexExprDef(0xc420095cc0, 0xc42000b560, 0xc420012720, 0x61cdc0, 0xc42000b6c0)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:747 +0x272

testdata/noisy/medium/circle.c

uclang testdata/noisy/medium/circle.c 
panic: unable to create store instruction; github.com/llir/llvm/ir/instruction.NewStore (memory.go:111): error: type mismatch between i32 and i8

github.com/mewmew/uc/irgen.(*Module).indexExprDef(0xc420081cc0, 0xc42000b680, 0xc420012660, 0x61cd40, 0xc420085fa0)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:747 +0x272

testdata/noisy/medium/fib.c

uclang testdata/noisy/medium/fib.c 
panic: unable to create store instruction; github.com/llir/llvm/ir/instruction.NewStore (memory.go:111): error: type mismatch between i32 and i8

github.com/mewmew/uc/irgen.(*Module).indexExprDef(0xc420081cc0, 0xc42000bea0, 0xc420012bd0, 0x61cd40, 0xc4200b2180)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:747 +0x272

testdata/noisy/advanced/bubble.c

uclang testdata/noisy/advanced/bubble.c
panic: unable to create store instruction; github.com/llir/llvm/ir/instruction.NewStore (memory.go:111): error: type mismatch between i32 and i8

github.com/mewmew/uc/irgen.(*Module).indexExprDef(0xc420081cc0, 0xc4200d73e0, 0xc420013800, 0x61cd40, 0xc4200c1080)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:747 +0x272

testdata/noisy/advanced/eval.c

uclang testdata/noisy/advanced/eval.c 
panic: unable to create icmp instruction; github.com/llir/llvm/ir/instruction.NewICmp (other.go:36): error: type mismatch between type of x (i8) and y (i32)

github.com/mewmew/uc/irgen.(*Module).binaryExpr(0xc420095cc0, 0xc42010a180, 0xc4200130e0, 0xc42009c028, 0xc42009c000)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:515 +0x42ad

testdata/noisy/advanced/primes.c

uclang testdata/noisy/advanced/primes.c 
panic: unable to create store instruction; github.com/llir/llvm/ir/instruction.NewStore (memory.go:111): error: type mismatch between i32 and i8

github.com/mewmew/uc/irgen.(*Module).indexExprDef(0xc420081cc0, 0xc42000b7a0, 0xc420012a50, 0x61cd40, 0xc4200c2340)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:747 +0x272

testdata/noisy/advanced/quick.c

uclang testdata/noisy/advanced/quick.c
panic: unable to create store instruction; github.com/llir/llvm/ir/instruction.NewStore (memory.go:111): error: type mismatch between i32 and i8

github.com/mewmew/uc/irgen.(*Module).indexExprDef(0xc420081cc0, 0xc4200dcba0, 0xc420013e90, 0x61cd40, 0xc4200a7b40)
    /home/u/Desktop/go/src/github.com/mewmew/uc/irgen/lower.go:747 +0x272
@mewmew mewmew added the irgen label Jun 17, 2016
@mewmew mewmew added this to the Assignment 5 milestone Jun 17, 2016
@mewmew
Copy link
Owner Author

mewmew commented Jun 17, 2016

@sangisos If you feel like it, please take a look at how we may wish to implement implicit type conversion. Hopefully we can keep add it at the right part of the irgen abstraction, so that the code is generic and doesn't have to be sprinkled across every expression generation function.

Related to this, we may wish to remove the zext (and possibly sext) instructions which are currently used to convert conditional binary expressions to the type of their arguments. This could potentially help fix #66.

For now, lets try to get it working first. So it is ok to sprinkle type conversions across each IR generation function. When we have it working and stable, we could try to find the right point to insert the abstraction, and also look closer at perhaps fixing #66.

Feel free to ping me if you wish to discuss these things, or have any thoughts regarding the implementation. I'll try to ponder myself on how we may wish to do this.

Cheers /u

@sangisos
Copy link
Collaborator

I have been reading the C99 draft and the clang sources, a typeCast function has an initial implementation in util(not yet pushed), but will be needed to be used in different ways before every use of a value.

I'm currently looking at how it is used in clangs ast context.

@mewmew
Copy link
Owner Author

mewmew commented Jun 18, 2016

I have been reading the C99 draft and the clang sources, a typeCast function has an initial implementation in util(not yet pushed), but will be needed to be used in different ways before every use of a value.

Great! I'd be happy to take a look once you push it.

I'm currently looking at how it is used in clangs ast context.

Found anything interesting? How do they do it?

@mewmew
Copy link
Owner Author

mewmew commented Jun 18, 2016

A duplicate of this issue is located at #63.

mewmew added a commit that referenced this issue Jun 18, 2016
mewmew added a commit that referenced this issue Jun 18, 2016
uclang is now capable of generating LLVM IR for all test cases.

Updates #69.
@mewmew
Copy link
Owner Author

mewmew commented Jun 18, 2016

Still left to do, implement conversion of function arguments in call expressions.

From callExpr:

    for _, arg := range callExpr.Args {
        expr := m.expr(f, arg)
        // TODO: Add cast
        args = append(args, expr)
    }

@mewmew
Copy link
Owner Author

mewmew commented Jun 18, 2016

Implicit conversion of function arguments in call expressions was implemented in commit a62d7fc. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants