Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Obliterate exec. Kill it dead.

git-svn-id: https://svn.parrot.org/parrot/branches/kill_jit@41346 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
commit 80f9b3a83c160943ad3b61b2de66afcae9802d15 1 parent 52a040b
darbelo authored
View
7 MANIFEST
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Fri Sep 18 21:45:35 2009 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Fri Sep 18 23:13:26 2009 UT
#
# See below for documentation on the format of this file.
#
@@ -968,7 +968,6 @@ include/parrot/encoding.h [main]include
include/parrot/enums.h [main]include
include/parrot/events.h [main]include
include/parrot/exceptions.h [main]include
-include/parrot/exec.h [main]include
include/parrot/exit.h [main]include
include/parrot/extend.h [main]include
include/parrot/gc_api.h [main]include
@@ -1272,10 +1271,6 @@ src/dynpmc/subproxy.pmc [devel]src
src/embed.c []
src/events.c []
src/exceptions.c []
-src/exec.c []
-src/exec_save.c []
-src/exec_save.h []
-src/exec_start.c []
src/exit.c []
src/extend.c []
src/frame_builder.c []
View
10 config/gen/makefiles/root.in
@@ -1062,10 +1062,6 @@ $(SRC_DIR)/library$(O) : $(GENERAL_H_FILES)
$(INC_DIR)/extend_vtable.h $(SRC_DIR)/extend_vtable.c $(SRC_DIR)/vtable.h : src/vtable.tbl $(BUILD_TOOLS_DIR)/vtable_extend.pl lib/Parrot/Vtable.pm
$(PERL) $(BUILD_TOOLS_DIR)/vtable_extend.pl
-$(SRC_DIR)/exec_start$(O) : $(GENERAL_H_FILES) @TEMP_exec_h@
-
-$(SRC_DIR)/exec_save$(O) : $(GENERAL_H_FILES) @TEMP_exec_h@
-
$(SRC_DIR)/key$(O) : $(GENERAL_H_FILES) $(SRC_DIR)/key.str $(SRC_DIR)/pmc/pmc_key.h
$(SRC_DIR)/gc/mark_sweep$(O) : $(GENERAL_H_FILES) $(SRC_DIR)/gc/gc_private.h
@@ -1635,7 +1631,6 @@ prog-clean :
$(SRC_DIR)/null_config$(O) \
$(SRC_DIR)/parrot_config$(O) \
$(SRC_DIR)/install_config$(O) \
- $(SRC_DIR)/exec_start$(O) \
$(SRC_DIR)/nci_test$(O) \
$(LIBNCI_TEST_SO) \
$(SRC_DIR)/glut_callbacks$(O) \
@@ -1671,7 +1666,6 @@ archclean: dynoplibs-clean dynpmc-clean dynext-clean
$(SRC_DIR)/null_config$(O) \
$(SRC_DIR)/parrot_config$(O) \
$(SRC_DIR)/install_config$(O) \
- $(SRC_DIR)/exec_start$(O) \
install_config.fpmc \
$(SRC_DIR)/nci_test$(O) \
$(LIBNCI_TEST_SO) \
@@ -2159,8 +2153,8 @@ win32-inno-installer : world installable
#
###############################################################################
-exec : $(SRC_DIR)/exec_start$(O) $(SRC_DIR)/parrot_config$(O) $(LIBPARROT)
- $(LINK) @ld_out@$(EXEC)$(EXE) $(EXEC)$(O) $(SRC_DIR)/exec_start$(O) $(SRC_DIR)/parrot_config$(O) @rpath_blib@ $(ALL_PARROT_LIBS) $(LINKFLAGS)
+exec : $(SRC_DIR)/parrot_config$(O) $(LIBPARROT)
+ $(LINK) @ld_out@$(EXEC)$(EXE) $(EXEC)$(O) $(SRC_DIR)/parrot_config$(O) @rpath_blib@ $(ALL_PARROT_LIBS) $(LINKFLAGS)
###### OS depend targets ##########
View
187 include/parrot/exec.h
@@ -1,187 +0,0 @@
-/*
- * Copyright (C) 2003-2007, Parrot Foundation.
- */
-
-/*
- * exec.h
- *
- * SVN Info
- * $Id$
- * Overview:
- * Exec header file.
- * History:
- * Initial version by Daniel Grunblatt on 2003.6.9
- * Notes:
- * References:
- */
-
-#ifndef PARROT_EXEC_H_GUARD
-#define PARROT_EXEC_H_GUARD
-
-#if EXEC_CAPABLE
-
-# ifdef PARROT_EXEC_OS_OPENBSD
-# ifdef PARROT_OPENBSD_ELF
-# define EXEC_ELF
-# else
-# define EXEC_A_OUT
-# endif
-# endif
-# ifdef PARROT_EXEC_OS_DARWIN
-# define EXEC_MACH_O
-# endif
-# if defined(PARROT_EXEC_OS_FREEBSD) || defined(PARROT_EXEC_OS_NETBSD) || defined(PARROT_EXEC_OS_LINUX)
-# define EXEC_ELF
-# endif
-# if defined(PARROT_EXEC_OS_MSWIN32) || defined(PARROT_EXEC_OS_CYGWIN)
-# define EXEC_COFF
-# endif
-
-# ifdef EXEC_A_OUT
-# define EXEC_CALLDISP jit_info->arena.start - jit_info->native_ptr - 4
-# elif defined(EXEC_COFF)
-# define EXEC_CALLDISP 0
-# else
-# define EXEC_CALLDISP 0xfffffffc
-# endif
-
-/* Symbol types */
-# define STYPE_UND 1 /* Undefined */
-# define STYPE_GCC 2 /* GCC */
-# ifdef I386
-# define STYPE_GDATA 3 /* Global data */
-# define STYPE_FUNC 4 /* Function */
-# else
-# define STYPE_GDATA 0x0F020000 /* Global data */
-# define STYPE_FUNC 0x0F010000 /* Function */
-# endif
-# define STYPE_COM 5 /* Variable */
-
-/* Rellocation types */
-# define RTYPE_DATA 1 /* Data */
-# define RTYPE_COM 2 /* Variable */
-# define RTYPE_FUNC 3 /* Function */
-# define RTYPE_DATA1 4 /* 2nd. rellocation for RISC machines */
-
-typedef struct Parrot_exec_symbol_t {
- int offset_list;
- int type;
- int value;
- const char *symbol;
-} Parrot_exec_symbol_t;
-
-typedef struct Parrot_exec_rellocation_t {
- int offset;
- short symbol_number;
- int type;
-} Parrot_exec_rellocation_t;
-
-typedef struct Parrot_exec_section_t {
- char *code;
- size_t size;
-} Parrot_exec_section_t;
-
-typedef struct Parrot_exec_objfile_t {
- Parrot_exec_section_t text;
- Parrot_exec_section_t data;
- Parrot_exec_section_t bss;
- int *data_size;
- int data_count;
- Parrot_exec_rellocation_t *text_rellocation_table;
- int text_rellocation_count;
- Parrot_exec_rellocation_t *data_rellocation_table;
- int data_rellocation_count;
- Parrot_exec_symbol_t *symbol_table;
- int symbol_count;
- int symbol_list_size;
- int bytecode_header_size;
-} Parrot_exec_objfile_t;
-
-/* HEADERIZER BEGIN: src/exec.c */
-/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
-
-PARROT_EXPORT
-void Parrot_exec_add_text_rellocation(
- ARGIN(Parrot_exec_objfile_t *obj),
- ARGIN(char *nptr),
- int type,
- ARGIN(const char *symbol),
- int disp)
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(4);
-
-PARROT_EXPORT
-void Parrot_exec_add_text_rellocation_func(
- ARGIN(Parrot_exec_objfile_t *obj),
- ARGIN(char *nptr),
- ARGIN(const char *func_name))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3);
-
-PARROT_EXPORT
-PARROT_CAN_RETURN_NULL
-int * Parrot_exec_add_text_rellocation_reg(
- ARGIN(Parrot_exec_objfile_t *obj),
- ARGIN(char *nptr),
- ARGIN(const char *var),
- int offset,
- int disp)
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3);
-
-void Parrot_exec(PARROT_INTERP,
- ARGIN(opcode_t *pc),
- ARGIN(opcode_t *code_start),
- ARGIN(opcode_t *code_end))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3)
- __attribute__nonnull__(4);
-
-int Parrot_exec_add_symbol(
- ARGMOD(Parrot_exec_objfile_t *obj),
- ARGIN(const char *symbol),
- int stype)
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(*obj);
-
-#define ASSERT_ARGS_Parrot_exec_add_text_rellocation \
- __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(obj) \
- || PARROT_ASSERT_ARG(nptr) \
- || PARROT_ASSERT_ARG(symbol)
-#define ASSERT_ARGS_Parrot_exec_add_text_rellocation_func \
- __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(obj) \
- || PARROT_ASSERT_ARG(nptr) \
- || PARROT_ASSERT_ARG(func_name)
-#define ASSERT_ARGS_Parrot_exec_add_text_rellocation_reg \
- __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(obj) \
- || PARROT_ASSERT_ARG(nptr) \
- || PARROT_ASSERT_ARG(var)
-#define ASSERT_ARGS_Parrot_exec __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(pc) \
- || PARROT_ASSERT_ARG(code_start) \
- || PARROT_ASSERT_ARG(code_end)
-#define ASSERT_ARGS_Parrot_exec_add_symbol __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(obj) \
- || PARROT_ASSERT_ARG(symbol)
-/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
-/* HEADERIZER END: src/exec.c */
-
-#endif /* EXEC_CAPABLE */
-
-#endif /* PARROT_EXEC_H_GUARD */
-
-/*
- * Local variables:
- * c-file-style: "parrot"
- * End:
- * vim: expandtab shiftwidth=4:
- */
View
417 src/exec.c
@@ -1,417 +0,0 @@
-/*
-Copyright (C) 2001-2009, Parrot Foundation.
-$Id$
-
-=head1 NAME
-
-src/exec.c - Generate an object file
-
-=head1 DESCRIPTION
-
-=head2 Functions
-
-=over 4
-
-=cut
-
-*/
-
-#include <parrot/parrot.h>
-#ifdef HAVE_COMPUTED_GOTO
-# include <parrot/oplib/core_ops_cgp.h>
-#endif /* HAVE_COMPUTED_GOTO */
-#include "parrot/exec.h"
-#include "jit.h"
-#define JIT_EMIT 1
-#include "jit_emit.h"
-#include "exec_dep.h"
-#include "exec_save.h"
-#include "parrot/compiler.h"
-
-/* HEADERIZER HFILE: include/parrot/exec.h */
-
-/* HEADERIZER BEGIN: static */
-/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
-
-static void add_data_member(
- ARGMOD(Parrot_exec_objfile_t *obj),
- ARGIN_NULLOK(const void *src),
- size_t len)
- __attribute__nonnull__(1)
- FUNC_MODIFIES(*obj);
-
-static void exec_init(ARGIN(Parrot_exec_objfile_t *obj))
- __attribute__nonnull__(1);
-
-static int symbol_list_find(
- ARGIN(const Parrot_exec_objfile_t *obj),
- ARGIN(const char *symbol))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-#define ASSERT_ARGS_add_data_member __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(obj)
-#define ASSERT_ARGS_exec_init __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(obj)
-#define ASSERT_ARGS_symbol_list_find __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(obj) \
- || PARROT_ASSERT_ARG(symbol)
-/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
-/* HEADERIZER END: static */
-
-/*
- * Parrot_exec_run must be 0 while the program runs.
- * It will be set to 2 inside eval (s. eval.pmc)
- * to switch to runops_jit (s. interpreter.c:runops_exec()).
- * Must be 1 while starting the compiled code to have Parrot_new()
- * return the address of the global interpreter (s. interpreter.c)
- * and PackFile_ConstTable_unpack use the global const_table (s. packfile.c).
- * Must also be 1 while generating the executable.
- */
-
-int Parrot_exec_run = 0;
-
-/*
-
-=item C<void Parrot_exec(PARROT_INTERP, opcode_t *pc, opcode_t *code_start,
-opcode_t *code_end)>
-
-Call the jit to get the program code. Adds the members of the data
-section. And emits the executable.
-
-=cut
-
-*/
-
-void
-Parrot_exec(PARROT_INTERP, ARGIN(opcode_t *pc),
- ARGIN(opcode_t *code_start), ARGIN(opcode_t *code_end))
-{
- ASSERT_ARGS(Parrot_exec)
-#ifdef JIT_CGP
- int i, j *k;
-#endif
- const char *output;
- long bhs;
- Parrot_jit_info_t *jit_info;
-
- Parrot_exec_objfile_t * const obj =
- mem_allocate_zeroed_typed(Parrot_exec_objfile_t);
- exec_init(obj);
- obj->bytecode_header_size =
- (interp->code->base.file_offset + 4) * sizeof (opcode_t);
- jit_info = parrot_build_asm(interp, code_start, code_end,
- obj, JIT_CODE_FILE);
-
- /* TODO Go zero the calls to jited opcodes. */
- /* Place the program code in the data section. */
- /* program_code */
- add_data_member(obj, interp->code->base.pf->src,
- interp->code->base.pf->size);
- /* opcode_map */
- add_data_member(obj, jit_info->arena.op_map, (jit_info->arena.map_size+1) *
- sizeof (opcode_t *));
- /* const_table */
- add_data_member(obj, NULL, interp->code->const_table->const_count *
- sizeof (PackFile_Constant));
-#ifdef JIT_CGP
- /* prederef_code */
- j = (int)cgp_core;
- j = (int)((op_func_t*)interp->op_lib->op_func_table)[2] - j;
- k = (int *)interp->code->prederef.code;
- for (i = 0; i < (int)interp->code->base.size; i++) {
- if (k[i] != j)
- k[i] = 0;
- }
- add_data_member(obj, interp->code->prederef.code,
- interp->code->base.size * sizeof (void *));
-#endif /* JIT_CGP */
- /* bytecode_offset */
- bhs = obj->bytecode_header_size / sizeof (opcode_t);
- add_data_member(obj, &bhs, 4);
-
- obj->text.code = jit_info->arena.start;
- obj->text.size = jit_info->arena.size;
-
- /* PAD */
- obj->text.size += (4 - obj->text.size % 4);
- obj->data.size += (4 - obj->data.size % 4);
- offset_fixup(obj);
- output = interp->output_file ?
- interp->output_file : "exec_output.o";
- Parrot_exec_save(interp, obj, output);
-}
-
-/*
-
-=item C<static void add_data_member(Parrot_exec_objfile_t *obj, const void *src,
-size_t len)>
-
-Adds a member to the data section, storing the size of it at
-C<< obj->data_size[N] >>.
-
-=cut
-
-*/
-
-static void
-add_data_member(ARGMOD(Parrot_exec_objfile_t *obj),
- ARGIN_NULLOK(const void *src), size_t len)
-{
- ASSERT_ARGS(add_data_member)
- char *cp;
-
- if (obj->data.size == 0) {
- obj->data.code = (char *)mem_sys_allocate(len);
- obj->data_size = (int *)mem_sys_allocate(sizeof (int));
- }
- else {
- int *nds;
- obj->data.code = (char *)mem_sys_realloc(obj->data.code,
- obj->data.size + len);
- nds = (int *)mem_sys_realloc(obj->data_size, (obj->data_count + 2) *
- sizeof (int));
- obj->data_size = nds;
- }
-
- cp = obj->data.code + obj->data.size;
- if (src)
- memcpy(cp, src, len);
- else
- memset(cp, 0, len);
- obj->data_size[obj->data_count++] = len;
- obj->data.size += len;
-}
-
-/*
-
-=item C<static void exec_init(Parrot_exec_objfile_t *obj)>
-
-Initialize the obj structure.
-
-=cut
-
-*/
-
-static void
-exec_init(ARGIN(Parrot_exec_objfile_t *obj))
-{
- ASSERT_ARGS(exec_init)
- obj->text_rellocation_table = (Parrot_exec_rellocation_t *)
- mem_sys_allocate_zeroed(sizeof (Parrot_exec_rellocation_t));
- obj->data_rellocation_table = (Parrot_exec_rellocation_t *)
- mem_sys_allocate_zeroed(sizeof (Parrot_exec_rellocation_t));
- obj->symbol_table = (Parrot_exec_symbol_t *)
- mem_sys_allocate_zeroed(sizeof (Parrot_exec_symbol_t));
- /* size of table */
-#ifdef PARROT_I386
- obj->symbol_list_size = 4;
-#else
- obj->symbol_list_size = 0;
-#endif
-#ifdef EXEC_ELF
- obj->symbol_list_size = 0;
-#endif
- Parrot_exec_add_symbol(obj, "program_code", STYPE_GDATA);
- Parrot_exec_add_symbol(obj, "opcode_map", STYPE_GDATA);
- Parrot_exec_add_symbol(obj, "const_table", STYPE_GDATA);
-#ifdef JIT_CGP
- Parrot_exec_add_symbol(obj, "exec_prederef_code", STYPE_GDATA);
-#endif /* JIT_CGP */
- Parrot_exec_add_symbol(obj, "bytecode_offset", STYPE_GDATA);
- Parrot_exec_add_symbol(obj, "run_compiled", STYPE_FUNC);
-}
-
-/*
-
-=item C<int Parrot_exec_add_symbol(Parrot_exec_objfile_t *obj, const char
-*symbol, int stype)>
-
-Adds a symbol to the object file.
-
-=cut
-
-*/
-
-int
-Parrot_exec_add_symbol(ARGMOD(Parrot_exec_objfile_t *obj),
- ARGIN(const char *symbol), int stype)
-{
- ASSERT_ARGS(Parrot_exec_add_symbol)
-
- int symbol_number = symbol_list_find(obj, symbol);
- if (symbol_number == -1) {
- Parrot_exec_symbol_t *new_symbol;
-
- symbol_number = obj->symbol_count;
- new_symbol = (Parrot_exec_symbol_t *)mem_sys_realloc(obj->symbol_table,
- (size_t)(obj->symbol_count + 1) * sizeof (Parrot_exec_symbol_t));
- obj->symbol_table = new_symbol;
-
- new_symbol = &obj->symbol_table[obj->symbol_count++];
- new_symbol->offset_list = obj->symbol_list_size;
- new_symbol->symbol = symbol;
- obj->symbol_list_size += strlen(symbol);
-#if defined(EXEC_A_OUT) || defined(EXEC_COFF)
- /* for the trailing "_" */
- obj->symbol_list_size++;
-#endif
- if (stype != STYPE_GCC)
- obj->symbol_list_size++;
- if (stype == STYPE_COM) {
- new_symbol->type = STYPE_COM;
- new_symbol->value = sizeof (Interp);
- }
- else {
- new_symbol->type = stype;
- new_symbol->value = 0;
- }
- }
- return symbol_number;
-}
-
-/*
-
-=item C<int * Parrot_exec_add_text_rellocation_reg(Parrot_exec_objfile_t *obj,
-char *nptr, const char *var, int offset, int disp)>
-
-Adds a register's text rellocation to the object file. Wrapper
-around C<Parrot_exec_add_text_rellocation>.
-
-Returns pointer to offset.
-
-=cut
-
-*/
-
-PARROT_EXPORT
-PARROT_CAN_RETURN_NULL
-int *
-Parrot_exec_add_text_rellocation_reg(ARGIN(Parrot_exec_objfile_t *obj),
- ARGIN(char *nptr), ARGIN(const char *var), int offset, int disp)
-{
- ASSERT_ARGS(Parrot_exec_add_text_rellocation_reg)
- Parrot_exec_add_text_rellocation(obj, nptr, RTYPE_COM, var, disp);
- return (int *)offset;
-}
-
-/*
-
-=item C<void Parrot_exec_add_text_rellocation_func(Parrot_exec_objfile_t *obj,
-char *nptr, const char *func_name)>
-
-Adds a function's text rellocation to the object file. Wrapper
-around C<Parrot_exec_add_text_rellocation>.
-
-=cut
-
-*/
-
-PARROT_EXPORT
-void
-Parrot_exec_add_text_rellocation_func(ARGIN(Parrot_exec_objfile_t *obj),
- ARGIN(char *nptr), ARGIN(const char *func_name))
-{
- ASSERT_ARGS(Parrot_exec_add_text_rellocation_func)
- Parrot_exec_add_text_rellocation(obj, nptr, RTYPE_FUNC, func_name, 1);
-}
-
-/*
-
-=item C<void Parrot_exec_add_text_rellocation(Parrot_exec_objfile_t *obj, char
-*nptr, int type, const char *symbol, int disp)>
-
-Adds a text rellocation to the object file.
-
-=cut
-
-*/
-
-PARROT_EXPORT
-void
-Parrot_exec_add_text_rellocation(ARGIN(Parrot_exec_objfile_t *obj), ARGIN(char *nptr),
- int type, ARGIN(const char *symbol), int disp)
-{
- ASSERT_ARGS(Parrot_exec_add_text_rellocation)
- int symbol_number;
- char *addr;
- Parrot_exec_rellocation_t * new_relloc = (Parrot_exec_rellocation_t *)
- mem_sys_realloc(obj->text_rellocation_table,
- (size_t)(obj->text_rellocation_count + 1) *
- sizeof (Parrot_exec_rellocation_t));
-
- obj->text_rellocation_table = new_relloc;
- new_relloc = &obj->text_rellocation_table[obj->text_rellocation_count++];
-
- switch (type) {
- case RTYPE_FUNC:
- symbol_number = Parrot_exec_add_symbol(obj, symbol, STYPE_UND);
- break;
- case RTYPE_COM:
- symbol_number = Parrot_exec_add_symbol(obj, symbol, STYPE_COM);
- break;
- case RTYPE_DATA:
- case RTYPE_DATA1:
- symbol_number = Parrot_exec_add_symbol(obj, symbol, STYPE_GDATA);
- break;
- default:
- symbol_number = 0;
- break;
- }
-
- addr = nptr + disp;
- new_relloc->offset = (int)(addr - obj->text.code);
- new_relloc->symbol_number = symbol_number;
- new_relloc->type = type;
-}
-
-/*
-
-=item C<static int symbol_list_find(const Parrot_exec_objfile_t *obj, const char
-*symbol)>
-
-Returns the index of C<symbol> in the symbol list. Returns -1 if it is
-not in the list.
-
-Used by C<Parrot_exec_add_symbol()>.
-
-=cut
-
-*/
-
-static int
-symbol_list_find(ARGIN(const Parrot_exec_objfile_t *obj), ARGIN(const char *symbol))
-{
- ASSERT_ARGS(symbol_list_find)
- int i;
-
- for (i = 0; i < obj->symbol_count; i++)
- if (STREQ(symbol, obj->symbol_table[i].symbol))
- return i;
- return -1;
-}
-
-/*
-
-=back
-
-=head1 SEE ALSO
-
-F<include/parrot/exec.h>, F<src/exec_cpu.c>, F<src/exec_save.h>
-and F<src/exec_start.c>.
-
-=head1 HISTORY
-
-Initial version by Daniel Grunblatt on 2003.6.9.
-
-=cut
-
-*/
-
-
-/*
- * Local variables:
- * c-file-style: "parrot"
- * End:
- * vim: expandtab shiftwidth=4:
- */
View
844 src/exec_save.c
@@ -1,844 +0,0 @@
-/*
-Copyright (C) 2001-2008, Parrot Foundation.
-$Id$
-
-=head1 NAME
-
-src/exec_save.c - Save object file in native format
-
-=head1 DESCRIPTION
-
-Save the C<Parrot_exec_objfile_t> to the native format.
-
-=head2 Functions
-
-=over 4
-
-=cut
-
-*/
-
-/* HEADERIZER HFILE: none */
-/* HEADERIZER STOP */
-
-#include <parrot/parrot.h>
-#include "parrot/exec.h"
-#include "exec_save.h"
-
-static void save_zero(FILE *fp);
-static void save_int(FILE *fp, int i);
-static void save_short(FILE *fp, short s);
-static void save_struct(FILE *fp, void *sp, size_t size);
-
-#ifdef EXEC_A_OUT
-
-# include <a.out.h>
-# include <link.h>
-
-/*
-
-=item C<void
-Parrot_exec_save(PARROT_INTERP, Parrot_exec_objfile_t *obj, const char *file)>
-
-Save the C<Parrot_exec_objfile_t> to C<file>.
-
-=cut
-
-*/
-
-void
-Parrot_exec_save(PARROT_INTERP, Parrot_exec_objfile_t *obj, const char *file)
-{
- FILE * const fp = fopen(file, "w");
- int i;
- struct exec header;
- struct relocation_info rellocation;
- struct nlist symlst;
-
-
- header.a_midmag = 0x07018600;
- header.a_text = obj->text.size;
- header.a_data = obj->data.size;
- header.a_bss = obj->bss.size;
- header.a_syms = obj->symbol_count * sizeof (struct nlist);
- header.a_entry = 0;
- header.a_trsize = obj->text_rellocation_count
- * sizeof (struct relocation_info);
- header.a_drsize = obj->data_rellocation_count
- * sizeof (struct relocation_info);
- save_struct(fp, &header, sizeof (struct exec));
- /* Text */
- for (i = 0; i < obj->text.size; i++)
- fprintf(fp, "%c", obj->text.code[i]);
- /* Data */
- for (i = 0; i < obj->data.size; i++)
- fprintf(fp, "%c", obj->data.code[i]);
- /* Text rellocations */
- for (i = obj->text_rellocation_count - 1; i >= 0; i--) {
- memset(&rellocation, 0, sizeof (struct relocation_info));
- rellocation.r_address = obj->text_rellocation_table[i].offset;
- rellocation.r_symbolnum = obj->text_rellocation_table[i].symbol_number;
- switch (obj->text_rellocation_table[i].type) {
- case RTYPE_FUNC:
- rellocation.r_pcrel = 1;
- rellocation.r_length = 2;
- rellocation.r_extern = 1;
- break;
- case RTYPE_COM:
- case RTYPE_DATA:
- rellocation.r_length = 2;
- rellocation.r_extern = 1;
- break;
- default:
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXEC_ERROR,
- "Unknown text rellocation type: %d\n",
- obj->text_rellocation_table[i].type);
- break;
- }
- save_struct(fp, &rellocation, sizeof (struct relocation_info));
- }
- /* Symbol table */
- for (i = 0; i < obj->symbol_count; i++) {
- memset(&symlst, 0, sizeof (struct nlist));
- symlst.n_un.n_strx = obj->symbol_table[i].offset_list;
- switch (obj->symbol_table[i].type) {
- case STYPE_FUNC:
- symlst.n_type = N_EXT | N_TEXT;
- symlst.n_other = AUX_FUNC;
- break;
- case STYPE_GDATA:
- symlst.n_type = N_EXT | N_DATA;
- symlst.n_other = AUX_OBJECT;
- symlst.n_value = obj->symbol_table[i].value;
- break;
- case STYPE_COM:
- symlst.n_type = N_EXT;
- symlst.n_value = obj->symbol_table[i].value;
- break;
- case STYPE_UND:
- symlst.n_type = N_EXT;
- break;
- default:
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXEC_ERROR,
- "Unknown symbol type: %d\n", obj->symbol_table[i].type);
- break;
- }
- save_struct(fp, &symlst, sizeof (struct nlist));
- }
- /* String table size */
- save_int(fp, obj->symbol_list_size);
- /* String table */
- for (i = 0; i < obj->symbol_count; i++) {
- if (obj->symbol_table[i].type != STYPE_GCC)
- fprintf(fp, "_%s", obj->symbol_table[i].symbol);
- else
- fprintf(fp, "%s", obj->symbol_table[i].symbol);
- save_zero(fp);
- }
- fclose(fp);
-}
-
-#endif /* EXEC_A_OUT */
-
-#ifdef EXEC_ELF
-
-# ifdef PARROT_EXEC_OS_OPENBSD
-# define R_386_32 1
-# define R_386_PC32 2
-# include <elf_abi.h>
-# else
-# include <elf.h>
-# endif
-
-# if defined(PARROT_PPC)
-# if !defined(R_PPC_ADDR16_HI) && !defined(R_PPC_ADDR16_LO) && \
- defined(R_PPC_16_HI) && defined(R_PPC_16_LO)
-# define R_PPC_ADDR16_HI R_PPC_16_HI
-# define R_PPC_ADDR16_LO R_PPC_16_LO
-# endif
- /*
- * NetBSD/powerpc 3.x and OpenBSD/powerpc doesn't define these constants,
- * but instead has them as enums, so add some workarounds for those.
- */
-# if !defined(R_PPC_ADDR16_HI) && !defined(R_PPC_ADDR16_LO) && \
- (defined(__NetBSD__) || defined(__OpenBSD__))
-# define R_PPC_ADDR16_HI RELOC_16_HI
-# define R_PPC_ADDR16_LO RELOC_16_LO
-# endif
-# if !defined(R_PPC_REL24) && (defined(__NetBSD__) || defined(__OpenBSD__))
-# define R_PPC_REL24 RELOC_REL24
-# endif
-# endif /* PARROT_PPC */
-
-/* Add a section to the file
- *
- * n = Name
- * t = Type
- * f = Flags
- * s = Size
- * l = Link
- * i = Info
- * a = Align
- * e = Entry size
- */
-# define sh_add(n, t, f, s, l, i, a, e) { \
- memset(&sechdr, 0, sizeof (Elf32_Shdr)); \
- sechdr.sh_name = shste - shst; \
- shste += sprintf(shste, "%s", (n)); \
- shste++; \
- sechdr.sh_type = (t); \
- sechdr.sh_flags = (f); \
- sechdr.sh_addr = 0; \
- sechdr.sh_offset = current_offset; \
- sechdr.sh_size = (s); \
- sechdr.sh_link = (l); \
- sechdr.sh_info = (i); \
- sechdr.sh_addralign = (a); \
- sechdr.sh_entsize = (e); \
- save_struct(fp, &sechdr, sizeof (Elf32_Shdr)); \
- current_offset += (s); \
- if ((s) % 4) \
- current_offset += (4 - (s) % 4); \
- }
-
-/* Sizeof the section header string table */
-# define SHSTRTABSIZE 0x48
-/* Previously defined symbols (zero, text, data, bss) */
-# define PDFS 4
-/* Number of sections */
-# define NSECTIONS 8
-
-void
-Parrot_exec_save(PARROT_INTERP, Parrot_exec_objfile_t *obj, const char *file)
-{
- FILE *fp = fopen(file, "w");
- char *shste;
- char shst[SHSTRTABSIZE];
-
- Elf32_Ehdr header;
- Elf32_Shdr sechdr;
- Elf32_Rel rellocation;
- Elf32_Rela rel_addend;
- Elf32_Sym symlst;
- Elf32_Off current_offset;
- int i;
-
- memset(&header, 0, sizeof (Elf32_Ehdr));
- header.e_ident[0] = ELFMAG0;
- header.e_ident[1] = ELFMAG1;
- header.e_ident[2] = ELFMAG2;
- header.e_ident[3] = ELFMAG3;
- header.e_ident[4] = ELFCLASS32;
-# if PARROT_BIGENDIAN
- header.e_ident[5] = ELFDATA2MSB;
-# else /* PARROT_BIGENDIAN */
- header.e_ident[5] = ELFDATA2LSB;
-# endif /* PARROT_BIGENDIAN */
- header.e_ident[6] = EV_CURRENT;
-# ifdef PARROT_EXEC_OS_FREEBSD
- header.e_ident[7] = ELFOSABI_FREEBSD;
-# endif
-# ifdef PARROT_EXEC_OS_NETBSD
- header.e_ident[7] = ELFOSABI_NETBSD;
-# endif
-# if defined(PARROT_EXEC_OS_LINUX) && defined(ELFOSABI_LINUX) && \
- !defined(PARROT_PPC) && !defined(PARROT_ARM)
- header.e_ident[7] = ELFOSABI_LINUX;
-# endif
-
- header.e_type = ET_REL;
-# ifdef PARROT_I386
- header.e_machine = EM_386;
-# endif
-# ifdef PARROT_PPC
- header.e_machine = EM_PPC;
-# endif
-# ifdef PARROT_ARM
- header.e_ident[7] = ELFOSABI_ARM;
- header.e_machine = EM_ARM;
-# endif
- header.e_version = EV_CURRENT;
- header.e_entry = 0;
- header.e_phoff = 0;
- header.e_shoff = sizeof (Elf32_Ehdr);
- header.e_flags = 0;
- header.e_ehsize = sizeof (Elf32_Ehdr);
- header.e_phentsize = 0;
- header.e_phnum = 0;
- header.e_shentsize = sizeof (Elf32_Shdr);
- header.e_shnum = NSECTIONS;
- header.e_shstrndx = 1;
-
- save_struct(fp, &header, sizeof (Elf32_Ehdr));
-
- current_offset = sizeof (Elf32_Ehdr) + NSECTIONS * sizeof (Elf32_Shdr);
-
- /* Sections */
- memset(&shst, 0, SHSTRTABSIZE);
- shste = shst + 1;
-
- /* NULL */
- memset(&sechdr, 0, sizeof (Elf32_Shdr));
- save_struct(fp, &sechdr, sizeof (Elf32_Shdr));
-
- /* Section Header String Table */
- sh_add(".shstrtab", SHT_STRTAB, 0, SHSTRTABSIZE, 0, 0, 1, 0);
-
- /* Text */
- sh_add(".text", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR, obj->text.size,
- 0, 0, 4, 0);
-
- /* Data */
- sh_add(".data", SHT_PROGBITS, SHF_WRITE | SHF_ALLOC, obj->data.size,
- 0, 0, 4, 0);
-
- /* Bss */
- sh_add(".bss", SHT_NOBITS, SHF_WRITE | SHF_ALLOC, obj->bss.size,
- 0, 0, 4, 0);
- /*
- * Text rellocation records.
- * Link must be the symtab section header index.
- * Info is the text section header index.
- */
-# if defined(PARROT_I386) || defined(PARROT_ARM)
- sh_add(".rel.text", SHT_REL, 0, obj->text_rellocation_count *
- sizeof (Elf32_Rel), 6, 2, 4, sizeof (Elf32_Rel));
-# endif
- /*
- * PPC requires rellocation structures with addends.
- */
-# ifdef PARROT_PPC
- sh_add(".rela.text", SHT_RELA, 0, obj->text_rellocation_count *
- sizeof (Elf32_Rela), 6, 2, 4, sizeof (Elf32_Rela));
-# endif
- /*
- * Symbol table.
- * Link is the strtab section header index.
- * Info is the index of the first symbol in the symbol table.
- */
- sh_add(".symtab", SHT_SYMTAB, 0, (obj->symbol_count + PDFS) *
- sizeof (Elf32_Sym), 7, PDFS - 1, 4, sizeof (Elf32_Sym));
- /* String Table */
- obj->symbol_list_size += 1; /* Trailing \0 */
- sh_add(".strtab", SHT_STRTAB, 0, obj->symbol_list_size, 0, 0, 1, 0);
-
- /* Section header string table */
- save_struct(fp, &shst, SHSTRTABSIZE);
- save_struct(fp, obj->text.code, obj->text.size); /* Text */
- save_struct(fp, obj->data.code, obj->data.size); /* Data */
- /* Text rellocations */
- for (i = 0; i < obj->text_rellocation_count; i++) {
-# ifdef PARROT_I386
- memset(&rellocation, 0, sizeof (Elf32_Rel));
-
- rellocation.r_offset = obj->text_rellocation_table[i].offset;
- switch (obj->text_rellocation_table[i].type) {
- case RTYPE_FUNC:
- rellocation.r_info =
- ELF32_R_INFO(
- obj->text_rellocation_table[i].symbol_number + PDFS,
- R_386_PC32);
- break;
- case RTYPE_DATA:
- case RTYPE_COM:
- rellocation.r_info =
- ELF32_R_INFO(
- obj->text_rellocation_table[i].symbol_number + PDFS,
- R_386_32);
- break;
- default:
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXEC_ERROR,
- "Unknown text rellocation type: %d\n",
- obj->text_rellocation_table[i].type);
- break;
- }
- save_struct(fp, &rellocation, sizeof (Elf32_Rel));
-# endif
-# ifdef PARROT_PPC
- memset(&rel_addend, 0, sizeof (Elf32_Rela));
- rel_addend.r_offset = obj->text_rellocation_table[i].offset;
- switch (obj->text_rellocation_table[i].type) {
- case RTYPE_FUNC:
- rel_addend.r_info =
- ELF32_R_INFO(
- obj->text_rellocation_table[i].symbol_number + PDFS,
- R_PPC_REL24);
- break;
- case RTYPE_DATA:
- case RTYPE_COM:
- rel_addend.r_info =
- ELF32_R_INFO(
- obj->text_rellocation_table[i].symbol_number + PDFS,
- R_PPC_ADDR16_HI);
- rel_addend.r_addend = *((short *)
- (&obj->text.code[obj->text_rellocation_table[i].offset]))
- << 16;
- rel_addend.r_addend += *((short *)
- (&obj->text.code[
- obj->text_rellocation_table[i].offset + 4]));
- break;
- case RTYPE_DATA1:
- rel_addend.r_info =
- ELF32_R_INFO(
- obj->text_rellocation_table[i].symbol_number + PDFS,
- R_PPC_ADDR16_LO);
- rel_addend.r_addend = *((short *)
- (&obj->text.code[obj->text_rellocation_table[i].offset]));
- rel_addend.r_addend += *((short *)
- (&obj->text.code[
- obj->text_rellocation_table[i].offset - 4])) << 16;
- break;
- default:
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXEC_ERROR,
- "Unknown text rellocation type: %d\n",
- obj->text_rellocation_table[i].type);
- break;
- }
- save_struct(fp, &rel_addend, sizeof (Elf32_Rela));
-# endif
-# ifdef PARROT_ARM
- memset(&rellocation, 0, sizeof (Elf32_Rel));
- rellocation.r_offset = obj->text_rellocation_table[i].offset;
- switch (obj->text_rellocation_table[i].type) {
- case RTYPE_FUNC:
- rellocation.r_info =
- ELF32_R_INFO(
- obj->text_rellocation_table[i].symbol_number + PDFS,
- R_ARM_ABS32);
- break;
- case RTYPE_DATA:
- rellocation.r_info =
- ELF32_R_INFO(
- obj->text_rellocation_table[i].symbol_number + PDFS,
- R_ARM_ABS32);
- break;
- default:
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXEC_ERROR,
- "Unknown text rellocation type: %d\n",
- obj->text_rellocation_table[i].type);
- break;
- }
- save_struct(fp, &rellocation, sizeof (Elf32_Rel));
-# endif
- }
- /* Symbol table */
- /* zero */
- memset(&symlst, 0, sizeof (Elf32_Sym));
- save_struct(fp, &symlst, sizeof (Elf32_Sym));
-
- /* Text */
- memset(&symlst, 0, sizeof (Elf32_Sym));
- symlst.st_info = ELF32_ST_INFO(STB_LOCAL, STT_SECTION);
- symlst.st_shndx = 2;
- save_struct(fp, &symlst, sizeof (Elf32_Sym));
-
- /* Data */
- memset(&symlst, 0, sizeof (Elf32_Sym));
- symlst.st_info = ELF32_ST_INFO(STB_LOCAL, STT_SECTION);
- symlst.st_shndx = 3;
- save_struct(fp, &symlst, sizeof (Elf32_Sym));
-
- /* Bss */
- memset(&symlst, 0, sizeof (Elf32_Sym));
- symlst.st_info = ELF32_ST_INFO(STB_LOCAL, STT_SECTION);
- symlst.st_shndx = 4;
- save_struct(fp, &symlst, sizeof (Elf32_Sym));
-
- for (i = 0; i < obj->symbol_count; i++) {
- memset(&symlst, 0, sizeof (Elf32_Sym));
- symlst.st_name = obj->symbol_table[i].offset_list + 1;
- switch (obj->symbol_table[i].type) {
- case STYPE_FUNC:
- symlst.st_info = ELF32_ST_INFO(STB_GLOBAL, STT_FUNC);
- symlst.st_size = obj->text.size;
- symlst.st_shndx = 2; /* text */
- break;
- case STYPE_GDATA:
- symlst.st_value = obj->symbol_table[i].value;
- symlst.st_size = obj->data_size[i];
- symlst.st_info = ELF32_ST_INFO(STB_GLOBAL, STT_OBJECT);
- symlst.st_shndx = 3; /* data */
- break;
- case STYPE_COM:
- symlst.st_value = obj->symbol_table[i].value;
- /* symlst.st_size = obj->data_size[i]; XXX daniel why? */
- symlst.st_info = ELF32_ST_INFO(STB_GLOBAL, STT_OBJECT);
- symlst.st_shndx = SHN_COMMON;
- break;
- case STYPE_UND:
- symlst.st_info = ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE);
- break;
- default:
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXEC_ERROR,
- "Unknown symbol type: %d\n", obj->symbol_table[i].type);
- break;
- }
- save_struct(fp, &symlst, sizeof (Elf32_Sym));
- }
- /* String table */
- save_zero(fp);
- for (i = 0; i < obj->symbol_count; i++) {
- fprintf(fp, "%s", obj->symbol_table[i].symbol);
- save_zero(fp);
- }
- /* PAD */
- for (i = 0; i < (4 - obj->symbol_list_size % 4); i++)
- save_zero(fp);
- fclose(fp);
-}
-
-#endif /* EXEC_ELF */
-
-#ifdef EXEC_MACH_O
-
-void
-Parrot_exec_save(PARROT_INTERP, Parrot_exec_objfile_t *obj, const char *file)
-{
- FILE *fp = fopen(file, "w");
- size_t i;
-
- fprintf(fp, "\xFE\xED\xFA\xCE"); /* Header for Darwin */
- save_int(fp, 0x12);
- save_int(fp, 0);
- save_int(fp, 0x1);
- save_int(fp, 0x3);
- save_int(fp, 0x128);
- save_int(fp, 0);
- save_int(fp, 0x1);
- save_int(fp, 0xC0);
- for (i = 0; i < 5; i++)
- save_int(fp, 0);
- /* Sizeof text + data */
- save_int(fp, obj->text.size + obj->data.size);
- /* Offset of text */
- save_int(fp, 0x144);
- save_int(fp, obj->text.size + obj->data.size);
- save_int(fp, 0x7);
- save_int(fp, 0x7);
- save_int(fp, 0x2);
- save_int(fp, 0);
- fprintf(fp, "__text");
- for (i = 0; i < 10; i++)
- save_zero(fp);
- fprintf(fp, "__TEXT");
- for (i = 0; i < 10; i++)
- save_zero(fp);
- save_int(fp, 0);
- /* Sizeof text */
- save_int(fp, obj->text.size);
- save_int(fp, 0x144);
- save_int(fp, 0x2);
- /* Offset of rellocation table. */
- save_int(fp, 0x144 + obj->text.size + obj->data.size);
- save_int(fp, obj->text_rellocation_count);
- save_int(fp, 0x80000400);
- save_int(fp, 0);
- save_int(fp, 0);
- fprintf(fp, "__data");
- for (i = 0; i < 10; i++)
- save_zero(fp);
- fprintf(fp, "__DATA");
- for (i = 0; i < 10; i++)
- save_zero(fp);
- /* Data VMA */
- save_int(fp, obj->text.size);
- /* Data size */
- save_int(fp, obj->data.size);
- /* Data file offset */
- save_int(fp, 0x144 + obj->text.size);
- save_int(fp, 0x2);
- for (i = 0; i < 5; i++)
- save_int(fp, 0);
- save_int(fp, 0x2);
- /* save_int(fp, obj->symbol_count * 0xc); */
- save_int(fp, 0x18);
- /* Offset of stabs */
- save_int(fp, 0x144 +
- obj->text.size + obj->data.size + obj->text_rellocation_count * 0x8);
- /* Number of stabs (symbol table) */
- save_int(fp, obj->symbol_count);
- /* Offset of symbol list */
- save_int(fp, 0x144 + obj->text.size + obj->data.size +
- obj->text_rellocation_count * 0x8 + obj->symbol_count * 0xc);
- /* Sizeof symbol list */
- save_int(fp, obj->symbol_list_size);
- save_int(fp, 0xB);
- save_int(fp, 0x50);
- for (i = 0; i < 3; i++)
- save_int(fp, 0);
- save_int(fp, obj->symbol_count);
- save_int(fp, obj->symbol_count);
- for (i = 0; i < 13; i++)
- save_int(fp, 0);
-
- /* Text */
- for (i = 0; i < obj->text.size; i++)
- fprintf(fp, "%c", obj->text.code[i]);
- /* Data */
- for (i = 0; i < obj->data.size; i++)
- fprintf(fp, "%c", obj->data.code[i]);
- /* Text rellocations */
- /* XXX This is an infinite loop. When i = 0, i-- goes to very large. */
- for (i = obj->text_rellocation_count - 1; i >= 0; i--) {
- save_int(fp, obj->text_rellocation_table[i].offset);
- save_short(fp, obj->text_rellocation_table[i].symbol_number);
- save_short(fp, obj->text_rellocation_table[i].type);
- }
- /* Symbol table */
- for (i = 0; i < obj->symbol_count; i++) {
- save_int(fp, obj->symbol_table[i].offset_list);
- save_int(fp, obj->symbol_table[i].type);
- save_int(fp, obj->symbol_table[i].value);
- }
- /* Symbol list */
- for (i = 0; i < obj->symbol_count; i++) {
- if (obj->symbol_table[i].type != STYPE_GCC)
- fprintf(fp, "_%s", obj->symbol_table[i].symbol);
- else
- fprintf(fp, "%s", obj->symbol_table[i].symbol);
- save_zero(fp);
- }
- fclose(fp);
-}
-
-#endif /* EXEC_MACH_O */
-
-#ifdef EXEC_COFF
-
-/* File offsets */
-# define TEXT_CODE 0x14 + (3 * 0x28)
-# define DATA_CODE TEXT_CODE + obj->text.size
-# define TEXT_RELOC DATA_CODE + obj->data.size
-# define DATA_RELOC TEXT_RELOC + (obj->text_rellocation_count * 0xA)
-# define SYMTAB DATA_RELOC + (obj->data_rellocation_count * 0xA)
-
-void
-Parrot_exec_save(PARROT_INTERP, Parrot_exec_objfile_t *obj, const char *file)
-{
- FILE *fp;
- int i;
- size_t j;
-
- fp = fopen(file, "wb");
-
- save_short(fp, 0x14C); /* i386 */
- save_short(fp, 3); /* Number of sections */
- save_int(fp, Parrot_intval_time());
- save_int(fp, SYMTAB);
- save_int(fp, obj->symbol_count);
- save_short(fp, 0);
- save_short(fp, 0x104); /* 32 bit LE, no line numbers */
-
- fwrite(".text\0\0\0", 8, 1, fp);
- save_int(fp, 0);
- save_int(fp, 0);
- save_int(fp, obj->text.size);
- save_int(fp, TEXT_CODE);
- save_int(fp, TEXT_RELOC);
- save_int(fp, 0);
- save_short(fp, (short)obj->text_rellocation_count);
- save_short(fp, 0);
- save_int(fp, 0x20);
-
- fwrite(".data\0\0\0", 8, 1, fp);
- save_int(fp, 0);
- save_int(fp, 0);
- save_int(fp, obj->data.size);
- save_int(fp, DATA_CODE);
- save_int(fp, DATA_RELOC);
- save_int(fp, 0);
- save_short(fp, (short)obj->data_rellocation_count);
- save_short(fp, 0);
- save_int(fp, 0x40);
-
- fwrite(".bss\0\0\0\0", 8, 1, fp);
- save_int(fp, 0);
- save_int(fp, 0);
- save_int(fp, obj->bss.size);
- save_int(fp, 0);
- save_int(fp, 0);
- save_int(fp, 0);
- save_short(fp, 0);
- save_short(fp, 0);
- save_int(fp, 0x80);
-
- /* Text */
- for (j = 0; j < obj->text.size; j++)
- fprintf(fp, "%c", obj->text.code[j]);
- /* Data */
- for (j = 0; j < obj->data.size; j++)
- fprintf(fp, "%c", obj->data.code[j]);
- /* Text rellocations */
- for (i = 0; i < obj->text_rellocation_count; i++) {
- save_int(fp, obj->text_rellocation_table[i].offset);
- save_int(fp, obj->text_rellocation_table[i].symbol_number);
- switch (obj->text_rellocation_table[i].type) {
- case RTYPE_FUNC:
- save_short(fp, 0x14);
- break;
- case RTYPE_COM:
- case RTYPE_DATA:
- save_short(fp, 0x06);
- break;
- default:
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXEC_ERROR,
- "Unknown text rellocation type: %d\n",
- obj->text_rellocation_table[i].type);
- break;
- }
- }
- /* Symbol table */
- for (i = 0; i < obj->symbol_count; i++) {
- save_int(fp, 0);
- save_int(fp, obj->symbol_table[i].offset_list);
- save_int(fp, obj->symbol_table[i].value);
- switch (obj->symbol_table[i].type) {
- case STYPE_FUNC:
- save_short(fp, 1); /* .text */
- save_short(fp, 0x20);
- break;
- case STYPE_GDATA:
- save_short(fp, 2); /* .data */
- save_short(fp, 0);
- break;
- case STYPE_COM:
- save_short(fp, 0);
- save_short(fp, 0);
- break;
- case STYPE_UND:
- save_short(fp, 0);
- save_short(fp, 0x20);
- break;
- default:
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXEC_ERROR,
- "Unknown symbol type: %d\n", obj->symbol_table[i].type);
- break;
- }
- putc(2, fp); /* "extern" class */
- putc(0, fp);
- }
- /* Symbol list */
- save_int(fp, obj->symbol_list_size);
- for (i = 0; i < obj->symbol_count; i++) {
- if (obj->symbol_table[i].type != STYPE_GCC)
- fprintf(fp, "_%s", obj->symbol_table[i].symbol);
- else
- fprintf(fp, "%s", obj->symbol_table[i].symbol);
- save_zero(fp);
- }
- fclose(fp);
-}
-
-#endif /* EXEC_COFF */
-
-/*
-
-=item C<static void save_struct(FILE *fp, void *sp, size_t size)>
-
-Writes the C<struct> C<sp> to the file.
-
-=cut
-
-*/
-
-static void
-save_struct(FILE *fp, void *sp, size_t size)
-{
- unsigned int i;
-
- for (i = 0; i < size; i++)
- fprintf(fp, "%c", ((char *)sp)[i]);
-}
-
-/*
-
-=item C<static void save_zero(FILE *fp)>
-
-Writes 0 to the file.
-
-=cut
-
-*/
-
-static void
-save_zero(FILE *fp)
-{
- fprintf(fp, "%c", 0);
-}
-
-#if PARROT_BIGENDIAN
-
-/*
-
-=item C<static void save_int(FILE *fp, int i)>
-
-Writes C<i> to the file.
-
-=cut
-
-*/
-
-static void
-save_int(FILE *fp, int i)
-{
- fprintf(fp, "%c%c%c%c", (char)(i >> 24), (char)(i >> 16),
- (char)(i >> 8), (char)i);
-}
-
-/*
-
-=item C<static void save_short(FILE *fp, short s)>
-
-Writes C<s> to the file.
-
-=cut
-
-*/
-
-static void
-save_short(FILE *fp, short s)
-{
- fprintf(fp, "%c%c", (char)(s >> 8), (char)s);
-}
-
-#else /* PARROT_BIGENDIAN */
-
-static void
-save_short(FILE *fp, short s)
-{
- fprintf(fp, "%c%c", (char)s, (char)(s >> 8));
-}
-
-static void
-save_int(FILE *fp, int i)
-{
- fprintf(fp, "%c%c%c%c", (char)i, (char)(i >> 8),
- (char)(i >> 16), (char)(i >> 24));
-}
-
-#endif /* PARROT_BIGENDIAN */
-
-/*
-
-=back
-
-=head1 SEE ALSO
-
-F<include/parrot/exec.h>, F<src/exec_save.h>, F<src/exec.c>
-and F<src/exec_start.c>.
-
-=head1 HISTORY
-
-Initial version by Daniel Grunblatt on 2003.6.9.
-
-=cut
-
-*/
-
-
-/*
- * Local variables:
- * c-file-style: "parrot"
- * End:
- * vim: expandtab shiftwidth=4:
- */
View
31 src/exec_save.h
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2003-2007, Parrot Foundation.
- */
-
-/*
- * exec.h
- *
- * SVN Info
- * $Id$
- * Overview:
- * Exec header file.
- * History:
- * Initial version by Daniel Grunblatt on 2003.6.9
- * Notes:
- * References:
- */
-
-#ifndef PARROT_EXEC_SAVE_H_GUARD
-#define PARROT_EXEC_SAVE_H_GUARD
-
-void Parrot_exec_save(PARROT_INTERP, Parrot_exec_objfile_t *obj, const char *file);
-
-#endif /* PARROT_EXEC_SAVE_H_GUARD */
-
-
-/*
- * Local variables:
- * c-file-style: "parrot"
- * End:
- * vim: expandtab shiftwidth=4:
- */
View
135 src/exec_start.c
@@ -1,135 +0,0 @@
-/*
-Copyright (C) 2001-2009, Parrot Foundation.
-$Id$
-
-=head1 NAME
-
-src/exec_start.c - Call compiled code
-
-=head1 SYNOPSIS
-
-I<What goes here?>
-
-=head1 DESCRIPTION
-
-Exec is a tool for using the JIT at compile time to generate native
-executables.
-
-=head2 Functions
-
-=over 4
-
-=cut
-
-*/
-
-#include "parrot/parrot.h"
-#include "parrot/string.h"
-#include "parrot/exec.h"
-#include "jit.h"
-#define JIT_EMIT 1
-#include "jit_emit.h"
-#include "parrot/embed.h"
-
-opcode_t* run_compiled(PARROT_INTERP,
- opcode_t *cur_opcode, opcode_t *code_start);
-
-/*
-
-=item C<int main(int argc, char * argv[])>
-
-The run-loop.
-
-=cut
-
-*/
-
-int
-main(int argc, char * argv[])
-{
- /* long * opp; */
- Interp * interp;
- PackFile * pf;
- opcode_t * code_start;
- extern char * program_code;
- /* extern long opcode_map; */
- /* extern int bytecode_offset; */
-#if defined(JIT_CGP)
- extern void * exec_prederef_code;
-#endif
- /* extern int Parrot_exec_run; */
- /* extern PackFile_Constant *exec_const_table; */
- /* extern PackFile_Constant const_table; */
- extern Interp interpre;
-
- /* s. exec.c */
- /* Parrot_exec_run = 1; */
- /* s. packfile.c (PackFile_ConstTable_unpack()) */
- /* exec_const_table = &const_table; */
- interp = Parrot_new(NULL);
- if (!interp) {
- return 1;
- }
-
- /* run_native = run_compiled; */
- /* TODO make also a shared variant of PackFile_new */
- pf = PackFile_new(interp, 0);
-
- if (!PackFile_unpack(interp, pf, (opcode_t *)(&program_code),
- sizeof (&program_code)))
- {
- printf("Can't unpack.\n");
- return 1;
- }
- Parrot_pbc_load(interp, pf);
- PackFile_fixup_subs(interp, PBC_PBC, NULL);
-
- /* opcode_map has the offset of each opcode in the compiled code
- * this modifies it to be address of the opcode.
- */
- /*
- opp = &opcode_map;
- for (i = 0; i < (int)interpre.code->base.size; i++) {
- opp[i] += (long)run_compiled;
- }
- */
-
-#if defined(JIT_CGP)
- exec_init_prederef(interp, &exec_prederef_code);
-#endif
- /* Parrot_runcore_switch(interp, Parrot_str_new_constant(interp, "exec"));
- interp->code->base.data =
- (opcode_t *)&((&program_code)[bytecode_offset]);
- Parrot_exec_run = 0; */
- Parrot_runcode(interp, argc, argv);
- /*
- run_compiled(interp,
- (opcode_t *)&((&program_code)[bytecode_offset]));
- */
- Parrot_exit(interp, 0);
-}
-
-/*
-
-=back
-
-=head1 SEE ALSO
-
-F<include/parrot/exec.h>, F<src/exec_save.h>, F<src/exec.c>
-and F<compilers/imcc/main.c>.
-
-=head1 HISTORY
-
-Initial version by Daniel Grunblatt on 2003.6.9
-
-=cut
-
-*/
-
-
-/*
- * Local variables:
- * c-file-style: "parrot"
- * End:
- * vim: expandtab shiftwidth=4:
- */
View
5 src/runcore/cores.c
@@ -255,11 +255,6 @@ next opcode, or examine and manipulate data from the executing program.
# include "parrot/oplib/core_ops_cgp.h"
#endif
-#if JIT_CAPABLE
-# include "parrot/exec.h"
-# include "../jit.h"
-#endif
-
#ifdef WIN32
# define getpid _getpid
#endif
View
4 src/runcore/main.c
@@ -40,10 +40,6 @@ have the same number of elements because there is a one-to-one mapping.
#include "parrot/oplib/ops.h"
#include "main.str"
-#if JIT_CAPABLE
-# include "parrot/exec.h"
-# include "../jit.h"
-#endif
#ifdef HAVE_COMPUTED_GOTO
# include "parrot/oplib/core_ops_cg.h"
# include "parrot/oplib/core_ops_cgp.h"
Please sign in to comment.
Something went wrong with that request. Please try again.