📄 oxcc.txt
字号:
callbacks will not work.
TYPEOF, ALIGNOF
The type of an expression can be derived and applied wherever a normal
type would be used.
e.g.:
typeof(x) y;
typeof(*x) y;
The alignment of an expression can be obtained.
e.g.:
int x = __alignof__(y);
COMPUTED TYPEDEF
A typedef can be computed.
e.g.:
typedef XTYPE = x;
XTYPE q;
STRUCTURE ALIGNMENT AND PACKING
Structures can be designated as packed with the `_Packed' keyword.
OXCC also supports the awful __attribute__ constructions of GCC.
OXCC also supports various forms of the #pragma pack(n) directives
but it is strongly suggested that these not be used because source
regeneration does not handle pragma regeneration.
LOCAL LABELS
Each block is a scope in which local labels can be declared. The
value of the label goes out of scope with the block. This is handy
for macros. GCC inspired.
e.g.:
{
__label__ l1: // declares l1 to be a local label
...
goto l1;
...
l1:
}
CASE RANGES
Case values may be expressed in the form:
case 2 ... 4:
ARITHMETIC ON VOID POINTERS
Pointers typed as void* are assumed to have the same size as char*
for the purpose of pointer arithmetic.
MACROS WITH VARIABLE NUMBERS OF ARGUMENTS
GCC inspired extension to the C preprocessor.
e.g.:
#define myprintf(format, args...) \
fprintf(stderr, format, ## args)
ZERO LENGTH ARRAYS
Arrays of zero length are allowed within structures.
CONDITIONALS WITH OMITTED OPERANDS
The construction x ? : y
is equivalent to x ? x : y
except that x is not evaluated a second time.
DOUBLE WORD INTEGERS
The long long type is supported.
LONG DOUBLE
The long double type is supported.
FUNCTION TYPES
Various keywords from the segmented DOS world are understood by OXCC.
Currently OXCC does not do anything other than label the function
for later processing. (see c.grm)
SEGMENT INFORMATION
The keywords `__segdef__' and `__seguse__' are used to specify
segment info. The arguments to __segdef__ must be constant expressions.
This info is passed along to back end code generators.
e.g.:
__segdef__ DATA16 arg1, arg2, arg3; // 0 to 3 args
__segdef__ DATA32 arg1, arg2, arg3;
__segdef__ TEXT16 arg1, arg2, arg3;
__seguse__ DATA32;
int x,y,z;
__seguse__ TEXT16;
int func()
{
}
__seguse__ TEXT32;
int func1()
{
}
BASED POINTERS
Microsoft C defines based pointers and segment variables, OXCC currently
parses and stores the information for later processing by back ends,
but it does not yet know how to interpret this stuff. It can correctly
regenerate source.
NEAR FAR HUGE POINTERS
Ditto as per Based pointers.(see c.grm)
ASSEMBLER INSTRUCTIONS
Various flavors of assembler code can be absorbed and regenerated by
OXCC. Interpretation is out of the question and assembler instructions
are not passed to back end code generators on the theory that portability
can never be achieved. The OXCC solution is to provide an extensible
facility for direct generation of ANF code. (see c.grm)
ANF INSTRUCTION BLOCKS
OXCC generates ANF code (see anf.doc, oxanf.h) from C instructions. The
programmer can generate ANF code by enclosing it in a block.
e.g.:
__anf__ {
mov x,y/2; // divide y by 2 and store in x
lsh y,z,3; // shift z left by 3 and store in y
...
}
ANF blocks can be placed inside or outside of functions.
The basic set of ANF instructions can be extended by programmers to
achieve meaningful (I hope) methods of expressing concepts which
normally require assembler code. Essentially, ANF instructions consist
of an opcode followed by up to 3 arguments, the opcode set can be
extended by:
1. add new strings to oxanf.h
2. compile oxanf.h
3. insert in oxlib.cff with `cfar.exe' (see oxcc.mak)
ANF arguments can be any valid C expression and are evaluated by OXCC with
code generation where appropriate.
NO-NAME STRUCTURES/UNIONS
Inspired by Visual C++ 2.0
In order to compile 32 bit Windows programs it is necessary to deal with
un-named structures and unions which are members of named struct/unions.
This feature permits the programmer to reference the members of the
un-named struct/unions as if they were members of the enclosing named
container. Just make sure that all of the member names are unique.
Very nice idea.
GLOBAL SUBROUTINES IN OXCC -- also callable by code being interpreted
(see oxcc.h and toxcc.c)
void *__builtin_iv(void);
void *__builtin_root(void);
void *oxcc_get_pg(void *iv);
void oxcc_enable_trace(void *iv);
void oxcc_disable_trace(void *iv);
void oxcc_debug(void *iv, int bits);
void oxcc_proc_ptr_info(void *iv, void (*func)());
func(void*,void*,void*,long);
void oxcc_proc_syms(void *iv, unsigned space, void (*func)());
func(AstP node, long symb, void *container);
void oxcc_proc_swtable(void*iv, void *swnode, void (*func)());
func(long swval, AstP root);
void oxcc_proc_mallocs(void *iv, void *func());
func(void *loc, int size, Item *ip);
void *oxcc_open_instance(void);
void oxcc_set_options(void *iv, char *opts);
int oxcc_preproc_file(void *iv, void *is, void *os, void *es,
int argc, char **argv);
int oxcc_parse_file(void *iv, void *is, void *es, char *filename);
void oxcc_print_parse_errors(void *iv, void *es);
int oxcc_check_ast_tree(void *iv, void *es, char *filename);
int oxcc_init_outers(void *iv, void *es);
int oxcc_run_tree(void *iv, void *es, char *fnam, char *arg, char *startf);
int oxcc_gen_code(void *iv, void *es, char *filename, void *os);
void oxcc_cleanup_parse(void *iv);
void oxcc_close_codefile(void *iv);
void oxcc_close_instance(void *iv);
void oxcc_print_ast(void *iv, void *os, int flag);
void *oxcc_get_ast_root(void *iv);
int oxcc_eval_expr(void *iv, void *buf, double *result, void *es);
void gSetup(void *self, void *str);
int gPreProc(void *self, void *is, void *os, void *es,int argc,char **argv);
int gParse(void *self, void *is, void *es, char *filename);
void gPerror(void *self, void *es);
int gCheckTree(void *self, void *es, char *filename);
int gInitOuters(void *self, void *es);
int gRunCode(void *self, void *es, char *filename, char *args);
int gGenCode(void *self, void *es, void *os, char *filename);
void gCleanup(void *self);
void gCloseCode(void *self);
void gPrtAst(void *self, void *es, int flag);
void *gGetRoot(void *self);
int gEval(void *self, void *buf, double *result, void *es);
TODO
1. Improved optimization
2. Inline functions
3. Flavor #2 for nested functions
4. Modify oxcc to be callable as a reentrant subroutine or class [DONE 25May]
5. True interpretation of segmented code and 16 bit code.
6. Interpret ANF instruction blocks.
7. Support long double and complex data types. [long double DONE 5Nov]
8. Write more back ends
9. Better documentation
10. Better test program [test.bat for starters]
11. Add a new type `enumstring' to avoid parallel tables
12. Built in inheritance engine with COM, SOM, DCE compliance. [Coming up]
13. Generate Java,RIP code (need to juice up the grammar a bit)
14. Make ANF more general and text readable
15. Suggestions ??
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -