|
Lhogho
0.0.027
|
Defines | |
| #define | SPACES TEXT(" ") |
| #define | DISASM_LABEL 1 |
| position for labels | |
| #define | DISASM_INSTR 14 |
| position for instructions | |
| #define | DISASM_PARAM 20 |
| position for parameters | |
| #define | DISASM_REM 40 |
| position for remarks | |
| #define | BUF_SIZE 128 |
Functions | |
| void | emit_1 (context_t *ctx, byte_t data) |
| emits a byte | |
| void | emit_2 (context_t *ctx, ushort_t data) |
| emits two bytes | |
| void | emit_4 (context_t *ctx, uint_t data) |
| emits four bytes | |
| void | reemit_4 (context_t *ctx, uint_t offset, uint_t data) |
| reemits four bytes at specific offset | |
| void | disasm_set_pos (int pos) |
| set disassembler's position | |
| void | disasm (context_t *ctx, int mode, chars_t format,...) |
| disassembler's print function | |
Variables | |
| int | disasm_pos = 1 |
| #define DISASM_LABEL 1 |
| #define DISASM_INSTR 14 |
| #define DISASM_PARAM 20 |
| #define DISASM_REM 40 |
| #define BUF_SIZE 128 |
| ctx | compilation context |
| data | byte to emit |
Emits (simulated or real) a byte to generated code. If ctx->generate=1 then the byte is really generated, otherwise only ctx->size is incremented in order to estimate the compiled size (in bytes).
| ctx | compilation context |
| data | bytes to emit |
Emits (simulated or real) 2 bytes to generated code. If ctx->generate=1 then the bytes are really generated, otherwise only ctx->size is incremented in order to estimate the compiled size (in bytes).
| ctx | compilation context |
| data | bytes to emit |
Emits (simulated or real) 4 bytes to generated code. If ctx->generate=1 then the bytes are really generated, otherwise only ctx->size is incremented in order to estimate the compiled size (in bytes).
| ctx | compilation context |
| offset | offset where to reemit the data |
| data | bytes to reemit |
Reemits (simulated or real) 4 bytes to specific location. If ctx->generate=1 then the bytes are really generated.
| void disasm_set_pos | ( | int | pos | ) |
| pos | position |
Set disassembler's position to required column. Next output data will start from this position. If the current position is greateer than pos, then start a new line. Otherwise fill with spaces.
{
// start new line if position cannot be reached
if( disasm_pos>=pos )
{
outter( TEXT("\n"), -1 );
disasm_pos = 1;
}
outter( SPACES, pos-disasm_pos );
disasm_pos = pos;
}
| ctx | compilation context |
| mode | disassembly mode |
| format | format string |
Prints text generated by the disassembler. The mode parameter determines the initial position and the color of the test:
mode==0 - continues the last mode mode==1 - prints assembler instruction (white, bold) mode==2 - prints information text (green) mode==3 - prints remark (gray) mode==4 - prints label (white, bold)
The format parameter is like a printf format string, but supports only these format specifiers:
d - integer number (like 5 or -5) p - integer number with forced sign (like +5 or -5) s - string of type chars_t a - atom of type atom_t l - atom of type atom_t, but only the first node of a list/expression is printed
{
if( !ASM ) return;
// instruction
if( mode==1 )
{
TERM_INSTR;
disasm_set_pos( DISASM_INSTR );
}
// info
if( mode==2 )
{
TERM_INFO;
disasm_set_pos( DISASM_INSTR );
if( STRLEN(format)>0 )
{
outter( TEXT(";; "), -1 );
disasm_pos += 3;
}
}
// rem
if( mode==3 )
{
TERM_REMARK;
disasm_set_pos( DISASM_REM );
outter( TEXT("; "), -1 );
disasm_pos += 2;
}
// label
if( mode==4 )
{
TERM_INSTR;
disasm_set_pos( DISASM_LABEL );
}
va_list param;
chars_t ch;
#define BUF_SIZE 128
char_t buf[BUF_SIZE];
chars_t strbuf;
va_start (param, format);
for( ch=format; *ch; ch++ )
{
if( *ch != TEXT('%') )
{
outter( ch, 1 );
disasm_pos++;
continue;
}
ch++;
switch( *ch )
{
case TEXT('d'): // n or -n
SPRINTF( buf, BUF_SIZE, TEXT("%d"), va_arg(param,int) );
outter( buf, -1 );
disasm_pos += STRLEN( buf );
break;
case TEXT('p'): // +n or -n
SPRINTF( buf, BUF_SIZE, TEXT("%+d"), va_arg(param,int) );
outter( buf, -1 );
disasm_pos += STRLEN( buf );
break;
case TEXT('s'): // string
strbuf = va_arg(param,chars_t);
outter( strbuf, -1 );
disasm_pos += STRLEN( strbuf );
break;
case TEXT('a'): // atom
outter_size = 0;
dump_atom( va_arg(param,atom_t), 1 );
disasm_pos += outter_size;
break;
case TEXT('l'): // atom or CAR(atom) if list
outter_size = 0;
atom_t a = va_arg(param,atom_t);
if( IS_LIST(a) && IS_NOT_EMPTY(a) )
{
dump_atom( CAR(a), 1 );
outter( TEXT("..."), 3 );
disasm_pos += 3;
}
else
dump_atom( a, 1 );
disasm_pos += outter_size;
break;
}
} //for
va_end( param );
}
| int disasm_pos = 1 |