Function pointers in global variables
Этот коммит содержится в:
		
							родитель
							
								
									a4fd096393
								
							
						
					
					
						коммит
						7956ca2f29
					
				
					 2 изменённых файлов: 19 добавлений и 1 удалений
				
			
		
							
								
								
									
										10
									
								
								compiler.go
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								compiler.go
									
										
									
									
									
								
							|  | @ -755,6 +755,16 @@ func (c *Compiler) getInterpretedValue(value Value) (llvm.Value, error) { | |||
| 	case *ConstValue: | ||||
| 		return c.parseConst(value.Expr) | ||||
| 
 | ||||
| 	case *FunctionValue: | ||||
| 		if value.Elem == nil { | ||||
| 			llvmType, err := c.getLLVMType(value.Type) | ||||
| 			if err != nil { | ||||
| 				return llvm.Value{}, err | ||||
| 			} | ||||
| 			return getZeroValue(llvmType) | ||||
| 		} | ||||
| 		return c.ir.GetFunction(value.Elem).llvmFn, nil | ||||
| 
 | ||||
| 	case *GlobalValue: | ||||
| 		zero := llvm.ConstInt(llvm.Int32Type(), 0, false) | ||||
| 		ptr := llvm.ConstInBoundsGEP(value.Global.llvmGlobal, []llvm.Value{zero}) | ||||
|  |  | |||
|  | @ -188,6 +188,8 @@ func (p *Program) getValue(value ssa.Value, locals map[ssa.Value]Value) (Value, | |||
| 	switch value := value.(type) { | ||||
| 	case *ssa.Const: | ||||
| 		return &ConstValue{value}, nil | ||||
| 	case *ssa.Function: | ||||
| 		return &FunctionValue{value.Type(), value}, nil | ||||
| 	case *ssa.Global: | ||||
| 		if strings.HasPrefix(value.Name(), "__cgofn__cgo_") || strings.HasPrefix(value.Name(), "_cgo_") { | ||||
| 			// Ignore CGo global variables which we don't use. | ||||
|  | @ -202,7 +204,6 @@ func (p *Program) getValue(value ssa.Value, locals map[ssa.Value]Value) (Value, | |||
| 			g.initializer = value | ||||
| 		} | ||||
| 		return &GlobalValue{g}, nil | ||||
| 		//return &PointerValue{&g.initializer}, nil | ||||
| 	default: | ||||
| 		if local, ok := locals[value]; ok { | ||||
| 			return local, nil | ||||
|  | @ -226,6 +227,8 @@ func (p *Program) getZeroValue(t types.Type) (Value, error) { | |||
| 		return &ArrayValue{typ.Elem(), elems}, nil | ||||
| 	case *types.Basic: | ||||
| 		return &ZeroBasicValue{typ}, nil | ||||
| 	case *types.Signature: | ||||
| 		return &FunctionValue{typ, nil}, nil | ||||
| 	case *types.Interface: | ||||
| 		return &InterfaceValue{typ, nil}, nil | ||||
| 	case *types.Map: | ||||
|  | @ -265,6 +268,11 @@ type PointerValue struct { | |||
| 	Elem *Value | ||||
| } | ||||
| 
 | ||||
| type FunctionValue struct { | ||||
| 	Type types.Type | ||||
| 	Elem *ssa.Function | ||||
| } | ||||
| 
 | ||||
| type InterfaceValue struct { | ||||
| 	Type types.Type | ||||
| 	Elem Value | ||||
|  |  | |||
		Загрузка…
	
	Создание таблицы
		
		Сослаться в новой задаче
	
	 Ayke van Laethem
						Ayke van Laethem