• Home
  • Install
  • Cosmos Website
  • Articles
  • Cosmos
  • X#
  • IL2CPU
Show / Hide Table of Contents
  • XSharp
    • AsmGenerator
    • AsmGenerator.FlagBool
    • Compiler
    • Compiler.Block
    • Compiler.BlockList
    • Compiler.BlockType
    • Extensions
    • Parser
    • Parser.CharType
    • Token
    • TokenList
    • TokenPatterns
    • TokenPatterns.Block
    • TokenPatterns.Blocks
    • TokenPatterns.CodeFunc
    • TokenPatterns.Pattern
    • TokenType
    • XS
    • XS.FPU
    • XS.SSE
    • XS.SSE2
    • XS.SSE3
    • XSRegisters
    • XSRegisters.Register
    • XSRegisters.Register16
    • XSRegisters.Register32
    • XSRegisters.Register8
    • XSRegisters.RegisterFPU
    • XSRegisters.RegisterSegment
    • XSRegisters.RegisterSize
    • XSRegisters.RegisterXMM
  • XSharp.Assembler
    • Assembler
    • AssemblerMethod
    • BaseAssemblerElement
    • Comment
    • DataEndIfDefined
    • DataIfDefined
    • DataIfNotDefined
    • DataMember
    • Define
    • ElementReference
    • Else
    • EndIfDefined
    • IDefine
    • IEndIfDefined
    • IfDefined
    • IfNotDefined
    • IIfDefined
    • IIfNotDefined
    • InfraExtensions
    • Instruction
    • Label
    • LiteralAssemblerCode
    • OpCodeAttribute
    • TypeComparer
  • XSharp.Assembler.x86
    • Add
    • AddWithCarry
    • And
    • Call
    • ClearInterruptFlag
    • ClrCarryFlag
    • ClrDirFlag
    • CmpXchg
    • Compare
    • ConditionalJump
    • ConditionalMove
    • ConditionalTestEnum
    • ConvByteToWord
    • CpuId
    • DebugNoop
    • Dec
    • Divide
    • ExternalLabel
    • Halt
    • IDivide
    • IInstructionWithArgument
    • IInstructionWithCondition
    • IInstructionWithDestination
    • IInstructionWithPrefix
    • IInstructionWithSize
    • IInstructionWithSource
    • Imul
    • INC
    • InfraExtensions
    • InFromDX
    • Instruction
    • Instruction.InstructionSize
    • Instruction.InstructionSizes
    • Instruction.OperandMemoryKinds
    • InstructionPrefixes
    • InstructionWithDestination
    • InstructionWithDestinationAndSize
    • InstructionWithDestinationAndSource
    • InstructionWithDestinationAndSourceAndArgument
    • InstructionWithDestinationAndSourceAndSize
    • InstructionWithSize
    • INT
    • INT1
    • INT3
    • Interrupt
    • IRET
    • Jump
    • JumpBase
    • JumpToSegment
    • Lea
    • Lgdt
    • Lidt
    • LoadStatusFlags
    • Mov
    • MoveCR
    • MoveD
    • MoveSignExtend
    • MoveToDR6
    • MoveZeroExtend
    • Movs
    • Multiply
    • Neg
    • Noop
    • Not
    • Or
    • OutToDX
    • Pop
    • Popad
    • Popfd
    • Push
    • Pushad
    • Pushfd
    • Rdmsr
    • Rdtsc
    • Registers
    • RegistersEnum
    • Return
    • RotateLeft
    • RotateRight
    • RotateThroughCarryRight
    • Scas
    • SetByteOnCondition
    • ShiftLeft
    • ShiftLeftArithmetic
    • ShiftLeftDouble
    • ShiftRight
    • ShiftRightArithmetic
    • ShiftRightDouble
    • SignExtendAX
    • Sti
    • Stos
    • Sub
    • SubWithCarry
    • Test
    • Xchg
    • Xor
  • XSharp.Assembler.x86.SSE
    • AddPD
    • AddSD
    • AddSS
    • AndPD
    • AndPS
    • ComparePD
    • ComparePS
    • ComparePseudoOpcodes
    • CompareSD
    • CompareSS
    • ConvertPD2DQAndTruncate
    • ConvertSD2SI
    • ConvertSD2SIAndTruncate
    • ConvertSD2SS
    • ConvertSI2SD
    • ConvertSI2SS
    • ConvertSS2SD
    • ConvertSS2SI
    • ConvertSS2SIAndTruncate
    • DivPD
    • DivPS
    • DivSD
    • DivSS
    • InstructionWithDestinationAndSourceAndPseudoOpcodes
    • MaxSS
    • MinSS
    • MoveAPD
    • MoveAPS
    • MoveDoubleAndDuplicate
    • MoveDoubleAndDupplicate
    • MoveDQA
    • MoveDQU
    • MoveHLPD
    • MoveHLPS
    • MoveHPD
    • MoveHPS
    • MoveLHPS
    • MoveLPD
    • MoveQ
    • MoveSD
    • MoveSS
    • MoveUPD
    • MoveUPS
    • MulPD
    • MulPS
    • MulSD
    • MulSS
    • OrPS
    • Por
    • Psrld
    • Shufps
    • SqrtScalardDouble
    • SSEInit
    • SubPD
    • SubPS
    • SubSD
    • SubSS
    • UnpackLowDouble
    • XorPD
    • XorPS
  • XSharp.Assembler.x86.X86
    • Cmps
  • XSharp.Assembler.x86.X86.SSE
    • AddPS
  • XSharp.Assembler.x86.X86.x87
    • FloatCompareAnd2Pop
    • FloatPushOne
    • FloatPushZero
    • FloatUCompareAnd2Pop
  • XSharp.Assembler.x86.x87
    • FloatABS
    • FloatAdd
    • FloatAddAndPop
    • FloatClearEx
    • FloatCompare
    • FloatCompareAndPop
    • FloatCompareAndSet
    • FloatCompareAndSetAndPop
    • FloatCompareOrderAndSetAndPop
    • FloatCompareOrderSetAndPop
    • FloatConditionalMoveTestEnum
    • FloatCosine
    • FloatDecTopPointer
    • FloatDivide
    • FloatDivideAndPop
    • FloatDivideAndPopReverse
    • FloatDivideReverse
    • FloatFree
    • FloatIncTopPointer
    • FloatInit
    • FloatLoad
    • FloatMul
    • FloatMulAndPop
    • FloatNegate
    • FloatPop
    • FloatPRem
    • FloatPRem1
    • FloatRound
    • FloatSine
    • FloatSqrt
    • FloatStore
    • FloatStoreAndPop
    • FloatSub
    • FloatSubAndPop
    • FloatSubAndPopReverse
    • FloatSubReverse
    • FloatTan
    • FloatTest
    • FloatUCompare
    • FloatUCompareAndPop
    • FloatXchg
    • FXSave
    • FXStore
    • IntAdd
    • IntCompare
    • IntCompareAndPop
    • IntDiv
    • IntDivReverse
    • IntLoad
    • IntMul
    • IntStore
    • IntStoreAndPop
    • IntStoreWithTrunc
    • IntSub
    • IntSubReverse
  • XSharp.Tokens
    • AsKeyword
    • Compare
    • Compare<TLeftValueType, TComparatorType, TRightValueType>
    • CompareConstConst
    • CompareConstInt16
    • CompareConstInt32
    • CompareConstInt8
    • CompareConstVar
    • CompareConstVarAddr
    • CompareInt16Const
    • CompareInt16Int16
    • CompareInt16Var
    • CompareInt32Const
    • CompareInt32Int32
    • CompareInt32Var
    • CompareInt32VarAddr
    • CompareInt8Const
    • CompareInt8Int8
    • CompareInt8Var
    • CompareMem<TLeftValueType, TComparatorType, TRightValueType>
    • CompareReg08Const
    • CompareReg08Reg08
    • CompareReg08Var
    • CompareReg16Const
    • CompareReg16Int16
    • CompareReg16Reg16
    • CompareReg16Var
    • CompareReg32Const
    • CompareReg32Int32
    • CompareReg32Reg32
    • CompareReg32Var
    • CompareReg8Int8
    • CompareRegConst
    • CompareRegVar
    • CompareRegVarAddr
    • CompareVar
    • CompareVarAddrConst
    • CompareVarAddrInt32
    • CompareVarAddrVar
    • CompareVarAddrVarAddr
    • CompareVarConst
    • CompareVarInt16
    • CompareVarInt32
    • CompareVarInt8
    • CompareVarVar
    • CompareVarVarAddr
    • CompareWithMem
    • Const
    • ConstKeyword
    • FunctionKeyword
    • GotoKeyword
    • Identifier
    • If
    • Int08u
    • Int16u
    • Int32u
    • Interrupt
    • NamespaceKeyword
    • NOP
    • Num
    • OpBitwise
    • OpComment
    • OpCompare
    • OpIncDec
    • OpInclude
    • OpLiteral
    • OpMath
    • OpPureComparators
    • OpRotate
    • OpShift
    • PopAll
    • PortKeyword
    • PushAll
    • Reg
    • Reg08
    • Reg16
    • Reg32
    • Repeat
    • Return
    • Size
    • TestKeyword
    • Times
    • Variable
    • VariableAddress
    • VarKeyword
    • While
    • ZeroParamOp
  • XSharp.x86
    • Map
    • OpCode
    • Register
    • Register.Names
  • XSharp.x86.Assemblers
    • Assembler
    • NASM
  • XSharp.x86.Emitters
    • AllEmitters
    • Assignments
    • BitwiseEmitters
    • Branching
    • Comments
    • Emitters
    • IncrementDecrement
    • Math
    • Namespace
    • Ports
    • PushPop
    • ShiftRotate
    • Test
    • ZeroParamOps
  • XSharp.x86.Params
    • Address
    • i08u
    • i16u
    • i32u
    • Identifier
    • List
    • MemoryAddress
    • Num
    • Param
    • Reg
    • Reg08
    • Reg16
    • Reg32
    • RegisterAddress
    • Root
    • Size

