Documentation
¶
Overview ¶
Copyright 2022 gorse Project Authors Copyright 2023 Roman Atachiants
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompileRequest ¶ added in v0.31.0
type CompileRequest struct {
Arch string `json:"arch"`
Package string `json:"package"`
Options []string `json:"options,omitempty"`
// Suffix is added to the names of the generated files, FunctionSuffix to
// the names of the generated functions.
Suffix string `json:"suffix,omitempty"`
FunctionSuffix string `json:"functionSuffix,omitempty"`
// OS, when set, is added to the build tags of the generated files. It is
// the operating system of the client: the server may run another one.
OS string `json:"os,omitempty"`
WithInternalFunctions bool `json:"withInternalFunctions,omitempty"`
// Source names the file to translate among Files.
Source string `json:"source"`
// Files holds the source and the files it includes, by their
// slash-separated path relative to a common directory.
Files map[string][]byte `json:"files"`
}
CompileRequest is what a Remote sends to a Server: a C source, the files it includes and the options of the translation.
type CompileResult ¶ added in v0.31.0
type CompileResult struct {
Asm File `json:"asm"`
Go File `json:"go"`
// Diagnostics is what the compiler printed while succeeding: its warnings.
Diagnostics string `json:"diagnostics,omitempty"`
}
CompileResult is the answer of a Server to a CompileRequest.
type Local ¶
type Local struct {
Arch *config.Arch
Clang *cc.Compiler
ObjDump *cc.Disassembler
Source string
FuncSuffix string
Assembly string
Object string
GoAssembly string
GoStub string
Package string
Options []string
// WithInternalFunctions enables the compiler and ABI conventions required
// for C functions that call compiler-emitted helper functions.
WithInternalFunctions bool
}
Local translates a C file to Go assembly
func NewLocal ¶
func NewLocal(arch *config.Arch, source, outputDir, suffix, functionSuffix, packageName string, options ...string) (*Local, error)
NewLocal creates a new translator that uses locally installed toolchain
func (*Local) Output ¶
func (t *Local) Output() (*CompileResult, error)
Output returns the generated files, named without their directory.
type Remote ¶
type Remote struct {
// Server is the address of the server, such as http://mac.local:8080.
Server string
// Token is the secret the server was started with, if any.
Token string
Arch string
Source string
Output string // directory the generated files are written to
Package string // name of that directory when empty
Suffix string
FuncSuffix string
OS string
Options []string
WithInternalFunctions bool
// Client is used for the request; one with a timeout longer than a
// compilation should take when nil.
Client *http.Client
}
Remote translates a C file to Go assembly on another machine, which runs a Server. The machine running the Remote needs no C toolchain.
type Server ¶ added in v0.31.0
type Server struct {
// Token, when set, has to be presented by every client.
Token string
// Timeout is the time one translation may take. Two minutes when zero.
Timeout time.Duration
// MaxRequestBytes limits the size of a request. 32 MiB when zero.
MaxRequestBytes int64
// Concurrency is the number of translations running at once; further
// requests wait. The number of CPUs when zero.
Concurrency int
// contains filtered or unexported fields
}
Server translates the C sources that Remote clients send it, with the toolchain of the machine it runs on.
It is meant for machines and networks you trust. A client chooses the compiler options and the source, and so can make the compiler read and write files as the user running the server. Token keeps strangers out; it does not make the server safe to expose to them.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
gocc
command
|
|
|
webserver
command
The webserver translates C sources for gocc clients that have no C toolchain of their own, or that should all use the compiler of one machine.
|
The webserver translates C sources for gocc clients that have no C toolchain of their own, or that should all use the compiler of one machine. |
|
example
|
|
|
internal
|
|