diff --git a/asm/inst_aggregate.go b/asm/inst_aggregate.go new file mode 100644 index 00000000..0d75df82 --- /dev/null +++ b/asm/inst_aggregate.go @@ -0,0 +1,34 @@ +package asm + +import ( + "fmt" + + "github.com/llir/l/ir" + "github.com/mewmew/l-tm/asm/ll/ast" +) + +// --- [ Aggregate instructions ] ---------------------------------------------- + +// ~~~ [ extractvalue ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstExtractValue(inst ir.Instruction, old *ast.ExtractValueInst) (*ir.InstExtractValue, error) { + i, ok := inst.(*ir.InstExtractValue) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstExtractValue, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ insertvalue ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstInsertValue(inst ir.Instruction, old *ast.InsertValueInst) (*ir.InstInsertValue, error) { + i, ok := inst.(*ir.InstInsertValue) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstInsertValue, got %T", inst)) + } + // TODO: implement + return i, nil +} diff --git a/asm/inst_binary.go b/asm/inst_binary.go new file mode 100644 index 00000000..e34b7217 --- /dev/null +++ b/asm/inst_binary.go @@ -0,0 +1,348 @@ +package asm + +import ( + "fmt" + + "github.com/llir/l/ir" + "github.com/mewmew/l-tm/asm/ll/ast" + "github.com/pkg/errors" +) + +// --- [ Binary instructions ] ------------------------------------------------- + +// ~~~ [ add ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstAdd(inst ir.Instruction, old *ast.AddInst) (*ir.InstAdd, error) { + i, ok := inst.(*ir.InstAdd) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstAdd, got %T", inst)) + } + // Overflow flags. + i.OverflowFlags = irOverflowFlags(old.OverflowFlags()) + // X operand. + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(x.Type(), old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ fadd ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstFAdd(inst ir.Instruction, old *ast.FAddInst) (*ir.InstFAdd, error) { + i, ok := inst.(*ir.InstFAdd) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFAdd, got %T", inst)) + } + // Fast math flags. + i.FastMathFlags = irFastMathFlags(old.FastMathFlags()) + // X operand. + // TODO: remove xType in favour of x.Type(). + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ sub ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstSub(inst ir.Instruction, old *ast.SubInst) (*ir.InstSub, error) { + i, ok := inst.(*ir.InstSub) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstSub, got %T", inst)) + } + // Overflow flags. + i.OverflowFlags = irOverflowFlags(old.OverflowFlags()) + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ fsub ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstFSub(inst ir.Instruction, old *ast.FSubInst) (*ir.InstFSub, error) { + i, ok := inst.(*ir.InstFSub) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFSub, got %T", inst)) + } + // Fast math flags. + i.FastMathFlags = irFastMathFlags(old.FastMathFlags()) + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ mul ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstMul(inst ir.Instruction, old *ast.MulInst) (*ir.InstMul, error) { + i, ok := inst.(*ir.InstMul) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstMul, got %T", inst)) + } + // Overflow flags. + i.OverflowFlags = irOverflowFlags(old.OverflowFlags()) + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ fmul ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstFMul(inst ir.Instruction, old *ast.FMulInst) (*ir.InstFMul, error) { + i, ok := inst.(*ir.InstFMul) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFMul, got %T", inst)) + } + // Fast math flags. + i.FastMathFlags = irFastMathFlags(old.FastMathFlags()) + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ udiv ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstUDiv(inst ir.Instruction, old *ast.UDivInst) (*ir.InstUDiv, error) { + i, ok := inst.(*ir.InstUDiv) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstUDiv, got %T", inst)) + } + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ sdiv ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstSDiv(inst ir.Instruction, old *ast.SDivInst) (*ir.InstSDiv, error) { + i, ok := inst.(*ir.InstSDiv) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstSDiv, got %T", inst)) + } + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ fdiv ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstFDiv(inst ir.Instruction, old *ast.FDivInst) (*ir.InstFDiv, error) { + i, ok := inst.(*ir.InstFDiv) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFDiv, got %T", inst)) + } + // Fast math flags. + i.FastMathFlags = irFastMathFlags(old.FastMathFlags()) + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ urem ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstURem(inst ir.Instruction, old *ast.URemInst) (*ir.InstURem, error) { + i, ok := inst.(*ir.InstURem) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstURem, got %T", inst)) + } + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ srem ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstSRem(inst ir.Instruction, old *ast.SRemInst) (*ir.InstSRem, error) { + i, ok := inst.(*ir.InstSRem) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstSRem, got %T", inst)) + } + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ frem ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstFRem(inst ir.Instruction, old *ast.FRemInst) (*ir.InstFRem, error) { + i, ok := inst.(*ir.InstFRem) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFRem, got %T", inst)) + } + // Fast math flags. + i.FastMathFlags = irFastMathFlags(old.FastMathFlags()) + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} diff --git a/asm/inst_bitwise.go b/asm/inst_bitwise.go new file mode 100644 index 00000000..e21790ad --- /dev/null +++ b/asm/inst_bitwise.go @@ -0,0 +1,175 @@ +package asm + +import ( + "fmt" + + "github.com/llir/l/ir" + "github.com/mewmew/l-tm/asm/ll/ast" + "github.com/pkg/errors" +) + +// --- [ Bitwise instructions ] ------------------------------------------------ + +// ~~~ [ shl ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstShl(inst ir.Instruction, old *ast.ShlInst) (*ir.InstShl, error) { + i, ok := inst.(*ir.InstShl) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstShl, got %T", inst)) + } + // Overflow flags. + i.OverflowFlags = irOverflowFlags(old.OverflowFlags()) + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ lshr ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstLShr(inst ir.Instruction, old *ast.LShrInst) (*ir.InstLShr, error) { + i, ok := inst.(*ir.InstLShr) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstLShr, got %T", inst)) + } + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ ashr ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstAShr(inst ir.Instruction, old *ast.AShrInst) (*ir.InstAShr, error) { + i, ok := inst.(*ir.InstAShr) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstAShr, got %T", inst)) + } + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ and ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstAnd(inst ir.Instruction, old *ast.AndInst) (*ir.InstAnd, error) { + i, ok := inst.(*ir.InstAnd) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstAnd, got %T", inst)) + } + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ or ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstOr(inst ir.Instruction, old *ast.OrInst) (*ir.InstOr, error) { + i, ok := inst.(*ir.InstOr) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstOr, got %T", inst)) + } + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} + +// ~~~ [ xor ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstXor(inst ir.Instruction, old *ast.XorInst) (*ir.InstXor, error) { + i, ok := inst.(*ir.InstXor) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstXor, got %T", inst)) + } + // X operand. + xType, err := fgen.gen.irType(old.X().Typ()) + if err != nil { + return nil, errors.WithStack(err) + } + x, err := fgen.astToIRTypeValue(old.X()) + if err != nil { + return nil, errors.WithStack(err) + } + i.X = x + // Y operand. + y, err := fgen.astToIRValue(xType, old.Y()) + if err != nil { + return nil, errors.WithStack(err) + } + i.Y = y + return i, nil +} diff --git a/asm/inst_conversion.go b/asm/inst_conversion.go new file mode 100644 index 00000000..870eda48 --- /dev/null +++ b/asm/inst_conversion.go @@ -0,0 +1,166 @@ +package asm + +import ( + "fmt" + + "github.com/llir/l/ir" + "github.com/mewmew/l-tm/asm/ll/ast" +) + +// --- [ Conversion instructions ] --------------------------------------------- + +// ~~~ [ trunc ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstTrunc(inst ir.Instruction, old *ast.TruncInst) (*ir.InstTrunc, error) { + i, ok := inst.(*ir.InstTrunc) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstTrunc, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ zext ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstZExt(inst ir.Instruction, old *ast.ZExtInst) (*ir.InstZExt, error) { + i, ok := inst.(*ir.InstZExt) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstZExt, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ sext ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstSExt(inst ir.Instruction, old *ast.SExtInst) (*ir.InstSExt, error) { + i, ok := inst.(*ir.InstSExt) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstSExt, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ fptrunc ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstFPTrunc(inst ir.Instruction, old *ast.FPTruncInst) (*ir.InstFPTrunc, error) { + i, ok := inst.(*ir.InstFPTrunc) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFPTrunc, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ fpext ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstFPExt(inst ir.Instruction, old *ast.FPExtInst) (*ir.InstFPExt, error) { + i, ok := inst.(*ir.InstFPExt) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFPExt, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ fptoui ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstFPToUI(inst ir.Instruction, old *ast.FPToUIInst) (*ir.InstFPToUI, error) { + i, ok := inst.(*ir.InstFPToUI) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFPToUI, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ fptosi ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstFPToSI(inst ir.Instruction, old *ast.FPToSIInst) (*ir.InstFPToSI, error) { + i, ok := inst.(*ir.InstFPToSI) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFPToSI, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ uitofp ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstUIToFP(inst ir.Instruction, old *ast.UIToFPInst) (*ir.InstUIToFP, error) { + i, ok := inst.(*ir.InstUIToFP) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstUIToFP, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ sitofp ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstSIToFP(inst ir.Instruction, old *ast.SIToFPInst) (*ir.InstSIToFP, error) { + i, ok := inst.(*ir.InstSIToFP) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstSIToFP, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ ptrtoint ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstPtrToInt(inst ir.Instruction, old *ast.PtrToIntInst) (*ir.InstPtrToInt, error) { + i, ok := inst.(*ir.InstPtrToInt) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstPtrToInt, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ inttoptr ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstIntToPtr(inst ir.Instruction, old *ast.IntToPtrInst) (*ir.InstIntToPtr, error) { + i, ok := inst.(*ir.InstIntToPtr) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstIntToPtr, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ bitcast ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstBitCast(inst ir.Instruction, old *ast.BitCastInst) (*ir.InstBitCast, error) { + i, ok := inst.(*ir.InstBitCast) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstBitCast, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ addrspacecast ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstAddrSpaceCast(inst ir.Instruction, old *ast.AddrSpaceCastInst) (*ir.InstAddrSpaceCast, error) { + i, ok := inst.(*ir.InstAddrSpaceCast) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstAddrSpaceCast, got %T", inst)) + } + // TODO: implement + return i, nil +} diff --git a/asm/inst_memory.go b/asm/inst_memory.go new file mode 100644 index 00000000..31c1a218 --- /dev/null +++ b/asm/inst_memory.go @@ -0,0 +1,94 @@ +package asm + +import ( + "fmt" + + "github.com/llir/l/ir" + "github.com/mewmew/l-tm/asm/ll/ast" +) + +// --- [ Memory instructions ] ------------------------------------------------- + +// ~~~ [ alloca ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstAlloca(inst ir.Instruction, old *ast.AllocaInst) (*ir.InstAlloca, error) { + i, ok := inst.(*ir.InstAlloca) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstAlloca, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ load ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstLoad(inst ir.Instruction, old *ast.LoadInst) (*ir.InstLoad, error) { + i, ok := inst.(*ir.InstLoad) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstLoad, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ store ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstStore(inst ir.Instruction, old *ast.StoreInst) (*ir.InstStore, error) { + i, ok := inst.(*ir.InstStore) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstStore, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ fence ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstFence(inst ir.Instruction, old *ast.FenceInst) (*ir.InstFence, error) { + i, ok := inst.(*ir.InstFence) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFence, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ cmpxchg ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstCmpXchg(inst ir.Instruction, old *ast.CmpXchgInst) (*ir.InstCmpXchg, error) { + i, ok := inst.(*ir.InstCmpXchg) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstCmpXchg, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ atomicrmw ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstAtomicRMW(inst ir.Instruction, old *ast.AtomicRMWInst) (*ir.InstAtomicRMW, error) { + i, ok := inst.(*ir.InstAtomicRMW) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstAtomicRMW, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ getelementptr ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstGetElementPtr(inst ir.Instruction, old *ast.GetElementPtrInst) (*ir.InstGetElementPtr, error) { + i, ok := inst.(*ir.InstGetElementPtr) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstGetElementPtr, got %T", inst)) + } + // TODO: implement + return i, nil +} diff --git a/asm/inst_other.go b/asm/inst_other.go new file mode 100644 index 00000000..7050cb10 --- /dev/null +++ b/asm/inst_other.go @@ -0,0 +1,123 @@ +package asm + +import ( + "fmt" + + "github.com/llir/l/ir" + "github.com/mewmew/l-tm/asm/ll/ast" +) + +// --- [ Other instructions ] -------------------------------------------------- + +// ~~~ [ icmp ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstICmp(inst ir.Instruction, old *ast.ICmpInst) (*ir.InstICmp, error) { + i, ok := inst.(*ir.InstICmp) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstICmp, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ fcmp ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstFCmp(inst ir.Instruction, old *ast.FCmpInst) (*ir.InstFCmp, error) { + i, ok := inst.(*ir.InstFCmp) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFCmp, got %T", inst)) + } + // Fast math flags. + i.FastMathFlags = irFastMathFlags(old.FastMathFlags()) + // TODO: implement + return i, nil +} + +// ~~~ [ phi ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstPhi(inst ir.Instruction, old *ast.PhiInst) (*ir.InstPhi, error) { + i, ok := inst.(*ir.InstPhi) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstPhi, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ select ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstSelect(inst ir.Instruction, old *ast.SelectInst) (*ir.InstSelect, error) { + i, ok := inst.(*ir.InstSelect) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstSelect, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ call ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstCall(inst ir.Instruction, old *ast.CallInst) (*ir.InstCall, error) { + i, ok := inst.(*ir.InstCall) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstCall, got %T", inst)) + } + // Fast math flags. + i.FastMathFlags = irFastMathFlags(old.FastMathFlags()) + // Calling convention. + i.CallingConv = irOptCallingConv(old.CallingConv()) + return i, nil +} + +// ~~~ [ va_arg ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstVAArg(inst ir.Instruction, old *ast.VAArgInst) (*ir.InstVAArg, error) { + i, ok := inst.(*ir.InstVAArg) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstVAArg, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ landingpad ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstLandingPad(inst ir.Instruction, old *ast.LandingPadInst) (*ir.InstLandingPad, error) { + i, ok := inst.(*ir.InstLandingPad) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstLandingPad, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ catchpad ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstCatchPad(inst ir.Instruction, old *ast.CatchPadInst) (*ir.InstCatchPad, error) { + i, ok := inst.(*ir.InstCatchPad) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstCatchPad, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ cleanuppad ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstCleanupPad(inst ir.Instruction, old *ast.CleanupPadInst) (*ir.InstCleanupPad, error) { + i, ok := inst.(*ir.InstCleanupPad) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstCleanupPad, got %T", inst)) + } + // TODO: implement + return i, nil +} diff --git a/asm/inst_vector.go b/asm/inst_vector.go new file mode 100644 index 00000000..bc08616f --- /dev/null +++ b/asm/inst_vector.go @@ -0,0 +1,46 @@ +package asm + +import ( + "fmt" + + "github.com/llir/l/ir" + "github.com/mewmew/l-tm/asm/ll/ast" +) + +// --- [ Vector instructions ] ------------------------------------------------- + +// ~~~ [ extractelement ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstExtractElement(inst ir.Instruction, old *ast.ExtractElementInst) (*ir.InstExtractElement, error) { + i, ok := inst.(*ir.InstExtractElement) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstExtractElement, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ insertelement ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstInsertElement(inst ir.Instruction, old *ast.InsertElementInst) (*ir.InstInsertElement, error) { + i, ok := inst.(*ir.InstInsertElement) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstInsertElement, got %T", inst)) + } + // TODO: implement + return i, nil +} + +// ~~~ [ shufflevector ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +func (fgen *funcGen) astToIRInstShuffleVector(inst ir.Instruction, old *ast.ShuffleVectorInst) (*ir.InstShuffleVector, error) { + i, ok := inst.(*ir.InstShuffleVector) + if !ok { + // NOTE: panic since this would indicate a bug in the implementation. + panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstShuffleVector, got %T", inst)) + } + // TODO: implement + return i, nil +} diff --git a/asm/local.go b/asm/local.go index ee366127..39d18b72 100644 --- a/asm/local.go +++ b/asm/local.go @@ -555,934 +555,6 @@ func (fgen *funcGen) astToIRValueInst(inst ir.Instruction, old ast.ValueInstruct } } -// --- [ Binary instructions ] ------------------------------------------------- - -// ~~~ [ add ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstAdd(inst ir.Instruction, old *ast.AddInst) (*ir.InstAdd, error) { - i, ok := inst.(*ir.InstAdd) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstAdd, got %T", inst)) - } - // Overflow flags. - i.OverflowFlags = irOverflowFlags(old.OverflowFlags()) - // X operand. - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(x.Type(), old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ fadd ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstFAdd(inst ir.Instruction, old *ast.FAddInst) (*ir.InstFAdd, error) { - i, ok := inst.(*ir.InstFAdd) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFAdd, got %T", inst)) - } - // Fast math flags. - i.FastMathFlags = irFastMathFlags(old.FastMathFlags()) - // X operand. - // TODO: remove xType in favour of x.Type(). - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ sub ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstSub(inst ir.Instruction, old *ast.SubInst) (*ir.InstSub, error) { - i, ok := inst.(*ir.InstSub) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstSub, got %T", inst)) - } - // Overflow flags. - i.OverflowFlags = irOverflowFlags(old.OverflowFlags()) - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ fsub ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstFSub(inst ir.Instruction, old *ast.FSubInst) (*ir.InstFSub, error) { - i, ok := inst.(*ir.InstFSub) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFSub, got %T", inst)) - } - // Fast math flags. - i.FastMathFlags = irFastMathFlags(old.FastMathFlags()) - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ mul ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstMul(inst ir.Instruction, old *ast.MulInst) (*ir.InstMul, error) { - i, ok := inst.(*ir.InstMul) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstMul, got %T", inst)) - } - // Overflow flags. - i.OverflowFlags = irOverflowFlags(old.OverflowFlags()) - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ fmul ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstFMul(inst ir.Instruction, old *ast.FMulInst) (*ir.InstFMul, error) { - i, ok := inst.(*ir.InstFMul) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFMul, got %T", inst)) - } - // Fast math flags. - i.FastMathFlags = irFastMathFlags(old.FastMathFlags()) - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ udiv ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstUDiv(inst ir.Instruction, old *ast.UDivInst) (*ir.InstUDiv, error) { - i, ok := inst.(*ir.InstUDiv) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstUDiv, got %T", inst)) - } - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ sdiv ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstSDiv(inst ir.Instruction, old *ast.SDivInst) (*ir.InstSDiv, error) { - i, ok := inst.(*ir.InstSDiv) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstSDiv, got %T", inst)) - } - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ fdiv ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstFDiv(inst ir.Instruction, old *ast.FDivInst) (*ir.InstFDiv, error) { - i, ok := inst.(*ir.InstFDiv) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFDiv, got %T", inst)) - } - // Fast math flags. - i.FastMathFlags = irFastMathFlags(old.FastMathFlags()) - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ urem ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstURem(inst ir.Instruction, old *ast.URemInst) (*ir.InstURem, error) { - i, ok := inst.(*ir.InstURem) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstURem, got %T", inst)) - } - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ srem ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstSRem(inst ir.Instruction, old *ast.SRemInst) (*ir.InstSRem, error) { - i, ok := inst.(*ir.InstSRem) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstSRem, got %T", inst)) - } - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ frem ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstFRem(inst ir.Instruction, old *ast.FRemInst) (*ir.InstFRem, error) { - i, ok := inst.(*ir.InstFRem) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFRem, got %T", inst)) - } - // Fast math flags. - i.FastMathFlags = irFastMathFlags(old.FastMathFlags()) - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// --- [ Bitwise instructions ] ------------------------------------------------ - -// ~~~ [ shl ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstShl(inst ir.Instruction, old *ast.ShlInst) (*ir.InstShl, error) { - i, ok := inst.(*ir.InstShl) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstShl, got %T", inst)) - } - // Overflow flags. - i.OverflowFlags = irOverflowFlags(old.OverflowFlags()) - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ lshr ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstLShr(inst ir.Instruction, old *ast.LShrInst) (*ir.InstLShr, error) { - i, ok := inst.(*ir.InstLShr) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstLShr, got %T", inst)) - } - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ ashr ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstAShr(inst ir.Instruction, old *ast.AShrInst) (*ir.InstAShr, error) { - i, ok := inst.(*ir.InstAShr) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstAShr, got %T", inst)) - } - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ and ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstAnd(inst ir.Instruction, old *ast.AndInst) (*ir.InstAnd, error) { - i, ok := inst.(*ir.InstAnd) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstAnd, got %T", inst)) - } - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ or ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstOr(inst ir.Instruction, old *ast.OrInst) (*ir.InstOr, error) { - i, ok := inst.(*ir.InstOr) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstOr, got %T", inst)) - } - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// ~~~ [ xor ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstXor(inst ir.Instruction, old *ast.XorInst) (*ir.InstXor, error) { - i, ok := inst.(*ir.InstXor) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstXor, got %T", inst)) - } - // X operand. - xType, err := fgen.gen.irType(old.X().Typ()) - if err != nil { - return nil, errors.WithStack(err) - } - x, err := fgen.astToIRTypeValue(old.X()) - if err != nil { - return nil, errors.WithStack(err) - } - i.X = x - // Y operand. - y, err := fgen.astToIRValue(xType, old.Y()) - if err != nil { - return nil, errors.WithStack(err) - } - i.Y = y - return i, nil -} - -// --- [ Vector instructions ] ------------------------------------------------- - -// ~~~ [ extractelement ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstExtractElement(inst ir.Instruction, old *ast.ExtractElementInst) (*ir.InstExtractElement, error) { - i, ok := inst.(*ir.InstExtractElement) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstExtractElement, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ insertelement ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstInsertElement(inst ir.Instruction, old *ast.InsertElementInst) (*ir.InstInsertElement, error) { - i, ok := inst.(*ir.InstInsertElement) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstInsertElement, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ shufflevector ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstShuffleVector(inst ir.Instruction, old *ast.ShuffleVectorInst) (*ir.InstShuffleVector, error) { - i, ok := inst.(*ir.InstShuffleVector) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstShuffleVector, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// --- [ Aggregate instructions ] ---------------------------------------------- - -// ~~~ [ extractvalue ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstExtractValue(inst ir.Instruction, old *ast.ExtractValueInst) (*ir.InstExtractValue, error) { - i, ok := inst.(*ir.InstExtractValue) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstExtractValue, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ insertvalue ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstInsertValue(inst ir.Instruction, old *ast.InsertValueInst) (*ir.InstInsertValue, error) { - i, ok := inst.(*ir.InstInsertValue) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstInsertValue, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// --- [ Memory instructions ] ------------------------------------------------- - -// ~~~ [ alloca ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstAlloca(inst ir.Instruction, old *ast.AllocaInst) (*ir.InstAlloca, error) { - i, ok := inst.(*ir.InstAlloca) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstAlloca, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ load ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstLoad(inst ir.Instruction, old *ast.LoadInst) (*ir.InstLoad, error) { - i, ok := inst.(*ir.InstLoad) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstLoad, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ store ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstStore(inst ir.Instruction, old *ast.StoreInst) (*ir.InstStore, error) { - i, ok := inst.(*ir.InstStore) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstStore, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ fence ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstFence(inst ir.Instruction, old *ast.FenceInst) (*ir.InstFence, error) { - i, ok := inst.(*ir.InstFence) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFence, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ cmpxchg ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstCmpXchg(inst ir.Instruction, old *ast.CmpXchgInst) (*ir.InstCmpXchg, error) { - i, ok := inst.(*ir.InstCmpXchg) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstCmpXchg, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ atomicrmw ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstAtomicRMW(inst ir.Instruction, old *ast.AtomicRMWInst) (*ir.InstAtomicRMW, error) { - i, ok := inst.(*ir.InstAtomicRMW) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstAtomicRMW, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ getelementptr ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstGetElementPtr(inst ir.Instruction, old *ast.GetElementPtrInst) (*ir.InstGetElementPtr, error) { - i, ok := inst.(*ir.InstGetElementPtr) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstGetElementPtr, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// --- [ Conversion instructions ] --------------------------------------------- - -// ~~~ [ trunc ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstTrunc(inst ir.Instruction, old *ast.TruncInst) (*ir.InstTrunc, error) { - i, ok := inst.(*ir.InstTrunc) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstTrunc, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ zext ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstZExt(inst ir.Instruction, old *ast.ZExtInst) (*ir.InstZExt, error) { - i, ok := inst.(*ir.InstZExt) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstZExt, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ sext ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstSExt(inst ir.Instruction, old *ast.SExtInst) (*ir.InstSExt, error) { - i, ok := inst.(*ir.InstSExt) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstSExt, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ fptrunc ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstFPTrunc(inst ir.Instruction, old *ast.FPTruncInst) (*ir.InstFPTrunc, error) { - i, ok := inst.(*ir.InstFPTrunc) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFPTrunc, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ fpext ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstFPExt(inst ir.Instruction, old *ast.FPExtInst) (*ir.InstFPExt, error) { - i, ok := inst.(*ir.InstFPExt) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFPExt, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ fptoui ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstFPToUI(inst ir.Instruction, old *ast.FPToUIInst) (*ir.InstFPToUI, error) { - i, ok := inst.(*ir.InstFPToUI) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFPToUI, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ fptosi ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstFPToSI(inst ir.Instruction, old *ast.FPToSIInst) (*ir.InstFPToSI, error) { - i, ok := inst.(*ir.InstFPToSI) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFPToSI, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ uitofp ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstUIToFP(inst ir.Instruction, old *ast.UIToFPInst) (*ir.InstUIToFP, error) { - i, ok := inst.(*ir.InstUIToFP) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstUIToFP, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ sitofp ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstSIToFP(inst ir.Instruction, old *ast.SIToFPInst) (*ir.InstSIToFP, error) { - i, ok := inst.(*ir.InstSIToFP) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstSIToFP, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ ptrtoint ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstPtrToInt(inst ir.Instruction, old *ast.PtrToIntInst) (*ir.InstPtrToInt, error) { - i, ok := inst.(*ir.InstPtrToInt) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstPtrToInt, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ inttoptr ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstIntToPtr(inst ir.Instruction, old *ast.IntToPtrInst) (*ir.InstIntToPtr, error) { - i, ok := inst.(*ir.InstIntToPtr) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstIntToPtr, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ bitcast ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstBitCast(inst ir.Instruction, old *ast.BitCastInst) (*ir.InstBitCast, error) { - i, ok := inst.(*ir.InstBitCast) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstBitCast, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ addrspacecast ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstAddrSpaceCast(inst ir.Instruction, old *ast.AddrSpaceCastInst) (*ir.InstAddrSpaceCast, error) { - i, ok := inst.(*ir.InstAddrSpaceCast) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstAddrSpaceCast, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// --- [ Other instructions ] -------------------------------------------------- - -// ~~~ [ icmp ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstICmp(inst ir.Instruction, old *ast.ICmpInst) (*ir.InstICmp, error) { - i, ok := inst.(*ir.InstICmp) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstICmp, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ fcmp ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstFCmp(inst ir.Instruction, old *ast.FCmpInst) (*ir.InstFCmp, error) { - i, ok := inst.(*ir.InstFCmp) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstFCmp, got %T", inst)) - } - // Fast math flags. - i.FastMathFlags = irFastMathFlags(old.FastMathFlags()) - // TODO: implement - return i, nil -} - -// ~~~ [ phi ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstPhi(inst ir.Instruction, old *ast.PhiInst) (*ir.InstPhi, error) { - i, ok := inst.(*ir.InstPhi) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstPhi, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ select ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstSelect(inst ir.Instruction, old *ast.SelectInst) (*ir.InstSelect, error) { - i, ok := inst.(*ir.InstSelect) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstSelect, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ call ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstCall(inst ir.Instruction, old *ast.CallInst) (*ir.InstCall, error) { - i, ok := inst.(*ir.InstCall) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstCall, got %T", inst)) - } - // Fast math flags. - i.FastMathFlags = irFastMathFlags(old.FastMathFlags()) - // Calling convention. - i.CallingConv = irOptCallingConv(old.CallingConv()) - return i, nil -} - -// ~~~ [ va_arg ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstVAArg(inst ir.Instruction, old *ast.VAArgInst) (*ir.InstVAArg, error) { - i, ok := inst.(*ir.InstVAArg) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstVAArg, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ landingpad ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstLandingPad(inst ir.Instruction, old *ast.LandingPadInst) (*ir.InstLandingPad, error) { - i, ok := inst.(*ir.InstLandingPad) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstLandingPad, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ catchpad ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstCatchPad(inst ir.Instruction, old *ast.CatchPadInst) (*ir.InstCatchPad, error) { - i, ok := inst.(*ir.InstCatchPad) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstCatchPad, got %T", inst)) - } - // TODO: implement - return i, nil -} - -// ~~~ [ cleanuppad ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -func (fgen *funcGen) astToIRInstCleanupPad(inst ir.Instruction, old *ast.CleanupPadInst) (*ir.InstCleanupPad, error) { - i, ok := inst.(*ir.InstCleanupPad) - if !ok { - // NOTE: panic since this would indicate a bug in the implementation. - panic(fmt.Errorf("invalid IR instruction for AST instruction; expected *ir.InstCleanupPad, got %T", inst)) - } - // TODO: implement - return i, nil -} - // ### [ Helper functions ] #################################################### // NOTE: aggregateElemType is copied from llir/l/ir/inst_aggregate.go and the