aboutsummaryrefslogtreecommitdiffhomepage
path: root/builder/error.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-11-11 15:26:15 +0100
committerRon Evans <[email protected]>2019-11-11 20:53:50 +0100
commit8e6cb89ceb47ec031863b8edb0cc4002215acc43 (patch)
treed61699293f9f19e9e8d02b42f65b2ab631e9f768 /builder/error.go
parent946e2dd405b66eecd51a9d9f3f82555c7e13a7d7 (diff)
downloadtinygo-8e6cb89ceb47ec031863b8edb0cc4002215acc43.tar.gz
tinygo-8e6cb89ceb47ec031863b8edb0cc4002215acc43.zip
main: refactor compile/link part to a builder package
This is a large commit that moves all code directly related to compiling/linking into a new builder package. This has a number of advantages: * It cleanly separates the API between the command line and the full compilation (with a very small API surface). * When the compiler finally compiles one package at a time (instead of everything at once as it does now), something will have to invoke it once per package. This builder package will be the natural place to do that, and also be the place where the whole process can be parallelized. * It allows the TinyGo compiler to be used as a package. A client can simply import the builder package and compile code using it. As part of this refactor, the following additional things changed: * Exported symbols have been made unexported when they weren't needed. * The compilation target has been moved into the compileopts.Options struct. This is done because the target really is just another compiler option, and the API is simplified by moving it in there. * The moveFile function has been duplicated. It does not really belong in the builder API but is used both by the builder and the command line. Moving it into a separate package didn't seem useful either for what is essentially an utility function. * Some doc strings have been improved. Some future changes/refactors I'd like to make after this commit: * Clean up the API between the builder and the compiler package. * Perhaps move the test files (in testdata/) into the builder package. * Perhaps move the loader package into the builder package.
Diffstat (limited to 'builder/error.go')
-rw-r--r--builder/error.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/builder/error.go b/builder/error.go
new file mode 100644
index 000000000..a6f59eb08
--- /dev/null
+++ b/builder/error.go
@@ -0,0 +1,25 @@
+package builder
+
+// MultiError is a list of multiple errors (actually: diagnostics) returned
+// during LLVM IR generation.
+type MultiError struct {
+ Errs []error
+}
+
+func (e *MultiError) Error() string {
+ // Return the first error, to conform to the error interface. Clients should
+ // really do a type-assertion on *MultiError.
+ return e.Errs[0].Error()
+}
+
+// commandError is an error type to wrap os/exec.Command errors. This provides
+// some more information regarding what went wrong while running a command.
+type commandError struct {
+ Msg string
+ File string
+ Err error
+}
+
+func (e *commandError) Error() string {
+ return e.Msg + " " + e.File + ": " + e.Err.Error()
+}