Example #1
0
// backendNewColor returns a new colorful error string using the following
// format:
//    pkg.func (file:line): error: text
func backendNewColor(text string, skip int) error {
	pc, file, line, ok := runtime.Caller(skip)
	if !ok {
		return errors.New(term.RedBold("error: ") + text)
	}
	f := runtime.FuncForPC(pc)
	if f == nil {
		format := term.WhiteBold("(%s:%d): ") + term.RedBold("error: ") + "%s"
		return fmt.Errorf(format, path.Base(file), line, text)
	}
	format := term.MagentaBold("%s") + term.WhiteBold(" (%s:%d): ") + term.RedBold("error: ") + "%s"
	return fmt.Errorf(format, f.Name(), path.Base(file), line, text)
}
Example #2
0
File: err.go Project: mewkiz/pkg
func (pos *position) String() string {
	if pos == nil {
		return "<no position>"
	}
	filePos := fmt.Sprintf("(%s:%d):", pos.file, pos.line)

	if UseColor {
		// Use colors.
		filePosColor := term.WhiteBold(filePos)
		if pos.callee == "" {
			return filePosColor
		}
		return fmt.Sprintf("%s %s", term.MagentaBold(pos.callee), filePosColor)
	}

	// No colors.
	if pos.callee == "" {
		return filePos
	}
	return fmt.Sprintf("%s %s", pos.callee, filePos)
}
Example #3
0
File: irgen.go Project: mewmew/uc
	"log"

	"github.com/llir/llvm/ir"
	"github.com/llir/llvm/ir/instruction"
	irtypes "github.com/llir/llvm/ir/types"
	"github.com/llir/llvm/ir/value"
	"github.com/mewkiz/pkg/errutil"
	"github.com/mewkiz/pkg/term"
	"github.com/mewmew/uc/ast"
	"github.com/mewmew/uc/sem"
)

// TODO: Remove debug output.

// dbg is a logger which prefixes debug messages with "irgen:".
var dbg = log.New(ioutil.Discard, term.WhiteBold("irgen:"), log.Lshortfile)

// A Module represents an LLVM IR module generator.
type Module struct {
	// Module being generated.
	*ir.Module
	// info holds semantic information about the program from the type-checker.
	info *sem.Info
	// Maps from identifier source code position to the associated value.
	idents map[int]value.Value
}

// NewModule returns a new module generator.
func NewModule(info *sem.Info) *Module {
	m := ir.NewModule()
	return &Module{Module: m, info: info, idents: make(map[int]value.Value)}