示例#1
0
文件: stmt.go 项目: qioixiy/llgo
func (c *compiler) VisitIncDecStmt(stmt *ast.IncDecStmt) {
	lhs := c.VisitExpr(stmt.X).(*LLVMValue)
	rhs := c.NewConstValue(exact.MakeUint64(1), lhs.Type())
	op := token.ADD
	if stmt.Tok == token.DEC {
		op = token.SUB
	}
	result := lhs.BinaryOp(op, rhs)
	c.builder.CreateStore(result.LLVMValue(), lhs.pointer.LLVMValue())

	// TODO make sure we cover all possibilities (maybe just delegate this to
	// an assignment statement handler, and do it all in one place).
	//
	// In the case of a simple variable, we simply calculate the new value and
	// update the value in the scope.
}
示例#2
0
func (c *checker) InsertMetricValuesFromContext(m *metrics.MetricContext) error {
	for metricName, metric := range m.Gauges {
		name := strings.Replace(metricName, ".", "_", -1) + "_value"
		c.sc.Insert(types.NewConst(0, c.pkg, name,
			types.New("float64"), exact.MakeFloat64(metric.Get())))
		sname := name + "_string"
		c.sc.Insert(types.NewConst(0, c.pkg, sname,
			types.New("string"), exact.MakeString(fmt.Sprintf("%0.2f", metric.Get()))))
	}
	for metricName, metric := range m.Counters {
		name := strings.Replace(metricName, ".", "_", -1) + "_current"
		c.sc.Insert(types.NewConst(0, c.pkg, name,
			types.New("float64"), exact.MakeUint64(metric.Get())))
		sname := name + "_string"
		c.sc.Insert(types.NewConst(0, c.pkg, sname,
			types.New("string"), exact.MakeString(fmt.Sprintf("%d", metric.Get()))))
		name = strings.Replace(metricName, ".", "_", -1) + "_rate"
		c.sc.Insert(types.NewConst(0, c.pkg, name,
			types.New("float64"), exact.MakeFloat64(metric.ComputeRate())))
	}
	return nil
}