ReactOS 0.4.17-dev-243-g1369312
asmpp.cpp File Reference
#include "tokenizer.hpp"
#include <cstdlib>
#include <cstdio>
#include <sstream>
#include <ctime>
Include dependency graph for asmpp.cpp:

Go to the source code of this file.

Classes

struct  IDENTIFIER
 

Macros

#define PROFILING_ENABLED   0
 
#define FOLLOWED_BY(x)   x
 
#define ANY_CHAR   R"((?:.|\n))"
 
#define WHITESPACE   R"((?:[ \t]++))"
 
#define NEWLINE   R"([\n])"
 
#define WS_OR_NL   R"((?:)" WHITESPACE "|" NEWLINE R"()+)"
 
#define SEPARATOR   R"([\s,\=\+\-\*\/\:\~\[\]])"
 
#define INSTRUCTION
 

Enumerations

enum  TOKEN_TYPE {
  Invalid = -1 , Eof , WhiteSpace , NewLine ,
  Comment , DecNumber , HexNumber , String ,
  BraceOpen , BraceClose , MemRefStart , MemRefEnd ,
  Colon , Operator , StringDef , KW_include ,
  KW_const , KW_code , KW_endprolog , KW_ALIGN ,
  KW_EXTERN , KW_PUBLIC , KW_ENDM , KW_END ,
  KW_if , KW_ifdef , KW_ifndef , KW_else ,
  KW_endif , KW_allocstack , KW_savereg , KW_savexmm128 ,
  KW_DB , KW_DW , KW_DD , KW_DQ ,
  KW_EQU , KW_TEXTEQU , KW_MACRO , KW_PROC ,
  KW_FRAME , KW_ENDP , KW_RECORD , KW_MASK ,
  KW_ERRDEF , Filename , Instruction , Reg8 ,
  Reg16 , Reg32 , Reg64 , RegXmm ,
  BYTE_PTR , WORD_PTR , DWORD_PTR , QWORD_PTR ,
  XMMWORD_PTR , LabelName , Identifier
}
 
enum class  IDTYPE {
  Memory , Register , Label , Constant ,
  Macro , Instruction , String , Unknown
}
 

Functions

int fake_printf (const char *format,...)
 
static void add_identifier (Token &tok, IDTYPE type)
 
void add_mem_id (Token &tok)
 
bool is_mem_id (Token &tok)
 
bool iequals (const string &a, const string &b)
 
const charget_expression_operator (const string &op)
 
Token get_expected_token (Token &&tok, TOKEN_TYPE type)
 
Token get_ws (Token &&tok)
 
Token get_ws_or_nl (Token &&tok)
 
bool is_string_in_list (vector< string > list, string str)
 
size_t translate_token (TokenList &tokens, size_t index, const vector< string > &macro_params)
 
size_t complete_line (TokenList &tokens, size_t index, const vector< string > &macro_params)
 
size_t translate_expression (TokenList &tokens, size_t index, const vector< string > &macro_params)
 
size_t translate_mem_ref (TokenList &tokens, size_t index, const vector< string > &macro_params)
 
static bool is_number_token (const Token &tok)
 
static size_t skip_whitespace (TokenList &tokens, size_t index)
 
static size_t translate_rip_relative_offset (TokenList &tokens, size_t index, const vector< string > &macro_params)
 
size_t translate_instruction_param (TokenList &tokens, size_t index, const vector< string > &macro_params)
 
static bool is_jmp_or_call (const Token &tok)
 
size_t translate_instruction (TokenList &tokens, size_t index, const vector< string > &macro_params)
 
size_t translate_item (TokenList &tokens, size_t index, const vector< string > &macro_params)
 
size_t translate_list (TokenList &tokens, size_t index, const vector< string > &macro_params)
 
size_t translate_data_def (TokenList &tokens, size_t index, const vector< string > &macro_params)
 
size_t translate_construct_one_param (string translated, TokenList &tokens, size_t index, const vector< string > &macro_params)
 
size_t translate_record (TokenList &tokens, size_t index, const vector< string > &macro_params)
 
static bool find_proc_frame (TokenList &tokens, size_t index, size_t &frameEndIndex)
 
size_t translate_identifier_construct (TokenList &tokens, size_t index, const vector< string > &macro_params)
 
size_t translate_construct (TokenList &tokens, size_t index, const vector< string > &macro_params)
 
size_t translate_macro (TokenList &tokens, size_t index)
 
void translate (TokenList &tokens)
 
int main (int argc, char *argv[])
 

Variables

time_t search_time
 
vector< TOKEN_DEFg_TokenList
 
unsigned int g_label_number = 0
 
bool g_processing_jmp = false
 
vector< boolg_proc_frame_stack
 
vector< IDENTIFIERg_identifiers
 
static bool g_intel_syntax_emitted = false
 

Macro Definition Documentation

◆ ANY_CHAR

#define ANY_CHAR   R"((?:.|\n))"

Definition at line 109 of file asmpp.cpp.

◆ FOLLOWED_BY

#define FOLLOWED_BY (   x)    x

Definition at line 107 of file asmpp.cpp.

◆ INSTRUCTION

#define INSTRUCTION

Definition at line 115 of file asmpp.cpp.

◆ NEWLINE

#define NEWLINE   R"([\n])"

Definition at line 111 of file asmpp.cpp.

◆ PROFILING_ENABLED

#define PROFILING_ENABLED   0

Definition at line 22 of file asmpp.cpp.

◆ SEPARATOR

#define SEPARATOR   R"([\s,\=\+\-\*\/\:\~\[\]])"

Definition at line 113 of file asmpp.cpp.

◆ WHITESPACE

#define WHITESPACE   R"((?:[ \t]++))"

Definition at line 110 of file asmpp.cpp.

◆ WS_OR_NL

#define WS_OR_NL   R"((?:)" WHITESPACE "|" NEWLINE R"()+)"

Definition at line 112 of file asmpp.cpp.

Enumeration Type Documentation

◆ IDTYPE

enum class IDTYPE
strong
Enumerator
Memory 
Register 
Label 
Constant 
Macro 
Instruction 
String 
Unknown 

Definition at line 303 of file asmpp.cpp.

304{
305 Memory,
306 Register,
307 Label,
308 Constant,
309 Macro,
311 String,
312 Unknown
313};
@ Instruction
Definition: asmpp.cpp:82
@ String
Definition: asmpp.cpp:37

◆ TOKEN_TYPE

