compiler: produce .hex files directly
Этот коммит содержится в:
		
							родитель
							
								
									f41a8032e7
								
							
						
					
					
						коммит
						c763e9f1a6
					
				
					 4 изменённых файлов: 21 добавлений и 4 удалений
				
			
		
							
								
								
									
										17
									
								
								main.go
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								main.go
									
										
									
									
									
								
							|  | @ -89,6 +89,7 @@ func Compile(pkgName, runtimePath, outpath, target string, printIR, dumpSSA bool | ||||||
| 
 | 
 | ||||||
| 		// Link the object file with the system compiler. | 		// Link the object file with the system compiler. | ||||||
| 		executable := filepath.Join(dir, "main") | 		executable := filepath.Join(dir, "main") | ||||||
|  | 		tmppath := executable // final file | ||||||
| 		args := append(spec.PreLinkArgs, "-o", executable, objfile) | 		args := append(spec.PreLinkArgs, "-o", executable, objfile) | ||||||
| 		cmd := exec.Command(spec.Linker, args...) | 		cmd := exec.Command(spec.Linker, args...) | ||||||
| 		cmd.Stdout = os.Stdout | 		cmd.Stdout = os.Stdout | ||||||
|  | @ -98,9 +99,21 @@ func Compile(pkgName, runtimePath, outpath, target string, printIR, dumpSSA bool | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if err := os.Rename(executable, outpath); err != nil { | 		if strings.HasSuffix(outpath, ".hex") { | ||||||
|  | 			// Get an Intel .hex file from the .elf file. | ||||||
|  | 			tmppath = filepath.Join(dir, "main.hex") | ||||||
|  | 			cmd := exec.Command(spec.Objcopy, "-O", "ihex", executable, tmppath) | ||||||
|  | 			cmd.Stdout = os.Stdout | ||||||
|  | 			cmd.Stderr = os.Stderr | ||||||
|  | 			err = cmd.Run() | ||||||
|  | 			if err != nil { | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if err := os.Rename(tmppath, outpath); err != nil { | ||||||
| 			// Moving failed. Do a file copy. | 			// Moving failed. Do a file copy. | ||||||
| 			inf, err := os.Open(executable) | 			inf, err := os.Open(tmppath) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				return err | 				return err | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | @ -18,6 +18,7 @@ type TargetSpec struct { | ||||||
| 	BuildTags   []string `json:"build-tags"` | 	BuildTags   []string `json:"build-tags"` | ||||||
| 	Linker      string   `json:"linker"` | 	Linker      string   `json:"linker"` | ||||||
| 	PreLinkArgs []string `json:"pre-link-args"` | 	PreLinkArgs []string `json:"pre-link-args"` | ||||||
|  | 	Objcopy     string   `json:"objcopy"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Load a target specification | // Load a target specification | ||||||
|  | @ -26,6 +27,7 @@ func LoadTarget(target string) (*TargetSpec, error) { | ||||||
| 		Triple:    target, | 		Triple:    target, | ||||||
| 		BuildTags: []string{runtime.GOOS, runtime.GOARCH}, | 		BuildTags: []string{runtime.GOOS, runtime.GOARCH}, | ||||||
| 		Linker:    "cc", | 		Linker:    "cc", | ||||||
|  | 		Objcopy:   "objcopy", | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// See whether there is a target specification for this target (e.g. | 	// See whether there is a target specification for this target (e.g. | ||||||
|  |  | ||||||
|  | @ -2,5 +2,6 @@ | ||||||
| 	"llvm-target": "avr-atmel-none", | 	"llvm-target": "avr-atmel-none", | ||||||
| 	"build-tags": ["avr", "avr8", "atmega", "atmega328p", "js", "wasm"], | 	"build-tags": ["avr", "avr8", "atmega", "atmega328p", "js", "wasm"], | ||||||
| 	"linker": "avr-gcc", | 	"linker": "avr-gcc", | ||||||
| 	"pre-link-args": ["-nostdlib", "-T", "targets/avr.ld", "-Wl,--gc-sections", "targets/avr.S"] | 	"pre-link-args": ["-nostdlib", "-T", "targets/avr.ld", "-Wl,--gc-sections", "targets/avr.S"], | ||||||
|  | 	"objcopy": "avr-objcopy" | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -2,5 +2,6 @@ | ||||||
| 	"llvm-target": "armv7m-none-eabi", | 	"llvm-target": "armv7m-none-eabi", | ||||||
| 	"build-tags": ["nrf", "nrf52", "nrf52832", "js", "wasm"], | 	"build-tags": ["nrf", "nrf52", "nrf52832", "js", "wasm"], | ||||||
| 	"linker": "arm-none-eabi-gcc", | 	"linker": "arm-none-eabi-gcc", | ||||||
| 	"pre-link-args": ["-nostdlib", "-nostartfiles", "-mcpu=cortex-m4", "-mthumb", "-T", "targets/arm.ld", "-Wl,--gc-sections", "-fno-exceptions", "-fno-unwind-tables", "-ffunction-sections", "-fdata-sections", "-Os", "-DNRF52832_XXAA", "-D__STARTUP_CLEAR_BSS", "-Ilib/CMSIS/CMSIS/Include", "lib/nrfx/mdk/gcc_startup_nrf51.S", "lib/nrfx/mdk/system_nrf52.c"] | 	"pre-link-args": ["-nostdlib", "-nostartfiles", "-mcpu=cortex-m4", "-mthumb", "-T", "targets/arm.ld", "-Wl,--gc-sections", "-fno-exceptions", "-fno-unwind-tables", "-ffunction-sections", "-fdata-sections", "-Os", "-DNRF52832_XXAA", "-D__STARTUP_CLEAR_BSS", "-Ilib/CMSIS/CMSIS/Include", "lib/nrfx/mdk/gcc_startup_nrf51.S", "lib/nrfx/mdk/system_nrf52.c"], | ||||||
|  | 	"objcopy": "arm-none-eabi-objcopy" | ||||||
| } | } | ||||||
|  |  | ||||||
		Загрузка…
	
	Создание таблицы
		
		Сослаться в новой задаче
	
	 Ayke van Laethem
						Ayke van Laethem