summaryrefslogtreecommitdiffhomepage
path: root/64x0/cc2/source/cppfront.cpp
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-09 11:59:12 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-09 12:01:26 +0100
commita8a55bc93e06cd8f75f7d397c013f7a312ea29a4 (patch)
tree39969558bed8fcff1c2014fda0d3674b794f6970 /64x0/cc2/source/cppfront.cpp
parentb16ae0960b396c8c20e4711eabfe4b826a039d7e (diff)
64asm/64ld: MP-UX specialized 64x0 assembler.
Refer to 64x0 the X64000 specific toolchain. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to '64x0/cc2/source/cppfront.cpp')
-rw-r--r--64x0/cc2/source/cppfront.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/64x0/cc2/source/cppfront.cpp b/64x0/cc2/source/cppfront.cpp
new file mode 100644
index 0000000..989a6ad
--- /dev/null
+++ b/64x0/cc2/source/cppfront.cpp
@@ -0,0 +1,115 @@
+
+// Copyright (c) Herb Sutter
+// SPDX-License-Identifier: CC-BY-NC-ND-4.0
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+//===========================================================================
+// main - driver
+//===========================================================================
+
+#include "to_cpp1.h"
+
+static auto flag_debug_output = false;
+static cpp2::cmdline_processor::register_flag cmd_debug(
+ 9,
+ "debug",
+ "Emit compiler debug output",
+ []{ flag_debug_output = true; }
+);
+
+auto main(
+ int argc,
+ char* argv[]
+)
+ -> int
+{
+ using namespace cpp2;
+
+ cmdline.set_args(argc, argv);
+ cmdline.process_flags();
+
+ if (cmdline.help_was_requested()) {
+ return EXIT_SUCCESS;
+ }
+
+ if (cmdline.arguments().empty()) {
+ std::cerr << "cppfront: error: no input files (try -help)\n";
+ return EXIT_FAILURE;
+ }
+
+ // For each Cpp2 source file
+ int exit_status = EXIT_SUCCESS;
+ for (auto const& arg : cmdline.arguments())
+ {
+ auto& out = flag_cpp1_filename != "stdout" ? std::cout : std::cerr;
+
+ out << arg.text << "...";
+
+ // Load + lex + parse + sema
+ cppfront c(arg.text);
+
+ // Generate Cpp1 (this may catch additional late errors)
+ auto count = c.lower_to_cpp1();
+
+ // If there were no errors, say so and generate Cpp1
+ if (c.had_no_errors())
+ {
+ if (!c.has_cpp1()) {
+ out << " ok (all Cpp2, passes safety checks)\n";
+ }
+ else if (c.has_cpp2()) {
+ out << " ok (mixed Cpp1/Cpp2, Cpp2 code passes safety checks)\n";
+ }
+ else {
+ out << " ok (all Cpp1)\n";
+ }
+
+ if (flag_verbose) {
+ out << " Cpp1: " << count.cpp1_lines << " line" << (count.cpp1_lines != 1 ? "s" : "");
+ out << "\n Cpp2: " << count.cpp2_lines << " line" << (count.cpp2_lines != 1 ? "s" : "");
+ auto total = count.cpp1_lines + count.cpp2_lines;
+ if (total > 0) {
+ out << " (";
+ if (count.cpp2_lines / count.cpp1_lines > 25) {
+ out << std::setprecision(3)
+ << 100.0 * count.cpp2_lines / total;
+ }
+ else {
+ out << 100 * count.cpp2_lines / total;
+ }
+ out << "%)";
+ }
+ }
+
+ out << "\n";
+ }
+ // Otherwise, print the errors
+ else
+ {
+ std::cerr << "\n";
+ c.print_errors();
+ std::cerr << "\n";
+ exit_status = EXIT_FAILURE;
+ }
+
+ // And, if requested, the debug information
+ if (flag_debug_output) {
+ c.debug_print();
+ }
+ }
+
+ if (flag_internal_debug) {
+ stackinstr::print_deepest();
+ stackinstr::print_largest();
+ }
+
+ return exit_status;
+}