Enumerator
Invalid 
Eof 
WhiteSpace 
NewLine 
Comment 
DecNumber 
HexNumber 
String 
BraceOpen 
BraceClose 
MemRefStart 
MemRefEnd 
Colon 
Operator 
StringDef 
KW_include 
KW_const 
KW_code 
KW_endprolog 
KW_ALIGN 
KW_EXTERN 
KW_PUBLIC 
KW_ENDM 
KW_END 
KW_if 
KW_ifdef 
KW_ifndef 
KW_else 
KW_endif 
KW_allocstack 
KW_savereg 
KW_savexmm128 
KW_DB 
KW_DW 
KW_DD 
KW_DQ 
KW_EQU 
KW_TEXTEQU 
KW_MACRO 
KW_PROC 
KW_FRAME 
KW_ENDP 
KW_RECORD 
KW_MASK 
KW_ERRDEF 
Filename 
Instruction 
Reg8 
Reg16 
Reg32 
Reg64 
RegXmm 
BYTE_PTR 
WORD_PTR 
DWORD_PTR 
QWORD_PTR 
XMMWORD_PTR 
LabelName 
Identifier 

Definition at line 28 of file asmpp.cpp.

29{
30 Invalid = -1,
31 Eof,
33 NewLine,
34 Comment,
37 String,
38
43 Colon,
46
49 KW_code,
54 KW_ENDM,
55 KW_END,
56 KW_if,
59 KW_else,
61
65
66 KW_DB,
67 KW_DW,
68 KW_DD,
69 KW_DQ,
70 KW_EQU,
73 KW_PROC,
75 KW_ENDP,
77
78 KW_MASK,
80
83 Reg8,
84 Reg16,
85 Reg32,
86 Reg64,
87 RegXmm,
93
96};
@ KW_allocstack
Definition: asmpp.cpp:62
@ Reg32
Definition: asmpp.cpp:85
@ KW_FRAME
Definition: asmpp.cpp:74
@ KW_savereg
Definition: asmpp.cpp:63
@ KW_EXTERN
Definition: asmpp.cpp:52
@ KW_PROC
Definition: asmpp.cpp:73
@ StringDef
Definition: asmpp.cpp:45
@ MemRefEnd
Definition: asmpp.cpp:42
@ KW_ENDM
Definition: asmpp.cpp:54
@ BraceClose
Definition: asmpp.cpp:40
@ Comment
Definition: asmpp.cpp:34
@ KW_else
Definition: asmpp.cpp:59
@ KW_END
Definition: asmpp.cpp:55
@ KW_code
Definition: asmpp.cpp:49
@ KW_endprolog
Definition: asmpp.cpp:50
@ DecNumber
Definition: asmpp.cpp:35
@ Identifier
Definition: asmpp.cpp:95
@ KW_DW
Definition: asmpp.cpp:67
@ BraceOpen
Definition: asmpp.cpp:39
@ KW_RECORD
Definition: asmpp.cpp:76
@ Colon
Definition: asmpp.cpp:43
@ KW_ENDP
Definition: asmpp.cpp:75
@ Filename
Definition: asmpp.cpp:81
@ KW_EQU
Definition: asmpp.cpp:70
@ BYTE_PTR
Definition: asmpp.cpp:88
@ RegXmm
Definition: asmpp.cpp:87
@ WhiteSpace
Definition: asmpp.cpp:32
@ KW_DB
Definition: asmpp.cpp:66
@ MemRefStart
Definition: asmpp.cpp:41
@ QWORD_PTR
Definition: asmpp.cpp:91
@ KW_include
Definition: asmpp.cpp:47
@ KW_MACRO
Definition: asmpp.cpp:72
@ HexNumber
Definition: asmpp.cpp:36
@ KW_DD
Definition: asmpp.cpp:68
@ LabelName
Definition: asmpp.cpp:94
@ KW_const
Definition: asmpp.cpp:48
@ KW_TEXTEQU
Definition: asmpp.cpp:71
@ Reg8
Definition: asmpp.cpp:83
@ NewLine
Definition: asmpp.cpp:33
@ KW_ifndef
Definition: asmpp.cpp:58
@ KW_ifdef
Definition: asmpp.cpp:57
@ XMMWORD_PTR
Definition: asmpp.cpp:92
@ KW_PUBLIC
Definition: asmpp.cpp:53
@ Operator
Definition: asmpp.cpp:44
@ KW_DQ
Definition: asmpp.cpp:69
@ Eof
Definition: asmpp.cpp:31
@ KW_ALIGN
Definition: asmpp.cpp:51
@ KW_savexmm128
Definition: asmpp.cpp:64
@ DWORD_PTR
Definition: asmpp.cpp:90
@ KW_endif
Definition: asmpp.cpp:60
@ KW_MASK
Definition: asmpp.cpp:78
@ KW_if
Definition: asmpp.cpp:56
@ WORD_PTR
Definition: asmpp.cpp:89
@ Invalid
Definition: asmpp.cpp:30
@ Reg16
Definition: asmpp.cpp:84
@ Reg64
Definition: asmpp.cpp:86
@ KW_ERRDEF
Definition: asmpp.cpp:79

Function Documentation

◆ add_identifier()

static void add_identifier ( Token tok,
IDTYPE  type 
)
static

Definition at line 325 of file asmpp.cpp.

326{
327 g_identifiers.push_back(IDENTIFIER{ tok.str(), type });
328 //fprintf(stderr, "Added id: '%s'\n", tok.str().c_str());
329}
vector< IDENTIFIER > g_identifiers
Definition: asmpp.cpp:321
std::string str() const
Definition: tokenizer.hpp:50
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545

Referenced by add_mem_id(), and translate_identifier_construct().

◆ add_mem_id()

void add_mem_id ( Token tok)

Definition at line 332 of file asmpp.cpp.

333{
335}
static void add_identifier(Token &tok, IDTYPE type)
Definition: asmpp.cpp:325

Referenced by translate_construct(), and translate_identifier_construct().

◆ complete_line()

size_t complete_line ( TokenList tokens,
size_t  index,
const vector< string > &  macro_params 
)

Definition at line 492 of file asmpp.cpp.

493{
494 while (index < tokens.size())
495 {
496 Token tok = tokens[index];
497 index = translate_token(tokens, index, macro_params);
498 if ((tok.type() == TOKEN_TYPE::NewLine) ||
499 (tok.type() == TOKEN_TYPE::Comment))
500 {
501 break;
502 }
503 }
504
505 return index;
506}
size_t translate_token(TokenList &tokens, size_t index, const vector< string > &macro_params)
Definition: asmpp.cpp:432
#define index(s, c)
Definition: various.h:29
size_t size() const
Definition: tokenizer.hpp:239
int type() const
Definition: tokenizer.hpp:55
GLuint index
Definition: glext.h:6031

