Skip to content

Commit

Permalink
interface module support fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gooofy committed Jan 8, 2022
1 parent 0e9c22e commit 1fe54c9
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 29 deletions.
8 changes: 7 additions & 1 deletion src/compiler/aqb.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static void print_usage(char *argv[])
fprintf(stderr, " -A <foo.s> create ASMOne/ASMPro source file\n");
fprintf(stderr, " -B <foo.s> create vasm source file\n");
fprintf(stderr, " -s <foo.sym> create symbol file\n");
fprintf(stderr, " -I interface module (no code)\n");
fprintf(stderr, " -o <foo> create hunk binary file\n");
fprintf(stderr, " -p <foo> create hunk object file\n");
fprintf(stderr, " -v verbose\n");
Expand Down Expand Up @@ -201,6 +202,7 @@ int main (int argc, char *argv[])
static bool write_obj = FALSE;
static bool write_bin = FALSE;
static bool launch_ide = TRUE;
static bool hasCode = TRUE;
static char symfn[PATH_MAX];
static char objfn[PATH_MAX];
static char binfn[PATH_MAX];
Expand Down Expand Up @@ -264,6 +266,9 @@ int main (int argc, char *argv[])
case 'O':
OPT_set(OPTION_RACOLOR, TRUE);
break;
case 'I':
hasCode = FALSE;
break;
case 'a':
optind++;
if (optind >= argc)
Expand Down Expand Up @@ -451,6 +456,7 @@ int main (int argc, char *argv[])
write_bin ? binfn : NULL,
write_asmgas ? asm_gas_fn : NULL,
write_asmpro ? asm_asmpro_fn : NULL,
write_vasm ? asm_vasm_fn : NULL);
write_vasm ? asm_vasm_fn : NULL,
hasCode);
}

5 changes: 3 additions & 2 deletions src/compiler/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ void CO_exit(int return_code)
longjmp (g_exit_jmp_buf, 1);
}

int CO_compile(string sourcefn, string module_name, string symfn, string objfn, string binfn, string asm_gas_fn, string asm_asmpro_fn, string asm_vasm_fn)
int CO_compile(string sourcefn, string module_name, string symfn, string objfn, string binfn,
string asm_gas_fn, string asm_asmpro_fn, string asm_vasm_fn, bool hasCode)
{
static CG_fragList frags;
static FILE *sourcef;
Expand Down Expand Up @@ -122,7 +123,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,

if (symfn)
{
if (FE_writeSymFile(symfn))
if (FE_writeSymFile(symfn, hasCode))
{
LOG_printf (OPT_get(OPTION_VERBOSE) ? LOG_INFO : LOG_DEBUG, "\n%s written.\n", symfn);
}
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#include "util.h"

int CO_compile(string sourcefn, string module_name, string symfn, string objfn, string binfn, string asm_gas_fn, string asm_asmpro_fn, string asm_vasm_fn);
int CO_compile(string sourcefn, string module_name, string symfn, string objfn, string binfn,
string asm_gas_fn, string asm_asmpro_fn, string asm_vasm_fn, bool hasCode);

void CO_exit(int return_code);

Expand Down
25 changes: 5 additions & 20 deletions src/compiler/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "logger.h"

#define SYM_MAGIC 0x53425141 // AQBS
#define SYM_VERSION 41
#define SYM_VERSION 42

E_module g_builtinsModule = NULL;

Expand Down Expand Up @@ -808,6 +808,8 @@ bool E_saveModule(string modfn, E_module mod)

fwrite_u2 (modf, SYM_VERSION);

fwrite_u1 (modf, mod->hasCode);

// module table (used in type serialization for module referencing)
TAB_table modTable; // S_symbol moduleName -> int mid
modTable = TAB_empty(UP_env);
Expand Down Expand Up @@ -1162,25 +1164,6 @@ E_module E_loadModule(S_symbol sModule)
LOG_printf(LOG_DEBUG, "env: E_loadModule(%s): TAB_enter ...\n", S_name(sModule));
TAB_enter (g_modCache, sModule, mod);

// check if <module>.a exists

{
char libfn[PATH_MAX];
snprintf(libfn, PATH_MAX, "%s.a", S_name(sModule));
FILE *f2 = E_openModuleFile (libfn);
if (f2)
{
fclose(f2);
mod->hasCode = TRUE;
}
else
{
mod->hasCode = FALSE;
}

LOG_printf (LOG_DEBUG, "env: E_loadModule(%s): hasCode=%d (libfn=%s)\n", S_name(sModule), mod->hasCode, libfn);
}

// check header

uint32_t m=fread_u4(modf);
Expand All @@ -1197,6 +1180,8 @@ E_module E_loadModule(S_symbol sModule)
goto fail;
}

mod->hasCode = fread_u1(modf);

// read module table

TAB_table modTable; // mid -> E_module
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -7532,8 +7532,9 @@ CG_fragList FE_sourceProgram(FILE *inf, const char *filename, bool is_main, stri
return CG_getResult();
}

bool FE_writeSymFile(string symfn)
bool FE_writeSymFile(string symfn, bool hasCode)
{
FE_mod->hasCode = hasCode;
return E_saveModule(symfn, FE_mod);
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern E_module FE_mod;

CG_fragList FE_sourceProgram(FILE *inf, const char *filename, bool is_main, string module_name);

bool FE_writeSymFile(string symfn);
bool FE_writeSymFile(string symfn, bool hasCode);

void FE_init(void);

Expand Down
3 changes: 2 additions & 1 deletion src/compiler/ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,8 @@ static bool _compile(IDE_instance ed)
ed->binfn,
/*asm_gas_fn=*/ NULL,
/*asm_asmpro_fn=*/ NULL,
/*asm_vasm_fn=*/ NULL);
/*asm_vasm_fn=*/ NULL,
/*hasCode=*/ TRUE);

//LOG_printf (LOG_INFO, "\n*** press any key to continue ***\n\n");
//UI_waitkey ();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/OSGadToolsConsts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include ../../../config.mk
all: OSGadToolsConsts.sym

OSGadToolsConsts.sym : OSGadToolsConsts.bas
$(AQB) -L .. -d _aqb -s OSGadToolsConsts.sym $<
$(AQB) -L .. -I -d _aqb -s OSGadToolsConsts.sym $<
pushd .. && rm -f OSGadToolsConsts.sym OSGadToolsConsts.a && ln -s OSGadToolsConsts/OSGadToolsConsts.sym && ln -s OSGadToolsConsts/OSGadToolsConsts.a && popd
cp $< $(DISTDIR)/libsrc
cp $@ $(DISTDIR)/lib
Expand Down
2 changes: 1 addition & 1 deletion tests/mod1/mod1.bas
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ASSERT foobares = 23
foobar(42)
ASSERT foobares = 42

TRACE v1.i1, v1.l1
' TRACE v1.i1, v1.l1
ASSERT v1.i1 = 23
ASSERT v1.l1 = 123456

Expand Down

0 comments on commit 1fe54c9

Please sign in to comment.