Skip to content

Commit

Permalink
irgen: Move expression type calculation from expr to the dedicated ex…
Browse files Browse the repository at this point in the history
…pression generation methods.
  • Loading branch information
mewmew committed Jun 15, 2016
1 parent 1d2ddee commit 09c1f2b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions irgen/lower.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,30 +287,31 @@ func (m *Module) whileStmt(f *Function, stmt *ast.WhileStmt) {

// expr lowers the given expression to LLVM IR, emitting code to f.
func (m *Module) expr(f *Function, expr ast.Expr) value.Value {
typ := m.typeOf(expr)
switch expr := expr.(type) {
case *ast.BasicLit:
return m.basicLit(f, expr, typ)
return m.basicLit(f, expr)
case *ast.BinaryExpr:
panic(fmt.Sprintf("support for type %T not yet implemented", expr))
case *ast.CallExpr:
panic(fmt.Sprintf("support for type %T not yet implemented", expr))
case *ast.Ident:
return m.ident(f, expr, typ)
return m.ident(f, expr)
case *ast.IndexExpr:
panic(fmt.Sprintf("support for type %T not yet implemented", expr))
case *ast.ParenExpr:
return m.expr(f, expr.X)
case *ast.UnaryExpr:
panic(fmt.Sprintf("support for type %T not yet implemented", expr))
//return m.unaryExpr(f, expr)
default:
panic(fmt.Sprintf("support for type %T not yet implemented", expr))
}
panic("unreachable")
}

// basicLit lowers the given basic literal to LLVM IR, emitting code to f.
func (m *Module) basicLit(f *Function, n *ast.BasicLit, typ irtypes.Type) value.Value {
func (m *Module) basicLit(f *Function, n *ast.BasicLit) value.Value {
typ := m.typeOf(n)
switch n.Kind {
case token.CharLit:
s, err := strconv.Unquote(n.Val)
Expand All @@ -334,14 +335,15 @@ func (m *Module) basicLit(f *Function, n *ast.BasicLit, typ irtypes.Type) value.
}

// ident lowers the given identifier to LLVM IR, emitting code to f.
func (m *Module) ident(f *Function, ident *ast.Ident, typ irtypes.Type) value.Value {
func (m *Module) ident(f *Function, ident *ast.Ident) value.Value {
// Input:
// void f() {
// int x;
// x; // <-- relevant line
// }
// Output:
// %1 = load i32, i32* %x
typ := m.typeOf(ident)
addr := f.local(ident.String())
inst, err := instruction.NewLoad(typ, addr)
if err != nil {
Expand Down

0 comments on commit 09c1f2b

Please sign in to comment.