Skip to content

Commit

Permalink
Pass asm by value
Browse files Browse the repository at this point in the history
  • Loading branch information
pwaller committed Nov 24, 2018
1 parent 6668372 commit f08aaaf
Show file tree
Hide file tree
Showing 21 changed files with 714 additions and 714 deletions.
52 changes: 26 additions & 26 deletions asm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@ import (

func (gen *generator) irConstant(t types.Type, old ast.Constant) (constant.Constant, error) {
switch old := old.(type) {
case *ast.BoolConst:
case ast.BoolConst:
return gen.irBoolConst(t, old)
case *ast.IntConst:
case ast.IntConst:
return gen.irIntConst(t, old)
case *ast.FloatConst:
case ast.FloatConst:
return gen.irFloatConst(t, old)
case *ast.NullConst:
case ast.NullConst:
return gen.irNullConst(t, old)
case *ast.NoneConst:
case ast.NoneConst:
return gen.irNoneConst(t, old)
case *ast.StructConst:
case ast.StructConst:
return gen.irStructConst(t, old)
case *ast.ArrayConst:
case ast.ArrayConst:
return gen.irArrayConst(t, old)
case *ast.CharArrayConst:
case ast.CharArrayConst:
return gen.irCharArrayConst(t, old)
case *ast.VectorConst:
case ast.VectorConst:
return gen.irVectorConst(t, old)
case *ast.ZeroInitializerConst:
case ast.ZeroInitializerConst:
return gen.irZeroInitializerConst(t, old)
case *ast.UndefConst:
case ast.UndefConst:
return gen.irUndefConst(t, old)
case *ast.BlockAddressConst:
case ast.BlockAddressConst:
return gen.irBlockAddressConst(t, old)
case *ast.GlobalIdent:
ident := globalIdent(*old)
case ast.GlobalIdent:
ident := globalIdent(old)
v, ok := gen.new.globals[ident]
if !ok {
return nil, errors.Errorf("unable to locate global identifier %q", ident)
Expand All @@ -64,7 +64,7 @@ func (gen *generator) irTypeConst(old ast.TypeConst) (constant.Constant, error)

// --- [ Boolean Constants ] ---------------------------------------------------

func (gen *generator) irBoolConst(t types.Type, old *ast.BoolConst) (*constant.Int, error) {
func (gen *generator) irBoolConst(t types.Type, old ast.BoolConst) (*constant.Int, error) {
typ, ok := t.(*types.IntType)
if !ok {
return nil, errors.Errorf("invalid type of boolean constant; expected *types.IntType, got %T", t)
Expand All @@ -81,7 +81,7 @@ func (gen *generator) irBoolConst(t types.Type, old *ast.BoolConst) (*constant.I

// --- [ Integer Constants ] ---------------------------------------------------

func (gen *generator) irIntConst(t types.Type, old *ast.IntConst) (*constant.Int, error) {
func (gen *generator) irIntConst(t types.Type, old ast.IntConst) (*constant.Int, error) {
typ, ok := t.(*types.IntType)
if !ok {
return nil, errors.Errorf("invalid type of integer constant; expected *types.IntType, got %T", t)
Expand All @@ -92,7 +92,7 @@ func (gen *generator) irIntConst(t types.Type, old *ast.IntConst) (*constant.Int

// --- [ Floating-point Constants ] --------------------------------------------

func (gen *generator) irFloatConst(t types.Type, old *ast.FloatConst) (*constant.Float, error) {
func (gen *generator) irFloatConst(t types.Type, old ast.FloatConst) (*constant.Float, error) {
typ, ok := t.(*types.FloatType)
if !ok {
return nil, errors.Errorf("invalid type of floating-point constant; expected *types.FloatType, got %T", t)
Expand All @@ -103,7 +103,7 @@ func (gen *generator) irFloatConst(t types.Type, old *ast.FloatConst) (*constant

// --- [ Null Pointer Constants ] ----------------------------------------------

func (gen *generator) irNullConst(t types.Type, old *ast.NullConst) (*constant.Null, error) {
func (gen *generator) irNullConst(t types.Type, old ast.NullConst) (*constant.Null, error) {
typ, ok := t.(*types.PointerType)
if !ok {
return nil, errors.Errorf("invalid type of null constant; expected *types.PointerType, got %T", t)
Expand All @@ -113,14 +113,14 @@ func (gen *generator) irNullConst(t types.Type, old *ast.NullConst) (*constant.N

// --- [ Token Constants ] -----------------------------------------------------

func (gen *generator) irNoneConst(t types.Type, old *ast.NoneConst) (constant.Constant, error) {
func (gen *generator) irNoneConst(t types.Type, old ast.NoneConst) (constant.Constant, error) {
// TODO: validate type t.
return constant.None, nil
}

// --- [ Structure Constants ] -------------------------------------------------

func (gen *generator) irStructConst(t types.Type, old *ast.StructConst) (*constant.Struct, error) {
func (gen *generator) irStructConst(t types.Type, old ast.StructConst) (*constant.Struct, error) {
typ, ok := t.(*types.StructType)
if !ok {
return nil, errors.Errorf("invalid type of struct constant; expected *types.StructType, got %T", t)
Expand All @@ -141,7 +141,7 @@ func (gen *generator) irStructConst(t types.Type, old *ast.StructConst) (*consta

// --- [ Array Constants ] -----------------------------------------------------

func (gen *generator) irArrayConst(t types.Type, old *ast.ArrayConst) (*constant.Array, error) {
func (gen *generator) irArrayConst(t types.Type, old ast.ArrayConst) (*constant.Array, error) {
typ, ok := t.(*types.ArrayType)
if !ok {
return nil, errors.Errorf("invalid type of array constant; expected *types.ArrayType, got %T", t)
Expand All @@ -166,7 +166,7 @@ func (gen *generator) irArrayConst(t types.Type, old *ast.ArrayConst) (*constant
return c, nil
}

func (gen *generator) irCharArrayConst(t types.Type, old *ast.CharArrayConst) (*constant.CharArray, error) {
func (gen *generator) irCharArrayConst(t types.Type, old ast.CharArrayConst) (*constant.CharArray, error) {
data := stringLitBytes(old.Val())
expr := constant.NewCharArray(data)
// TODO: validate t against expr.Typ.
Expand All @@ -175,7 +175,7 @@ func (gen *generator) irCharArrayConst(t types.Type, old *ast.CharArrayConst) (*

// --- [ Vector Constants ] ----------------------------------------------------

func (gen *generator) irVectorConst(t types.Type, old *ast.VectorConst) (*constant.Vector, error) {
func (gen *generator) irVectorConst(t types.Type, old ast.VectorConst) (*constant.Vector, error) {
typ, ok := t.(*types.VectorType)
if !ok {
return nil, errors.Errorf("invalid type of vector constant; expected *types.VectorType, got %T", t)
Expand All @@ -202,19 +202,19 @@ func (gen *generator) irVectorConst(t types.Type, old *ast.VectorConst) (*consta

// --- [ Zero Initialization Constants ] ---------------------------------------

func (gen *generator) irZeroInitializerConst(t types.Type, old *ast.ZeroInitializerConst) (*constant.ZeroInitializer, error) {
func (gen *generator) irZeroInitializerConst(t types.Type, old ast.ZeroInitializerConst) (*constant.ZeroInitializer, error) {
return constant.NewZeroInitializer(t), nil
}

// --- [ Undefined Values ] ----------------------------------------------------

func (gen *generator) irUndefConst(t types.Type, old *ast.UndefConst) (*constant.Undef, error) {
func (gen *generator) irUndefConst(t types.Type, old ast.UndefConst) (*constant.Undef, error) {
return constant.NewUndef(t), nil
}

// --- [ Addresses of Basic Blocks ] -------------------------------------------

func (gen *generator) irBlockAddressConst(t types.Type, old *ast.BlockAddressConst) (*constant.BlockAddress, error) {
func (gen *generator) irBlockAddressConst(t types.Type, old ast.BlockAddressConst) (*constant.BlockAddress, error) {
// Function.
funcName := globalIdent(old.Func())
v, ok := gen.new.globals[funcName]
Expand Down

0 comments on commit f08aaaf

Please sign in to comment.