We are planning to upgrade GitLab to the latest version this Friday morning. Expect some downtime!

Commit 9aaf8026 authored by Camil Staps's avatar Camil Staps 🍃

Rename bcunreloc to bcprelink

parent 05a6350b
......@@ -8,12 +8,12 @@ tasks between a server and a browser client.
## Tools
Because there is no WebAssembly parser one needs to use `bcunreloc` to produce
Because there is no WebAssembly parser one needs to use `bcprelink` to produce
a version of the bytecode which can readily be copied into WebAssembly's linear
memory. This is done with:
```bash
bcunreloc MODULE.bc -o MODULE.ubc
bcprelink MODULE.bc -o MODULE.ubc
```
**TODO**: add support to `cpm`/the IDE for this.
......@@ -64,15 +64,16 @@ defaultDeserializationSettings :: DeserializationSettings
serialize :: a !String !*World -> *(!Maybe SerializedGraph, !*World)
/**
* Serialize an expression for unrelocated interpretation. This is a mode of
* Serialize an expression for prelinked interpretation. This is a mode of
* interpretation where the code and data addresses are fixed. It is useful for
* the WebAssembly interpreter where memory always starts at index 0.
*
* @param The value to serialize.
* @param The path to the executable's bytecode (set by the `ByteCode` option in the project file).
* @param The path to the executable itself.
* @result The result may be `Nothing` if the bytecode could not be parsed.
*/
serialize_for_unrelocated_interpretation :: a !String !String !*World -> *(!Maybe String, !*World)
serialize_for_prelinked_interpretation :: a !String !String !*World -> *(!Maybe String, !*World)
/**
* Deserialize an expression using the ABC interpreter.
......
......@@ -75,8 +75,8 @@ where
ccall strip_bytecode "sA:VIp"
}
serialize_for_unrelocated_interpretation :: a !String !String !*World -> *(!Maybe String, !*World)
serialize_for_unrelocated_interpretation graph bcfile thisexe w
serialize_for_prelinked_interpretation :: a !String !String !*World -> *(!Maybe String, !*World)
serialize_for_prelinked_interpretation graph bcfile thisexe w
# (host_syms,w) = accFiles (read_symbols thisexe) w
# (graph,descinfo,modules) = copy_to_string_with_names graph
......@@ -196,7 +196,7 @@ where
| d==array_desc-4*8+2 = (1,True) // CHAR
| d==array_desc-5*8+2 = (IF_INT_64_OR_32 1 2,True) // REAL
| d==array_desc-6*8+2 = (1,True) // INT/dINT
| otherwise = abort "internal error in serialize_for_unrelocated_interpretation\n"
| otherwise = abort "internal error in serialize_for_prelinked_interpretation\n"
# arity = get_D_node_arity d
| arity<256 = (0,True)
# record_a_arity = get_D_record_a_arity d
......
abcopt
bcgen
bclink
bcprelink
bcstrip
bcunreloc
debug
interpret
......
......@@ -49,19 +49,19 @@ ifeq ($(OS),Windows_NT)
ABCOPT:=ABCOptimiser.exe
BCGEN:=ByteCodeGenerator.exe
BCLINK:=ByteCodeLinker.exe
BCPRELINK:=ByteCodePrelinker.exe
BCSTRIP:=ByteCodeStripper.exe
BCUNRELOC:=ByteCodeUnrelocator.exe
INTERP:=interpret.exe
else
ABCOPT:=abcopt
BCGEN:=bcgen
BCLINK:=bclink
BCPRELINK:=bcprelink
BCSTRIP:=bcstrip
BCUNRELOC:=bcunreloc
INTERP:=interpret
endif
BINARIES:=$(ABCOPT) $(BCGEN) $(BCLINK) $(BCSTRIP) $(BCUNRELOC) $(INTERP)
BINARIES:=$(ABCOPT) $(BCGEN) $(BCLINK) $(BCPRELINK) $(BCSTRIP) $(INTERP)
SRC_BCGEN:=\
abc_instructions.c\
......@@ -82,23 +82,23 @@ SRC_BCLINK:=\
util.c
DEP_BCLINK:=$(subst .c,.h,$(SRC_BCLINK)) settings.h
SRC_BCSTRIP:=\
SRC_BCPRELINK:=\
abc_instructions.c\
bcgen_instructions.c\
bcstrip.c\
bcprelink.c\
bytecode.c\
parse.c\
strip.c\
util.c
DEP_BCSTRIP:=$(subst .c,.h,$(SRC_BCSTRIP)) settings.h
DEP_BCPRELINK:=$(subst .c,.h,$(SRC_BCPRELINK)) settings.h
SRC_BCUNRELOC:=\
SRC_BCSTRIP:=\
abc_instructions.c\
bcunreloc.c\
bcgen_instructions.c\
bcstrip.c\
bytecode.c\
parse.c\
strip.c\
util.c
DEP_BCUNRELOC:=$(subst .c,.h,$(SRC_BCUNRELOC)) settings.h
DEP_BCSTRIP:=$(subst .c,.h,$(SRC_BCSTRIP)) settings.h
SRC_INTERPRET:=\
abc_instructions.c\
......@@ -148,12 +148,12 @@ $(BCGEN): $(SRC_BCGEN) $(DEP_BCGEN)
$(BCLINK): $(SRC_BCLINK) $(DEP_BCLINK)
$(CC) $(CFLAGS) $(CLIBS) -UCOMPUTED_GOTOS $(SRC_BCLINK) -DLINKER -o $@
$(BCPRELINK): $(SRC_BCPRELINK) $(DEP_BCPRELINK)
$(CC) $(CFLAGS) $(CLIBS) -UCOMPUTED_GOTOS -DPRELINKER -UWORD_WIDTH -DWORD_WIDTH=64 $(SRC_BCPRELINK) -o $@
$(BCSTRIP): $(SRC_BCSTRIP) $(DEP_BCSTRIP)
$(CC) $(CFLAGS) $(CLIBS) -UCOMPUTED_GOTOS $(SRC_BCSTRIP) -o $@
$(BCUNRELOC): $(SRC_BCUNRELOC) $(DEP_BCUNRELOC)
$(CC) $(CFLAGS) $(CLIBS) -UCOMPUTED_GOTOS -DUNRELOCATOR -UWORD_WIDTH -DWORD_WIDTH=64 $(SRC_BCUNRELOC) -o $@
$(INTERP): $(SRC_INTERPRET) $(DEP_INTERPRET)
$(CC) $(CFLAGS) $(CLIBS) -DINTERPRETER $(SRC_INTERPRET) -o $@
......
......@@ -19,7 +19,7 @@ enum section_type {
#define _4chars2int(a,b,c,d) ((uint64_t) (a+(b<<8)+(c<<16)+(d<<24)))
#define _7chars2int(a,b,c,d,e,f,g) ((uint64_t) (a+(b<<8)+(c<<16)+(d<<24)+((uint64_t)e<<32)+((uint64_t)f<<40)+((uint64_t)g<<48)))
#define _8chars2int(a,b,c,d,e,f,g,h) ((uint64_t) (a+(b<<8)+(c<<16)+(d<<24)+((uint64_t)e<<32)+((uint64_t)f<<40)+((uint64_t)g<<48)+((uint64_t)h<<56)))
uint64_t unrelocator_preamble[658] = {
uint64_t prelinker_preamble[658] = {
/* 0 */ 0, 0, 0, 7, _7chars2int('_','A','R','R','A','Y','_'),
/* 5 */ 0, 0, 0, 8, _8chars2int('_','S','T','R','I','N','G','_'),
/* 10 */ 0, 0, 0, 4, _4chars2int('B','O','O','L'),
......@@ -66,13 +66,13 @@ uint64_t unrelocator_preamble[658] = {
void prepare_preamble(void) {
for (int i=0; i<=32; i++) {
unrelocator_preamble[30+i*2]=26*8+2; /* INT+2 */
unrelocator_preamble[30+i*2+1]=i;
prelinker_preamble[30+i*2]=26*8+2; /* INT+2 */
prelinker_preamble[30+i*2+1]=i;
}
for (int i=0; i<256; i++) {
unrelocator_preamble[146+i*2]=16*8+2; /* CHAR+2 */
unrelocator_preamble[146+i*2+1]=i;
prelinker_preamble[146+i*2]=16*8+2; /* CHAR+2 */
prelinker_preamble[146+i*2+1]=i;
}
}
......@@ -129,7 +129,7 @@ int main(int argc, char **argv) {
struct program *program=state.program;
prepare_preamble();
write_section(output_file, ST_Preamble, sizeof(unrelocator_preamble)/sizeof(uint64_t), unrelocator_preamble);
write_section(output_file, ST_Preamble, sizeof(prelinker_preamble)/sizeof(uint64_t), prelinker_preamble);
write_section(output_file, ST_Code, program->code_size, program->code);
write_section(output_file, ST_Data, program->data_size, program->data);
write_section(output_file, ST_Start, 1, &program->symbol_table[program->start_symbol_id].offset);
......
#pragma once
extern uint64_t prelinker_preamble[658];
#pragma once
extern uint64_t unrelocator_preamble[658];
......@@ -13,8 +13,8 @@
# include "bcgen_instructions.h"
#endif
#ifdef UNRELOCATOR
# include "bcunreloc.h"
#ifdef PRELINKER
# include "bcprelink.h"
#endif
#ifdef LINK_CLEAN_RUNTIME
......@@ -272,8 +272,8 @@ int parse_program(struct parser *state, struct char_provider *cp) {
# else
state->program->data_size = elem32;
# endif
/* The unrelocator writes data size between code and data segment, so reserve this space.
* TODO: better would be to use a different file format in the unrelocator. */
/* The prelinker writes data size between code and data segment, so reserve this space.
* TODO: better would be to use a different file format in the prelinker. */
state->program->code = safe_malloc(sizeof(BC_WORD) * (code_size+state->program->data_size+1));
state->program->data = state->program->code + code_size + 1;
#endif
......@@ -512,25 +512,25 @@ int parse_program(struct parser *state, struct char_provider *cp) {
return 1;
state->program->symbols[state->symbols_ptr++] = elem8;
} while (elem8);
#if defined(INTERPRETER) || defined(UNRELOCATOR)
#if defined(INTERPRETER) || defined(PRELINKER)
# ifdef INTERPRETER
# define INTERPRETER_OR_UNRELOCATOR(i,u) i
# define INTERPRETER_OR_PRELINKER(i,u) i
# else
# define INTERPRETER_OR_UNRELOCATOR(i,u) (u*8)
# define INTERPRETER_OR_PRELINKER(i,u) (u*8)
# endif
if (!strcmp(state->program->symbol_table[state->ptr].name, "__ARRAY__")) {
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_UNRELOCATOR(&__ARRAY__,1);
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&__ARRAY__,1);
} else if (!strcmp(state->program->symbol_table[state->ptr].name, "__STRING__")) {
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_UNRELOCATOR(&__STRING__,6);
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&__STRING__,6);
} else if (!strcmp(state->program->symbol_table[state->ptr].name, "INT") ||
!strcmp(state->program->symbol_table[state->ptr].name, "dINT")) {
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_UNRELOCATOR(&INT,26);
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&INT,26);
} else if (!strcmp(state->program->symbol_table[state->ptr].name, "BOOL")) {
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_UNRELOCATOR(&BOOL,11);
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&BOOL,11);
} else if (!strcmp(state->program->symbol_table[state->ptr].name, "CHAR")) {
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_UNRELOCATOR(&CHAR,16);
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&CHAR,16);
} else if (!strcmp(state->program->symbol_table[state->ptr].name, "REAL")) {
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_UNRELOCATOR(&REAL,21);
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&REAL,21);
} else if (state->program->symbol_table[state->ptr].offset == -1) {
# ifdef DEBUG_CLEAN_LINKS
EPRINTF("Warning: symbol '%s' is not defined.\n",state->program->symbol_table[state->ptr].name);
......@@ -554,8 +554,8 @@ int parse_program(struct parser *state, struct char_provider *cp) {
# endif
# ifdef INTERPRETER
state->program->symbol_table[state->ptr].offset += (BC_WORD) state->program->data;
# elif defined(UNRELOCATOR)
state->program->symbol_table[state->ptr].offset += ((BC_WORD)state->program->code_size+3)*8+sizeof(unrelocator_preamble);
# elif defined(PRELINKER)
state->program->symbol_table[state->ptr].offset += ((BC_WORD)state->program->code_size+3)*8+sizeof(prelinker_preamble);
# endif
# ifdef LINK_CLEAN_RUNTIME
if (state->program->symbol_table[state->ptr].name[0]) {
......@@ -591,8 +591,8 @@ int parse_program(struct parser *state, struct char_provider *cp) {
# endif
# ifdef INTERPRETER
state->program->symbol_table[state->ptr].offset += (BC_WORD) state->program->code;
# elif defined(UNRELOCATOR)
state->program->symbol_table[state->ptr].offset += 2*8+sizeof(unrelocator_preamble);
# elif defined(PRELINKER)
state->program->symbol_table[state->ptr].offset += 2*8+sizeof(prelinker_preamble);
# endif
# ifdef LINK_CLEAN_RUNTIME
if (state->program->symbol_table[state->ptr].name[0]) {
......
......@@ -101,7 +101,7 @@ while true; do
-w)
WASM=1
IP="js ../src-js/interpret.js"
SRCMAKETARGETS="abcopt bcgen bclink bcstrip bcunreloc"
SRCMAKETARGETS="abcopt bcgen bclink bcprelink bcstrip"
BC_EXTENSION="ubc"
shift;;
......@@ -223,7 +223,7 @@ do
[ $BENCHMARK -gt 0 ] && mv "$MODULE.icl.nobm" "$MODULE.icl"
[ $WASM -gt 0 ] && ../src/bcunreloc "$MODULE.bc" -o "$MODULE.ubc"
[ $WASM -gt 0 ] && ../src/bcprelink "$MODULE.bc" -o "$MODULE.ubc"
if [ $BENCHMARK -gt 0 ]; then
/usr/bin/time -p $IP $MODULE_RUNFLAGS $RUNFLAGS $MODULE.$BC_EXTENSION 2>bm-tmp >$MODULE.result
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment