Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Jun 2025 19:33:59 GMT
From:      Jose Luis Duran <jlduran@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 4dfbc03d6492 - main - dtc: Sync with upstream commit 23387dd
Message-ID:  <202506161933.55GJXxga047055@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by jlduran:

URL: https://cgit.FreeBSD.org/src/commit/?id=4dfbc03d6492d9fccb781700cc17d58111dff456

commit 4dfbc03d6492d9fccb781700cc17d58111dff456
Author:     Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2025-06-16 19:31:43 +0000
Commit:     Jose Luis Duran <jlduran@FreeBSD.org>
CommitDate: 2025-06-16 19:31:57 +0000

    dtc: Sync with upstream commit 23387dd
    
    Add the ability to parse char literals needed to compile DTBs currently
    in base.
    
    Reviewed by:    theraven, emaste
    Approved by:    emaste (mentor)
    Differential Revision:  https://reviews.freebsd.org/D42438
---
 usr.bin/dtc/input_buffer.cc | 53 +++++++++++++++++++++++++++++++++++++++++++++
 usr.bin/dtc/input_buffer.hh | 22 +++++++++++++++++++
 2 files changed, 75 insertions(+)

diff --git a/usr.bin/dtc/input_buffer.cc b/usr.bin/dtc/input_buffer.cc
index 278dd42b5ac6..20f747f29cd8 100644
--- a/usr.bin/dtc/input_buffer.cc
+++ b/usr.bin/dtc/input_buffer.cc
@@ -337,6 +337,47 @@ input_buffer::consume(const char *str)
 	return false;
 }
 
+bool
+input_buffer::consume_char_literal(unsigned long long &outInt)
+{
+	outInt = (unsigned char)((*this)[0]);
+	cursor++;
+
+	if(outInt != '\\')
+	{
+		return true;
+	}
+	else if(cursor >= size)
+	{
+		return false;
+	}
+
+	outInt = (unsigned char)((*this)[0]);
+	cursor++;
+
+	switch (outInt) {
+		default:
+			return false;
+		case 'n':
+			outInt = (unsigned char)'\n';
+			break;
+		case 'r':
+			outInt = (unsigned char)'\r';
+			break;
+		case 't':
+			outInt = (unsigned char)'\t';
+			break;
+		case '0':
+			outInt = 0;
+			break;
+		case '\'':
+		case '\\':
+			break;
+	}
+
+	return true;
+}
+
 bool
 input_buffer::consume_integer(unsigned long long &outInt)
 {
@@ -874,6 +915,18 @@ expression_ptr text_input_buffer::parse_expression(bool stopAtParen)
 	source_location l = location();
 	switch (*(*this))
 	{
+		case '\'':
+			consume('\'');
+			if(!consume_char_literal(leftVal))
+			{
+				return nullptr;
+			}
+			if (!consume('\''))
+			{
+				return nullptr;
+			}
+			lhs.reset(new terminal_expr(l, leftVal));
+			break;
 		case '0'...'9':
 			if (!consume_integer(leftVal))
 			{
diff --git a/usr.bin/dtc/input_buffer.hh b/usr.bin/dtc/input_buffer.hh
index d6b033952bad..395c7b044df3 100644
--- a/usr.bin/dtc/input_buffer.hh
+++ b/usr.bin/dtc/input_buffer.hh
@@ -193,6 +193,13 @@ class input_buffer
 	 * current point in the input.
 	 */
 	bool consume(const char *str);
+	/**
+	 * Reads unsigned from char literal.  Returns true and advances
+	 * the cursor to next char.
+	 *
+	 * The parsed value is returned via the argument.
+	 */
+	bool consume_char_literal(unsigned long long &outInt);
 	/**
 	 * Reads an integer in base 8, 10, or 16.  Returns true and advances
 	 * the cursor to the end of the integer if the cursor points to an
@@ -412,6 +419,21 @@ class text_input_buffer
 		}
 		return input_stack.top()->consume(str);
 	}
+	/**
+	 * Converts next char into unsigned
+	 *
+	 * The parsed value is returned via the argument.
+	 *
+	 * This method does not scan between files.
+	 */
+	bool consume_char_literal(unsigned long long &outInt)
+	{
+		if (input_stack.empty())
+		{
+			return false;
+		}
+		return input_stack.top()->consume_char_literal(outInt);
+	}
 	/**
 	 * Reads an integer in base 8, 10, or 16.  Returns true and advances
 	 * the cursor to the end of the integer if the cursor points to an



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202506161933.55GJXxga047055>