2015-01-22 10:48:02 -08:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
// Package flags implements top-level flags and the usage message for the assembler.
|
|
|
|
|
package flags
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
2015-01-28 15:41:12 -08:00
|
|
|
Debug = flag.Bool("debug", false, "dump instructions as they are parsed")
|
|
|
|
|
OutputFile = flag.String("o", "", "output file; default foo.6 for /a/b/c/foo.s on amd64")
|
|
|
|
|
PrintOut = flag.Bool("S", false, "print assembly and machine code")
|
2015-02-24 14:28:49 -08:00
|
|
|
TrimPath = flag.String("trimpath", "", "remove prefix from recorded source file paths")
|
2015-01-22 10:48:02 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
D MultiFlag
|
|
|
|
|
I MultiFlag
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
flag.Var(&D, "D", "predefined symbol with optional simple value -D=identifer=value; can be set multiple times")
|
|
|
|
|
flag.Var(&I, "I", "include directory; can be set multiple times")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MultiFlag allows setting a value multiple times to collect a list, as in -I=dir1 -I=dir2.
|
|
|
|
|
type MultiFlag []string
|
|
|
|
|
|
|
|
|
|
func (m *MultiFlag) String() string {
|
|
|
|
|
return fmt.Sprint(*m)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *MultiFlag) Set(val string) error {
|
|
|
|
|
(*m) = append(*m, val)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Usage() {
|
|
|
|
|
fmt.Fprintf(os.Stderr, "usage: asm [options] file.s\n")
|
|
|
|
|
fmt.Fprintf(os.Stderr, "Flags:\n")
|
|
|
|
|
flag.PrintDefaults()
|
|
|
|
|
os.Exit(2)
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-02 10:56:41 -08:00
|
|
|
func Parse(theChar int) {
|
2015-01-22 10:48:02 -08:00
|
|
|
flag.Usage = Usage
|
|
|
|
|
flag.Parse()
|
|
|
|
|
if flag.NArg() != 1 {
|
|
|
|
|
flag.Usage()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Flag refinement.
|
|
|
|
|
if *OutputFile == "" {
|
|
|
|
|
input := filepath.Base(flag.Arg(0))
|
|
|
|
|
if strings.HasSuffix(input, ".s") {
|
|
|
|
|
input = input[:len(input)-2]
|
|
|
|
|
}
|
|
|
|
|
*OutputFile = fmt.Sprintf("%s.%c", input, theChar)
|
|
|
|
|
}
|
|
|
|
|
}
|