Class TokenPatterns

This class is able to translate a single X# source code line into one or more target assembler source code and data lines. The class is a group of pattern each of which defines a transformation function from the X# syntax to the target assembler syntax.

Inheritance
System.Object
TokenPatterns
Namespace: XSharp
Assembly: XSharp.dll
Syntax
public class TokenPatterns : object

Constructors

| Improve this Doc View Source

TokenPatterns()

Declaration
public TokenPatterns()

Fields

| Improve this Doc View Source

EmitUserComments

Declaration
public bool EmitUserComments
Field Value
Type Description
System.Boolean
| Improve this Doc View Source

mBlocks

The set of blocks for the currently assembled function. Each time we begin assembling a new function this blocks collection is reset to an empty state.

Declaration
protected TokenPatterns.Blocks mBlocks
Field Value
Type Description
TokenPatterns.Blocks
| Improve this Doc View Source

mCompareOps

Declaration
protected string[] mCompareOps
Field Value
Type Description
System.String[]
| Improve this Doc View Source

mCompares

Declaration
protected List<string> mCompares
Field Value
Type Description
List<System.String>
| Improve this Doc View Source

mFuncExitFound

Declaration
protected bool mFuncExitFound
Field Value
Type Description
System.Boolean
| Improve this Doc View Source

