Skip to content
Browse files

blah

  • Loading branch information...
1 parent c5c9e8f commit 4a6aa8644c70e24f6a4434313fcd8cdc3c4b63e4 @comex committed Sep 14, 2010
Showing with 287 additions and 145 deletions.
  1. +1 −1 ddi.py
  2. +1 −1 disas.nim
  3. +10 −0 funcs.nim
  4. +8 −1 gen_lazyAC.py
  5. +249 −123 lazyAC.nim
  6. +1 −1 nullAC.nim
  7. +17 −8 stringAC.nim
  8. +0 −10 types.nim
View
2 ddi.py
@@ -223,7 +223,7 @@ def foo(bitsize, insns, known={}):
for k in handlers:
print '! Bad handler: ' + k
open('disas.nim', 'w').write('''
-import armtypes, armfuncs, types
+import armtypes, armfuncs, types, funcs
import allAC
include "ltgt"
template ctxspec(TAsmCtx : typedesc, TVal : typedesc, TRVal : typedesc) =
View
2 disas.nim
@@ -1,5 +1,5 @@
-import armtypes, armfuncs, types
+import armtypes, armfuncs, types, funcs
import allAC
include "ltgt"
template ctxspec(TAsmCtx : typedesc, TVal : typedesc, TRVal : typedesc) =
View
10 funcs.nim
@@ -4,3 +4,13 @@ proc bROR*(b : TBinary, amt : int) : TBinary =
result.num = (b.num shr amt) or (b.num shl (b.size - amt))
result.num = result.num and ((1 shl b.size) - 1)
+proc sxt*(b : TBinary) : TBinary =
+ result.num = b.num
+ result.size = 32
+ if b[b.size-1].bit:
+ orr(result.num, not ((1 shl b.size) - 1))
+
+proc zxt*(b : TBinary) : TBinary {.inline.} =
+ result.num = b.num
+ result.size = 32
+
View
9 gen_lazyAC.py
@@ -125,7 +125,14 @@
"YIELD",
]
+print 'type TOpName* = enum'
+print ' ' + ',\n '.join('opn' + op.split(' ')[0] for op in ops) + '\n\n'
+
print 'template beLazy*(TAsmCtx : typedesc, TVal : typedesc) ='
for op in ops:
+ # I should use Python 3 so I can do op, *args...
+ x = op.split(' ')
+ args = x[1:]
+ op = x[0]
print ' proc op%s*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =' % op
- print ' return ctx.GenericOp("%s", flags, ents)' % op
+ print ' return ctx.GenericOp(opn%s, "%s", flags, ents)' % (op, op)
View
372 lazyAC.nim
@@ -1,247 +1,373 @@
+type TOpName* = enum
+ opnADC,
+ opnADD,
+ opnADDW,
+ opnADR,
+ opnAND,
+ opnASR,
+ opnB,
+ opnBFC,
+ opnBFI,
+ opnBIC,
+ opnBKPT,
+ opnBL,
+ opnBLX,
+ opnBX,
+ opnCBNZ,
+ opnCBZ,
+ opnCDP,
+ opnCDP2,
+ opnCLREX,
+ opnCLZ,
+ opnCMN,
+ opnCMP,
+ opnCPS,
+ opnDBG,
+ opnDMB,
+ opnDSB,
+ opnEOR,
+ opnISB,
+ opnIT,
+ opnLDC,
+ opnLDC2,
+ opnLDM,
+ opnLDMIA,
+ opnLDMDB,
+ opnLDR,
+ opnLDRB,
+ opnLDRBT,
+ opnLDRD,
+ opnLDREX,
+ opnLDREXB,
+ opnLDREXH,
+ opnLDRH,
+ opnLDRHT,
+ opnLDRSB,
+ opnLDRSBT,
+ opnLDRSH,
+ opnLDRSHT,
+ opnLDRT,
+ opnLSL,
+ opnLSR,
+ opnMCR,
+ opnMCR2,
+ opnMCRR,
+ opnMCRR2,
+ opnMLA,
+ opnMLS,
+ opnMOV,
+ opnMOVS,
+ opnMOVT,
+ opnMOVW,
+ opnMRC,
+ opnMRC2,
+ opnMRRC,
+ opnMRRC2,
+ opnMRS,
+ opnMSR,
+ opnMUL,
+ opnMVN,
+ opnNOP,
+ opnORN,
+ opnORR,
+ opnPLD,
+ opnPLI,
+ opnPOP,
+ opnPUSH,
+ opnRBIT,
+ opnREV,
+ opnREV16,
+ opnREVSH,
+ opnROR,
+ opnRRX,
+ opnRSB,
+ opnSBC,
+ opnSBFX,
+ opnSDIV,
+ opnSEV,
+ opnSMLAL,
+ opnSMULL,
+ opnSSAT,
+ opnSTC,
+ opnSTC2,
+ opnSTM,
+ opnSTMIA,
+ opnSTMDB,
+ opnSTR,
+ opnSTRB,
+ opnSTRBT,
+ opnSTRD,
+ opnSTREX,
+ opnSTREXB,
+ opnSTREXH,
+ opnSTRH,
+ opnSTRHT,
+ opnSTRT,
+ opnSUB,
+ opnSUBW,
+ opnSVC,
+ opnSXTB,
+ opnSXTH,
+ opnTBB,
+ opnTBH,
+ opnTEQ,
+ opnTST,
+ opnUBFX,
+ opnUDIV,
+ opnUMLAL,
+ opnUMULL,
+ opnUSAT,
+ opnUXTB,
+ opnUXTH,
+ opnWFE,
+ opnWFI,
+ opnYIELD
+
+
template beLazy*(TAsmCtx : typedesc, TVal : typedesc) =
proc opADC*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("ADC", flags, ents)
+ return ctx.GenericOp(opnADC, "ADC", flags, ents)
proc opADD*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("ADD", flags, ents)
+ return ctx.GenericOp(opnADD, "ADD", flags, ents)
proc opADDW*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("ADDW", flags, ents)
+ return ctx.GenericOp(opnADDW, "ADDW", flags, ents)
proc opADR*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("ADR", flags, ents)
+ return ctx.GenericOp(opnADR, "ADR", flags, ents)
proc opAND*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("AND", flags, ents)
+ return ctx.GenericOp(opnAND, "AND", flags, ents)
proc opASR*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("ASR", flags, ents)
+ return ctx.GenericOp(opnASR, "ASR", flags, ents)
proc opB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("B", flags, ents)
+ return ctx.GenericOp(opnB, "B", flags, ents)
proc opBFC*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("BFC", flags, ents)
+ return ctx.GenericOp(opnBFC, "BFC", flags, ents)
proc opBFI*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("BFI", flags, ents)
+ return ctx.GenericOp(opnBFI, "BFI", flags, ents)
proc opBIC*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("BIC", flags, ents)
+ return ctx.GenericOp(opnBIC, "BIC", flags, ents)
proc opBKPT*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("BKPT", flags, ents)
+ return ctx.GenericOp(opnBKPT, "BKPT", flags, ents)
proc opBL*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("BL", flags, ents)
+ return ctx.GenericOp(opnBL, "BL", flags, ents)
proc opBLX*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("BLX", flags, ents)
+ return ctx.GenericOp(opnBLX, "BLX", flags, ents)
proc opBX*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("BX", flags, ents)
+ return ctx.GenericOp(opnBX, "BX", flags, ents)
proc opCBNZ*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("CBNZ", flags, ents)
+ return ctx.GenericOp(opnCBNZ, "CBNZ", flags, ents)
proc opCBZ*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("CBZ", flags, ents)
+ return ctx.GenericOp(opnCBZ, "CBZ", flags, ents)
proc opCDP*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("CDP", flags, ents)
+ return ctx.GenericOp(opnCDP, "CDP", flags, ents)
proc opCDP2*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("CDP2", flags, ents)
+ return ctx.GenericOp(opnCDP2, "CDP2", flags, ents)
proc opCLREX*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("CLREX", flags, ents)
+ return ctx.GenericOp(opnCLREX, "CLREX", flags, ents)
proc opCLZ*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("CLZ", flags, ents)
+ return ctx.GenericOp(opnCLZ, "CLZ", flags, ents)
proc opCMN*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("CMN", flags, ents)
+ return ctx.GenericOp(opnCMN, "CMN", flags, ents)
proc opCMP*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("CMP", flags, ents)
+ return ctx.GenericOp(opnCMP, "CMP", flags, ents)
proc opCPS*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("CPS", flags, ents)
+ return ctx.GenericOp(opnCPS, "CPS", flags, ents)
proc opDBG*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("DBG", flags, ents)
+ return ctx.GenericOp(opnDBG, "DBG", flags, ents)
proc opDMB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("DMB", flags, ents)
+ return ctx.GenericOp(opnDMB, "DMB", flags, ents)
proc opDSB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("DSB", flags, ents)
+ return ctx.GenericOp(opnDSB, "DSB", flags, ents)
proc opEOR*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("EOR", flags, ents)
+ return ctx.GenericOp(opnEOR, "EOR", flags, ents)
proc opISB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("ISB", flags, ents)
+ return ctx.GenericOp(opnISB, "ISB", flags, ents)
proc opIT*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("IT", flags, ents)
+ return ctx.GenericOp(opnIT, "IT", flags, ents)
proc opLDC*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDC", flags, ents)
+ return ctx.GenericOp(opnLDC, "LDC", flags, ents)
proc opLDC2*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDC2", flags, ents)
+ return ctx.GenericOp(opnLDC2, "LDC2", flags, ents)
proc opLDM*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDM", flags, ents)
+ return ctx.GenericOp(opnLDM, "LDM", flags, ents)
proc opLDMIA*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDMIA", flags, ents)
+ return ctx.GenericOp(opnLDMIA, "LDMIA", flags, ents)
proc opLDMDB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDMDB", flags, ents)
+ return ctx.GenericOp(opnLDMDB, "LDMDB", flags, ents)
proc opLDR*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDR", flags, ents)
+ return ctx.GenericOp(opnLDR, "LDR", flags, ents)
proc opLDRB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDRB", flags, ents)
+ return ctx.GenericOp(opnLDRB, "LDRB", flags, ents)
proc opLDRBT*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDRBT", flags, ents)
+ return ctx.GenericOp(opnLDRBT, "LDRBT", flags, ents)
proc opLDRD*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDRD", flags, ents)
+ return ctx.GenericOp(opnLDRD, "LDRD", flags, ents)
proc opLDREX*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDREX", flags, ents)
+ return ctx.GenericOp(opnLDREX, "LDREX", flags, ents)
proc opLDREXB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDREXB", flags, ents)
+ return ctx.GenericOp(opnLDREXB, "LDREXB", flags, ents)
proc opLDREXH*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDREXH", flags, ents)
+ return ctx.GenericOp(opnLDREXH, "LDREXH", flags, ents)
proc opLDRH*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDRH", flags, ents)
+ return ctx.GenericOp(opnLDRH, "LDRH", flags, ents)
proc opLDRHT*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDRHT", flags, ents)
+ return ctx.GenericOp(opnLDRHT, "LDRHT", flags, ents)
proc opLDRSB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDRSB", flags, ents)
+ return ctx.GenericOp(opnLDRSB, "LDRSB", flags, ents)
proc opLDRSBT*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDRSBT", flags, ents)
+ return ctx.GenericOp(opnLDRSBT, "LDRSBT", flags, ents)
proc opLDRSH*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDRSH", flags, ents)
+ return ctx.GenericOp(opnLDRSH, "LDRSH", flags, ents)
proc opLDRSHT*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDRSHT", flags, ents)
+ return ctx.GenericOp(opnLDRSHT, "LDRSHT", flags, ents)
proc opLDRT*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LDRT", flags, ents)
+ return ctx.GenericOp(opnLDRT, "LDRT", flags, ents)
proc opLSL*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LSL", flags, ents)
+ return ctx.GenericOp(opnLSL, "LSL", flags, ents)
proc opLSR*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("LSR", flags, ents)
+ return ctx.GenericOp(opnLSR, "LSR", flags, ents)
proc opMCR*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MCR", flags, ents)
+ return ctx.GenericOp(opnMCR, "MCR", flags, ents)
proc opMCR2*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MCR2", flags, ents)
+ return ctx.GenericOp(opnMCR2, "MCR2", flags, ents)
proc opMCRR*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MCRR", flags, ents)
+ return ctx.GenericOp(opnMCRR, "MCRR", flags, ents)
proc opMCRR2*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MCRR2", flags, ents)
+ return ctx.GenericOp(opnMCRR2, "MCRR2", flags, ents)
proc opMLA*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MLA", flags, ents)
+ return ctx.GenericOp(opnMLA, "MLA", flags, ents)
proc opMLS*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MLS", flags, ents)
+ return ctx.GenericOp(opnMLS, "MLS", flags, ents)
proc opMOV*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MOV", flags, ents)
+ return ctx.GenericOp(opnMOV, "MOV", flags, ents)
proc opMOVS*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MOVS", flags, ents)
+ return ctx.GenericOp(opnMOVS, "MOVS", flags, ents)
proc opMOVT*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MOVT", flags, ents)
+ return ctx.GenericOp(opnMOVT, "MOVT", flags, ents)
proc opMOVW*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MOVW", flags, ents)
+ return ctx.GenericOp(opnMOVW, "MOVW", flags, ents)
proc opMRC*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MRC", flags, ents)
+ return ctx.GenericOp(opnMRC, "MRC", flags, ents)
proc opMRC2*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MRC2", flags, ents)
+ return ctx.GenericOp(opnMRC2, "MRC2", flags, ents)
proc opMRRC*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MRRC", flags, ents)
+ return ctx.GenericOp(opnMRRC, "MRRC", flags, ents)
proc opMRRC2*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MRRC2", flags, ents)
+ return ctx.GenericOp(opnMRRC2, "MRRC2", flags, ents)
proc opMRS*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MRS", flags, ents)
+ return ctx.GenericOp(opnMRS, "MRS", flags, ents)
proc opMSR*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MSR", flags, ents)
+ return ctx.GenericOp(opnMSR, "MSR", flags, ents)
proc opMUL*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MUL", flags, ents)
+ return ctx.GenericOp(opnMUL, "MUL", flags, ents)
proc opMVN*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("MVN", flags, ents)
+ return ctx.GenericOp(opnMVN, "MVN", flags, ents)
proc opNOP*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("NOP", flags, ents)
+ return ctx.GenericOp(opnNOP, "NOP", flags, ents)
proc opORN*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("ORN", flags, ents)
+ return ctx.GenericOp(opnORN, "ORN", flags, ents)
proc opORR*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("ORR", flags, ents)
+ return ctx.GenericOp(opnORR, "ORR", flags, ents)
proc opPLD*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("PLD", flags, ents)
+ return ctx.GenericOp(opnPLD, "PLD", flags, ents)
proc opPLI*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("PLI", flags, ents)
+ return ctx.GenericOp(opnPLI, "PLI", flags, ents)
proc opPOP*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("POP", flags, ents)
+ return ctx.GenericOp(opnPOP, "POP", flags, ents)
proc opPUSH*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("PUSH", flags, ents)
+ return ctx.GenericOp(opnPUSH, "PUSH", flags, ents)
proc opRBIT*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("RBIT", flags, ents)
+ return ctx.GenericOp(opnRBIT, "RBIT", flags, ents)
proc opREV*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("REV", flags, ents)
+ return ctx.GenericOp(opnREV, "REV", flags, ents)
proc opREV16*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("REV16", flags, ents)
+ return ctx.GenericOp(opnREV16, "REV16", flags, ents)
proc opREVSH*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("REVSH", flags, ents)
+ return ctx.GenericOp(opnREVSH, "REVSH", flags, ents)
proc opROR*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("ROR", flags, ents)
+ return ctx.GenericOp(opnROR, "ROR", flags, ents)
proc opRRX*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("RRX", flags, ents)
+ return ctx.GenericOp(opnRRX, "RRX", flags, ents)
proc opRSB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("RSB", flags, ents)
+ return ctx.GenericOp(opnRSB, "RSB", flags, ents)
proc opSBC*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("SBC", flags, ents)
+ return ctx.GenericOp(opnSBC, "SBC", flags, ents)
proc opSBFX*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("SBFX", flags, ents)
+ return ctx.GenericOp(opnSBFX, "SBFX", flags, ents)
proc opSDIV*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("SDIV", flags, ents)
+ return ctx.GenericOp(opnSDIV, "SDIV", flags, ents)
proc opSEV*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("SEV", flags, ents)
+ return ctx.GenericOp(opnSEV, "SEV", flags, ents)
proc opSMLAL*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("SMLAL", flags, ents)
+ return ctx.GenericOp(opnSMLAL, "SMLAL", flags, ents)
proc opSMULL*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("SMULL", flags, ents)
+ return ctx.GenericOp(opnSMULL, "SMULL", flags, ents)
proc opSSAT*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("SSAT", flags, ents)
+ return ctx.GenericOp(opnSSAT, "SSAT", flags, ents)
proc opSTC*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STC", flags, ents)
+ return ctx.GenericOp(opnSTC, "STC", flags, ents)
proc opSTC2*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STC2", flags, ents)
+ return ctx.GenericOp(opnSTC2, "STC2", flags, ents)
proc opSTM*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STM", flags, ents)
+ return ctx.GenericOp(opnSTM, "STM", flags, ents)
proc opSTMIA*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STMIA", flags, ents)
+ return ctx.GenericOp(opnSTMIA, "STMIA", flags, ents)
proc opSTMDB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STMDB", flags, ents)
+ return ctx.GenericOp(opnSTMDB, "STMDB", flags, ents)
proc opSTR*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STR", flags, ents)
+ return ctx.GenericOp(opnSTR, "STR", flags, ents)
proc opSTRB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STRB", flags, ents)
+ return ctx.GenericOp(opnSTRB, "STRB", flags, ents)
proc opSTRBT*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STRBT", flags, ents)
+ return ctx.GenericOp(opnSTRBT, "STRBT", flags, ents)
proc opSTRD*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STRD", flags, ents)
+ return ctx.GenericOp(opnSTRD, "STRD", flags, ents)
proc opSTREX*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STREX", flags, ents)
+ return ctx.GenericOp(opnSTREX, "STREX", flags, ents)
proc opSTREXB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STREXB", flags, ents)
+ return ctx.GenericOp(opnSTREXB, "STREXB", flags, ents)
proc opSTREXH*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STREXH", flags, ents)
+ return ctx.GenericOp(opnSTREXH, "STREXH", flags, ents)
proc opSTRH*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STRH", flags, ents)
+ return ctx.GenericOp(opnSTRH, "STRH", flags, ents)
proc opSTRHT*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STRHT", flags, ents)
+ return ctx.GenericOp(opnSTRHT, "STRHT", flags, ents)
proc opSTRT*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("STRT", flags, ents)
+ return ctx.GenericOp(opnSTRT, "STRT", flags, ents)
proc opSUB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("SUB", flags, ents)
+ return ctx.GenericOp(opnSUB, "SUB", flags, ents)
proc opSUBW*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("SUBW", flags, ents)
+ return ctx.GenericOp(opnSUBW, "SUBW", flags, ents)
proc opSVC*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("SVC", flags, ents)
+ return ctx.GenericOp(opnSVC, "SVC", flags, ents)
proc opSXTB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("SXTB", flags, ents)
+ return ctx.GenericOp(opnSXTB, "SXTB", flags, ents)
proc opSXTH*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("SXTH", flags, ents)
+ return ctx.GenericOp(opnSXTH, "SXTH", flags, ents)
proc opTBB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("TBB", flags, ents)
+ return ctx.GenericOp(opnTBB, "TBB", flags, ents)
proc opTBH*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("TBH", flags, ents)
+ return ctx.GenericOp(opnTBH, "TBH", flags, ents)
proc opTEQ*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("TEQ", flags, ents)
+ return ctx.GenericOp(opnTEQ, "TEQ", flags, ents)
proc opTST*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("TST", flags, ents)
+ return ctx.GenericOp(opnTST, "TST", flags, ents)
proc opUBFX*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("UBFX", flags, ents)
+ return ctx.GenericOp(opnUBFX, "UBFX", flags, ents)
proc opUDIV*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("UDIV", flags, ents)
+ return ctx.GenericOp(opnUDIV, "UDIV", flags, ents)
proc opUMLAL*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("UMLAL", flags, ents)
+ return ctx.GenericOp(opnUMLAL, "UMLAL", flags, ents)
proc opUMULL*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("UMULL", flags, ents)
+ return ctx.GenericOp(opnUMULL, "UMULL", flags, ents)
proc opUSAT*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("USAT", flags, ents)
+ return ctx.GenericOp(opnUSAT, "USAT", flags, ents)
proc opUXTB*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("UXTB", flags, ents)
+ return ctx.GenericOp(opnUXTB, "UXTB", flags, ents)
proc opUXTH*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("UXTH", flags, ents)
+ return ctx.GenericOp(opnUXTH, "UXTH", flags, ents)
proc opWFE*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("WFE", flags, ents)
+ return ctx.GenericOp(opnWFE, "WFE", flags, ents)
proc opWFI*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("WFI", flags, ents)
+ return ctx.GenericOp(opnWFI, "WFI", flags, ents)
proc opYIELD*(ctx : TAsmCtx, flags : TInsnFlags, ents : openarray[TVal]) : TVal =
- return ctx.GenericOp("YIELD", flags, ents)
+ return ctx.GenericOp(opnYIELD, "YIELD", flags, ents)
View
2 nullAC.nim
@@ -45,7 +45,7 @@ proc ShiftA*(ctx : PNullAsmCtx, base : TNullRVal, kind : TShiftKind, amt : TNull
proc DerefA*(ctx : PNullAsmCtx, base : TNullVal, offset : TNullRVal, size : TDerefSize, kind : TDerefKind) : TNullVal {.inline.} =
nil
-proc GenericOp*(ctx : PNullAsmCtx, name : string, flags : TInsnFlags, ents : openarray[TNullVal]) : TNullVal {.inline.} =
+proc GenericOp*(ctx : PNullAsmCtx, iname : TOpName, name : string, flags : TInsnFlags, ents : openarray[TNullVal]) : TNullVal {.inline.} =
nil
beLazy(PNullAsmCtx, TNullVal)
View
25 stringAC.nim
@@ -20,10 +20,12 @@ proc `$`*(a : TStringVal) : string =
return a.str
proc PCrel(input : TStringVal) : TStringVal =
+ if not input.isImm: return input
result.isImm = false
result.str ="PCrel:#" & $input.imm
proc SPrel(input : TStringVal) : TStringVal =
+ if not input.isImm: return input
result.isImm = false
result.str = "SPrel:#" & $input.imm
@@ -110,9 +112,9 @@ proc ShiftA*(ctx : PStringAsmCtx, base : TStringVal, kind : TShiftKind, amt : TS
proc DerefA*(ctx : PStringAsmCtx, base : TStringVal, offset : TStringVal, size : TDerefSize, kind : TDerefKind) : TStringVal =
var sizeA = (if size == 4: "" else: "." & $size)
var offsetA = offset
- if base.str == "PC" and offsetA.isImm:
+ if base.str == "PC":
offsetA = PCrel(offsetA)
- elif base.str == "SP" and offsetA.isImm:
+ elif base.str == "SP":
offsetA = SPrel(offsetA)
var res : string
case kind
@@ -125,21 +127,28 @@ proc DerefA*(ctx : PStringAsmCtx, base : TStringVal, offset : TStringVal, size :
result.isImm = false
result.str = res
-proc GenericOp*(ctx : PStringAsmCtx, name : string, flags : TInsnFlags, ents : openarray[TStringVal]) : TStringVal =
+proc GenericOp*(ctx : PStringAsmCtx, iname : TOpName, name : string, flags : TInsnFlags, ents : openarray[TStringVal]) : TStringVal =
var a = name
if ifS in flags:
add(a, "S")
if ifMagic in flags:
- case name
- of "STCL": add(a, "L")
- of "PLDW": add(a, "W")
- of "CPS": add(a, "IE")
+ case iname
+ of opnSTC: add(a, "L")
+ of opnPLD: add(a, "W")
+ of opnCPS: add(a, "IE")
+ else: nil
+
var cond : string = $toCond(flags)
if cond == "AL": cond = ""
add(a, cond)
add(a, " ")
for i in 0..high(ents):
- add(a, $ents[i])
+ var ent = ents[i]
+ if i == 2 and iname == opnADD and $ents[1] == "PC":
+ ent = PCrel(ent)
+ elif i == 1 and (iname == opnB or iname == opnBL or iname == opnBLX):
+ ent = PCrel(ent)
+ add(a, $ent)
if i != high(ents): add(a, ", ")
result.isImm = false
result.str = a
View
10 types.nim
@@ -99,13 +99,3 @@ proc bit*(b : TBinary) : bool {.inline.} =
proc bit*(b : int) : bool {.inline.} =
return b != 0
-proc sxt*(b : TBinary) : TBinary =
- result.num = b.num
- result.size = 32
- if b[b.size-1].bit:
- orr(result.num, not (1 shl (b.size - 1)))
-
-proc zxt*(b : TBinary) : TBinary {.inline.} =
- result.num = b.num
- result.size = 32
-

0 comments on commit 4a6aa86

Please sign in to comment.
Something went wrong with that request. Please try again.