C指针原理教程之C指针基础
tcctok.h定义了C语言的词法分析的基本元素,主要定义了关键字。
/keywords/
DEF(TOK_INT,"int")
DEF(TOK_VOID,"void")
DEF(TOK_CHAR,"char")
DEF(TOK_IF,"if")
DEF(TOK_ELSE,"else")
DEF(TOK_WHILE,"while")
DEF(TOK_BREAK,"break")
DEF(TOK_RETURN,"return")
DEF(TOK_FOR,"for")
DEF(TOK_EXTERN,"extern")
DEF(TOK_STATIC,"static")
DEF(TOK_UNSIGNED,"unsigned")
DEF(TOK_GOTO,"goto")
DEF(TOK_DO,"do")
DEF(TOK_CONTINUE,"continue")
DEF(TOK_SWITCH,"switch")
DEF(TOK_CASE,"case")
..............................
..............................
..............................
同时定义了条件编译的相关内容
/*****/
/thefollowingarenotkeywords.Theyareincludedtoeaseparsing/
/preprocessoronly/
DEF(TOK_DEFINE,"define")
DEF(TOK_INCLUDE,"include")
DEF(TOK_INCLUDE_NEXT,"include_next")
DEF(TOK_IFDEF,"ifdef")
DEF(TOK_IFNDEF,"ifndef")
DEF(TOK_ELIF,"elif")
DEF(TOK_ENDIF,"endif")
DEF(TOK_DEFINED,"defined")
在i386-tok.h中定义了汇编的相关关键词
/------------------------------------------------------------------/
/WARNING:relativeorderoftokensisimportant./
/register/
DEF_ASM(al)
DEF_ASM(cl)
DEF_ASM(dl)
DEF_ASM(bl)
DEF_ASM(ah)
DEF_ASM(ch)
DEF_ASM(dh)
DEF_ASM(bh)
DEF_ASM(ax)
DEF_ASM(cx)
DEF_ASM(dx)
DEF_ASM(bx)
DEF_ASM(sp)
DEF_ASM(bp)
DEF_ASM(si)
DEF_ASM(di)
DEF_ASM(eax)
DEF_ASM(ecx)
DEF_ASM(edx)
DEF_ASM(ebx)
DEF_ASM(esp)
DEF_ASM(ebp)
DEF_ASM(esi)
DEF_ASM(edi)
#ifdefTCC_TARGET_X86_64
DEF_ASM(rax)
DEF_ASM(rcx)
DEF_ASM(rdx)
...........................
............................
在x86_64-asm.h中定义了64位汇编相关关键字
DEF_ASM_OP0(clc,0xf8)/mustbefirstOP0/
DEF_ASM_OP0(cld,0xfc)
DEF_ASM_OP0(cli,0xfa)
DEF_ASM_OP0(clts,0x0f06)
DEF_ASM_OP0(cmc,0xf5)
DEF_ASM_OP0(lahf,0x9f)
DEF_ASM_OP0(sahf,0x9e)
DEF_ASM_OP0(pushfl,0x9c)
DEF_ASM_OP0(popfl,0x9d)
DEF_ASM_OP0(pushf,0x9c)
DEF_ASM_OP0(popf,0x9d)
DEF_ASM_OP0(stc,0xf9)
DEF_ASM_OP0(std,0xfd)
DEF_ASM_OP0(sti,0xfb)
DEF_ASM_OP0(aaa,0x37)
先从几个重要文件入手。
libtcc.c
/ TCC-TinyCCompiler Copyright(c)2001-2004FabriceBellard Thislibraryisfreesoftware;youcanredistributeitand/or modifyitunderthetermsoftheGNULesserGeneralPublic LicenseaspublishedbytheFreeSoftwareFoundation;either version2oftheLicense,or(atyouroption)anylaterversion. Thislibraryisdistributedinthehopethatitwillbeuseful, butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.SeetheGNU LesserGeneralPublicLicenseformoredetails. YoushouldhavereceivedacopyoftheGNULesserGeneralPublic Licensealongwiththislibrary;ifnot,writetotheFreeSoftware Foundation,Inc.,59TemplePlace,Suite330,Boston,MA02111-1307USA */ #include"tcc.h" /****/ /globalvariables/ 使用GCC扩展还是TCC扩展 /useGNUCextensions/ ST_DATAintgnu_ext=1; /useTinyCCextensions/ ST_DATAinttcc_ext=1; ST_DATA结构标注TCC状态。 /XXX:getridofthisASAP/ ST_DATAstructTCCState*tcc_state; /****/
根据标志包含一些相应TCC文件。
#ifdefONE_SOURCE
#include"tccpp.c"
#include"tccgen.c"
#include"tccelf.c"
#include"tccrun.c"
#ifdefTCC_TARGET_I386
#include"i386-gen.c"
#endif
#ifdefTCC_TARGET_ARM
#include"arm-gen.c"
#endif
#ifdefTCC_TARGET_C67
#include"c67-gen.c"
#endif
#ifdefTCC_TARGET_X86_64
#include"x86_64-gen.c"
#endif
#ifdefCONFIG_TCC_ASM
#include"tccasm.c"
#ifdefinedTCC_TARGET_I386||definedTCC_TARGET_X86_64
#include"i386-asm.c"
#endif
#endif
#ifdefTCC_TARGET_COFF
#include"tcccoff.c"
#endif
#ifdefTCC_TARGET_PE
#include"tccpe.c"
#endif
#endif/ONE_SOURCE/
CONFIG_TCC_ASM打开内联汇编的开关
/****/
#ifndefCONFIG_TCC_ASM
ST_FUNCvoidasm_instr(void)
{
tcc_error("inlineasm()notsupported");
}
ST_FUNCvoidasm_global_instr(void)
{
tcc_error("inlineasm()notsupported");
}
#endif