├── gc ├── libatomic_ops │ ├── NEWS │ ├── Makefile.am │ ├── src │ │ ├── atomic_ops │ │ │ ├── sysdeps │ │ │ │ ├── sunc │ │ │ │ │ ├── sparc.S │ │ │ │ │ └── sparc.h │ │ │ │ ├── README │ │ │ │ ├── standard_ao_double_t.h │ │ │ │ ├── gcc │ │ │ │ │ └── sh.h │ │ │ │ ├── Makefile.am │ │ │ │ ├── ordered.h │ │ │ │ ├── all_atomic_load_store.h │ │ │ │ ├── all_aligned_atomic_load_store.h │ │ │ │ ├── all_acquire_release_volatile.h │ │ │ │ ├── test_and_set_t_is_char.h │ │ │ │ ├── test_and_set_t_is_ao_t.h │ │ │ │ ├── atomic_load_store.h │ │ │ │ ├── int_atomic_load_store.h │ │ │ │ ├── char_atomic_load_store.h │ │ │ │ ├── short_atomic_load_store.h │ │ │ │ ├── aligned_atomic_load_store.h │ │ │ │ ├── int_aligned_atomic_load_store.h │ │ │ │ └── short_aligned_atomic_load_store.h │ │ │ └── Makefile.am │ │ ├── atomic_ops_sysdeps.S │ │ ├── Makefile.am │ │ ├── Makefile.msft │ │ ├── atomic_ops_malloc.h │ │ └── config.h.in │ ├── doc │ │ ├── Makefile.am │ │ └── README_win32.txt │ ├── AUTHORS │ ├── configure.ac │ └── tests │ │ ├── Makefile.am │ │ └── list_atomic.template ├── gctest.exe ├── doc │ ├── README.Mac │ ├── README.MacOSX │ ├── README.uts │ ├── README.OS2 │ ├── README.dj │ ├── README.rs6000 │ ├── README.hp │ ├── README.win64 │ ├── doc.am │ └── README.sgi ├── cord │ ├── de_win.ICO │ ├── cord.am │ └── de_cmds.h ├── extra │ ├── gc.h │ ├── gc_cpp.h │ ├── gcname.c │ ├── add_gc_prefix.c │ ├── if_mach.c │ └── if_not_there.c ├── gc_cpp.cpp ├── include │ ├── extra │ │ ├── gc.h │ │ └── gc_cpp.h │ ├── leak_detector.h │ ├── private │ │ ├── darwin_stop_world.h │ │ └── pthread_stop_world.h │ ├── gc_amiga_redirects.h │ ├── gc_version.h │ ├── javaxfc.h │ ├── include.am │ └── ec.h ├── configure_atomic_ops.sh ├── build_atomic_ops.sh ├── callprocs ├── Mac_files │ ├── dataend.c │ └── datastart.c ├── leak_detector.h ├── bdw-gc.pc.in ├── bdw-gc.pc ├── ia64_save_regs_in_stack.s ├── gctest.gc.log ├── a.c ├── a.c~ ├── build_atomic_ops.sh.cygwin ├── tests │ ├── smash_test.c │ ├── middle.c │ ├── leak_test.c │ ├── trace_test.c │ ├── thread_leak_test.c │ └── huge_test.c ├── hpux_test_and_clear.s ├── mips_ultrix_mach_dep.s ├── autogen.sh ├── sparc_sunos4_mach_dep.s ├── sparc_netbsd_mach_dep.s ├── real_malloc.c ├── private │ ├── darwin_stop_world.h │ └── pthread_stop_world.h ├── gc_amiga_redirects.h ├── mips_sgi_mach_dep.s ├── stubborn.c ├── gc_version.h ├── configure.host ├── javaxfc.h ├── include.am ├── PCR-Makefile └── ec.h ├── regression ├── colon.c ├── empty.c ├── tiny.c ├── clean.bat ├── exn3.c ├── gen.exe ├── gen2.exe ├── test.c ├── add.c ├── long-exp.c ├── while.c ├── deadcode.c ├── for-continue.c ├── scope.c ├── exp2.c ├── bool.c ├── dup-field.c ├── unclosed-string.c ├── exp.c ├── break.c ├── sum.c ├── cmd-line.c ├── random.c ├── for.c ├── exn.c ├── continue.c ├── scope2.c ├── field.c ├── hello.c ├── call.c ├── elab-example.c ├── break-continue.c ├── exn2.c ├── array.c ├── list.c ├── gen.c ├── gen2.c ├── tree.c └── qsort.c └── src ├── control ├── version.c ├── version.h ├── command-line.h ├── region.h ├── coordinate.h ├── pass.h ├── error-msg.h ├── pass.c ├── region.c ├── coordinate.c ├── log.h ├── error-msg.c ├── control.h └── log.c ├── lib ├── debug.h ├── io.h ├── test.h ├── random.h ├── system.h ├── unused.h ├── random.c ├── void.h ├── double.h ├── void.c ├── append-list.c ├── io.c ├── append-list.h ├── int.h ├── property-list.c ├── debug.c ├── system.c ├── property-list.h ├── char.h ├── dlist.h ├── poly.h ├── dot.h ├── error.c ├── file.h ├── box.h ├── char-buffer.h ├── string.h ├── tuple.h ├── list-pair.h ├── stack.h ├── double.c ├── todo.h ├── app-list.h ├── triple.h ├── print.c ├── print.h ├── property.h ├── dlist.c ├── tree.h ├── set.h ├── tuple.c ├── mem.h ├── char.c ├── file.c ├── hash-set.h ├── trace.c ├── graph.h ├── int.c ├── triple.c ├── list-pair.c ├── hash.h ├── mem.c ├── stack.c ├── char-buffer.c └── list.h ├── main ├── main-main.h └── compile.h ├── ssa ├── type-check.c ├── out-ssa.h ├── dead-code.h ├── const-fold.h ├── const-prop.h ├── type-check.h ├── construct-ssa.h ├── ssa-main.h ├── trans-ssa.h ├── dead-block.h ├── trivial-block.h ├── const-and-dead.h ├── union-block.h ├── const-and-dead.c └── ssa-main.c ├── runtime ├── main.c ├── dragon-lib.h └── dragon-lib.c ├── main.c ├── elaborate ├── check-ast.h ├── lift-dec.h ├── elaborate.h ├── combine-stm.h ├── trans-ast.h ├── elaborate-main.h ├── type.h ├── elaborate-main.c └── env.h ├── hil ├── dead-code.h ├── hil-main.h ├── trans-hil.h └── hil-main.c ├── x86 ├── peep-hole.h ├── x86-codegen.h ├── x86-main.h └── x86-main.c ├── lexer ├── lex.h ├── keyword.h └── token.h ├── machine ├── machine-main.h ├── gen-frame.h ├── gen-layout.h ├── runtime.h ├── runtime.c └── machine-main.c ├── parser └── parse.h ├── atoms ├── atoms.h ├── label.h ├── id.h ├── class.h ├── dec.h ├── operator.h ├── atype.h ├── label.c ├── dec.c ├── class.c └── id.c ├── c-codegen ├── c-codegen.h ├── c-codegen-main.h └── c-codegen-main.c └── ast ├── ast-id.h └── ast-id.c /gc/libatomic_ops/NEWS: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /regression/colon.c: -------------------------------------------------------------------------------- 1 | : 2 | -------------------------------------------------------------------------------- /regression/empty.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | return 0; 4 | } -------------------------------------------------------------------------------- /regression/tiny.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /regression/clean.bat: -------------------------------------------------------------------------------- 1 | rm -rf *.ast *.hil *.machine *.tac *.s *~ *.exe 2 | -------------------------------------------------------------------------------- /gc/gctest.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bjhua/dragon/HEAD/gc/gctest.exe -------------------------------------------------------------------------------- /regression/exn3.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | throw; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /gc/doc/README.Mac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bjhua/dragon/HEAD/gc/doc/README.Mac -------------------------------------------------------------------------------- /gc/libatomic_ops/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = src doc tests 2 | 3 | #distclean-local: 4 | -------------------------------------------------------------------------------- /gc/cord/de_win.ICO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bjhua/dragon/HEAD/gc/cord/de_win.ICO -------------------------------------------------------------------------------- /gc/doc/README.MacOSX: -------------------------------------------------------------------------------- 1 | See README.darwin for the latest Darwin/MacOSX information. 2 | -------------------------------------------------------------------------------- /regression/gen.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bjhua/dragon/HEAD/regression/gen.exe -------------------------------------------------------------------------------- /regression/gen2.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bjhua/dragon/HEAD/regression/gen2.exe -------------------------------------------------------------------------------- /gc/extra/gc.h: -------------------------------------------------------------------------------- 1 | /* This file is installed for backward compatibility. */ 2 | #include 3 | -------------------------------------------------------------------------------- /gc/gc_cpp.cpp: -------------------------------------------------------------------------------- 1 | // Visual C++ seems to prefer a .cpp extension to .cc 2 | #include "gc_cpp.ccxx" 3 | -------------------------------------------------------------------------------- /src/control/version.c: -------------------------------------------------------------------------------- 1 | #include "version.h" 2 | 3 | String_t Version_version = "Version 0.2"; 4 | -------------------------------------------------------------------------------- /gc/extra/gc_cpp.h: -------------------------------------------------------------------------------- 1 | /* This file is installed for backward compatibility. */ 2 | #include 3 | -------------------------------------------------------------------------------- /gc/include/extra/gc.h: -------------------------------------------------------------------------------- 1 | /* This file is installed for backward compatibility. */ 2 | #include 3 | -------------------------------------------------------------------------------- /src/lib/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef DEBUG_H 2 | #define DEBUG_H 3 | 4 | void Debug_printInt(int i); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/lib/io.h: -------------------------------------------------------------------------------- 1 | #ifndef IO_H 2 | #define IO_H 3 | 4 | int Io_printSpaces(long n); 5 | 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /src/lib/test.h: -------------------------------------------------------------------------------- 1 | #ifndef LIB_TEST_H 2 | #define LIB_TEST_H 3 | 4 | int Lib_test(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /gc/doc/README.uts: -------------------------------------------------------------------------------- 1 | Alistair Crooks supplied the port. He used Lexa C version 2.1.3 with 2 | -Xa to compile. 3 | -------------------------------------------------------------------------------- /gc/include/extra/gc_cpp.h: -------------------------------------------------------------------------------- 1 | /* This file is installed for backward compatibility. */ 2 | #include 3 | -------------------------------------------------------------------------------- /regression/test.c: -------------------------------------------------------------------------------- 1 | int main () 2 | { 3 | int x, y, z; 4 | 5 | (x = y) = z; 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /src/lib/random.h: -------------------------------------------------------------------------------- 1 | #ifndef RANDOM_H 2 | #define RANDOM_H 3 | 4 | int Random_nextInt(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/lib/system.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSTEM_H 2 | #define SYSTEM_H 3 | 4 | void System_run(char *cmd); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/lib/unused.h: -------------------------------------------------------------------------------- 1 | #ifndef UNUSED_H 2 | #define UNUSED_H 3 | 4 | #define UNUSED(x) (void) (x) 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /gc/configure_atomic_ops.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | P=`pwd`/libatomic_ops-install 3 | cd libatomic_ops 4 | ./configure --prefix=$P 5 | -------------------------------------------------------------------------------- /src/main/main-main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | int Main_main(int argc, char **argv); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/ssa/type-check.c: -------------------------------------------------------------------------------- 1 | #include "type-check.h" 2 | 3 | Ssa_Prog_t Ssa_typeCheck(Ssa_Prog_t p) { 4 | return p; 5 | } 6 | -------------------------------------------------------------------------------- /regression/add.c: -------------------------------------------------------------------------------- 1 | int dragon() { 2 | int a; 3 | a = 1; 4 | 5 | printi(a); 6 | return 0; 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/lib/random.c: -------------------------------------------------------------------------------- 1 | #include "random.h" 2 | #include 3 | 4 | int Random_nextInt(void) { 5 | return rand(); 6 | } 7 | -------------------------------------------------------------------------------- /src/runtime/main.c: -------------------------------------------------------------------------------- 1 | 2 | extern int dragon(void); 3 | 4 | int main(int argc, char **argv) { 5 | dragon(); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /regression/long-exp.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | int a; 4 | 5 | a = 1+2+3+4+5; 6 | printi (a); 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /src/lib/void.h: -------------------------------------------------------------------------------- 1 | #ifndef VOID_H 2 | #define VOID_H 3 | 4 | #include "string.h" 5 | 6 | String_t Void_toString(void *s); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | #include "main/main-main.h" 2 | 3 | int main(int argc, char **argv) { 4 | Main_main(argc, argv); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /gc/build_atomic_ops.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | P=`pwd`/libatomic_ops-install 3 | cd libatomic_ops 4 | ./configure --prefix=$P 5 | $MAKE CC=$CC install 6 | -------------------------------------------------------------------------------- /src/lib/double.h: -------------------------------------------------------------------------------- 1 | #ifndef DOUBLE_H 2 | #define DOUBLE_H 3 | 4 | #include "string.h" 5 | 6 | String_t Double_toString(double f); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/runtime/dragon-lib.h: -------------------------------------------------------------------------------- 1 | #ifndef DRAGON_LIB_H 2 | #define DRAGON_LIB_H 3 | 4 | long prints(char *s); 5 | long printi(long i); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /src/lib/void.c: -------------------------------------------------------------------------------- 1 | #include "void.h" 2 | #include "unused.h" 3 | 4 | String_t Void_toString(void *s) { 5 | UNUSED(s); 6 | return "()"; 7 | } 8 | -------------------------------------------------------------------------------- /regression/while.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | int i = 9; 4 | while (i){ 5 | i = i-1; 6 | } 7 | printi (i); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /src/ssa/out-ssa.h: -------------------------------------------------------------------------------- 1 | #ifndef SSA_OUT_SSA_H 2 | #define SSA_OUT_SSA_H 3 | 4 | #include "ssa.h" 5 | 6 | Ssa_Prog_t Ssa_outSsa(Ssa_Prog_t p); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/sunc/sparc.S: -------------------------------------------------------------------------------- 1 | .seg "text" 2 | .globl AO_test_and_set_full 3 | AO_test_and_set_full: 4 | retl 5 | ldstub [%o0],%o0 6 | -------------------------------------------------------------------------------- /regression/deadcode.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | int r; 4 | r = printi (1+2*3); 5 | return 0; 6 | r = r+1; 7 | r = r+1; 8 | return r; 9 | } 10 | -------------------------------------------------------------------------------- /regression/for-continue.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | int i=0; 4 | 5 | for (i=0; i<10; i=i+1) 6 | printi (i); 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /src/control/version.h: -------------------------------------------------------------------------------- 1 | #ifndef VERSION_H 2 | #define VERSION_H 3 | 4 | #include "../lib/string.h" 5 | 6 | extern String_t Version_version; 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/elaborate/check-ast.h: -------------------------------------------------------------------------------- 1 | #ifndef CHECK_AST_H 2 | #define CHECK_AST_H 3 | 4 | #include "../ast/ast.h" 5 | 6 | void Check_ast (Ast_Prog_t p); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/elaborate/lift-dec.h: -------------------------------------------------------------------------------- 1 | #ifndef LIFT_DEC_H 2 | #define LIFT_DEC_H 3 | 4 | #include "../ast/ast.h" 5 | 6 | Ast_Prog_t Lift_dec (Ast_Prog_t); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/main/compile.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPILE_H 2 | #define COMPILE_H 3 | 4 | #include "../lib/list.h" 5 | 6 | List_t Compile_compile(List_t files); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /regression/scope.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | int z = 2; 4 | { 5 | int z = 3; 6 | printi (z); 7 | } 8 | 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /src/hil/dead-code.h: -------------------------------------------------------------------------------- 1 | #ifndef HIL_DEAD_CODE_H 2 | #define HIL_DEAD_CODE_H 3 | 4 | #include "hil.h" 5 | 6 | Hil_Prog_t Hil_deadCode (Hil_Prog_t p); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/ssa/dead-code.h: -------------------------------------------------------------------------------- 1 | #ifndef SSA_DEAD_CODE_H 2 | #define SSA_DEAD_CODE_H 3 | 4 | #include "ssa.h" 5 | 6 | Ssa_Prog_t Ssa_deadCode(Ssa_Prog_t p); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/elaborate/elaborate.h: -------------------------------------------------------------------------------- 1 | #ifndef ELABORATE_H 2 | #define ELABORATE_H 3 | 4 | #include "../ast/ast.h" 5 | 6 | Ast_Prog_t Elaborate_ast (Ast_Prog_t); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/ssa/const-fold.h: -------------------------------------------------------------------------------- 1 | #ifndef SSA_CONST_FOLD_H 2 | #define SSA_CONST_FOLD_H 3 | 4 | #include "ssa.h" 5 | 6 | Ssa_Prog_t Ssa_constFold(Ssa_Prog_t p); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/ssa/const-prop.h: -------------------------------------------------------------------------------- 1 | #ifndef SSA_CONST_PROP_H 2 | #define SSA_CONST_PROP_H 3 | 4 | #include "ssa.h" 5 | 6 | Ssa_Prog_t Ssa_constProp(Ssa_Prog_t p); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/ssa/type-check.h: -------------------------------------------------------------------------------- 1 | #ifndef SSA_TYPE_CHECK_H 2 | #define SSA_TYPE_CHECK_H 3 | 4 | #include "ssa.h" 5 | 6 | Ssa_Prog_t Ssa_typeCheck(Ssa_Prog_t p); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /gc/callprocs: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | GC_DEBUG=1 3 | export GC_DEBUG 4 | $* 2>&1 | awk '{print "0x3e=c\""$0"\""};/^\t##PC##=/ {if ($2 != 0) {print $2"?i"}}' | adb $1 | sed "s/^ >/>/" 5 | -------------------------------------------------------------------------------- /src/elaborate/combine-stm.h: -------------------------------------------------------------------------------- 1 | #ifndef COMBINE_STM_H 2 | #define COMBINE_STM_H 3 | 4 | #include "../ast/ast.h" 5 | 6 | Ast_Prog_t Combine_stm (Ast_Prog_t); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/x86/peep-hole.h: -------------------------------------------------------------------------------- 1 | #ifndef PEEP_HOLE_H 2 | #define PEEP_HOLE_H 3 | 4 | #include "x86.h" 5 | 6 | X86_Prog_t PeepHole_shrink(X86_Prog_t p); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /gc/libatomic_ops/doc/Makefile.am: -------------------------------------------------------------------------------- 1 | # installed documentation 2 | # 3 | dist_pkgdata_DATA=COPYING LICENSING.txt README.txt COPYING README_stack.txt README_malloc.txt README_win32.txt 4 | -------------------------------------------------------------------------------- /regression/exp2.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | int i = 0; 4 | int j = 1; 5 | 6 | { 7 | int i = 3; 8 | int j = 4; 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /src/lexer/lex.h: -------------------------------------------------------------------------------- 1 | #ifndef LEX_H 2 | #define LEX_H 3 | 4 | #include "token.h" 5 | 6 | Token_t Lex_getToken(void); 7 | void Lex_init(String_t fileName); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/machine/machine-main.h: -------------------------------------------------------------------------------- 1 | #ifndef MACHINE_MAIN_H 2 | #define MACHINE_MAIN_H 3 | 4 | #include "machine.h" 5 | 6 | Machine_Prog_t Machine_main(Machine_Prog_t p); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/ssa/construct-ssa.h: -------------------------------------------------------------------------------- 1 | #ifndef SSA_CONSTRUCT_SSA_H 2 | #define SSA_CONSTRUCT_SSA_H 3 | 4 | #include "ssa.h" 5 | 6 | Ssa_Prog_t Ssa_constructSsa(Ssa_Prog_t p); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /regression/bool.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | int i = 1; 4 | int j = 10; 5 | 6 | @ 3 && 4; 7 | 8 | @ !3; 9 | 10 | @ 6 || 7; 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /gc/Mac_files/dataend.c: -------------------------------------------------------------------------------- 1 | /* 2 | dataend.c 3 | 4 | A hack to get the extent of global data for the Macintosh. 5 | 6 | by Patrick C. Beard. 7 | */ 8 | 9 | long __dataend; 10 | -------------------------------------------------------------------------------- /gc/libatomic_ops/AUTHORS: -------------------------------------------------------------------------------- 1 | Originally written by Hans Boehm, with some platform-dependent code 2 | imported from the Boehm-Demers-Weiser GC, where it was contributed 3 | by many others. 4 | 5 | -------------------------------------------------------------------------------- /src/control/command-line.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMAND_LINE_H 2 | #define COMMAND_LINE_H 3 | 4 | #include "../lib/list.h" 5 | 6 | List_t CommandLine_doarg (int argc, char **argv); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/hil/hil-main.h: -------------------------------------------------------------------------------- 1 | #ifndef HIL_MAIN_H 2 | #define HIL_MAIN_H 3 | 4 | #include "hil.h" 5 | #include "../ssa/ssa.h" 6 | 7 | Ssa_Prog_t Hil_main (Hil_Prog_t p); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/hil/trans-hil.h: -------------------------------------------------------------------------------- 1 | #ifndef HIL_TRANS_H 2 | #define HIL_TRANS_H 3 | 4 | #include "hil.h" 5 | #include "../ssa/ssa.h" 6 | 7 | Ssa_Prog_t Hil_trans (Hil_Prog_t p); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/machine/gen-frame.h: -------------------------------------------------------------------------------- 1 | #ifndef GEN_FRAME_H 2 | #define GEN_FRAME_H 3 | 4 | 5 | #include "machine.h" 6 | 7 | Machine_Prog_t Machine_genFrame(Machine_Prog_t p); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /gc/Mac_files/datastart.c: -------------------------------------------------------------------------------- 1 | /* 2 | datastart.c 3 | 4 | A hack to get the extent of global data for the Macintosh. 5 | 6 | by Patrick C. Beard. 7 | */ 8 | 9 | long __datastart; 10 | -------------------------------------------------------------------------------- /regression/dup-field.c: -------------------------------------------------------------------------------- 1 | class s {int x; int x;} 2 | 3 | int dragon () 4 | { 5 | int x; 6 | int x; 7 | int z; 8 | s k; 9 | 10 | k.x = 1; 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /regression/unclosed-string.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | string s = "hello; 4 | { 5 | int s = 0; 6 | string t = "; 7 | return s; 8 | } 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /src/machine/gen-layout.h: -------------------------------------------------------------------------------- 1 | #ifndef GEN_LAYOUT_H 2 | #define GEN_LAYOUT_H 3 | 4 | 5 | #include "machine.h" 6 | 7 | Machine_Prog_t Machine_genLayout(Machine_Prog_t p); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/parser/parse.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSE_H 2 | #define PARSE_H 3 | 4 | #include "../lib/string.h" 5 | #include "../ast/ast.h" 6 | 7 | Ast_Prog_t Parse_parse (String_t file); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /regression/exp.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | int a; 4 | int b; 5 | int c; 6 | int[] d; 7 | 8 | a = b + (-c); 9 | 10 | d[0] = 1; 11 | 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/ssa/ssa-main.h: -------------------------------------------------------------------------------- 1 | #ifndef SSA_MAIN_H 2 | #define SSA_MAIN_H 3 | 4 | #include "ssa.h" 5 | #include "../machine/machine.h" 6 | 7 | Machine_Prog_t Ssa_main(Ssa_Prog_t p); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/elaborate/trans-ast.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANS_AST_H 2 | #define TRANS_AST_H 3 | 4 | #include "../ast/ast.h" 5 | #include "../hil/hil.h" 6 | 7 | Hil_Prog_t Trans_ast (Ast_Prog_t); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/ssa/trans-ssa.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANS_SSA_H 2 | #define TRANS_SSA_H 3 | 4 | #include "ssa.h" 5 | #include "../machine/machine.h" 6 | 7 | Machine_Prog_t Trans_ssa(Ssa_Prog_t p); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /regression/break.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | int i=0; 4 | 5 | while (i<10){ 6 | printi (i); 7 | prints ("\n"); 8 | if (i==5) 9 | break; 10 | i = i+1; 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /regression/sum.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | int i = 0; 4 | int sum = 0; 5 | 6 | for (i=0; i<=100; i=i+1) 7 | sum = sum + i; 8 | 9 | printi (sum); 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/lib/append-list.c: -------------------------------------------------------------------------------- 1 | #include "append-list.h" 2 | 3 | #define T AppendList_t 4 | 5 | struct T { 6 | int junk; 7 | }; 8 | 9 | T AppendList_new() { 10 | return 0; 11 | } 12 | 13 | #undef T 14 | -------------------------------------------------------------------------------- /src/x86/x86-codegen.h: -------------------------------------------------------------------------------- 1 | #ifndef X86_CODEGEN_H 2 | #define X86_CODEGEN_H 3 | 4 | #include "../machine/machine.h" 5 | #include "x86.h" 6 | 7 | X86_Prog_t X86_codegen(Machine_Prog_t p); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /regression/cmd-line.c: -------------------------------------------------------------------------------- 1 | int dragon (int argc, string[] argv) 2 | { 3 | int i; 4 | 5 | for (i=0; i 2 | 3 | int main () 4 | { 5 | int i; 6 | for (i=0; i<100; i++){ 7 | // srand (clock()); 8 | printf ("%d\n", rand ()); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /src/atoms/atoms.h: -------------------------------------------------------------------------------- 1 | #ifndef ATOMS_H 2 | #define ATOMS_H 3 | 4 | #include "atype.h" 5 | #include "class.h" 6 | #include "dec.h" 7 | #include "id.h" 8 | #include "label.h" 9 | #include "operator.h" 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/c-codegen/c-codegen.h: -------------------------------------------------------------------------------- 1 | #ifndef C_CODEGEN_H 2 | #define C_CODEGEN_H 3 | 4 | #include "../lib/file.h" 5 | #include "../machine/machine.h" 6 | 7 | int C_codegen(File_t file, Machine_Prog_t p); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/elaborate/elaborate-main.h: -------------------------------------------------------------------------------- 1 | #ifndef ELABORATE_MAIN_H 2 | #define ELABORATE_MAIN_H 3 | 4 | #include "../ast/ast.h" 5 | #include "../hil/hil.h" 6 | 7 | Hil_Prog_t Elaborate_main (Ast_Prog_t p); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/runtime/dragon-lib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dragon-lib.h" 3 | 4 | long prints(char *s) { 5 | return printf("%s", s); 6 | } 7 | 8 | long printi(long i) { 9 | return printf("%ld", i); 10 | } 11 | -------------------------------------------------------------------------------- /src/machine/runtime.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNTIME_H 2 | #define RUNTIME_H 3 | 4 | #include "../atoms/atoms.h" 5 | 6 | extern Id_t Runtime_array; 7 | extern Id_t Runtime_class; 8 | 9 | void Runtime_init(void); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/lib/io.c: -------------------------------------------------------------------------------- 1 | #include "io.h" 2 | #include 3 | #include 4 | 5 | int Io_printSpaces(long n) { 6 | assert(n >= 0); 7 | while (n-- > 0) { 8 | printf(" "); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /src/ssa/dead-block.h: -------------------------------------------------------------------------------- 1 | #ifndef SSA_DEAD_BLOCK_H 2 | #define SSA_DEAD_BLOCK_H 3 | 4 | #include "ssa.h" 5 | 6 | // cutting blocks unreachable from the entry block 7 | Ssa_Prog_t Ssa_deadBlock(Ssa_Prog_t p); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/lib/append-list.h: -------------------------------------------------------------------------------- 1 | #ifndef APPEND_LIST_H 2 | #define APPEND_LIST_H 3 | 4 | #include "list.h" 5 | 6 | #define T AppendList_t 7 | 8 | typedef struct T *T; 9 | 10 | T AppendList_new(void); 11 | 12 | #undef T 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/lib/int.h: -------------------------------------------------------------------------------- 1 | #ifndef INT_H 2 | #define INT_H 3 | 4 | #include "string.h" 5 | 6 | extern const int Int_zero; 7 | 8 | String_t Int_toString(long i); 9 | 10 | long Int_fromString(String_t s, long *result); 11 | 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /regression/for.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | int sum = 0; 4 | int i; 5 | 6 | for (i = 0; i<=100; i=i+1) 7 | sum = sum +i; 8 | 9 | prints ("1+2+...+100 = "); 10 | printi (sum); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/lib/property-list.c: -------------------------------------------------------------------------------- 1 | #include "property-list.h" 2 | 3 | #define T Plist_t 4 | 5 | T Plist_new(void) { 6 | return List_new(); 7 | } 8 | 9 | //int Plist_equals(T p1, T p2) { 10 | // return p1 == p2; 11 | //} 12 | 13 | #undef T 14 | -------------------------------------------------------------------------------- /regression/exn.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | try{ 4 | prints ("ready to throw\n"); 5 | throw; 6 | prints ("after thrown\n"); 7 | } 8 | catch{ 9 | prints ("caught\n"); 10 | } 11 | prints ("end\n"); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/c-codegen/c-codegen-main.h: -------------------------------------------------------------------------------- 1 | #ifndef C_CODEGEN_MAIN_H 2 | #define C_CODEGEN_MAIN_H 3 | 4 | #include "../lib/file.h" 5 | #include "../lib/string.h" 6 | #include "../machine/machine.h" 7 | 8 | String_t C_codegen_main (Machine_Prog_t p); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/x86/x86-main.h: -------------------------------------------------------------------------------- 1 | #ifndef X86_MAIN_H 2 | #define X86_MAIN_H 3 | 4 | #include "../lib/tuple.h" 5 | #include "../machine/machine.h" 6 | #include "../x86/x86.h" 7 | 8 | /* a tuple of the IR and its assembly */ 9 | Tuple_t X86_main(Machine_Prog_t p); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/lib/debug.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "debug.h" 3 | 4 | 5 | #ifndef NDEBUG 6 | #define DEBUG_FLAG 1 7 | #else 8 | #define DEBUG_FLAG 0 9 | #endif 10 | 11 | 12 | void Debug_printInt(int i) { 13 | if (DEBUG_FLAG) 14 | printf("%d\n", i); 15 | else; 16 | } 17 | -------------------------------------------------------------------------------- /gc/leak_detector.h: -------------------------------------------------------------------------------- 1 | #define GC_DEBUG 2 | #include "gc.h" 3 | #define malloc(n) GC_MALLOC(n) 4 | #define calloc(m,n) GC_MALLOC((m)*(n)) 5 | #define free(p) GC_FREE(p) 6 | #define realloc(p,n) GC_REALLOC((p),(n)) 7 | #undef strdup 8 | #define strdup(s) GC_STRDUP((s)) 9 | #define CHECK_LEAKS() GC_gcollect() 10 | -------------------------------------------------------------------------------- /regression/continue.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | int i=0; 4 | int j=10; 5 | 6 | while (i<=j){ 7 | prints ("i==="); 8 | printi (i); 9 | prints ("\nj==="); 10 | printi (j); 11 | prints ("\n\n"); 12 | 13 | i = i+1; 14 | continue; 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /regression/scope2.c: -------------------------------------------------------------------------------- 1 | class x 2 | { 3 | x x; 4 | } 5 | 6 | x x (x x) 7 | { 8 | x y = new x (null); 9 | y.x = null; 10 | { 11 | x y = new x(null); 12 | y.x = null; 13 | return y.x; 14 | } 15 | return y.x; 16 | } 17 | 18 | int dragon () 19 | { 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/lib/system.c: -------------------------------------------------------------------------------- 1 | #include "system.h" 2 | #include "error.h" 3 | #include 4 | 5 | void System_run(char *s) { 6 | if (!s) 7 | Error_error("invalid command\n"); 8 | 9 | // the return value is platform-dependent, so it's 10 | // useless to check this. 11 | system(s); 12 | } 13 | -------------------------------------------------------------------------------- /gc/bdw-gc.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: Boehm-Demers-Weiser Conservative Garbage Collector 7 | Description: A garbage collector for C and C++ 8 | Version: @PACKAGE_VERSION@ 9 | Libs: -L${libdir} -lgc 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /gc/include/leak_detector.h: -------------------------------------------------------------------------------- 1 | #define GC_DEBUG 2 | #include "gc.h" 3 | #define malloc(n) GC_MALLOC(n) 4 | #define calloc(m,n) GC_MALLOC((m)*(n)) 5 | #define free(p) GC_FREE(p) 6 | #define realloc(p,n) GC_REALLOC((p),(n)) 7 | #undef strdup 8 | #define strdup(s) GC_STRDUP((s)) 9 | #define CHECK_LEAKS() GC_gcollect() 10 | -------------------------------------------------------------------------------- /gc/bdw-gc.pc: -------------------------------------------------------------------------------- 1 | prefix=/usr/local 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: Boehm-Demers-Weiser Conservative Garbage Collector 7 | Description: A garbage collector for C and C++ 8 | Version: 7.2alpha4 9 | Libs: -L${libdir} -lgc 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /gc/ia64_save_regs_in_stack.s: -------------------------------------------------------------------------------- 1 | .text 2 | .align 16 3 | .global GC_save_regs_in_stack 4 | .proc GC_save_regs_in_stack 5 | GC_save_regs_in_stack: 6 | .body 7 | flushrs 8 | ;; 9 | mov r8=ar.bsp 10 | br.ret.sptk.few rp 11 | .endp GC_save_regs_in_stack 12 | 13 | -------------------------------------------------------------------------------- /src/ssa/trivial-block.h: -------------------------------------------------------------------------------- 1 | #ifndef SSA_TRIVIAL_BLOCK_H 2 | #define SSA_TRIVIAL_BLOCK_H 3 | 4 | #include "ssa.h" 5 | 6 | // a trivial block is of the form: 7 | /* 8 | L1: 9 | jump L2 10 | */ 11 | // Then all jumps to L1 can be replaced with a jump to L2 12 | Ssa_Prog_t Ssa_trivialBlock(Ssa_Prog_t p); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /gc/extra/gcname.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | if (GC_ALPHA_VERSION == GC_NOT_ALPHA) { 7 | printf("gc%d.%d", GC_VERSION_MAJOR, GC_VERSION_MINOR); 8 | } else { 9 | printf("gc%d.%dalpha%d", GC_VERSION_MAJOR, 10 | GC_VERSION_MINOR, GC_ALPHA_VERSION); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/lib/property-list.h: -------------------------------------------------------------------------------- 1 | #ifndef PROPERTY_LIST_H 2 | #define PROPERTY_LIST_H 3 | 4 | #include "list.h" 5 | #include "poly.h" 6 | 7 | #define T Plist_t 8 | 9 | typedef List_t T; 10 | 11 | typedef T (*Poly_tyPlist)(Poly_t); 12 | 13 | T Plist_new(void); 14 | /* int PropertyList_equals (T, T); */ 15 | 16 | #undef T 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /regression/field.c: -------------------------------------------------------------------------------- 1 | class a 2 | { 3 | int x; 4 | int y; 5 | } 6 | 7 | int printa (a z) 8 | { 9 | printi (z.x); 10 | prints (" "); 11 | printi (z.y); 12 | prints ("\n"); 13 | return 0; 14 | } 15 | 16 | int dragon () 17 | { 18 | int[] z = new int [10]; 19 | 20 | z[0] = 999; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /regression/hello.c: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | int x; 4 | } 5 | 6 | class B 7 | { 8 | A x; 9 | B y; 10 | } 11 | 12 | int dragon (int argc, string[] argv) 13 | { 14 | prints ("hello, world\n"); 15 | f (); 16 | return 0; 17 | } 18 | 19 | int f () 20 | { 21 | A a; 22 | 23 | a = new A (999); 24 | printi (a.x); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/machine/runtime.c: -------------------------------------------------------------------------------- 1 | #include "runtime.h" 2 | 3 | Id_t Runtime_array = 0; 4 | Id_t Runtime_class = 0; 5 | 6 | void Runtime_init(void) { 7 | Runtime_class = 8 | Id_fromString("Dragon_Runtime_alloc_class"); 9 | 10 | Runtime_array = 11 | Id_fromString("Dragon_Runtime_alloc_array"); 12 | // return; 13 | } 14 | -------------------------------------------------------------------------------- /regression/call.c: -------------------------------------------------------------------------------- 1 | int f (int first, int second, int third) 2 | { 3 | prints ("the first one: "); 4 | printi (first); 5 | prints ("\nthe second one: "); 6 | printi (second); 7 | prints ("\nthe third one: "); 8 | printi (third); 9 | return 0; 10 | } 11 | 12 | 13 | int dragon () 14 | { 15 | f (3, 4, 5); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /gc/gctest.gc.log: -------------------------------------------------------------------------------- 1 | Completed 6 tests 2 | Allocated 3437682 collectable objects 3 | Allocated 1212 uncollectable objects 4 | Allocated 7252659 atomic objects 5 | Allocated 137744 stubborn objects 6 | Finalized 13354/13360 objects - finalization is probably ok 7 | Total number of bytes allocated is 568179926 8 | Final heap size is 8982528 bytes 9 | Collector appears to work 10 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops_sysdeps.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Include the appropriate system-dependent assembly file, if any. 3 | * This is used only if the platform supports neither inline assembly 4 | * code, nor appropriate compiler intrinsics. 5 | */ 6 | 7 | #if !defined(__GNUC__) && (defined(sparc) || defined(__sparc)) 8 | # include "atomic_ops/sysdeps/sunc/sparc.S" 9 | #endif 10 | -------------------------------------------------------------------------------- /regression/elab-example.c: -------------------------------------------------------------------------------- 1 | class x {x x; y y;} 2 | class y = {x x; y y;} 3 | 4 | int f () 5 | { 6 | int z = 1; 7 | printi (z); 8 | { 9 | int z = 2; 10 | printi (z); 11 | } 12 | g (); 13 | return 0; 14 | } 15 | 16 | int g () 17 | { 18 | // @ f (); 19 | return 0; 20 | } 21 | 22 | int dragon () 23 | { 24 | f (); 25 | return 0; 26 | } 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /gc/doc/README.OS2: -------------------------------------------------------------------------------- 1 | The code assumes static linking, and a single thread. The editor de has 2 | not been ported. The cord test program has. The supplied OS2_MAKEFILE 3 | assumes the IBM C Set/2 environment, but the code shouldn't. 4 | 5 | Since we haven't figured out hoe to do perform partial links or to build static 6 | libraries, clients currently need to link against a long list of executables. 7 | -------------------------------------------------------------------------------- /src/lib/char.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAR_H 2 | #define CHAR_H 3 | 4 | #include "string.h" 5 | 6 | /* return the size of a "blank", in the number of ' ''s. 7 | * return 0 if c is not a "blank". 8 | */ 9 | int Char_blankSize(int c); 10 | 11 | int Char_isAlpha(int c); 12 | 13 | int Char_isBlank(int c); 14 | 15 | int Char_isDigit(int c); 16 | 17 | String_t Char_toString(int c); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/lib/dlist.h: -------------------------------------------------------------------------------- 1 | #ifndef DLIST_H 2 | #define DLIST_H 3 | 4 | // Doubly-linked list. 5 | 6 | #include "poly.h" 7 | 8 | #define T Dlist_t 9 | 10 | typedef struct T *T; 11 | 12 | // CDT 13 | struct T { 14 | Poly_t data; 15 | T next; 16 | T prev; 17 | }; 18 | 19 | 20 | T Dlist_new(void); 21 | 22 | void Dlist_insertLast(T, Poly_t); 23 | 24 | 25 | #undef T 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/lib/poly.h: -------------------------------------------------------------------------------- 1 | #ifndef POLY_H 2 | #define POLY_H 3 | 4 | #define T Poly_t 5 | 6 | typedef void *T; 7 | 8 | typedef long (*Poly_tyEquals)(T, T); 9 | 10 | typedef char *(*Poly_tyToString)(T); 11 | 12 | typedef T (*Poly_tyId)(T); 13 | 14 | typedef long (*tyHashCode)(T); 15 | 16 | typedef void (*Poly_tyVoid)(T); 17 | 18 | typedef long (*Poly_tyPred)(T); 19 | 20 | #undef T 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/atoms/label.h: -------------------------------------------------------------------------------- 1 | #ifndef LABEL_H 2 | #define LABEL_H 3 | 4 | #include "../lib/property-list.h" 5 | #include "../lib/string.h" 6 | 7 | #define T Label_t 8 | 9 | typedef struct T *T; 10 | 11 | T Label_new(void); 12 | int Label_hashCode(T x); 13 | String_t Label_toString(T x); 14 | int Label_equals(T, T); 15 | Plist_t Label_plist(T); 16 | void Label_print(T); 17 | 18 | #undef T 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /gc/a.c: -------------------------------------------------------------------------------- 1 | #include "include/gc.h" 2 | #include 3 | #include 4 | 5 | int notmain() 6 | { 7 | int i; 8 | 9 | GC_INIT(); /* Optional on Linux/X86; see below. */ 10 | for (i = 0; i < 10000000; ++i) 11 | { 12 | int *q = (int *) GC_MALLOC_ATOMIC(sizeof(int)); 13 | if (i % 100000 == 0) 14 | printf("Heap size = %zu\n", GC_get_heap_size()); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /gc/a.c~: -------------------------------------------------------------------------------- 1 | #include "include/gc.h" 2 | #include 3 | #include 4 | 5 | int notmain() 6 | { 7 | int i; 8 | 9 | GC_INIT(); /* Optional on Linux/X86; see below. */ 10 | for (i = 0; i < 10000000; ++i) 11 | { 12 | int *q = (int *) GC_MALLOC_ATOMIC(sizeof(int)); 13 | if (i % 100000 == 0) 14 | printf("Heap size = %d\n", GC_get_heap_size()); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/README: -------------------------------------------------------------------------------- 1 | There are two kinds of entities in this directory: 2 | 3 | - Subdirectories corresponding to specific compilers (or compiler/OS combinations). 4 | Each of these includes one or more architecture-specific headers. 5 | 6 | - More generic header files corresponding to a particular ordering and/or 7 | atomicity property that might be shared by multiple hardware platforms. 8 | -------------------------------------------------------------------------------- /regression/break-continue.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | int i=0; 4 | 5 | prints ("break\n"); 6 | 7 | while (i<10){ 8 | printi (i); 9 | prints ("\n"); 10 | if (i==5) 11 | break; 12 | i = i+1; 13 | } 14 | 15 | prints ("continue\n"); 16 | 17 | for (i=0; i<10; i=i+1){ 18 | if (i%3!=0) 19 | continue; 20 | printi (i); 21 | prints ("\n"); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/ssa/const-and-dead.h: -------------------------------------------------------------------------------- 1 | #ifndef SSA_CONST_AND_DEAD_H 2 | #define SSA_CONST_AND_DEAD_H 3 | 4 | // This pass consists of many passes, which does 5 | // any constant propagation and constant folding, as well 6 | // as any dead code (dec) elimination. 7 | // This pass should run when any other optimization is 8 | // done. 9 | 10 | #include "ssa.h" 11 | 12 | Ssa_Prog_t Ssa_constAndDead(Ssa_Prog_t p); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /regression/exn2.c: -------------------------------------------------------------------------------- 1 | int dragon () 2 | { 3 | int x; 4 | x = x; 5 | x = 99; 6 | printi (x); 7 | try { 8 | prints ("before\n"); 9 | f (); 10 | prints ("after\n"); 11 | } 12 | catch { 13 | prints ("caught\n"); 14 | } 15 | 16 | prints ("after try\n"); 17 | return 0; 18 | } 19 | 20 | int f () 21 | { 22 | return g (); 23 | } 24 | 25 | int g () 26 | { 27 | throw; 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/control/region.h: -------------------------------------------------------------------------------- 1 | #ifndef REGION_H 2 | #define REGION_H 3 | 4 | #include "../lib/string.h" 5 | #include "coordinate.h" 6 | 7 | #define T Region_t 8 | 9 | typedef struct Region_t *Region_t; 10 | 11 | T Region_new(Coordinate_t from, Coordinate_t to); 12 | T Region_bogus(void); 13 | Coordinate_t Region_from(T t); 14 | Coordinate_t Region_to(T t); 15 | String_t Region_toString(T t); 16 | 17 | #undef T 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/lib/dot.h: -------------------------------------------------------------------------------- 1 | #ifndef DOT_H 2 | #define DOT_H 3 | 4 | #include "string.h" 5 | #include "file.h" 6 | #include "poly.h" 7 | 8 | #define T Dot_t 9 | 10 | typedef struct T *T; 11 | 12 | T Dot_new(Poly_tyPrint printer); 13 | 14 | // for the "info" arg, passing 0 for non-existing ones 15 | void Dot_insert(T d, Poly_t from, Poly_t to, Poly_t info); 16 | 17 | void Dot_toJpg(T d, String_t fname); 18 | 19 | #undef T 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /gc/doc/README.dj: -------------------------------------------------------------------------------- 1 | [Original version supplied by Xiaokun Zhu ] 2 | [This version came mostly from Gary Leavens. ] 3 | 4 | Look first at Makefile.dj, and possibly change the definitions of 5 | RM and MV if you don't have rm and mv installed. 6 | Then use Makefile.dj to compile the garbage collector. 7 | For example, you can do: 8 | 9 | make -f Makefile.dj test 10 | 11 | All the tests should work fine. 12 | 13 | -------------------------------------------------------------------------------- /regression/array.c: -------------------------------------------------------------------------------- 1 | int f (int[] a) 2 | { 3 | int x = 9999; 4 | 5 | a[0] = a[9] = x; 6 | return 0; 7 | } 8 | 9 | int dragon () 10 | { 11 | int[] a = new int[10]; 12 | int i; 13 | 14 | for (i=0; i<10; i=i+1){ 15 | for (i = 1; i<10; i=i+1){ 16 | a[i = i] = i; 17 | } 18 | } 19 | 20 | f (a); 21 | for (i=0; i<10; i=i+1){ 22 | printi (a[i]); 23 | prints (" "); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS=sysdeps 2 | 3 | EXTRA_DIST=generalize-small.template 4 | 5 | #Private Headers 6 | private_HEADERS=generalize.h generalize-small.h 7 | privatedir=${includedir}/atomic_ops/ 8 | 9 | generalize-small.h: generalize-small.template 10 | sed -e s:XSIZE:char:g -e s:XCTYPE:char:g $? > $@ 11 | sed -e s:XSIZE:short:g -e s:XCTYPE:short:g $? >> $@ 12 | sed -e s:XSIZE:int:g -e s:XCTYPE:int:g $? >> $@ 13 | -------------------------------------------------------------------------------- /src/lib/error.c: -------------------------------------------------------------------------------- 1 | #include "error.h" 2 | #include 3 | #include 4 | 5 | void Error_error(const char *s) { 6 | fprintf(stderr, "Error: %s\n", s); 7 | exit(1); 8 | } 9 | 10 | void Error_error2(const char *s, const char *s2) { 11 | fprintf(stderr, "Error: %s %s\n", s, s2); 12 | exit(1); 13 | } 14 | 15 | //void Error_fatal(const char *s) { 16 | // fprintf(stderr, "Error: %s\n", s); 17 | // exit(1); 18 | //} 19 | -------------------------------------------------------------------------------- /src/atoms/id.h: -------------------------------------------------------------------------------- 1 | #ifndef ID_H 2 | #define ID_H 3 | 4 | #include "../lib/property-list.h" 5 | #include "../lib/string.h" 6 | 7 | #define T Id_t 8 | 9 | typedef struct T *T; 10 | 11 | T Id_fromString(String_t s); 12 | T Id_bogus(void); 13 | T Id_newNoName(void); 14 | long Id_hashCode(T x); 15 | void Id_init(void); 16 | String_t Id_toString(T x); 17 | long Id_equals(T, T); 18 | Plist_t Id_plist(T); 19 | void Id_print(T); 20 | 21 | #undef T 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/control/coordinate.h: -------------------------------------------------------------------------------- 1 | #ifndef COORDINATE_H 2 | #define COORDINATE_H 3 | 4 | #include "../lib/string.h" 5 | 6 | #define T Coordinate_t 7 | 8 | typedef struct Coordinate_t *Coordinate_t; 9 | 10 | T Coordinate_new(String_t file, int line, int column); 11 | T Coordinate_bogus(void); 12 | String_t Coordinate_file(T t); 13 | int Coordinate_column(T t); 14 | int Coordinate_line(T t); 15 | String_t Coordinate_toString(T t); 16 | 17 | #undef T 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /gc/build_atomic_ops.sh.cygwin: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # We install through the temporary directory in case pwd contains spaces, 3 | # which otherwise breaks the build machinery. 4 | # This is a gross hack and probably breaks incremental rebuilds 5 | mkdir libatomic_ops-install 6 | P=`pwd` 7 | Q=`mktemp -d` 8 | ln -s "$P" $Q/dir 9 | cd $Q/dir/libatomic_ops 10 | ./configure --prefix=$Q/dir/libatomic_ops-install 11 | $MAKE CC=$CC install 12 | cd / 13 | rm $Q/dir 14 | rmdir $Q 15 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS=atomic_ops 2 | 3 | AM_CFLAGS=@PICFLAG@ 4 | 5 | include_HEADERS=atomic_ops.h atomic_ops_stack.h atomic_ops_malloc.h 6 | lib_LIBRARIES = libatomic_ops.a libatomic_ops_gpl.a 7 | if NEED_ASM 8 | libatomic_ops_a_SOURCES = atomic_ops.c atomic_ops_sysdeps.S 9 | else 10 | libatomic_ops_a_SOURCES = atomic_ops.c 11 | endif 12 | 13 | libatomic_ops_gpl_a_SOURCES = atomic_ops_stack.c atomic_ops_malloc.c 14 | 15 | EXTRA_DIST=Makefile.msft 16 | 17 | -------------------------------------------------------------------------------- /src/lib/file.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE_H 2 | #define FILE_H 3 | 4 | #include 5 | #include "string.h" 6 | #include "poly.h" 7 | 8 | #define T File_t 9 | 10 | typedef FILE *T; 11 | 12 | typedef T (*Poly_tyPrint)(T, Poly_t); 13 | 14 | int File_flush(T); 15 | 16 | int File_saveToFile(String_t fname, Poly_tyPrint print, Poly_t x); 17 | 18 | T File_open(String_t fname, String_t mode); 19 | 20 | void File_write(T, String_t s); 21 | 22 | void File_close(T); 23 | 24 | #undef T 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/atoms/class.h: -------------------------------------------------------------------------------- 1 | #ifndef CLASS_H 2 | #define CLASS_H 3 | 4 | #include "atype.h" 5 | #include "id.h" 6 | #include "../lib/file.h" 7 | #include "../lib/string.h" 8 | #include "../lib/list.h" 9 | 10 | #define T Class_t 11 | 12 | typedef struct T *T; 13 | 14 | struct T { 15 | Id_t name; 16 | // List 17 | List_t decs; 18 | }; 19 | 20 | T Class_new(Id_t, List_t); 21 | 22 | String_t Class_toString(T); 23 | 24 | File_t Class_print(File_t file, T); 25 | 26 | #undef T 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/lib/box.h: -------------------------------------------------------------------------------- 1 | #ifndef BOX_H 2 | #define BOX_H 3 | 4 | #include "poly.h" 5 | #include "string.h" 6 | #include "file.h" 7 | #include "list.h" 8 | 9 | #define T Box_t 10 | 11 | typedef struct T *T; 12 | 13 | T Box_str(String_t str); 14 | 15 | T Box_h(T, ...); 16 | 17 | T Box_hlist(List_t); 18 | 19 | T Box_v(T, ...); 20 | 21 | T Box_vlist(List_t); 22 | 23 | T Box_indent(T, int); 24 | 25 | void Box_print(T, void (*)(String_t)); 26 | 27 | void Box_output(T, File_t); 28 | 29 | #undef T 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /regression/list.c: -------------------------------------------------------------------------------- 1 | class list 2 | { 3 | int data; 4 | list next; 5 | } 6 | 7 | list List_create() 8 | { 9 | return new list (1, new list (2, new list (3, new list (4, null)))); 10 | } 11 | 12 | int List_print (list l) 13 | { 14 | if (l == null) 15 | return 0; 16 | 17 | printi (l.data); 18 | prints (", "); 19 | List_print (l.next); 20 | return 0; 21 | } 22 | 23 | int dragon (int argc, string[] argv) 24 | { 25 | list l = List_create (); 26 | List_print (l); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /src/ssa/union-block.h: -------------------------------------------------------------------------------- 1 | #ifndef SSA_UNION_BLOCK_H 2 | #define SSA_UNION_BLOCK_H 3 | 4 | #include "ssa.h" 5 | 6 | // This code union blocks of this form: 7 | /* 8 | L1: 9 | stms1 10 | jump L2 11 | 12 | L2: 13 | stms2 14 | jump L3 15 | 16 | ============> 17 | L1: 18 | stms1 19 | stms2 20 | jump L3 21 | */ 22 | // L2 should only have one predecessor L1, and L1 has one 23 | // successor L2 24 | Ssa_Prog_t Ssa_unionBlock(Ssa_Prog_t p); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /gc/extra/add_gc_prefix.c: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | 4 | int main(argc, argv, envp) 5 | int argc; 6 | char ** argv; 7 | char ** envp; 8 | { 9 | int i; 10 | 11 | for (i = 1; i < argc; i++) { 12 | if (GC_ALPHA_VERSION == GC_NOT_ALPHA) { 13 | printf("gc%d.%d/%s ", GC_VERSION_MAJOR, GC_VERSION_MINOR, argv[i]); 14 | } else { 15 | printf("gc%d.%dalpha%d/%s ", GC_VERSION_MAJOR, 16 | GC_VERSION_MINOR, GC_ALPHA_VERSION, argv[i]); 17 | } 18 | } 19 | return(0); 20 | } 21 | -------------------------------------------------------------------------------- /src/lib/char-buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAR_BUFFER_H 2 | #define CHAR_BUFFER_H 3 | 4 | #include "string.h" 5 | 6 | #define T CharBuffer_t 7 | 8 | typedef struct T *T; 9 | 10 | T CharBuffer_new(void); 11 | 12 | void CharBuffer_append(T x, int c); 13 | 14 | void CharBuffer_appendString(T x, String_t s); 15 | 16 | long CharBuffer_numItems(T x); 17 | 18 | void CharBuffer_resetIndex(T x); 19 | 20 | String_t CharBuffer_toString(T x); 21 | 22 | String_t CharBuffer_toStringBeforeClear(T x); 23 | 24 | #undef T 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/control/pass.h: -------------------------------------------------------------------------------- 1 | #ifndef PASS_H 2 | #define PASS_H 3 | 4 | #include "../lib/string.h" 5 | #include "../lib/poly.h" 6 | #include "control.h" 7 | 8 | typedef struct { 9 | String_t name; // name of a compilation pass 10 | Verbose_t level; // at what level to see 11 | Poly_t thunk; // argument to this pass 12 | Poly_t (*action)(Poly_t); // actions. 13 | } Pass_t; 14 | 15 | Pass_t Pass_new(String_t, Verbose_t, Poly_t, Poly_t (*)(Poly_t)); 16 | 17 | Poly_t Pass_doit(Pass_t *pass); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/machine/machine-main.c: -------------------------------------------------------------------------------- 1 | #include "../control/pass.h" 2 | #include "gen-frame.h" 3 | #include "gen-layout.h" 4 | #include "machine-main.h" 5 | 6 | Machine_Prog_t Machine_main(Machine_Prog_t p) { 7 | Pass_t genFrame, genLayout; 8 | 9 | genFrame = Pass_new("genFrame", VERBOSE_SUBPASS, p, (Poly_tyId) Machine_genFrame); 10 | p = Pass_doit(&genFrame); 11 | 12 | genLayout = Pass_new("genLayout", VERBOSE_SUBPASS, p, (Poly_tyId) Machine_genLayout); 13 | p = Pass_doit(&genLayout); 14 | 15 | return p; 16 | } 17 | -------------------------------------------------------------------------------- /gc/tests/smash_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test that overwrite error detection works reasonably. 3 | */ 4 | #define GC_DEBUG 5 | #include 6 | #include 7 | 8 | #define COUNT 7000 9 | #define SIZE 40 10 | 11 | char * A[COUNT]; 12 | 13 | int main () 14 | { 15 | int i; 16 | char *p; 17 | 18 | GC_INIT(); 19 | 20 | for (i = 0; i < COUNT; ++i) { 21 | A[i] = p = GC_MALLOC(SIZE); 22 | 23 | if (i%3000 == 0) GC_gcollect(); 24 | if (i%5678 == 0) p[SIZE + i/2000] = 42; 25 | } 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/lib/string.h: -------------------------------------------------------------------------------- 1 | #ifndef STRING_H 2 | #define STRING_H 3 | 4 | #define T String_t 5 | 6 | typedef char *T; 7 | 8 | long String_equals(T x, T y); 9 | T String_new(char *s); 10 | T String_concat(char *s, ...); 11 | /*void String_append (T, T);*/ 12 | T String_fromArray(long size, char *array[], char *sep); 13 | long String_size(T s); 14 | T String_toString(T x); 15 | long String_hashCode(T x); 16 | void String_print(T x); 17 | //File_t String_printAsIs (File_t file, T); 18 | T String_toStrAsIs(T x); 19 | 20 | #undef T 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /gc/cord/cord.am: -------------------------------------------------------------------------------- 1 | 2 | lib_LTLIBRARIES += libcord.la 3 | 4 | libcord_la_LIBADD = $(top_builddir)/libgc.la 5 | libcord_la_LDFLAGS = -version-info 1:3:0 -no-undefined 6 | 7 | libcord_la_SOURCES = \ 8 | cord/cordbscs.c \ 9 | cord/cordprnt.c \ 10 | cord/cordtest.c \ 11 | cord/cordxtra.c 12 | 13 | 14 | EXTRA_DIST += \ 15 | cord/cordbscs.c cord/cordtest.c cord/de.c \ 16 | cord/cordprnt.c cord/cordxtra.c cord/de_cmds.h \ 17 | cord/de_win.h cord/de_win.c cord/de_win.RC cord/de_win.ICO 18 | 19 | pkginclude_HEADERS += include/cord.h 20 | -------------------------------------------------------------------------------- /src/lib/tuple.h: -------------------------------------------------------------------------------- 1 | #ifndef TUPLE_H 2 | #define TUPLE_H 3 | 4 | #include "poly.h" 5 | 6 | #define T Tuple_t 7 | #define P Poly_t 8 | 9 | typedef struct T *T; 10 | 11 | T Tuple_new(P x, P y); 12 | P Tuple_first(T t); 13 | P Tuple_second(T t); 14 | int Tuple_equals(T t1, 15 | T t2, 16 | Poly_tyEquals eqx, 17 | Poly_tyEquals eqy); 18 | char *Tuple_toString(T t, 19 | Poly_tyToString tx, 20 | Poly_tyToString ty); 21 | 22 | #undef P 23 | #undef T 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /gc/doc/README.rs6000: -------------------------------------------------------------------------------- 1 | We have so far failed to find a good way to determine the stack base. 2 | It is highly recommended that GC_stackbottom be set explicitly on program 3 | startup. The supplied value sometimes causes failure under AIX 4.1, though 4 | it appears to work under 3.X. HEURISTIC2 seems to work under 4.1, but 5 | involves a substantial performance penalty, and will fail if there is 6 | no limit on stack size. 7 | 8 | There is no thread support. (I assume recent versions of AIX provide 9 | pthreads? I no longer have access to a machine ...) 10 | -------------------------------------------------------------------------------- /src/lib/list-pair.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_PAIR_H 2 | #define LIST_PAIR_H 3 | 4 | #include "list.h" 5 | #include "poly.h" 6 | 7 | #define T ListPair_t 8 | #define L List_t 9 | #define P Poly_t 10 | 11 | typedef L T; 12 | 13 | /* if x and y are of different size, return 0. */ 14 | T ListPair_new(void *x, void *y); 15 | 16 | void ListPair_insertLast(T l, P x, P y); 17 | 18 | L ListPair_first(T l); 19 | 20 | L ListPair_second(T l); 21 | 22 | int ListPair_forall(T x, int (*pred)(Poly_t, Poly_t)); 23 | 24 | #undef L 25 | #undef T 26 | #undef P 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/lib/stack.h: -------------------------------------------------------------------------------- 1 | #ifndef STACK_H 2 | #define STACK_H 3 | 4 | #include "list.h" 5 | #include "poly.h" 6 | 7 | #define T Stack_t 8 | #define P Poly_t 9 | 10 | typedef List_t Stack_t; 11 | 12 | T Stack_new(void); 13 | void Stack_push(T stk, P x); 14 | P Stack_pop(T stk); 15 | int Stack_isEmpty(T stk); 16 | int Stack_size(T stk); 17 | T Stack_stack(P x1, ...); 18 | char *Stack_toString(T stk, 19 | String_t sep, 20 | Poly_tyToString tx); 21 | P Stack_getTop(T stk); 22 | 23 | #undef P 24 | #undef T 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/lib/double.c: -------------------------------------------------------------------------------- 1 | #include "double.h" 2 | #include "mem.h" 3 | #include 4 | 5 | #define BUF_SIZE 1024 6 | 7 | String_t Double_toString(double f) { 8 | char *temp; 9 | Mem_NEW_SIZE(temp, BUF_SIZE); 10 | /* Note that I initially want to write: 11 | * snprintf (temp, BUF_SIZE, "%d", i); 12 | * but it seems that this version of GCC I'm using has a bug on 13 | * the function "snprintf". So I've to write this unsafe "sprintf". 14 | */ 15 | snprintf(temp, BUF_SIZE - 1, "%lf", f); 16 | return temp; 17 | } 18 | 19 | #undef BUF_SIZE 20 | -------------------------------------------------------------------------------- /src/atoms/dec.h: -------------------------------------------------------------------------------- 1 | #ifndef DEC_H 2 | #define DEC_H 3 | 4 | #include "../lib/file.h" 5 | #include "atype.h" 6 | #include "id.h" 7 | 8 | #define T Dec_t 9 | 10 | typedef struct T *T; 11 | 12 | struct T { 13 | Atype_t ty; 14 | Id_t id; 15 | }; 16 | 17 | T Dec_new(Atype_t, Id_t); 18 | 19 | // The variable in this declaration may be GCed. 20 | int Dec_maybeGc(T); 21 | 22 | String_t Dec_toString(T); 23 | 24 | File_t Dec_print(File_t file, T); 25 | 26 | File_t Dec_printAsArg(File_t file, T); 27 | 28 | File_t Dec_printAsLocal(File_t file, T); 29 | 30 | #undef T 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/lib/todo.h: -------------------------------------------------------------------------------- 1 | #ifndef TODO_H 2 | #define TODO_H 3 | 4 | #include 5 | #include 6 | 7 | #define TODO \ 8 | do { \ 9 | printf("\n\ 10 | #############################################################\n\ 11 | @@ TODO: fill in your code.\n\ 12 | @@ in file: \"%s\", function: \"%s\"\n\ 13 | @@ at line: %d\n\ 14 | #############################################################\n",\ 15 | __FILE__, __func__, __LINE__); \ 16 | exit(1); \ 17 | } while (0) 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /gc/hpux_test_and_clear.s: -------------------------------------------------------------------------------- 1 | .SPACE $PRIVATE$ 2 | .SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31 3 | .SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82 4 | .SPACE $TEXT$ 5 | .SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44 6 | .SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY 7 | .IMPORT $global$,DATA 8 | .IMPORT $$dyncall,MILLICODE 9 | .SPACE $TEXT$ 10 | .SUBSPA $CODE$ 11 | 12 | .align 4 13 | .EXPORT GC_test_and_clear,ENTRY,PRIV_LEV=3,ARGW0=GR,RTNVAL=GR 14 | GC_test_and_clear 15 | .PROC 16 | .CALLINFO FRAME=0,NO_CALLS 17 | .ENTRY 18 | ldcw,co (%r26),%r28 19 | bv,n 0(%r2) 20 | .EXIT 21 | .PROCEND 22 | -------------------------------------------------------------------------------- /regression/gen.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (int argc, char **argv) 4 | { 5 | int i, numStms; 6 | 7 | if (argc<2){ 8 | fprintf (stderr, "Usage: gen \n"); 9 | return; 10 | } 11 | printf ("// Automatically generated. Don't modify.\n" 12 | "int dragon (int argc, string[] argv)\n" 13 | "{\n" 14 | " int i = 0;\n" 15 | " int r;\n"); 16 | numStms = atoi (argv[1]); 17 | for (i=0; i 2 | #include 3 | 4 | int main (int argc, char **argv) 5 | { 6 | int i, numDecs; 7 | 8 | if (argc<2){ 9 | fprintf (stderr, "Usage: gen2 \n"); 10 | return; 11 | } 12 | printf ("// Automatically generated!. Don't modify.\n" 13 | "int dragon (int argc, string[] argv)\n" 14 | "{\n"); 15 | numDecs = atoi (argv[1]); 16 | for (i=0; i 6 | #include 7 | 8 | int main () 9 | { 10 | int i; 11 | 12 | GC_all_interior_pointers = 0; 13 | GC_INIT(); 14 | 15 | for (i = 0; i < 20000; ++i) { 16 | GC_malloc_atomic (4096); 17 | GC_malloc (4096); 18 | } 19 | for (i = 0; i < 20000; ++i) { 20 | GC_malloc_atomic (2048); 21 | GC_malloc (2048); 22 | } 23 | printf("Final heap size is %ld\n", GC_get_heap_size()); 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/lib/app-list.h: -------------------------------------------------------------------------------- 1 | #ifndef APP_LIST_H 2 | #define APP_LIST_H 3 | 4 | #include "list.h" 5 | #include "poly.h" 6 | 7 | #define T AppList_t 8 | 9 | typedef struct T *T; 10 | 11 | 12 | // argument: List 13 | T AppList_new_list(List_t); 14 | 15 | T AppList_new_va(T, ...); 16 | // concatenation 17 | T AppList_concat(T, T); 18 | 19 | // Cook an appList from any single data item x 20 | T AppList_fromItem(Poly_t x); 21 | // cook an applist from any single list 22 | // argument: List