Referenced by translate_construct().

◆ fake_printf()

int fake_printf ( const char format,
  ... 
)

Definition at line 98 of file asmpp.cpp.

99{
100 return 0;
101}

◆ find_proc_frame()

static bool find_proc_frame ( TokenList tokens,
size_t  index,
size_t frameEndIndex 
)
static

Definition at line 1014 of file asmpp.cpp.

1015{
1016 while (index < tokens.size())
1017 {
1018 Token tok = tokens[index];
1019 if ((tok.type() == TOKEN_TYPE::NewLine) ||
1020 (tok.type() == TOKEN_TYPE::Comment))
1021 {
1022 return false;
1023 }
1024
1025 if (tok.type() == TOKEN_TYPE::KW_FRAME)
1026 {
1027 frameEndIndex = index + 1;
1028 return true;
1029 }
1030
1031 index++;
1032 }
1033
1034 return false;
1035}

Referenced by translate_identifier_construct().

◆ get_expected_token()

Token get_expected_token ( Token &&  tok,
TOKEN_TYPE  type 
)

Definition at line 385 of file asmpp.cpp.

386{
387 if (tok.type() != type)
388 {
389 throw "Not white space after identifier!\n";
390 }
391
392 return tok;
393}

Referenced by translate_construct(), translate_identifier_construct(), and translate_record().

◆ get_expression_operator()

const char * get_expression_operator ( const string op)

Definition at line 364 of file asmpp.cpp.

365{
366 const struct
367 {
368 const char* masm;
369 const char* gas;
370 } operators[] = {
371 {"and", "&"}, {"or", "|"}, {"shl", "<<"}, {"shr", ">>"}, {"not", "~"},
372 {"eq", "=="}, {"ne", "!="}, {"lt", "<"}, {"le", "<="}, {"gt", ">"}, {"ge", ">="},
373 };
374
375 for (const auto& entry : operators)
376 {
377 if (iequals(op, entry.masm))
378 return entry.gas;
379 }
380
381 return nullptr;
382}
bool iequals(const string &a, const string &b)
Definition: asmpp.cpp:352
UINT op
Definition: effect.c:236
uint32_t entry
Definition: isohybrid.c:63

Referenced by translate_expression().

◆ get_ws()

Token get_ws ( Token &&  tok)

Definition at line 395 of file asmpp.cpp.

396{
397 int type = tok.type();
398 if (type != TOKEN_TYPE::WhiteSpace)
399 {
400 throw "Not white space after identifier!\n";
401 }
402
403 return tok;
404}

Referenced by translate_construct_one_param(), translate_data_def(), and translate_identifier_construct().

◆ get_ws_or_nl()

Token get_ws_or_nl ( Token &&  tok)

Definition at line 406 of file asmpp.cpp.

407{
408 int type = tok.type();
409 if ((type != TOKEN_TYPE::WhiteSpace) &&
410 (type != TOKEN_TYPE::NewLine))
411 {
412 throw "Not white space after identifier!\n";
413 }
414
415 return tok;
416}

Referenced by translate_construct().

◆ iequals()

bool iequals ( const string a,
const string b 
)

Definition at line 352 of file asmpp.cpp.

353{
354 size_t sz = a.size();
355 if (b.size() != sz)
356 return false;
357 for (unsigned int i = 0; i < sz; ++i)
358 if (tolower(a[i]) != tolower(b[i]))
359 return false;
360 return true;
361}
int CDECL tolower(int c)
Definition: ctype.c:572
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by get_expression_operator(), and is_jmp_or_call().

◆ is_jmp_or_call()

static bool is_jmp_or_call ( const Token tok)
static

Definition at line 714 of file asmpp.cpp.

715{
716 const char* inst_list[] = {
717 "jmp", "call", "ja", "jae", "jb", "jbe", "jc", "jcxz", "je", "jecxz", "jg", "jge",
718 "jl", "jle", "jna", "jnae", "jnb", "jnbe", "jnc", "jne", "jng", "jnge", "jnl", "jnle",
719 "jno", "jnp", "jns", "jnz", "jo", "jp", "jpe", "jpo", "jrcxz", "js", "jz", "loop", "loope",
720 "loopne", "loopnz", "loopz"
721 };
722
723 for (const char* inst : inst_list)
724 {
725 if (iequals(tok.str(), inst))
726 {
727 return true;
728 }
729 }
730
731 return false;
732}

Referenced by translate_instruction().

◆ is_mem_id()

bool is_mem_id ( Token tok)

Definition at line 338 of file asmpp.cpp.

339{
340 for (IDENTIFIER& identifier : g_identifiers)
341 {
342 if (identifier.Name == tok.str())
343 {
344 return identifier.Type == IDTYPE::Memory;
345 }
346 }
347
348 return true;
349}

Referenced by translate_instruction_param().

◆ is_number_token()

static bool is_number_token ( const Token tok)
static

Definition at line 611 of file asmpp.cpp.

612{
613 return ((tok.type() == TOKEN_TYPE::DecNumber) ||
614 (tok.type() == TOKEN_TYPE::HexNumber));
615}

Referenced by translate_rip_relative_offset().

◆ is_string_in_list()

bool is_string_in_list ( vector< string list,
string  str 
)

Definition at line 418 of file asmpp.cpp.

419{
420 for (string &s : list)
421 {
422 if (s == str)
423 {
424 return true;
425 }
426 }
427
428 return false;
429}
Definition: list.h:37
GLdouble s
Definition: gl.h:2039
const WCHAR * str

Referenced by translate_instruction_param(), and translate_token().

◆ main()

int main ( int  argc,
char argv[] 
)

hosttype.c Copyright (C) 2002 by Brian Palmer brian.nosp@m.p@sg.nosp@m.inet..nosp@m.com

Definition at line 1355 of file asmpp.cpp.

