Skip to content

Commit

Permalink
CORE: Fix alignment of instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
MineGame159 committed Jan 27, 2024
1 parent 263e4c9 commit 59d76a5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion core/codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (c *codegen) load(value exprValue, type_ ast.Type) exprValue {
v: c.block.Add(&ir.LoadInst{
Typ: value.v.Type().(*ir.PointerType).Pointee,
Pointer: value.v,
Align: type_.Align() * 8,
Align: type_.Align(),
}),
addressable: false,
}
Expand Down
2 changes: 1 addition & 1 deletion core/codegen/declarations.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *codegen) VisitFunc(decl *ast.Func) {
c.block.Add(&ir.StoreInst{
Pointer: pointer,
Value: function.Typ.Params[index],
Align: param.Type.Align() * 8,
Align: param.Type.Align(),
})

c.scopes.addVariable(param.Name, param.Type, exprValue{v: pointer}, uint32(index+1))
Expand Down
18 changes: 9 additions & 9 deletions core/codegen/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (c *codegen) VisitStructInitializer(expr *ast.StructInitializer) {
c.block.Add(&ir.StoreInst{
Pointer: pointer,
Value: result,
Align: struct_.Align() * 8,
Align: struct_.Align(),
})

c.exprResult = exprValue{v: pointer}
Expand Down Expand Up @@ -285,7 +285,7 @@ func (c *codegen) VisitUnary(expr *ast.Unary) {
result = c.block.Add(&ir.LoadInst{
Typ: result.Type().(*ir.PointerType).Pointee,
Pointer: result,
Align: expr.Result().Type.Align() * 8,
Align: expr.Result().Type.Align(),
})
}

Expand Down Expand Up @@ -314,7 +314,7 @@ func (c *codegen) VisitUnary(expr *ast.Unary) {
c.block.Add(&ir.StoreInst{
Pointer: value.v,
Value: newValue.v,
Align: expr.Value.Result().Type.Align() * 8,
Align: expr.Value.Result().Type.Align(),
})

result = newValue.v
Expand Down Expand Up @@ -356,7 +356,7 @@ func (c *codegen) VisitUnary(expr *ast.Unary) {
c.block.Add(&ir.StoreInst{
Pointer: value.v,
Value: newValue.v,
Align: expr.Value.Result().Type.Align() * 8,
Align: expr.Value.Result().Type.Align(),
})

result = prevValue.v
Expand Down Expand Up @@ -514,7 +514,7 @@ func (c *codegen) VisitAssignment(expr *ast.Assignment) {
store := c.block.Add(&ir.StoreInst{
Pointer: assignee.v,
Value: value.v,
Align: expr.Result().Type.Align() * 8,
Align: expr.Result().Type.Align(),
})

c.setLocationMeta(store, expr)
Expand Down Expand Up @@ -667,7 +667,7 @@ func (c *codegen) VisitCall(expr *ast.Call) {
c.block.Add(&ir.StoreInst{
Pointer: pointer.v,
Value: c.exprResult.v,
Align: function.Returns.Align() * 8,
Align: function.Returns.Align(),
})

c.exprResult = pointer
Expand All @@ -682,7 +682,7 @@ func (c *codegen) VisitIndex(expr *ast.Index) {
value = exprValue{v: c.block.Add(&ir.LoadInst{
Typ: value.v.Type().(*ir.PointerType).Pointee,
Pointer: value.v,
Align: pointer.Pointee.Align() * 8,
Align: pointer.Pointee.Align(),
})}
}

Expand Down Expand Up @@ -834,7 +834,7 @@ func (c *codegen) VisitMember(expr *ast.Member) {
c.block.Add(&ir.StoreInst{
Pointer: pointer.v,
Value: value.v,
Align: node.Align() * 8,
Align: node.Align(),
})

value = pointer
Expand Down Expand Up @@ -865,7 +865,7 @@ func (c *codegen) memberLoad(type_ ast.Type, value exprValue) (exprValue, *ast.S
load := c.block.Add(&ir.LoadInst{
Typ: value.v.Type().(*ir.PointerType).Pointee,
Pointer: value.v,
Align: v.Align() * 8,
Align: v.Align(),
})

return exprValue{
Expand Down
2 changes: 1 addition & 1 deletion core/codegen/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func (c *codegen) alloca(type_ ast.Type, name string, node ast.Node) ir.Value {
pointer := c.block.Add(&ir.AllocaInst{
Typ: c.types.get(type_),
Align: type_.Align() * 8,
Align: type_.Align(),
})

if name != "" {
Expand Down
2 changes: 1 addition & 1 deletion core/codegen/statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (c *codegen) VisitVar(stmt *ast.Var) {
store := c.block.Add(&ir.StoreInst{
Pointer: pointer.v,
Value: initializer,
Align: stmt.ActualType.Align() * 8,
Align: stmt.ActualType.Align(),
})

c.setLocationMeta(store, stmt)
Expand Down

0 comments on commit 59d76a5

Please sign in to comment.