Lhogho  0.0.028
 All Data Structures Files Functions Variables Typedefs Macros Pages
asm.c File Reference

Go to the source code of this file.

Macros

#define SPACES   TEXT(" ")
 
#define DISASM_LABEL   1
 position for labels More...
 
#define DISASM_INSTR   14
 position for instructions More...
 
#define DISASM_PARAM   20
 position for parameters More...
 
#define DISASM_REM   40
 position for remarks More...
 
#define BUF_SIZE   128
 

Functions

void emit_1 (context_t *ctx, byte_t data)
 emits a byte More...
 
void emit_2 (context_t *ctx, ushort_t data)
 emits two bytes More...
 
void emit_4 (context_t *ctx, uint_t data)
 emits four bytes More...
 
void reemit_4 (context_t *ctx, uint_t offset, uint_t data)
 reemits four bytes at specific offset More...
 
void disasm_set_pos (int pos)
 set disassembler's position More...
 
void disasm (context_t *ctx, int mode, chars_t format,...)
 disassembler's print function More...
 

Variables

int disasm_pos = 1
 

Macro Definition Documentation

#define SPACES   TEXT(" ")

Definition at line 136 of file asm.c.

#define DISASM_LABEL   1

Definition at line 140 of file asm.c.

#define DISASM_INSTR   14

Definition at line 141 of file asm.c.

#define DISASM_PARAM   20

Definition at line 142 of file asm.c.

#define DISASM_REM   40

Definition at line 143 of file asm.c.

#define BUF_SIZE   128

Function Documentation

void emit_1 ( context_t ctx,
byte_t  data 
)
Parameters
ctxcompilation context
databyte 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).

Definition at line 54 of file asm.c.

55 {
56  if( ctx->generate )
57  {
58  *((byte_t*)(((char*)MEMORY(ctx->generate))+ctx->size)) = data;
59  }
60  ctx->size += sizeof(byte_t);
61 }
void emit_2 ( context_t ctx,
ushort_t  data 
)
Parameters
ctxcompilation context
databytes 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).

Definition at line 77 of file asm.c.

78 {
79  if( ctx->generate )
80  {
81  *((ushort_t*)(((char*)MEMORY(ctx->generate))+ctx->size)) = data;
82  }
83  ctx->size += sizeof(ushort_t);
84 }
void emit_4 ( context_t ctx,
uint_t  data 
)
Parameters
ctxcompilation context
databytes 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).

Definition at line 100 of file asm.c.

101 {
102  if( ctx->generate )
103  {
104  *((uint_t*)(((char*)MEMORY(ctx->generate))+ctx->size)) = data;
105  }
106  ctx->size += sizeof(uint_t);
107 }
void reemit_4 ( context_t ctx,
uint_t  offset,
uint_t  data 
)
Parameters
ctxcompilation context
offsetoffset where to reemit the data
databytes to reemit

Reemits (simulated or real) 4 bytes to specific location. If ctx->generate=1 then the bytes are really generated.

Definition at line 123 of file asm.c.

124 {
125  if( ctx->generate )
126  {
127  *((uint_t*)(((char*)MEMORY(ctx->generate))+offset)) = data;
128  //printf("===fix=%d=%x====\n",data,data);
129  }
130 }
void disasm_set_pos ( int  pos)
Parameters
posposition

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.

Definition at line 156 of file asm.c.

157 {
158  // start new line if position cannot be reached
159  if( disasm_pos>=pos )
160  {
161  outter( TEXT("\n"), -1 );
162  disasm_pos = 1;
163  }
164  outter( SPACES, pos-disasm_pos );
165  disasm_pos = pos;
166 }
void disasm ( context_t ctx,
int  mode,
chars_t  format,
  ... 
)
Parameters
ctxcompilation context
modedisassembly mode
formatformat 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

Definition at line 195 of file asm.c.

196 {
197  if( !ASM ) return;
198 
199  // instruction
200  if( mode==1 )
201  {
202  TERM_INSTR;
204  }
205 
206  // info
207  if( mode==2 )
208  {
209  TERM_INFO;
211  if( STRLEN(format)>0 )
212  {
213  outter( TEXT(";; "), -1 );
214  disasm_pos += 3;
215  }
216  }
217 
218  // rem
219  if( mode==3 )
220  {
221  TERM_REMARK;
223  outter( TEXT("; "), -1 );
224  disasm_pos += 2;
225  }
226 
227  // label
228  if( mode==4 )
229  {
230  TERM_INSTR;
232  }
233 
234  va_list param;
235  chars_t ch;
236 
237  #define BUF_SIZE 128
238  char_t buf[BUF_SIZE];
239  chars_t strbuf;
240 
241  va_start (param, format);
242 
243  for( ch=format; *ch; ch++ )
244  {
245  if( *ch != TEXT('%') )
246  {
247  outter( ch, 1 );
248  disasm_pos++;
249  continue;
250  }
251 
252  ch++;
253  switch( *ch )
254  {
255  case TEXT('d'): // n or -n
256  SPRINTF( buf, BUF_SIZE, TEXT("%d"), va_arg(param,int) );
257  outter( buf, -1 );
258  disasm_pos += STRLEN( buf );
259  break;
260  case TEXT('p'): // +n or -n
261  SPRINTF( buf, BUF_SIZE, TEXT("%+d"), va_arg(param,int) );
262  outter( buf, -1 );
263  disasm_pos += STRLEN( buf );
264  break;
265  case TEXT('s'): // string
266  strbuf = va_arg(param,chars_t);
267  outter( strbuf, -1 );
268  disasm_pos += STRLEN( strbuf );
269  break;
270  case TEXT('a'): // atom
271  outter_size = 0;
272  dump_atom( va_arg(param,atom_t), 1 );
274  break;
275  case TEXT('l'): // atom or CAR(atom) if list
276  outter_size = 0;
277  atom_t a = va_arg(param,atom_t);
278  if( IS_LIST(a) && IS_NOT_EMPTY(a) )
279  {
280  dump_atom( CAR(a), 1 );
281  outter( TEXT("..."), 3 );
282  disasm_pos += 3;
283  }
284  else
285  dump_atom( a, 1 );
287  break;
288  }
289  } //for
290 
291  va_end( param );
292 }

Variable Documentation

int disasm_pos = 1

Definition at line 138 of file asm.c.


[ HOME | INDEX | ATOMS | VARS | REFERENCE ]
Lhogho Developer's Documentation
Wed Jul 10 2013