1356{
1357 if (argc < 2)
1358 {
1359 fprintf(stderr, "Invalid parameter!\n");
1360 return -1;
1361 }
1362
1363#if PROFILING_ENABLED
1364 time_t start_time = time(NULL);
1365#endif
1366
1367 try
1368 {
1369 // Open and read the input file
1370 string filename(argv[1]);
1373 buffer << file.rdbuf();
1374 string text = buffer.str();
1375
1376 // Create the tokenizer
1377 Tokenizer tokenizer(g_TokenList);
1378
1379 // Get a token list
1380 TokenList toklist(tokenizer, text);
1381
1382 // Now translate the tokens
1383 translate(toklist);
1384 }
1385 catch (const char* message)
1386 {
1387 fprintf(stderr, "Exception caught: '%s'\n", message);
1388 return -2;
1389 }
1390
1391#if PROFILING_ENABLED
1392 time_t total_time = time(NULL) + 1 - start_time;
1393 fprintf(stderr, "total_time = %llu\n", total_time);
1394 fprintf(stderr, "search_time = %llu\n", search_time);
1395 fprintf(stderr, "search: %llu %%\n", search_time * 100 / total_time);
1396#endif
1397
1398 return 0;
1399}
vector< TOKEN_DEF > g_TokenList
Definition: asmpp.cpp:225
void translate(TokenList &tokens)
Definition: asmpp.cpp:1333
time_t search_time
Definition: asmpp.cpp:26
#define NULL
Definition: types.h:112
MonoAssembly int argc
Definition: metahost.c:107
const WCHAR * text
Definition: package.c:1794
int WINAPIV fprintf(FILE *file, const char *format,...)
Definition: file.c:5549
__time32_t time_t
Definition: corecrt.h:228
#define stderr
GLuint buffer
Definition: glext.h:5915
const char * filename
Definition: ioapi.h:137
__u16 time
Definition: mkdosfs.c:8
#define argv
Definition: mplay32.c:18
Definition: fci.c:127
Definition: tftpd.h:60

◆ skip_whitespace()

static size_t skip_whitespace ( TokenList tokens,
size_t  index 
)
static

Definition at line 619 of file asmpp.cpp.

620{
621 if ((index < tokens.size()) &&
622 (tokens[index].type() == TOKEN_TYPE::WhiteSpace))
623 {
624 index++;
625 }
626
627 return index;
628}

◆ translate()

void translate ( TokenList tokens)

Definition at line 1333 of file asmpp.cpp.

1334{
1335 size_t index = 0;
1336 size_t size = tokens.size();
1337 vector<string> empty_macro_params;
1338
1339 while (index < size)
1340 {
1341 // Macros are special
1342 if ((tokens[index].type() == TOKEN_TYPE::Identifier) &&
1343 (tokens[index + 1].type() == TOKEN_TYPE::WhiteSpace) &&
1344 (tokens[index + 2].type() == TOKEN_TYPE::KW_MACRO))
1345 {
1346 index = translate_macro(tokens, index);
1347 }
1348 else
1349 {
1350 index = translate_construct(tokens, index, empty_macro_params);
1351 }
1352 }
1353}
size_t translate_construct(TokenList &tokens, size_t index, const vector< string > &macro_params)
Definition: asmpp.cpp:1149
size_t translate_macro(TokenList &tokens, size_t index)
Definition: asmpp.cpp:1280
GLsizeiptr size
Definition: glext.h:5919

Referenced by main().

◆ translate_construct()

size_t translate_construct ( TokenList tokens,
size_t  index,
const vector< string > &  macro_params 
)

Definition at line 1149 of file asmpp.cpp.

1150{
1151 Token tok = tokens[index];
1152
1153 switch (tok.type())
1154 {
1155 case TOKEN_TYPE::WhiteSpace:
1156 case TOKEN_TYPE::NewLine:
1157 case TOKEN_TYPE::Comment:
1158 return translate_token(tokens, index, macro_params);
1159
1160 case TOKEN_TYPE::Identifier:
1161 return translate_identifier_construct(tokens, index, macro_params);
1162
1163 case TOKEN_TYPE::KW_ALIGN:
1164 index = translate_construct_one_param(".align", tokens, index, macro_params);
1165 break;
1166
1167 case TOKEN_TYPE::KW_allocstack:
1168 index = translate_construct_one_param(".seh_stackalloc", tokens, index, macro_params);
1169 break;
1170
1171 case TOKEN_TYPE::KW_code:
1172 {
1173 printf(".text\n");
1174#ifdef TARGET_amd64
1175 printf(".code64\n");
1176#else
1177 printf(".code32\n");
1178#endif
1180 {
1181 printf(".intel_syntax noprefix\n");
1183 }
1184 index++;
1185 break;
1186 }
1187
1188 case TOKEN_TYPE::KW_const:
1189 printf(".section .rdata");
1190 index++;
1191 break;
1192
1193 case TOKEN_TYPE::KW_DB:
1194 case TOKEN_TYPE::KW_DW:
1195 case TOKEN_TYPE::KW_DD:
1196 case TOKEN_TYPE::KW_DQ:
1197 return translate_data_def(tokens, index, macro_params);
1198
1199 case TOKEN_TYPE::KW_END:
1200 printf("// END\n");
1201 return tokens.size();
1202
1203 case TOKEN_TYPE::KW_endprolog:
1204 printf(".seh_endprologue");
1205 index++;
1206 break;
1207
1208 case TOKEN_TYPE::KW_EXTERN:
1209 {
1210 Token tok1 = get_ws_or_nl(tokens[index + 1]);
1211 Token tok2 = get_expected_token(tokens[index + 2], TOKEN_TYPE::Identifier);
1212 add_mem_id(tok2);
1213 printf("//");
1214 return complete_line(tokens, index, macro_params);
1215 }
1216
1217 case TOKEN_TYPE::KW_if:
1218 printf(".");
1219 return translate_expression(tokens, index, macro_params);
1220
1221 case TOKEN_TYPE::KW_ifdef:
1222 case TOKEN_TYPE::KW_ifndef:
1223 case TOKEN_TYPE::KW_else:
1224 case TOKEN_TYPE::KW_endif:
1225 printf(".");
1226 return complete_line(tokens, index, macro_params);
1227
1228 case TOKEN_TYPE::KW_include:
1229 {
1230 // The next token should be white space
1231 Token tok1 = get_ws_or_nl(tokens[index + 1]);
1232 Token tok2 = get_expected_token(tokens[index + 2], TOKEN_TYPE::Filename);
1233 printf("#include \"%s.h\"", tok2.str().c_str());
1234 index += 3;
1235 break;
1236 }
1237
1238 case TOKEN_TYPE::KW_PUBLIC:
1239 index = translate_construct_one_param(".global", tokens, index, macro_params);
1240 break;
1241
1242 case TOKEN_TYPE::KW_savereg:
1243 printf(".seh_savereg");
1244 return complete_line(tokens, index + 1, macro_params);
1245
1246 case TOKEN_TYPE::KW_savexmm128:
1247 printf(".seh_savexmm");
1248 return complete_line(tokens, index + 1, macro_params);
1249
1250 case TOKEN_TYPE::Instruction:
1251 index = translate_instruction(tokens, index, macro_params);
1252 break;
1253
1254 case TOKEN_TYPE::KW_ERRDEF:
1255 printf("//");
1256 return complete_line(tokens, index, macro_params);
1257
1258 default:
1259 throw "failed to translate construct";
1260 }
1261
1262 // Skip optional white-space
1263 if (tokens[index].type() == TOKEN_TYPE::WhiteSpace)
1264 {
1265 index++;
1266 }
1267
1268 // Line should end here!
1269 Token end = tokens[index];
1270 if ((end.type() != TOKEN_TYPE::Comment) &&
1271 (end.type() != TOKEN_TYPE::NewLine))
1272 {
1273 throw "unexpected tokens";
1274 }
1275
1276 return index;
1277}
void add_mem_id(Token &tok)
Definition: asmpp.cpp:332
size_t translate_data_def(TokenList &tokens, size_t index, const vector< string > &macro_params)
Definition: asmpp.cpp:832
Token get_ws_or_nl(Token &&tok)
Definition: asmpp.cpp:406
size_t complete_line(TokenList &tokens, size_t index, const vector< string > &macro_params)
Definition: asmpp.cpp:492
static bool g_intel_syntax_emitted
Definition: asmpp.cpp:1146
size_t translate_expression(TokenList &tokens, size_t index, const vector< string > &macro_params)
Definition: asmpp.cpp:509
Token get_expected_token(Token &&tok, TOKEN_TYPE type)
Definition: asmpp.cpp:385
size_t translate_identifier_construct(TokenList &tokens, size_t index, const vector< string > &macro_params)
Definition: asmpp.cpp:1038
size_t translate_construct_one_param(string translated, TokenList &tokens, size_t index, const vector< string > &macro_params)
Definition: asmpp.cpp:923
size_t translate_instruction(TokenList &tokens, size_t index, const vector< string > &macro_params)
Definition: asmpp.cpp:734
#define printf
Definition: freeldr.h:103
GLuint GLuint end
Definition: gl.h:1545

