-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from dekarrin/ghi016-selfhosting
Ghi016 selfhosting
- Loading branch information
Showing
23 changed files
with
1,552 additions
and
578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
# vim | ||
*.swp | ||
|
||
/testout | ||
/.testout | ||
/ictcc | ||
/.sim | ||
/.gen | ||
/diag | ||
/fishic | ||
|
||
# mac | ||
.DS_Store | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/dekarrin/ictiobus/types" | ||
) | ||
|
||
const ( | ||
// ExitSuccess is the exit code for a successful run. | ||
ExitSuccess = iota | ||
|
||
// ExitErrNoFiles is the code returned as exit status when no files are | ||
// provided to the invocation. | ||
ExitErrNoFiles | ||
|
||
// ExitErrInvalidFlags is used if the combination of flags specified is | ||
// invalid. | ||
ExitErrInvalidFlags | ||
|
||
// ExitErrSyntax is the code returned as exit status when a syntax error | ||
// occurs. | ||
ExitErrSyntax | ||
|
||
// ExitErrParser is the code returned as exit status when there is an error | ||
// generating the parser. | ||
ExitErrParser | ||
|
||
// ExitErrGeneration is the code returned as exit status when there is an | ||
// error creating the generated files. | ||
ExitErrGeneration | ||
|
||
// ExitErrOther is a generic error code for any other error. | ||
ExitErrOther | ||
) | ||
|
||
var ( | ||
exitStatus = ExitSuccess | ||
) | ||
|
||
// errNoFiles sets the exit status to ExitErrNoFiles and prints the given error | ||
// message to stderr by calling exitErr. | ||
// | ||
// Caller is responsible for exiting main immediately after this function | ||
// returns. | ||
func errNoFiles(msg string) { | ||
exitErr(ExitErrNoFiles, msg) | ||
} | ||
|
||
// errInvalidFlags sets the exit status to ExitErrInvalidFlags and prints the | ||
// given error message to stderr by calling exitErr. | ||
// | ||
// Caller is responsible for exiting main immediately after this function | ||
// returns. | ||
func errInvalidFlags(msg string) { | ||
exitErr(ExitErrInvalidFlags, msg) | ||
} | ||
|
||
// errSyntax sets the exit status to ExitErrSyntax and prints an error message | ||
// given by the syntax error to stderr. | ||
// | ||
// Caller is responsible for exiting main immediately after this function | ||
// returns. | ||
func errSyntax(filename string, synErr *types.SyntaxError) { | ||
if filename == "" { | ||
filename = "<INPUT>" | ||
} | ||
fmt.Fprintf(os.Stderr, "%s\n", synErr.MessageForFile(filename)) | ||
exitStatus = ExitErrSyntax | ||
} | ||
|
||
// errParser sets the exit status to ExitErrParser and prints the given error | ||
// message to stderr by calling exitErr. | ||
// | ||
// Caller is responsible for exiting main immediately after this function | ||
// returns. | ||
func errParser(msg string) { | ||
exitErr(ExitErrParser, msg) | ||
} | ||
|
||
// errGeneration sets the exit status to ExitErrGeneration and prints the given | ||
// error message to stderr by calling exitErr. | ||
// | ||
// Caller is responsible for exiting main immediately after this function | ||
// returns. | ||
func errGeneration(msg string) { | ||
exitErr(ExitErrGeneration, msg) | ||
} | ||
|
||
// errOther sets the exit status to ExitErrOther and prints the given error | ||
// message to stderr by calling exitErr. | ||
// | ||
// Caller is responsible for exiting main immediately after this function | ||
// returns. | ||
func errOther(msg string) { | ||
exitErr(ExitErrOther, msg) | ||
} | ||
|
||
// exitErr sets the exit status and prints "ERROR: " followed by the given | ||
// error message to stderr. Automatically ends printed message with a newline. | ||
// | ||
// Caller is responsible for exiting main immediately after this function | ||
// returns. | ||
func exitErr(statusCode int, msg string) { | ||
fmt.Fprintf(os.Stderr, "ERROR: %s\n", msg) | ||
exitStatus = statusCode | ||
} | ||
|
||
// basic function to check if panic is happening and recover it while also | ||
// preserving possibly-set exit code. Immediately call this as defered as first | ||
// statement in main. | ||
func preservePanicOrExitWithStatus() { | ||
if panicErr := recover(); panicErr != nil { | ||
// we are panicking, make sure we dont lose the panic just because | ||
// we checked | ||
panic("unrecoverable panic occured") | ||
} else { | ||
os.Exit(exitStatus) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package main | ||
|
||
const ( | ||
Version = "0.6.0" | ||
Version = "0.6.1" | ||
) | ||
|
||
func GetVersionString() string { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package fishi | ||
|
||
import "github.com/dekarrin/ictiobus" | ||
|
||
// File cgstructs.go contains structs used as part of code generation. | ||
|
||
// TODO: move most structs from codegen to here. | ||
|
||
// MainBinaryParams is paramters for generating a main.go file for a binary. | ||
// Unless otherwise specified, all fields are required. | ||
type MainBinaryParams struct { | ||
// Parser is the parser to use for the generated compiler. | ||
Parser ictiobus.Parser | ||
|
||
// HooksPkgDir is the path to the directory containing the hooks package. | ||
HooksPkgDir string | ||
|
||
// HooksExpr is the expression to use to get the hooks map. This can be a | ||
// function call, constant name, or var name. | ||
HooksExpr string | ||
|
||
// FormatPkgDir is the path to the directory containing the format package. | ||
// It is completely optional; if not set, the generated main will not | ||
// contain any pre-formatting code and will assume files are directly ready | ||
// to be fed into the frontend. Must be set if FormatCall is set. | ||
FormatPkgDir string | ||
|
||
// FormatCall is the name of a function within the package specified by | ||
// FormatPkgDir that gets an io.Reader that will run any required | ||
// pre-formatting on an input io.Reader to get code that can be analyzed by | ||
// the frontend. Is is optional; if not set, the generated main will not | ||
// contain any pre-formatting code and will assume files are directly ready | ||
// to be fed into the frontend. Must be set if FormatPkgDir is set. | ||
FormatCall string | ||
|
||
// FrontendPkgName is the name of the package to place generated frontend | ||
// code in. | ||
FrontendPkgName string | ||
|
||
// GenPath is the path to a directory to generate code in. If it does not | ||
// exist, it will be created. If it does exist, any existing files in it | ||
// will be removed will be emptied before code is generated. | ||
GenPath string | ||
|
||
// BinName is the name of the binary being generated. This will be used | ||
// within code for showing help output and other messages. | ||
BinName string | ||
|
||
// Opts are options for code generation. This must be set and its IRType | ||
// field is required to be set, but all other fields within it are optional. | ||
Opts CodegenOptions | ||
} |
Oops, something went wrong.