Exemplo n.º 1
0
Arquivo: main.go Projeto: DanB91/dcpu
func main() {
	parseArgs()

	// Collect all the source code into the given AST.
	// This takes care of resolving includes and identifying
	// unresolved label references.
	var ast parser.AST

	err := util.ReadSource(&ast, infile, includes)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Source reader: %v\n", err)
		os.Exit(1)
	}

	// Run pre-processors on the generated AST.
	err = PreProcess(&ast, *optimize)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Pre processor: %v\n", err)
		os.Exit(1)
	}

	// Dump AST or source code if necessary.
	if *dumpast || *dumpsrc {
		err = writeSource(&ast, *outfile, *dumpast)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Source writer: %v\n", err)
			os.Exit(1)
		}
		os.Exit(0)
	}

	// Assemble program.
	program, dbg, err := asm.Assemble(&ast)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Assembler: %v\n", err)
		os.Exit(1)
	}

	// Run post-processors on generated binary code and debug symbols.
	err = PostProcess(program, dbg, *optimize)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Post processor: %v\n", err)
		os.Exit(1)
	}

	// Write debug file.
	if err = writeDebug(dbg, *debugfile); err != nil {
		fmt.Fprintf(os.Stderr, "Debug writer: %v\n", err)
		os.Exit(1)
	}

	// Write binary output.
	if err = writeProgram(program, *outfile, *littleendian); err != nil {
		fmt.Fprintf(os.Stderr, "Binary writer: %v\n", err)
		os.Exit(1)
	}
}
Exemplo n.º 2
0
Arquivo: test.go Projeto: DanB91/dcpu
// parse reads the test source and constructs a complete AST.
// This includes importing externally referenced files.
func (t *Test) parse() (*dp.AST, error) {
	var ast dp.AST

	err := util.ReadSource(&ast, t.file, t.includes)
	if err != nil {
		return nil, err
	}

	return &ast, nil
}