@@ -30,6 +30,8 @@ type ErrorHandler func(pos token.Position, msg string)
3030type Scanner struct {
3131 // 查询特定平台的指令和寄存器
3232 lookupRegisterOrAs func (ident string ) token.Token
33+ // 是否为ARM64风格的注释
34+ useArmStyleComment bool
3335
3436 // immutable state
3537 file * token.File // source file handle
@@ -52,9 +54,10 @@ type Scanner struct {
5254
5355const bom = 0xFEFF // byte order mark, only permitted as very first character
5456
55- func NewScanner (lookupRegisterOrAs func (ident string ) token.Token ) * Scanner {
57+ func NewScanner (lookupRegisterOrAs func (ident string ) token.Token , useArmStyleComment bool ) * Scanner {
5658 s := & Scanner {}
5759 s .lookupRegisterOrAs = lookupRegisterOrAs
60+ s .useArmStyleComment = useArmStyleComment
5861 return s
5962}
6063
@@ -747,16 +750,43 @@ scanAgain:
747750 insertSemi = true
748751 tok = token .RBRACK
749752 case '#' :
750- // #-style comment
751- if s .insertSemi && s .findLineEnd ('#' ) {
753+ if s .useArmStyleComment {
754+ // ARM语法中 #123 为立即数
755+ insertSemi = true
756+ tok , lit = s .scanNumber ()
757+ } else {
758+ // #-style comment
759+ if s .insertSemi && s .findLineEnd ('#' ) {
760+ // reset position to the beginning of the comment
761+ s .ch = '#'
762+ s .offset = s .file .Offset (pos )
763+ s .rdOffset = s .offset + 1
764+ s .insertSemi = false // newline consumed
765+ return pos , token .SEMICOLON , "\n "
766+ }
767+ comment := s .scanComment ('#' )
768+ if s .mode & ScanComments == 0 {
769+ // skip comment
770+ s .insertSemi = false // newline consumed
771+ goto scanAgain
772+ }
773+ tok = token .COMMENT
774+ lit = comment
775+ }
776+
777+ case '/' :
778+ // comment
779+ // 对于 ARM64, # 被用于立即数前缀, 因此需要提供不同的注释语法
780+ // 对于格式化时, 也需要做特别处理
781+ if s .insertSemi && s .findLineEnd ('/' ) {
752782 // reset position to the beginning of the comment
753- s .ch = '# '
783+ s .ch = '/ '
754784 s .offset = s .file .Offset (pos )
755785 s .rdOffset = s .offset + 1
756786 s .insertSemi = false // newline consumed
757787 return pos , token .SEMICOLON , "\n "
758788 }
759- comment := s .scanComment ('# ' )
789+ comment := s .scanComment ('/ ' )
760790 if s .mode & ScanComments == 0 {
761791 // skip comment
762792 s .insertSemi = false // newline consumed
0 commit comments