Referenced by translate(), and translate_macro().

◆ translate_construct_one_param()

size_t translate_construct_one_param ( string  translated,
TokenList tokens,
size_t  index,
const vector< string > &  macro_params 
)

Definition at line 923 of file asmpp.cpp.

924{
925 // The next token should be white space
926 Token tok1 = get_ws(tokens[index + 1]);
927
928 printf("%s%s", translated.c_str(), tok1.str().c_str());
929 return translate_expression(tokens, index + 2, macro_params);
930}
Token get_ws(Token &&tok)
Definition: asmpp.cpp:395
const _CharT * c_str() const
Definition: _string.h:949

Referenced by translate_construct().

◆ translate_data_def()

size_t translate_data_def ( TokenList tokens,
size_t  index,
const vector< string > &  macro_params 
)

Definition at line 832 of file asmpp.cpp.

833{
834 Token tok = tokens[index];
835 Token tok1 = get_ws(tokens[index + 1]);
836 string directive, need, have ="";
837
838 switch (tok.type())
839 {
840 case TOKEN_TYPE::KW_DB:
841 directive = ".byte";
842 break;
843
844 case TOKEN_TYPE::KW_DW:
845 directive = ".short";
846 break;
847
848 case TOKEN_TYPE::KW_DD:
849 directive = ".long";
850 break;
851
852 case TOKEN_TYPE::KW_DQ:
853 directive = ".quad";
854 break;
855 }
856
857 index += 2;
858
859 while (index < tokens.size())
860 {
861 // Check if we need '.ascii' for ASCII strings
862 if (tokens[index].str()[0] == '\"')
863 {
864 need = ".ascii";
865 }
866 else
867 {
868 need = directive;
869 }
870
871 // Output the directive we need (or a comma)
872 if (have == "")
873 {
874 printf("%s ", need.c_str());
875 }
876 else if (have != need)
877 {
878 printf("\n%s ", need.c_str());
879 }
880 else
881 {
882 printf(", ");
883 }
884
885 have = need;
886
887 // The item itself
888 index = translate_item(tokens, index, macro_params);
889
890 // Optional white space
891 if (tokens[index].type() == TOKEN_TYPE::WhiteSpace)
892 {
893 index = translate_token(tokens, index, macro_params);
894 }
895
896 // End of list?
897 if ((tokens[index].type() == TOKEN_TYPE::Comment) ||
898 (tokens[index].type() == TOKEN_TYPE::NewLine))
899 {
900 return index;
901 }
902
903 // We expect a comma here
904 if ((tokens[index].type() != TOKEN_TYPE::Operator) ||
905 (tokens[index].str() != ","))
906 {
907 throw "Unexpected end of list";
908 }
909
910 // Skip comma and optional white-space
911 index++;
912 if (tokens[index].type() == TOKEN_TYPE::WhiteSpace)
913 {
914 index++;
915 }
916 }
917
918 throw "Failed to translate list";
919 return -1;
920}
size_t translate_item(TokenList &tokens, size_t index, const vector< string > &macro_params)
Definition: asmpp.cpp:778
static UINT PSTR DWORD UINT * need
Definition: parser.c:36

Referenced by translate_construct(), and translate_identifier_construct().

◆ translate_expression()

size_t translate_expression ( TokenList tokens,
size_t  index,
const vector< string > &  macro_params 
)

Definition at line 509 of file asmpp.cpp.

510{
511 while (index < tokens.size())
512 {
513 Token tok = tokens[index];
514 switch (tok.type())
515 {
516 case TOKEN_TYPE::NewLine:
517 case TOKEN_TYPE::Comment:
518 return index;
519
520 case TOKEN_TYPE::KW_MASK:
521 printf("MASK_");
522 index += 2;
523 break;
524
525 case TOKEN_TYPE::Instruction:
526 {
527 const char* op = get_expression_operator(tok.str());
528 if (!op)
529 {
530 throw "Invalid expression";
531 }
532 printf("%s", op);
533 index += 1;
534 break;
535 }
536
537 case TOKEN_TYPE::Operator:
538 if (tok.str() == ",")
539 {
540 return index;
541 }
542 index = translate_token(tokens, index, macro_params);
543 break;
544
545 case TOKEN_TYPE::Identifier:
546 {
547 const char* op = get_expression_operator(tok.str());
548 if (op)
549 {
550 printf("%s", op);
551 index += 1;
552 }
553 else
554 {
555 index = translate_token(tokens, index, macro_params);
556 }
557 break;
558 }
559
560 case TOKEN_TYPE::WhiteSpace:
561 case TOKEN_TYPE::BraceOpen:
562 case TOKEN_TYPE::BraceClose:
563 case TOKEN_TYPE::DecNumber:
564 case TOKEN_TYPE::HexNumber:
565 index = translate_token(tokens, index, macro_params);
566 break;
567
568 default:
569 index = translate_token(tokens, index, macro_params);
570 }
571 }
572
573 return index;
574}
const char * get_expression_operator(const string &op)
Definition: asmpp.cpp:364

