Skip to content

Commit

Permalink
enables binary+execution for ADA (#1971)
Browse files Browse the repository at this point in the history
* enables binary+execution for ADA

* generic bandaid for missing executables

* -eS commands are not errors

* support error annotations

* restore original default but add exec example

* re-enable rpath

* add tools
  • Loading branch information
partouf committed May 20, 2020
1 parent 60ee4fb commit 5bc4e3b
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 45 deletions.
22 changes: 20 additions & 2 deletions etc/config/ada.amazon.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ defaultCompiler=gnat82
demangler=/opt/compiler-explorer/gcc-9.1.0/bin/c++filt
objdumper=/opt/compiler-explorer/gcc-9.1.0/bin/objdump
versionFlag=--version
supportsBinary=false
supportsExecute=false
supportsBinary=true
supportsExecute=true
intelAsm=-masm=intel
compilerType=ada

Expand All @@ -27,3 +27,21 @@ compiler.gnatsnapshot.semver=(trunk)
#################################
# Installed libs (See c++.amazon.properties for a scheme of libs group)
libs=

#################################
# Tools
tools=readelf:ldd

tools.readelf.name=readelf (trunk)
tools.readelf.exe=/opt/compiler-explorer/gcc-snapshot/bin/readelf
tools.readelf.type=postcompilation
tools.readelf.class=readelf-tool
tools.readelf.exclude=djggp
tools.readelf.stdinHint=disabled

tools.ldd.name=ldd
tools.ldd.exe=/usr/bin/ldd
tools.ldd.type=postcompilation
tools.ldd.class=readelf-tool
tools.ldd.exclude=djggp
tools.ldd.stdinHint=disabled
30 changes: 30 additions & 0 deletions examples/ada/Square_Executable.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
with Ada.Command_Line;
with Ada.Text_IO;

function Example return Integer is

function Square(num : Integer) return Integer is
begin
return num**2;
end Square;

function ReadCmdArgumentOrDefault(default: Integer) return Integer is
begin
if Ada.Command_Line.Argument_Count > 0 then
return Integer'Value(Ada.Command_Line.Argument(1));
else
return Default;
end if;
end ReadCmdArgumentOrDefault;

NumberToSquare: Integer;
Answer: Integer;
begin
NumberToSquare := ReadCmdArgumentOrDefault(4);
Ada.Text_IO.Put_Line("Number to square: " & NumberToSquare'Image);

Answer := Square(NumberToSquare);
Ada.Text_IO.Put_Line("Square answer: " & Answer'Image);

return Answer;
end Example;
34 changes: 17 additions & 17 deletions examples/ada/default.adb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
-- This pragma will remove the warning produced by the default
-- CE filename and the procedure name differing,
-- see : https://gcc.gnu.org/onlinedocs/gcc-8.2.0/gnat_rm/Pragma-Source_005fFile_005fName.html#Pragma-Source_005fFile_005fName
pragma Source_File_Name (Square, Body_File_Name => "example.adb");

-- Type your code here, or load an example.
function Square(num : Integer) return Integer is
begin
return num**2;
end Square;

-- Ada 2012 also provides Expression Functions
-- (http://www.ada-auth.org/standards/12rm/html/RM-6-8.html)
-- as a short hand for functions whose body consists of a
-- single return statement. However they cannot be used as a
-- complication unit.
-- function Square(num : Integer) return Integer is (num**2);
-- This pragma will remove the warning produced by the default
-- CE filename and the procedure name differing,
-- see : https://gcc.gnu.org/onlinedocs/gcc-8.2.0/gnat_rm/Pragma-Source_005fFile_005fName.html#Pragma-Source_005fFile_005fName
pragma Source_File_Name (Square, Body_File_Name => "example.adb");

-- Type your code here, or load an example.
function Square(num : Integer) return Integer is
begin
return num**2;
end Square;

-- Ada 2012 also provides Expression Functions
-- (http://www.ada-auth.org/standards/12rm/html/RM-6-8.html)
-- as a short hand for functions whose body consists of a
-- single return statement. However they cannot be used as a
-- complication unit.
-- function Square(num : Integer) return Integer is (num**2);
17 changes: 16 additions & 1 deletion lib/base-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,28 @@ class BaseCompiler {
const buildResult = await this.getOrBuildExecutable(key);
if (buildResult.code !== 0) {
return {
code: 0,
code: -1,
didExecute: false,
buildResult,
stderr: [],
stdout: []
};
} else {
if (!fs.existsSync(buildResult.executableFilename)) {
const verboseResult = {
code: -1,
didExecute: false,
buildResult,
stderr: [],
stdout: []
};

verboseResult.buildResult.stderr.push({text:"Compiler did not produce an executable"});

return verboseResult;
}
}

executeParameters.ldPath = this.getSharedLibraryPathsAsLdLibraryPaths(key.libraries);
const result = await this.runExecutable(buildResult.executableFilename, executeParameters);
result.didExecute = true;
Expand Down
67 changes: 42 additions & 25 deletions lib/compilers/ada.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,45 @@ class AdaCompiler extends BaseCompiler {
this.compiler.supportsIntel = true;
}

getExecutableFilename(dirPath) {
return path.join(dirPath, "example");
}

getOutputFilename(dirPath) {
return path.join(dirPath, "example.o");
}

optionsForFilter(filters, outputFilename) {
let options = ['compile',
'-g', // enable debugging
'-c', // Compile only
'-S', // Generate ASM
'-fdiagnostics-color=always',
'-fverbose-asm', // Geneate verbose ASM showing variables
'-cargs', // Compiler Switches for gcc.
'-o', // Set the output executable name
outputFilename
];
if (this.compiler.intelAsm && filters.intel && !filters.binary) {
options = options.concat(this.compiler.intelAsm.split(" "));
let options = [];

if (!filters.binary) {
options.push(
'compile',
'-g', // enable debugging
'-S', // Generate ASM
'-fdiagnostics-color=always',
'-fverbose-asm', // Geneate verbose ASM showing variables
'-c', // Compile only
'-eS', // commands are not errors
'-cargs', // Compiler Switches for gcc.
'-o',
outputFilename,
);

if (this.compiler.intelAsm && filters.intel) {
options = options.concat(this.compiler.intelAsm.split(" "));
}
} else {
options.push(
'make',
'-eS',
'-g',
'example',
'-cargs'
);
}
return options;
}

// I have left the overloaded preProcess method in case there is a
// need to any actual pre-processing of the input.
// As Ada expects the outermost function name to match the source file name.
// The initial solution was to wrap any input in a dummy example procedure,
// this however restricts users from including standard library packages, as
// Ada mandates that 'with' clauses are placed in the context clause,
// which in the case of a single subprogram is outside of its declaration and body.
preProcess(source) {
return source;
return options;
}

async runCompiler(compiler, options, inputFilename, execOptions) {
Expand All @@ -67,6 +80,7 @@ class AdaCompiler extends BaseCompiler {
}
// Set the working directory to be the temp directory that has been created
execOptions.customCwd = path.dirname(inputFilename);

// As the file name is always appended to the end of the options array we need to
// find where the '-cargs' flag is in options. This is to allow us to set the
// output as 'output.s' and not end up with 'example.s'. If the output is left
Expand All @@ -78,10 +92,13 @@ class AdaCompiler extends BaseCompiler {
break;
}
}

const result = await this.exec(compiler, options, execOptions);
result.inputFilename = inputFilename;
result.stdout = utils.parseOutput(result.stdout, inputFilename);
result.stderr = utils.parseOutput(result.stderr, inputFilename);

const baseFilename = path.basename(inputFileName);
result.stdout = utils.parseOutput(result.stdout, baseFilename, execOptions.customCwd);
result.stderr = utils.parseOutput(result.stderr, baseFilename, execOptions.customCwd);
return result;
}
}
Expand Down

0 comments on commit 5bc4e3b

Please sign in to comment.