runtime: add runtime.nanotime
This function returns the current timestamp, or 0 at compile time. runtime.nanotime is used at package initialization by the time package starting with Go 1.12.
Этот коммит содержится в:
		
							родитель
							
								
									9c41011e17
								
							
						
					
					
						коммит
						4d82f42d61
					
				
					 3 изменённых файлов: 10 добавлений и 1 удалений
				
			
		|  | @ -310,6 +310,8 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re | |||
| 			case callee.Name() == "runtime.makeInterface": | ||||
| 				uintptrType := callee.Type().Context().IntType(fr.TargetData.PointerSize() * 8) | ||||
| 				fr.locals[inst] = &LocalValue{fr.Eval, llvm.ConstPtrToInt(inst.Operand(0), uintptrType)} | ||||
| 			case callee.Name() == "runtime.nanotime": | ||||
| 				fr.locals[inst] = &LocalValue{fr.Eval, llvm.ConstInt(fr.Mod.Context().Int64Type(), 0, false)} | ||||
| 			case strings.HasPrefix(callee.Name(), "runtime.print") || callee.Name() == "runtime._panic": | ||||
| 				// This are all print instructions, which necessarily have side | ||||
| 				// effects but no results. | ||||
|  |  | |||
|  | @ -28,6 +28,9 @@ func (e *Eval) hasSideEffects(fn llvm.Value) *sideEffectResult { | |||
| 	case "runtime.alloc": | ||||
| 		// Cannot be scanned but can be interpreted. | ||||
| 		return &sideEffectResult{severity: sideEffectNone} | ||||
| 	case "runtime.nanotime": | ||||
| 		// Fixed value at compile time. | ||||
| 		return &sideEffectResult{severity: sideEffectNone} | ||||
| 	case "runtime._panic": | ||||
| 		return &sideEffectResult{severity: sideEffectLimited} | ||||
| 	} | ||||
|  |  | |||
|  | @ -84,9 +84,13 @@ func sleep(d int64) { | |||
| 	sleepTicks(timeUnit(d / tickMicros)) | ||||
| } | ||||
| 
 | ||||
| func nanotime() int64 { | ||||
| 	return int64(ticks()) * tickMicros | ||||
| } | ||||
| 
 | ||||
| //go:linkname now time.now | ||||
| func now() (sec int64, nsec int32, mono int64) { | ||||
| 	mono = int64(ticks()) * tickMicros | ||||
| 	mono = nanotime() | ||||
| 	sec = mono / (1000 * 1000 * 1000) | ||||
| 	nsec = int32(mono - sec*(1000*1000*1000)) | ||||
| 	return | ||||
|  |  | |||
		Загрузка…
	
	Создание таблицы
		
		Сослаться в новой задаче
	
	 Ayke van Laethem
						Ayke van Laethem