Skip to content

Commit 41a2510

Browse files
authored
Merge pull request #6111 from xmake-io/ti
Support TI-CGT C6000 compiler
2 parents ff79cf6 + 7b0bfaa commit 41a2510

File tree

10 files changed

+590
-0
lines changed

10 files changed

+590
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ iverilog Icarus Verilog
246246
verilator Verilator open-source SystemVerilog simulator and lint system
247247
cosmocc build-once run-anywhere
248248
hdk Harmony SDK
249+
ti-c6000 TI-CGT C6000 compiler
249250
```
250251

251252
## Supported languages

README_zh.md

+1
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ iverilog Icarus Verilog
307307
verilator Verilator open-source SystemVerilog simulator and lint system
308308
cosmocc build-once run-anywhere
309309
hdk Harmony SDK
310+
ti-c6000 TI-CGT C6000 compiler
310311
```
311312

312313
## 支持语言

xmake/modules/core/project/depend.lua

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import("private.tools.cl.parse_deps_json", {alias = "parse_deps_cl_json"})
2626
import("private.tools.rc.parse_deps", {alias = "parse_deps_rc"})
2727
import("private.tools.gcc.parse_deps", {alias = "parse_deps_gcc"})
2828
import("private.tools.armcc.parse_deps", {alias = "parse_deps_armcc"})
29+
import("private.tools.cl6x.parse_deps", {alias = "parse_deps_cl6x"})
2930

3031
-- load depfiles
3132
function _load_depfiles(parser, dependinfo, depfiles, opt)
@@ -62,6 +63,9 @@ function load(dependfile, opt)
6263
elseif dependinfo.depfiles_armcc then
6364
_load_depfiles(parse_deps_armcc, dependinfo, dependinfo.depfiles_armcc, opt)
6465
dependinfo.depfiles_armcc = nil
66+
elseif dependinfo.depfiles_cl6x then
67+
_load_depfiles(parse_deps_cl6x, dependinfo, dependinfo.depfiles_cl6x, opt)
68+
dependinfo.depfiles_cl6x = nil
6569
end
6670
return dependinfo
6771
end

xmake/modules/core/tools/ar6x.lua

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--!A cross-platform build utility based on Lua
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
--
15+
-- Copyright (C) 2015-present, TBOOX Open Source Group.
16+
--
17+
-- @author ruki
18+
-- @file ar6x.lua
19+
--
20+
21+
inherit("ar")
22+
23+
-- init it
24+
function init(self)
25+
self:set("arflags", "-r")
26+
end
27+

xmake/modules/core/tools/cl6x.lua