23 | T AppList_fromItemList(List_t); 24 | // An empty applist 25 | T AppList_new_empty(void); 26 | 27 | List_t AppList_toList(T); 28 | 29 | #undef T 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/lib/triple.h: -------------------------------------------------------------------------------- 1 | #ifndef TRIPLE_H 2 | #define TRIPLE_H 3 | 4 | #include "poly.h" 5 | 6 | #define T Triple_t 7 | #define P Poly_t 8 | 9 | typedef struct T *T; 10 | 11 | T Triple_new(P x, P y, P z); 12 | P Triple_first(T t); 13 | P Triple_second(T t); 14 | P Triple_third(T t); 15 | int Triple_equals(T t1, T t2, 16 | Poly_tyEquals eqx, 17 | Poly_tyEquals eqy, 18 | Poly_tyEquals eqz); 19 | char *Triple_toString(T t, 20 | Poly_tyToString tx, 21 | Poly_tyToString ty, 22 | Poly_tyToString tz); 23 | 24 | #undef P 25 | #undef T 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/lib/print.c: -------------------------------------------------------------------------------- 1 | #include "unused.h" 2 | #include 3 | 4 | int result = 0; 5 | 6 | //static int flag = 1; 7 | //static int ind = 0; 8 | 9 | //void dprint(const char *s) { 10 | // UNUSED(s); 11 | // printf("to do"); 12 | // return; 13 | //} 14 | 15 | //static void printIndent(void) { 16 | // int n = ind; 17 | // 18 | // while (n--) 19 | // printf(" "); 20 | //} 21 | // 22 | //static void indent(void) { 23 | // ind += 3; 24 | //} 25 | // 26 | //static void unindent(void) { 27 | // ind -= 3; 28 | //} 29 | 30 | //void Dp_print(char *s) { 31 | // if (flag) 32 | // printf("%s\n", s); 33 | // else 34 | // ; 35 | //} 36 | -------------------------------------------------------------------------------- /gc/tests/leak_test.c: -------------------------------------------------------------------------------- 1 | #include "leak_detector.h" 2 | 3 | main() { 4 | int *p[10]; 5 | int i; 6 | GC_find_leak = 1; /* for new collect versions not compiled */ 7 | /* with -DFIND_LEAK. */ 8 | 9 | GC_INIT(); /* Needed if thread-local allocation is enabled. */ 10 | /* FIXME: This is not ideal. */ 11 | for (i = 0; i < 10; ++i) { 12 | p[i] = malloc(sizeof(int)+i); 13 | } 14 | CHECK_LEAKS(); 15 | for (i = 1; i < 10; ++i) { 16 | free(p[i]); 17 | } 18 | for (i = 0; i < 9; ++i) { 19 | p[i] = malloc(sizeof(int)+i); 20 | } 21 | CHECK_LEAKS(); 22 | CHECK_LEAKS(); 23 | CHECK_LEAKS(); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/hil/hil-main.c: -------------------------------------------------------------------------------- 1 | #include "../control/pass.h" 2 | #include "hil.h" 3 | #include "dead-code.h" 4 | #include "../ssa/ssa.h" 5 | #include "trans-hil.h" 6 | #include "hil-main.h" 7 | 8 | Ssa_Prog_t Hil_main(Hil_Prog_t p) { 9 | Pass_t deadCode, trans; 10 | Hil_Prog_t p1; 11 | Ssa_Prog_t q; 12 | 13 | deadCode = Pass_new("hilDeadCode", 14 | VERBOSE_SUBPASS, 15 | p, 16 | (Poly_tyId) Hil_deadCode); 17 | p1 = Pass_doit(&deadCode); 18 | 19 | trans = Pass_new("convSsa", 20 | VERBOSE_SUBPASS, 21 | p1, 22 | (Poly_tyId) Hil_trans); 23 | q = Pass_doit(&trans); 24 | 25 | return q; 26 | } 27 | -------------------------------------------------------------------------------- /gc/mips_ultrix_mach_dep.s: -------------------------------------------------------------------------------- 1 | # define call_push(x) move $4,x; jal GC_push_one 2 | 3 | .text 4 | # Mark from machine registers that are saved by C compiler 5 | .globl GC_push_regs 6 | .ent GC_push_regs 7 | GC_push_regs: 8 | subu $sp,8 ## Need to save only return address 9 | sw $31,4($sp) 10 | .mask 0x80000000,-4 11 | .frame $sp,8,$31 12 | call_push($2) 13 | call_push($3) 14 | call_push($16) 15 | call_push($17) 16 | call_push($18) 17 | call_push($19) 18 | call_push($20) 19 | call_push($21) 20 | call_push($22) 21 | call_push($23) 22 | call_push($30) 23 | lw $31,4($sp) 24 | addu $sp,8 25 | j $31 26 | .end GC_push_regs 27 | -------------------------------------------------------------------------------- /gc/autogen.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | set -e 4 | 5 | # These version are ok, pre-1.7 is not. Post 1.7 may produce a lot of 6 | # warnings for unrelated projects, so prefer 1.7 for now. 7 | am_version= 8 | for v in 1.10 1.9 1.8 1.7; do 9 | if type -p &>/dev/null automake-$v; then 10 | am_version="-$v" 11 | break 12 | fi 13 | done 14 | if [ -z "$am_version" ]; then 15 | case "`automake --version`" in 16 | *\ 0.*|*\ 1.[0-6].*|*\ 1.[0-6]\ *) 17 | echo "$0: Automake-1.7 or later is needed." 18 | exit 2 19 | ;; 20 | esac 21 | fi 22 | 23 | set -x 24 | aclocal$am_version 25 | autoconf 26 | autoheader 27 | automake$am_version -ac 28 | libtoolize --automake --force 29 | set +x 30 | echo 31 | echo "Ready to run './configure'." 32 | echo 33 | -------------------------------------------------------------------------------- /src/lib/print.h: -------------------------------------------------------------------------------- 1 | #ifndef PRINT_H 2 | #define RPINT_H 3 | 4 | #include 5 | 6 | extern int result; 7 | 8 | void printIndent(); 9 | 10 | void indent(); 11 | 12 | void unindent(); 13 | 14 | #define Trace_trace(s, f, x, r) \ 15 | do { \ 16 | printIndent(); \ 17 | printf("%s starts\n", s); \ 18 | indent(); \ 19 | r = f x; \ 20 | unindent(); \ 21 | printIndent(); \ 22 | printf("%s ends\n", s); \ 23 | }while (0) 24 | 25 | void Dp_print(char *s); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/lib/property.h: -------------------------------------------------------------------------------- 1 | #ifndef PROPERTY_H 2 | #define PROPERTY_H 3 | 4 | #include "poly.h" 5 | #include "property-list.h" 6 | #include "string.h" 7 | 8 | #define T Property_t 9 | #define K Poly_t 10 | #define V Poly_t 11 | #define P Plist_t 12 | 13 | typedef struct T *T; 14 | 15 | typedef V (*Poly_tyPropInit)(K); 16 | 17 | T Property_new(Poly_tyPlist); 18 | // take an extra "init" argument, which will be called 19 | // when the search failed on some item "k", and the 20 | // generated 21 | // "V" will be set on that item "k". 22 | T Property_newInitFun(Poly_tyPlist, V (*init)(K)); 23 | void Property_set(T prop, K k, V v); 24 | V Property_get(T, K k); 25 | void Property_clear(T prop); 26 | String_t Property_status(void); 27 | 28 | #undef T 29 | #undef K 30 | #undef V 31 | #undef P 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/control/pass.c: -------------------------------------------------------------------------------- 1 | #include "control.h" 2 | #include "verbose.h" 3 | #include "log.h" 4 | #include "pass.h" 5 | 6 | Pass_t Pass_new(String_t name, Verbose_t level, Poly_t thunk, Poly_t (*a)(Poly_t)) { 7 | Pass_t x = {name, level, thunk, a}; 8 | return x; 9 | } 10 | 11 | Poly_t Pass_doit(Pass_t *p) { 12 | Poly_t r; 13 | 14 | // if this pass is to be dropped, then do nothing 15 | if (Control_mayDropPass(p->name)) 16 | return p->thunk; 17 | 18 | // if this pass is to be logged, then do this 19 | if (Control_logPass(p->name)) { 20 | Log_set(p->name); 21 | } 22 | 23 | Verbose_TRACE (p->name, p->action, (p->thunk), r, p->level); 24 | 25 | // reset the log 26 | if (Control_logPass(p->name)) 27 | Log_reset(); 28 | 29 | return r; 30 | } 31 | -------------------------------------------------------------------------------- /src/lib/dlist.c: -------------------------------------------------------------------------------- 1 | #include "dlist.h" 2 | #include "mem.h" 3 | #include 4 | 5 | #define T Dlist_t 6 | 7 | T Dlist_new() { 8 | T t; 9 | 10 | Mem_NEW(t); 11 | t->data = 0; 12 | t->next = t; 13 | t->prev = t; 14 | return t; 15 | } 16 | 17 | void Dlist_insertLast(T t, Poly_t data) { 18 | assert(t); 19 | assert(data); 20 | 21 | T tmp; 22 | Mem_NEW(tmp); 23 | tmp->data = data; 24 | assert(t); 25 | tmp->prev = t->prev; 26 | tmp->prev->next = tmp; 27 | tmp->next = t; 28 | t->prev = tmp; 29 | // return; 30 | } 31 | 32 | //static int Dlist_length(T t) { 33 | // T p = t->next; 34 | // int i = 0; 35 | // 36 | // while (p != t) { 37 | // ++i; 38 | // p = p->next; 39 | // } 40 | // return i; 41 | //} 42 | 43 | #undef T 44 | -------------------------------------------------------------------------------- /src/lib/tree.h: -------------------------------------------------------------------------------- 1 | // This is a general tree module: each vertex 2 | // may have an arbitary number of children. 3 | #ifndef TREE_H 4 | #define TREE_H 5 | 6 | #include "list.h" 7 | #include "poly.h" 8 | #include "string.h" 9 | 10 | #define T Tree_t 11 | 12 | typedef struct T *T; 13 | 14 | T Tree_new(Poly_tyEquals equals); 15 | T Tree_newWithName(Poly_tyEquals equals, String_t name); 16 | void Tree_insertVertex(T t, Poly_t data); 17 | void Tree_insertEdge(T t, Poly_t from, Poly_t to); 18 | void Tree_toJpg(T t, Poly_tyPrint printer); 19 | void Tree_toJpgWithName(T t, Poly_tyPrint printer, String_t fname); 20 | void Tree_dfs(T t, Poly_t start, void (*visit)(Poly_t)); 21 | // List

