diff options
| author | Cliff Click <cliffc@acm.org> | 2025-02-07 08:58:36 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2025-02-07 08:58:36 -0800 |
| commit | 2aa8c5d1d0659bd1c828134f1a1f14d025a2d0f1 (patch) | |
| tree | 0532f3ba5d74de006fcaa906dad9b787ebb06e2e /src/main/java/com/seaofnodes/simple/SB.java | |
| parent | 68dc63b9390bbe4ec50cc1b814d4e559e459c057 (diff) | |
| download | Simple-linear-chapter19.tar.gz Simple-linear-chapter19.zip | |
Ch# Chapter 19: Instruction Selection and Portable Compilationlinear-chapter19
Co-authored-by: hadha <helsgithub15@gmail.com>
Co-authored-by: Tamás Hadházy <85063808+Hels15@users.noreply.github.com>
Diffstat (limited to 'src/main/java/com/seaofnodes/simple/SB.java')
| -rw-r--r-- | src/main/java/com/seaofnodes/simple/SB.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/main/java/com/seaofnodes/simple/SB.java b/src/main/java/com/seaofnodes/simple/SB.java index 6f5a29ee..7d580c21 100644 --- a/src/main/java/com/seaofnodes/simple/SB.java +++ b/src/main/java/com/seaofnodes/simple/SB.java @@ -29,6 +29,23 @@ public final class SB { public SB p( int s ) { _sb.append(s); return this; } public SB p( long s ) { _sb.append(s); return this; } public SB p( boolean s) { _sb.append(s); return this; } + // 4 hex digits + public SB hex4(int s) { + assert (s>>4*4)==0; // Fits in 16 bits + for( int i=0; i<4; i++ ) { + int digit = (s>>((3-i)*4)) & 0xf; + _sb.append((char)((digit <= 9 ? '0' : ('A'-10))+digit)); + } + return this; + } + // Fixed width field + public SB fix( int sz, String s ) { + assert sz >=0; + for( int i=0; i<sz; i++ ) + _sb.append( i < s.length() ? s.charAt(i) : ' '); + return this; + } + // Not spelled "p" on purpose: too easy to accidentally say "p(1.0)" and // suddenly call the autoboxed version. public SB pobj( Object s ) { _sb.append(s.toString()); return this; } |