Referenced by translate_construct(), translate_construct_one_param(), translate_identifier_construct(), and translate_instruction_param().

◆ translate_identifier_construct()

size_t translate_identifier_construct ( TokenList tokens,
size_t  index,
const vector< string > &  macro_params 
)

Definition at line 1038 of file asmpp.cpp.

1039{
1040 Token tok = tokens[index];
1041 Token tok1 = tokens[index + 1];
1042
1043 if (tok1.type() == TOKEN_TYPE::Colon)
1044 {
1045 if (tok.str() == "@@")
1046 {
1048 printf("%u:", g_label_number);
1049 }
1050 else
1051 {
1052 printf("%s:", tok.str().c_str());
1053 }
1055 return index + 2;
1056 }
1057
1058 Token tok2 = tokens[index + 2];
1059
1060 switch (tok2.type())
1061 {
1062 case TOKEN_TYPE::KW_MACRO:
1063 throw "Cannot have a nested macro!";
1064
1065 case TOKEN_TYPE::KW_DB:
1066 case TOKEN_TYPE::KW_DW:
1067 case TOKEN_TYPE::KW_DD:
1068 case TOKEN_TYPE::KW_DQ:
1069 printf("%s:%s", tok.str().c_str(), tok1.str().c_str());
1070 add_mem_id(tok);
1071 return translate_data_def(tokens, index + 2, macro_params);
1072
1073 case TOKEN_TYPE::KW_EQU:
1074 //printf("%s%s", tok.str().c_str(), tok1.str().c_str());
1075 printf("#define %s ", tok.str().c_str());
1077 return translate_expression(tokens, index + 3, macro_params);
1078
1079 case TOKEN_TYPE::KW_TEXTEQU:
1080 {
1081 Token tok3 = get_ws(tokens[index + 3]);
1082 Token tok4 = get_expected_token(tokens[index + 4], TOKEN_TYPE::StringDef);
1083
1084 string textdef = tok4.str();
1085 printf("#define %s %s", tok.str().c_str(), textdef.substr(1, textdef.size() - 2).c_str());
1087 return index + 5;
1088 }
1089
1090 case TOKEN_TYPE::KW_PROC:
1091 {
1092 printf("%s:", tok.str().c_str());
1093 index += 3;
1094
1095 size_t frameEndIndex;
1096 bool hasFrame = find_proc_frame(tokens, index, frameEndIndex);
1097 g_proc_frame_stack.push_back(hasFrame);
1098
1099 if (hasFrame)
1100 {
1101#ifdef TARGET_amd64
1102 printf("\n.seh_proc %s\n", tok.str().c_str());
1103#else
1104 printf("\n.cfi_startproc\n");
1105#endif
1106 index = frameEndIndex;
1107 }
1109 break;
1110 }
1111
1112 case TOKEN_TYPE::KW_ENDP:
1113 {
1114 bool hasFrame = false;
1115 if (!g_proc_frame_stack.empty())
1116 {
1117 hasFrame = g_proc_frame_stack.back();
1118 g_proc_frame_stack.pop_back();
1119 }
1120
1121 if (hasFrame)
1122 {
1123#ifdef TARGET_amd64
1124 printf(".seh_endproc");
1125#else
1126 printf(".cfi_endproc");
1127#endif
1128 }
1129 index += 3;
1130 break;
1131 }
1132
1133 case TOKEN_TYPE::KW_RECORD:
1134 index = translate_record(tokens, index, macro_params);
1135 break;
1136
1137 default:
1138 // We don't know what it is, assume it's a macro and treat it like an instruction
1139 index = translate_instruction(tokens, index, macro_params);
1140 break;
1141 }
1142
1143 return index;
1144}
static bool find_proc_frame(TokenList &tokens, size_t index, size_t &frameEndIndex)
Definition: asmpp.cpp:1014
vector< bool > g_proc_frame_stack
Definition: asmpp.cpp:301
unsigned int g_label_number
Definition: asmpp.cpp:297
size_t translate_record(TokenList &tokens, size_t index, const vector< string > &macro_params)
Definition: asmpp.cpp:933
_Self substr(size_type __pos=0, size_type __n=npos) const
Definition: _string.h:1022
size_type size() const
Definition: _string.h:400

Referenced by translate_construct().

◆ translate_instruction()

size_t translate_instruction ( TokenList tokens,
size_t  index,
const vector< string > &  macro_params 
)

Definition at line 734 of file asmpp.cpp.

735{
736 // Check for jump/call instructions
737 if (is_jmp_or_call(tokens[index]))
738 {
739 g_processing_jmp = true;
740 }
741
742 // Translate the instruction itself
743 index = translate_token(tokens, index, macro_params);
744
745 // Handle instruction parameters
746 while (index < tokens.size())
747 {
748 // Optional whitespace
749 if (tokens[index].type() == TOKEN_TYPE::WhiteSpace)
750 {
751 index = translate_token(tokens, index, macro_params);
752 }
753
754 // Check for parameters
755 Token tok = tokens[index];
756 switch (tok.type())
757 {
758 case TOKEN_TYPE::Comment:
759 case TOKEN_TYPE::NewLine:
760 g_processing_jmp = false;
761 return index;
762
763 case TOKEN_TYPE::WhiteSpace:
764 case TOKEN_TYPE::Operator:
765 index = translate_token(tokens, index, macro_params);
766 break;
767
768 default:
769 index = translate_instruction_param(tokens, index, macro_params);
770 break;
771 }
772 }
773
774 g_processing_jmp = false;
775 return index;
776}
static bool is_jmp_or_call(const Token &tok)
Definition: asmpp.cpp:714
bool g_processing_jmp
Definition: asmpp.cpp:299
size_t translate_instruction_param(TokenList &tokens, size_t index, const vector< string > &macro_params)
Definition: asmpp.cpp:658

Referenced by translate_construct(), and translate_identifier_construct().

◆ translate_instruction_param()

size_t translate_instruction_param ( TokenList tokens,
size_t  index,
const vector< string > &  macro_params 
)

Definition at line 658 of file asmpp.cpp.

