Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- uses: actions/checkout@v3
- name: build
run: |
make LDFLAGS="-s -static" ack-setup.exe
make LDFLAGS="-s -static" ack-setup.exe AB_SANDBOX=no
- name: upload setup
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

- name: build
run: |
make LDFLAGS="-s -static" ack-setup.exe
make LDFLAGS="-s -static" ack-setup.exe AB_SANDBOX=no

- name: date
run: |
Expand Down
9 changes: 8 additions & 1 deletion build/ab.mk
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ build-file-timestamps = $(shell ls -l $(build-files) | md5sum)
# Wipe the build file (forcing a regeneration) if the make environment is different.
# (Conveniently, this includes the pkg-config hash calculated above.)

ignored-variables = MAKE_RESTARTS .VARIABLES MAKECMDGOALS MAKEFLAGS MFLAGS
ignored-variables = MAKE_RESTARTS .VARIABLES MAKECMDGOALS MAKEFLAGS MFLAGS PAGER _ \
DESKTOP_STARTUP_ID XAUTHORITY ICEAUTHORITY SSH_AUTH_SOCK SESSION_MANAGER \
INVOCATION_ID SYSTEMD_EXEC_PID MANAGER_PID SSH_AGENT_PID JOURNAL_STREAM \
GPG_TTY WINDOWID MANAGERPID MAKE_TERMOUT MAKE_TERMERR OLDPWD
$(shell mkdir -p $(OBJ))
$(file >$(OBJ)/newvars.txt,$(foreach v,$(filter-out $(ignored-variables),$(.VARIABLES)),$(v)=$($(v))$(newline)))
$(shell touch $(OBJ)/vars.txt)
Expand All @@ -104,13 +107,17 @@ clean::
@echo CLEAN
$(hide) rm -rf $(OBJ)

compile_commands.json: $(OBJ)/build.ninja
+$(hide) $(NINJA) -f $(OBJ)/build.ninja -t compdb > $@

export PYTHONHASHSEED = 1
$(OBJ)/build.ninja $(OBJ)/build.targets &:
@echo "AB"
$(hide) $(PYTHON) -X pycache_prefix=$(OBJ)/__pycache__ build/ab.py \
-o $(OBJ) build.py \
-v $(OBJ)/vars.txt \
|| (rm -f $@ && false)
$(hide) cp $(OBJ)/compile_commands.json compile_commands.json

include $(OBJ)/build.targets
.PHONY: $(ninja-targets)
Expand Down
70 changes: 53 additions & 17 deletions build/ab.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import importlib
import importlib.util
import inspect
import json
import os
import re
import string
Expand All @@ -27,6 +28,7 @@
materialisingStack = []
defaultGlobals = {}
outputTargets = set()
commandsDb = []