mFuncName

Declaration
protected string mFuncName
Field Value
Type Description
System.String
| Improve this Doc View Source

mInIntHandler

Declaration
protected bool mInIntHandler
Field Value
Type Description
System.Boolean
| Improve this Doc View Source

mNamespace

Declaration
protected string mNamespace
Field Value
Type Description
System.String
| Improve this Doc View Source

mPatterns

Declaration
protected List<TokenPatterns.Pattern> mPatterns
Field Value
Type Description
List<TokenPatterns.Pattern>

Methods

| Improve this Doc View Source

AddPattern(String, TokenPatterns.CodeFunc)

Register a single pattern with its associated transformation handler.

Declaration
protected void AddPattern(string aPattern, TokenPatterns.CodeFunc aCode)
Parameters
Type Name Description
System.String aPattern

A single line of X# code that define the pattern optionally using pattern reserved syntax.

TokenPatterns.CodeFunc aCode

The associated code transformation handler.

| Improve this Doc View Source

AddPattern(String[], TokenPatterns.CodeFunc)

Register a collection of patterns that share a single transformation handler.

Declaration
protected void AddPattern(string[] aPatterns, TokenPatterns.CodeFunc aCode)
Parameters
Type Name Description
System.String[] aPatterns

A collection of X# lines of code. Each line of code define a pattern optionally using the pattern reserved syntax.