659{
660 switch (tokens[index].type())
661 {
662 case TOKEN_TYPE::BYTE_PTR:
663 case TOKEN_TYPE::WORD_PTR:
664 case TOKEN_TYPE::DWORD_PTR:
665 case TOKEN_TYPE::QWORD_PTR:
666 case TOKEN_TYPE::XMMWORD_PTR:
667 index = translate_token(tokens, index, macro_params);
668
669 // Optional whitespace
670 if (tokens[index].type() == TOKEN_TYPE::WhiteSpace)
671 {
672 index = translate_token(tokens, index, macro_params);
673 }
674 }
675
676 while (index < tokens.size())
677 {
678 Token tok = tokens[index];
679 switch (tok.type())
680 {
681 case TOKEN_TYPE::MemRefStart:
682 return translate_mem_ref(tokens, index, macro_params);
683
684 case TOKEN_TYPE::NewLine:
685 case TOKEN_TYPE::Comment:
686 return index;
687
688 case TOKEN_TYPE::Operator:
689 if (tok.str() == ",")
690 return index;
691 return translate_token(tokens, index, macro_params);
692
693 case TOKEN_TYPE::Identifier:
694 index = translate_token(tokens, index, macro_params);
695 if (is_mem_id(tok) &&
696 !is_string_in_list(macro_params, tok.str()) &&
698 {
699 index = translate_rip_relative_offset(tokens, index, macro_params);
700 printf("[rip]");
701 }
702 break;
703
704 default:
705 index = translate_expression(tokens, index, macro_params);
706 }
707 }
708
709 return index;
710}
static size_t translate_rip_relative_offset(TokenList &tokens, size_t index, const vector< string > &macro_params)
Definition: asmpp.cpp:632
bool is_mem_id(Token &tok)
Definition: asmpp.cpp:338
bool is_string_in_list(vector< string > list, string str)
Definition: asmpp.cpp:418
size_t translate_mem_ref(TokenList &tokens, size_t index, const vector< string > &macro_params)
Definition: asmpp.cpp:576

Referenced by translate_instruction().

◆ translate_item()

size_t translate_item ( TokenList tokens,
size_t  index,
const vector< string > &  macro_params 
)

Definition at line 778 of file asmpp.cpp.

779{
780 switch (tokens[index].type())
781 {
782 case TOKEN_TYPE::DecNumber:
783 case TOKEN_TYPE::HexNumber:
784 case TOKEN_TYPE::String:
785 case TOKEN_TYPE::WhiteSpace:
786 return translate_token(tokens, index, macro_params);
787 }
788
789 throw "Failed to translate item";
790 return -1;
791}

Referenced by translate_data_def(), and translate_list().

◆ translate_list()

size_t translate_list ( TokenList tokens,
size_t  index,
const vector< string > &  macro_params 
)

Definition at line 793 of file asmpp.cpp.

794{
795 while (index < tokens.size())
796 {
797 // The item itself
798 index = translate_item(tokens, index, macro_params);
799
800 // Optional white space
801 if (tokens[index].type() == TOKEN_TYPE::WhiteSpace)
802 {
803 index = translate_token(tokens, index, macro_params);
804 }
805
806 // End of list?
807 if ((tokens[index].type() == TOKEN_TYPE::Comment) ||
808 (tokens[index].type() == TOKEN_TYPE::NewLine))
809 {
810 return index;
811 }
812
813 // We expect a comma here
814 if ((tokens[index].type() != TOKEN_TYPE::Operator) ||
815 (tokens[index].str() != ","))
816 {
817 throw "Unexpected end of list";
818 }
819
820 index = translate_token(tokens, index, macro_params);
821 if (tokens[index].type() == TOKEN_TYPE::WhiteSpace)
822 {
823 index = translate_token(tokens, index, macro_params);
824 }
825 }
826
827 throw "Failed to translate list";
828 return -1;
829}

◆ translate_macro()

size_t translate_macro ( TokenList tokens,
size_t  index 
)

Definition at line 1280 of file asmpp.cpp.

1281{
1282 vector<string> macro_params;
1283
1284 printf(".macro %s", tokens[index].str().c_str());
1285
1286 // Parse marameters
1287 index += 3;
1288 while (index < tokens.size())
1289 {
1290 Token tok = tokens[index];
1291 switch (tok.type())
1292 {
1293 case TOKEN_TYPE::NewLine:
1294 case TOKEN_TYPE::Comment:
1295 index = translate_token(tokens, index, macro_params);
1296 break;
1297
1298 case TOKEN_TYPE::Identifier:
1299 macro_params.push_back(tok.str());
1300 printf("%s", tok.str().c_str());
1301 index++;
1302 continue;
1303
1304 case TOKEN_TYPE::WhiteSpace:
1305 case TOKEN_TYPE::Operator:
1306 index = translate_token(tokens, index, macro_params);
1307 continue;
1308 }
1309
1310 break;
1311 }
1312
1313 // Parse content
1314 while (index < tokens.size())
1315 {
1316 Token tok = tokens[index];
1317 switch (tok.type())
1318 {
1319 case TOKEN_TYPE::KW_ENDM:
1320 printf(".endm");
1321 return index + 1;
1322
1323 default:
1324 index = translate_construct(tokens, index, macro_params);
1325 }
1326 }
1327
1328 throw "Failed to translate macro";
1329 return -1;
1330}
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:379

Referenced by translate().

◆ translate_mem_ref()

size_t translate_mem_ref ( TokenList tokens,
size_t  index,
const vector< string > &  macro_params 
)

Definition at line 576 of file asmpp.cpp.

577{
578 unsigned int offset = 0;
579
580 Token tok = tokens[index];
581
582 if ((tok.type() == TOKEN_TYPE::DecNumber) ||
583 (tok.type() == TOKEN_TYPE::HexNumber))
584 {
585 offset = stoi(tok.str(), nullptr, 0);
586 index += 2;
587 }
588
589 index = translate_token(tokens, index, macro_params);
590
591 while (index < tokens.size())
592 {
593 Token tok = tokens[index];
594 index = translate_token(tokens, index, macro_params);
595 if (tok.type() == TOKEN_TYPE::MemRefEnd)
596 {
597 if (offset != 0)
598 {
599 printf(" + %u", offset);
600 }
601 return index;
602 }
603 }
604
605 throw "Failed to translate memory ref";
606 return index;
607}
GLintptr offset
Definition: glext.h:5920

Referenced by translate_instruction_param().

◆ translate_record()

size_t translate_record ( TokenList tokens,
size_t  index,
const vector< string > &  macro_params 
)

Definition at line 933 of file asmpp.cpp.

934{
935 unsigned int bits, bitpos = 0;
936 unsigned long long oldmask = 0, mask = 0;
937
938 Token tok_name = get_expected_token(tokens[index], TOKEN_TYPE::Identifier);
939 index += 4;
940 while (index < tokens.size())
941 {
942 Token tok_member = get_expected_token(tokens[index++], TOKEN_TYPE::Identifier);
943
944 if (tokens[index].type() == TOKEN_TYPE::WhiteSpace)
945 {
946 index++;
947 }
948
949 if (tokens[index++].str() != ":")
950 {
951 throw "Unexpected token";
952 }
953
954 if (tokens[index].type() == TOKEN_TYPE::WhiteSpace)
955 {
956 index++;
957 }
958
959 Token tok_bits = tokens[index++];
960 if ((tok_bits.type() != TOKEN_TYPE::DecNumber) &&
961 (tok_bits.type() != TOKEN_TYPE::HexNumber))
962 {
963 throw "Unexpected token";
964 }
965
966 bits = stoi(tok_bits.str(), nullptr, 0);
967
968 printf("%s = %u\n", tok_member.str().c_str(), bitpos);
969
970 oldmask = (1ULL << bitpos) - 1;
971 bitpos += bits;
972 mask = (1ULL << bitpos) - 1 - oldmask;
973 printf("MASK_%s = 0x%llx\n", tok_member.str().c_str(), mask);
974
975 if (tokens[index].type() == TOKEN_TYPE::WhiteSpace)
976 {
977 index++;
978 }
979
980 if ((tokens[index].type() == TOKEN_TYPE::NewLine) ||
981 (tokens[index].type() == TOKEN_TYPE::Comment))
982 {
983 break;
984 }
985
986 if (tokens[index].str() != ",")
987 {
988 throw "unexpected token";
989 }
990
991 index++;
992 if (tokens[index].type() == TOKEN_TYPE::WhiteSpace)
993 {
994 index++;
995 }
996
997 if ((tokens[index].type() == TOKEN_TYPE::NewLine) ||
998 (tokens[index].type() == TOKEN_TYPE::Comment))
999 {
1000 index++;
1001 }
1002
1003 if (tokens[index].type() == TOKEN_TYPE::WhiteSpace)
1004 {
1005 index++;
1006 }
1007 }
1008
1009 return index;
1010}
GLenum GLint GLuint mask
Definition: glext.h:6028
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
#define bits
Definition: infblock.c:15

Referenced by translate_identifier_construct().

◆ translate_rip_relative_offset()

static size_t translate_rip_relative_offset ( TokenList tokens,
size_t  index,
const vector< string > &  macro_params 
)
static

Definition at line 632 of file asmpp.cpp.

633{
634 size_t operatorIndex = skip_whitespace(tokens, index);
635 if ((operatorIndex == tokens.size()) ||
636 (tokens[operatorIndex].type() != TOKEN_TYPE::Operator) ||
637 ((tokens[operatorIndex].str() != "+") &&
638 (tokens[operatorIndex].str() != "-")))
639 {
640 return index;
641 }
642
643 size_t numberIndex = skip_whitespace(tokens, operatorIndex + 1);
644 if ((numberIndex == tokens.size()) ||
645 !is_number_token(tokens[numberIndex]))
646 {
647 return index;
648 }
649
650 while (index <= numberIndex)
651 {
652 index = translate_token(tokens, index, macro_params);
653 }
654
655 return index;
656}
static bool is_number_token(const Token &tok)
Definition: asmpp.cpp:611
static void skip_whitespace()
Definition: regtests2xml.c:188

Referenced by translate_instruction_param().

◆ translate_token()

size_t translate_token ( TokenList tokens,
size_t  index,
const vector< string > &  macro_params 
)

Definition at line 432 of file asmpp.cpp.

433{
434 Token tok = tokens[index];
435 switch (tok.type())
436 {
437 case TOKEN_TYPE::Comment:
438 printf("//%s", tok.str().c_str() + 1);
439 break;
440
441 case TOKEN_TYPE::DecNumber:
442 {
443 unsigned long long num = stoull(tok.str(), nullptr, 10);
444 printf("%llu", num);
445 break;
446 }
447
448 case TOKEN_TYPE::HexNumber:
449 {
450 string number = tok.str();
451 printf("0x%s", number.substr(0, number.size() - 1).c_str());
452 break;
453 }
454
455 case TOKEN_TYPE::Identifier:
456 if (is_string_in_list(macro_params, tok.str()))
457 {
458 printf("\\");
459 }
460 printf("%s", tok.str().c_str());
461 break;
462
463 // We migt want to improve these
464 case TOKEN_TYPE::BYTE_PTR:
465 case TOKEN_TYPE::WORD_PTR:
466 case TOKEN_TYPE::DWORD_PTR:
467 case TOKEN_TYPE::QWORD_PTR:
468 case TOKEN_TYPE::XMMWORD_PTR:
469
470 // Check these. valid only in instructions?
471 case TOKEN_TYPE::Reg8:
472 case TOKEN_TYPE::Reg16:
473 case TOKEN_TYPE::Reg32:
474 case TOKEN_TYPE::Reg64:
475 case TOKEN_TYPE::RegXmm:
476 case TOKEN_TYPE::Instruction:
477
478 case TOKEN_TYPE::WhiteSpace:
479 case TOKEN_TYPE::NewLine:
480 case TOKEN_TYPE::Operator:
481 printf("%s", tok.str().c_str());
482 break;
483
484 default:
485 printf("%s", tok.str().c_str());
486 break;
487 }
488
489 return index + 1;
490}
GLuint GLuint num
Definition: glext.h:9618
static unsigned int number
Definition: dsound.c:1479

Referenced by complete_line(), translate_construct(), translate_data_def(), translate_expression(), translate_instruction(), translate_instruction_param(), translate_item(), translate_list(), translate_macro(), translate_mem_ref(), and translate_rip_relative_offset().

Variable Documentation

◆ g_identifiers

vector<IDENTIFIER> g_identifiers

Definition at line 321 of file asmpp.cpp.

Referenced by add_identifier(), and is_mem_id().

◆ g_intel_syntax_emitted

bool g_intel_syntax_emitted = false
static

Definition at line 1146 of file asmpp.cpp.

Referenced by translate_construct().

◆ g_label_number

unsigned int g_label_number = 0

Definition at line 297 of file asmpp.cpp.

Referenced by translate_identifier_construct().

◆ g_proc_frame_stack

vector<bool> g_proc_frame_stack

Definition at line 301 of file asmpp.cpp.

Referenced by translate_identifier_construct().

◆ g_processing_jmp

bool g_processing_jmp = false

Definition at line 299 of file asmpp.cpp.

Referenced by translate_instruction(), and translate_instruction_param().

◆ g_TokenList

vector<TOKEN_DEF> g_TokenList

Definition at line 225 of file asmpp.cpp.

Referenced by main().

◆ search_time

time_t search_time

Definition at line 26 of file asmpp.cpp.

Referenced by main(), and Tokenizer::match().