From patchwork Sun Jun 21 18:02:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 7279 X-Patchwork-Delegate: vapier@gentoo.org Received: (qmail 71260 invoked by alias); 21 Jun 2015 18:02:15 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 71249 invoked by uid 89); 21 Jun 2015 18:02:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: smtp.gentoo.org Received: from smtp.gentoo.org (HELO smtp.gentoo.org) (140.211.166.183) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sun, 21 Jun 2015 18:02:13 +0000 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id A7AF4340BC0 for ; Sun, 21 Jun 2015 18:02:11 +0000 (UTC) From: Mike Frysinger To: gdb-patches@sourceware.org Subject: [PATCH/RFC] sim: common: add PRI printf defines Date: Sun, 21 Jun 2015 14:02:09 -0400 Message-Id: <1434909729-6766-1-git-send-email-vapier@gentoo.org> X-IsSubscribed: yes Keeping track of the right printf formats for the various types can be a pretty big hassle, especially in common code which has to support a variety of bitsizes. Take a page from the existing standards and add a set of PRI macros which hide the details in a common header. --- sim/common/ChangeLog | 8 ++++++++ sim/common/sim-types.h | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 722ad98..db67a1d 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,5 +1,13 @@ 2015-06-21 Mike Frysinger + * sim-types.h (_SIM_PRI_TB, __SIM_PRI_TB): New helper macros for + expanding target bitsizes into standard PRI formats. + (PRI_TW, PRIiTW, PRIxTW): New PRI target word defines. + (PRI_TA, PRIiTA, PRIxTA): New PRI target address defines. + (PRI_TF, PRIiTF, PRIxTF): New PRI target floating point defines. + +2015-06-21 Mike Frysinger + * sim-model.c (sim_model_init): Assert model is not NULL. 2015-06-21 Mike Frysinger diff --git a/sim/common/sim-types.h b/sim/common/sim-types.h index 862f4e0..a64f644 100644 --- a/sim/common/sim-types.h +++ b/sim/common/sim-types.h @@ -87,6 +87,11 @@ typedef unsigned64 unsigned_8; typedef unsigned128 unsigned_16; +/* Macros for printf. */ +#define _SIM_PRI_TB(t, b) __SIM_PRI_TB(t, b) +#define __SIM_PRI_TB(t, b) PRI##t##b + + /* for general work, the following are defined */ /* unsigned: >= 32 bits */ /* signed: >= 32 bits */ @@ -107,6 +112,10 @@ typedef unsigned16 unsigned_word; typedef signed16 signed_word; #endif +#define PRI_TW(t) _SIM_PRI_TB(t, WITH_TARGET_WORD_BITSIZE) +#define PRIiTW PRI_TW(i) +#define PRIxTW PRI_TW(x) + /* Other instructions */ #if (WITH_TARGET_ADDRESS_BITSIZE == 64) @@ -123,6 +132,10 @@ typedef signed16 signed_address; #endif typedef unsigned_address address_word; +#define PRI_TA(t) _SIM_PRI_TB(t, WITH_TARGET_ADDRESS_BITSIZE) +#define PRIiTA PRI_TA(i) +#define PRIxTA PRI_TA(x) + /* IEEE 1275 cell size */ #if (WITH_TARGET_CELL_BITSIZE == 64) @@ -135,6 +148,10 @@ typedef signed32 signed_cell; #endif typedef signed_cell cell_word; /* cells are normally signed */ +#define PRI_TC(t) _SIM_PRI_TB(t, WITH_TARGET_CELL_BITSIZE) +#define PRIiTC PRI_TC(i) +#define PRIxTC PRI_TC(x) + /* Floating point registers */ #if (WITH_TARGET_FLOATING_POINT_BITSIZE == 64) @@ -144,4 +161,8 @@ typedef unsigned64 fp_word; typedef unsigned32 fp_word; #endif +#define PRI_TF(t) _SIM_PRI_TB(t, WITH_TARGET_FLOATING_POINT_BITSIZE) +#define PRIiTF PRI_TF(i) +#define PRIxTF PRI_TF(x) + #endif