TokenPatterns.CodeFunc aCode

The code transformation handler that is common abmongst all the patterns from the collection.

| Improve this Doc View Source

AddPatterns()

Declaration
protected void AddPatterns()
| Improve this Doc View Source

Assemble(String)

Declaration
public void Assemble(string aLine)
Parameters
Type Name Description
System.String aLine
| Improve this Doc View Source

BlockLabel(String)

Builds a label having the given name at current function block level.

Declaration
protected string BlockLabel(string aLabel)
Parameters
Type Name Description
System.String aLabel

Local label name at function block level.

Returns
Type Description
System.String

The label name.

| Improve this Doc View Source

ConstLabel(Token)

Builds a label that is suitable to denote a constant which name is given by the token.

Declaration
protected string ConstLabel(Token aToken)
Parameters
Type Name Description
Token aToken
Returns
Type Description
System.String
| Improve this Doc View Source

EndFunc()

Terminate assembling current function. If a local to function exit label has not been explicitly defined a new one is automatically created. This is because some "return" keyword might have been used in function X# code. This keyword requires an exit label to be defined at function level. This method also automatically insert an IRET or RET instruction depending on whether the function is an interrupt handler or a standard function.

Declaration
protected void EndFunc()
| Improve this Doc View Source

FindMatch(TokenList)

Declaration
protected TokenPatterns.Pattern FindMatch(TokenList aTokens)
Parameters
Type Name Description
TokenList aTokens
Returns
Type Description
TokenPatterns.Pattern
| Improve this Doc View Source

FuncLabel(String)

Builds a label at function level having the given name.

Declaration
protected string FuncLabel(string aLabel)
Parameters
Type Name Description
System.String aLabel

Local label name at function level.

Returns
Type Description
System.String

The label name

| Improve this Doc View Source

GetJump(String, Boolean)

Declaration
protected ConditionalTestEnum GetJump(string aComparison, bool aInvert = false)
Parameters
Type Name Description
System.String aComparison
System.Boolean aInvert
Returns
Type Description
ConditionalTestEnum
| Improve this Doc View Source

GetLabel(Token)

Build a label name for the given token. This method enforce the rule for . and .. prefixes and build the label at appropriate level.

Declaration
protected string GetLabel(Token aToken)
Parameters
Type Name Description
Token aToken
Returns
Type Description
System.String
| Improve this Doc View Source

GetNamespace()

Declaration
protected string GetNamespace()
Returns
Type Description
System.String
| Improve this Doc View Source

GetPatternCode(TokenList)

Declaration
public bool GetPatternCode(TokenList aTokens)
Parameters
Type Name Description
TokenList aTokens
Returns
Type Description
System.Boolean
| Improve this Doc View Source

GetRef(List<Token>, ref Int32, Boolean)

Declaration
protected string GetRef(List<Token> aTokens, ref int rIdx, bool onlySingleTokenRefs = false)
Parameters
Type Name Description
List<Token> aTokens
System.Int32 rIdx
System.Boolean onlySingleTokenRefs
Returns
Type Description
System.String
| Improve this Doc View Source

GetSimpleRef(Token)

Declaration
protected string GetSimpleRef(Token aToken)
Parameters
Type Name Description
Token aToken
Returns
Type Description
System.String
| Improve this Doc View Source

GroupLabel(String)

Builds a label at namespace level having the given name.

Declaration
protected string GroupLabel(string aLabel)
Parameters
Type Name Description
System.String aLabel

Local label name at namespace level.

Returns
Type Description
System.String

The label name

| Improve this Doc View Source

HandleIf(TokenList, String)

Declaration
protected void HandleIf(TokenList aTokens, string xComparison)
Parameters
Type Name Description
TokenList aTokens
System.String xComparison
| Improve this Doc View Source

StartFunc(String)

Start a new function having the given name. The current blocks collection is reset to an empty state and the function name is saved for later reuse in local to function labels' name construction.

Declaration
protected void StartFunc(string aName)
Parameters
Type Name Description
System.String aName

Function name.

  • Improve this Doc
  • View Source
☀
☾
In This Article
Back to top
☀
☾