22 | List_t Tree_children(T t, Poly_t n); 23 | Tree_t Tree_map(T t, Poly_tyEquals, Poly_t (*map)(Poly_t)); 24 | 25 | #undef T 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /regression/tree.c: -------------------------------------------------------------------------------- 1 | class Tree_t 2 | { 3 | int data; 4 | Tree_t left; 5 | Tree_t right; 6 | } 7 | 8 | // 2 9 | // / \ 10 | // 1 3 11 | Tree_t Tree_cook () 12 | { 13 | return new Tree_t(2, 14 | new Tree_t (1, 15 | null, 16 | null), 17 | new Tree_t (3, 18 | null, 19 | null)); 20 | } 21 | 22 | int Tree_preorder (Tree_t x) 23 | { 24 | if (x==null) 25 | return 0; 26 | 27 | printi (x.data); 28 | prints (" "); 29 | Tree_preorder (x.left); 30 | Tree_preorder (x.right); 31 | return 0; 32 | } 33 | 34 | int dragon () 35 | { 36 | Tree_t tree = Tree_cook (); 37 | 38 | Tree_preorder (tree); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /gc/tests/trace_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef GC_DEBUG 4 | # define GC_DEBUG 5 | #endif 6 | 7 | #include "gc.h" 8 | #include "gc_backptr.h" 9 | 10 | struct treenode { 11 | struct treenode *x; 12 | struct treenode *y; 13 | } * root[10]; 14 | 15 | struct treenode * mktree(int i) { 16 | struct treenode * r = GC_MALLOC(sizeof(struct treenode)); 17 | if (0 == i) return 0; 18 | if (1 == i) r = GC_MALLOC_ATOMIC(sizeof(struct treenode)); 19 | r -> x = mktree(i-1); 20 | r -> y = mktree(i-1); 21 | return r; 22 | } 23 | 24 | int main(void) 25 | { 26 | int i; 27 | GC_INIT(); 28 | for (i = 0; i < 10; ++i) { 29 | root[i] = mktree(12); 30 | } 31 | GC_generate_random_backtrace(); 32 | GC_generate_random_backtrace(); 33 | GC_generate_random_backtrace(); 34 | GC_generate_random_backtrace(); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /gc/extra/if_mach.c: -------------------------------------------------------------------------------- 1 | /* Conditionally execute a command based on machine and OS from gcconfig.h */ 2 | 3 | # include "private/gcconfig.h" 4 | # include 5 | # include 6 | # include 7 | 8 | int main(int argc, char **argv, char **envp) 9 | { 10 | if (argc < 4) goto Usage; 11 | if (strcmp(MACH_TYPE, argv[1]) != 0) return(0); 12 | if (strcmp(OS_TYPE, "") != 0 && strcmp(argv[2], "") != 0 13 | && strcmp(OS_TYPE, argv[2]) != 0) return(0); 14 | fprintf(stderr, "^^^^Starting command^^^^\n"); 15 | fflush(stdout); 16 | execvp(argv[3], argv+3); 17 | perror("Couldn't execute"); 18 | 19 | Usage: 20 | fprintf(stderr, "Usage: %s mach_type os_type command\n", argv[0]); 21 | fprintf(stderr, "Currently mach_type = %s, os_type = %s\n", 22 | MACH_TYPE, OS_TYPE); 23 | return(1); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /src/ssa/const-and-dead.c: -------------------------------------------------------------------------------- 1 | #include "const-and-dead.h" 2 | #include "../control/log.h" 3 | #include "../lib/trace.h" 4 | #include "const-prop.h" 5 | #include "dead-code.h" 6 | 7 | static Ssa_Prog_t Ssa_constAndDeadTraced(Ssa_Prog_t p) { 8 | p = Ssa_constProp(p); 9 | p = Ssa_deadCode(p); 10 | return p; 11 | } 12 | 13 | static void printArg(Ssa_Prog_t p) { 14 | File_t file = File_open("constAndDead.arg", "w+"); 15 | Ssa_Prog_print(file, p); 16 | File_close(file); 17 | } 18 | 19 | static void printResult(Ssa_Prog_t p) { 20 | File_t file = File_open("constAndDead.result", "w+"); 21 | Ssa_Prog_print(file, p); 22 | File_close(file); 23 | } 24 | 25 | Ssa_Prog_t Ssa_constAndDead(Ssa_Prog_t p) { 26 | Ssa_Prog_t r; 27 | 28 | Log_POS(); 29 | Trace_TRACE("Ssa_constAndDead", Ssa_constAndDeadTraced, (p), printArg, r, printResult); 30 | return r; 31 | } 32 | -------------------------------------------------------------------------------- /src/lib/set.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_H 2 | #define SET_H 3 | 4 | #include "list.h" 5 | #include "poly.h" 6 | 7 | #define T Set_t 8 | 9 | typedef struct T *T; 10 | 11 | T Set_new(Poly_tyEquals equals); 12 | void Set_delete(T set, Poly_t x); 13 | void Set_deleteAll(T set1, Poly_tyPred pred); 14 | int Set_exists(T set, Poly_t x); 15 | T Set_fromList(Poly_tyEquals equals, List_t list); 16 | void Set_foreach(T set, Poly_tyVoid f); 17 | void Set_insert(T set, Poly_t x); 18 | T Set_intersection(T, T); 19 | int Set_isEmpty(T); 20 | // Remove one element from a set. 21 | Poly_t Set_removeOne(T); 22 | T Set_singleton(Poly_tyEquals equals, Poly_t x); 23 | List_t Set_toList(T set); 24 | T Set_union(T, T); 25 | // this has the side effect of modifying "p". that is 26 | // p = p \/ q 27 | void Set_unionVoid(T p, T q); 28 | long Set_size(T set); 29 | int Set_equals(T set1, T set2); 30 | 31 | #undef T 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /gc/doc/README.hp: -------------------------------------------------------------------------------- 1 | Dynamic loading support requires that executables be linked with -ldld. 2 | The alternative is to build the collector without defining DYNAMIC_LOADING 3 | in gcconfig.h and ensuring that all garbage collectable objects are 4 | accessible without considering statically allocated variables in dynamic 5 | libraries. 6 | 7 | The collector should compile with either plain cc or cc -Ae. Cc -Aa 8 | fails to define _HPUX_SOURCE and thus will not configure the collector 9 | correctly. 10 | 11 | Incremental collection support was reccently added, and should now work. 12 | 13 | In spite of past claims, pthread support under HP/UX 11 should now work. 14 | Define GC_HPUX_THREADS for the build. Incremental collection still does not 15 | work in combination with it. 16 | 17 | The stack finding code can be confused by putenv calls before collector 18 | initialization. Call GC_malloc or GC_init before any putenv calls. 19 | -------------------------------------------------------------------------------- /src/atoms/atype.h: -------------------------------------------------------------------------------- 1 | #ifndef ATYPE_H 2 | #define ATYPE_H 3 | 4 | #include "../lib/string.h" 5 | #include "id.h" 6 | 7 | #define T Atype_t 8 | 9 | typedef struct T *T; 10 | 11 | struct T { 12 | enum { 13 | ATYPE_INT, 14 | ATYPE_STRING, 15 | ATYPE_CLASS, 16 | ATYPE_INT_ARRAY, 17 | ATYPE_STRING_ARRAY, 18 | ATYPE_CLASS_ARRAY, 19 | ATYPE_FUN 20 | } kind; 21 | union { 22 | Id_t id; 23 | struct { 24 | // List 25 | List_t from; 26 | T to; 27 | } fun; 28 | } u; 29 | }; 30 | 31 | T Atype_new_int(void); 32 | T Atype_new_int_array(void); 33 | T Atype_new_string(const String_t); 34 | T Atype_new_string_array(void); 35 | T Atype_new_class(Id_t); 36 | T Atype_new_class_array(Id_t); 37 | T Atype_new_fun(List_t from, T to); 38 | int Atype_maybeGc(T); 39 | String_t Atype_toString(T); 40 | 41 | #undef T 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/standard_ao_double_t.h: -------------------------------------------------------------------------------- 1 | /* NEC LE-IT: For 64Bit OS we extend the double type to hold two int64's 2 | * 3 | * x86-64: __m128 serves as placeholder which also requires the compiler 4 | * to align it on 16 byte boundary (as required by cmpxchg16. 5 | * Similar things could be done for PowerPC 64bit using a VMX data type... */ 6 | 7 | #if (defined(__x86_64__) && defined(__GNUC__)) || defined(_WIN64) 8 | # include 9 | typedef __m128 double_ptr_storage; 10 | #elif defined(_WIN32) && !defined(__GNUC__) 11 | typedef unsigned __int64 double_ptr_storage; 12 | #else 13 | typedef unsigned long long double_ptr_storage; 14 | #endif 15 | 16 | # define AO_HAVE_DOUBLE_PTR_STORAGE 17 | 18 | typedef union { 19 | double_ptr_storage AO_whole; 20 | struct {AO_t AO_v1; AO_t AO_v2;} AO_parts; 21 | } AO_double_t; 22 | 23 | #define AO_HAVE_double_t 24 | #define AO_val1 AO_parts.AO_v1 25 | #define AO_val2 AO_parts.AO_v2 26 | -------------------------------------------------------------------------------- /src/lib/tuple.c: -------------------------------------------------------------------------------- 1 | #include "tuple.h" 2 | #include "mem.h" 3 | #include "string.h" 4 | #include "todo.h" 5 | #include 6 | #include 7 | #include 8 | 9 | #define T Tuple_t 10 | #define P Poly_t 11 | 12 | struct T { 13 | P x; 14 | P y; 15 | }; 16 | 17 | T Tuple_new(P x, P y) { 18 | T t; 19 | 20 | Mem_NEW(t); 21 | t->x = x; 22 | t->y = y; 23 | return t; 24 | } 25 | 26 | P Tuple_first(T t) { 27 | assert(t); 28 | return t->x; 29 | } 30 | 31 | P Tuple_second(T t) { 32 | assert(t); 33 | return t->y; 34 | } 35 | 36 | int Tuple_equals(T t1, T t2, Poly_tyEquals eqx, 37 | Poly_tyEquals eqy) { 38 | assert(t1); 39 | assert(t2); 40 | return eqx(t1->x, t2->x) && eqy(t1->y, t2->y); 41 | } 42 | 43 | char *Tuple_toString(T t, Poly_tyToString tx, 44 | Poly_tyToString ty) { 45 | return String_concat("(", tx(t->x), ", ", 46 | ty(t->y), ")", 0); 47 | } 48 | -------------------------------------------------------------------------------- /src/control/region.c: -------------------------------------------------------------------------------- 1 | #include "region.h" 2 | #include "../lib/mem.h" 3 | #include 4 | 5 | #define T Region_t 6 | 7 | struct T { 8 | Coordinate_t from; 9 | Coordinate_t to; 10 | }; 11 | 12 | T Region_new(Coordinate_t from, Coordinate_t to) { 13 | T t; 14 | Mem_NEW(t); 15 | t->from = from; 16 | t->to = to; 17 | return t; 18 | } 19 | 20 | T Region_bogus(void) { 21 | Coordinate_t bogus = Coordinate_bogus(); 22 | return Region_new(bogus, bogus); 23 | } 24 | 25 | Coordinate_t Region_from(T t) { 26 | assert(t); 27 | return t->from; 28 | } 29 | 30 | Coordinate_t Region_to(T t) { 31 | assert(t); 32 | return t->to; 33 | } 34 | 35 | String_t Region_toString(T t) { 36 | assert(t); 37 | return String_concat("from ", 38 | Coordinate_toString(t->from), 39 | ", to ", 40 | Coordinate_toString(t->to), 41 | 0); 42 | } 43 | 44 | #undef T 45 | -------------------------------------------------------------------------------- /src/lib/mem.h: -------------------------------------------------------------------------------- 1 | #ifndef MEM_H 2 | #define MEM_H 3 | 4 | #include 5 | #include 6 | /*#include "control.h"*/ 7 | #include "error.h" 8 | 9 | extern long Mem_allocated; 10 | extern long Mem_initFlag; 11 | 12 | #define Mem_NEW(p) \ 13 | do { \ 14 | (p) = Mem_alloc(sizeof(*(p))); \ 15 | } while (0) 16 | 17 | #define Mem_NEW_SIZE(p, n) \ 18 | do { \ 19 | if (n <= 0) \ 20 | Error_error("invalid buffer size"); \ 21 | unsigned long new_n = ((unsigned long) (n)) * sizeof(*(p)); \ 22 | (p) = Mem_alloc((long) new_n); \ 23 | } while (0) 24 | 25 | void *Mem_alloc(long size); 26 | 27 | clock_t Mem_getClock(void); 28 | 29 | void Mem_init(void); 30 | 31 | void Mem_status(void); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/c-codegen/c-codegen-main.c: -------------------------------------------------------------------------------- 1 | #include "c-codegen-main.h" 2 | #include "../control/pass.h" 3 | #include "../lib/int.h" 4 | #include "c-codegen.h" 5 | 6 | static int counter = 0; 7 | 8 | static String_t genFileName(void) { 9 | String_t f; 10 | 11 | if (Control_dump_lookup(DUMP_C)) { 12 | f = String_concat("files-", Int_toString(counter++), ".c", 0); 13 | return f; 14 | } 15 | 16 | f = String_concat("", Control_asmDirectory, "files-", Int_toString(counter++), ".c", 0); 17 | return f; 18 | } 19 | 20 | static String_t out(Machine_Prog_t p) { 21 | String_t f; 22 | File_t file; 23 | 24 | f = genFileName(); 25 | file = File_open(f, "w+"); 26 | C_codegen(file, p); 27 | File_close(file); 28 | return f; 29 | } 30 | 31 | String_t C_codegen_main(Machine_Prog_t p) { 32 | Pass_t output; 33 | String_t f; 34 | 35 | output = Pass_new("outputC", VERBOSE_SUBPASS, p, (Poly_tyId) out); 36 | f = Pass_doit(&output); 37 | return f; 38 | } 39 | -------------------------------------------------------------------------------- /gc/sparc_sunos4_mach_dep.s: -------------------------------------------------------------------------------- 1 | ! SPARCompiler 3.0 and later apparently no longer handles 2 | ! asm outside functions. So we need a separate .s file 3 | ! This is only set up for SunOS 4. 4 | ! Assumes this is called before the stack contents are 5 | ! examined. 6 | 7 | .seg "text" 8 | .globl _GC_save_regs_in_stack 9 | .globl _GC_push_regs 10 | _GC_save_regs_in_stack: 11 | _GC_push_regs: 12 | ta 0x3 ! ST_FLUSH_WINDOWS 13 | mov %sp,%o0 14 | retl 15 | nop 16 | 17 | .globl _GC_clear_stack_inner 18 | _GC_clear_stack_inner: 19 | mov %sp,%o2 ! Save sp 20 | add %sp,-8,%o3 ! p = sp-8 21 | clr %g1 ! [g0,g1] = 0 22 | add %o1,-0x60,%sp ! Move sp out of the way, 23 | ! so that traps still work. 24 | ! Includes some extra words 25 | ! so we can be sloppy below. 26 | loop: 27 | std %g0,[%o3] ! *(long long *)p = 0 28 | cmp %o3,%o1 29 | bgu loop ! if (p > limit) goto loop 30 | add %o3,-8,%o3 ! p -= 8 (delay slot) 31 | retl 32 | mov %o2,%sp ! Restore sp., delay slot 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /gc/extra/if_not_there.c: -------------------------------------------------------------------------------- 1 | /* Conditionally execute a command based if the file argv[1] doesn't exist */ 2 | /* Except for execvp, we stick to ANSI C. */ 3 | # include "private/gcconfig.h" 4 | # include 5 | # include 6 | # include 7 | #ifdef __DJGPP__ 8 | #include 9 | #endif /* __DJGPP__ */ 10 | 11 | int main(int argc, char **argv, char **envp) 12 | { 13 | FILE * f; 14 | #ifdef __DJGPP__ 15 | DIR * d; 16 | #endif /* __DJGPP__ */ 17 | if (argc < 3) goto Usage; 18 | if ((f = fopen(argv[1], "rb")) != 0 19 | || (f = fopen(argv[1], "r")) != 0) { 20 | fclose(f); 21 | return(0); 22 | } 23 | #ifdef __DJGPP__ 24 | if ((d = opendir(argv[1])) != 0) { 25 | closedir(d); 26 | return(0); 27 | } 28 | #endif 29 | printf("^^^^Starting command^^^^\n"); 30 | fflush(stdout); 31 | execvp(argv[2], argv+2); 32 | exit(1); 33 | 34 | Usage: 35 | fprintf(stderr, "Usage: %s file_name command\n", argv[0]); 36 | return(1); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/atoms/label.c: -------------------------------------------------------------------------------- 1 | #include "label.h" 2 | #include "../lib/int.h" 3 | #include "../lib/mem.h" 4 | #include "../lib/random.h" 5 | #include 6 | 7 | #define T Label_t 8 | 9 | static int counter = 0; 10 | 11 | struct T { 12 | int count; 13 | int hashCode; 14 | Plist_t plist; 15 | }; 16 | 17 | T Label_new(void) { 18 | T x; 19 | 20 | Mem_NEW(x); 21 | x->count = counter++; 22 | x->hashCode = Random_nextInt(); 23 | x->plist = Plist_new(); 24 | return x; 25 | } 26 | 27 | int Label_hashCode(T x) { 28 | assert(x); 29 | return x->hashCode; 30 | } 31 | 32 | String_t Label_toString(T x) { 33 | assert(x); 34 | return String_concat("L_", Int_toString(x->count), 0); 35 | } 36 | 37 | int Label_equals(T x, T y) { 38 | assert(x); 39 | assert(y); 40 | return x == y; 41 | } 42 | 43 | Plist_t Label_plist(T x) { 44 | assert(x); 45 | return x->plist; 46 | } 47 | 48 | void Label_print(T x) { 49 | assert(x); 50 | printf("%s_%d", "L", x->count); 51 | } 52 | 53 | #undef T 54 | -------------------------------------------------------------------------------- /gc/sparc_netbsd_mach_dep.s: -------------------------------------------------------------------------------- 1 | ! SPARCompiler 3.0 and later apparently no longer handles 2 | ! asm outside functions. So we need a separate .s file 3 | ! This is only set up for SunOS 4. 4 | ! Assumes this is called before the stack contents are 5 | ! examined. 6 | 7 | #include "machine/asm.h" 8 | 9 | .seg "text" 10 | .globl _C_LABEL(GC_save_regs_in_stack) 11 | .globl _C_LABEL(GC_push_regs) 12 | _C_LABEL(GC_save_regs_in_stack): 13 | _C_LABEL(GC_push_regs): 14 | ta 0x3 ! ST_FLUSH_WINDOWS 15 | mov %sp,%o0 16 | retl 17 | nop 18 | 19 | .globl _C_LABEL(GC_clear_stack_inner) 20 | _C_LABEL(GC_clear_stack_inner): 21 | mov %sp,%o2 ! Save sp 22 | add %sp,-8,%o3 ! p = sp-8 23 | clr %g1 ! [g0,g1] = 0 24 | add %o1,-0x60,%sp ! Move sp out of the way, 25 | ! so that traps still work. 26 | ! Includes some extra words 27 | ! so we can be sloppy below. 28 | loop: 29 | std %g0,[%o3] ! *(long long *)p = 0 30 | cmp %o3,%o1 31 | bgu loop ! if (p > limit) goto loop 32 | add %o3,-8,%o3 ! p -= 8 (delay slot) 33 | retl 34 | mov %o2,%sp ! Restore sp., delay slot 35 | -------------------------------------------------------------------------------- /src/lexer/keyword.h: -------------------------------------------------------------------------------- 1 | #ifndef KEY_WORD_H 2 | #define KEY_WORD_H 3 | 4 | #include "../lib/string.h" 5 | #include "token.h" 6 | 7 | struct KeyWord_t { 8 | char *str; 9 | Token_Kind_t kind; 10 | }; 11 | 12 | struct KeyWord_t keyWordTable[] = { 13 | {"break", TOKEN_BREAK}, 14 | {"catch", TOKEN_CATCH}, 15 | {"class", TOKEN_CLASS}, 16 | {"continue", TOKEN_CONTINUE}, 17 | {"do", TOKEN_DO}, 18 | {"else", TOKEN_ELSE}, 19 | {"for", TOKEN_FOR}, 20 | {"if", TOKEN_IF}, 21 | {"int", TOKEN_INT}, 22 | {"new", TOKEN_NEW}, 23 | {"null", TOKEN_NULL}, 24 | {"return", TOKEN_RETURN}, 25 | {"string", TOKEN_STRING}, 26 | {"throw", TOKEN_THROW}, 27 | {"try", TOKEN_TRY}, 28 | {"while", TOKEN_WHILE}, 29 | {0, (Token_Kind_t) 0}}; 30 | 31 | static int isKeyWord(const char *s) { 32 | char *t; 33 | for (int i = 0; (t = keyWordTable[i].str); i++) 34 | if (0 == strcmp(s, t)) 35 | return keyWordTable[i].kind; 36 | return 0; 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /gc/cord/de_cmds.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved. 3 | * 4 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 5 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 6 | * 7 | * Permission is hereby granted to use or copy this program 8 | * for any purpose, provided the above notices are retained on all copies. 9 | * Permission to modify the code and to distribute modified code is granted, 10 | * provided the above notices are retained, and a notice that the code was 11 | * modified is included with the above copyright notice. 12 | */ 13 | /* Boehm, May 19, 1994 2:24 pm PDT */ 14 | 15 | #ifndef DE_CMDS_H 16 | 17 | # define DE_CMDS_H 18 | 19 | # define UP 16 /* ^P */ 20 | # define DOWN 14 /* ^N */ 21 | # define LEFT 2 /* ^B */ 22 | # define RIGHT 6 /* ^F */ 23 | # define DEL 127 /* ^? */ 24 | # define BS 8 /* ^H */ 25 | # define UNDO 21 /* ^U */ 26 | # define WRITE 23 /* ^W */ 27 | # define QUIT 4 /* ^D */ 28 | # define REPEAT 18 /* ^R */ 29 | # define LOCATE 12 /* ^L */ 30 | # define TOP 20 /* ^T */ 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /src/lib/char.c: -------------------------------------------------------------------------------- 1 | #include "char.h" 2 | #include "mem.h" 3 | 4 | /* editor-dependent. */ 5 | #define TAB_SIZE 8 6 | 7 | /* a subset of the ASCII. */ 8 | int Char_isBlank(int c) { 9 | return c == ' ' || c == '\t'; 10 | } 11 | 12 | int Char_blankSize(int c) { 13 | switch (c) { 14 | case ' ': 15 | return 1; 16 | case '\t': 17 | return TAB_SIZE; 18 | default: 19 | return -1; 20 | } 21 | } 22 | 23 | int Char_isDigit(int c) { 24 | return '0' <= c && c <= '9'; 25 | } 26 | 27 | int Char_isAlpha(int c) { 28 | return (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')); 29 | } 30 | 31 | #define BUF_SIZE 1024 32 | 33 | String_t Char_toString(int i) { 34 | char *temp; 35 | Mem_NEW_SIZE(temp, BUF_SIZE); 36 | /* Note that I initially want to write: 37 | * snprintf (temp, BUF_SIZE, "%d", i); 38 | * but it seems that this version of GCC I'm using has a bug on 39 | * the function "snprintf". So I've to write this unsafe "sprintf". 40 | */ 41 | snprintf(temp, BUF_SIZE - 1, "%c", i); 42 | return temp; 43 | } 44 | -------------------------------------------------------------------------------- /src/lib/file.c: -------------------------------------------------------------------------------- 1 | #include "file.h" 2 | #include "error.h" 3 | #include 4 | 5 | #define T File_t 6 | 7 | int File_saveToFile(String_t fname, T (*print)(T, Poly_t), Poly_t x) { 8 | T file = fopen(fname, "w+"); 9 | 10 | if (!file) 11 | Error_bug(String_concat("fail to open file: ", 12 | fname, 13 | 0)); 14 | print(file, x); 15 | fclose(file); 16 | return 0; 17 | } 18 | 19 | int File_flush(T f) { 20 | return fflush(f); 21 | } 22 | 23 | T File_open(String_t s, String_t mode) { 24 | T fp; 25 | if ((fp = fopen(s, mode))) 26 | return fp; 27 | 28 | Error_error(String_concat("file open failed: ", s, " in mode ", "[", mode, "]", 0)); 29 | return 0; 30 | } 31 | 32 | void File_write(T f, String_t s) { 33 | assert(f); 34 | assert(s); 35 | 36 | fputs(s, f); 37 | return; 38 | } 39 | 40 | void File_close(T f) { 41 | int r = fclose(f); 42 | 43 | if (r) { 44 | *((int *) 1) = 0; 45 | Error_error("close file failed\n"); 46 | } 47 | return; 48 | } 49 | 50 | 51 | #undef T 52 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/gcc/sh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 by Takashi YOSHII. All rights reserved. 3 | * 4 | * 5 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 6 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 7 | * 8 | * Permission is hereby granted to use or copy this program 9 | * for any purpose, provided the above notices are retained on all copies. 10 | * Permission to modify the code and to distribute modified code is granted, 11 | * provided the above notices are retained, and a notice that the code was 12 | * modified is included with the above copyright notice. 13 | */ 14 | 15 | #include "../all_atomic_load_store.h" 16 | #include "../ordered.h" 17 | 18 | /* sh has tas.b(byte) only */ 19 | #include "../test_and_set_t_is_char.h" 20 | 21 | AO_INLINE AO_TS_VAL_t 22 | AO_test_and_set_full(volatile AO_TS_t *addr) 23 | { 24 | int oldval; 25 | __asm__ __volatile__( 26 | "tas.b @%1; movt %0" 27 | : "=r" (oldval) 28 | : "r" (addr) 29 | : "t", "memory"); 30 | return oldval? AO_TS_CLEAR : AO_TS_SET; 31 | } 32 | #define AO_HAVE_test_and_set_full 33 | -------------------------------------------------------------------------------- /src/atoms/dec.c: -------------------------------------------------------------------------------- 1 | #include "dec.h" 2 | #include "../lib/mem.h" 3 | #include 4 | 5 | #define T Dec_t 6 | 7 | T Dec_new(Atype_t ty, Id_t id) { 8 | T p; 9 | 10 | Mem_NEW(p); 11 | p->ty = ty; 12 | p->id = id; 13 | return p; 14 | } 15 | 16 | int Dec_maybeGc(T dec) { 17 | return Atype_maybeGc(dec->ty); 18 | } 19 | 20 | String_t Dec_toString(T dec) { 21 | assert(dec); 22 | return String_concat(Atype_toString(dec->ty), " ", Id_toString(dec->id), 0); 23 | } 24 | 25 | File_t Dec_print(File_t file, T dec) { 26 | assert(file); 27 | assert(dec); 28 | 29 | fprintf(file, "%s %s", Atype_toString(dec->ty), Id_toString(dec->id)); 30 | return file; 31 | } 32 | 33 | File_t Dec_printAsArg(File_t file, T dec) { 34 | assert(file); 35 | assert(dec); 36 | 37 | fprintf(file, "%s %s, ", Atype_toString(dec->ty), Id_toString(dec->id)); 38 | return file; 39 | } 40 | 41 | File_t Dec_printAsLocal(File_t file, T dec) { 42 | assert(file); 43 | assert(dec); 44 | 45 | fprintf(file, "\t%s %s;\n", Atype_toString(dec->ty), Id_toString(dec->id)); 46 | return file; 47 | } 48 | 49 | 50 | #undef T 51 | -------------------------------------------------------------------------------- /src/lib/hash-set.h: -------------------------------------------------------------------------------- 1 | #ifndef HASH_SET_H 2 | #define HASH_SET_H 3 | 4 | #include "poly.h" 5 | #include "set.h" 6 | #include "list.h" 7 | 8 | #define T HashSet_t 9 | 10 | typedef struct T *T; 11 | 12 | T HashSet_new(long (*)(Poly_t), Poly_tyEquals equals); 13 | 14 | void HashSet_delete(T set, Poly_t x); 15 | 16 | long HashSet_exists(T set, Poly_t x); 17 | 18 | T HashSet_fromList(Poly_tyEquals equals, List_t list); 19 | 20 | void HashSet_foreach(T set, Poly_tyVoid f); 21 | 22 | void HashSet_insert(T set, Poly_t x); 23 | 24 | T HashSet_intersection(T, T); 25 | 26 | long HashSet_isEmpty(T); 27 | 28 | // Remove one element from a set. 29 | Poly_t HashSet_removeOne(T); 30 | 31 | T HashSet_singleton(Poly_tyEquals equals, Poly_t x); 32 | 33 | List_t HashSet_toList(T set); 34 | 35 | T HashSet_union(T, T); 36 | 37 | // this has the side-effect of modifying "p". that is 38 | // p = p \/ q 39 | void HashSet_unionVoid(T p, T q); 40 | 41 | // this has the side-effect of modifying "p". that is 42 | // p = p \/ q 43 | void HashSet_unionVoidSet(T p, Set_t q); 44 | 45 | // turn a hashset to set. 46 | Set_t HashSet_toSet(Poly_tyEquals eqs, T set); 47 | 48 | #undef T 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /gc/tests/thread_leak_test.c: -------------------------------------------------------------------------------- 1 | #ifndef GC_THREADS 2 | # define GC_THREADS 3 | #endif /* GC_THREADS */ 4 | #include "leak_detector.h" 5 | #include 6 | #include 7 | 8 | void * test(void * arg) { 9 | int *p[10]; 10 | int i; 11 | GC_find_leak = 1; /* for new collect versions not compiled */ 12 | /* with -DFIND_LEAK. */ 13 | for (i = 0; i < 10; ++i) { 14 | p[i] = malloc(sizeof(int)+i); 15 | } 16 | CHECK_LEAKS(); 17 | for (i = 1; i < 10; ++i) { 18 | free(p[i]); 19 | } 20 | return 0; 21 | } 22 | 23 | #define NTHREADS 5 24 | 25 | main() { 26 | int i; 27 | pthread_t t[NTHREADS]; 28 | int code; 29 | 30 | GC_INIT(); 31 | for (i = 0; i < NTHREADS; ++i) { 32 | if ((code = pthread_create(t + i, 0, test, 0)) != 0) { 33 | printf("Thread creation failed %d\n", code); 34 | } 35 | } 36 | for (i = 0; i < NTHREADS; ++i) { 37 | if ((code = pthread_join(t[i], 0)) != 0) { 38 | printf("Thread join failed %lu\n", code); 39 | } 40 | } 41 | CHECK_LEAKS(); 42 | CHECK_LEAKS(); 43 | CHECK_LEAKS(); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /src/lib/trace.c: -------------------------------------------------------------------------------- 1 | #include "trace.h" 2 | #include "list.h" 3 | #include "string.h" 4 | #include "unused.h" 5 | #include 6 | #include 7 | 8 | #define STEP 3 9 | 10 | static int indent = 0; 11 | 12 | static List_t names = 0; 13 | 14 | void Trace_indent(void) { 15 | indent += STEP; 16 | } 17 | 18 | void Trace_unindent(void) { 19 | indent -= STEP; 20 | } 21 | 22 | void Trace_spaces(void) { 23 | int i = indent; 24 | while (i--) 25 | printf(" "); 26 | } 27 | 28 | int Trace_lookup(char *s) { 29 | if (!names) 30 | names = List_new(); 31 | return List_exists(names, 32 | s, 33 | (Poly_tyEquals) String_equals); 34 | } 35 | 36 | void Trace_insert(char *s) { 37 | if (!names) 38 | names = List_new(); 39 | List_insertFirst(names, s); 40 | } 41 | 42 | List_t Trace_allFuncs(void) { 43 | if (!names) 44 | return List_new(); 45 | return names; 46 | } 47 | 48 | void Trace_reset(void) { 49 | names = 0; 50 | } 51 | 52 | String_t Trace_junk(void) { 53 | return ""; 54 | } 55 | 56 | String_t Trace_junk2(void *s) { 57 | UNUSED(s); 58 | return ""; 59 | } 60 | -------------------------------------------------------------------------------- /src/control/coordinate.c: -------------------------------------------------------------------------------- 1 | #include "coordinate.h" 2 | #include "../lib/int.h" 3 | #include "../lib/mem.h" 4 | #include 5 | 6 | #define T Coordinate_t 7 | 8 | struct T { 9 | String_t file; 10 | int line; 11 | int column; 12 | }; 13 | 14 | T Coordinate_new(String_t file, int line, int column) { 15 | T t; 16 | Mem_NEW(t); 17 | t->file = file; 18 | t->line = line; 19 | t->column = column; 20 | return t; 21 | } 22 | 23 | T Coordinate_bogus(void) { 24 | return Coordinate_new("", 25 | -1, 26 | -1); 27 | } 28 | 29 | String_t Coordinate_file(T t) { 30 | assert(t); 31 | return t->file; 32 | } 33 | 34 | int Coordinate_column(T t) { 35 | assert(t); 36 | return t->column; 37 | } 38 | 39 | int Coordinate_line(T t) { 40 | assert(t); 41 | return t->line; 42 | } 43 | 44 | String_t Coordinate_toString(T t) { 45 | assert(t); 46 | return String_concat("(file \"", t->file, 47 | "\", line ", Int_toString(t->line), 48 | ", column ", Int_toString(t->column), 49 | ")", 50 | 0); 51 | } 52 | 53 | #undef T 54 | -------------------------------------------------------------------------------- /src/elaborate/type.h: -------------------------------------------------------------------------------- 1 | #ifndef TYPE_H 2 | #define TYPE_H 3 | 4 | #include "../ast/ast-id.h" 5 | #include "../lib/list.h" 6 | #include "../lib/string.h" 7 | #include "../lib/tuple.h" 8 | 9 | #define T Type_t 10 | 11 | typedef struct T *T; 12 | struct T { 13 | enum { 14 | TYPE_A_INT, 15 | TYPE_A_STRING, 16 | TYPE_A_NS, 17 | TYPE_A_CLASS, 18 | TYPE_A_PRODUCT, 19 | TYPE_A_FUN 20 | } kind; 21 | int isArray; 22 | union { 23 | AstId_t className; 24 | /* List */ 25 | List_t product; 26 | struct { 27 | T from; 28 | T to; 29 | } fun; 30 | } u; 31 | }; 32 | 33 | T Type_new_int(void); 34 | T Type_new_string(void); 35 | T Type_new_ns(void); 36 | T Type_new_class(AstId_t name); 37 | T Type_new_array(T); 38 | T Type_new_product(T t, ...); 39 | T Type_new_product2(List_t prod); 40 | T Type_new_fun(T arg, T ret); 41 | void Type_set_array(T); 42 | Id_t Type_dest_array(T); 43 | T Type_clearArray(T); 44 | Id_t Type_searchField(T t, AstId_t id); 45 | Tuple_t Type_dest_fun(T); 46 | int Type_equals(T, T); 47 | int Type_equals_int(T); 48 | int Type_equals_string(T); 49 | String_t Type_toString(T); 50 | 51 | #undef T 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/atoms/class.c: -------------------------------------------------------------------------------- 1 | #include "class.h" 2 | #include "../lib/mem.h" 3 | #include "dec.h" 4 | #include 5 | 6 | #define T Class_t 7 | 8 | T Class_new(Id_t name, List_t decs) { 9 | T p; 10 | 11 | Mem_NEW(p); 12 | p->name = name; 13 | p->decs = decs; 14 | return p; 15 | } 16 | 17 | String_t Class_toString(T c) { 18 | String_t s; 19 | List_t p; 20 | 21 | assert(c); 22 | s = String_concat("class ", 23 | Id_toString(c->name), 24 | "\n{\n", 25 | 0); 26 | p = List_getFirst(c->decs); 27 | while (p) { 28 | Dec_t dec = (Dec_t) p->data; 29 | s = String_concat(s, 30 | " ", 31 | Dec_toString(dec), 32 | ";\n", 33 | 0); 34 | p = p->next; 35 | } 36 | s = String_concat(s, "}", 0); 37 | return s; 38 | } 39 | 40 | File_t Class_print(File_t file, T c) { 41 | assert(c); 42 | fprintf(file, "%s", "class "); 43 | fprintf(file, "%s\n{\n", Id_toString(c->name)); 44 | List_foldl(c->decs, file, (Poly_tyFold) Dec_printAsLocal); 45 | fprintf(file, "%s", "}\n"); 46 | return file; 47 | } 48 | 49 | #undef T 50 | -------------------------------------------------------------------------------- /src/control/log.h: -------------------------------------------------------------------------------- 1 | #ifndef LOG_H 2 | #define LOG_H 3 | 4 | #include "../lib/file.h" 5 | #include "../lib/int.h" 6 | #include "../lib/poly.h" 7 | #include "../lib/string.h" 8 | #include 9 | 10 | typedef File_t (*Poly_tyLog)(File_t, Poly_t); 11 | typedef void (*Poly_tyDot)(Poly_t, String_t); 12 | 13 | #define Log_POS() \ 14 | do { \ 15 | Log_strs(__FILE__, ": ", Int_toString(__LINE__), "\n\n", 0); \ 16 | } while (0) 17 | 18 | // call f on a and str 19 | void Log_dot(Poly_tyDot f, Poly_t a, String_t name); 20 | // call the function f on a 21 | void Log_fun(Poly_t a, File_t (*f)(File_t, Poly_t)); 22 | // flush current log info, and keep log for nothing now on. 23 | void Log_reset(void); 24 | // given the name of pass, keep the log for that pass 25 | void Log_set(String_t passname); 26 | // log a single string 27 | void Log_str(String_t str); 28 | // maybe we should not need such detailed information. 29 | #define Log_STR(str) \ 30 | do { \ 31 | Log_POS(); \ 32 | Log_str(str); \ 33 | } while (0); 34 | // log a sequence of strings 35 | void Log_strs(String_t str, ...); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/lib/graph.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPH_H 2 | #define GRAPH_H 3 | 4 | #include "poly.h" 5 | #include "property.h" 6 | #include "string.h" 7 | #include "tree.h" 8 | //#include "weight.h" 9 | #include "list.h" 10 | #include "set.h" 11 | 12 | 13 | #define T Graph_t 14 | 15 | typedef struct T *T; 16 | 17 | T Graph_new(Poly_tyEquals equals); 18 | 19 | T Graph_newWithName(Poly_tyEquals equals, String_t graphName); 20 | 21 | void Graph_insertVertex(T g, Poly_t data); 22 | 23 | void Graph_insertEdge(T g, Poly_t from, Poly_t to); 24 | 25 | List_t Graph_successors(T, Poly_t v); 26 | 27 | List_t Graph_predessors(T, Poly_t v); 28 | 29 | void Graph_toJpg(T g, Poly_tyPrint printer); 30 | 31 | void Graph_toJpgWithName(T g, Poly_tyPrint printer, String_t fname); 32 | 33 | //void Graph_toJpgEdge (T g 34 | // , String_t fname 35 | // , Property_t edgeProp); 36 | 37 | void Graph_dfs(T g, 38 | Poly_t start, 39 | void (*visit)(Poly_t)); 40 | 41 | // Tree 42 | Tree_t Graph_domTree(T g, Poly_t start); 43 | 44 | // Each vertex's dominance frontier. Note that this 45 | // property is set by "dfProp"; 46 | Tree_t Graph_df(T g, Poly_t start, void (*markDf)(Poly_t, Set_t)); 47 | 48 | 49 | #undef T 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /gc/doc/README.win64: -------------------------------------------------------------------------------- 1 | 64-bit Windows on AMD64/Intel EM64T is somewhat supported in the 7.0 2 | and later release. A collector can be built with Microsoft Visual C++ 2005 3 | or with mingw-w64 gcc. 4 | More testing would clearly be helpful. 5 | 6 | NT_X64_STATIC_THREADS_MAKEFILE has been used in 7 | this environment. Copy this file to MAKEFILE, and then type "nmake" 8 | in a Visual C++ command line window to build the static library 9 | and the usual test programs. To verify that the collector is 10 | at least somewhat functional, run gctest.exe. This should create 11 | gctest.gc.log after a few seconds. 12 | 13 | This process is completely analogous to NT_STATIC_THREADS_MAKEFILE 14 | for the 32-bit version. 15 | 16 | A similar procedure using NT_X64_THREADS_MAKEFILE should be usable to 17 | build the dynamic library. Test_cpp.exe did not seem to run correctly this 18 | way. It seems that we're getting the wrong instances of operator new/delete 19 | in some cases. The C tests seemed OK. 20 | 21 | Note that currently a few warnings are still generated by default, 22 | and a number of others have been explicitly turned off in the makefile. 23 | 24 | VC++ note: to suppress warnings use -D_CRT_SECURE_NO_DEPRECATE. 25 | 26 | gcc note: -fno-strict-aliasing should be used if optimizing. 27 | -------------------------------------------------------------------------------- /gc/real_malloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers 3 | * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved. 4 | * 5 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 6 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 7 | * 8 | * Permission is hereby granted to use or copy this program 9 | * for any purpose, provided the above notices are retained on all copies. 10 | * Permission to modify the code and to distribute modified code is granted, 11 | * provided the above notices are retained, and a notice that the code was 12 | * modified is included with the above copyright notice. 13 | */ 14 | 15 | # ifdef HAVE_CONFIG_H 16 | # include "private/config.h" 17 | # endif 18 | 19 | # ifdef PCR 20 | /* 21 | * This definition should go in its own file that includes no other 22 | * header files. Otherwise, we risk not getting the underlying system 23 | * malloc. 24 | */ 25 | # define PCR_NO_RENAME 26 | # include 27 | 28 | void * real_malloc(size_t size) 29 | { 30 | return(malloc(size)); 31 | } 32 | 33 | # else 34 | 35 | extern int GC_quiet; 36 | /* ANSI C doesn't allow translation units to be empty. */ 37 | /* So we guarantee this one is nonempty. */ 38 | 39 | #endif /* PCR */ 40 | -------------------------------------------------------------------------------- /gc/private/darwin_stop_world.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved. 3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved. 4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved. 5 | * Copyright (c) 2000-2009 by Hewlett-Packard Development Company. 6 | * All rights reserved. 7 | * 8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 10 | * 11 | * Permission is hereby granted to use or copy this program 12 | * for any purpose, provided the above notices are retained on all copies. 13 | * Permission to modify the code and to distribute modified code is granted, 14 | * provided the above notices are retained, and a notice that the code was 15 | * modified is included with the above copyright notice. 16 | */ 17 | 18 | #ifndef GC_DARWIN_STOP_WORLD_H 19 | #define GC_DARWIN_STOP_WORLD_H 20 | 21 | #if !defined(GC_DARWIN_THREADS) 22 | # error darwin_stop_world.h included without GC_DARWIN_THREADS defined 23 | #endif 24 | 25 | #include 26 | #include 27 | 28 | struct thread_stop_info { 29 | mach_port_t mach_thread; 30 | }; 31 | 32 | struct GC_mach_thread { 33 | thread_act_t thread; 34 | int already_suspended; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /gc/include/private/darwin_stop_world.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved. 3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved. 4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved. 5 | * Copyright (c) 2000-2009 by Hewlett-Packard Development Company. 6 | * All rights reserved. 7 | * 8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 10 | * 11 | * Permission is hereby granted to use or copy this program 12 | * for any purpose, provided the above notices are retained on all copies. 13 | * Permission to modify the code and to distribute modified code is granted, 14 | * provided the above notices are retained, and a notice that the code was 15 | * modified is included with the above copyright notice. 16 | */ 17 | 18 | #ifndef GC_DARWIN_STOP_WORLD_H 19 | #define GC_DARWIN_STOP_WORLD_H 20 | 21 | #if !defined(GC_DARWIN_THREADS) 22 | # error darwin_stop_world.h included without GC_DARWIN_THREADS defined 23 | #endif 24 | 25 | #include 26 | #include 27 | 28 | struct thread_stop_info { 29 | mach_port_t mach_thread; 30 | }; 31 | 32 | struct GC_mach_thread { 33 | thread_act_t thread; 34 | int already_suspended; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /gc/gc_amiga_redirects.h: -------------------------------------------------------------------------------- 1 | #ifndef GC_AMIGA_REDIRECTS_H 2 | 3 | # define GC_AMIGA_REDIRECTS_H 4 | 5 | # if ( defined(_AMIGA) && !defined(GC_AMIGA_MAKINGLIB) ) 6 | extern void *GC_amiga_realloc(void *old_object,size_t new_size_in_bytes); 7 | # define GC_realloc(a,b) GC_amiga_realloc(a,b) 8 | extern void GC_amiga_set_toany(void (*func)(void)); 9 | extern int GC_amiga_free_space_divisor_inc; 10 | extern void *(*GC_amiga_allocwrapper_do) \ 11 | (size_t size,void *(*AllocFunction)(size_t size2)); 12 | # define GC_malloc(a) \ 13 | (*GC_amiga_allocwrapper_do)(a,GC_malloc) 14 | # define GC_malloc_atomic(a) \ 15 | (*GC_amiga_allocwrapper_do)(a,GC_malloc_atomic) 16 | # define GC_malloc_uncollectable(a) \ 17 | (*GC_amiga_allocwrapper_do)(a,GC_malloc_uncollectable) 18 | # define GC_malloc_stubborn(a) \ 19 | (*GC_amiga_allocwrapper_do)(a,GC_malloc_stubborn) 20 | # define GC_malloc_atomic_uncollectable(a) \ 21 | (*GC_amiga_allocwrapper_do)(a,GC_malloc_atomic_uncollectable) 22 | # define GC_malloc_ignore_off_page(a) \ 23 | (*GC_amiga_allocwrapper_do)(a,GC_malloc_ignore_off_page) 24 | # define GC_malloc_atomic_ignore_off_page(a) \ 25 | (*GC_amiga_allocwrapper_do)(a,GC_malloc_atomic_ignore_off_page) 26 | # endif /* _AMIGA && !GC_AMIGA_MAKINGLIB */ 27 | 28 | #endif /* GC_AMIGA_REDIRECTS_H */ 29 | 30 | 31 | -------------------------------------------------------------------------------- /gc/include/gc_amiga_redirects.h: -------------------------------------------------------------------------------- 1 | #ifndef GC_AMIGA_REDIRECTS_H 2 | 3 | # define GC_AMIGA_REDIRECTS_H 4 | 5 | # if ( defined(_AMIGA) && !defined(GC_AMIGA_MAKINGLIB) ) 6 | extern void *GC_amiga_realloc(void *old_object,size_t new_size_in_bytes); 7 | # define GC_realloc(a,b) GC_amiga_realloc(a,b) 8 | extern void GC_amiga_set_toany(void (*func)(void)); 9 | extern int GC_amiga_free_space_divisor_inc; 10 | extern void *(*GC_amiga_allocwrapper_do) \ 11 | (size_t size,void *(*AllocFunction)(size_t size2)); 12 | # define GC_malloc(a) \ 13 | (*GC_amiga_allocwrapper_do)(a,GC_malloc) 14 | # define GC_malloc_atomic(a) \ 15 | (*GC_amiga_allocwrapper_do)(a,GC_malloc_atomic) 16 | # define GC_malloc_uncollectable(a) \ 17 | (*GC_amiga_allocwrapper_do)(a,GC_malloc_uncollectable) 18 | # define GC_malloc_stubborn(a) \ 19 | (*GC_amiga_allocwrapper_do)(a,GC_malloc_stubborn) 20 | # define GC_malloc_atomic_uncollectable(a) \ 21 | (*GC_amiga_allocwrapper_do)(a,GC_malloc_atomic_uncollectable) 22 | # define GC_malloc_ignore_off_page(a) \ 23 | (*GC_amiga_allocwrapper_do)(a,GC_malloc_ignore_off_page) 24 | # define GC_malloc_atomic_ignore_off_page(a) \ 25 | (*GC_amiga_allocwrapper_do)(a,GC_malloc_atomic_ignore_off_page) 26 | # endif /* _AMIGA && !GC_AMIGA_MAKINGLIB */ 27 | 28 | #endif /* GC_AMIGA_REDIRECTS_H */ 29 | 30 | 31 | -------------------------------------------------------------------------------- /gc/private/pthread_stop_world.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved. 3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved. 4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved. 5 | * Copyright (c) 2000-2009 by Hewlett-Packard Development Company. 6 | * All rights reserved. 7 | * 8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 10 | * 11 | * Permission is hereby granted to use or copy this program 12 | * for any purpose, provided the above notices are retained on all copies. 13 | * Permission to modify the code and to distribute modified code is granted, 14 | * provided the above notices are retained, and a notice that the code was 15 | * modified is included with the above copyright notice. 16 | */ 17 | 18 | #ifndef GC_PTHREAD_STOP_WORLD_H 19 | #define GC_PTHREAD_STOP_WORLD_H 20 | 21 | struct thread_stop_info { 22 | # ifndef GC_OPENBSD_THREADS 23 | word last_stop_count; /* GC_last_stop_count value when thread */ 24 | /* last successfully handled a suspend */ 25 | /* signal. */ 26 | # endif 27 | 28 | ptr_t stack_ptr; /* Valid only when stopped. */ 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/lib/int.c: -------------------------------------------------------------------------------- 1 | #include "int.h" 2 | #include "mem.h" 3 | #include "string.h" 4 | #include 5 | 6 | const int Int_zero = 0; 7 | 8 | #define BUF_SIZE 1024 9 | 10 | String_t Int_toString(long i) { 11 | char *temp; 12 | Mem_NEW_SIZE(temp, BUF_SIZE); 13 | /* Note that I initially want to write: 14 | * snprintf (temp, BUF_SIZE, "%d", i); 15 | * but it seems that this version of GCC I'm using 16 | * has a bug on the function "snprintf". So I've 17 | * to write this unsafe "sprintf". 18 | */ 19 | snprintf(temp, BUF_SIZE - 1, "%ld", i); 20 | return temp; 21 | } 22 | 23 | // The stdlib has "strtol" family of conversion functions, 24 | // but that is not what I want. Here, I want the code 25 | // issue error for illegal strings, such as these: 26 | // "123xy" 27 | // For now, it only works with deciminal numbers, but 28 | // this algorithm is of no difficulty to scale to 29 | // other numbers. 30 | // Return 0 for failure, 1 for success. 31 | long Int_fromString(String_t s, long *result) { 32 | unsigned char c = 0; 33 | long sum = 0; 34 | 35 | while ((c = (unsigned char) *s++)) { 36 | if (c >= '0' && c <= '9') 37 | sum = sum * 10 + (c - '0'); 38 | else 39 | return 0; 40 | } 41 | *result = sum; 42 | return 1; 43 | } 44 | 45 | 46 | #undef BUF_SIZE 47 | -------------------------------------------------------------------------------- /gc/include/private/pthread_stop_world.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved. 3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved. 4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved. 5 | * Copyright (c) 2000-2009 by Hewlett-Packard Development Company. 6 | * All rights reserved. 7 | * 8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 10 | * 11 | * Permission is hereby granted to use or copy this program 12 | * for any purpose, provided the above notices are retained on all copies. 13 | * Permission to modify the code and to distribute modified code is granted, 14 | * provided the above notices are retained, and a notice that the code was 15 | * modified is included with the above copyright notice. 16 | */ 17 | 18 | #ifndef GC_PTHREAD_STOP_WORLD_H 19 | #define GC_PTHREAD_STOP_WORLD_H 20 | 21 | struct thread_stop_info { 22 | # ifndef GC_OPENBSD_THREADS 23 | word last_stop_count; /* GC_last_stop_count value when thread */ 24 | /* last successfully handled a suspend */ 25 | /* signal. */ 26 | # endif 27 | 28 | ptr_t stack_ptr; /* Valid only when stopped. */ 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/lib/triple.c: -------------------------------------------------------------------------------- 1 | #include "triple.h" 2 | #include "mem.h" 3 | #include "string.h" 4 | #include 5 | 6 | #define T Triple_t 7 | #define P Poly_t 8 | 9 | struct T { 10 | P x; 11 | P y; 12 | P z; 13 | }; 14 | 15 | T Triple_new(P x, P y, P z) { 16 | T t; 17 | 18 | Mem_NEW(t); 19 | t->x = x; 20 | t->y = y; 21 | t->z = z; 22 | return t; 23 | } 24 | 25 | P Triple_first(T t) { 26 | assert(t); 27 | return t->x; 28 | } 29 | 30 | P Triple_second(T t) { 31 | assert(t); 32 | return t->y; 33 | } 34 | 35 | P Triple_third(T t) { 36 | assert(t); 37 | return t->z; 38 | } 39 | 40 | int Triple_equals(T t1, T t2, Poly_tyEquals eqx, 41 | Poly_tyEquals eqy, 42 | Poly_tyEquals eqz) { 43 | assert(t1); 44 | assert(t2); 45 | return eqx(t1->x, t2->x) && eqy(t1->y, t2->y) && eqz(t1->z, t2->z); 46 | } 47 | 48 | char *Triple_toString(T t, Poly_tyToString tx, 49 | Poly_tyToString ty, 50 | Poly_tyToString tz) { 51 | return String_concat("(", 52 | tx(t->x), 53 | ", ", 54 | ty(t->y), 55 | ", ", 56 | tz(t->z), 57 | ")", 58 | 0); 59 | } 60 | 61 | #undef P 62 | #undef T 63 | -------------------------------------------------------------------------------- /src/lexer/token.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011-2012, Baojian Hua. 2 | * Copyright (C) 2011-2012, School of Software Engineering, USTC. 3 | * 4 | * See the Copyright for more information. 5 | */ 6 | 7 | #ifndef TOKEN_H 8 | #define TOKEN_H 9 | 10 | #include "../control/coordinate.h" 11 | #include "../control/region.h" 12 | #include "../lib/string.h" 13 | 14 | typedef enum { 15 | TOKEN_AND = -128, 16 | TOKEN_BREAK, 17 | TOKEN_CATCH, 18 | TOKEN_CLASS, 19 | TOKEN_CONTINUE, 20 | TOKEN_DO, 21 | TOKEN_ELSE, 22 | TOKEN_EQ, 23 | TOKEN_FOR, 24 | TOKEN_GE, 25 | TOKEN_ID, 26 | TOKEN_IF, 27 | TOKEN_INT, 28 | TOKEN_INTLIT, 29 | TOKEN_LE, 30 | TOKEN_NEQ, 31 | TOKEN_NEW, 32 | TOKEN_NULL, 33 | TOKEN_OF, 34 | TOKEN_OR, 35 | TOKEN_RETURN, 36 | TOKEN_STRING, 37 | TOKEN_STRINGLIT, 38 | TOKEN_THROW, 39 | TOKEN_TRY, 40 | TOKEN_WHILE 41 | } Token_Kind_t; 42 | 43 | #define T Token_t 44 | 45 | typedef struct T *T; 46 | 47 | struct T { 48 | Token_Kind_t kind; 49 | String_t lexeme; 50 | Region_t region; 51 | }; 52 | 53 | T Token_new(Token_Kind_t kind, 54 | String_t lexeme, 55 | Coordinate_t left, 56 | Coordinate_t right); 57 | String_t Token_Kind_toString(Token_Kind_t kind); 58 | String_t Token_toString(T t); 59 | String_t Token_toStringWithPos(T t); 60 | 61 | #undef T 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/elaborate/elaborate-main.c: -------------------------------------------------------------------------------- 1 | #include "elaborate-main.h" 2 | #include "../control/pass.h" 3 | #include "check-ast.h" 4 | #include "combine-stm.h" 5 | #include "elaborate.h" 6 | #include "lift-dec.h" 7 | #include "trans-ast.h" 8 | 9 | Hil_Prog_t Elaborate_main(Ast_Prog_t p) { 10 | Pass_t elab, check, combine, lift, trans; 11 | Ast_Prog_t p1, p2, p3; 12 | Hil_Prog_t q; 13 | 14 | check = Pass_new("well-formedness checking", 15 | VERBOSE_SUBPASS, 16 | p, 17 | (Poly_tyId) Check_ast); 18 | Pass_doit(&check); 19 | 20 | elab = Pass_new("type checking", 21 | VERBOSE_SUBPASS, 22 | p, 23 | (Poly_tyId) Elaborate_ast); 24 | p1 = Pass_doit(&elab); 25 | 26 | combine = Pass_new("combine statement", 27 | VERBOSE_SUBPASS, 28 | p1, 29 | (Poly_tyId) Combine_stm); 30 | p2 = Pass_doit(&combine); 31 | 32 | lift = Pass_new("declaration lifting", 33 | VERBOSE_SUBPASS, 34 | p2, 35 | (Poly_tyId) Lift_dec); 36 | p3 = Pass_doit(&lift); 37 | 38 | trans = Pass_new("conversion", 39 | VERBOSE_SUBPASS, 40 | p3, 41 | (Poly_tyId) Trans_ast); 42 | q = Pass_doit(&trans); 43 | 44 | return q; 45 | } 46 | -------------------------------------------------------------------------------- /src/lib/list-pair.c: -------------------------------------------------------------------------------- 1 | #include "list-pair.h" 2 | #include "tuple.h" 3 | #include "unused.h" 4 | #include 5 | 6 | #define T ListPair_t 7 | #define L List_t 8 | #define P Poly_t 9 | 10 | T ListPair_new(void *x, void *y) { 11 | UNUSED(x); 12 | UNUSED(y); 13 | return List_new(); 14 | } 15 | 16 | void ListPair_insertLast(T l, P x, P y) { 17 | assert(l); 18 | List_insertLast(l, Tuple_new(x, y)); 19 | } 20 | 21 | L ListPair_first(T l) { 22 | L tmp, p; 23 | 24 | assert(l); 25 | tmp = List_new(); 26 | p = List_getFirst(l); 27 | while (p) { 28 | List_insertLast(tmp, Tuple_first(p->data)); 29 | p = p->next; 30 | } 31 | return tmp; 32 | } 33 | 34 | L ListPair_second(T l) { 35 | L tmp, p; 36 | 37 | assert(l); 38 | tmp = List_new(); 39 | p = List_getFirst(l); 40 | while (p) { 41 | List_insertLast(tmp, Tuple_second(p->data)); 42 | p = p->next; 43 | } 44 | return tmp; 45 | } 46 | 47 | int ListPair_forall(T x, int (*pred)(Poly_t, Poly_t)) { 48 | T tmp; 49 | Tuple_t tuple; 50 | 51 | assert(x); 52 | assert(pred); 53 | tmp = List_getFirst(x); 54 | while (tmp) { 55 | tuple = (Tuple_t) tmp->data; 56 | if (!pred(Tuple_first(tuple), Tuple_second(tuple))) 57 | return 0; 58 | tmp = tmp->next; 59 | } 60 | return 1; 61 | } 62 | 63 | #undef L 64 | #undef T 65 | #undef P 66 | -------------------------------------------------------------------------------- /src/ast/ast-id.c: -------------------------------------------------------------------------------- 1 | #include "ast-id.h" 2 | #include "../lib/mem.h" 3 | #include 4 | 5 | #define T AstId_t 6 | 7 | struct T { 8 | Id_t id; 9 | Region_t region; 10 | }; 11 | 12 | static T AstId_new(Id_t id, Region_t r) { 13 | T t; 14 | Mem_NEW(t); 15 | t->id = id; 16 | t->region = r; 17 | return t; 18 | } 19 | 20 | T AstId_fromString(String_t s, Region_t r) { 21 | return AstId_new(Id_fromString(s), r); 22 | } 23 | 24 | T AstId_bogus(void) { 25 | return AstId_new(Id_bogus(), Region_bogus()); 26 | } 27 | 28 | T AstId_newNoName(void) { 29 | return AstId_new(Id_newNoName(), Region_bogus()); 30 | } 31 | 32 | Id_t AstId_toId(T id) { 33 | assert(id); 34 | return id->id; 35 | } 36 | 37 | long AstId_equals(T id1, T id2) { 38 | assert(id1); 39 | assert(id2); 40 | return Id_equals(id1->id, id2->id); 41 | } 42 | 43 | long AstId_hashCode(T t) { 44 | assert(t); 45 | return Id_hashCode(t->id); 46 | } 47 | 48 | String_t AstId_toString(T t) { 49 | assert(t); 50 | return Id_toString(t->id); 51 | } 52 | 53 | Region_t AstId_dest(T t) { 54 | assert(t); 55 | return t->region; 56 | } 57 | 58 | Region_t AstId_getRegion(T t) { 59 | assert(t); 60 | return t->region; 61 | } 62 | 63 | Plist_t AstId_plist(T t) { 64 | assert(t); 65 | return Id_plist(t->id); 66 | } 67 | 68 | void AstId_print(T t) { 69 | assert(t); 70 | Id_print(t->id); 71 | } 72 | 73 | 74 | #undef T 75 | -------------------------------------------------------------------------------- /gc/mips_sgi_mach_dep.s: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /* This file must be preprocessed. But the SGI assembler always does */ 4 | /* that. Furthermore, a generic preprocessor won't do, since some of */ 5 | /* the SGI-supplied include files rely on behavior of the MIPS */ 6 | /* assembler. Hence we treat and name this file as though it required */ 7 | /* no preprocessing. */ 8 | 9 | # define call_push(x) move $4,x; jal GC_push_one 10 | 11 | .option pic2 12 | .text 13 | /* Mark from machine registers that are saved by C compiler */ 14 | # define FRAMESZ 32 15 | # define RAOFF FRAMESZ-SZREG 16 | # define GPOFF FRAMESZ-(2*SZREG) 17 | NESTED(GC_push_regs, FRAMESZ, ra) 18 | .mask 0x80000000,-SZREG # inform debugger of saved ra loc 19 | move t0,gp 20 | SETUP_GPX(t8) 21 | PTR_SUBU sp,FRAMESZ 22 | # ifdef SETUP_GP64 23 | SETUP_GP64(GPOFF, GC_push_regs) 24 | # endif 25 | SAVE_GP(GPOFF) 26 | REG_S ra,RAOFF(sp) 27 | # if (_MIPS_SIM == _ABIO32) 28 | call_push($2) 29 | call_push($3) 30 | # endif 31 | call_push($16) 32 | call_push($17) 33 | call_push($18) 34 | call_push($19) 35 | call_push($20) 36 | call_push($21) 37 | call_push($22) 38 | call_push($23) 39 | call_push($30) 40 | REG_L ra,RAOFF(sp) 41 | # ifdef RESTORE_GP64 42 | RESTORE_GP64 43 | # endif 44 | PTR_ADDU sp,FRAMESZ 45 | j ra 46 | .end GC_push_regs 47 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/Makefile.am: -------------------------------------------------------------------------------- 1 | #General sysdep utility headers, followed by the arch-specific ones 2 | nobase_sysdep_HEADERS= generic_pthread.h \ 3 | atomic_load_store.h \ 4 | aligned_atomic_load_store.h \ 5 | acquire_release_volatile.h \ 6 | char_acquire_release_volatile.h \ 7 | char_atomic_load_store.h \ 8 | short_acquire_release_volatile.h \ 9 | short_aligned_atomic_load_store.h \ 10 | short_atomic_load_store.h \ 11 | int_acquire_release_volatile.h \ 12 | int_aligned_atomic_load_store.h \ 13 | int_atomic_load_store.h \ 14 | all_acquire_release_volatile.h \ 15 | all_aligned_atomic_load_store.h \ 16 | all_atomic_load_store.h \ 17 | read_ordered.h \ 18 | ordered_except_wr.h \ 19 | ordered.h \ 20 | ao_t_is_int.h \ 21 | test_and_set_t_is_ao_t.h \ 22 | test_and_set_t_is_char.h \ 23 | emul_cas.h \ 24 | standard_ao_double_t.h \ 25 | README \ 26 | \ 27 | armcc/arm_v6.h \ 28 | \ 29 | gcc/alpha.h gcc/arm.h gcc/cris.h \ 30 | gcc/hppa.h gcc/ia64.h gcc/m68k.h \ 31 | gcc/mips.h gcc/powerpc.h gcc/s390.h \ 32 | gcc/sh.h gcc/sparc.h gcc/x86.h gcc/x86_64.h \ 33 | \ 34 | hpc/hppa.h hpc/ia64.h \ 35 | \ 36 | ibmc/powerpc.h \ 37 | \ 38 | icc/ia64.h \ 39 | \ 40 | msftc/arm.h msftc/common32_defs.h msftc/x86.h \ 41 | msftc/x86_64.h \ 42 | \ 43 | sunc/sparc.h sunc/x86.h sunc/x86_64.h 44 | 45 | sysdepdir= ${includedir}/atomic_ops/sysdeps 46 | 47 | # A few architectures require special .S files 48 | EXTRA_DIST = sunc/sparc.S 49 | -------------------------------------------------------------------------------- /regression/qsort.c: -------------------------------------------------------------------------------- 1 | // This implementation is based on "Introduction to algorithm" 2 | // (second edition), chap.8. 3 | 4 | int Array_print (int[] array, int left, int right) 5 | { 6 | int i; 7 | 8 | for (i=left; ipivot); 26 | do { 27 | i = i+1; 28 | } while (array[i]=right) 44 | return 0; 45 | 46 | 47 | index = partition (a, left, right); 48 | qsort (a, left, index); 49 | qsort (a, index+1, right); 50 | return 0; 51 | } 52 | 53 | int dragon () 54 | { 55 | int i; 56 | int size = 10; 57 | 58 | int[] array = new int[size]; 59 | 60 | 61 | for (i=0; i v into a hash h, 21 | * with the equality testing function "equals". 22 | * if such a binding already exists, then call dup(k). 23 | */ 24 | void Hash_insert(T h, K k, V v); 25 | 26 | 27 | V Hash_lookup(T h, K k); 28 | // Just behave as "lookup", but return the 29 | // found key in "*result" (if result!=0). 30 | V Hash_lookupCand(T h, K k, K *result); 31 | /* lookup the key "k" in the hash "h". 32 | * if the item not found, then call gen(k) to generate 33 | * a value insert the binding "k->v" into the hash 34 | * before returning v. 35 | */ 36 | V Hash_lookupOrInsert(T h, 37 | K k, 38 | V (*gen)(K)); 39 | 40 | /* delete a key k from a hash. Error if k not exists, 41 | * call notFound (k). 42 | */ 43 | void Hash_delete(T h, K x); 44 | 45 | // apply f to each k in h. 46 | void Hash_foreach(T h, void (*f)(K)); 47 | 48 | double Hash_loadFactor(T h); 49 | 50 | String_t Hash_status(T h); 51 | 52 | void Hash_statusAll(void); 53 | 54 | long Hash_size(T h); 55 | 56 | long Hash_numItems(T h); 57 | 58 | // turn key into a list. 59 | List_t Hash_keyToList(T h); 60 | 61 | #undef K 62 | #undef V 63 | #undef T 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/lib/mem.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "gc.h" 5 | #include "mem.h" 6 | 7 | long Mem_allocated = 0; 8 | long Mem_initFlag = 0; 9 | 10 | /* the accumulated time should include GC time */ 11 | static clock_t totalClocks = 0; 12 | 13 | void Mem_init(void) { 14 | //GC_INIT(); 15 | totalClocks = 0; 16 | } 17 | 18 | #undef GC_MALLOC 19 | #define GC_MALLOC malloc 20 | 21 | void *Mem_alloc(long size) { 22 | void *p; 23 | clock_t start, finish; 24 | 25 | start = clock(); 26 | p = GC_MALLOC((unsigned long) size); 27 | if (0 == p) 28 | Error_error("allocation failed\n"); 29 | 30 | // initialized it with zeros to catch bugs 31 | { 32 | char *cp = (char *) p; 33 | assert(cp); 34 | for (long i = 0; i < size; i++) 35 | cp[i] = '\0'; 36 | } 37 | 38 | // status info 39 | Mem_allocated += size; 40 | finish = clock(); 41 | totalClocks += (finish - start); 42 | return p; 43 | } 44 | 45 | clock_t Mem_getClock(void) { 46 | return totalClocks; 47 | } 48 | 49 | #define ONEM (1024 * 1024) 50 | 51 | void Mem_status(void) { 52 | unsigned long total = 0, sinceLast = 0; 53 | 54 | //total = GC_get_total_bytes(); 55 | //sinceLast = GC_get_bytes_since_gc(); 56 | printf("Heap status:\n" 57 | " Total allocation : %lu bytes (~%ldM)\n" 58 | " Allocation since last GC: %ld bytes (~%ldM)\n", 59 | total, total / ONEM, 60 | sinceLast, sinceLast / ONEM); 61 | 62 | Mem_allocated = 0; 63 | return; 64 | } 65 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/all_atomic_load_store.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* 24 | * Describes architectures on which AO_t, unsigned char, unsigned short, 25 | * and unsigned int loads and stores are atomic for all normally legal 26 | * alignments. 27 | */ 28 | #include "atomic_load_store.h" 29 | #include "char_atomic_load_store.h" 30 | #include "short_atomic_load_store.h" 31 | #include "int_atomic_load_store.h" 32 | -------------------------------------------------------------------------------- /src/control/error-msg.c: -------------------------------------------------------------------------------- 1 | #include "error-msg.h" 2 | #include 3 | #include 4 | #include 5 | 6 | static int numErrors = 0; 7 | 8 | void ErrorMsg_warn(String_t msg) { 9 | fprintf(stderr, 10 | "Warning: %s\n", 11 | msg); 12 | } 13 | 14 | void ErrorMsg_die(String_t msg) { 15 | fprintf(stderr, 16 | "Error: %s\n", 17 | msg); 18 | exit(0); 19 | } 20 | 21 | void ErrorMsg_lexError(char *s, char *file, 22 | int line, int column) { 23 | numErrors++; 24 | fprintf(stderr, "Lexical error: (file %s, " 25 | "line %d, column %d)\n%s\n", 26 | file, 27 | line, 28 | column, 29 | s); 30 | exit(0); 31 | } 32 | 33 | void ErrorMsg_syntaxError(char *s, Region_t r) { 34 | assert(r); 35 | numErrors++; 36 | fprintf(stderr, "Syntax error: %s\n%s", 37 | Coordinate_toString(Region_from(r)), 38 | s); 39 | exit(0); 40 | } 41 | 42 | void ErrorMsg_elabError(char *s, Region_t r) { 43 | assert(s); 44 | numErrors++; 45 | if (r) 46 | fprintf(stderr, "Elaboration error: %s\n" 47 | "%s\n", 48 | Coordinate_toString(Region_from(r)), 49 | s); 50 | else 51 | fprintf(stderr, "Elaboration error: \n" 52 | " %s\n", 53 | s); 54 | } 55 | 56 | void ErrorMsg_init(void) { 57 | numErrors = 0; 58 | } 59 | 60 | void ErrorMsg_errorExit(void) { 61 | if (numErrors) { 62 | numErrors = 0; 63 | exit(0); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /gc/doc/doc.am: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 4 | # OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 5 | # 6 | # Permission is hereby granted to use or copy this program 7 | # for any purpose, provided the above notices are retained on all copies. 8 | # Permission to modify the code and to distribute modified code is granted, 9 | # provided the above notices are retained, and a notice that the code was 10 | # modified is included with the above copyright notice. 11 | # 12 | # Modified by: Grzegorz Jakacki 13 | # Modified by: Petter Urkedal 14 | 15 | ## Process this file with automake to produce Makefile.in. 16 | 17 | # installed documentation 18 | # 19 | dist_pkgdata_DATA = \ 20 | doc/barrett_diagram \ 21 | doc/debugging.html \ 22 | doc/gc.man \ 23 | doc/gcdescr.html \ 24 | doc/README \ 25 | doc/README.amiga \ 26 | doc/README.arm.cross \ 27 | doc/README.autoconf \ 28 | doc/README.changes \ 29 | doc/README.contributors \ 30 | doc/README.cords \ 31 | doc/README.DGUX386 \ 32 | doc/README.dj \ 33 | doc/README.environment \ 34 | doc/README.ews4800 \ 35 | doc/README.hp \ 36 | doc/README.linux \ 37 | doc/README.Mac \ 38 | doc/README.MacOSX \ 39 | doc/README.macros \ 40 | doc/README.OS2 \ 41 | doc/README.rs6000 \ 42 | doc/README.sgi \ 43 | doc/README.solaris2 \ 44 | doc/README.uts \ 45 | doc/README.win32 \ 46 | doc/README.win64 \ 47 | doc/overview.html \ 48 | doc/tree.html \ 49 | doc/leak.html \ 50 | doc/gcinterface.html \ 51 | doc/scale.html \ 52 | doc/README.darwin \ 53 | doc/simple_example.html \ 54 | doc/porting.html 55 | 56 | -------------------------------------------------------------------------------- /src/lib/stack.c: -------------------------------------------------------------------------------- 1 | #include "stack.h" 2 | #include "error.h" 3 | #include "mem.h" 4 | #include "string.h" 5 | #include "todo.h" 6 | #include "unused.h" 7 | #include 8 | #include 9 | 10 | #define T Stack_t 11 | #define P Poly_t 12 | 13 | T Stack_new(void) { 14 | return List_new(); 15 | } 16 | 17 | int Stack_isEmpty(T stk) { 18 | assert(stk); 19 | return List_isEmpty(stk); 20 | } 21 | 22 | void Stack_push(T stk, P x) { 23 | assert(stk); 24 | List_insertFirst(stk, x); 25 | return; 26 | } 27 | 28 | P Stack_pop(T stk) { 29 | T t; 30 | 31 | assert(stk); 32 | if (List_isEmpty(stk)) 33 | Error_error("try to pop on empty stacks\n"); 34 | t = stk->next->data; 35 | stk->next = stk->next->next; 36 | return t; 37 | } 38 | 39 | int Stack_size(T stk) { 40 | return List_size(stk); 41 | } 42 | 43 | T Stack_stack(P x1, ...) { 44 | UNUSED(x1); 45 | TODO; 46 | } 47 | 48 | char *Stack_toString(T stk, String_t sep, 49 | Poly_tyToString tx) { 50 | T temp = stk; 51 | String_t str = String_new("["); 52 | while (temp) { 53 | str = String_concat(str, 54 | tx(temp->data), 55 | sep, 56 | 0); 57 | temp = temp->next; 58 | } 59 | str = String_concat(str, "]", 0); 60 | return str; 61 | } 62 | 63 | P Stack_getTop(T stk) { 64 | assert(stk); 65 | if (List_isEmpty(stk)) { 66 | *((int *) 1) = 0; 67 | Error_error("try to get top of an empty stack"); 68 | } 69 | return stk->next->data; 70 | } 71 | 72 | #undef T 73 | #undef P 74 | -------------------------------------------------------------------------------- /src/x86/x86-main.c: -------------------------------------------------------------------------------- 1 | #include "x86-main.h" 2 | #include "../control/control.h" 3 | #include "../control/pass.h" 4 | #include "../lib/int.h" 5 | #include "peep-hole.h" 6 | #include "x86-codegen.h" 7 | #include "x86.h" 8 | 9 | static int counter = 0; 10 | 11 | static String_t genFileName(void) { 12 | String_t f = String_concat("", 13 | Control_asmDirectory, 14 | "files-", 15 | Int_toString(counter++), 16 | ".s", 17 | 0); 18 | return f; 19 | } 20 | 21 | static String_t outputX86(X86_Prog_t p) { 22 | String_t f; 23 | 24 | f = genFileName(); 25 | File_saveToFile(f, (Poly_tyPrint) X86_Prog_print, p); 26 | return f; 27 | } 28 | 29 | Tuple_t X86_main(Machine_Prog_t p) { 30 | Pass_t codeGen, 31 | peepHole, 32 | output; 33 | X86_Prog_t p1, p2; 34 | String_t f; 35 | 36 | codeGen = Pass_new("codegen", 37 | VERBOSE_SUBPASS, 38 | p, 39 | (Poly_tyId) X86_codegen); 40 | p1 = Pass_doit(&codeGen); 41 | 42 | peepHole = Pass_new("peephole", 43 | VERBOSE_SUBPASS, 44 | p1, 45 | (Poly_tyId) PeepHole_shrink); 46 | p2 = Pass_doit(&peepHole); 47 | // p1 = 0; 48 | 49 | output = Pass_new("output", 50 | VERBOSE_SUBPASS, 51 | p2, 52 | (Poly_tyId) outputX86); 53 | f = Pass_doit(&output); 54 | 55 | return Tuple_new(p2, f); 56 | } 57 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/all_aligned_atomic_load_store.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* 24 | * Describes architectures on which AO_t, unsigned char, unsigned short, 25 | * and unsigned int loads and stores are atomic for all normally legal 26 | * alignments. 27 | */ 28 | #include "aligned_atomic_load_store.h" 29 | #include "char_atomic_load_store.h" 30 | #include "short_aligned_atomic_load_store.h" 31 | #include "int_aligned_atomic_load_store.h" 32 | -------------------------------------------------------------------------------- /src/lib/char-buffer.c: -------------------------------------------------------------------------------- 1 | #include "char-buffer.h" 2 | #include "mem.h" 3 | #include 4 | 5 | #define T CharBuffer_t 6 | 7 | #define INIT_SIZE 16 8 | #define SCALE 2 9 | 10 | struct T { 11 | char *buffer; 12 | long last; 13 | long size; 14 | }; 15 | 16 | T CharBuffer_new(void) { 17 | T x; 18 | 19 | Mem_NEW(x); 20 | Mem_NEW_SIZE(x->buffer, INIT_SIZE); 21 | x->last = 0; 22 | x->size = INIT_SIZE; 23 | return x; 24 | } 25 | 26 | long CharBuffer_numItems(T x) { 27 | assert(x); 28 | return x->last; 29 | } 30 | 31 | void CharBuffer_resetIndex(T x) { 32 | assert(x); 33 | x->last = 0; 34 | } 35 | 36 | void CharBuffer_append(T x, int c) { 37 | char *tmp; 38 | 39 | assert(x); 40 | if (x->last >= x->size - 1) { 41 | tmp = x->buffer; 42 | Mem_NEW_SIZE(x->buffer, x->size * SCALE); 43 | x->size *= SCALE; 44 | for (long i = 0; i < x->last; i++) 45 | x->buffer[i] = tmp[i]; 46 | } 47 | x->buffer[x->last++] = (char) c; 48 | // return; 49 | } 50 | 51 | void CharBuffer_appendString(T x, String_t s) { 52 | assert(x); 53 | assert(s); 54 | while (*s) { 55 | CharBuffer_append(x, *s); 56 | s++; 57 | } 58 | // return; 59 | } 60 | 61 | 62 | String_t CharBuffer_toString(T x) { 63 | assert(x); 64 | x->buffer[x->last] = '\0'; 65 | return x->buffer; 66 | } 67 | 68 | String_t CharBuffer_toStringBeforeClear(T x) { 69 | String_t str = CharBuffer_toString(x); 70 | Mem_NEW_SIZE(x->buffer, INIT_SIZE); 71 | x->last = 0; 72 | x->size = INIT_SIZE; 73 | return str; 74 | } 75 | 76 | #undef T 77 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/Makefile.msft: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2003-2005 Hewlett-Packard Development Company, L.P. 3 | # 4 | # The really trivial win32/VC++ Makefile. Note that atomic_ops.c isn't useful. 5 | # And we rely on a pre-built test_atomic_include.h and generalize-small.h, 6 | # since we can't rely on sed. 7 | # Win32 clients only need to include the header files. 8 | # To install, copy atomic_ops.h and the atomic_ops/... tree to your favorite 9 | # include directory. 10 | 11 | #MY_CPU=X86 12 | #CPU=$(MY_CPU) 13 | #!include 14 | 15 | LIB_OBJS=atomic_ops_stack.obj atomic_ops_malloc.obj 16 | 17 | all: check 18 | 19 | atomic_ops_stack.obj: 20 | cl -O2 -c -DAO_ASSUME_WINDOWS98 atomic_ops_stack.c 21 | 22 | atomic_ops_malloc.obj: 23 | cl -O2 -c -DAO_ASSUME_WINDOWS98 atomic_ops_malloc.c 24 | 25 | test_atomic: ..\tests\test_atomic.c ..\tests\test_atomic_include.h 26 | cl -O2 -I. -DAO_ASSUME_WINDOWS98 ..\tests\test_atomic.c -o test_atomic 27 | 28 | test_atomic_w95: ..\tests\test_atomic.c ..\tests\test_atomic_include.h 29 | cl -O2 -I. ..\tests\test_atomic.c -o test_atomic_w95 30 | 31 | test_malloc: ..\tests\test_malloc.c ..\tests\test_atomic_include.h \ 32 | libatomic_ops_gpl.lib 33 | cl -O2 -DAO_ASSUME_WINDOWS98 -I. ..\tests\test_malloc.c -o test_malloc libatomic_ops_gpl.lib 34 | 35 | libatomic_ops_gpl.lib: $(LIB_OBJS) 36 | lib /MACHINE:i386 /out:libatomic_ops_gpl.lib $(LIB_OBJS) 37 | 38 | check: test_atomic test_atomic_w95 test_malloc 39 | echo The following will print lots of \"Missing ...\" messages. 40 | test_atomic_w95 41 | echo The following will print some \"Missing ...\" messages. 42 | test_atomic 43 | test_malloc 44 | 45 | 46 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/all_acquire_release_volatile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* 24 | * Describes architectures on which volatile AO_t, unsigned char, unsigned 25 | * short, and unsigned int loads and stores have acquire/release semantics for 26 | * all normally legal alignments. 27 | */ 28 | #include "acquire_release_volatile.h" 29 | #include "char_acquire_release_volatile.h" 30 | #include "short_acquire_release_volatile.h" 31 | #include "int_acquire_release_volatile.h" 32 | -------------------------------------------------------------------------------- /src/ssa/ssa-main.c: -------------------------------------------------------------------------------- 1 | #include "../control/pass.h" 2 | #include "type-check.h" 3 | #include "dead-block.h" 4 | #include "trans-ssa.h" 5 | #include "trivial-block.h" 6 | #include "union-block.h" 7 | #include "construct-ssa.h" 8 | #include "const-and-dead.h" 9 | #include "out-ssa.h" 10 | #include "ssa-main.h" 11 | 12 | Machine_Prog_t Ssa_main(Ssa_Prog_t p) { 13 | Pass_t typeCheck 14 | , deadBlock 15 | , trivialBlock 16 | , unionBlock 17 | , makeSsa 18 | , constAndDead 19 | , outSsa 20 | , trans; 21 | Machine_Prog_t q; 22 | 23 | typeCheck = Pass_new("type-check", VERBOSE_SUBPASS, p, (Poly_tyId) Ssa_typeCheck); 24 | p = Pass_doit(&typeCheck); 25 | 26 | // want to run this first for it simplifies 27 | // many later phases by cutting dead blocks 28 | deadBlock = Pass_new("deadBlock", VERBOSE_SUBPASS, p, (Poly_tyId) Ssa_deadBlock); 29 | p = Pass_doit(&deadBlock); 30 | 31 | trivialBlock = Pass_new("trivialBlock", VERBOSE_SUBPASS, p, (Poly_tyId) Ssa_trivialBlock); 32 | p = Pass_doit(&trivialBlock); 33 | 34 | unionBlock = Pass_new("unionBlock", VERBOSE_SUBPASS, p, (Poly_tyId) Ssa_unionBlock); 35 | p = Pass_doit(&unionBlock); 36 | 37 | makeSsa = Pass_new("consSsa", VERBOSE_SUBPASS, p, (Poly_tyId) Ssa_constructSsa); 38 | p = Pass_doit(&makeSsa); 39 | 40 | constAndDead = Pass_new("constAndDead", VERBOSE_SUBPASS, p, (Poly_tyId) Ssa_constAndDead); 41 | p = Pass_doit(&constAndDead); 42 | 43 | outSsa = Pass_new("outSsa", VERBOSE_SUBPASS, p, (Poly_tyId) Ssa_outSsa); 44 | p = Pass_doit(&outSsa); 45 | 46 | trans = Pass_new("consMachine", VERBOSE_SUBPASS, p, (Poly_tyId) Trans_ssa); 47 | q = Pass_doit(&trans); 48 | 49 | return q; 50 | } 51 | -------------------------------------------------------------------------------- /gc/libatomic_ops/configure.ac: -------------------------------------------------------------------------------- 1 | # Process this file with autoconf to produce a configure script. 2 | AC_INIT([libatomic_ops],[7.2alpha4]) 3 | AC_CANONICAL_TARGET([]) 4 | AC_CONFIG_SRCDIR(src/atomic_ops.c) 5 | AM_INIT_AUTOMAKE 6 | AC_PROG_RANLIB 7 | 8 | AM_CONFIG_HEADER(src/config.h) 9 | 10 | # Checks for programs. 11 | AM_PROG_CC_C_O 12 | AM_PROG_AS 13 | 14 | # Checks for functions. 15 | AC_FUNC_MMAP 16 | 17 | # Checks for header files. 18 | AC_HEADER_STDC 19 | # AC_CHECK_HEADERS([ ]) 20 | 21 | # Determine PIC flag, adjust default CFLAGS 22 | need_asm=false 23 | PICFLAG= 24 | AC_MSG_CHECKING(Determining PIC compiler flag) 25 | if test "$GCC" = yes; then 26 | AC_MSG_RESULT(-fPIC) 27 | PICFLAG=-fPIC 28 | else 29 | case "$host" in 30 | *-*-hpux*) 31 | AC_MSG_RESULT("+Z") 32 | PICFLAG="+Z" 33 | if test "$GCC" != yes; then 34 | CFLAGS="$CFLAGS +O2 -mt" 35 | fi 36 | ;; 37 | *-*-solaris*) 38 | AC_MSG_RESULT(-Kpic) 39 | PICFLAG=-Kpic 40 | if test "$GCC" != yes; then 41 | CFLAGS="$CFLAGS -O" 42 | need_asm=true 43 | fi 44 | ;; 45 | *-*-linux*) 46 | AC_MSG_RESULT(-fPIC) 47 | PICFLAG=-fPIC 48 | # Any Linux compiler had better be gcc compatible. 49 | ;; 50 | *) 51 | AC_MSG_RESULT("") 52 | ;; 53 | esac 54 | fi 55 | CFLAGS="$CFLAGS -DNDEBUG" 56 | 57 | AC_SUBST(PICFLAG) 58 | AC_SUBST(DEFS) 59 | 60 | AM_CONDITIONAL(NEED_ASM, test x$need_asm = xtrue) 61 | 62 | AC_CONFIG_FILES([Makefile src/Makefile src/atomic_ops/Makefile src/atomic_ops/sysdeps/Makefile doc/Makefile tests/Makefile]) 63 | AC_CONFIG_COMMANDS([default],[[]],[[ 64 | PICFLAG="${PICFLAG}" 65 | CC="${CC}" 66 | DEFS="${DEFS}" 67 | ]]) 68 | AC_OUTPUT 69 | -------------------------------------------------------------------------------- /src/control/control.h: -------------------------------------------------------------------------------- 1 | #ifndef CONTROL_H 2 | #define CONTROL_H 3 | 4 | #include "../lib/list.h" 5 | #include "../lib/string.h" 6 | 7 | typedef enum { 8 | VERBOSE_SILENT, 9 | VERBOSE_PASS, 10 | VERBOSE_SUBPASS, 11 | VERBOSE_DETAIL 12 | } Verbose_t; 13 | 14 | typedef enum { 15 | EXPERT_NORMAL, 16 | EXPERT_EXPERT 17 | } Expert_t; 18 | 19 | typedef enum { 20 | DUMP_AST, 21 | DUMP_HIL, 22 | DUMP_TAC, 23 | DUMP_MACHINE, 24 | DUMP_C, 25 | DUMP_X86 26 | } Dump_t; 27 | 28 | typedef enum { 29 | CODEGEN_C, 30 | CODEGEN_X86 31 | } Codegen_t; 32 | 33 | extern long Control_bufferSize; 34 | extern Codegen_t Control_codegen; 35 | extern Expert_t Control_expert; 36 | extern long Control_labelInfo; 37 | // show type information in ILs 38 | extern long Control_showType; 39 | extern List_t Control_trace; 40 | extern Verbose_t Control_verbose; 41 | extern String_t Control_out_file_name; 42 | 43 | // keep jpg, should be a more 44 | extern long Control_jpg; 45 | 46 | /* this is platform dependent, so should be 47 | * sent to another place. 48 | */ 49 | extern String_t Control_asmDirectory; 50 | extern String_t Control_libDirectory; 51 | extern String_t Control_headerDirectory; 52 | 53 | int Control_Verb_order(Verbose_t v1, Verbose_t v2); 54 | void Control_dump_insert(Dump_t); 55 | int Control_dump_lookup(Dump_t); 56 | // drop pass 57 | int Control_mayDropPass(String_t name); 58 | void Control_dropPass_insert(String_t name); 59 | 60 | // log pass 61 | int Control_logPass(String_t passname); 62 | void Control_logPass_insert(String_t passname); 63 | 64 | // code-generation-related 65 | extern int Control_Target_size; 66 | // 67 | void Control_init(void); 68 | void Control_printFlags(void); 69 | 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/test_and_set_t_is_char.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* 24 | * These are common definitions for architectures on which test_and_set 25 | * operates on byte sized quantities, the "clear" value contains 26 | * all zeroes, and the "set" value contains all ones. 27 | */ 28 | 29 | #define AO_TS_t unsigned char 30 | typedef enum {AO_BYTE_TS_clear = 0, AO_BYTE_TS_set = 0xff} AO_BYTE_TS_val; 31 | #define AO_TS_VAL_t AO_BYTE_TS_val 32 | #define AO_TS_CLEAR AO_BYTE_TS_clear 33 | #define AO_TS_SET AO_BYTE_TS_set 34 | 35 | #define AO_CHAR_TS_T 1 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/sunc/sparc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include "../all_atomic_load_store.h" 24 | 25 | /* Real SPARC code uses TSO: */ 26 | #include "../ordered_except_wr.h" 27 | 28 | /* Test_and_set location is just a byte. */ 29 | #include "../test_and_set_t_is_char.h" 30 | 31 | extern AO_TS_VAL_t 32 | AO_test_and_set_full(volatile AO_TS_t *addr); 33 | /* Implemented in separate .S file, for now. */ 34 | 35 | #define AO_HAVE_test_and_set_full 36 | 37 | /* FIXME: Like the gcc version, this needs to be extended for V8 */ 38 | /* and V9. */ 39 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/test_and_set_t_is_ao_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* 24 | * These are common definitions for architectures on which test_and_set 25 | * operates on pointer-sized quantities, the "clear" value contains 26 | * all zeroes, and the "set" value contains only one lowest bit set. 27 | * This can be used if test_and_set is synthesized from compare_and_swap. 28 | */ 29 | typedef enum {AO_TS_clear = 0, AO_TS_set = 1} AO_TS_val; 30 | #define AO_TS_VAL_t AO_TS_val 31 | #define AO_TS_CLEAR AO_TS_clear 32 | #define AO_TS_SET AO_TS_set 33 | 34 | #define AO_TS_t AO_t 35 | 36 | #define AO_AO_TS_T 1 37 | -------------------------------------------------------------------------------- /gc/stubborn.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers 3 | * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved. 4 | * 5 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 6 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 7 | * 8 | * Permission is hereby granted to use or copy this program 9 | * for any purpose, provided the above notices are retained on all copies. 10 | * Permission to modify the code and to distribute modified code is granted, 11 | * provided the above notices are retained, and a notice that the code was 12 | * modified is included with the above copyright notice. 13 | */ 14 | 15 | #include "private/gc_priv.h" 16 | 17 | #if defined(MANUAL_VDB) 18 | 19 | /* Stubborn object (hard to change, nearly immutable) allocation. */ 20 | /* This interface is deprecated. We mostly emulate it using */ 21 | /* MANUAL_VDB. But that imposes the additional constraint that */ 22 | /* written, but not yet GC_dirty()ed objects must be referenced */ 23 | /* by a stack. */ 24 | 25 | GC_API void * GC_CALL GC_malloc_stubborn(size_t lb) 26 | { 27 | return(GC_malloc(lb)); 28 | } 29 | 30 | GC_API void GC_CALL GC_end_stubborn_change(void *p) 31 | { 32 | GC_dirty(p); 33 | } 34 | 35 | /*ARGSUSED*/ 36 | GC_API void GC_CALL GC_change_stubborn(void *p) 37 | { 38 | } 39 | 40 | #else /* !MANUAL_VDB */ 41 | 42 | GC_API void * GC_CALL GC_malloc_stubborn(size_t lb) 43 | { 44 | return(GC_malloc(lb)); 45 | } 46 | 47 | /*ARGSUSED*/ 48 | GC_API void GC_CALL GC_end_stubborn_change(void *p) 49 | { 50 | } 51 | 52 | /*ARGSUSED*/ 53 | GC_API void GC_CALL GC_change_stubborn(void *p) 54 | { 55 | } 56 | 57 | #endif /* !MANUAL_VDB */ 58 | -------------------------------------------------------------------------------- /gc/gc_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved. 3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved. 4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved. 5 | * Copyright (c) 2000-2009 by Hewlett-Packard Development Company. 6 | * All rights reserved. 7 | * 8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 10 | * 11 | * Permission is hereby granted to use or copy this program 12 | * for any purpose, provided the above notices are retained on all copies. 13 | * Permission to modify the code and to distribute modified code is granted, 14 | * provided the above notices are retained, and a notice that the code was 15 | * modified is included with the above copyright notice. 16 | */ 17 | 18 | /* The version here should match that in configure/configure.ac */ 19 | /* Eventually this one may become unnecessary. For now we need */ 20 | /* it to keep the old-style build process working. */ 21 | #define GC_TMP_VERSION_MAJOR 7 22 | #define GC_TMP_VERSION_MINOR 2 23 | #define GC_TMP_ALPHA_VERSION 4 24 | 25 | #ifndef GC_NOT_ALPHA 26 | # define GC_NOT_ALPHA 0xff 27 | #endif 28 | 29 | #if defined(GC_VERSION_MAJOR) 30 | # if GC_TMP_VERSION_MAJOR != GC_VERSION_MAJOR || \ 31 | GC_TMP_VERSION_MINOR != GC_VERSION_MINOR || \ 32 | defined(GC_ALPHA_VERSION) != (GC_TMP_ALPHA_VERSION != GC_NOT_ALPHA) || \ 33 | defined(GC_ALPHA_VERSION) && GC_TMP_ALPHA_VERSION != GC_ALPHA_VERSION 34 | # error Inconsistent version info. Check doc/README, include/gc_version.h, and configure.ac. 35 | # endif 36 | #else 37 | # define GC_VERSION_MAJOR GC_TMP_VERSION_MAJOR 38 | # define GC_VERSION_MINOR GC_TMP_VERSION_MINOR 39 | # define GC_ALPHA_VERSION GC_TMP_ALPHA_VERSION 40 | #endif 41 | -------------------------------------------------------------------------------- /gc/tests/huge_test.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #ifndef GC_IGNORE_WARN 7 | /* Ignore misleading "Out of Memory!" warning (which is printed on */ 8 | /* every GC_MALLOC(LONG_MAX) call) by defining this macro before */ 9 | /* "gc.h" inclusion. */ 10 | # define GC_IGNORE_WARN 11 | #endif 12 | 13 | #include "gc.h" 14 | 15 | /* 16 | * Check that very large allocation requests fail. "Success" would usually 17 | * indicate that the the size was somehow converted to a negative 18 | * number. Clients shouldn't do this, but we should fail in the 19 | * expected manner. 20 | */ 21 | 22 | int main(void) 23 | { 24 | GC_INIT(); 25 | 26 | GC_set_max_heap_size(100*1024*1024); 27 | /* Otherwise heap expansion aborts when deallocating large block. */ 28 | /* That's OK. We test this corner case mostly to make sure that */ 29 | /* it fails predictably. */ 30 | GC_expand_hp(1024*1024*5); 31 | if (sizeof(long) == sizeof(void *)) { 32 | void *r = GC_MALLOC(LONG_MAX-1024); 33 | if (0 != r) { 34 | fprintf(stderr, 35 | "Size LONG_MAX-1024 allocation unexpectedly succeeded\n"); 36 | exit(1); 37 | } 38 | r = GC_MALLOC(LONG_MAX); 39 | if (0 != r) { 40 | fprintf(stderr, 41 | "Size LONG_MAX allocation unexpectedly succeeded\n"); 42 | exit(1); 43 | } 44 | r = GC_MALLOC((size_t)LONG_MAX + 1024); 45 | if (0 != r) { 46 | fprintf(stderr, 47 | "Size LONG_MAX+1024 allocation unexpectedly succeeded\n"); 48 | exit(1); 49 | } 50 | } 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /src/control/log.c: -------------------------------------------------------------------------------- 1 | #include "log.h" 2 | #include "../lib/error.h" 3 | #include 4 | #include 5 | 6 | struct Log_t { 7 | int effective;// whether this logger is on 8 | String_t name;// name of the log file 9 | File_t file; // log file pointer 10 | }; 11 | 12 | static struct Log_t log = {0, 0, 0}; 13 | 14 | void Log_set(String_t name) { 15 | if (log.effective) 16 | Error_error("don't support nested log\n"); 17 | 18 | log.effective = 1; 19 | log.name = String_concat(name, ".log", 0); 20 | log.file = File_open(log.name, "w+"); 21 | } 22 | 23 | void Log_reset(void) { 24 | if (!log.effective) 25 | Error_impossible(); 26 | 27 | log.effective = 0; 28 | log.name = 0; 29 | File_close(log.file); 30 | } 31 | 32 | void Log_dot(void (*f)(Poly_t, String_t), Poly_t p, String_t s) { 33 | assert(s); 34 | if (!log.effective) 35 | return; 36 | 37 | f(p, s); 38 | } 39 | 40 | void Log_str(String_t s) { 41 | assert(s); 42 | if (!log.effective) 43 | return; 44 | 45 | File_write(log.file, s); 46 | File_write(log.file, "\n"); 47 | // 48 | File_flush(log.file); 49 | } 50 | 51 | void Log_strs(String_t s, ...) { 52 | va_list ap; 53 | String_t current; 54 | 55 | if (!log.effective) 56 | return; 57 | 58 | File_write(log.file, s); 59 | va_start(ap, s); 60 | current = va_arg(ap, String_t); 61 | while (current) { 62 | File_write(log.file, current); 63 | current = va_arg(ap, String_t); 64 | } 65 | //File_write (log.file, "\n"); 66 | va_end(ap); 67 | File_flush(log.file); 68 | } 69 | 70 | void Log_fun(Poly_t a, File_t (*f)(File_t, Poly_t)) { 71 | if (!log.effective) 72 | return; 73 | 74 | f(log.file, a); 75 | File_flush(log.file); 76 | } 77 | -------------------------------------------------------------------------------- /src/elaborate/env.h: -------------------------------------------------------------------------------- 1 | #ifndef ENV_H 2 | #define ENV_H 3 | 4 | #include "../ast/ast-id.h" 5 | #include "type.h" 6 | 7 | ///////////////////////////////////////////////////// 8 | // Env binding. For "Venv" and "Senv". 9 | typedef struct { 10 | Type_t type; 11 | AstId_t fresh; 12 | } *Env_Binding_t; 13 | 14 | Env_Binding_t Env_Binding_new(Type_t, AstId_t); 15 | 16 | /////////////////////////////////////////////////////// 17 | // ClassName env. 18 | /* This env stores all 19 | * defined class names. This is used in the 1st pass 20 | * scan of all classes. The result Id_t is the fresh 21 | * name the class is assigned. 22 | * 23 | * Cenv: Id_t -> {Id_t, List_t} 24 | */ 25 | void Cenv_init(void); 26 | 27 | // insert a new class name and it's fields into Cenv. 28 | // If a name already exist, report errors. 29 | AstId_t Cenv_insert(AstId_t id, List_t); 30 | 31 | // peek. Slient for non-existing names. 32 | AstId_t Cenv_lookup(AstId_t id); 33 | 34 | // peek. Complain for non-existing names. 35 | AstId_t Cenv_lookupMustExist(AstId_t); 36 | 37 | // peek class fields, must exist 38 | List_t Cenv_lookupFields(AstId_t); 39 | 40 | /////////////////////////////////////////////////////// 41 | /* variable env: 42 | * Stack> 43 | */ 44 | void Venv_init(void); 45 | 46 | AstId_t Venv_insert(AstId_t id, Type_t type); 47 | 48 | Env_Binding_t Venv_lookup(AstId_t); 49 | 50 | Env_Binding_t Venv_lookupMustExist(AstId_t); 51 | 52 | void Venv_enterScope(void); 53 | 54 | void Venv_exitScope(void); 55 | 56 | /////////////////////////////////////////////////////// 57 | /* Class field env: 58 | * Id_t * Id_t -> Id_t 59 | */ 60 | void Senv_init(void); 61 | 62 | AstId_t Senv_insert(AstId_t sid, AstId_t fid, Type_t ty); 63 | 64 | Env_Binding_t Senv_lookupMustExist(AstId_t sid, AstId_t fid); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /gc/include/gc_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved. 3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved. 4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved. 5 | * Copyright (c) 2000-2009 by Hewlett-Packard Development Company. 6 | * All rights reserved. 7 | * 8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 10 | * 11 | * Permission is hereby granted to use or copy this program 12 | * for any purpose, provided the above notices are retained on all copies. 13 | * Permission to modify the code and to distribute modified code is granted, 14 | * provided the above notices are retained, and a notice that the code was 15 | * modified is included with the above copyright notice. 16 | */ 17 | 18 | /* The version here should match that in configure/configure.ac */ 19 | /* Eventually this one may become unnecessary. For now we need */ 20 | /* it to keep the old-style build process working. */ 21 | #define GC_TMP_VERSION_MAJOR 7 22 | #define GC_TMP_VERSION_MINOR 2 23 | #define GC_TMP_ALPHA_VERSION 4 24 | 25 | #ifndef GC_NOT_ALPHA 26 | # define GC_NOT_ALPHA 0xff 27 | #endif 28 | 29 | #if defined(GC_VERSION_MAJOR) 30 | # if GC_TMP_VERSION_MAJOR != GC_VERSION_MAJOR || \ 31 | GC_TMP_VERSION_MINOR != GC_VERSION_MINOR || \ 32 | defined(GC_ALPHA_VERSION) != (GC_TMP_ALPHA_VERSION != GC_NOT_ALPHA) || \ 33 | defined(GC_ALPHA_VERSION) && GC_TMP_ALPHA_VERSION != GC_ALPHA_VERSION 34 | # error Inconsistent version info. Check doc/README, include/gc_version.h, and configure.ac. 35 | # endif 36 | #else 37 | # define GC_VERSION_MAJOR GC_TMP_VERSION_MAJOR 38 | # define GC_VERSION_MINOR GC_TMP_VERSION_MINOR 39 | # define GC_ALPHA_VERSION GC_TMP_ALPHA_VERSION 40 | #endif 41 | -------------------------------------------------------------------------------- /gc/configure.host: -------------------------------------------------------------------------------- 1 | # configure.host 2 | 3 | # This shell script handles all host based configuration for the garbage 4 | # collector. 5 | # It sets various shell variables based on the the host and the 6 | # configuration options. You can modify this shell script without 7 | # needing to rerun autoconf. 8 | 9 | # This shell script should be invoked as 10 | # . configure.host 11 | # If it encounters an error, it will exit with a message. 12 | 13 | # It uses the following shell variables: 14 | # host The configuration host 15 | # host_cpu The configuration host CPU 16 | # target_optspace --enable-target-optspace ("yes", "no", "") 17 | # GCC should be "yes" if using gcc 18 | 19 | # It sets the following shell variables: 20 | # gc_cflags Special CFLAGS to use when building 21 | 22 | gc_cflags="" 23 | 24 | # We should set -fexceptions if we are using gcc and might be used 25 | # inside something like gcj. This is the zeroth approximation: 26 | if test :"$GCC": = :yes: ; then 27 | gc_cflags="${gc_cflags} -fexceptions" 28 | else 29 | case "$host" in 30 | hppa*-*-hpux* ) 31 | if test :$GCC: != :"yes": ; then 32 | gc_cflags="${gc_flags} +ESdbgasm" 33 | fi 34 | # :TODO: actaully we should check using Autoconf if 35 | # the compiler supports this option. 36 | ;; 37 | esac 38 | fi 39 | 40 | case "${target_optspace}:${host}" in 41 | yes:*) 42 | gc_cflags="${gc_cflags} -Os" 43 | ;; 44 | :m32r-* | :d10v-* | :d30v-*) 45 | gc_cflags="${gc_cflags} -Os" 46 | ;; 47 | no:* | :*) 48 | # Nothing. 49 | ;; 50 | esac 51 | 52 | # Set any host dependent compiler flags. 53 | # THIS TABLE IS SORTED. KEEP IT THAT WAY. 54 | 55 | case "${host}" in 56 | mips-tx39-*|mipstx39-unknown-*) 57 | gc_cflags="${gc_cflags} -G 0" 58 | ;; 59 | *) 60 | ;; 61 | esac 62 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/atomic_load_store.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* 24 | * Definitions for architectures on which loads and stores of AO_t are 25 | * atomic for all legal alignments. 26 | */ 27 | 28 | AO_INLINE AO_t 29 | AO_load(const volatile AO_t *addr) 30 | { 31 | /* Cast away the volatile for architectures like IA64 where */ 32 | /* volatile adds barrier semantics. */ 33 | return (*(const AO_t *)addr); 34 | } 35 | 36 | #define AO_HAVE_load 37 | 38 | AO_INLINE void 39 | AO_store(volatile AO_t *addr, AO_t new_val) 40 | { 41 | (*(AO_t *)addr) = new_val; 42 | } 43 | 44 | #define AO_HAVE_store 45 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops_malloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* Almost lock-free malloc implementation based on stack implementation. */ 24 | /* See README.malloc file for detailed usage rules. */ 25 | 26 | #ifndef AO_ATOMIC_H 27 | #define AO_ATOMIC_H 28 | 29 | #include /* For size_t */ 30 | 31 | #include "atomic_ops_stack.h" 32 | 33 | #ifdef AO_STACK_IS_LOCK_FREE 34 | # define AO_MALLOC_IS_LOCK_FREE 35 | #endif 36 | 37 | void AO_free(void *); 38 | 39 | void * AO_malloc(size_t); 40 | 41 | /* Allow use of mmpa to grow the heap. No-op on some platforms. */ 42 | void AO_malloc_enable_mmap(void); 43 | 44 | #endif /* !AO_ATOMIC_H */ 45 | -------------------------------------------------------------------------------- /gc/javaxfc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved. 3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved. 4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved. 5 | * Copyright (c) 2000-2009 by Hewlett-Packard Development Company. 6 | * All rights reserved. 7 | * 8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 10 | * 11 | * Permission is hereby granted to use or copy this program 12 | * for any purpose, provided the above notices are retained on all copies. 13 | * Permission to modify the code and to distribute modified code is granted, 14 | * provided the above notices are retained, and a notice that the code was 15 | * modified is included with the above copyright notice. 16 | */ 17 | 18 | #ifndef GC_H 19 | # include "gc.h" 20 | #endif 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /* 27 | * Invoke all remaining finalizers that haven't yet been run. (Since the 28 | * notifier is not called, this should be called from a separate thread.) 29 | * This function is needed for strict compliance with the Java standard, 30 | * which can make the runtime guarantee that all finalizers are run. 31 | * This is problematic for several reasons: 32 | * 1) It means that finalizers, and all methods called by them, 33 | * must be prepared to deal with objects that have been finalized in 34 | * spite of the fact that they are still referenced by statically 35 | * allocated pointer variables. 36 | * 1) It may mean that we get stuck in an infinite loop running 37 | * finalizers which create new finalizable objects, though that's 38 | * probably unlikely. 39 | * Thus this is not recommended for general use. 40 | */ 41 | GC_API void GC_CALL GC_finalize_all(void); 42 | 43 | #ifdef __cplusplus 44 | } /* end of extern "C" */ 45 | #endif 46 | -------------------------------------------------------------------------------- /gc/include/javaxfc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved. 3 | * Copyright (c) 1996 by Silicon Graphics. All rights reserved. 4 | * Copyright (c) 1998 by Fergus Henderson. All rights reserved. 5 | * Copyright (c) 2000-2009 by Hewlett-Packard Development Company. 6 | * All rights reserved. 7 | * 8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 10 | * 11 | * Permission is hereby granted to use or copy this program 12 | * for any purpose, provided the above notices are retained on all copies. 13 | * Permission to modify the code and to distribute modified code is granted, 14 | * provided the above notices are retained, and a notice that the code was 15 | * modified is included with the above copyright notice. 16 | */ 17 | 18 | #ifndef GC_H 19 | # include "gc.h" 20 | #endif 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /* 27 | * Invoke all remaining finalizers that haven't yet been run. (Since the 28 | * notifier is not called, this should be called from a separate thread.) 29 | * This function is needed for strict compliance with the Java standard, 30 | * which can make the runtime guarantee that all finalizers are run. 31 | * This is problematic for several reasons: 32 | * 1) It means that finalizers, and all methods called by them, 33 | * must be prepared to deal with objects that have been finalized in 34 | * spite of the fact that they are still referenced by statically 35 | * allocated pointer variables. 36 | * 1) It may mean that we get stuck in an infinite loop running 37 | * finalizers which create new finalizable objects, though that's 38 | * probably unlikely. 39 | * Thus this is not recommended for general use. 40 | */ 41 | GC_API void GC_CALL GC_finalize_all(void); 42 | 43 | #ifdef __cplusplus 44 | } /* end of extern "C" */ 45 | #endif 46 | -------------------------------------------------------------------------------- /gc/libatomic_ops/tests/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST=test_atomic.template list_atomic.template run_parallel.inc \ 2 | test_atomic_include.h 3 | # We distribute test_atomic_include.h, since it's hard to regenerate 4 | # on Windows without sed. 5 | 6 | BUILT_SOURCES = test_atomic_include.h list_atomic.i 7 | CLEANFILES = test_atomic_include.h list_atomic.c list_atomic.i 8 | 9 | AM_CPPFLAGS=-I$(srcdir)/../src 10 | 11 | TESTS=test_atomic test_atomic_pthreads test_stack test_malloc 12 | 13 | #create the test_atomic test program 14 | check_PROGRAMS=test_atomic test_atomic_pthreads test_stack test_malloc 15 | 16 | test_atomic_SOURCES=test_atomic.c 17 | test_atomic_LDADD=-lpthread ../src/libatomic_ops.a 18 | 19 | test_atomic_pthreads_SOURCES=test_atomic.c 20 | test_atomic_pthreads_CPPFLAGS=-DAO_USE_PTHREAD_DEFS $(AM_CPPFLAGS) 21 | test_atomic_pthreads_LDADD=-lpthread ../src/libatomic_ops.a 22 | 23 | test_stack_SOURCES=test_stack.c 24 | test_stack_LDADD=-lpthread ../src/libatomic_ops_gpl.a ../src/libatomic_ops.a 25 | 26 | test_malloc_SOURCES=test_malloc.c 27 | test_malloc_LDADD=-lpthread ../src/libatomic_ops_gpl.a ../src/libatomic_ops.a 28 | 29 | test_atomic_include.h: test_atomic.template 30 | sed -e s/XX// $? > $@ 31 | sed -e s/XX/_release/ $? >> $@ 32 | sed -e s/XX/_acquire/ $? >> $@ 33 | sed -e s/XX/_read/ $? >> $@ 34 | sed -e s/XX/_write/ $? >> $@ 35 | sed -e s/XX/_full/ $? >> $@ 36 | sed -e s/XX/_release_write/ $? >> $@ 37 | sed -e s/XX/_acquire_read/ $? >> $@ 38 | 39 | list_atomic.c: list_atomic.template 40 | echo "#include \"atomic_ops.h\" " > $@ 41 | sed -e s/XX// $? >> $@ 42 | sed -e s/XX/_release/ $? >> $@ 43 | sed -e s/XX/_acquire/ $? >> $@ 44 | sed -e s/XX/_read/ $? >> $@ 45 | sed -e s/XX/_write/ $? >> $@ 46 | sed -e s/XX/_full/ $? >> $@ 47 | sed -e s/XX/_release_write/ $? >> $@ 48 | sed -e s/XX/_acquire_read/ $? >> $@ 49 | 50 | list_atomic.i: list_atomic.c 51 | $(COMPILE) $? -E > list_atomic.i 52 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/int_atomic_load_store.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 by Hewlett-Packard Company. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* 24 | * Definitions for architectures on which loads and stores of unsigned int are 25 | * atomic for all legal alignments. 26 | */ 27 | 28 | AO_INLINE unsigned int 29 | AO_int_load(const volatile unsigned int *addr) 30 | { 31 | /* Cast away the volatile for architectures like IA64 where */ 32 | /* volatile adds barrier semantics. */ 33 | return (*(const unsigned int *)addr); 34 | } 35 | 36 | #define AO_HAVE_int_load 37 | 38 | AO_INLINE void 39 | AO_int_store(volatile unsigned int *addr, unsigned int new_val) 40 | { 41 | (*(unsigned int *)addr) = new_val; 42 | } 43 | 44 | #define AO_HAVE_int_store 45 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/char_atomic_load_store.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 by Hewlett-Packard Company. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* 24 | * Definitions for architectures on which loads and stores of unsigned char are 25 | * atomic for all legal alignments. 26 | */ 27 | 28 | AO_INLINE unsigned char 29 | AO_char_load(const volatile unsigned char *addr) 30 | { 31 | /* Cast away the volatile for architectures like IA64 where */ 32 | /* volatile adds barrier semantics. */ 33 | return (*(const unsigned char *)addr); 34 | } 35 | 36 | #define AO_HAVE_char_load 37 | 38 | AO_INLINE void 39 | AO_char_store(volatile unsigned char *addr, unsigned char new_val) 40 | { 41 | (*(unsigned char *)addr) = new_val; 42 | } 43 | 44 | #define AO_HAVE_char_store 45 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/short_atomic_load_store.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 by Hewlett-Packard Company. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* 24 | * Definitions for architectures on which loads and stores of unsigned short 25 | * are atomic for all legal alignments. 26 | */ 27 | 28 | AO_INLINE unsigned short 29 | AO_short_load(const volatile unsigned short *addr) 30 | { 31 | /* Cast away the volatile for architectures like IA64 where */ 32 | /* volatile adds barrier semantics. */ 33 | return (*(const unsigned short *)addr); 34 | } 35 | 36 | #define AO_HAVE_short_load 37 | 38 | AO_INLINE void 39 | AO_short_store(volatile unsigned short *addr, unsigned short new_val) 40 | { 41 | (*(unsigned short *)addr) = new_val; 42 | } 43 | 44 | #define AO_HAVE_short_store 45 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/aligned_atomic_load_store.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* 24 | * Definitions for architectures on which loads and stores of AO_t are 25 | * atomic fo all legal alignments. 26 | */ 27 | 28 | AO_INLINE AO_t 29 | AO_load(const volatile AO_t *addr) 30 | { 31 | assert(((size_t)addr & (sizeof(AO_t) - 1)) == 0); 32 | /* Cast away the volatile for architectures where */ 33 | /* volatile adds barrier semantics. */ 34 | return *(AO_t *)addr; 35 | } 36 | 37 | #define AO_HAVE_load 38 | 39 | AO_INLINE void 40 | AO_store(volatile AO_t *addr, AO_t new_val) 41 | { 42 | assert(((size_t)addr & (sizeof(AO_t) - 1)) == 0); 43 | (*(AO_t *)addr) = new_val; 44 | } 45 | 46 | #define AO_HAVE_store 47 | -------------------------------------------------------------------------------- /gc/libatomic_ops/tests/list_atomic.template: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 by Hewlett-Packard Company. All rights reserved. 3 | * 4 | * This file is covered by the GNU general public license, version 2. 5 | * see doc/COPYING for details. 6 | */ 7 | 8 | /* This generates a compilable program. But it is really meant to be */ 9 | /* be used only with cc -E, to inspect the expensions generated by */ 10 | /* primitives. */ 11 | 12 | /* The result will not link or run. */ 13 | 14 | void list_atomicXX(void) 15 | { 16 | AO_T *addr, val, newval, oldval; 17 | AO_TS_T tsaddr; 18 | long incr; 19 | 20 | # if defined(AO_HAVE_nopXX) 21 | "AO_nopXX(): "; 22 | AO_nopXX(); 23 | # else 24 | "No AO_nopXX"; 25 | # endif 26 | # if defined(AO_HAVE_loadXX) 27 | "AO_loadXX(addr):"; 28 | AO_loadXX(addr); 29 | # else 30 | "No AO_loadXX"; 31 | # endif 32 | # if defined(AO_HAVE_storeXX) 33 | "AO_storeXX(addr, val):"; 34 | AO_storeXX(addr, val); 35 | # else 36 | "No AO_storeXX"; 37 | # endif 38 | # if defined(AO_HAVE_test_and_setXX) 39 | "AO_test_and_setXX(tsaddr):"; 40 | AO_test_and_setXX(tsaddr); 41 | # else 42 | "No AO_test_and_setXX"; 43 | # endif 44 | # if defined(AO_HAVE_fetch_and_add1XX) 45 | "AO_fetch_and_add1XX(addr):"; 46 | AO_fetch_and_add1XX(addr); 47 | # else 48 | "No AO_fetch_and_add1XX"; 49 | # endif 50 | # if defined(AO_HAVE_fetch_and_sub1XX) 51 | "AO_fetch_and_sub1XX(addr):"; 52 | AO_fetch_and_sub1XX(addr); 53 | # else 54 | "No AO_fetch_and_sub1XX"; 55 | # endif 56 | # if defined(AO_HAVE_fetch_and_addXX) 57 | "AO_fetch_and_addXX(addr, incr):"; 58 | AO_fetch_and_addXX(addr, incr); 59 | # else 60 | "No AO_fetch_and_addXX"; 61 | # endif 62 | # if defined(AO_HAVE_compare_and_swapXX) 63 | "AO_compare_and_swapXX(addr, oldval, newval):"; 64 | AO_compare_and_swapXX(addr, oldval, newval); 65 | # else 66 | "No AO_compare_and_swapXX"; 67 | # endif 68 | } 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/lib/list.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_H 2 | #define LIST_H 3 | 4 | #include "file.h" 5 | #include "poly.h" 6 | #include "string.h" 7 | 8 | #define T List_t 9 | #define P Poly_t 10 | 11 | typedef struct T *T; 12 | struct T { 13 | Poly_t data; 14 | List_t next; 15 | }; 16 | 17 | typedef P (*Poly_tyFold)(P, P); 18 | 19 | typedef File_t (*Poly_tyListPrint)(File_t, P); 20 | 21 | T List_new(void); 22 | 23 | T List_concat(T, T); 24 | 25 | int List_isEmpty(T l); 26 | 27 | int List_size(T l); 28 | 29 | void List_insertFirst(T l, P x); 30 | 31 | void List_insertLast(T l, P x); 32 | 33 | void List_foreach(T l, void (*f)(P)); 34 | 35 | void List_append(T l1, T l2); 36 | 37 | void List_appendNode(T l1, T l2); 38 | 39 | void List_delete(T l1, P x, Poly_tyEquals equals); 40 | 41 | void List_deleteAll(T, Poly_tyPred pred); 42 | 43 | T List_map(T l, Poly_tyId f); 44 | 45 | T List_list(P x, ...); 46 | 47 | P List_removeHead(T l); 48 | 49 | P List_nth(T l, int n); 50 | // f (f (f (starter, x1), x2), ...) 51 | P List_foldl(T list, P starter, P (*f)(P, P)); 52 | 53 | T List_rev(T l); 54 | 55 | int List_exists(T l, P x, Poly_tyEquals f); 56 | 57 | /* find the first element y, which satisfied f(x, y), and 58 | * apply g(y) before return. 59 | */ 60 | int List_exists2(T l, P x, 61 | Poly_tyEquals f, 62 | Poly_tyVoid g); 63 | 64 | T List_filter(T l, Poly_tyPred f); 65 | 66 | T List_getFirst(T l); 67 | 68 | String_t List_toString(T list, 69 | String_t sep, 70 | String_t (*f)(P)); 71 | 72 | String_t List_toStringNoLastSep(T list, 73 | String_t sep, 74 | String_t (*f)(P)); 75 | 76 | // print out "list" to "file", with separator "sep", 77 | // "sep" does not appear last, each element is print out 78 | // by "f". 79 | File_t List_print(T list, String_t sep, File_t file, File_t (*f)(File_t, Poly_t)); 80 | 81 | #undef P 82 | #undef T 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /gc/include.am: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 4 | # OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 5 | # 6 | # Permission is hereby granted to use or copy this program 7 | # for any purpose, provided the above notices are retained on all copies. 8 | # Permission to modify the code and to distribute modified code is granted, 9 | # provided the above notices are retained, and a notice that the code was 10 | # modified is included with the above copyright notice. 11 | # 12 | # Modified by: Grzegorz Jakacki 13 | # Modified by: Petter Urkedal 14 | 15 | ## Process this file with automake to produce part of Makefile.in. 16 | 17 | # installed headers 18 | # 19 | pkginclude_HEADERS += \ 20 | include/gc.h \ 21 | include/gc_typed.h \ 22 | include/gc_inline.h \ 23 | include/gc_mark.h \ 24 | include/gc_cpp.h \ 25 | include/weakpointer.h \ 26 | include/new_gc_alloc.h \ 27 | include/gc_allocator.h \ 28 | include/gc_backptr.h \ 29 | include/gc_gcj.h \ 30 | include/leak_detector.h \ 31 | include/gc_amiga_redirects.h \ 32 | include/gc_pthread_redirects.h \ 33 | include/gc_config_macros.h \ 34 | include/gc_tiny_fl.h \ 35 | include/gc_version.h 36 | 37 | # headers which are not installed 38 | # 39 | dist_noinst_HEADERS += \ 40 | include/private/gc_hdrs.h \ 41 | include/private/gc_priv.h \ 42 | include/private/gcconfig.h \ 43 | include/private/gc_pmark.h \ 44 | include/private/gc_locks.h \ 45 | include/private/dbg_mlc.h \ 46 | include/private/specific.h \ 47 | include/private/cord_pos.h \ 48 | include/private/pthread_support.h \ 49 | include/private/pthread_stop_world.h \ 50 | include/private/darwin_semaphore.h \ 51 | include/private/darwin_stop_world.h \ 52 | include/private/thread_local_alloc.h \ 53 | include/cord.h \ 54 | include/ec.h \ 55 | include/javaxfc.h 56 | 57 | # unprefixed header 58 | include_HEADERS += \ 59 | include/extra/gc.h \ 60 | include/extra/gc_cpp.h 61 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/config.h.in: -------------------------------------------------------------------------------- 1 | /* src/config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if you have the `getpagesize' function. */ 4 | #undef HAVE_GETPAGESIZE 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #undef HAVE_INTTYPES_H 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #undef HAVE_MEMORY_H 11 | 12 | /* Define to 1 if you have a working `mmap' system call. */ 13 | #undef HAVE_MMAP 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_STDINT_H 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #undef HAVE_STDLIB_H 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_STRINGS_H 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_STRING_H 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_SYS_STAT_H 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_SYS_TYPES_H 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #undef HAVE_UNISTD_H 35 | 36 | /* Define to 1 if your C compiler doesn't accept -c and -o together. */ 37 | #undef NO_MINUS_C_MINUS_O 38 | 39 | /* Name of package */ 40 | #undef PACKAGE 41 | 42 | /* Define to the address where bug reports for this package should be sent. */ 43 | #undef PACKAGE_BUGREPORT 44 | 45 | /* Define to the full name of this package. */ 46 | #undef PACKAGE_NAME 47 | 48 | /* Define to the full name and version of this package. */ 49 | #undef PACKAGE_STRING 50 | 51 | /* Define to the one symbol short name of this package. */ 52 | #undef PACKAGE_TARNAME 53 | 54 | /* Define to the home page for this package. */ 55 | #undef PACKAGE_URL 56 | 57 | /* Define to the version of this package. */ 58 | #undef PACKAGE_VERSION 59 | 60 | /* Define to 1 if you have the ANSI C header files. */ 61 | #undef STDC_HEADERS 62 | 63 | /* Version number of package */ 64 | #undef VERSION 65 | -------------------------------------------------------------------------------- /gc/include/include.am: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 4 | # OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 5 | # 6 | # Permission is hereby granted to use or copy this program 7 | # for any purpose, provided the above notices are retained on all copies. 8 | # Permission to modify the code and to distribute modified code is granted, 9 | # provided the above notices are retained, and a notice that the code was 10 | # modified is included with the above copyright notice. 11 | # 12 | # Modified by: Grzegorz Jakacki 13 | # Modified by: Petter Urkedal 14 | 15 | ## Process this file with automake to produce part of Makefile.in. 16 | 17 | # installed headers 18 | # 19 | pkginclude_HEADERS += \ 20 | include/gc.h \ 21 | include/gc_typed.h \ 22 | include/gc_inline.h \ 23 | include/gc_mark.h \ 24 | include/gc_cpp.h \ 25 | include/weakpointer.h \ 26 | include/new_gc_alloc.h \ 27 | include/gc_allocator.h \ 28 | include/gc_backptr.h \ 29 | include/gc_gcj.h \ 30 | include/leak_detector.h \ 31 | include/gc_amiga_redirects.h \ 32 | include/gc_pthread_redirects.h \ 33 | include/gc_config_macros.h \ 34 | include/gc_tiny_fl.h \ 35 | include/gc_version.h 36 | 37 | # headers which are not installed 38 | # 39 | dist_noinst_HEADERS += \ 40 | include/private/gc_hdrs.h \ 41 | include/private/gc_priv.h \ 42 | include/private/gcconfig.h \ 43 | include/private/gc_pmark.h \ 44 | include/private/gc_locks.h \ 45 | include/private/dbg_mlc.h \ 46 | include/private/specific.h \ 47 | include/private/cord_pos.h \ 48 | include/private/pthread_support.h \ 49 | include/private/pthread_stop_world.h \ 50 | include/private/darwin_semaphore.h \ 51 | include/private/darwin_stop_world.h \ 52 | include/private/thread_local_alloc.h \ 53 | include/cord.h \ 54 | include/ec.h \ 55 | include/javaxfc.h 56 | 57 | # unprefixed header 58 | include_HEADERS += \ 59 | include/extra/gc.h \ 60 | include/extra/gc_cpp.h 61 | -------------------------------------------------------------------------------- /gc/doc/README.sgi: -------------------------------------------------------------------------------- 1 | Performance of the incremental collector can be greatly enhanced with 2 | -DNO_EXECUTE_PERMISSION. 3 | 4 | The collector should run with all of the -32, -n32 and -64 ABIs. Remember to 5 | define the AS macro in the Makefile to be "as -64", or "as -n32". 6 | 7 | If you use -DREDIRECT_MALLOC=GC_malloc with C++ code, your code should make 8 | at least one explicit call to malloc instead of new to ensure that the proper 9 | version of malloc is linked in. 10 | 11 | Sproc threads are not supported in this version, though there may exist other 12 | ports. 13 | 14 | Pthreads support is provided. This requires that: 15 | 16 | 1) You compile the collector with -DGC_IRIX_THREADS specified in the Makefile. 17 | 18 | 2) You have the latest pthreads patches installed. 19 | 20 | (Though the collector makes only documented pthread calls, 21 | it relies on signal/threads interactions working just right in ways 22 | that are not required by the standard. It is unlikely that this code 23 | will run on other pthreads platforms. But please tell me if it does.) 24 | 25 | 3) Every file that makes thread calls should define IRIX_THREADS and then 26 | include gc.h. Gc.h redefines some of the pthread primitives as macros which 27 | also provide the collector with information it requires. 28 | 29 | 4) pthread_cond_wait and pthread_cond_timed_wait should be prepared for 30 | premature wakeups. (I believe the pthreads and realted standards require this 31 | anyway. Irix pthreads often terminate a wait if a signal arrives. 32 | The garbage collector uses signals to stop threads.) 33 | 34 | 5) It is expensive to stop a thread waiting in IO at the time the request is 35 | initiated. Applications with many such threads may not exhibit acceptable 36 | performance with the collector. (Increasing the heap size may help.) 37 | 38 | 6) The collector should not be compiled with -DREDIRECT_MALLOC. This 39 | confuses some library calls made by the pthreads implementation, which 40 | expect the standard malloc. 41 | 42 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/int_aligned_atomic_load_store.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* 24 | * Definitions for architectures on which loads and stores of unsigned int are 25 | * atomic for all legal alignments. 26 | */ 27 | 28 | AO_INLINE unsigned int 29 | AO_int_load(const volatile unsigned int *addr) 30 | { 31 | assert(((size_t)addr & (sizeof(unsigned int) - 1)) == 0); 32 | /* Cast away the volatile for architectures like IA64 where */ 33 | /* volatile adds barrier semantics. */ 34 | return (*(unsigned int *)addr); 35 | } 36 | 37 | #define AO_HAVE_int_load 38 | 39 | AO_INLINE void 40 | AO_int_store(volatile unsigned int *addr, unsigned int new_val) 41 | { 42 | assert(((size_t)addr & (sizeof(unsigned int) - 1)) == 0); 43 | (*(unsigned int *)addr) = new_val; 44 | } 45 | 46 | #define AO_HAVE_int_store 47 | -------------------------------------------------------------------------------- /gc/PCR-Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Default target 3 | # 4 | 5 | default: gc.o 6 | 7 | include ../config/common.mk 8 | 9 | # 10 | # compilation flags, etc. 11 | # 12 | 13 | 14 | CPPFLAGS = $(INCLUDE) $(CONFIG_CPPFLAGS) \ 15 | -DPCR_NO_RENAME -DPCR_NO_HOSTDEP_ERR 16 | #CFLAGS = -DPCR $(CONFIG_CFLAGS) 17 | CFLAGS = -DPCR $(CONFIG_CFLAGS) 18 | SPECIALCFLAGS = # For code involving asm's 19 | 20 | ASPPFLAGS = $(INCLUDE) $(CONFIG_ASPPFLAGS) \ 21 | -DPCR_NO_RENAME -DPCR_NO_HOSTDEP_ERR -DASM 22 | 23 | ASFLAGS = $(CONFIG_ASFLAGS) 24 | 25 | LDRFLAGS = $(CONFIG_LDRFLAGS) 26 | 27 | LDFLAGS = $(CONFIG_LDFLAGS) 28 | 29 | # 30 | # 31 | # 32 | # 33 | # BEGIN PACKAGE-SPECIFIC PART 34 | # 35 | # 36 | # 37 | # 38 | 39 | # Fix to point to local pcr installation directory. 40 | PCRDIR= .. 41 | 42 | COBJ= alloc.o reclaim.o allchblk.o misc.o os_dep.o mark_rts.o headers.o mark.o obj_map.o pcr_interface.o blacklst.o finalize.o new_hblk.o real_malloc.o dyn_load.o dbg_mlc.o malloc.o stubborn.o checksums.o solaris_threads.o typd_mlc.o ptr_chck.o mallocx.o 43 | 44 | CSRC= reclaim.c allchblk.c misc.c alloc.c mach_dep.c os_dep.c mark_rts.c headers.c mark.c obj_map.c pcr_interface.c blacklst.c finalize.c new_hblk.c real_malloc.c dyn_load.c dbg_mlc.c malloc.c stubborn.c checksums.c solaris_threads.c typd_mlc.c ptr_chck.c mallocx.c 45 | 46 | SHELL= /bin/sh 47 | 48 | default: gc.o 49 | 50 | gc.o: $(COBJ) mach_dep.o 51 | $(LDR) $(CONFIG_LDRFLAGS) -o gc.o $(COBJ) mach_dep.o 52 | 53 | 54 | mach_dep.o: mach_dep.c mips_mach_dep.s rs6000_mach_dep.s if_mach if_not_there 55 | rm -f mach_dep.o 56 | ./if_mach MIPS "" as -o mach_dep.o mips_mach_dep.s 57 | ./if_mach POWERPC AIX as -o mach_dep.o rs6000_mach_dep.s 58 | ./if_mach ALPHA "" as -o mach_dep.o alpha_mach_dep.s 59 | ./if_mach SPARC SOLARIS as -o mach_dep.o sparc_mach_dep.s 60 | ./if_not_there mach_dep.o $(CC) -c $(SPECIALCFLAGS) mach_dep.c 61 | 62 | if_mach: extra/if_mach.c gcconfig.h 63 | $(CC) $(CFLAGS) -o if_mach extra/if_mach.c 64 | 65 | if_not_there: extra/if_not_there.c 66 | $(CC) $(CFLAGS) -o if_not_there extra/if_not_there.c 67 | 68 | 69 | -------------------------------------------------------------------------------- /gc/ec.h: -------------------------------------------------------------------------------- 1 | # ifndef EC_H 2 | # define EC_H 3 | 4 | # ifndef CORD_H 5 | # include "cord.h" 6 | # endif 7 | 8 | /* Extensible cords are strings that may be destructively appended to. */ 9 | /* They allow fast construction of cords from characters that are */ 10 | /* being read from a stream. */ 11 | /* 12 | * A client might look like: 13 | * 14 | * { 15 | * CORD_ec x; 16 | * CORD result; 17 | * char c; 18 | * FILE *f; 19 | * 20 | * ... 21 | * CORD_ec_init(x); 22 | * while(...) { 23 | * c = getc(f); 24 | * ... 25 | * CORD_ec_append(x, c); 26 | * } 27 | * result = CORD_balance(CORD_ec_to_cord(x)); 28 | * 29 | * If a C string is desired as the final result, the call to CORD_balance 30 | * may be replaced by a call to CORD_to_char_star. 31 | */ 32 | 33 | # ifndef CORD_BUFSZ 34 | # define CORD_BUFSZ 128 35 | # endif 36 | 37 | typedef struct CORD_ec_struct { 38 | CORD ec_cord; 39 | char * ec_bufptr; 40 | char ec_buf[CORD_BUFSZ+1]; 41 | } CORD_ec[1]; 42 | 43 | /* This structure represents the concatenation of ec_cord with */ 44 | /* ec_buf[0 ... (ec_bufptr-ec_buf-1)] */ 45 | 46 | /* Flush the buffer part of the extended chord into ec_cord. */ 47 | /* Note that this is almost the only real function, and it is */ 48 | /* implemented in 6 lines in cordxtra.c */ 49 | void CORD_ec_flush_buf(CORD_ec x); 50 | 51 | /* Convert an extensible cord to a cord. */ 52 | # define CORD_ec_to_cord(x) (CORD_ec_flush_buf(x), (x)[0].ec_cord) 53 | 54 | /* Initialize an extensible cord. */ 55 | # define CORD_ec_init(x) ((x)[0].ec_cord = 0, (x)[0].ec_bufptr = (x)[0].ec_buf) 56 | 57 | /* Append a character to an extensible cord. */ 58 | # define CORD_ec_append(x, c) \ 59 | { \ 60 | if ((x)[0].ec_bufptr == (x)[0].ec_buf + CORD_BUFSZ) { \ 61 | CORD_ec_flush_buf(x); \ 62 | } \ 63 | *((x)[0].ec_bufptr)++ = (c); \ 64 | } 65 | 66 | /* Append a cord to an extensible cord. Structure remains shared with */ 67 | /* original. */ 68 | void CORD_ec_append_cord(CORD_ec x, CORD s); 69 | 70 | # endif /* EC_H */ 71 | -------------------------------------------------------------------------------- /gc/libatomic_ops/src/atomic_ops/sysdeps/short_aligned_atomic_load_store.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* 24 | * Definitions for architectures on which loads and stores of unsigned short 25 | * are atomic for all legal alignments. 26 | */ 27 | 28 | AO_INLINE unsigned short 29 | AO_short_load(const volatile unsigned short *addr) 30 | { 31 | assert(((size_t)addr & (sizeof(unsigned short) - 1)) == 0); 32 | /* Cast away the volatile for architectures like IA64 where */ 33 | /* volatile adds barrier semantics. */ 34 | return (*(unsigned short *)addr); 35 | } 36 | 37 | #define AO_HAVE_short_load 38 | 39 | AO_INLINE void 40 | AO_short_store(volatile unsigned short *addr, unsigned short new_val) 41 | { 42 | assert(((size_t)addr & (sizeof(unsigned short) - 1)) == 0); 43 | (*(unsigned short *)addr) = new_val; 44 | } 45 | 46 | #define AO_HAVE_short_store 47 | -------------------------------------------------------------------------------- /gc/include/ec.h: -------------------------------------------------------------------------------- 1 | # ifndef EC_H 2 | # define EC_H 3 | 4 | # ifndef CORD_H 5 | # include "cord.h" 6 | # endif 7 | 8 | /* Extensible cords are strings that may be destructively appended to. */ 9 | /* They allow fast construction of cords from characters that are */ 10 | /* being read from a stream. */ 11 | /* 12 | * A client might look like: 13 | * 14 | * { 15 | * CORD_ec x; 16 | * CORD result; 17 | * char c; 18 | * FILE *f; 19 | * 20 | * ... 21 | * CORD_ec_init(x); 22 | * while(...) { 23 | * c = getc(f); 24 | * ... 25 | * CORD_ec_append(x, c); 26 | * } 27 | * result = CORD_balance(CORD_ec_to_cord(x)); 28 | * 29 | * If a C string is desired as the final result, the call to CORD_balance 30 | * may be replaced by a call to CORD_to_char_star. 31 | */ 32 | 33 | # ifndef CORD_BUFSZ 34 | # define CORD_BUFSZ 128 35 | # endif 36 | 37 | typedef struct CORD_ec_struct { 38 | CORD ec_cord; 39 | char * ec_bufptr; 40 | char ec_buf[CORD_BUFSZ+1]; 41 | } CORD_ec[1]; 42 | 43 | /* This structure represents the concatenation of ec_cord with */ 44 | /* ec_buf[0 ... (ec_bufptr-ec_buf-1)] */ 45 | 46 | /* Flush the buffer part of the extended chord into ec_cord. */ 47 | /* Note that this is almost the only real function, and it is */ 48 | /* implemented in 6 lines in cordxtra.c */ 49 | void CORD_ec_flush_buf(CORD_ec x); 50 | 51 | /* Convert an extensible cord to a cord. */ 52 | # define CORD_ec_to_cord(x) (CORD_ec_flush_buf(x), (x)[0].ec_cord) 53 | 54 | /* Initialize an extensible cord. */ 55 | # define CORD_ec_init(x) ((x)[0].ec_cord = 0, (x)[0].ec_bufptr = (x)[0].ec_buf) 56 | 57 | /* Append a character to an extensible cord. */ 58 | # define CORD_ec_append(x, c) \ 59 | { \ 60 | if ((x)[0].ec_bufptr == (x)[0].ec_buf + CORD_BUFSZ) { \ 61 | CORD_ec_flush_buf(x); \ 62 | } \ 63 | *((x)[0].ec_bufptr)++ = (c); \ 64 | } 65 | 66 | /* Append a cord to an extensible cord. Structure remains shared with */ 67 | /* original. */ 68 | void CORD_ec_append_cord(CORD_ec x, CORD s); 69 | 70 | # endif /* EC_H */ 71 | -------------------------------------------------------------------------------- /src/atoms/id.c: -------------------------------------------------------------------------------- 1 | #include "id.h" 2 | #include "../lib/hash.h" 3 | #include "../lib/int.h" 4 | #include "../lib/mem.h" 5 | #include "../lib/property-list.h" 6 | #include "../lib/random.h" 7 | #include 8 | 9 | #define T Id_t 10 | 11 | /* table: String_t -> Id_t 12 | */ 13 | static Hash_t table = 0; 14 | 15 | static int counter = 0; 16 | 17 | struct T { 18 | String_t name; 19 | String_t newName; 20 | long hashCode; 21 | Plist_t plist; 22 | }; 23 | 24 | 25 | static T Id_create(String_t s) { 26 | T x; 27 | 28 | assert(s); 29 | Mem_NEW(x); 30 | x->name = s; 31 | x->newName = 0; 32 | x->hashCode = String_hashCode(s); 33 | x->plist = Plist_new(); 34 | return x; 35 | } 36 | 37 | T Id_bogus(void) { 38 | return Id_create(""); 39 | } 40 | 41 | T Id_fromString(String_t s) { 42 | T x; 43 | 44 | assert(s); 45 | x = Hash_lookupOrInsert(table, s, (tyKV) Id_create); 46 | return x; 47 | } 48 | 49 | T Id_newNoName(void) { 50 | T x; 51 | Mem_NEW(x); 52 | x->name = 0; 53 | x->newName = String_concat("x_", 54 | Int_toString(counter++), 55 | 0); 56 | x->hashCode = Random_nextInt(); 57 | x->plist = Plist_new(); 58 | return x; 59 | } 60 | 61 | long Id_hashCode(T x) { 62 | assert(x); 63 | return x->hashCode; 64 | } 65 | 66 | String_t Id_toString(T x) { 67 | assert(x); 68 | assert(((x->name == 0) && (x->newName == 0))); 69 | return (x->name) ? (x->name) : (x->newName); 70 | } 71 | 72 | void Id_init(void) { 73 | table = Hash_new((tyHashCode) String_hashCode, (Poly_tyEquals) String_equals 74 | // should never call this function. 75 | , 76 | 0); 77 | } 78 | 79 | long Id_equals(T x, T y) { 80 | assert(x); 81 | assert(y); 82 | return x == y; 83 | } 84 | 85 | Plist_t Id_plist(T x) { 86 | assert(x); 87 | return x->plist; 88 | } 89 | 90 | void Id_print(T x) { 91 | assert(x); 92 | assert((x->name == 0) && (x->newName == 0)); 93 | printf("%s", (x->name) ? (x->name) : (x->newName)); 94 | } 95 | 96 | 97 | #undef T 98 | --------------------------------------------------------------------------------