+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
--!A cross-platform build utility based on Lua
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
--
15+
-- Copyright (C) 2015-present, TBOOX Open Source Group.
16+
--
17+
-- @author ruki
18+
-- @file cl6x.lua
19+
--
20+
21+
-- imports
22+
import("core.base.option")
23+
import("core.base.global")
24+
import("core.project.policy")
25+
import("core.language.language")
26+
import("utils.progress")
27+
28+
-- init it
29+
function init(self)
30+
end
31+
32+
-- make the symbol flag
33+
function nf_symbol(self, level)
34+
-- only for source kind
35+
local kind = self:kind()
36+
if language.sourcekinds()[kind] then
37+
local maps = _g.symbol_maps
38+
if not maps then
39+
maps =
40+
{
41+
debug = "-g"
42+
}
43+
_g.symbol_maps = maps
44+
end
45+
return maps[level .. '_' .. kind] or maps[level]
46+
end
47+
end
48+
49+
-- make the optimize flag
50+
function nf_optimize(self, level)
51+
local maps =
52+
{
53+
none = "-O0"
54+
, fast = "-O1"
55+
, faster = "-O2"
56+
, fastest = "-O3"
57+
, smallest = "-m3"
58+
, aggressive = "-O3"
59+
}
60+
return maps[level]
61+
end
62+
63+
-- make the define flag
64+
function nf_define(self, macro)
65+
return "-D" .. macro
66+
end
67+
68+
-- make the undefine flag
69+
function nf_undefine(self, macro)
70+
return "-U" .. macro
71+
end
72+
73+
-- make the includedir flag
74+
function nf_includedir(self, dir)
75+
return {"-I" .. dir}
76+
end
77+
78+
-- make the sysincludedir flag
79+
function nf_sysincludedir(self, dir)
80+
return nf_includedir(self, dir)
81+
end
82+
83+
-- make the link flag
84+
function nf_link(self, lib)
85+
if not lib:endswith(".a") and not lib:endswith(".so") then
86+
lib = "lib" .. lib .. ".a"
87+
end
88+
return "-l" .. lib
89+
end
90+
91+
-- make the syslink flag
92+
function nf_syslink(self, lib)
93+
return nf_link(self, lib)
94+
end
95+
96+
-- make the linkdir flag
97+
function nf_linkdir(self, dir)
98+
return {"-i" .. path.translate(dir)}
99+
end
100+
101+
-- make the rpathdir flag
102+
function nf_rpathdir(self, dir, opt)
103+
opt = opt or {}
104+
local extra = opt.extra
105+
if extra and extra.installonly then
106+
return
107+
end
108+
dir = path.translate(dir)
109+
return {"-rpath=" .. dir}
110+
end
111+
112+
-- make the link arguments list
113+
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
114+
local argv = table.join("-z", "--output_file=" .. targetfile, objectfiles, flags)
115+
return self:program(), argv
116+
end
117+
118+
-- link the target file
119+
--
120+
-- maybe we need to use os.vrunv() to show link output when enable verbose information
121+
-- @see https://github.com/xmake-io/xmake/discussions/2916
122+
--
123+
function link(self, objectfiles, targetkind, targetfile, flags, opt)
124+
opt = opt or {}
125+
os.mkdir(path.directory(targetfile))
126+
local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags)
127+
if option.get("verbose") then
128+
os.execv(program, argv, {envs = self:runenvs(), shell = opt.shell})
129+
else
130+
os.vrunv(program, argv, {envs = self:runenvs(), shell = opt.shell})
131+
end
132+
end
133+
134+
-- make the compile arguments list
135+
function compargv(self, sourcefile, objectfile, flags)
136+
return self:program(), table.join("-c", "--preproc_with_compile", flags, "--output_file=" .. objectfile, sourcefile)
137+
end
138+
139+
-- compile the source file
140+
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
141+
os.mkdir(path.directory(objectfile))
142+
local depfile = dependinfo and os.tmpfile() or nil
143+
try
144+
{
145+
function ()
146+
local compflags = flags
147+
if depfile then
148+
compflags = table.join(compflags, "-ppd=" .. depfile)
149+
end
150+
local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, compflags))
151+
return (outdata or "") .. (errdata or "")
152+
end,
153+
catch
154+
{
155+
function (errors)
156+
157+
-- try removing the old object file for forcing to rebuild this source file
158+
os.tryrm(objectfile)
159+
160+
-- find the start line of error
161+
local lines = tostring(errors):split("\n")
162+
local start = 0
163+
for index, line in ipairs(lines) do
164+
if line:find("error:", 1, true) or line:find("错误:", 1, true) then
165+
start = index
166+
break
167+
end
168+
end
169+
170+
-- get 16 lines of errors
171+
if start > 0 or not option.get("verbose") then
172+
if start == 0 then start = 1 end
173+
errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n")
174+
end
175+
176+
-- raise compiling errors
177+
raise(errors)
178+
end
179+
},
180+
finally
181+
{
182+
function (ok, warnings)
183+
184+
-- print some warnings
185+
if warnings and #warnings > 0 and policy.build_warnings(opt) then
186+
if progress.showing_without_scroll() then
187+
print("")
188+
end
189+
cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n'))
190+
end
191+
192+
-- generate the dependent includes
193+
if depfile and os.isfile(depfile) then
194+
if dependinfo then
195+
dependinfo.depfiles_cl6x = io.readfile(depfile, {continuation = "\\"})
196+
end
197+
198+
-- remove the temporary dependent file
199+
os.tryrm(depfile)
200+
end
201+
end
202+
}
203+
}
204+
end
205+
206+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
--!A cross-platform build utility based on Lua
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
--
15+
-- Copyright (C) 2015-present, TBOOX Open Source Group.
16+
--
17+
-- @author ruki
18+
-- @file has_flags.lua
19+
--
20+
21+
-- imports
22+
import("core.cache.detectcache")
23+
import("core.language.language")
24+
25+
-- is linker?
26+
function _islinker(flags, opt)
27+
local toolkind = opt.toolkind or ""
28+
return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh")
29+
end
30+
31+
-- try running
32+
function _try_running(program, argv, opt)
33+
local errors = nil
34+
return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors
35+
end
36+
37+
-- attempt to check it from known flags
38+
function _check_from_knownargs(flags, opt, islinker)
39+
local flag = flags[1]
40+
if not islinker then
41+
if flag:startswith("-D") or
42+
flag:startswith("-U") or
43+
flag:startswith("-I") then
44+
return true
45+
end
46+
end
47+
end
48+
49+
-- attempt to check it from the argument list
50+
function _check_from_arglist(flags, opt, islinker)
51+
local key = "detect.tools.cl6x." .. (islinker and "has_ldflags" or "has_cflags")
52+
local flagskey = opt.program .. "_" .. (opt.programver or "")
53+
local allflags = detectcache:get2(key, flagskey)
54+
if not allflags then
55+
allflags = {}
56+
local arglist = try {function () return os.iorunv(opt.program, {"--help"}, {envs = opt.envs}) end}
57+
if arglist then
58+
for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do
59+
allflags[arg] = true
60+
end
61+
end
62+
detectcache:set2(key, flagskey, allflags)
63+
detectcache:save()
64+
end
65+
local flag = flags[1]
66+
return allflags[flag]
67+
end
68+
69+
-- get extension
70+
function _get_extension(opt)
71+
-- @note we need to detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
72+
return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c")
73+
end
74+
75+
-- try running to check flags
76+
function _check_try_running(flags, opt, islinker)
77+
78+
-- make an stub source file
79+
local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}\n"
80+
local sourcefile = os.tmpfile("cl6x_has_flags:" .. snippet) .. _get_extension(opt)
81+
if not os.isfile(sourcefile) then
82+
io.writefile(sourcefile, snippet)
83+
end
84+
85+
-- check flags for linker
86+
local tmpfile = os.tmpfile()
87+
if islinker then
88+
return _try_running(opt.program, table.join(flags, "-z", "--output_file=" .. tmpfile, sourcefile), opt)
89+
end
90+
91+
-- check flags for compiler
92+
-- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage
93+
return _try_running(opt.program, table.join(flags, "-c", "--output_file=" .. tmpfile, sourcefile), opt)
94+
end
95+
96+
-- has_flags(flags)?
97+
--
98+
-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"}
99+
--
100+
-- @return true or false
101+
--
102+
function main(flags, opt)
103+
104+
-- is linker?
105+
opt = opt or {}
106+
local islinker = _islinker(flags, opt)
107+
108+
-- attempt to check it from the argument list
109+
if not opt.tryrun then
110+
if _check_from_arglist(flags, opt, islinker) then
111+
return true
112+
end
113+
if _check_from_knownargs(flags, opt, islinker) then
114+
return true
115+
end
116+
end
117+
118+
-- try running to check it
119+
return _check_try_running(flags, opt, islinker)
120+
end
121+

0 commit comments

Comments
 (0)