Skip to content

Commit cf13574

Browse files
committed
add swiftlint, fix violations and disable some linting rules
1 parent a97f3d9 commit cf13574

27 files changed

+557
-603
lines changed

.swiftlint.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
excluded:
2+
- Sources/Capstone/*Enums.swift
3+
disabled_rules:
4+
- large_tuple
5+
- nesting
6+
- line_length
7+
identifier_name:
8+
min_length: 1

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let package = Package(
1010
.library(
1111
name: "Capstone",
1212
targets: ["Capstone"]
13-
),
13+
)
1414
],
1515
dependencies: [
1616
// Dependencies declare other packages that this package depends on.
@@ -27,6 +27,6 @@ let package = Package(
2727
dependencies: ["Ccapstone"]),
2828
.testTarget(
2929
name: "CapstoneTests",
30-
dependencies: ["Capstone"]),
30+
dependencies: ["Capstone"])
3131
]
3232
)

Sources/Capstone/Architecture.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class TMS320C64xInstruction: PlatformInstruction<Tms320c64xIns, Tms320c64
6565
public class M680xInstruction: PlatformInstruction<M680xIns, M680xGrp, M680xReg> {}
6666

6767
/// Ethereum Instruction
68-
public class EthereumInstruction: PlatformInstruction_IG<EvmIns, EvmGrp> {}
68+
public class EthereumInstruction: PlatformInstructionBase<EvmIns, EvmGrp> {}
6969

7070
/// MOS65XX Instruction
7171
public class Mos65xxInstruction: PlatformInstruction<Mos65xxIns, Mos65xxGrp, Mos65xxReg> {}
@@ -103,15 +103,15 @@ public extension Architecture {
103103
return Mos65xxInstruction.self
104104
}
105105
}
106-
106+
107107
/// The type for registers used in this architecture, if any
108108
var registerType: Any.Type? {
109-
instructionClass.RegisterType
109+
instructionClass.registerType
110110
}
111-
111+
112112
/// The type for instructions used in this architecture
113113
var instructionType: InstructionType.Type {
114-
instructionClass.InstructionType
114+
instructionClass.instructionType
115115
}
116116
}
117117

Sources/Capstone/Arm.swift

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ extension ArmInstruction: OperandContainer {
55
let operands: [cs_arm_op] = readDetailsArray(array: detail?.arm.operands, size: detail?.arm.op_count)
66
return operands.map({ Operand(op: $0) })
77
}
8-
8+
99
/// User-mode registers to be loaded (for LDM/STM instructions).
1010
/// nil when detail mode is off
1111
public var usermode: Bool! { detail?.arm.usermode }
12-
12+
1313
/// Scalar size for vector instructions
1414
/// nil when detail mode is off
1515
public var vectorSize: Int! { optionalNumericCast(detail?.arm.vector_size) }
16-
16+
1717
/// Data type for elements of vector instructions
1818
/// nil when detail mode is off, or wrong instruction
1919
public var vectorDataType: ArmVectordata! {
2020
optionalEnumCast(detail?.arm.vector_data, ignoring: ARM_VECTORDATA_INVALID)
2121
}
22-
22+
2323
/// CPS mode for CPS instruction
2424
/// nil when detail mode is off, or wrong instruction
2525
public var cpsMode: (mode: ArmCpsmode, flag: ArmCpsflag)! {
@@ -29,86 +29,86 @@ extension ArmInstruction: OperandContainer {
2929
}
3030
return (mode, flag)
3131
}
32-
32+
3333
/// Condition code
3434
/// nil when detail mode is off, or instruction has no condition code
3535
public var conditionCode: ArmCc! {
3636
optionalEnumCast(detail?.arm.cc, ignoring: ARM_CC_INVALID)
3737
}
38-
38+
3939
/// Does this instruction update flags?
4040
/// nil when detail mode is off
4141
public var updatesFlags: Bool! { detail?.arm.update_flags }
42-
42+
4343
/// Does this instruction write-back?
4444
/// nil when detail mode is off
4545
public var writeBack: Bool! { detail?.arm.writeback }
46-
46+
4747
/// Option for some memory barrier instructions
4848
/// nil when detail mode is off, or wrong instruction
4949
public var memoryBarrier: ArmMb! {
5050
optionalEnumCast(detail?.arm.mem_barrier, ignoring: ARM_MB_INVALID)
5151
}
52-
52+
5353
public struct Operand: InstructionOperand, CustomStringConvertible {
5454
internal var op: cs_arm_op
55-
55+
5656
public var type: ArmOp { enumCast(op.type) }
57-
57+
5858
/// Operand access mode
5959
public var access: Access { enumCast(op.access) }
60-
60+
6161
/// Vector Index for some vector operands
6262
public var vectorIndex: Int! {
6363
guard op.vector_index != -1 else {
6464
return nil
6565
}
6666
return numericCast(op.vector_index)
6767
}
68-
68+
6969
/// Operand shift
7070
public var shift: Shift? {
7171
guard op.shift.type != ARM_SFT_INVALID else {
7272
return nil
7373
}
7474
return Shift(op.shift)
7575
}
76-
76+
7777
/// In some instructions, an operand can be subtracted or added to the base register
7878
public var subtracted: Bool { op.subtracted }
79-
79+
8080
/// Neon lane index for NEON instructions
8181
public var neonLane: Int! {
8282
guard op.neon_lane != -1 else {
8383
return nil
8484
}
8585
return numericCast(op.neon_lane)
8686
}
87-
87+
8888
/// Register value for register operand
8989
public var register: ArmReg! {
9090
guard type == .reg else { return nil }
9191
return enumCast(op.reg)
9292
}
93-
93+
9494
/// Register value for system register operand
9595
public var systemRegister: ArmSysreg! {
9696
guard type == .sysreg else { return nil }
9797
return enumCast(op.reg)
9898
}
99-
99+
100100
/// Immediate value for C-IMM, P-IMM or IMM operand
101101
public var immediateValue: Int32! {
102102
guard type.immediate else { return nil }
103103
return op.imm
104104
}
105-
105+
106106
/// Floating point value for FP operand
107107
public var doubleValue: Double! {
108108
guard type == .fp else { return nil }
109109
return op.fp
110110
}
111-
111+
112112
/// Base/index/scale/disp value for memory operand
113113
public var memory: Memory! {
114114
guard type == .mem else { return nil }
@@ -120,13 +120,13 @@ extension ArmInstruction: OperandContainer {
120120
leftShift: op.mem.lshift == 0 ? nil : numericCast(op.mem.lshift)
121121
)
122122
}
123-
123+
124124
/// Operand type for SETEND instruction
125125
public var setend: ArmSetend! {
126126
guard type == .setend else { return nil }
127127
return enumCast(op.setend)
128128
}
129-
129+
130130
/// Operand value
131131
public var value: ArmOperandValue {
132132
switch type {
@@ -147,11 +147,11 @@ extension ArmInstruction: OperandContainer {
147147
return 0
148148
}
149149
}
150-
150+
151151
public var description: String {
152152
"\(type)<\(value)>"
153153
}
154-
154+
155155
/// Instruction operand shift
156156
public enum Shift {
157157
public enum Direction: UInt8 {
@@ -166,10 +166,10 @@ extension ArmInstruction: OperandContainer {
166166
/// Rotate Right with eXtend
167167
case rrx = 5
168168
}
169-
169+
170170
case immediate(direction: Direction, value: UInt)
171171
case register(direction: Direction, register: ArmReg)
172-
172+
173173
init(_ shift: cs_arm_op.__Unnamed_struct_shift) {
174174
switch shift.type.rawValue {
175175
case ARM_SFT_LSL.rawValue...ARM_SFT_RRX.rawValue:
@@ -181,7 +181,7 @@ extension ArmInstruction: OperandContainer {
181181
}
182182
}
183183
}
184-
184+
185185
/// Instruction's operand referring to memory
186186
public struct Memory {
187187
/// Base register

0 commit comments

Comments
 (0)