From 653485ece625b23e90c2e1711b3a124610f5ff95 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Tue, 18 Feb 2025 21:14:36 -0800 Subject: [PATCH] rewriter: reformat `CAbi.h`, `DetermineAbi.{h,cpp}` --- tools/rewriter/CAbi.h | 56 +++++++++++++++++++++++++-------- tools/rewriter/DetermineAbi.cpp | 15 ++++++--- tools/rewriter/DetermineAbi.h | 4 +-- 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/tools/rewriter/CAbi.h b/tools/rewriter/CAbi.h index e9ff3342c..a4264aa84 100644 --- a/tools/rewriter/CAbi.h +++ b/tools/rewriter/CAbi.h @@ -1,8 +1,9 @@ #pragma once + #include #include -#include #include +#include class ArgLocation { public: @@ -23,18 +24,20 @@ class ArgLocation { Kind _kind; unsigned _size; unsigned _align; - const char* _reg = nullptr; + const char *_reg = nullptr; size_t _stack_offset = 0; public: static ArgLocation Register(Kind kind, unsigned size) { return ArgLocation(kind, size, size); } - static ArgLocation Stack(int64_t size, int64_t align) { - auto loc = ArgLocation(Kind::Memory, static_cast(size), static_cast(align)); + + static ArgLocation Stack(int64_t size, int64_t align) { + auto loc = ArgLocation(Kind::Memory, static_cast(size), static_cast(align)); loc._onStack = true; return loc; } + static ArgLocation Indirect(unsigned size, unsigned align) { auto loc = ArgLocation(Kind::Integral, static_cast(size), static_cast(align)); loc._indirectOnStack = true; @@ -46,35 +49,62 @@ class ArgLocation { _allocated = true; _reg = r; } + void allocate_stack(size_t offset) { assert(!_allocated); _allocated = true; _onStack = true; _stack_offset = offset; } + void set_indirect_on_stack() { assert(!_indirectOnStack); _indirectOnStack = true; } - bool is_allocated() const { return _allocated; } - bool is_stack() const { return _onStack; } - bool is_indirect() const { return _indirectOnStack; } + bool is_allocated() const { + return _allocated; + } + + bool is_stack() const { + return _onStack; + } + + bool is_indirect() const { + return _indirectOnStack; + } + bool is_128bit_float() const { return _reg != nullptr && ((_reg[0] == 'x' && _reg[1] == 'm' && _reg[2] == 'm') || _reg[0] == 'q'); } - const char* as_str() const { + + const char *as_str() const { if (_onStack) { return ""; } else { return _reg; } } - operator const char *() const { return as_str(); } - Kind kind() const { return _kind; } - size_t size() const { return is_128bit_float() ? 16 : _size; } - size_t align() const { return _align; } - size_t stack_offset() const { return _stack_offset; } + + operator const char *() const { + return as_str(); + } + + Kind kind() const { + return _kind; + } + + size_t size() const { + return is_128bit_float() ? 16 : _size; + } + + size_t align() const { + return _align; + } + + size_t stack_offset() const { + return _stack_offset; + } }; struct AbiSignature { diff --git a/tools/rewriter/DetermineAbi.cpp b/tools/rewriter/DetermineAbi.cpp index a299a1b55..990b0d3bd 100644 --- a/tools/rewriter/DetermineAbi.cpp +++ b/tools/rewriter/DetermineAbi.cpp @@ -22,9 +22,14 @@ #define VERBOSE_DEBUG 0 #if VERBOSE_DEBUG -#define DEBUG(X) do { X; } while (0) +#define DEBUG(X) \ + do { \ + X; \ + } while (0) #else -#define DEBUG(X) do { } while (0) +#define DEBUG(X) \ + do { \ + } while (0) #endif static ArgLocation classifyScalarType(const llvm::Type &type) { @@ -104,7 +109,7 @@ abiSlotsForArg(const clang::QualType &qt, // We have a scalar type, so classify it. return {classifyScalarType(*Ty)}; } - case Kind::Ignore: // no ABI presence + case Kind::Ignore: // no ABI presence return {}; case Kind::InAlloca: // via implicit pointer // It looks like inalloca is only valid on Win32 @@ -139,7 +144,7 @@ cgFunctionInfo(clang::CodeGen::CodeGenModule &cgm, } AbiSignature determineAbi(const clang::CodeGen::CGFunctionInfo &info, - const clang::ASTContext &astContext, Arch arch) { + const clang::ASTContext &astContext, Arch arch) { // get ABI for return type and each parameter AbiSignature sig; sig.variadic = info.isVariadic(); @@ -220,7 +225,7 @@ AbiSignature determineAbiForDecl(const clang::FunctionDecl &fnDecl, Arch arch) { } AbiSignature determineAbiForProtoType(const clang::FunctionProtoType &fpt, - clang::ASTContext &astContext, Arch arch) { + clang::ASTContext &astContext, Arch arch) { // FIXME: This is copied verbatim from determineAbiForDecl and could be // factored out. This depends on what we do with PR #78 so I'm leaving it as // is for now. diff --git a/tools/rewriter/DetermineAbi.h b/tools/rewriter/DetermineAbi.h index 17c69de43..0080b29b3 100644 --- a/tools/rewriter/DetermineAbi.h +++ b/tools/rewriter/DetermineAbi.h @@ -6,5 +6,5 @@ auto determineAbiForDecl(const clang::FunctionDecl &fnDecl, Arch arch) -> AbiSignature; AbiSignature determineAbiForProtoType(const clang::FunctionProtoType &fpt, - clang::ASTContext &astContext, - Arch arch); + clang::ASTContext &astContext, + Arch arch);