diff --git a/compiler/compile-unit.go b/compiler/compile-unit.go index b1377f7..7433a8b 100644 --- a/compiler/compile-unit.go +++ b/compiler/compile-unit.go @@ -35,7 +35,9 @@ func (this *Compiler) CompileUnit (address entity.Address) error { // extension of the input. if that isn't specified, default to .o if this.Filetype == FiletypeUnknown { var ok bool - this.Filetype, ok = FiletypeFromExt(filepath.Ext(this.Output)) + this.Filetype, ok = FiletypeFromExt ( + *this.Target, + filepath.Ext(this.Output)) if !ok { this.Filetype = FiletypeObject } @@ -46,7 +48,7 @@ func (this *Compiler) CompileUnit (address entity.Address) error { if this.Output == "" { nickname, ok := entity.Address(path).Nickname() if !ok { nickname = "output" } - this.Output = this.Filetype.Extend(nickname) + this.Output = this.Filetype.Extend(*this.Target, nickname) } // do something based on the output extension diff --git a/compiler/filetype.go b/compiler/filetype.go index e229b10..040ea7b 100644 --- a/compiler/filetype.go +++ b/compiler/filetype.go @@ -1,6 +1,7 @@ package compiler import "fmt" +import "git.tebibyte.media/fspl/fspl/generator" // Filetype represents an output filetype. type Filetype int; const ( @@ -24,15 +25,13 @@ func FiletypeFromString (ext string) (Filetype, bool) { } // FiletypeFromExt returns a filetype based on the given filename extension. -func FiletypeFromExt (ext string) (Filetype, bool) { - // FIXME some of these are platform dependent, for example on windows - // FiletypeLib would be .dll +func FiletypeFromExt (target generator.Target, ext string) (Filetype, bool) { switch ext { - case ".o": return FiletypeObject, true - case ".so": return FiletypeLibrary, true - case ".s": return FiletypeAssembly, true - case ".ll": return FiletypeIR, true - default: return FiletypeUnknown, false + case ".o": return FiletypeObject, true + case targetSoExt(target): return FiletypeLibrary, true + case ".s": return FiletypeAssembly, true + case ".ll": return FiletypeIR, true + default: return FiletypeUnknown, false } } @@ -49,12 +48,11 @@ func (filetype Filetype) String () string { } // Ext returns the standard filename extension of the filetype. -func (filetype Filetype) Ext () string { - // FIXME again, some of these are platform dependent +func (filetype Filetype) Ext (target generator.Target) string { switch filetype { case FiletypeUnknown: return "" case FiletypeObject: return ".o" - case FiletypeLibrary: return ".so" + case FiletypeLibrary: return targetSoExt(target) case FiletypeAssembly: return ".s" case FiletypeIR: return ".ll" default: return "" @@ -62,6 +60,14 @@ func (filetype Filetype) Ext () string { } // Extend adds the extension of the filetype onto the specified path. -func (filetype Filetype) Extend (path string) string { - return path + filetype.Ext() +func (filetype Filetype) Extend (target generator.Target, path string) string { + return path + filetype.Ext(target) +} + +func targetSoExt (target generator.Target) string { + // TODO: more research is required here + switch target.OS { + case "windows": return ".dll" + default: return ".so" + } }