Skip to content

Commit

Permalink
Update Java code to use new plugin-based clang-16 AST dumper on Linux…
Browse files Browse the repository at this point in the history
… platforms
  • Loading branch information
lm-sousa committed Jul 8, 2024
1 parent a530663 commit d36a93d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static WebResourceProvider create(String resourceUrl) {
WebResourceProvider WIN_DLL1 = create("windows/libwinpthread-1.dll");
WebResourceProvider WIN_DLL2 = create("windows/zlib1.dll");

WebResourceProvider LINUX_EXE = create("linux_ubuntu_18/clang_ast", "v12.0.7");
WebResourceProvider LINUX_EXE = create("linux_ubuntu_18/clang-plugin.so", "16");

// Disabled while we do not have an updated Odroid
WebResourceProvider LINUX_ARMV7_EXE = create("linux_ubuntu_14_armv7/clang_ast", "v4.2.19");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import pt.up.fe.specs.clang.ClangAstKeys;
import pt.up.fe.specs.clang.ClangResources;
import pt.up.fe.specs.clang.LibcMode;
import pt.up.fe.specs.clang.dumper.ClangAstData;
import pt.up.fe.specs.clang.dumper.ClangAstDumper;
import pt.up.fe.specs.clang.dumper.ClangAstParser;
Expand Down Expand Up @@ -118,6 +119,10 @@ public App parse(List<File> inputSources, List<String> compilerOptions, ClavaCon
// Prepare resources before execution
// ClangResources clangResources = new ClangResources(get(SHOW_CLANG_DUMP));
ClangResources clangResources = new ClangResources(this);
if (SpecsSystem.isLinux()) {
set(ClangAstKeys.LIBC_CXX_MODE, LibcMode.SYSTEM);
ClavaLog.debug(() -> "In Linux, ClangAstDumper is a plugin. LIBC_CXX_MODE is reset to SYSTEM.");
}
var clangFiles = clangResources.getClangFiles(version, get(ClangAstKeys.LIBC_CXX_MODE));
// File clangExecutable = clangResources.prepareResources(version);
// List<String> builtinIncludes = clangResources.prepareIncludes(clangExecutable,
Expand Down
67 changes: 47 additions & 20 deletions ClangAstParser/src/pt/up/fe/specs/clang/dumper/ClangAstDumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,37 @@ private ClangAstData parsePrivate(File sourceFile, String id, Standard standard,
LocalOptionsKeys.getProvider().getStoreDefinition());

List<String> arguments = new ArrayList<>();
arguments.add(clangExecutable.getAbsolutePath());
if (SpecsPlatforms.isLinux()) {
arguments.add("clang-16");
arguments.add("-c");

arguments.add("-Xclang");
arguments.add("-load");
arguments.add("-Xclang");
arguments.add(clangExecutable.getAbsolutePath());
arguments.add("-Xclang");
arguments.add("-plugin");
arguments.add("-Xclang");
arguments.add("DumpAst");
arguments.add("-Xclang");
arguments.add("-plugin-arg-DumpAst");
arguments.add("-Xclang");
arguments.add("-file-id=" + id);
arguments.add("-Xclang");
arguments.add("-plugin-arg-DumpAst");
arguments.add("-Xclang");
arguments.add("-system-threshold=" + systemIncludesThreshold);
} else {
arguments.add(clangExecutable.getAbsolutePath());

arguments.add(sourceFile.getAbsolutePath());
arguments.add(sourceFile.getAbsolutePath());

arguments.add("-id=" + id);
arguments.add("-id=" + id);

arguments.add("-system-header-threshold=" + systemIncludesThreshold);
arguments.add("-system-header-threshold=" + systemIncludesThreshold);

arguments.add("--");
arguments.add("--");
}

var extension = SpecsIo.getExtension(sourceFile);
boolean isOpenCL = extension.equals("cl");
Expand Down Expand Up @@ -223,23 +245,28 @@ else if (SourceType.isHeader(sourceFile)) {
arguments.add(standard.isCxx() ? "c++" : "c");
}

if (SpecsPlatforms.isLinux()) {
arguments.add(sourceFile.getAbsolutePath());
} else {

List<String> systemIncludes = new ArrayList<>();

// Add includes bundled with program
// (only on Windows, it is expected that a Linux system has its own headers for libc/libc++)
// if (Platforms.isWindows()) {
// systemIncludes.addAll(clangAstParser.prepareIncludes(clangExecutable, usePlatformLibc));
systemIncludes.addAll(builtinIncludes);
// }

// Add custom includes
systemIncludes.addAll(localData.get(LocalOptionsKeys.SYSTEM_INCLUDES).getStringList());

// Add local system includes
// for (String systemInclude : localData.get(LocalOptionsKeys.SYSTEM_INCLUDES)) {
for (String systemInclude : systemIncludes) {
arguments.add("-isystem");
arguments.add(systemInclude);
// Add includes bundled with program
// (only on Windows, it is expected that a Linux system has its own headers for libc/libc++)
// if (Platforms.isWindows()) {
// systemIncludes.addAll(clangAstParser.prepareIncludes(clangExecutable, usePlatformLibc));
systemIncludes.addAll(builtinIncludes);
// }

// Add custom includes
systemIncludes.addAll(localData.get(LocalOptionsKeys.SYSTEM_INCLUDES).getStringList());

// Add local system includes
// for (String systemInclude : localData.get(LocalOptionsKeys.SYSTEM_INCLUDES)) {
for (String systemInclude : systemIncludes) {
arguments.add("-isystem");
arguments.add(systemInclude);
}
}

arguments.addAll(ArgumentsParser.newCommandLine().parse(config.get(ClavaOptions.FLAGS)));
Expand Down

0 comments on commit d36a93d

Please sign in to comment.