RE_FORMAT_SPEC = re.compile(
r"(?:(?P<fill>[\s\S])?(?P<align>[<>=^]))?"
Expand Down Expand Up @@ -540,6 +542,15 @@ def shell(*args):
shellFp.write(s)


def add_commanddb_entry(commands, file):
global commandsDb
commandsDb += [{
"directory": os.getcwd(),
"command": (" && ".join(commands)),
"file": file
}
]

def emit_rule(self, ins, outs, cmds=[], label=None):
name = self.name
fins = [self.templateexpand(f) for f in set(filenamesof(ins))]
Expand All @@ -558,19 +569,26 @@ def emit_rule(self, ins, outs, cmds=[], label=None):
os.makedirs(self.dir, exist_ok=True)
rule = []

sandbox = join(self.dir, "sandbox")
emit(f"rm -rf {sandbox}", into=rule)
emit(
f"{G.PYTHON} build/_sandbox.py --link -s", sandbox, *fins, into=rule
)
for c in cmds:
emit(f"(cd {sandbox} &&", c, ")", into=rule)
emit(
f"{G.PYTHON} build/_sandbox.py --export -s",
sandbox,
*fouts,
into=rule,
)
if G.AB_SANDBOX == "yes":
sandbox = join(self.dir, "sandbox")
emit(f"rm -rf {sandbox}", into=rule)
emit(
f"{G.PYTHON} build/_sandbox.py --link -s",
sandbox,
*fins,
into=rule,
)
for c in cmds:
emit(f"(cd {sandbox} &&", c, ")", into=rule)
emit(
f"{G.PYTHON} build/_sandbox.py --export -s",
sandbox,
*fouts,
into=rule,
)
else:
for c in cmds:
emit(c, into=rule)

ruletext = "".join(rule)
if len(ruletext) > 7000:
Expand All @@ -581,7 +599,7 @@ def emit_rule(self, ins, outs, cmds=[], label=None):
fp.write("set -e\n")
fp.write(ruletext)

emit("build", *fouts, ":rule", *fins, rulef)
emit("build", *fouts, ":rule", *fins)
emit(" command=sh", rulef)
else:
emit("build", *fouts, ":rule", *fins)
Expand All @@ -592,7 +610,6 @@ def emit_rule(self, ins, outs, cmds=[], label=None):
if label:
emit(" description=", label)
emit("build", name, ":phony", *fouts)

else:
assert len(cmds) == 0, "rules with no outputs cannot have commands"
emit("build", name, ":phony", *fins)
Expand All @@ -608,6 +625,7 @@ def simplerule(
outs: Targets = [],
deps: Targets = [],
commands=[],
add_to_commanddb=False,
label="RULE",
):
self.ins = ins
Expand All @@ -623,8 +641,22 @@ def simplerule(

cs = [("mkdir -p %s" % dir) for dir in dirs]

coreCommands = []
for c in commands:
cs += [self.templateexpand(c)]
coreCommands += [self.templateexpand(c)]
cs += coreCommands

if add_to_commanddb:
infiles = filenamesof(ins)
if len(infiles) > 0:
global commandsDb
commandsDb += [
{
"directory": os.getcwd(),
"command": (" && ".join(coreCommands)),
"file": infiles[0],
}
]

emit_rule(
self=self,
Expand Down Expand Up @@ -696,8 +728,9 @@ def main():
if "=" in line:
name, value = line.split("=", 1)
G.setdefault(name.strip(), value.strip())
G.setdefault("AB_SANDBOX", "yes")

global ninjaFp, shellFp, outputdir
global ninjaFp, shellFp, jsonFp, outputdir
outputdir = args.outputdir
G.setdefault("OBJ", outputdir)
ninjaFp = open(outputdir + "/build.ninja", "wt")
Expand All @@ -721,5 +754,8 @@ def main():
fp.write("ninja-targets =")
fp.write(substituteGlobalVariables(" ".join(outputTargets)))

with open(outputdir + "/compile_commands.json", "wt") as fp:
json.dump(commandsDb, fp)


main()
3 changes: 2 additions & 1 deletion build/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
filenamesof,
flatten,
simplerule,
emit,
add_commanddb_entry,
G,
)
from build.utils import stripext, collectattrs
Expand Down Expand Up @@ -116,6 +116,7 @@ def cfileimpl(self, name, srcs, deps, suffix, commands, label, toolchain, cflags
outs=[outleaf],
label=label,
commands=commands,
add_to_commanddb=True,
args={"cflags": cflags},
)

Expand Down
1 change: 1 addition & 0 deletions compile_commands.json

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions util/ncgg/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def ncgg(self, name, srcs: Targets = [], deps: Targets = [], cflags=[]):
ins=["util/ncgg", cpptable],
outs=["=tables.c", "=tables.h"],
commands=[
"$[ins]",
"mv tables.H $[dir]/tables.h",
"mv tables.c $[dir]/tables.c",
"$[ins[0]] -o $[dir] $[ins[1:]]"
],
label="NCGG",
)
14 changes: 10 additions & 4 deletions util/ncgg/extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */

extern int wordsize;
extern int pointersize;
Expand Down Expand Up @@ -31,7 +30,7 @@ extern int allsetno;
extern int inproc;
extern int callproc;
extern int procarg[];
extern int fc1,fc2,fc3,fc4;
extern int fc1, fc2, fc3, fc4;
extern int maxmembers;
extern int regclass;
extern int maxtokensize;
Expand All @@ -48,7 +47,7 @@ extern void initemhash(void);
/* error.c */
extern void fatal(const char* s, ...);
extern void error(const char* s, ...);
extern int tabovf(char *string);
extern int tabovf(char* string);

/* output.c */
extern void errorexit(void);
Expand All @@ -57,4 +56,11 @@ extern void finishio(void);
extern void statistics(void);

/* strlookup.c */
extern int strlookup(char *str);
extern int strlookup(char* str);

/* Global parameters */
extern int nerrors;
extern int code_in_c;
extern int tabledebug;
extern int verbose;
extern const char* outputdir;
18 changes: 7 additions & 11 deletions util/ncgg/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,18 @@
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef NORCSID
static char rcsid[] = "$Id$";
#endif

#include <stdlib.h>
#include <stdio.h>
#include "param.h"
#include "hall.h"
#include "expr.h"
#include "extern.h"
#include "lookup.h"

char *filename;
char* filename;

int main(int argc, char **argv)
int main(int argc, char** argv)
{
extern int nerrors;
extern int code_in_c;
extern int tabledebug;
extern int verbose;

while (argc > 1 && argv[1][0] == '-')
{
switch (argv[1][1])
Expand All @@ -36,6 +27,11 @@ int main(int argc, char **argv)
case 'v':
verbose++;
break;
case 'o':
outputdir = argv[2];
argv++;
argc--;
break;
default:
error("Unknown flag -%c", argv[1][1]);
}
Expand Down
6 changes: 4 additions & 2 deletions util/ncgg/ncgg.6
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cgg \- Code table translating utility
.SH SYNOPSIS
.B ~em/lib.bin/cgg
[-c] [-d] [-v] table
[-c] [-d] [-v] [-o outputdir] table
.SH DESCRIPTION
cgg translates a machine description table into the internal
structures needed by em_cg.
Expand All @@ -25,8 +25,10 @@ bittable described under the -u option of em_ncg(6).
Give statistics about table usage at end of program.
Normally only the tables that have been used more than 75%
are reported.
.IP -o outputdir
Write the output files to the specified directory.
.SH FILES
tables.H, tables.c
tables.h, tables.c
.br
code If the -c flag was given
.br
Expand Down
46 changes: 28 additions & 18 deletions util/ncgg/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,14 @@
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* #define CODEDEBUG *//* print readable code */
#ifdef CODEDEBUG
int code_in_c=0; /* put readable code in "code" */
int tabledebug=1; /* generate code for table debugging */
#else
int code_in_c = 1; /* put code in "tables.c" */
int tabledebug = 0; /* do not generate code for table debugging */
#endif
int verbose = 0; /* print all statistics */
int use_tes; /* use top element size information */
char *c_file = "tables.c";
char *h_file = "tables.H";
char *cd_file = "code";

#ifndef NORCSID
static char rcsid[] = "$Id$";
#endif
/* #define CODEDEBUG */ /* print readable code */

#include <errno.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include "varinfo.h"
#include "param.h"
#include "reg.h"
Expand All @@ -36,7 +23,21 @@ static char rcsid[] = "$Id$";
#include "pseudo.h"
#include "regvar.h"
#include "extern.h"
#include "subr.h"

#ifdef CODEDEBUG
int code_in_c=0; /* put readable code in "code" */
int tabledebug=1; /* generate code for table debugging */
#else
int code_in_c = 1; /* put code in "tables.c" */
int tabledebug = 0; /* do not generate code for table debugging */
#endif
int verbose = 0; /* print all statistics */
int use_tes; /* use top element size information */
char *c_file = "tables.c";
char *h_file = "tables.h";
char *cd_file = "code";
const char* outputdir = ".";
#define BMASK 0xFF
#define BSHIFT 8

Expand Down Expand Up @@ -105,6 +106,12 @@ void unlfile(FILE *f, char *s)

void initio(void)
{
char* oldcwd = mygetcwd();

errno = 0;
chdir(outputdir);
if (errno)
perror("output directory inaccessible");

opnfile(&ctable, c_file);
opnfile(&htable, h_file);
Expand All @@ -114,7 +121,10 @@ void initio(void)
opnfile(&code, cd_file);
patbyte(0);
if (tabledebug)
lineset = (short *) myalloc(SZOFSET(MAXSOURCELINES) * sizeof(short));
lineset = (short*)myalloc(SZOFSET(MAXSOURCELINES) * sizeof(short));

chdir(oldcwd);
free(oldcwd);
}

void finishcode(void)
Expand Down
Loading
Loading