Skip to content

Commit c43f413

Browse files
committed
[ms] [llvm-ml] Add support for INCLUDE environment variable
Also adds support for the ML.exe command-line flag /X, which ignores the INCLUDE environment variable.
1 parent 222cce3 commit c43f413

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: INCLUDE=%S llvm-ml -filetype=s %s /Fo - | FileCheck %s
2+
3+
include included.inc
4+
5+
.code
6+
7+
t1:
8+
mov eax, Const
9+
10+
; CHECK-LABEL: t1:
11+
; CHECK-NEXT: mov eax, 8
12+
13+
t2:
14+
push_pop ebx
15+
16+
; CHECK-LABEL: t2:
17+
; CHECK-NEXT: push ebx
18+
; CHECK-NEXT: pop ebx
19+
20+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: not llvm-ml -filetype=s %s /Fo - 2>&1 | FileCheck %s --implicit-check-not=error:
2+
; RUN: INCLUDE=%S not llvm-ml -filetype=s %s /X /Fo - 2>&1 | FileCheck %s --implicit-check-not=error:
3+
4+
; CHECK: :[[# @LINE + 1]]:9: error: Could not find include file 'included.inc'
5+
include included.inc
6+
7+
.code
8+
9+
t1:
10+
mov eax, Const
11+
12+
t2:
13+
; CHECK: :[[# @LINE + 1]]:1: error: invalid instruction mnemonic 'push_pop'
14+
push_pop ebx
15+
16+
end

llvm/tools/llvm-ml/Opts.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def assembly_file : MLJoinedOrSeparate<"Ta">,
7373
def error_on_warning : MLFlag<"WX">, Alias<fatal_warnings>;
7474
def parse_only : MLFlag<"Zs">, HelpText<"Run a syntax-check only">,
7575
Alias<filetype>, AliasArgs<["null"]>;
76+
def ignore_include_envvar : MLFlag<"X">,
77+
HelpText<"Ignore the INCLUDE environment variable">;
7678

7779
def tiny_model_support : UnsupportedFlag<"AT">, HelpText<"">;
7880
def alternate_linker : UnsupportedJoined<"Bl">, HelpText<"">;
@@ -105,7 +107,6 @@ def listing_title : UnsupportedSeparate<"St">, HelpText<"">;
105107
def listing_false_conditionals : UnsupportedFlag<"Sx">, HelpText<"">;
106108
def extra_warnings : UnsupportedFlag<"w">, HelpText<"">;
107109
def warning_level : UnsupportedJoined<"W">, HelpText<"">;
108-
def ignore_include_envvar : UnsupportedFlag<"X">, HelpText<"">;
109110
def line_number_info : UnsupportedFlag<"Zd">, HelpText<"">;
110111
def export_all_symbols : UnsupportedFlag<"Zf">, HelpText<"">;
111112
def codeview_info : UnsupportedFlag<"Zi">, HelpText<"">;

llvm/tools/llvm-ml/llvm-ml.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "llvm/Support/InitLLVM.h"
3737
#include "llvm/Support/MemoryBuffer.h"
3838
#include "llvm/Support/Path.h"
39+
#include "llvm/Support/Process.h"
3940
#include "llvm/Support/SourceMgr.h"
4041
#include "llvm/Support/TargetRegistry.h"
4142
#include "llvm/Support/TargetSelect.h"
@@ -263,8 +264,21 @@ int main(int Argc, char **Argv) {
263264
SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc());
264265

265266
// Record the location of the include directories so that the lexer can find
266-
// it later.
267-
SrcMgr.setIncludeDirs(InputArgs.getAllArgValues(OPT_include_path));
267+
// included files later.
268+
std::vector<std::string> IncludeDirs =
269+
InputArgs.getAllArgValues(OPT_include_path);
270+
if (!InputArgs.hasArg(OPT_ignore_include_envvar)) {
271+
if (llvm::Optional<std::string> cl_include_dir =
272+
llvm::sys::Process::GetEnv("INCLUDE")) {
273+
SmallVector<StringRef, 8> Dirs;
274+
StringRef(*cl_include_dir)
275+
.split(Dirs, ";", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
276+
IncludeDirs.reserve(IncludeDirs.size() + Dirs.size());
277+
for (StringRef Dir : Dirs)
278+
IncludeDirs.push_back(Dir.str());
279+
}
280+
}
281+
SrcMgr.setIncludeDirs(IncludeDirs);
268282

269283
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
270284
assert(MRI && "Unable to create target register info!");

0 commit comments

Comments
 (0)