diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 0e2da3d91d..f313bd93cc 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -47,13 +47,12 @@ jobs: flex zip git + ninja + diffutils - uses: actions/checkout@v3 - name: build run: | - make LDFLAGS="-s -static" - - name: package - run: | - make ack-setup.exe + make LDFLAGS="-s -static" ack-setup.exe - name: upload setup uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ef8227e2ca..25b19e52e3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,16 +31,14 @@ jobs: mingw-w64-ucrt-x86_64-pkg-config mingw-w64-ucrt-x86_64-python zip + ninja + diffutils - uses: actions/checkout@v3 - name: build run: | - make LDFLAGS="-s -static" - - - name: package - run: | - make ack-setup.exe + make LDFLAGS="-s -static" ack-setup.exe - name: date run: | diff --git a/Makefile b/Makefile index 7d6d605c5b..2624d43195 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,7 @@ HOSTCFLAGS = $(CFLAGS) ACKCFLAGS = -O LDFLAGS ?= -g +ACKLDFLAGS = # Various commands. diff --git a/build/ab.mk b/build/ab.mk index b1a58994c7..588cdf6f69 100644 --- a/build/ab.mk +++ b/build/ab.mk @@ -1,6 +1,4 @@ MAKENOT4 := $(if $(findstring 3.9999, $(lastword $(sort 3.9999 $(MAKE_VERSION)))),yes,no) -MAKE4.3 := $(if $(findstring 4.3, $(firstword $(sort 4.3 $(MAKE_VERSION)))),yes,no) -MAKE4.1 := $(if $(findstring no_no,$(MAKENOT4)_$(MAKE4.3)),yes,no) ifeq ($(MAKENOT4),yes) $(error You need GNU Make 4.x for this (if you're on OSX, use gmake).) @@ -17,16 +15,17 @@ HOSTCC ?= gcc HOSTCXX ?= g++ HOSTAR ?= ar HOSTCFLAGS ?= -g -Og +HOSTCXXFLAGS ?= $(HOSTCFLAGS) HOSTLDFLAGS ?= -g CC ?= $(HOSTCC) CXX ?= $(HOSTCXX) AR ?= $(HOSTAR) CFLAGS ?= $(HOSTCFLAGS) +CXXFLAGS ?= $(CFLAGS) LDFLAGS ?= $(HOSTLDFLAGS) -export PKG_CONFIG -export HOST_PKG_CONFIG +NINJA ?= ninja ifdef VERBOSE hide = @@ -65,32 +64,33 @@ EXT ?= CWD=$(shell pwd) -ifeq ($(AB_ENABLE_PROGRESS_INFO),true) - ifeq ($(PROGRESSINFO),) - # The first make invocation here has to have its output discarded or else it - # produces spurious 'Leaving directory' messages... don't know why. - rulecount := $(strip $(shell $(MAKE) --no-print-directory -q $(OBJ)/build.mk PROGRESSINFO=1 > /dev/null \ - && $(MAKE) --no-print-directory -n $(MAKECMDGOALS) PROGRESSINFO=XXXPROGRESSINFOXXX | grep XXXPROGRESSINFOXXX | wc -l)) - ruleindex := 1 - PROGRESSINFO = "[$(ruleindex)/$(rulecount)]$(eval ruleindex := $(shell expr $(ruleindex) + 1)) " - endif -else - PROGRESSINFO = "" -endif +define newline + + +endef + +define check_for_command + $(shell command -v $1 >/dev/null || (echo "Required command '$1' missing" >&2 && kill $$PPID)) +endef -PKG_CONFIG_HASHES = $(OBJ)/.pkg-config-hashes/target-$(word 1, $(shell $(PKG_CONFIG) --list-all | md5sum)) -HOST_PKG_CONFIG_HASHES = $(OBJ)/.pkg-config-hashes/host-$(word 1, $(shell $(HOST_PKG_CONFIG) --list-all | md5sum)) +$(call check_for_command,ninja) +$(call check_for_command,cmp) +$(call check_for_command,$(PYTHON)) -$(OBJ)/build.mk : $(PKG_CONFIG_HASHES) $(HOST_PKG_CONFIG_HASHES) -$(PKG_CONFIG_HASHES) $(HOST_PKG_CONFIG_HASHES) &: - $(hide) rm -rf $(OBJ)/.pkg-config-hashes - $(hide) mkdir -p $(OBJ)/.pkg-config-hashes - $(hide) touch $(PKG_CONFIG_HASHES) $(HOST_PKG_CONFIG_HASHES) +pkg-config-hash = $(shell ($(PKG_CONFIG) --list-all && $(HOST_PKG_CONFIG) --list-all) | md5sum) +build-files = $(shell find . -name .obj -prune -o \( -name 'build.py' -a -type f \) -print) $(wildcard build/*.py) $(wildcard config.py) +build-file-timestamps = $(shell ls -l $(build-files) | md5sum) -include $(OBJ)/build.mk +# Wipe the build file (forcing a regeneration) if the make environment is different. +# (Conveniently, this includes the pkg-config hash calculated above.) -MAKEFLAGS += -r -j$(shell nproc) -.DELETE_ON_ERROR: +ignored-variables = MAKE_RESTARTS .VARIABLES MAKECMDGOALS MAKEFLAGS MFLAGS +$(shell mkdir -p $(OBJ)) +$(file >$(OBJ)/newvars.txt,$(foreach v,$(filter-out $(ignored-variables),$(.VARIABLES)),$(v)=$($(v))$(newline))) +$(shell touch $(OBJ)/vars.txt) +#$(shell diff -u $(OBJ)/vars.txt $(OBJ)/newvars.txt >&2) +$(shell cmp -s $(OBJ)/newvars.txt $(OBJ)/vars.txt || (rm -f $(OBJ)/build.ninja && echo "Environment changed --- regenerating" >&2)) +$(shell mv $(OBJ)/newvars.txt $(OBJ)/vars.txt) .PHONY: update-ab update-ab: @@ -105,9 +105,15 @@ clean:: $(hide) rm -rf $(OBJ) export PYTHONHASHSEED = 1 -build-files = $(shell find . -name 'build.py') $(wildcard build/*.py) $(wildcard config.py) -$(OBJ)/build.mk: Makefile $(build-files) build/ab.mk +$(OBJ)/build.ninja $(OBJ)/build.targets &: @echo "AB" - @mkdir -p $(OBJ) - $(hide) $(PYTHON) -X pycache_prefix=$(OBJ)/__pycache__ build/ab.py -o $@ build.py \ - || rm -f $@ + $(hide) $(PYTHON) -X pycache_prefix=$(OBJ)/__pycache__ build/ab.py \ + -o $(OBJ) build.py \ + -v $(OBJ)/vars.txt \ + || (rm -f $@ && false) + +include $(OBJ)/build.targets +.PHONY: $(ninja-targets) +.NOTPARALLEL: +$(ninja-targets): $(OBJ)/build.ninja + +$(hide) $(NINJA) -f $(OBJ)/build.ninja $@ diff --git a/build/ab.ninja b/build/ab.ninja new file mode 100644 index 0000000000..98599f85ff --- /dev/null +++ b/build/ab.ninja @@ -0,0 +1,2 @@ +rule rule + command = $command diff --git a/build/ab.py b/build/ab.py index 561d39275b..d8606e22b0 100644 --- a/build/ab.py +++ b/build/ab.py @@ -1,36 +1,32 @@ +from collections import namedtuple +from copy import copy +from importlib.machinery import SourceFileLoader, PathFinder, ModuleSpec from os.path import * from pathlib import Path from typing import Iterable import argparse +import ast import builtins -from copy import copy import functools +import hashlib import importlib import importlib.util -from importlib.machinery import ( - SourceFileLoader, - PathFinder, - ModuleSpec, -) import inspect +import os +import re import string import sys -import hashlib -import re -import ast -from collections import namedtuple +import types -VERBOSE_MK_FILE = False +VERBOSE_NINJA_FILE = False -verbose = False quiet = False cwdStack = [""] targets = {} unmaterialisedTargets = {} # dict, not set, to get consistent ordering materialisingStack = [] defaultGlobals = {} -globalId = 1 -wordCache = {} +outputTargets = set() RE_FORMAT_SPEC = re.compile( r"(?:(?P[\s\S])?(?P[<>=^]))?" @@ -52,6 +48,15 @@ old_import = builtins.__import__ +class Environment(types.SimpleNamespace): + def setdefault(self, name, value): + if not hasattr(self, name): + setattr(self, name, value) + + +G = Environment() + + class PathFinderImpl(PathFinder): def find_spec(self, fullname, path, target=None): # The second test here is needed for Python 3.9. @@ -102,27 +107,88 @@ def error(message): raise ABException(message) +def _undo_escaped_dollar(s, op): + return s.replace(f"$${op}", f"${op}") + + class BracketedFormatter(string.Formatter): def parse(self, format_string): while format_string: - left, *right = format_string.split("$[", 1) - if not right: - yield (left, None, None, None) + m = re.search(f"(?:[^$]|^)()\\$\\[()", format_string) + if not m: + yield ( + _undo_escaped_dollar(format_string, "["), + None, + None, + None, + ) break - right = right[0] + left = format_string[: m.start(1)] + right = format_string[m.end(2) :] offset = len(right) + 1 try: ast.parse(right) except SyntaxError as e: - if not str(e).startswith("unmatched ']'"): + if not str(e).startswith(f"unmatched ']'"): raise e offset = e.offset expr = right[0 : offset - 1] format_string = right[offset:] - yield (left if left else None, expr, None, None) + yield ( + _undo_escaped_dollar(left, "[") if left else None, + expr, + None, + None, + ) + + +class GlobalFormatter(string.Formatter): + def parse(self, format_string): + while format_string: + m = re.search(f"(?:[^$]|^)()\\$\\(([^)]*)\\)()", format_string) + if not m: + yield ( + format_string, + None, + None, + None, + ) + break + left = format_string[: m.start(1)] + var = m[2] + format_string = format_string[m.end(3) :] + + yield ( + left if left else None, + var, + None, + None, + ) + + def get_field(self, name, a1, a2): + return ( + getattr(G, name), + False, + ) + + def format_field(self, value, format_spec): + if not value: + return "" + return str(value) + + +globalFormatter = GlobalFormatter() + + +def substituteGlobalVariables(value): + while True: + oldValue = value + value = globalFormatter.format(value) + if value == oldValue: + return _undo_escaped_dollar(value, "(") def Rule(func): @@ -187,12 +253,10 @@ def _isiterable(xs): class Target: def __init__(self, cwd, name): - if verbose: - print("rule('%s', cwd='%s'" % (name, cwd)) self.name = name self.localname = self.name.rsplit("+")[-1] self.traits = set() - self.dir = join("$(OBJ)", name) + self.dir = join(G.OBJ, name) self.ins = [] self.outs = [] self.deps = [] @@ -232,7 +296,8 @@ def format_field(self, value, format_spec): [selfi.templateexpand(f) for f in filenamesof(value)] ) - return Formatter().format(s) + s = Formatter().format(s) + return substituteGlobalVariables(s) def materialise(self, replacing=False): if self not in unmaterialisedTargets: @@ -341,10 +406,10 @@ def targetof(value, cwd=None): elif value.startswith("./"): value = normpath(join(cwd, value)) # Explicit directories are always raw files. - elif value.endswith("/"): + if value.endswith("/"): return _filetarget(value, cwd) - # Anything starting with a variable expansion is always a raw file. - elif value.startswith("$"): + # Anything in .obj is a raw file. + elif value.startswith(outputdir) or value.startswith(G.OBJ): return _filetarget(value, cwd) # If this is not a rule lookup... @@ -467,89 +532,71 @@ def emit(*args, into=None): if into is not None: into += [s] else: - outputFp.write(s) + ninjaFp.write(s) + + +def shell(*args): + s = "".join(args) + "\n" + shellFp.write(s) def emit_rule(self, ins, outs, cmds=[], label=None): name = self.name - fins_list = filenamesof(ins) - fins = set(fins_list) - fouts = filenamesof(outs) - nonobjs = [f for f in fouts if not f.startswith("$(OBJ)")] + fins = [self.templateexpand(f) for f in set(filenamesof(ins))] + fouts = [self.templateexpand(f) for f in filenamesof(outs)] + + global outputTargets + outputTargets.update(fouts) + outputTargets.add(name) emit("") - if VERBOSE_MK_FILE: + if VERBOSE_NINJA_FILE: for k, v in self.args.items(): emit(f"# {k} = {v}") - lines = [] - if nonobjs: - emit("clean::", into=lines) - emit("\t$(hide) rm -f", *nonobjs, into=lines) - - hashable = cmds + fins_list + fouts - hash = hashlib.sha1(bytes("\n".join(hashable), "utf-8")).hexdigest() - hashfile = join(self.dir, f"hash_{hash}") - - global globalId - emit(".PHONY:", name, into=lines) if outs: - outsn = globalId - globalId = globalId + 1 - insn = globalId - globalId = globalId + 1 - - emit(f"OUTS_{outsn}", "=", *fouts, into=lines) - emit(f"INS_{insn}", "=", *fins, into=lines) - emit( - name, - ":", - hashfile, - f"$(OUTS_{outsn})", - into=lines, - ) - emit("ifeq ($(MAKE4.3),yes)", into=lines) - emit( - hashfile, - f"$(OUTS_{outsn})", - "&:", - f"$(INS_{insn})", - into=lines, - ) - emit("else", into=lines) - emit(f"$(OUTS_{outsn})", ":", hashfile, into=lines) - emit(hashfile, ":", f"$(INS_{insn})", into=lines) - emit("endif", into=lines) - - if label: - emit("\t$(hide)", "$(ECHO) $(PROGRESSINFO)" + label, into=lines) + os.makedirs(self.dir, exist_ok=True) + rule = [] sandbox = join(self.dir, "sandbox") - emit("\t$(hide)", f"rm -rf {sandbox}", into=lines) + emit(f"rm -rf {sandbox}", into=rule) emit( - "\t$(hide)", - "$(PYTHON) build/_sandbox.py --link -s", - sandbox, - f"$(INS_{insn})", - into=lines, + f"{G.PYTHON} build/_sandbox.py --link -s", sandbox, *fins, into=rule ) for c in cmds: - emit(f"\t$(hide) cd {sandbox} && (", c, ")", into=lines) + emit(f"(cd {sandbox} &&", c, ")", into=rule) emit( - "\t$(hide)", - "$(PYTHON) build/_sandbox.py --export -s", + f"{G.PYTHON} build/_sandbox.py --export -s", sandbox, - f"$(OUTS_{outsn})", - into=lines, + *fouts, + into=rule, ) + + ruletext = "".join(rule) + if len(ruletext) > 7000: + rulehash = hashlib.sha1(ruletext.encode()).hexdigest() + + rulef = join(self.dir, f"rule-{rulehash}.sh") + with open(rulef, "wt") as fp: + fp.write("set -e\n") + fp.write(ruletext) + + emit("build", *fouts, ":rule", *fins, rulef) + emit(" command=sh", rulef) + else: + emit("build", *fouts, ":rule", *fins) + emit( + " command=", + "&&".join([s.strip() for s in rule]).replace("$", "$$"), + ) + if label: + emit(" description=", label) + emit("build", name, ":phony", *fouts) + else: assert len(cmds) == 0, "rules with no outputs cannot have commands" - emit(name, ":", *fins, into=lines) + emit("build", name, ":phony", *fins) - outputFp.write("".join(lines)) - - if outs: - emit(f"\t$(hide) touch {hashfile}") emit("") @@ -596,47 +643,65 @@ def export(self, name=None, items: TargetsMap = {}, deps: Targets = []): dest = self.targetof(dest) outs += [dest] - destf = filenameof(dest) + destf = self.templateexpand(filenameof(dest)) + outputTargets.update([destf]) srcs = filenamesof([src]) assert ( len(srcs) == 1 ), "a dependency of an exported file must have exactly one output file" + srcf = self.templateexpand(srcs[0]) subrule = simplerule( name=f"{self.localname}/{destf}", cwd=self.cwd, ins=[srcs[0]], outs=[destf], - commands=["$(CP) -H %s %s" % (srcs[0], destf)], - label="", + commands=["$(CP) -H %s %s" % (srcf, destf)], + label="EXPORT", ) subrule.materialise() self.ins = [] self.outs = deps + outs + outputTargets.add(name) emit("") - emit(".PHONY:", name) - emit(name, ":", *filenamesof(outs + deps)) + emit( + "build", + name, + ":phony", + *[self.templateexpand(f) for f in filenamesof(outs + deps)], + ) def main(): parser = argparse.ArgumentParser() - parser.add_argument("-v", "--verbose", action="store_true") parser.add_argument("-q", "--quiet", action="store_true") - parser.add_argument("-o", "--output") + parser.add_argument("-v", "--varfile") + parser.add_argument("-o", "--outputdir") + parser.add_argument("-D", "--define", action="append", default=[]) parser.add_argument("files", nargs="+") args = parser.parse_args() - global verbose - verbose = args.verbose - global quiet quiet = args.quiet - global outputFp - outputFp = open(args.output, "wt") + vardefs = args.define + if args.varfile: + with open(args.varfile, "rt") as fp: + vardefs = vardefs + list(fp) + + for line in vardefs: + if "=" in line: + name, value = line.split("=", 1) + G.setdefault(name.strip(), value.strip()) + + global ninjaFp, shellFp, outputdir + outputdir = args.outputdir + G.setdefault("OBJ", outputdir) + ninjaFp = open(outputdir + "/build.ninja", "wt") + ninjaFp.write(f"include build/ab.ninja\n") for k in ["Rule"]: defaultGlobals[k] = globals()[k] @@ -651,7 +716,10 @@ def main(): while unmaterialisedTargets: t = next(iter(unmaterialisedTargets)) t.materialise() - emit("AB_LOADED = 1\n") + + with open(outputdir + "/build.targets", "wt") as fp: + fp.write("ninja-targets =") + fp.write(substituteGlobalVariables(" ".join(outputTargets))) main() diff --git a/build/c.py b/build/c.py index 1a07a3e84e..15c08732fc 100644 --- a/build/c.py +++ b/build/c.py @@ -7,23 +7,22 @@ flatten, simplerule, emit, + G, ) -from build.utils import filenamesmatchingof, stripext, collectattrs +from build.utils import stripext, collectattrs from build.toolchain import Toolchain, HostToolchain from os.path import * -emit( - """ -ifeq ($(OSX),no) -STARTGROUP ?= -Wl,--start-group -ENDGROUP ?= -Wl,--end-group -endif -""" -) +if G.OSX != "yes": + G.STARTGROUP = "-Wl,--start-group" + G.ENDGROUP = "-Wl,--end-group" +else: + G.STARTGROUP = "" + G.ENDGROUP = "" Toolchain.CC = ["$(CC) -c -o $[outs[0]] $[ins[0]] $(CFLAGS) $[cflags]"] Toolchain.CPP = ["$(CC) -E -P -o $[outs] $[cflags] -x c $[ins]"] -Toolchain.CXX = ["$(CXX) -c -o $[outs[0]] $[ins[0]] $(CFLAGS) $[cflags]"] +Toolchain.CXX = ["$(CXX) -c -o $[outs[0]] $[ins[0]] $(CXXFLAGS) $[cflags]"] Toolchain.AR = ["$(AR) cqs $[outs[0]] $[ins]"] Toolchain.ARXX = ["$(AR) cqs $[outs[0]] $[ins]"] Toolchain.CLINK = [ @@ -70,13 +69,9 @@ def _toolchain_find_header_targets(deps, initial=[]): Toolchain.find_c_header_targets = _toolchain_find_header_targets -HostToolchain.CC = [ - "$(HOSTCC) -c -o $[outs[0]] $[ins[0]] $(HOSTCFLAGS) $[cflags]" -] +HostToolchain.CC = ["$(HOSTCC) -c -o $[outs[0]] $[ins[0]] $(HOSTCFLAGS) $[cflags]"] HostToolchain.CPP = ["$(HOSTCC) -E -P -o $[outs] $[cflags] -x c $[ins]"] -HostToolchain.CXX = [ - "$(HOSTCXX) -c -o $[outs[0]] $[ins[0]] $(HOSTCFLAGS) $[cflags]" -] +HostToolchain.CXX = ["$(HOSTCXX) -c -o $[outs[0]] $[ins[0]] $(HOSTCFLAGS) $[cflags]"] HostToolchain.AR = ["$(HOSTAR) cqs $[outs[0]] $[ins]"] HostToolchain.ARXX = ["$(HOSTAR) cqs $[outs[0]] $[ins]"] HostToolchain.CLINK = [ @@ -102,9 +97,7 @@ def _indirect(deps, name): return r -def cfileimpl( - self, name, srcs, deps, suffix, commands, label, toolchain, cflags -): +def cfileimpl(self, name, srcs, deps, suffix, commands, label, toolchain, cflags): outleaf = "=" + stripext(basename(filenameof(srcs[0]))) + suffix hdr_deps = toolchain.find_c_header_targets(deps) @@ -114,9 +107,7 @@ def cfileimpl( if ("cheader_deps" not in d.args) and ("clibrary_deps" not in d.args) ] hdr_files = collectattrs(targets=hdr_deps, name="cheader_files") - cflags = collectattrs( - targets=hdr_deps, name="caller_cflags", initial=cflags - ) + cflags = collectattrs(targets=hdr_deps, name="caller_cflags", initial=cflags) t = simplerule( replaces=self, @@ -194,7 +185,7 @@ def findsources(self, srcs, deps, cflags, filerule, toolchain, cwd): for s in flatten(srcs): objs += [ filerule( - name=join(self.localname, _removeprefix(f, "$(OBJ)/")), + name=join(self.localname, _removeprefix(f, G.OBJ + "/")), srcs=[f], deps=deps, cflags=sorted(set(cflags)), @@ -239,9 +230,7 @@ def libraryimpl( i = 0 for dest, src in hdrs.items(): s = filenamesof([src]) - assert ( - len(s) == 1 - ), "the target of a header must return exactly one file" + assert len(s) == 1, "the target of a header must return exactly one file" cs += [f"$(CP) $[ins[{i}]] $[outs[{i}]]"] outs += ["=" + dest] @@ -431,15 +420,11 @@ def programimpl( label, filerule, ): - cfiles = findsources( - self, srcs, deps, cflags, filerule, toolchain, self.cwd - ) + cfiles = findsources(self, srcs, deps, cflags, filerule, toolchain, self.cwd) lib_deps = toolchain.find_c_library_targets(deps) libs = collectattrs(targets=lib_deps, name="clibrary_files") - ldflags = collectattrs( - targets=lib_deps, name="caller_ldflags", initial=ldflags - ) + ldflags = collectattrs(targets=lib_deps, name="caller_ldflags", initial=ldflags) simplerule( replaces=self, @@ -558,9 +543,7 @@ def hostcxxprogram( def _cppfileimpl(self, name, srcs, deps, cflags, toolchain): hdr_deps = _indirect(deps, "cheader_deps") - cflags = collectattrs( - targets=hdr_deps, name="caller_cflags", initial=cflags - ) + cflags = collectattrs(targets=hdr_deps, name="caller_cflags", initial=cflags) simplerule( replaces=self, diff --git a/build/pkg.py b/build/pkg.py index 6103e716d4..e1adec5375 100644 --- a/build/pkg.py +++ b/build/pkg.py @@ -1,4 +1,4 @@ -from build.ab import Rule, Target +from build.ab import Rule, Target, G import os import subprocess @@ -31,8 +31,8 @@ def get_property(self, name, flag): return self.package_properties[p] -TargetPkgConfig = _PkgConfig(os.getenv("PKG_CONFIG")) -HostPkgConfig = _PkgConfig(os.getenv("HOST_PKG_CONFIG")) +TargetPkgConfig = _PkgConfig(G.PKG_CONFIG) +HostPkgConfig = _PkgConfig(G.HOST_PKG_CONFIG) def _package(self, name, package, fallback, pkgconfig): @@ -49,9 +49,7 @@ def _package(self, name, package, fallback, pkgconfig): self.traits.update({"clibrary", "cxxlibrary"}) return - assert ( - fallback - ), f"Required package '{package}' not installed when materialising target '$[name]'" + assert fallback, f"Required package '{package}' not installed" if "cheader_deps" in fallback.args: self.args["cheader_deps"] = fallback.args["cheader_deps"] diff --git a/build/utils.py b/build/utils.py index 53a85e0d1a..e0af591107 100644 --- a/build/utils.py +++ b/build/utils.py @@ -7,10 +7,13 @@ cwdStack, error, simplerule, + G ) from os.path import relpath, splitext, join, basename, isfile from glob import iglob import fnmatch +import subprocess +import shutil def filenamesmatchingof(xs, pattern): @@ -51,6 +54,16 @@ def itemsof(pattern, root=None, cwd=None): return result +def does_command_exist(cmd): + basecmd = cmd.strip().split()[0] + return shutil.which(basecmd) + + +def shell(cmd): + r = subprocess.check_output([G.SHELL, "-c", cmd]) + return r.decode("utf-8").strip() + + @Rule def objectify(self, name, src: Target, symbol): simplerule( diff --git a/build/yacc.py b/build/yacc.py index aad21c7989..e4e5e57bcd 100644 --- a/build/yacc.py +++ b/build/yacc.py @@ -1,11 +1,7 @@ -from build.ab import simplerule, Rule, Target, Targets, emit +from build.ab import simplerule, Rule, Target, Targets, emit, G -emit( - """ -BISON ?= bison -FLEX ?= flex -""" -) +G.setdefault("BISON", "bison") +G.setdefault("FLEX", "flex") @Rule @@ -17,9 +13,7 @@ def bison(self, name, src: Target, deps: Targets = [], stem=None): ins=[src], outs=[f"={stem}.c", f"={stem}.h"], deps=deps, - commands=[ - "$(BISON) --defines=$[outs[1]] --output=$[outs[0]] $[ins[0]]" - ], + commands=["$(BISON) --defines=$[outs[1]] --output=$[outs[0]] $[ins[0]]"], label="BISON", ) diff --git a/examples/dhry.h b/examples/dhry.h index 0651f063a2..dcb42ec4ca 100644 --- a/examples/dhry.h +++ b/examples/dhry.h @@ -348,6 +348,7 @@ #include /* for exit */ #include +#include #include /* for strcpy, strcmp */ @@ -419,8 +420,6 @@ typedef float measure; #define Null 0 /* Value of a Null pointer */ -#define true 1 -#define false 0 typedef int One_Thirty; typedef int One_Fifty; diff --git a/examples/startrek.c b/examples/startrek.c index 6f7ffb3a53..7fb07344ea 100644 --- a/examples/startrek.c +++ b/examples/startrek.c @@ -70,19 +70,12 @@ #else #include #endif +#include #include #include #include #include -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE ! FALSE -#endif - /* Standard Line Length */ #define MAXLEN 255 @@ -98,7 +91,6 @@ /* Useful typedefs */ -typedef int bool; typedef char line[MAXCOL]; typedef char string[MAXLEN]; @@ -222,7 +214,7 @@ string sG2; /* Used to pass string results */ #ifndef SMALL FILE *stream; -bool bFlag = FALSE; /* Prevent multiple file opens */ +bool bFlag = false; /* Prevent multiple file opens */ #endif void @@ -1944,7 +1936,7 @@ openfile(char * sFilename, char * sMode) return 1; } - bFlag = TRUE; + bFlag = true; return 0; } @@ -1955,7 +1947,7 @@ closefile(void) if (! bFlag) fclose(stream); - bFlag = FALSE; + bFlag = false; } int diff --git a/lang/basic/src/basic.g b/lang/basic/src/basic.g index e79e8fc308..249517dd10 100644 --- a/lang/basic/src/basic.g +++ b/lang/basic/src/basic.g @@ -89,6 +89,7 @@ #define YYDEBUG #include #include +#include #include "bem.h" #include "util.h" #include "gencode.h" diff --git a/lang/basic/src/basic.lex b/lang/basic/src/basic.lex index 53b7b57d24..af8c257f67 100644 --- a/lang/basic/src/basic.lex +++ b/lang/basic/src/basic.lex @@ -238,7 +238,7 @@ int getinputline(void) /* get next input line */ if ( our_fgets(inputline,MAXLINELENGTH,yyin) == 0) - return(FALSE); + return(false); yylineno ++; if ( strchr(inputline,'\n') == 0) error("source line too long"); @@ -246,7 +246,7 @@ int getinputline(void) if ( listing) fprintf(stderr, inputline); cptr= inputline; - return(TRUE); + return(true); } diff --git a/lang/basic/src/symbols.h b/lang/basic/src/symbols.h index c0c0b615df..f8d40e690b 100644 --- a/lang/basic/src/symbols.h +++ b/lang/basic/src/symbols.h @@ -11,8 +11,6 @@ #endif #define NIL 0 -#define TRUE 1 -#define FALSE 0 #define DEFAULTTYPE 500 #define INTTYPE 501 diff --git a/lang/cem/cemcom.ansi/LLlex.c b/lang/cem/cemcom.ansi/LLlex.c index 177a56e960..a21a94a7e5 100644 --- a/lang/cem/cemcom.ansi/LLlex.c +++ b/lang/cem/cemcom.ansi/LLlex.c @@ -5,6 +5,8 @@ /* $Id$ */ /* L E X I C A L A N A L Y Z E R */ +#include +#include #include #include #include @@ -19,7 +21,7 @@ #include "Lpars.h" #include "class.h" #include "sizes.h" -#include "type.h" /* no_long_long() */ +#include "type.h" /* no_long_long() */ #include "error.h" #include "domacro.h" #include "specials.h" /* registration of special identifiers */ @@ -38,21 +40,20 @@ int File_Inserted = 0; /* a file has just been inserted */ int LexSave = 0; /* last character read by GetChar */ #define MAX_LL_DEPTH 2 -#define FLG_ESEEN 0x01 /* possibly a floating point number */ +#define FLG_ESEEN 0x01 /* possibly a floating point number */ #define FLG_DOTSEEN 0x02 /* certainly a floating point number */ #ifdef LINT extern int lint_skip_comment; #endif - /* Internal function declarations */ static arith char_constant(char*); -static char* string_token(char *, int , int *); +static char* string_token(char*, int, int*); static int quoted(int); static int hex_val(int); -static void strflt2tok(char [], struct token *); -static void strint2tok(char [], struct token *); +static void strflt2tok(char[], struct token*); +static void strint2tok(char[], struct token*); int LLlex(void) { @@ -85,7 +86,6 @@ int LLlex(void) return DOT; } - int GetToken(struct token* ptok) { /* GetToken() is the actual token recognizer. It calls the @@ -128,8 +128,7 @@ int GetToken(struct token* ptok) */ return ptok->tk_symb = EOI; - while ((ch = GetChar()), (ch == '#' - || class(ch) == STSKIP)) + while ((ch = GetChar()), (ch == '#' || class(ch) == STSKIP)) { /* blanks are allowed before hashes */ if (ch == '#') @@ -292,8 +291,7 @@ int GetToken(struct token* ptok) idef->id_file = ptok->tk_file; idef->id_line = ptok->tk_line; ptok->tk_symb - = (idef->id_reserved - ? idef->id_reserved + = (idef->id_reserved ? idef->id_reserved : idef->id_def && idef->id_def->df_sc == TYPEDEF ? TYPE_IDENTIFIER : IDENTIFIER); return IDENTIFIER; @@ -424,7 +422,7 @@ static arith char_constant(char* nm) return val; } -static char* string_token(char *nm, int stop_char, int *plen) +static char* string_token(char* nm, int stop_char, int* plen) { int ch; int str_size; @@ -686,7 +684,7 @@ static void strint2tok(char intbuf[], struct token* ptok) and long, then C89 tries unsigned long, but C99 tries long long (WG14, Rationale for C99, C99RationaleV5.10.pdf, 6.4.4.1 Integer constants). - This compiler follows C89 when the literal has no + This compiler follows C89 when the literal has no long long suffix. */ cut = 0; @@ -727,8 +725,7 @@ static void strint2tok(char intbuf[], struct token* ptok) fund = ERRONEOUS; else { - assert(sizeof(val) > long_size || - (lnglng_size >= 0 && sizeof(val) > lnglng_size)); + assert(sizeof(val) > long_size || (lnglng_size >= 0 && sizeof(val) > lnglng_size)); lexwarning("constant too large for target machine"); cut = 1; } diff --git a/lang/cem/cemcom.ansi/LLlex.h b/lang/cem/cemcom.ansi/LLlex.h index 7c9102b3e8..c3204d5e28 100644 --- a/lang/cem/cemcom.ansi/LLlex.h +++ b/lang/cem/cemcom.ansi/LLlex.h @@ -6,8 +6,8 @@ /* D E F I N I T I O N S F O R T H E L E X I C A L A N A L Y Z E R */ /* A token from the input stream is represented by an integer, - called a "symbol", but it may have other information associated - to it. + called a "symbol", but it may have other information associated + to it. */ #ifndef LLLEX_H_ #define LLLEX_H_ @@ -15,49 +15,52 @@ #include "file_info.h" /* the structure of a token: */ -struct token { - int tok_symb; /* the token itself */ - char *tok_file; /* the file it (probably) comes from */ - unsigned int tok_line; /* the line it (probably) comes from */ +struct token +{ + int tok_symb; /* the token itself */ + char* tok_file; /* the file it (probably) comes from */ + unsigned int tok_line; /* the line it (probably) comes from */ int tok_fund; - union { - struct idf *tok_idf; /* for IDENTIFIER & TYPE_IDENTIFIER */ - struct { /* for STRING */ - char *tok_bts; /* row of bytes */ - int tok_len; /* length of row of bytes */ + union + { + struct idf* tok_idf; /* for IDENTIFIER & TYPE_IDENTIFIER */ + struct + { /* for STRING */ + char* tok_bts; /* row of bytes */ + int tok_len; /* length of row of bytes */ } tok_string; - writh tok_ival; /* for INTEGER */ - char *tok_fval; /* for FLOATING */ + writh tok_ival; /* for INTEGER */ + char* tok_fval; /* for FLOATING */ } tok_data; }; -#define tk_symb tok_symb -#define tk_file tok_file -#define tk_line tok_line -#define tk_fund tok_fund -#define tk_idf tok_data.tok_idf -#define tk_bts tok_data.tok_string.tok_bts -#define tk_len tok_data.tok_string.tok_len -#define tk_ival tok_data.tok_ival -#define tk_fval tok_data.tok_fval +#define tk_symb tok_symb +#define tk_file tok_file +#define tk_line tok_line +#define tk_fund tok_fund +#define tk_idf tok_data.tok_idf +#define tk_bts tok_data.tok_string.tok_bts +#define tk_len tok_data.tok_string.tok_len +#define tk_ival tok_data.tok_ival +#define tk_fval tok_data.tok_fval extern struct token dot, ahead, aside; -extern int token_nmb; /* number of the ahead token */ -extern int tk_nmb_at_last_syn_err; /* token number at last syntax error */ +extern int token_nmb; /* number of the ahead token */ +extern int tk_nmb_at_last_syn_err; /* token number at last syntax error */ -extern int EoiForNewline; /* "LLlex.c" */ -extern int AccFileSpecifier; /* "LLlex.c" */ -extern int File_Inserted; /* "LLlex.c" */ +extern int EoiForNewline; /* "LLlex.c" */ +extern int AccFileSpecifier; /* "LLlex.c" */ +extern int File_Inserted; /* "LLlex.c" */ -extern int NoUnstack; /* buffer.c */ +extern int NoUnstack; /* buffer.c */ -extern int err_occurred; /* "error.c" */ +extern int err_occurred; /* "error.c" */ -#define DOT dot.tk_symb -#define AHEAD ahead.tk_symb -#define ASIDE aside.tk_symb +#define DOT dot.tk_symb +#define AHEAD ahead.tk_symb +#define ASIDE aside.tk_symb -#define EOF (-1) +#define EOF (-1) extern int GetChar(void); extern int LLlex(void); diff --git a/lang/cem/cemcom.ansi/LLmessage.c b/lang/cem/cemcom.ansi/LLmessage.c index 94ff745717..3e1105917a 100644 --- a/lang/cem/cemcom.ansi/LLmessage.c +++ b/lang/cem/cemcom.ansi/LLmessage.c @@ -5,17 +5,17 @@ /* $Id$ */ /* PARSER ERROR ADMINISTRATION */ -#include -#include -#include "idf.h" -#include "arith.h" -#include "LLlex.h" -#include "Lpars.h" -#include "error.h" +#include +#include +#include +#include +#include "idf.h" +#include "arith.h" +#include "LLlex.h" +#include "Lpars.h" +#include "error.h" - - -static void insert_token(int ); +static void insert_token(int); void LLmessage(int tk) { @@ -50,23 +50,23 @@ static void insert_token(int tk) switch (tk) { - /* The operands need some body */ - case IDENTIFIER: - dot.tk_idf = gen_idf(); - break; - case TYPE_IDENTIFIER: - dot.tk_idf = str2idf("int", 0); - break; - case STRING: - dot.tk_bts = strdup(""); - dot.tk_len = 1; - break; - case INTEGER: - dot.tk_fund = INT; - dot.tk_ival = 1; - break; - case FLOATING: - dot.tk_fval = strdup("0.0"); - break; + /* The operands need some body */ + case IDENTIFIER: + dot.tk_idf = gen_idf(); + break; + case TYPE_IDENTIFIER: + dot.tk_idf = str2idf("int", 0); + break; + case STRING: + dot.tk_bts = strdup(""); + dot.tk_len = 1; + break; + case INTEGER: + dot.tk_fund = INT; + dot.tk_ival = 1; + break; + case FLOATING: + dot.tk_fval = strdup("0.0"); + break; } } diff --git a/lang/cem/cemcom.ansi/align.h b/lang/cem/cemcom.ansi/align.h index 09f58fbcda..ff037efed7 100644 --- a/lang/cem/cemcom.ansi/align.h +++ b/lang/cem/cemcom.ansi/align.h @@ -8,24 +8,20 @@ #include "parameters.h" #ifndef NOCROSS -extern int - short_align, word_align, int_align, long_align, - lnglng_align, - float_align, double_align, lngdbl_align, - pointer_align, - struct_align, union_align; +extern int short_align, word_align, int_align, long_align, lnglng_align, float_align, double_align, + lngdbl_align, pointer_align, struct_align, union_align; #else /* NOCROSS */ -#define short_align ((int)AL_SHORT) -#define word_align ((int)AL_WORD) -#define int_align ((int)AL_INT) -#define long_align ((int)AL_LONG) -#define lnglng_align ((int)AL_LNGLNG) -#define float_align ((int)AL_FLOAT) -#define double_align ((int)AL_DOUBLE) -#define lngdbl_align ((int)AL_LNGDBL) -#define pointer_align ((int)AL_POINTER) -#define struct_align ((int)AL_STRUCT) -#define union_align ((int)AL_UNION) +#define short_align ((int)AL_SHORT) +#define word_align ((int)AL_WORD) +#define int_align ((int)AL_INT) +#define long_align ((int)AL_LONG) +#define lnglng_align ((int)AL_LNGLNG) +#define float_align ((int)AL_FLOAT) +#define double_align ((int)AL_DOUBLE) +#define lngdbl_align ((int)AL_LNGDBL) +#define pointer_align ((int)AL_POINTER) +#define struct_align ((int)AL_STRUCT) +#define union_align ((int)AL_UNION) #endif /* NOCROSS */ extern arith align(arith pos, int al); diff --git a/lang/cem/cemcom.ansi/arith.c b/lang/cem/cemcom.ansi/arith.c index 8016abfc11..36b8012b72 100644 --- a/lang/cem/cemcom.ansi/arith.c +++ b/lang/cem/cemcom.ansi/arith.c @@ -6,63 +6,59 @@ /* A R I T H M E T I C C O N V E R S I O N S */ /* This file contains the routines for the various conversions that - may befall operands in C. It is structurally a mess, but I haven't - decided yet whether I can't find the right structure or the - semantics of C is a mess. + may befall operands in C. It is structurally a mess, but I haven't + decided yet whether I can't find the right structure or the + semantics of C is a mess. */ -#include -#include -#include "parameters.h" -#include -#include -#include "arith.h" -#include "sizes.h" -#include "type.h" -#include "proto.h" -#include "label.h" -#include "expr.h" -#include "Lpars.h" -#include "LLlex.h" -#include "field.h" -#include "mes.h" -#include "cstoper.h" -#include "ch3bin.h" -#include "ch3.h" -#include "error.h" - - +#include +#include +#include +#include "parameters.h" +#include +#include +#include "arith.h" +#include "sizes.h" +#include "type.h" +#include "proto.h" +#include "label.h" +#include "expr.h" +#include "Lpars.h" +#include "LLlex.h" +#include "field.h" +#include "mes.h" +#include "cstoper.h" +#include "ch3bin.h" +#include "ch3.h" +#include "error.h" extern char options[]; /* 3.1.2.5 */ -void arithbalance(struct expr **e1p, int oper, struct expr **e2p) +void arithbalance(struct expr** e1p, int oper, struct expr** e2p) { /* The expressions *e1p and *e2p are balanced to be operands - of the arithmetic operator oper. - We check here if the EX_PTRDIFF flag should be retained. - They are set to zero in because one of the opreands might - have a floating type, in which case the flags shouldn't - travel upward in the expression tree. + of the arithmetic operator oper. + We check here if the EX_PTRDIFF flag should be retained. + They are set to zero in because one of the opreands might + have a floating type, in which case the flags shouldn't + travel upward in the expression tree. */ struct type *convert1, *convert2; int t1, t2, u1, u2; - int shifting = (oper == LEFT || oper == RIGHT - || oper == LEFTAB || oper == RIGHTAB); + int shifting = (oper == LEFT || oper == RIGHT || oper == LEFTAB || oper == RIGHTAB); int ptrdiff = 0; t1 = any2arith(e1p, oper); t2 = any2arith(e2p, oper); - if (int_size != pointer_size) { - if (ptrdiff = ((*e1p)->ex_flags & EX_PTRDIFF) - || ((*e2p)->ex_flags & EX_PTRDIFF)) { - if (!((*e1p)->ex_flags & EX_PTRDIFF) - && (t1 == LONG || t1 == LNGLNG)) + if (int_size != pointer_size) + { + if (ptrdiff = ((*e1p)->ex_flags & EX_PTRDIFF) || ((*e2p)->ex_flags & EX_PTRDIFF)) + { + if (!((*e1p)->ex_flags & EX_PTRDIFF) && (t1 == LONG || t1 == LNGLNG)) ptrdiff = 0; - if (!((*e2p)->ex_flags & EX_PTRDIFF) - && (t2 == LONG || t2 == LNGLNG) - && !shifting) + if (!((*e2p)->ex_flags & EX_PTRDIFF) && (t2 == LONG || t2 == LNGLNG) && !shifting) ptrdiff = 0; } /* Now turn off ptrdiff flags */ @@ -71,41 +67,49 @@ void arithbalance(struct expr **e1p, int oper, struct expr **e2p) } /* Now t1 and t2 are either INT, LONG, LNGLNG, - FLOAT, DOUBLE, or LNGDBL + FLOAT, DOUBLE, or LNGDBL */ /* If any operand has the type long double, the other operand - is converted to long double. + is converted to long double. */ /* ??? t1 == LNGDBL, t2 == DOUBLE */ - if (t1 == LNGDBL) { - if (t2 != LNGDBL) { - if (t2 == DOUBLE || t2 == FLOAT) - float2float(e2p, lngdbl_type); - else - int2float(e2p, lngdbl_type); + if (t1 == LNGDBL) + { + if (t2 != LNGDBL) + { + if (t2 == DOUBLE || t2 == FLOAT) + float2float(e2p, lngdbl_type); + else + int2float(e2p, lngdbl_type); } return; - } else if (t2 == LNGDBL) { - if (t1 != LNGDBL) { - if (t1 == DOUBLE || t1 == FLOAT) - float2float(e1p, lngdbl_type); - else - int2float(e1p, lngdbl_type); + } + else if (t2 == LNGDBL) + { + if (t1 != LNGDBL) + { + if (t1 == DOUBLE || t1 == FLOAT) + float2float(e1p, lngdbl_type); + else + int2float(e1p, lngdbl_type); } return; } /* If any operand has the type double, the other operand - is converted to double. + is converted to double. */ - if (t1 == DOUBLE) { + if (t1 == DOUBLE) + { if (t2 == FLOAT) float2float(e2p, double_type); else if (t2 != DOUBLE) int2float(e2p, double_type); return; - } else if (t2 == DOUBLE) { + } + else if (t2 == DOUBLE) + { if (t1 == FLOAT) float2float(e1p, double_type); else if (t1 != DOUBLE) @@ -114,13 +118,16 @@ void arithbalance(struct expr **e1p, int oper, struct expr **e2p) } /* If any operand has the type float, the other operand - is converted to float. + is converted to float. */ - if (t1 == FLOAT) { + if (t1 == FLOAT) + { if (t2 != FLOAT) int2float(e2p, float_type); return; - } else if (t2 == FLOAT) { + } + else if (t2 == FLOAT) + { if (t1 != FLOAT) int2float(e1p, float_type); return; @@ -133,34 +140,40 @@ void arithbalance(struct expr **e1p, int oper, struct expr **e2p) convert2 = NULL; /* If either operand is a long long, the other operand - is converted to long long; else if either operand is - a long, the other operand is converted to a long. - - If one operand is signed and the other operand is - unsigned, if the signed type can represent all values - of the unsigned type, the unsigned operand is - converted to the signed type, else both operands are - converted to an unsigned type. + is converted to long long; else if either operand is + a long, the other operand is converted to a long. + + If one operand is signed and the other operand is + unsigned, if the signed type can represent all values + of the unsigned type, the unsigned operand is + converted to the signed type, else both operands are + converted to an unsigned type. */ - if (shifting) { + if (shifting) + { /* In shifts like o1 << o2, never convert o1, - and let ch3bin() convert o2 to int. + and let ch3bin() convert o2 to int. */ - } else if (t1 == LNGLNG && u1 && (t2 != LNGLNG || !u2)) + } + else if (t1 == LNGLNG && u1 && (t2 != LNGLNG || !u2)) convert2 = ulnglng_type; else if (t2 == LNGLNG && u2 && (t1 != LNGLNG || !u1)) convert1 = ulnglng_type; - else if (t1 == LNGLNG && t2 != LNGLNG && u2) { + else if (t1 == LNGLNG && t2 != LNGLNG && u2) + { if ((t2 == LONG ? long_size : int_size) < lnglng_size) convert2 = lnglng_type; else convert1 = convert2 = ulnglng_type; - } else if (t2 == LNGLNG && t1 != LNGLNG && u1) { + } + else if (t2 == LNGLNG && t1 != LNGLNG && u1) + { if ((t1 == LONG ? long_size : int_size) < lnglng_size) convert1 = lnglng_type; else convert1 = convert2 = ulnglng_type; - } else if (t1 == LNGLNG && t2 != LNGLNG) + } + else if (t1 == LNGLNG && t2 != LNGLNG) convert2 = lnglng_type; else if (t2 == LNGLNG && t1 != LNGLNG) convert1 = lnglng_type; @@ -168,17 +181,21 @@ void arithbalance(struct expr **e1p, int oper, struct expr **e2p) convert2 = ulong_type; else if (t2 == LONG && u2 && (t1 != LONG || !u1)) convert1 = ulong_type; - else if (t1 == LONG && t2 == INT && u2) { + else if (t1 == LONG && t2 == INT && u2) + { if (int_size < long_size) convert2 = long_type; else convert1 = convert2 = ulong_type; - } else if (t2 == LONG && t1 == INT && u1) { + } + else if (t2 == LONG && t1 == INT && u1) + { if (int_size < long_size) convert1 = long_type; else convert1 = convert2 = ulong_type; - } else if (t1 == LONG && t2 != LONG) + } + else if (t1 == LONG && t2 != LONG) convert2 = long_type; else if (t2 == LONG && t1 != LONG) convert1 = long_type; @@ -192,38 +209,38 @@ void arithbalance(struct expr **e1p, int oper, struct expr **e2p) u2 = (*e2p)->ex_type->tp_unsigned; /* If either operand has type unsigned int, the other operand - is converted to unsigned int. - Otherwise, both operands have type int. + is converted to unsigned int. + Otherwise, both operands have type int. */ if (u1 && !u2 && !shifting) t2 = int2int(e2p, uint_type); - else - if (!u1 && u2 && !shifting) + else if (!u1 && u2 && !shifting) t1 = int2int(e1p, uint_type); - if (int_size != pointer_size) { - if (ptrdiff) { + if (int_size != pointer_size) + { + if (ptrdiff) + { (*e1p)->ex_flags |= EX_PTRDIFF; (*e2p)->ex_flags |= EX_PTRDIFF; } } } -void relbalance(struct expr **e1p, int oper, struct expr **e2p) +void relbalance(struct expr** e1p, int oper, struct expr** e2p) { /* The expressions *e1p and *e2p are balanced to be operands - of the relational operator oper, or the ':'. - Care is taken to switch the operands in case of a - null-pointer constant. This is done so that ch3cast() - allows assignments of a null-pointer to a function - pointer. + of the relational operator oper, or the ':'. + Care is taken to switch the operands in case of a + null-pointer constant. This is done so that ch3cast() + allows assignments of a null-pointer to a function + pointer. */ struct expr *e1 = *e1p, *e2 = *e2p; - struct expr *tmpexpr; + struct expr* tmpexpr; - if (e1->ex_type->tp_fund == POINTER - && is_cp_cst(e1) - && e1->VL_VALUE == 0) { + if (e1->ex_type->tp_fund == POINTER && is_cp_cst(e1) && e1->VL_VALUE == 0) + { tmpexpr = e1; e1 = e2; e2 = tmpexpr; @@ -232,124 +249,128 @@ void relbalance(struct expr **e1p, int oper, struct expr **e2p) ch3pointer(e2p, oper, e1->ex_type); else if (e2->ex_type->tp_fund == POINTER) ch3pointer(e1p, oper, e2->ex_type); - else if (e1->ex_type == e2->ex_type - && e1->ex_type->tp_fund == ENUM) {} - else if (oper == ':' - && e1->ex_type->tp_fund == VOID - && e2->ex_type->tp_fund == VOID) {} + else if (e1->ex_type == e2->ex_type && e1->ex_type->tp_fund == ENUM) + { + } + else if (oper == ':' && e1->ex_type->tp_fund == VOID && e2->ex_type->tp_fund == VOID) + { + } else arithbalance(e1p, oper, e2p); } -void ch3pointer(struct expr **expp, int oper, struct type *tp) +void ch3pointer(struct expr** expp, int oper, struct type* tp) { /* Checks whether *expp may be compared to tp using oper, - as described in chapter 3.3.8 and 3.3.9. - tp is known to be a pointer. + as described in chapter 3.3.8 and 3.3.9. + tp is known to be a pointer. */ - struct expr *exp = *expp; + struct expr* exp = *expp; - if (exp->ex_type->tp_fund == POINTER) { + if (exp->ex_type->tp_fund == POINTER) + { if (exp->ex_type != tp) ch3cast(expp, oper, tp); } - else - if (is_integral_type(exp->ex_type)) { + else if (is_integral_type(exp->ex_type)) + { if ((oper != EQUAL && oper != NOTEQUAL && oper != ':') - || !(is_cp_cst(exp) && exp->VL_VALUE == 0)) { - expr_error(exp,"%s on %s and pointer", - symbol2str(oper), - symbol2str(exp->ex_type->tp_fund)); + || !(is_cp_cst(exp) && exp->VL_VALUE == 0)) + { + expr_error( + exp, "%s on %s and pointer", symbol2str(oper), symbol2str(exp->ex_type->tp_fund)); } ch3cast(expp, CAST, tp); } - else { - expr_error(exp, "%s on %s and pointer", - symbol2str(oper), - symbol2str(exp->ex_type->tp_fund) - ); + else + { + expr_error( + exp, "%s on %s and pointer", symbol2str(oper), symbol2str(exp->ex_type->tp_fund)); ch3cast(expp, oper, tp); } } -int -any2arith(struct expr **expp, int oper) +int any2arith(struct expr** expp, int oper) { /* Turns any expression into int_type, long_type, - float_type, double_type or lngdbl_type. + float_type, double_type or lngdbl_type. */ int fund; - switch (fund = (*expp)->ex_type->tp_fund) { - case CHAR: - case SHORT: - assert((*expp)->ex_type->tp_size <= int_type->tp_size); + switch (fund = (*expp)->ex_type->tp_fund) + { + case CHAR: + case SHORT: + assert((*expp)->ex_type->tp_size <= int_type->tp_size); - if ((*expp)->ex_type->tp_unsigned - && (*expp)->ex_type->tp_size == int_type->tp_size) { - int2int(expp, uint_type); - } else { + if ((*expp)->ex_type->tp_unsigned && (*expp)->ex_type->tp_size == int_type->tp_size) + { + int2int(expp, uint_type); + } + else + { + int2int(expp, int_type); + } + break; + case INT: + case LONG: + case LNGLNG: + break; + case ENUM: +#ifndef LINT + /* we do not want this conversion for lint, since we + want to keep enums and ints separate + */ int2int(expp, int_type); - } - break; - case INT: - case LONG: - case LNGLNG: - break; - case ENUM: -#ifndef LINT - /* we do not want this conversion for lint, since we - want to keep enums and ints separate - */ - int2int(expp, int_type); -#endif /* LINT */ - break; - case FLOAT: -/* only when it is a parameter and the default promotion should - occur. Hence this code is moved to any2parameter(). - float2float(expp, double_type); - break; -*/ - case DOUBLE: - case LNGDBL: - break; +#endif /* LINT */ + break; + case FLOAT: + /* only when it is a parameter and the default promotion should + occur. Hence this code is moved to any2parameter(). + float2float(expp, double_type); + break; + */ + case DOUBLE: + case LNGDBL: + break; #ifndef NOBITFIELD - case FIELD: - field2arith(expp); - break; + case FIELD: + field2arith(expp); + break; #endif /* NOBITFIELD */ - default: - expr_error(*expp, "operator %s on non-numerical operand (%s)", - symbol2str(oper), symbol2str(fund)); - case ERRONEOUS: - erroneous2int(expp); - break; + default: + expr_error( + *expp, "operator %s on non-numerical operand (%s)", symbol2str(oper), + symbol2str(fund)); + case ERRONEOUS: + erroneous2int(expp); + break; } return (*expp)->ex_type->tp_fund; } -void erroneous2int(struct expr **expp) +void erroneous2int(struct expr** expp) { /* the (erroneous) expression *expp is replaced by an - int expression + int expression */ - struct expr *exp = *expp; + struct expr* exp = *expp; int flags = exp->ex_flags; - + free_expression(exp); exp = intexpr((arith)0, INT); exp->ex_flags = (flags | EX_ERROR); *expp = exp; } -struct expr *arith2arith(struct type *tp, int oper, struct expr *expr) +struct expr* arith2arith(struct type* tp, int oper, struct expr* expr) { /* arith2arith constructs a new expression containing a - run-time conversion between some arithmetic types. + run-time conversion between some arithmetic types. */ - struct expr *new = new_expr(); - + struct expr* new = new_expr(); + new->ex_file = expr->ex_file; new->ex_line = expr->ex_line; new->ex_type = tp; @@ -357,34 +378,36 @@ struct expr *arith2arith(struct type *tp, int oper, struct expr *expr) return new_oper(tp, new, oper, expr); } -int int2int(struct expr **expp, struct type *tp) +int int2int(struct expr** expp, struct type* tp) { /* The expression *expp, which is of some integral type, is - converted to the integral type tp. + converted to the integral type tp. */ - struct expr *exp = *expp; - - if (is_cp_cst(exp)) { - struct type *tp1 = exp->ex_type; + struct expr* exp = *expp; + + if (is_cp_cst(exp)) + { + struct type* tp1 = exp->ex_type; exp->ex_type = tp; - if (! tp1->tp_unsigned && tp->tp_unsigned) { + if (!tp1->tp_unsigned && tp->tp_unsigned) + { /* Avoid "unreal" overflow warnings, such as - caused by f.i.: - unsigned int x = ~0; - unsigned int y = -1; + caused by f.i.: + unsigned int x = ~0; + unsigned int y = -1; */ - writh remainder = exp->VL_VALUE & - ~full_mask[(int)(tp->tp_size)]; + writh remainder = exp->VL_VALUE & ~full_mask[(int)(tp->tp_size)]; - if (remainder == 0 || - remainder == ~full_mask[(int)(tp->tp_size)]) { + if (remainder == 0 || remainder == ~full_mask[(int)(tp->tp_size)]) + { exp->VL_VALUE &= ~remainder; } } cut_size(exp); } - else { + else + { exp = arith2arith(tp, INT2INT, exp); } *expp = exp; @@ -404,33 +427,36 @@ static int fit4(writh val, int uns) /* With compile-time constants, we don't set fp_used, since this is done * only when necessary in eval.c. */ -void int2float(struct expr **expp, struct type *tp) +void int2float(struct expr** expp, struct type* tp) { /* The expression *expp, which is of some integral type, is - converted to the floating type tp. + converted to the floating type tp. */ - struct expr *exp = *expp; + struct expr* exp = *expp; int uns = exp->ex_type->tp_unsigned; - - if (is_cp_cst(exp) && fit4(exp->VL_VALUE, uns)) { + + if (is_cp_cst(exp) && fit4(exp->VL_VALUE, uns)) + { exp->ex_type = tp; exp->ex_class = Float; flt_arith2flt((arith)exp->VL_VALUE, &(exp->FL_ARITH), uns); } - else { + else + { fp_used = 1; *expp = arith2arith(tp, INT2FLOAT, *expp); } } -void float2int(struct expr **expp, struct type *tp) +void float2int(struct expr** expp, struct type* tp) { /* The expression *expp, which is of some floating type, is - converted to the integral type tp. + converted to the integral type tp. */ - struct expr *ex = *expp; + struct expr* ex = *expp; - if (is_fp_cst(ex)) { + if (is_fp_cst(ex)) + { arith ar = flt_flt2arith(&ex->FL_ARITH, tp->tp_unsigned); #ifdef NOTDEF /* Historically, we always did the conversion at @@ -438,15 +464,15 @@ void float2int(struct expr **expp, struct type *tp) too narrow for an 8-byte integer. */ if (flt_status == FLT_OVFL) - expr_warning(ex,"overflow in float to int conversion"); + expr_warning(ex, "overflow in float to int conversion"); else if (flt_status == FLT_UNFL) - expr_warning(ex,"underflow in float to unsigned conversion"); + expr_warning(ex, "underflow in float to unsigned conversion"); #endif /* NOTDEF */ /* Now, we defer the conversion until run time unless it fits in 4 bytes. */ - if (flt_status != FLT_OVFL && flt_status != FLT_UNFL && - fit4((writh)ar, tp->tp_unsigned)) { + if (flt_status != FLT_OVFL && flt_status != FLT_UNFL && fit4((writh)ar, tp->tp_unsigned)) + { ex->ex_type = tp; /* The following lines are copied from fill_int_expr */ ex->ex_class = Value; @@ -460,45 +486,44 @@ void float2int(struct expr **expp, struct type *tp) *expp = arith2arith(tp, FLOAT2INT, ex); } -void float2float(struct expr **expp, struct type *tp) +void float2float(struct expr** expp, struct type* tp) { /* The expression *expp, which is of some floating type, is - converted to the floating type tp. - There is no need for an explicit conversion operator - if the expression is a constant. + converted to the floating type tp. + There is no need for an explicit conversion operator + if the expression is a constant. */ - + if (is_fp_cst(*expp)) (*expp)->ex_type = tp; - else { + else + { fp_used = 1; *expp = arith2arith(tp, FLOAT2FLOAT, *expp); } } -void array2pointer(struct expr *exp) +void array2pointer(struct expr* exp) { /* The expression, which must be an array, is converted - to a pointer. + to a pointer. */ - exp->ex_type = construct_type(POINTER, exp->ex_type->tp_up - , /* exp->ex_type->tp_typequal */ 0 - , (arith)0, NO_PROTO); + exp->ex_type = construct_type( + POINTER, exp->ex_type->tp_up, /* exp->ex_type->tp_typequal */ 0, (arith)0, NO_PROTO); } -void function2pointer(struct expr *exp) +void function2pointer(struct expr* exp) { /* The expression, which must be a function, is converted - to a pointer to the function. + to a pointer to the function. */ - exp->ex_type = construct_type(POINTER, exp->ex_type, 0, - (arith)0, NO_PROTO); + exp->ex_type = construct_type(POINTER, exp->ex_type, 0, (arith)0, NO_PROTO); } -void string2pointer(struct expr *ex) +void string2pointer(struct expr* ex) { /* The expression, which must be a string constant, is converted - to a pointer to the string-containing area. + to a pointer to the string-containing area. */ label lbl; @@ -509,148 +534,150 @@ void string2pointer(struct expr *ex) ex->VL_VALUE = (arith)0; } -void opnd2integral(struct expr **expp, int oper) +void opnd2integral(struct expr** expp, int oper) { int fund = (*expp)->ex_type->tp_fund; - if (fund != INT && fund != LONG && fund != LNGLNG) { - expr_error(*expp, "%s operand to %s", - symbol2str(fund), symbol2str(oper)); + if (fund != INT && fund != LONG && fund != LNGLNG) + { + expr_error(*expp, "%s operand to %s", symbol2str(fund), symbol2str(oper)); erroneous2int(expp); /* fund = INT; */ } } -void opnd2logical(struct expr **expp, int oper) +void opnd2logical(struct expr** expp, int oper) { int fund = (*expp)->ex_type->tp_fund; - if (fund == FUNCTION || fund == ARRAY) { - expr_warning(*expp, "%s operand to %s", - symbol2str(fund), - symbol2str(oper)); - if (fund == FUNCTION) function2pointer(*expp); - else array2pointer(*expp); + if (fund == FUNCTION || fund == ARRAY) + { + expr_warning(*expp, "%s operand to %s", symbol2str(fund), symbol2str(oper)); + if (fund == FUNCTION) + function2pointer(*expp); + else + array2pointer(*expp); } #ifndef NOBITFIELD - else - if (fund == FIELD) + else if (fund == FIELD) field2arith(expp); #endif /* NOBITFIELD */ - switch (fund = (*expp)->ex_type->tp_fund) { - case CHAR: - case SHORT: - case INT: - case LONG: - case LNGLNG: - case ENUM: - case POINTER: - case FLOAT: - case DOUBLE: - case LNGDBL: - break; - default: - expr_error(*expp, "%s operand to %s", - symbol2str(fund), symbol2str(oper)); - case ERRONEOUS: - erroneous2int(expp); - break; + switch (fund = (*expp)->ex_type->tp_fund) + { + case CHAR: + case SHORT: + case INT: + case LONG: + case LNGLNG: + case ENUM: + case POINTER: + case FLOAT: + case DOUBLE: + case LNGDBL: + break; + default: + expr_error(*expp, "%s operand to %s", symbol2str(fund), symbol2str(oper)); + case ERRONEOUS: + erroneous2int(expp); + break; } } -void -opnd2test(struct expr **expp, int oper) +void opnd2test(struct expr** expp, int oper) { opnd2logical(expp, oper); - if ((*expp)->ex_class == Oper) { - switch((*expp)->OP_OPER) { - case '<': - case '>': - case LESSEQ: - case GREATEREQ: - case EQUAL: - case NOTEQUAL: - case '!': - case AND: - case OR: /* && and || also impose a test */ - /* It is already a test */ - return; - case ',': - opnd2test(&((*expp)->OP_RIGHT), oper); - return; + if ((*expp)->ex_class == Oper) + { + switch ((*expp)->OP_OPER) + { + case '<': + case '>': + case LESSEQ: + case GREATEREQ: + case EQUAL: + case NOTEQUAL: + case '!': + case AND: + case OR: /* && and || also impose a test */ + /* It is already a test */ + return; + case ',': + opnd2test(&((*expp)->OP_RIGHT), oper); + return; } } ch3bin(expp, NOTEQUAL, intexpr((arith)0, INT)); } -void any2opnd(struct expr **expp, int oper) +void any2opnd(struct expr** expp, int oper) { if (!*expp) return; - if (oper == SIZEOF || oper == ADDRESSOF) return; - - switch ((*expp)->ex_type->tp_fund) { - case CHAR: - case SHORT: - case ENUM: - /* case FLOAT: *//* not necessary anymore */ - any2arith(expp, oper); - break; - case ARRAY: - array2pointer(*expp); - break; - case POINTER: - if ((*expp)->ex_class == String) - string2pointer(*expp); - break; - case FUNCTION: - function2pointer(*expp); - break; + if (oper == SIZEOF || oper == ADDRESSOF) + return; + + switch ((*expp)->ex_type->tp_fund) + { + case CHAR: + case SHORT: + case ENUM: + /* case FLOAT: */ /* not necessary anymore */ + any2arith(expp, oper); + break; + case ARRAY: + array2pointer(*expp); + break; + case POINTER: + if ((*expp)->ex_class == String) + string2pointer(*expp); + break; + case FUNCTION: + function2pointer(*expp); + break; #ifndef NOBITFIELD - case FIELD: - field2arith(expp); - break; + case FIELD: + field2arith(expp); + break; #endif /* NOBITFIELD */ } } -void any2parameter(struct expr **expp) +void any2parameter(struct expr** expp) { /* To handle default argument promotions - */ + */ any2opnd(expp, '('); if (int_size != pointer_size) - if ((*expp)->ex_flags & EX_PTRDIFF) - expr_warning(*expp, "pointer difference caused long expression"); + if ((*expp)->ex_flags & EX_PTRDIFF) + expr_warning(*expp, "pointer difference caused long expression"); if ((*expp)->ex_type->tp_fund == FLOAT) float2float(expp, double_type); } #ifndef NOBITFIELD -void field2arith(struct expr **expp) +void field2arith(struct expr** expp) { /* The expression to extract the bitfield value from the - memory word is put in the tree. + memory word is put in the tree. */ - struct type *tp = (*expp)->ex_type->tp_up; - struct field *fd = (*expp)->ex_type->tp_field; + struct type* tp = (*expp)->ex_type->tp_up; + struct field* fd = (*expp)->ex_type->tp_field; (*expp)->ex_type = word_type; - if (tp->tp_unsigned) { /* don't worry about the sign bit */ + if (tp->tp_unsigned) + { /* don't worry about the sign bit */ if (fd->fd_width >= 8 * (int)word_size) (*expp)->ex_type = uword_type; ch3bin(expp, RIGHT, intexpr((arith)fd->fd_shift, INT)); ch3bin(expp, '&', intexpr(fd->fd_mask, INT)); } - else { /* take care of the sign bit: sign extend if needed */ + else + { /* take care of the sign bit: sign extend if needed */ arith other_bits = (int)word_size * 8 - fd->fd_width; - ch3bin(expp, LEFT, - intexpr(other_bits - fd->fd_shift, - INT) - ); + ch3bin(expp, LEFT, intexpr(other_bits - fd->fd_shift, INT)); ch3bin(expp, RIGHT, intexpr(other_bits, INT)); } } @@ -659,25 +686,26 @@ void field2arith(struct expr **expp) /* switch_sign_fp() negates the given floating constant expression, * and frees the string representing the old value. */ -void switch_sign_fp(struct expr *expr) +void switch_sign_fp(struct expr* expr) { flt_umin(&(expr->FL_ARITH)); } -char *writh2str(writh val, int uns) +char* writh2str(writh val, int uns) { /* Converts val to a decimal string, like - long2str(val, 10), but allows wider values. + long2str(val, 10), but allows wider values. */ static char buf[NUMSIZE + 1]; - char *cp = &buf[NUMSIZE + 1]; + char* cp = &buf[NUMSIZE + 1]; int negative = (!uns && val < 0); unsigned writh u = (unsigned writh)val; if (negative) u = -u; *--cp = '\0'; - do { + do + { *--cp = '0' + (u % 10); u /= 10; } while (u != 0); diff --git a/lang/cem/cemcom.ansi/arith.h b/lang/cem/cemcom.ansi/arith.h index 6491bc0eb2..43a338dfad 100644 --- a/lang/cem/cemcom.ansi/arith.h +++ b/lang/cem/cemcom.ansi/arith.h @@ -6,56 +6,56 @@ /* COMPILER ARITHMETIC */ /* The compiler uses 2 types, arith and writh, for its internal - arithmetic. Type arith is normally long, and may be too - narrow for long long values. We can't change arith to a wider - type, because both (pulled by ) and - define arith. - - Type writh (wide arithmetic) is for values that might not fit - in arith. Normally writh is the long long native to the - source machine, which is always good for local compilations, - and generally OK too for cross compilations downwards and - sidewards. + arithmetic. Type arith is normally long, and may be too + narrow for long long values. We can't change arith to a wider + type, because both (pulled by ) and + define arith. + + Type writh (wide arithmetic) is for values that might not fit + in arith. Normally writh is the long long native to the + source machine, which is always good for local compilations, + and generally OK too for cross compilations downwards and + sidewards. */ #ifndef ARITH_H_ #define ARITH_H_ -#include /* obtain definition of "arith" */ -#include /* obtain definition of "label" */ +#include /* obtain definition of "arith" */ +#include /* obtain definition of "label" */ -#define writh long long +#define writh long long /* The compiler also uses "unsigned writh". */ struct expr; struct type; -#define arith_size (sizeof(arith)) -#define arith_sign ((arith) 1 << (arith_size * 8 - 1)) -#define max_arith (~arith_sign) - -extern writh full_mask[]; /* cstoper.c */ - -void arithbalance(struct expr **e1p, int oper, struct expr **e2p); -void relbalance(struct expr **e1p, int oper, struct expr **e2p); -void ch3pointer(struct expr **expp, int oper, struct type *tp); -int any2arith(struct expr **expp, int oper); -void erroneous2int(struct expr **expp); -struct expr *arith2arith(struct type *tp, int oper, struct expr *expr); -int int2int(struct expr **expp, struct type *tp); -void int2float(struct expr **expp, struct type *tp); -void float2int(struct expr **expp, struct type *tp); -void float2float(struct expr **expp, struct type *tp); -void array2pointer(struct expr *exp); -void function2pointer(struct expr *exp); -void string2pointer(struct expr *ex); -void opnd2integral(struct expr **expp, int oper); -void opnd2logical(struct expr **expp, int oper); -void opnd2test(struct expr **expp, int oper); -void any2opnd(struct expr **expp, int oper); -void any2parameter(struct expr **expp); -void field2arith(struct expr **expp); -void switch_sign_fp(struct expr *expr); -char *writh2str(writh val, int uns); -label code_string(char * val, int len); +#define arith_size (sizeof(arith)) +#define arith_sign ((arith)1 << (arith_size * 8 - 1)) +#define max_arith (~arith_sign) + +extern writh full_mask[]; /* cstoper.c */ + +void arithbalance(struct expr** e1p, int oper, struct expr** e2p); +void relbalance(struct expr** e1p, int oper, struct expr** e2p); +void ch3pointer(struct expr** expp, int oper, struct type* tp); +int any2arith(struct expr** expp, int oper); +void erroneous2int(struct expr** expp); +struct expr* arith2arith(struct type* tp, int oper, struct expr* expr); +int int2int(struct expr** expp, struct type* tp); +void int2float(struct expr** expp, struct type* tp); +void float2int(struct expr** expp, struct type* tp); +void float2float(struct expr** expp, struct type* tp); +void array2pointer(struct expr* exp); +void function2pointer(struct expr* exp); +void string2pointer(struct expr* ex); +void opnd2integral(struct expr** expp, int oper); +void opnd2logical(struct expr** expp, int oper); +void opnd2test(struct expr** expp, int oper); +void any2opnd(struct expr** expp, int oper); +void any2parameter(struct expr** expp); +void field2arith(struct expr** expp); +void switch_sign_fp(struct expr* expr); +char* writh2str(writh val, int uns); +label code_string(char* val, int len); #endif /* ARITH_H_ */ diff --git a/lang/cem/cemcom.ansi/atw.h b/lang/cem/cemcom.ansi/atw.h index 74f0044ed6..4a3fd42eb9 100644 --- a/lang/cem/cemcom.ansi/atw.h +++ b/lang/cem/cemcom.ansi/atw.h @@ -7,4 +7,4 @@ #include "sizes.h" -#define ATW(arg) ((((arg) + ((int)word_size - 1)) / word_size) * word_size) +#define ATW(arg) ((((arg) + ((int)word_size - 1)) / word_size) * word_size) diff --git a/lang/cem/cemcom.ansi/blocks.c b/lang/cem/cemcom.ansi/blocks.c index d4df8b73e9..8317ab1fbd 100644 --- a/lang/cem/cemcom.ansi/blocks.c +++ b/lang/cem/cemcom.ansi/blocks.c @@ -5,9 +5,11 @@ /* $Id$ */ /* B L O C K S T O R I N G A N D L O A D I N G */ -#include "parameters.h" -#ifndef LINT +#include "parameters.h" +#ifndef LINT +#include +#include #include #include #include "arith.h" @@ -22,54 +24,53 @@ #include "macro.h" #include "util.h" -#define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER) -#define LocalIntVar() NewLocal(int_size, int_align, reg_any, REGISTER) +#define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER) +#define LocalIntVar() NewLocal(int_size, int_align, reg_any, REGISTER) #endif /* STB */ /* Because EM does not support the loading and storing of - objects having other sizes than word fragment and multiple, - we need to have a way of transferring these objects, whereby - we simulate "loi" and "sti": the address of the source resp. - destination is located on top of stack and a call is done - to load_block() resp. store_block(). - =============================================================== - # Loadblock() works on the stack as follows: ([ ] indicates the - # position of the stackpointer) - # lower address---> - # 1) | &object - # 2) | ... ATW(sz) bytes ... | sz | &stack_block | &object - # 3) | ... ATW(sz) bytes ... - =============================================================== - Loadblock() pushes ATW(sz) bytes directly onto the stack! - - Store_block() works on the stack as follows: - lower address---> - 1) | ... ATW(sz) bytes ... | &object - 2) | ... ATW(sz) bytes ... | &object | &stack_block | sz - 3) - - If sz is a legal argument for "loi" or "sti", just one EM - instruction is generated. - In the other cases, the notion of alignment is taken into account: - we only push an object of the size accepted by EM onto the stack, - while we need a loop to store the stack block into a memory object. + objects having other sizes than word fragment and multiple, + we need to have a way of transferring these objects, whereby + we simulate "loi" and "sti": the address of the source resp. + destination is located on top of stack and a call is done + to load_block() resp. store_block(). + =============================================================== + # Loadblock() works on the stack as follows: ([ ] indicates the + # position of the stackpointer) + # lower address---> + # 1) | &object + # 2) | ... ATW(sz) bytes ... | sz | &stack_block | &object + # 3) | ... ATW(sz) bytes ... + =============================================================== + Loadblock() pushes ATW(sz) bytes directly onto the stack! + + Store_block() works on the stack as follows: + lower address---> + 1) | ... ATW(sz) bytes ... | &object + 2) | ... ATW(sz) bytes ... | &object | &stack_block | sz + 3) + + If sz is a legal argument for "loi" or "sti", just one EM + instruction is generated. + In the other cases, the notion of alignment is taken into account: + we only push an object of the size accepted by EM onto the stack, + while we need a loop to store the stack block into a memory object. */ int suitable_sz(arith sz, int al) { - return ((int)sz % (int)word_size == 0 && al % word_align == 0) || - ( - word_size % sz == 0 && - (al >= (int)sz || al >= word_align) - /* Lots of Irritating Stupid Parentheses */ - ); + return ((int)sz % (int)word_size == 0 && al % word_align == 0) + || (word_size % sz == 0 && (al >= (int)sz || al >= word_align) + /* Lots of Irritating Stupid Parentheses */ + ); } void store_block(arith sz, int al) { if (suitable_sz(sz, al)) C_sti(sz); - else { + else + { #ifndef STB arith src, dst; @@ -79,7 +80,7 @@ void store_block(arith sz, int al) /* load the addresses */ StoreLocal(dst, pointer_size); - C_lor((arith)1); /* push current sp */ + C_lor((arith)1); /* push current sp */ StoreLocal(src, pointer_size); copy_loop(sz, src, dst); C_asp(ATW(sz)); @@ -89,13 +90,13 @@ void store_block(arith sz, int al) /* address of destination lies on the stack */ /* push address of first byte of block on stack onto - the stack by computing it from the current stack - pointer position + the stack by computing it from the current stack + pointer position */ - C_lor((arith)1); /* push current sp */ - C_adp(pointer_size); /* set & to 1st byte of block */ - C_loc(sz); /* number of bytes to transfer */ - C_cal("__stb"); /* call transfer routine */ + C_lor((arith)1); /* push current sp */ + C_adp(pointer_size); /* set & to 1st byte of block */ + C_loc(sz); /* number of bytes to transfer */ + C_cal("__stb"); /* call transfer routine */ C_asp(pointer_size + pointer_size + int_size + ATW(sz)); #endif /* STB */ } @@ -106,7 +107,8 @@ void load_block(arith sz, int al) if (suitable_sz(sz, al)) C_loi(sz); - else { + else + { #ifndef STB arith src, dst; @@ -115,21 +117,21 @@ void load_block(arith sz, int al) dst = LocalPtrVar(); StoreLocal(src, pointer_size); - C_asp(-ATW(sz)); /* allocate stack block */ - C_lor((arith)1); /* push & of stack block as dst */ + C_asp(-ATW(sz)); /* allocate stack block */ + C_lor((arith)1); /* push & of stack block as dst */ StoreLocal(dst, pointer_size); copy_loop(sz, src, dst); FreeLocal(dst); FreeLocal(src); #else /* STB */ arith esz = ATW(sz) - pointer_size; - C_asp(-esz); /* allocate stack block */ - C_lor((arith)1); /* push & of stack block as dst */ - C_dup(pointer_size); /* fetch source address */ + C_asp(-esz); /* allocate stack block */ + C_lor((arith)1); /* push & of stack block as dst */ + C_dup(pointer_size); /* fetch source address */ C_adp(esz); C_loi(pointer_size); - C_loc(sz); /* # bytes to copy */ - C_cal("__stb"); /* library copy routine */ + C_loc(sz); /* # bytes to copy */ + C_cal("__stb"); /* library copy routine */ C_asp(int_size + pointer_size + pointer_size); #endif /* STB */ } @@ -140,7 +142,8 @@ void copy_block(arith sz, int al) if (suitable_sz(sz, al)) C_blm(sz); - else { + else + { #ifndef STB arith src, dst; @@ -154,8 +157,8 @@ void copy_block(arith sz, int al) FreeLocal(dst); FreeLocal(src); #else /* STB */ - C_loc(sz); /* # bytes to copy */ - C_cal("__stb"); /* library copy routine */ + C_loc(sz); /* # bytes to copy */ + C_cal("__stb"); /* library copy routine */ C_asp(int_size + pointer_size + pointer_size); #endif /* STB */ } @@ -168,7 +171,7 @@ void copy_loop(arith sz, arith src, arith dst) label l_cont = text_label(), l_stop = text_label(); arith tmp_sz = LocalIntVar(); - C_loc(sz); /* amount of bytes */ + C_loc(sz); /* amount of bytes */ StoreLocal(tmp_sz, int_size); C_df_ilb(l_cont); LoadLocal(tmp_sz, int_size); @@ -190,5 +193,4 @@ void copy_loop(arith sz, arith src, arith dst) } #endif /* STB */ -#endif /* LINT */ - +#endif /* LINT */ diff --git a/lang/cem/cemcom.ansi/ch3.c b/lang/cem/cemcom.ansi/ch3.c index 14635c7df6..60e42ef7e2 100644 --- a/lang/cem/cemcom.ansi/ch3.c +++ b/lang/cem/cemcom.ansi/ch3.c @@ -5,189 +5,203 @@ /* $Id$ */ /* S E M A N T I C A N A L Y S I S -- C H A P T E R 3.3 */ -#include -#include "parameters.h" -#include -#include "arith.h" -#include "ch3.h" -#include "idf.h" -#include "proto.h" -#include "type.h" -#include "struct.h" -#include "label.h" -#include "expr.h" -#include "def.h" -#include "Lpars.h" -#include "LLlex.h" -#include "error.h" -#include "ch3bin.h" -#include "file_info.h" -#include "decspecs.h" +#include +#include +#include +#include "parameters.h" +#include +#include "arith.h" +#include "ch3.h" +#include "idf.h" +#include "proto.h" +#include "type.h" +#include "struct.h" +#include "label.h" +#include "expr.h" +#include "def.h" +#include "Lpars.h" +#include "LLlex.h" +#include "error.h" +#include "ch3bin.h" +#include "file_info.h" +#include "decspecs.h" extern char options[]; /* Most expression-handling routines have a pointer to a - (struct type *) as first parameter. The object under the pointer - gets updated in the process. + (struct type *) as first parameter. The object under the pointer + gets updated in the process. */ -void ch3sel(struct expr **expp, int oper, struct idf *idf) +void ch3sel(struct expr** expp, int oper, struct idf* idf) { /* The selector idf is applied to *expp; oper may be '.' or - ARROW. + ARROW. */ - struct expr *exp; - struct type *tp; - struct sdef *sd; + struct expr* exp; + struct type* tp; + struct sdef* sd; any2opnd(expp, oper); exp = *expp; tp = exp->ex_type; - if (oper == ARROW) { - if (tp->tp_fund == POINTER && - ( tp->tp_up->tp_fund == STRUCT || - tp->tp_up->tp_fund == UNION)) /* normal case */ + if (oper == ARROW) + { + if (tp->tp_fund == POINTER + && (tp->tp_up->tp_fund == STRUCT || tp->tp_up->tp_fund == UNION)) /* normal case */ tp = tp->tp_up; - else { /* constructions like "12->selector" and - "char c; c->selector" - */ - switch (tp->tp_fund) { - case POINTER: - break; - case INT: - case LONG: - case LNGLNG: - /* An error is given in idf2sdef() */ - ch3cast(expp, CAST, pa_type); - sd = idf2sdef(idf, tp); - tp = sd->sd_stype; - break; - default: - expr_error(exp, "-> applied to %s", - symbol2str(tp->tp_fund)); - case ERRONEOUS: - exp->ex_type = error_type; - return; + else + { /* constructions like "12->selector" and + "char c; c->selector" + */ + switch (tp->tp_fund) + { + case POINTER: + break; + case INT: + case LONG: + case LNGLNG: + /* An error is given in idf2sdef() */ + ch3cast(expp, CAST, pa_type); + sd = idf2sdef(idf, tp); + tp = sd->sd_stype; + break; + default: + expr_error(exp, "-> applied to %s", symbol2str(tp->tp_fund)); + case ERRONEOUS: + exp->ex_type = error_type; + return; } } - } else { /* oper == '.' */ + } + else + { /* oper == '.' */ /* nothing */ } exp = *expp; - switch (tp->tp_fund) { - case POINTER: /* for int *p; p->next = ... */ - case STRUCT: - case UNION: - break; - case INT: - case LONG: - case LNGLNG: - /* warning will be given by idf2sdef() */ - break; - default: - if (!is_anon_idf(idf)) - expr_error(exp, "selector %s applied to %s", - idf->id_text, symbol2str(tp->tp_fund)); - case ERRONEOUS: - exp->ex_type = error_type; - return; + switch (tp->tp_fund) + { + case POINTER: /* for int *p; p->next = ... */ + case STRUCT: + case UNION: + break; + case INT: + case LONG: + case LNGLNG: + /* warning will be given by idf2sdef() */ + break; + default: + if (!is_anon_idf(idf)) + expr_error(exp, "selector %s applied to %s", idf->id_text, symbol2str(tp->tp_fund)); + case ERRONEOUS: + exp->ex_type = error_type; + return; } sd = idf2sdef(idf, tp); - if (oper == '.') { + if (oper == '.') + { /* there are 3 cases in which the selection can be - performed compile-time: - I: n.sel (n either an identifier or a constant) - II: (e.s1).s2 (transformed into (e.(s1+s2))) - III: (e->s1).s2 (transformed into (e->(s1+s2))) - The code performing these conversions is - extremely obscure. + performed compile-time: + I: n.sel (n either an identifier or a constant) + II: (e.s1).s2 (transformed into (e.(s1+s2))) + III: (e->s1).s2 (transformed into (e->(s1+s2))) + The code performing these conversions is + extremely obscure. */ - if (exp->ex_class == Value) { + if (exp->ex_class == Value) + { /* It is an object we know the address of; so - we can calculate the address of the - selected member + we can calculate the address of the + selected member */ exp->VL_VALUE += sd->sd_offset; exp->ex_type = sd->sd_type; exp->ex_lvalue = exp->ex_type->tp_fund != ARRAY; - if (exp->ex_type == error_type) { + if (exp->ex_type == error_type) + { exp->ex_flags |= EX_ERROR; } } - else - if (exp->ex_class == Oper) { - struct oper *op = &(exp->ex_object.ex_oper); - - if (op->op_oper == '.' || op->op_oper == ARROW) { + else if (exp->ex_class == Oper) + { + struct oper* op = &(exp->ex_object.ex_oper); + + if (op->op_oper == '.' || op->op_oper == ARROW) + { assert(is_cp_cst(op->op_right)); op->op_right->VL_VALUE += sd->sd_offset; exp->ex_type = sd->sd_type; exp->ex_lvalue = exp->ex_type->tp_fund != ARRAY; - if (exp->ex_type == error_type) { + if (exp->ex_type == error_type) + { exp->ex_flags |= EX_ERROR; } } - else { - exp = new_oper(sd->sd_type, exp, '.', - intexpr(sd->sd_offset, INT)); + else + { + exp = new_oper(sd->sd_type, exp, '.', intexpr(sd->sd_offset, INT)); exp->ex_lvalue = sd->sd_type->tp_fund != ARRAY; if (!exp->OP_LEFT->ex_lvalue) exp->ex_flags |= EX_ILVALUE; } } } - else { /* oper == ARROW */ - if (is_ld_cst(exp)) { + else + { /* oper == ARROW */ + if (is_ld_cst(exp)) + { exp->VL_VALUE += sd->sd_offset; exp->ex_type = sd->sd_type; } - else { - exp = new_oper(sd->sd_type, - exp, oper, intexpr(sd->sd_offset, INT)); + else + { + exp = new_oper(sd->sd_type, exp, oper, intexpr(sd->sd_offset, INT)); } exp->ex_lvalue = (sd->sd_type->tp_fund != ARRAY); exp->ex_flags &= ~EX_ILVALUE; } - if ((sd->sd_type->tp_typequal & TQ_CONST) - || (tp->tp_typequal & TQ_CONST)) + if ((sd->sd_type->tp_typequal & TQ_CONST) || (tp->tp_typequal & TQ_CONST)) exp->ex_flags |= EX_READONLY; - if ((sd->sd_type->tp_typequal & TQ_VOLATILE) - || (tp->tp_typequal & TQ_VOLATILE)) + if ((sd->sd_type->tp_typequal & TQ_VOLATILE) || (tp->tp_typequal & TQ_VOLATILE)) exp->ex_flags |= EX_VOLATILE; - if (oper == '.' && exp->ex_flags & EX_READONLY) { + if (oper == '.' && exp->ex_flags & EX_READONLY) + { exp->ex_type = qualifier_type(exp->ex_type, TQ_CONST); } - if (exp->ex_flags & EX_VOLATILE) { + if (exp->ex_flags & EX_VOLATILE) + { exp->ex_type = qualifier_type(exp->ex_type, TQ_VOLATILE); } *expp = exp; } -void ch3incr(struct expr **expp, int oper) +void ch3incr(struct expr** expp, int oper) { /* The monadic prefix/postfix incr/decr operator oper is - applied to *expp. + applied to *expp. */ ch3asgn(expp, oper, intexpr((arith)1, INT)); } -void ch3cast(struct expr **expp, int oper, struct type *tp) +void ch3cast(struct expr** expp, int oper, struct type* tp) { /* The expression *expp is cast to type tp; the cast is - caused by the operator oper. If the cast has - to be passed on to run time, its left operand will be an - expression of class Type. + caused by the operator oper. If the cast has + to be passed on to run time, its left operand will be an + expression of class Type. */ - struct type *oldtp; - struct expr *exp = *expp; + struct type* oldtp; + struct expr* exp = *expp; int qual_lev, ascompat = 0; - if (oper == RETURN && tp->tp_fund == VOID) { + if (oper == RETURN && tp->tp_fund == VOID) + { expr_strict(exp, "return in function returning void"); exp->ex_type = void_type; return; } - if (exp->ex_type->tp_fund == FUNCTION) { + if (exp->ex_type->tp_fund == FUNCTION) + { function2pointer(exp); } if (exp->ex_type->tp_fund == ARRAY) @@ -196,355 +210,391 @@ void ch3cast(struct expr **expp, int oper, struct type *tp) string2pointer(exp); oldtp = exp->ex_type; - if (oldtp->tp_size <= 0 && oldtp->tp_fund != VOID) { - expr_error(exp,"incomplete type in expression"); + if (oldtp->tp_size <= 0 && oldtp->tp_fund != VOID) + { + expr_error(exp, "incomplete type in expression"); } #ifndef NOBITFIELD - if (oldtp->tp_fund == FIELD) { + if (oldtp->tp_fund == FIELD) + { field2arith(expp); ch3cast(expp, oper, tp); return; } - if (tp->tp_fund == FIELD) { + if (tp->tp_fund == FIELD) + { ch3cast(expp, oper, tp->tp_up); return; } #endif /* NOBITFIELD */ - switch (oper) { - default: qual_lev = -1; break; - case CAST: qual_lev = -999; break; /* ??? hack */ - case CASTAB: - case '=': - case RETURN: ascompat = 1; /* assignment compatibility */ - /* fallthrough */ - case '-': - case '<': - case '>': - case LESSEQ: - case GREATEREQ: - case EQUAL: - case NOTEQUAL: - case ':': + switch (oper) + { + default: + qual_lev = -1; + break; + case CAST: + qual_lev = -999; + break; /* ??? hack */ + case CASTAB: + case '=': + case RETURN: + ascompat = 1; /* assignment compatibility */ + /* fallthrough */ + case '-': + case '<': + case '>': + case LESSEQ: + case GREATEREQ: + case EQUAL: + case NOTEQUAL: + case ':': qual_lev = -2; break; } - if (equal_type(tp, oldtp, qual_lev, 0)) { + if (equal_type(tp, oldtp, qual_lev, 0)) + { /* life is easy */ - if (ascompat && tp->tp_fund == POINTER) { - if ((tp->tp_up->tp_typequal & oldtp->tp_up->tp_typequal) - != oldtp->tp_up->tp_typequal) { - expr_strict( exp, "qualifier error"); + if (ascompat && tp->tp_fund == POINTER) + { + if ((tp->tp_up->tp_typequal & oldtp->tp_up->tp_typequal) != oldtp->tp_up->tp_typequal) + { + expr_strict(exp, "qualifier error"); } } - exp->ex_type = tp; /* so qualifiers are allright */ + exp->ex_type = tp; /* so qualifiers are allright */ } - else - if (tp->tp_fund == VOID) { + else if (tp->tp_fund == VOID) + { /* easy again */ exp->ex_type = void_type; } - else - if (is_arith_type(oldtp) && is_arith_type(tp)) { + else if (is_arith_type(oldtp) && is_arith_type(tp)) + { int oldi = is_integral_type(oldtp); int i = is_integral_type(tp); - if (oldi && i) { -#ifdef LINT + if (oldi && i) + { +#ifdef LINT if (oper == CAST) exp->ex_type = tp; - else { + else + { int2int(expp, tp); } -#else /* LINT */ +#else /* LINT */ int2int(expp, tp); -#endif /* LINT */ +#endif /* LINT */ } - else - if (oldi && !i) { -#ifdef LINT + else if (oldi && !i) + { +#ifdef LINT if (oper == CAST) exp->ex_type = tp; - else { + else + { int2float(expp, tp); } -#else /* LINT */ +#else /* LINT */ int2float(expp, tp); -#endif /* LINT */ +#endif /* LINT */ } - else - if (!oldi && i) { -#ifdef LINT + else if (!oldi && i) + { +#ifdef LINT if (oper == CAST) exp->ex_type = tp; - else { + else + { float2int(expp, tp); } -#else /* LINT */ +#else /* LINT */ float2int(expp, tp); -#endif /* LINT */ +#endif /* LINT */ } - else { + else + { /* !oldi && !i */ -#ifdef LINT +#ifdef LINT if (oper == CAST) exp->ex_type = tp; - else { + else + { float2float(expp, tp); } -#else /* LINT */ +#else /* LINT */ float2float(expp, tp); -#endif /* LINT */ +#endif /* LINT */ } } - else - if (oldtp->tp_fund == POINTER && tp->tp_fund == POINTER) { - switch (oper) { - case EQUAL: - case NOTEQUAL: - case '=': - case CASTAB: - case RETURN: - case ':': - if (tp->tp_up && oldtp->tp_up) { - if (tp->tp_up->tp_fund == VOID - && oldtp->tp_up->tp_fund != FUNCTION) { - break; /* switch */ - } - if (oldtp->tp_up->tp_fund == VOID - && tp->tp_up->tp_fund != FUNCTION) { - break; /* switch */ - } - if (oldtp->tp_up->tp_fund == VOID - && is_cp_cst(exp) - && exp->VL_VALUE == 0) - break; /* switch */ - } - /* falltrough */ - default: - if (oper == CASTAB) - expr_strict(exp, "incompatible pointers in call"); - else - expr_strict(exp, "incompatible pointers in %s", - symbol2str(oper)); - break; - case CAST: break; + else if (oldtp->tp_fund == POINTER && tp->tp_fund == POINTER) + { + switch (oper) + { + case EQUAL: + case NOTEQUAL: + case '=': + case CASTAB: + case RETURN: + case ':': + if (tp->tp_up && oldtp->tp_up) + { + if (tp->tp_up->tp_fund == VOID && oldtp->tp_up->tp_fund != FUNCTION) + { + break; /* switch */ + } + if (oldtp->tp_up->tp_fund == VOID && tp->tp_up->tp_fund != FUNCTION) + { + break; /* switch */ + } + if (oldtp->tp_up->tp_fund == VOID && is_cp_cst(exp) && exp->VL_VALUE == 0) + break; /* switch */ + } + /* falltrough */ + default: + if (oper == CASTAB) + expr_strict(exp, "incompatible pointers in call"); + else + expr_strict(exp, "incompatible pointers in %s", symbol2str(oper)); + break; + case CAST: + break; } -#ifdef LINT +#ifdef LINT if (oper != CAST) lint_ptr_conv(oldtp->tp_up->tp_fund, tp->tp_up->tp_fund); -#endif /* LINT */ - exp->ex_type = tp; /* free conversion */ +#endif /* LINT */ + exp->ex_type = tp; /* free conversion */ } - else - if (oldtp->tp_fund == POINTER && is_integral_type(tp)) { + else if (oldtp->tp_fund == POINTER && is_integral_type(tp)) + { /* from pointer to integral */ if (oper != CAST) - expr_strict(exp, - "illegal conversion of pointer to %s", - symbol2str(tp->tp_fund)); + expr_strict(exp, "illegal conversion of pointer to %s", symbol2str(tp->tp_fund)); if (oldtp->tp_size > tp->tp_size) - expr_warning(exp, - "conversion of pointer to %s loses accuracy", - symbol2str(tp->tp_fund)); - if (oldtp->tp_size != tp->tp_size) { + expr_warning( + exp, "conversion of pointer to %s loses accuracy", symbol2str(tp->tp_fund)); + if (oldtp->tp_size != tp->tp_size) + { int2int(expp, tp); - } else + } + else exp->ex_type = tp; } - else - if (tp->tp_fund == POINTER && is_integral_type(oldtp)) { + else if (tp->tp_fund == POINTER && is_integral_type(oldtp)) + { /* from integral to pointer */ - switch (oper) { - case CAST: - break; - case CASTAB: - case EQUAL: - case NOTEQUAL: - case '=': - case RETURN: - if (is_cp_cst(exp) && exp->VL_VALUE == 0) + switch (oper) + { + case CAST: + break; + case CASTAB: + case EQUAL: + case NOTEQUAL: + case '=': + case RETURN: + if (is_cp_cst(exp) && exp->VL_VALUE == 0) + break; + default: + expr_strict(exp, "illegal conversion of %s to pointer", symbol2str(oldtp->tp_fund)); break; - default: - expr_strict(exp, - "illegal conversion of %s to pointer", - symbol2str(oldtp->tp_fund)); - break; } if (oldtp->tp_size > tp->tp_size) - expr_warning(exp, - "conversion of %s to pointer loses accuracy", - symbol2str(oldtp->tp_fund)); - if (oldtp->tp_size != tp->tp_size) { + expr_warning( + exp, "conversion of %s to pointer loses accuracy", symbol2str(oldtp->tp_fund)); + if (oldtp->tp_size != tp->tp_size) + { int2int(expp, tp); - } else + } + else exp->ex_type = tp; } - else - if (oldtp->tp_fund == ERRONEOUS) { + else if (oldtp->tp_fund == ERRONEOUS) + { /* we just won't look */ - exp->ex_type = tp; /* brute force */ + exp->ex_type = tp; /* brute force */ } - else - if (oldtp->tp_size == tp->tp_size && oper == CAST) { + else if (oldtp->tp_size == tp->tp_size && oper == CAST) + { expr_strict(exp, "dubious conversion based on equal size"); - exp->ex_type = tp; /* brute force */ + exp->ex_type = tp; /* brute force */ } - else { + else + { if (oldtp->tp_fund != ERRONEOUS && tp->tp_fund != ERRONEOUS) - expr_error(exp, "cannot convert %s to %s", - symbol2str(oldtp->tp_fund), - symbol2str(tp->tp_fund) - ); - exp->ex_type = tp; /* brute force */ + expr_error( + exp, "cannot convert %s to %s", symbol2str(oldtp->tp_fund), + symbol2str(tp->tp_fund)); + exp->ex_type = tp; /* brute force */ } /* re-initialize exp, since *expp may have changed */ exp = *expp; - if (oper == CAST) { + if (oper == CAST) + { exp->ex_flags |= EX_ILVALUE; } } /* Determine whether two types are equal. -*/ -int equal_type(struct type *tp,struct type *otp, int qual_lev, int diag) + */ +int equal_type(struct type* tp, struct type* otp, int qual_lev, int diag) { - if (tp == otp) + if (tp == otp) return 1; - if (!tp - || !otp - || (tp->tp_fund != otp->tp_fund) - || (tp->tp_unsigned != otp->tp_unsigned) + if (!tp || !otp || (tp->tp_fund != otp->tp_fund) || (tp->tp_unsigned != otp->tp_unsigned) || (tp->tp_align != otp->tp_align)) return 0; - if (tp->tp_size != otp->tp_size) { - if (tp->tp_fund != ARRAY - || (tp->tp_size != -1 && otp->tp_size != -1)) + if (tp->tp_size != otp->tp_size) + { + if (tp->tp_fund != ARRAY || (tp->tp_size != -1 && otp->tp_size != -1)) return 0; } - if (qual_lev >= 0 && tp->tp_typequal != otp->tp_typequal) { + if (qual_lev >= 0 && tp->tp_typequal != otp->tp_typequal) + { strict("missing or illegal qualifiers"); } - switch (tp->tp_fund) { + switch (tp->tp_fund) + { - case FUNCTION: - /* If both types have parameter type lists, the type of - each parameter in the composite parameter type list - is the composite type of the corresponding paramaters. - */ - if (tp->tp_proto && otp->tp_proto) { - if (!equal_proto(tp->tp_proto, otp->tp_proto, diag)) - return 0; - } else if (tp->tp_proto || otp->tp_proto) { - if (!legal_mixture(tp, otp, diag)) - return 0; - } - return equal_type(tp->tp_up, otp->tp_up, qual_lev + 1, diag); + case FUNCTION: + /* If both types have parameter type lists, the type of + each parameter in the composite parameter type list + is the composite type of the corresponding paramaters. + */ + if (tp->tp_proto && otp->tp_proto) + { + if (!equal_proto(tp->tp_proto, otp->tp_proto, diag)) + return 0; + } + else if (tp->tp_proto || otp->tp_proto) + { + if (!legal_mixture(tp, otp, diag)) + return 0; + } + return equal_type(tp->tp_up, otp->tp_up, qual_lev + 1, diag); - case ARRAY: - /* If one type is an array of known size, the composite - type is an array of that size - */ - if (tp->tp_size != otp->tp_size && - (tp->tp_size != -1 && otp->tp_size != -1)) - return 0; - return equal_type(tp->tp_up, otp->tp_up, qual_lev/* ??? +1 */, diag); + case ARRAY: + /* If one type is an array of known size, the composite + type is an array of that size + */ + if (tp->tp_size != otp->tp_size && (tp->tp_size != -1 && otp->tp_size != -1)) + return 0; + return equal_type(tp->tp_up, otp->tp_up, qual_lev /* ??? +1 */, diag); - case POINTER: - return equal_type(tp->tp_up, otp->tp_up, qual_lev + 1, diag); + case POINTER: + return equal_type(tp->tp_up, otp->tp_up, qual_lev + 1, diag); - case FIELD: - return equal_type(tp->tp_up, otp->tp_up, qual_lev/* ??? +1 */, diag); + case FIELD: + return equal_type(tp->tp_up, otp->tp_up, qual_lev /* ??? +1 */, diag); - case STRUCT: - case UNION: - case ENUM: - return tp->tp_idf == otp->tp_idf && tp->tp_sdef == otp->tp_sdef; + case STRUCT: + case UNION: + case ENUM: + return tp->tp_idf == otp->tp_idf && tp->tp_sdef == otp->tp_sdef; - default: - return 1; + default: + return 1; } } -int check_pseudoproto(struct proto *pl,struct proto *opl, int diag) +int check_pseudoproto(struct proto* pl, struct proto* opl, int diag) { int retval = 1; - if (pl->pl_flag & PL_ELLIPSIS) { - if (diag) { + if (pl->pl_flag & PL_ELLIPSIS) + { + if (diag) + { error("illegal ellipsis terminator"); pl->pl_flag |= PL_ERRGIVEN; opl->pl_flag |= PL_ERRGIVEN; } return 0; } - if (opl->pl_flag & PL_VOID) { - if (!(pl->pl_flag & PL_VOID)) { - if (diag) { + if (opl->pl_flag & PL_VOID) + { + if (!(pl->pl_flag & PL_VOID)) + { + if (diag) + { strict("function is defined without parameters"); } return 0; } return 1; } - while (pl && opl) { - if (!equal_type(pl->pl_type, opl->pl_type, -1, diag)) { - if (diag) { - if (!(pl->pl_flag & PL_ERRGIVEN) - && !(opl->pl_flag & PL_ERRGIVEN)) - error("incorrect type for parameter %s of definition", - opl->pl_idf->id_text); - pl->pl_flag |= PL_ERRGIVEN; - opl->pl_flag |= PL_ERRGIVEN; + while (pl && opl) + { + if (!equal_type(pl->pl_type, opl->pl_type, -1, diag)) + { + if (diag) + { + if (!(pl->pl_flag & PL_ERRGIVEN) && !(opl->pl_flag & PL_ERRGIVEN)) + error("incorrect type for parameter %s of definition", opl->pl_idf->id_text); + pl->pl_flag |= PL_ERRGIVEN; + opl->pl_flag |= PL_ERRGIVEN; + } + retval = 0; } - retval = 0; - } - pl = pl->next; - opl = opl->next; + pl = pl->next; + opl = opl->next; } - if (pl || opl) { - if (diag) error("incorrect number of parameters"); + if (pl || opl) + { + if (diag) + error("incorrect number of parameters"); retval = 0; } return retval; } -int legal_mixture(struct type *tp, struct type *otp, int diag) +int legal_mixture(struct type* tp, struct type* otp, int diag) { struct proto *pl = tp->tp_proto, *opl = otp->tp_proto; int retval = 1; - struct proto *prot; + struct proto* prot; int fund; - assert( (pl != 0) ^ (opl != 0)); - if (pl) { + assert((pl != 0) ^ (opl != 0)); + if (pl) + { prot = pl; - } else { + } + else + { prot = opl; } - if (!opl && otp->tp_pseudoproto) { + if (!opl && otp->tp_pseudoproto) + { return check_pseudoproto(tp->tp_proto, otp->tp_pseudoproto, diag); } - if (prot->pl_flag & PL_ELLIPSIS) { - if (prot->pl_flag & PL_ERRGIVEN) { + if (prot->pl_flag & PL_ELLIPSIS) + { + if (prot->pl_flag & PL_ERRGIVEN) + { if (pl) error("illegal ellipsis terminator"); - else error("ellipsis terminator in previous (prototype) declaration"); + else + error("ellipsis terminator in previous (prototype) declaration"); prot->pl_flag |= PL_ERRGIVEN; } return 0; } - while (prot) { - /* if (!(prot->pl_flag & PL_ELLIPSIS)) {} */ + while (prot) + { + /* if (!(prot->pl_flag & PL_ELLIPSIS)) {} */ fund = prot->pl_type->tp_fund; - if (fund == CHAR || fund == SHORT || fund == FLOAT) { + if (fund == CHAR || fund == SHORT || fund == FLOAT) + { if (diag && !(prot->pl_flag & PL_ERRGIVEN)) - error("illegal %s parameter in %sdeclaration", - symbol2str(fund), (opl ? "previous (prototype) " : "" )); + error( + "illegal %s parameter in %sdeclaration", symbol2str(fund), + (opl ? "previous (prototype) " : "")); prot->pl_flag |= PL_ERRGIVEN; retval = 0; } @@ -553,90 +603,103 @@ int legal_mixture(struct type *tp, struct type *otp, int diag) return retval; } -int equal_proto(struct proto *pl, struct proto *opl, int diag) +int equal_proto(struct proto* pl, struct proto* opl, int diag) { if (pl == opl) return 1; /* If only one type is a function type with a parameter type list - (a function prototype), the composite type is a function - prototype with parameter type list. + (a function prototype), the composite type is a function + prototype with parameter type list. */ - while ( pl && opl) { + while (pl && opl) + { - if ((pl->pl_flag & ~PL_ERRGIVEN) != (opl->pl_flag & ~PL_ERRGIVEN) || - !equal_type(pl->pl_type, opl->pl_type, -1, diag)) - return 0; + if ((pl->pl_flag & ~PL_ERRGIVEN) != (opl->pl_flag & ~PL_ERRGIVEN) + || !equal_type(pl->pl_type, opl->pl_type, -1, diag)) + return 0; - pl = pl->next; - opl = opl->next; + pl = pl->next; + opl = opl->next; } return !(pl || opl); } /* check if a type has a consqualified member */ -int recurqual(struct type *tp, int qual) +int recurqual(struct type* tp, int qual) { - struct sdef *sdf; + struct sdef* sdf; assert(tp); - if (tp->tp_typequal & qual) return 1; - switch(tp->tp_fund) { - case UNION: - case STRUCT: - case ENUM: - sdf = tp->tp_sdef; - while (sdf) { - if (recurqual(sdf->sd_type, qual)) - return 1; - sdf = sdf->sd_sdef; - } - break; + if (tp->tp_typequal & qual) + return 1; + switch (tp->tp_fund) + { + case UNION: + case STRUCT: + case ENUM: + sdf = tp->tp_sdef; + while (sdf) + { + if (recurqual(sdf->sd_type, qual)) + return 1; + sdf = sdf->sd_sdef; + } + break; } return 0; } -void ch3asgn(struct expr **expp, int oper, struct expr *expr) +void ch3asgn(struct expr** expp, int oper, struct expr* expr) { /* The assignment operators. - "f op= e" should be interpreted as - "f = (typeof f)((typeof (f op e))f op (typeof (f op e))e)" - and not as "f = f op (typeof f)e". - Consider, for example, (i == 10) i *= 0.9; (i == 9), where - typeof i == int. - The resulting expression tree becomes: - op= - / \ - / \ - f (typeof (f op e))e - EVAL should however take care of evaluating (typeof (f op e))f + "f op= e" should be interpreted as + "f = (typeof f)((typeof (f op e))f op (typeof (f op e))e)" + and not as "f = f op (typeof f)e". + Consider, for example, (i == 10) i *= 0.9; (i == 9), where + typeof i == int. + The resulting expression tree becomes: + op= + / \ + / \ + f (typeof (f op e))e + EVAL should however take care of evaluating (typeof (f op e))f */ - struct expr *exp = *expp; + struct expr* exp = *expp; int fund = exp->ex_type->tp_fund; - struct type *tp; - char *oper_string = symbol2str(oper); + struct type* tp; + char* oper_string = symbol2str(oper); /* We expect an lvalue */ - if (fund == ARRAY || fund == FUNCTION) exp->ex_lvalue = 0; - if (!exp->ex_lvalue) { + if (fund == ARRAY || fund == FUNCTION) + exp->ex_lvalue = 0; + if (!exp->ex_lvalue) + { expr_error(exp, "no lvalue in operand of %s", oper_string); - } else if (exp->ex_flags & EX_ILVALUE) { + } + else if (exp->ex_flags & EX_ILVALUE) + { expr_strict(exp, "incorrect lvalue in operand of %s", oper_string); - } else if (exp->ex_flags & EX_READONLY) { + } + else if (exp->ex_flags & EX_READONLY) + { expr_error(exp, "operand of %s is read-only", oper_string); - } else if (fund == STRUCT || fund == UNION) { + } + else if (fund == STRUCT || fund == UNION) + { if (recurqual(exp->ex_type, TQ_CONST)) - expr_error(exp,"operand of %s contains a const-qualified member", - oper_string); + expr_error(exp, "operand of %s contains a const-qualified member", oper_string); } - if (oper == '=') { + if (oper == '=') + { ch3cast(&expr, oper, exp->ex_type); tp = expr->ex_type; } - else { /* turn e into e' where typeof(e') = typeof (f op e) */ - struct expr *extmp = intexpr((arith)0, INT); + else + { /* turn e into e' where typeof(e') = typeof (f op e) */ + struct expr* extmp = intexpr((arith)0, INT); /* this is really $#@&*%$# ! */ /* if you correct this, please correct lint_new_oper() too */ @@ -644,14 +707,15 @@ void ch3asgn(struct expr **expp, int oper, struct expr *expr) extmp->ex_type = exp->ex_type; ch3bin(&extmp, oper, expr); /* Note that ch3bin creates a tree of the expression - ((typeof (f op e))f op (typeof (f op e))e), + ((typeof (f op e))f op (typeof (f op e))e), where f ~ extmp and e ~ expr. We want to use (typeof (f op e))e. Ch3bin does not create a tree if both operands were illegal or constants! */ - tp = extmp->ex_type; /* perform the arithmetic in type tp */ - if (extmp->ex_class == Oper) { + tp = extmp->ex_type; /* perform the arithmetic in type tp */ + if (extmp->ex_class == Oper) + { expr = extmp->OP_RIGHT; extmp->OP_RIGHT = NILEXPR; free_expression(extmp); @@ -660,55 +724,56 @@ void ch3asgn(struct expr **expp, int oper, struct expr *expr) expr = extmp; } #ifndef NOBITFIELD - exp = new_oper(fund == FIELD ? exp->ex_type->tp_up : exp->ex_type, - exp, oper, expr); + exp = new_oper(fund == FIELD ? exp->ex_type->tp_up : exp->ex_type, exp, oper, expr); #else /* NOBITFIELD */ exp = new_oper(exp->ex_type, exp, oper, expr); #endif /* NOBITFIELD */ - exp->OP_TYPE = tp; /* for EVAL() */ + exp->OP_TYPE = tp; /* for EVAL() */ exp->ex_flags |= EX_SIDEEFFECTS; *expp = exp; } /* Some interesting (?) questions answered. -*/ -int is_integral_type(struct type *tp) + */ +int is_integral_type(struct type* tp) { - switch (tp->tp_fund) { - case CHAR: - case SHORT: - case INT: - case LONG: - case LNGLNG: - case ENUM: - return 1; + switch (tp->tp_fund) + { + case CHAR: + case SHORT: + case INT: + case LONG: + case LNGLNG: + case ENUM: + return 1; #ifndef NOBITFIELD - case FIELD: - return is_integral_type(tp->tp_up); + case FIELD: + return is_integral_type(tp->tp_up); #endif /* NOBITFIELD */ - default: - return 0; + default: + return 0; } } -int is_arith_type(struct type *tp) +int is_arith_type(struct type* tp) { - switch (tp->tp_fund) { - case CHAR: - case SHORT: - case INT: - case LONG: - case LNGLNG: - case ENUM: - case FLOAT: - case DOUBLE: - case LNGDBL: - return 1; + switch (tp->tp_fund) + { + case CHAR: + case SHORT: + case INT: + case LONG: + case LNGLNG: + case ENUM: + case FLOAT: + case DOUBLE: + case LNGDBL: + return 1; #ifndef NOBITFIELD - case FIELD: - return is_arith_type(tp->tp_up); + case FIELD: + return is_arith_type(tp->tp_up); #endif /* NOBITFIELD */ - default: - return 0; + default: + return 0; } } diff --git a/lang/cem/cemcom.ansi/ch3.h b/lang/cem/cemcom.ansi/ch3.h index c5d0bd2299..363b37a25b 100644 --- a/lang/cem/cemcom.ansi/ch3.h +++ b/lang/cem/cemcom.ansi/ch3.h @@ -13,17 +13,16 @@ struct type; struct proto; struct idf; - -void ch3sel(struct expr **expp, int oper, struct idf *idf); -void ch3incr(struct expr **expp, int oper); -void ch3cast(struct expr **expp, int oper, struct type *tp); -int equal_type(struct type *tp,struct type *otp, int qual_lev, int diag); -int check_pseudoproto(struct proto *pl,struct proto *opl, int diag); -int legal_mixture(struct type *tp, struct type *otp, int diag); -int equal_proto(struct proto *pl, struct proto *opl, int diag); -int recurqual(struct type *tp, int qual); -void ch3asgn(struct expr **expp, int oper, struct expr *expr); -int is_integral_type(struct type *tp); -int is_arith_type(struct type *tp); +void ch3sel(struct expr** expp, int oper, struct idf* idf); +void ch3incr(struct expr** expp, int oper); +void ch3cast(struct expr** expp, int oper, struct type* tp); +int equal_type(struct type* tp, struct type* otp, int qual_lev, int diag); +int check_pseudoproto(struct proto* pl, struct proto* opl, int diag); +int legal_mixture(struct type* tp, struct type* otp, int diag); +int equal_proto(struct proto* pl, struct proto* opl, int diag); +int recurqual(struct type* tp, int qual); +void ch3asgn(struct expr** expp, int oper, struct expr* expr); +int is_integral_type(struct type* tp); +int is_arith_type(struct type* tp); #endif /* CH3_H_ */ diff --git a/lang/cem/cemcom.ansi/ch3bin.c b/lang/cem/cemcom.ansi/ch3bin.c index 0f502255dc..e1f45081df 100644 --- a/lang/cem/cemcom.ansi/ch3bin.c +++ b/lang/cem/cemcom.ansi/ch3bin.c @@ -5,45 +5,47 @@ /* $Id$ */ /* SEMANTIC ANALYSIS (CHAPTER 3.3) -- BINARY OPERATORS */ -#include "parameters.h" -#include -#include -#include "arith.h" -#include "type.h" -#include "struct.h" -#include "label.h" -#include "expr.h" -#include "Lpars.h" -#include "LLlex.h" -#include "sizes.h" -#include "ch3bin.h" -#include "ch3mon.h" -#include "ch3.h" -#include "error.h" -#include "cstoper.h" -#include "fltcstoper.h" +#include "parameters.h" +#include +#include +#include +#include +#include "arith.h" +#include "type.h" +#include "struct.h" +#include "label.h" +#include "expr.h" +#include "Lpars.h" +#include "LLlex.h" +#include "sizes.h" +#include "ch3bin.h" +#include "ch3mon.h" +#include "ch3.h" +#include "error.h" +#include "cstoper.h" +#include "fltcstoper.h" extern char options[]; /* This chapter asks for the repeated application of code to handle - an operation that may be executed at compile time or at run time, - depending on the constancy of the operands. + an operation that may be executed at compile time or at run time, + depending on the constancy of the operands. */ /* * Although the relational operators are generally not commutative, we can * switch the arguments if the operator is adapted (e.g. < becomes >) */ -#define non_commutative_binop(expp, oper, expr) mk_binop(expp, oper, expr, 0) -#define commutative_binop(expp, oper, expr) mk_binop(expp, oper, expr, 1) -#define non_commutative_relop(expp, oper, expr) mk_binop(expp, oper, expr, 1) +#define non_commutative_binop(expp, oper, expr) mk_binop(expp, oper, expr, 0) +#define commutative_binop(expp, oper, expr) mk_binop(expp, oper, expr, 1) +#define non_commutative_relop(expp, oper, expr) mk_binop(expp, oper, expr, 1) -void ch3bin(struct expr **expp, int oper, struct expr *expr) +void ch3bin(struct expr** expp, int oper, struct expr* expr) { /* apply binary operator oper between *expp and expr. - NB: don't swap operands if op is one of the op= operators!!! + NB: don't swap operands if op is one of the op= operators!!! */ - struct type *expp_tp; + struct type* expp_tp; any2opnd(expp, oper); expp_tp = (*expp)->ex_type; @@ -51,275 +53,295 @@ void ch3bin(struct expr **expp, int oper, struct expr *expr) * to pointer (except for SIZEOF and unary &). */ any2opnd(&expr, oper); - switch (oper) { - case '[': /* 3.3.2.1 */ - /* indexing follows the commutative laws */ - switch (expp_tp->tp_fund) { - case POINTER: - break; - case ERRONEOUS: - return; - default: /* unindexable */ - switch (expr->ex_type->tp_fund) { - case POINTER: - break; - case ERRONEOUS: - return; - default: - expr_error(*expp, - "indexing an object of type %s", - symbol2str(expp_tp->tp_fund)); - return; + switch (oper) + { + case '[': /* 3.3.2.1 */ + /* indexing follows the commutative laws */ + switch (expp_tp->tp_fund) + { + case POINTER: + break; + case ERRONEOUS: + return; + default: /* unindexable */ + switch (expr->ex_type->tp_fund) + { + case POINTER: + break; + case ERRONEOUS: + return; + default: + expr_error( + *expp, "indexing an object of type %s", + symbol2str(expp_tp->tp_fund)); + return; + } + break; } - break; - } - ch3bin(expp, '+', expr); - ch3mon('*', expp); - break; - - case '(': /* 3.3.2.2 */ - if (expp_tp->tp_fund == POINTER - && expp_tp->tp_up->tp_fund == FUNCTION) { + ch3bin(expp, '+', expr); ch3mon('*', expp); - expp_tp = (*expp)->ex_type; - } - if (expp_tp->tp_fund != FUNCTION) { - expr_error(*expp, "call of non-function (%s)", - symbol2str(expp_tp->tp_fund)); - /* leave the expression; it may still serve */ - free_expression(expr); /* there go the parameters */ - *expp = new_oper(error_type, - *expp, '(', (struct expr *)0); - } - else - *expp = new_oper(expp_tp->tp_up, *expp, '(', expr); - (*expp)->ex_flags |= EX_SIDEEFFECTS; - break; + break; - case PARCOMMA: /* 3.3.2.2 */ - *expp = new_oper(expr->ex_type, *expp, PARCOMMA, expr); - break; + case '(': /* 3.3.2.2 */ + if (expp_tp->tp_fund == POINTER && expp_tp->tp_up->tp_fund == FUNCTION) + { + ch3mon('*', expp); + expp_tp = (*expp)->ex_type; + } + if (expp_tp->tp_fund != FUNCTION) + { + expr_error(*expp, "call of non-function (%s)", symbol2str(expp_tp->tp_fund)); + /* leave the expression; it may still serve */ + free_expression(expr); /* there go the parameters */ + *expp = new_oper(error_type, *expp, '(', (struct expr*)0); + } + else + *expp = new_oper(expp_tp->tp_up, *expp, '(', expr); + (*expp)->ex_flags |= EX_SIDEEFFECTS; + break; - case '%': - case MODAB: - case ANDAB: - case XORAB: - case ORAB: - opnd2integral(expp, oper); - opnd2integral(&expr, oper); - /* fallthrough */ - case '/': - case DIVAB: - case TIMESAB: - arithbalance(expp, oper, &expr); - non_commutative_binop(expp, oper, expr); - break; + case PARCOMMA: /* 3.3.2.2 */ + *expp = new_oper(expr->ex_type, *expp, PARCOMMA, expr); + break; - case '&': - case '^': - case '|': - opnd2integral(expp, oper); - opnd2integral(&expr, oper); - /* fallthrough */ - case '*': - arithbalance(expp, oper, &expr); - commutative_binop(expp, oper, expr); - break; + case '%': + case MODAB: + case ANDAB: + case XORAB: + case ORAB: + opnd2integral(expp, oper); + opnd2integral(&expr, oper); + /* fallthrough */ + case '/': + case DIVAB: + case TIMESAB: + arithbalance(expp, oper, &expr); + non_commutative_binop(expp, oper, expr); + break; - case '+': - if (expr->ex_type->tp_fund == POINTER) { /* swap operands */ - struct expr *etmp = expr; - expp_tp = expr->ex_type; /* both in registers */ - expr = *expp; - *expp = etmp; - } - /* fallthrough */ - case PLUSAB: - case POSTINCR: - case PLUSPLUS: - if (expp_tp->tp_fund == POINTER) { - pointer_arithmetic(expp, oper, &expr); - if (expr->ex_type->tp_size != (*expp)->ex_type->tp_size) - ch3cast(&expr, CAST, (*expp)->ex_type); - pointer_binary(expp, oper, expr); - } - else { + case '&': + case '^': + case '|': + opnd2integral(expp, oper); + opnd2integral(&expr, oper); + /* fallthrough */ + case '*': arithbalance(expp, oper, &expr); - if (oper == '+') - commutative_binop(expp, oper, expr); - else - non_commutative_binop(expp, oper, expr); - } - break; + commutative_binop(expp, oper, expr); + break; - case '-': - case MINAB: - case POSTDECR: - case MINMIN: - if (expp_tp->tp_fund == POINTER) { + case '+': if (expr->ex_type->tp_fund == POINTER) - pntminuspnt(expp, oper, expr); - else { + { /* swap operands */ + struct expr* etmp = expr; + expp_tp = expr->ex_type; /* both in registers */ + expr = *expp; + *expp = etmp; + } + /* fallthrough */ + case PLUSAB: + case POSTINCR: + case PLUSPLUS: + if (expp_tp->tp_fund == POINTER) + { pointer_arithmetic(expp, oper, &expr); + if (expr->ex_type->tp_size != (*expp)->ex_type->tp_size) + ch3cast(&expr, CAST, (*expp)->ex_type); pointer_binary(expp, oper, expr); } - } - else { - arithbalance(expp, oper, &expr); - non_commutative_binop(expp, oper, expr); - } - break; + else + { + arithbalance(expp, oper, &expr); + if (oper == '+') + commutative_binop(expp, oper, expr); + else + non_commutative_binop(expp, oper, expr); + } + break; + + case '-': + case MINAB: + case POSTDECR: + case MINMIN: + if (expp_tp->tp_fund == POINTER) + { + if (expr->ex_type->tp_fund == POINTER) + pntminuspnt(expp, oper, expr); + else + { + pointer_arithmetic(expp, oper, &expr); + pointer_binary(expp, oper, expr); + } + } + else + { + arithbalance(expp, oper, &expr); + non_commutative_binop(expp, oper, expr); + } + break; - case LEFT: - case RIGHT: - case LEFTAB: - case RIGHTAB: - opnd2integral(expp, oper); - opnd2integral(&expr, oper); - arithbalance(expp, oper, &expr); /* ch. 3.3.7 */ - ch3cast(&expr, oper, int_type); /* cvt. rightop to int */ - non_commutative_binop(expp, oper, expr); - break; + case LEFT: + case RIGHT: + case LEFTAB: + case RIGHTAB: + opnd2integral(expp, oper); + opnd2integral(&expr, oper); + arithbalance(expp, oper, &expr); /* ch. 3.3.7 */ + ch3cast(&expr, oper, int_type); /* cvt. rightop to int */ + non_commutative_binop(expp, oper, expr); + break; - case '<': - case '>': - case LESSEQ: - case GREATEREQ: - case EQUAL: - case NOTEQUAL: - relbalance(expp, oper, &expr); - non_commutative_relop(expp, oper, expr); - (*expp)->ex_type = int_type; - break; + case '<': + case '>': + case LESSEQ: + case GREATEREQ: + case EQUAL: + case NOTEQUAL: + relbalance(expp, oper, &expr); + non_commutative_relop(expp, oper, expr); + (*expp)->ex_type = int_type; + break; - case AND: - case OR: - opnd2test(expp, oper); - opnd2test(&expr, oper); - if (is_cp_cst(*expp)) { - struct expr *ex = *expp; + case AND: + case OR: + opnd2test(expp, oper); + opnd2test(&expr, oper); + if (is_cp_cst(*expp)) + { + struct expr* ex = *expp; - /* the following condition is a short-hand for - ((oper == AND) && o1) || ((oper == OR) && !o1) - where o1 == (*expp)->VL_VALUE; - and ((oper == AND) || (oper == OR)) - */ - if ((oper == AND) == (ex->VL_VALUE != 0)) { - *expp = expr; + /* the following condition is a short-hand for + ((oper == AND) && o1) || ((oper == OR) && !o1) + where o1 == (*expp)->VL_VALUE; + and ((oper == AND) || (oper == OR)) + */ + if ((oper == AND) == (ex->VL_VALUE != 0)) + { + *expp = expr; + } + else + { + ex->ex_flags |= expr->ex_flags; + free_expression(expr); + *expp = intexpr((arith)(oper != AND), INT); + } + (*expp)->ex_flags |= ex->ex_flags | EX_ILVALUE; + free_expression(ex); } - else { - ex->ex_flags |= expr->ex_flags; - free_expression(expr); - *expp = intexpr((arith)(oper != AND), INT); + else if (is_cp_cst(expr)) + { + /* Note!!!: the following condition is a short-hand for + ((oper == AND) && o2) || ((oper == OR) && !o2) + where o2 == expr->VL_VALUE + and ((oper == AND) || (oper == OR)) + */ + if ((oper == AND) == (expr->VL_VALUE != 0)) + { + (*expp)->ex_flags |= expr->ex_flags | EX_ILVALUE; + free_expression(expr); + } + else + { + if (oper == OR) + expr->VL_VALUE = 1; + ch3bin(expp, ',', expr); + } } - (*expp)->ex_flags |= ex->ex_flags | EX_ILVALUE; - free_expression(ex); - } - else - if (is_cp_cst(expr)) { - /* Note!!!: the following condition is a short-hand for - ((oper == AND) && o2) || ((oper == OR) && !o2) - where o2 == expr->VL_VALUE - and ((oper == AND) || (oper == OR)) - */ - if ((oper == AND) == (expr->VL_VALUE != 0)) { - (*expp)->ex_flags |= expr->ex_flags | EX_ILVALUE; - free_expression(expr); + else + { + *expp = new_oper(int_type, *expp, oper, expr); + } + (*expp)->ex_flags |= EX_LOGICAL; + break; + + case ':': + if (is_struct_or_union(expp_tp->tp_fund) || is_struct_or_union(expr->ex_type->tp_fund)) + { + if (!equal_type(expp_tp, expr->ex_type, -1, 0)) + expr_error(*expp, "illegal balance"); } - else { - if (oper == OR) - expr->VL_VALUE = 1; - ch3bin(expp, ',', expr); + else + relbalance(expp, oper, &expr); +#ifdef LINT + if ((is_cp_cst(*expp) && is_cp_cst(expr)) && (*expp)->VL_VALUE == expr->VL_VALUE) + { + hwarning("operands of : are constant and equal"); } - } - else { - *expp = new_oper(int_type, *expp, oper, expr); - } - (*expp)->ex_flags |= EX_LOGICAL; - break; +#endif /* LINT */ + *expp = new_oper((*expp)->ex_type, *expp, oper, expr); + break; - case ':': - if (is_struct_or_union(expp_tp->tp_fund) - || is_struct_or_union(expr->ex_type->tp_fund)) { - if (!equal_type(expp_tp, expr->ex_type, -1, 0)) - expr_error(*expp, "illegal balance"); - } - else - relbalance(expp, oper, &expr); -#ifdef LINT - if ( (is_cp_cst(*expp) && is_cp_cst(expr)) - && (*expp)->VL_VALUE == expr->VL_VALUE - ) { - hwarning("operands of : are constant and equal"); - } -#endif /* LINT */ - *expp = new_oper((*expp)->ex_type, *expp, oper, expr); - break; + case '?': + opnd2logical(expp, oper); + if (is_cp_cst(*expp)) + { +#ifdef LINT + hwarning("condition in ?: expression is constant"); +#endif /* LINT */ + if ((*expp)->VL_VALUE) + { + free_expression(*expp); + free_expression(expr->OP_RIGHT); + *expp = expr->OP_LEFT; + } + else + { + free_expression(*expp); + free_expression(expr->OP_LEFT); + *expp = expr->OP_RIGHT; + } + free_expr(expr); + (*expp)->ex_flags |= EX_ILVALUE; + } + else + { + *expp = new_oper(expr->ex_type, *expp, oper, expr); + } + break; - case '?': - opnd2logical(expp, oper); - if (is_cp_cst(*expp)) { -#ifdef LINT - hwarning("condition in ?: expression is constant"); -#endif /* LINT */ - if ((*expp)->VL_VALUE) { + case ',': + if (is_cp_cst(*expp)) + { +#ifdef LINT + hwarning("constant expression ignored"); +#endif /* LINT */ free_expression(*expp); - free_expression(expr->OP_RIGHT); - *expp = expr->OP_LEFT; + *expp = expr; } - else { - free_expression(*expp); - free_expression(expr->OP_LEFT); - *expp = expr->OP_RIGHT; + else + { + *expp = new_oper(expr->ex_type, *expp, oper, expr); } - free_expr(expr); - (*expp)->ex_flags |= EX_ILVALUE; - } - else { - *expp = new_oper(expr->ex_type, *expp, oper, expr); - } - break; - - case ',': - if (is_cp_cst(*expp)) { -#ifdef LINT - hwarning("constant expression ignored"); -#endif /* LINT */ - free_expression(*expp); - *expp = expr; - } - else { - *expp = new_oper(expr->ex_type, *expp, oper, expr); - } - (*expp)->ex_flags |= EX_COMMA; - break; + (*expp)->ex_flags |= EX_COMMA; + break; } } -void pntminuspnt(struct expr **expp, int oper, struct expr *expr) +void pntminuspnt(struct expr** expp, int oper, struct expr* expr) { /* Subtracting two pointers is so complicated it merits a - routine of its own. + routine of its own. */ - struct type *up_type = (*expp)->ex_type->tp_up; + struct type* up_type = (*expp)->ex_type->tp_up; - if (!equal_type(up_type, expr->ex_type->tp_up, -1, 0)) { + if (!equal_type(up_type, expr->ex_type->tp_up, -1, 0)) + { expr_error(*expp, "subtracting incompatible pointers"); free_expression(expr); erroneous2int(expp); return; } /* we hope the optimizer will eliminate the load-time - pointer subtraction + pointer subtraction */ *expp = new_oper((*expp)->ex_type, *expp, oper, expr); - ch3cast(expp, CAST, pa_type); /* ptr-ptr: result has pa_type */ - ch3bin(expp, '/' - , intexpr(size_of_type(up_type, symbol2str(up_type->tp_fund)) - , pa_type->tp_fund)); - ch3cast(expp, CAST, pa_type); /* result will be an integral expr */ - /* cast necessary ??? */ - if (int_size != pointer_size) (*expp)->ex_flags |= EX_PTRDIFF; + ch3cast(expp, CAST, pa_type); /* ptr-ptr: result has pa_type */ + ch3bin( + expp, '/', intexpr(size_of_type(up_type, symbol2str(up_type->tp_fund)), pa_type->tp_fund)); + ch3cast(expp, CAST, pa_type); /* result will be an integral expr */ + /* cast necessary ??? */ + if (int_size != pointer_size) + (*expp)->ex_flags |= EX_PTRDIFF; } /* @@ -329,64 +351,63 @@ void pntminuspnt(struct expr **expp, int oper, struct expr *expr) */ int arg_switched(int oper) { - switch (oper) { - case '<': return '>'; - case '>': return '<'; - case LESSEQ: return GREATEREQ; - case GREATEREQ: return LESSEQ; - default: return oper; + switch (oper) + { + case '<': + return '>'; + case '>': + return '<'; + case LESSEQ: + return GREATEREQ; + case GREATEREQ: + return LESSEQ; + default: + return oper; } } -void mk_binop(struct expr **expp, int oper, struct expr *expr, int commutative) +void mk_binop(struct expr** expp, int oper, struct expr* expr, int commutative) { /* Constructs in *expp the operation indicated by the operands. - "commutative" indicates whether "oper" is a commutative - operator. + "commutative" indicates whether "oper" is a commutative + operator. */ - struct expr *ex = *expp; + struct expr* ex = *expp; if (is_cp_cst(expr) && is_cp_cst(ex)) cstbin(expp, oper, expr); else if (is_fp_cst(expr) && is_fp_cst(ex)) fltcstbin(expp, oper, expr); - else { - *expp = (commutative - && !(ex->ex_flags & EX_VOLATILE) - && (expr->ex_depth > ex->ex_depth - || ((expr->ex_flags & EX_SIDEEFFECTS) - && !(ex->ex_flags & EX_SIDEEFFECTS)) - || is_cp_cst(ex))) - ? new_oper(ex->ex_type, expr, arg_switched(oper), ex) - : new_oper(ex->ex_type, ex, oper, expr); + else + { + *expp = (commutative && !(ex->ex_flags & EX_VOLATILE) + && (expr->ex_depth > ex->ex_depth + || ((expr->ex_flags & EX_SIDEEFFECTS) && !(ex->ex_flags & EX_SIDEEFFECTS)) + || is_cp_cst(ex))) + ? new_oper(ex->ex_type, expr, arg_switched(oper), ex) + : new_oper(ex->ex_type, ex, oper, expr); } } -void pointer_arithmetic(struct expr **expp1, int oper, struct expr **expp2) +void pointer_arithmetic(struct expr** expp1, int oper, struct expr** expp2) { int typ; /* prepares the integral expression expp2 in order to - apply it to the pointer expression expp1 + apply it to the pointer expression expp1 */ - if ((typ = any2arith(expp2, oper)) == FLOAT - || typ == DOUBLE - || typ == LNGDBL) { - expr_error(*expp2, - "illegal combination of %s and pointer", - symbol2str(typ)); + if ((typ = any2arith(expp2, oper)) == FLOAT || typ == DOUBLE || typ == LNGDBL) + { + expr_error(*expp2, "illegal combination of %s and pointer", symbol2str(typ)); erroneous2int(expp2); } - ch3bin( expp2, '*', - intexpr(size_of_type((*expp1)->ex_type->tp_up, "object"), - pa_type->tp_fund) - ); + ch3bin(expp2, '*', intexpr(size_of_type((*expp1)->ex_type->tp_up, "object"), pa_type->tp_fund)); } -void pointer_binary(struct expr **expp, int oper, struct expr *expr) +void pointer_binary(struct expr** expp, int oper, struct expr* expr) { /* constructs the pointer arithmetic expression out of - a pointer expression, a binary operator and an integral - expression. + a pointer expression, a binary operator and an integral + expression. */ if (is_ld_cst(expr) && is_ld_cst(*expp)) cstbin(expp, oper, expr); diff --git a/lang/cem/cemcom.ansi/ch3bin.h b/lang/cem/cemcom.ansi/ch3bin.h index ce9cf9fd05..eface48ecf 100644 --- a/lang/cem/cemcom.ansi/ch3bin.h +++ b/lang/cem/cemcom.ansi/ch3bin.h @@ -10,12 +10,11 @@ struct expr; -void ch3bin(struct expr **expp, int oper, struct expr *expr); -void pntminuspnt(struct expr **expp, int oper, struct expr *expr); +void ch3bin(struct expr** expp, int oper, struct expr* expr); +void pntminuspnt(struct expr** expp, int oper, struct expr* expr); int arg_switched(int oper); -void mk_binop(struct expr **expp, int oper, struct expr *expr, int commutative); -void pointer_arithmetic(struct expr **expp1, int oper, struct expr **expp2); -void pointer_binary(struct expr **expp, int oper, struct expr *expr); - +void mk_binop(struct expr** expp, int oper, struct expr* expr, int commutative); +void pointer_arithmetic(struct expr** expp1, int oper, struct expr** expp2); +void pointer_binary(struct expr** expp, int oper, struct expr* expr); #endif /* CH3BIN_H_ */ diff --git a/lang/cem/cemcom.ansi/ch3mon.c b/lang/cem/cemcom.ansi/ch3mon.c index 3185df7676..87969c6a6a 100644 --- a/lang/cem/cemcom.ansi/ch3mon.c +++ b/lang/cem/cemcom.ansi/ch3mon.c @@ -5,163 +5,166 @@ /* $Id$ */ /* SEMANTIC ANALYSIS (CHAPTER 3.3) -- MONADIC OPERATORS */ -#include "ch3mon.h" -#include "parameters.h" -#include -#include "Lpars.h" -#include -#include "idf.h" -#include "arith.h" -#include "LLlex.h" -#include "type.h" -#include "label.h" -#include "expr.h" -#include "def.h" -#include "sizes.h" -#include "ch3.h" -#include "error.h" - +#include +#include +#include "ch3mon.h" +#include "parameters.h" +#include +#include "Lpars.h" +#include +#include "idf.h" +#include "arith.h" +#include "LLlex.h" +#include "type.h" +#include "label.h" +#include "expr.h" +#include "def.h" +#include "sizes.h" +#include "ch3.h" +#include "error.h" extern char options[]; -void ch3mon(int oper, struct expr **expp) +void ch3mon(int oper, struct expr** expp) { /* The monadic prefix operator oper is applied to *expp. - */ - struct expr *expr; + */ + struct expr* expr; if (oper != PLUSPLUS && oper != MINMIN) any2opnd(expp, oper); - switch (oper) { - case '*': /* 3.3.3.2 */ - /* no FIELD type allowed */ - expr = *expp; - if (expr->ex_type->tp_fund != POINTER) { - if (expr->ex_type != error_type) { - expr_error(expr, - "* applied to non-pointer (%s)", - symbol2str(expr->ex_type->tp_fund)); - } - } else { - if (is_ld_cst(expr)) - /* dereference in administration only */ - expr->ex_type = expr->ex_type->tp_up; - else /* runtime code */ - *expp = new_oper(expr->ex_type->tp_up, NILEXPR, - '*', expr); + switch (oper) + { + case '*': /* 3.3.3.2 */ + /* no FIELD type allowed */ expr = *expp; - expr->ex_lvalue = ( - expr->ex_type->tp_fund != ARRAY && - expr->ex_type->tp_fund != FUNCTION - ); - if (expr->ex_lvalue && expr->ex_type->tp_size <= 0) { - expr_error(expr, "incomplete type in expression"); + if (expr->ex_type->tp_fund != POINTER) + { + if (expr->ex_type != error_type) + { + expr_error( + expr, "* applied to non-pointer (%s)", symbol2str(expr->ex_type->tp_fund)); + } } - if (expr->ex_type->tp_typequal & TQ_CONST) - expr->ex_flags |= EX_READONLY; - if (expr->ex_type->tp_typequal & TQ_VOLATILE) - expr->ex_flags |= EX_VOLATILE; - expr->ex_flags &= ~EX_ILVALUE; - } - break; - case ADDRESSOF: - if ((*expp)->ex_type->tp_fund == ARRAY) { - (*expp)->ex_type = pointer_to((*expp)->ex_type, 0); - } - else - if ((*expp)->ex_type->tp_fund == FUNCTION) { - (*expp)->ex_type = pointer_to((*expp)->ex_type, 0); - } - else + else + { + if (is_ld_cst(expr)) + /* dereference in administration only */ + expr->ex_type = expr->ex_type->tp_up; + else /* runtime code */ + *expp = new_oper(expr->ex_type->tp_up, NILEXPR, '*', expr); + expr = *expp; + expr->ex_lvalue + = (expr->ex_type->tp_fund != ARRAY && expr->ex_type->tp_fund != FUNCTION); + if (expr->ex_lvalue && expr->ex_type->tp_size <= 0) + { + expr_error(expr, "incomplete type in expression"); + } + if (expr->ex_type->tp_typequal & TQ_CONST) + expr->ex_flags |= EX_READONLY; + if (expr->ex_type->tp_typequal & TQ_VOLATILE) + expr->ex_flags |= EX_VOLATILE; + expr->ex_flags &= ~EX_ILVALUE; + } + break; + case ADDRESSOF: + if ((*expp)->ex_type->tp_fund == ARRAY) + { + (*expp)->ex_type = pointer_to((*expp)->ex_type, 0); + } + else if ((*expp)->ex_type->tp_fund == FUNCTION) + { + (*expp)->ex_type = pointer_to((*expp)->ex_type, 0); + } + else #ifndef NOBITFIELD - if ((*expp)->ex_type->tp_fund == FIELD) - expr_error(*expp, "& applied to field variable"); - else + if ((*expp)->ex_type->tp_fund == FIELD) + expr_error(*expp, "& applied to field variable"); + else #endif /* NOBITFIELD */ - if (!(*expp)->ex_lvalue) - expr_error(*expp, "& applied to non-lvalue"); - else if ((*expp)->ex_flags & EX_ILVALUE) - expr_error(*expp, "& applied to illegal lvalue"); - else { - /* assume that enums are already filtered out */ - if (ISNAME(*expp)) { - struct def *def = - (*expp)->VL_IDF->id_def; + if (!(*expp)->ex_lvalue) + expr_error(*expp, "& applied to non-lvalue"); + else if ((*expp)->ex_flags & EX_ILVALUE) + expr_error(*expp, "& applied to illegal lvalue"); + else + { + /* assume that enums are already filtered out */ + if (ISNAME(*expp)) + { + struct def* def = (*expp)->VL_IDF->id_def; - /* & indicates that - cannot be used as register - anymore - */ - if (def->df_sc == REGISTER) { - expr_error(*expp, - "& on register variable not allowed"); - break; /* break case ADDRESSOF */ + /* & indicates that + cannot be used as register + anymore + */ + if (def->df_sc == REGISTER) + { + expr_error(*expp, "& on register variable not allowed"); + break; /* break case ADDRESSOF */ + } + } + (*expp)->ex_type = pointer_to((*expp)->ex_type, (*expp)->ex_type->tp_typequal); + (*expp)->ex_lvalue = 0; + (*expp)->ex_flags &= ~(EX_READONLY | EX_VOLATILE); } + break; + case '~': + { + int fund = (*expp)->ex_type->tp_fund; + + if (fund == FLOAT || fund == DOUBLE || fund == LNGDBL) + { + expr_error(*expp, "~ not allowed on %s operands", symbol2str(fund)); + erroneous2int(expp); + break; } - (*expp)->ex_type = pointer_to((*expp)->ex_type, - (*expp)->ex_type->tp_typequal); - (*expp)->ex_lvalue = 0; - (*expp)->ex_flags &= ~(EX_READONLY | EX_VOLATILE); + /* FALLTHROUGH */ } - break; - case '~': - { - int fund = (*expp)->ex_type->tp_fund; + case '-': + any2arith(expp, oper); + if (is_cp_cst(*expp)) + { + writh o1 = (*expp)->VL_VALUE; - if (fund == FLOAT || fund == DOUBLE || fund == LNGDBL) { - expr_error( *expp, - "~ not allowed on %s operands", - symbol2str(fund)); - erroneous2int(expp); + (*expp)->VL_VALUE = (oper == '-') + ? -o1 + : ((*expp)->ex_type->tp_unsigned + ? (~o1) & full_mask[(int)(*expp)->ex_type->tp_size] + : ~o1); + } + else if (is_fp_cst(*expp)) + switch_sign_fp(*expp); + else + *expp = new_oper((*expp)->ex_type, NILEXPR, oper, *expp); + break; + case '!': + opnd2test(expp, '!'); + if (is_cp_cst(*expp)) + { + (*expp)->VL_VALUE = !((*expp)->VL_VALUE); + (*expp)->ex_type = int_type; /* a cast ???(EB) */ + } + else + *expp = new_oper(int_type, NILEXPR, oper, *expp); + (*expp)->ex_flags |= EX_LOGICAL; + break; + case PLUSPLUS: + case MINMIN: + ch3incr(expp, oper); + break; + case SIZEOF: + if (ISNAME(*expp) && (*expp)->VL_IDF->id_def->df_formal_array) + expr_warning( + *expp, "sizeof formal array %s is sizeof pointer!", (*expp)->VL_IDF->id_text); + expr = intexpr( + (*expp)->ex_class == String + ? (arith)((*expp)->SG_LEN) + : size_of_type((*expp)->ex_type, symbol2str((*expp)->ex_type->tp_fund)), + UNSIGNED); + expr->ex_flags |= EX_SIZEOF; + free_expression(*expp); + *expp = expr; break; - } - /* FALLTHROUGH */ - } - case '-': - any2arith(expp, oper); - if (is_cp_cst(*expp)) { - writh o1 = (*expp)->VL_VALUE; - - (*expp)->VL_VALUE = (oper == '-') ? -o1 : - ((*expp)->ex_type->tp_unsigned ? - (~o1) & full_mask[(int)(*expp)->ex_type->tp_size] : - ~o1 - ); - } - else - if (is_fp_cst(*expp)) - switch_sign_fp(*expp); - else - *expp = new_oper((*expp)->ex_type, - NILEXPR, oper, *expp); - break; - case '!': - opnd2test(expp, '!'); - if (is_cp_cst(*expp)) { - (*expp)->VL_VALUE = !((*expp)->VL_VALUE); - (*expp)->ex_type = int_type; /* a cast ???(EB) */ - } - else - *expp = new_oper(int_type, NILEXPR, oper, *expp); - (*expp)->ex_flags |= EX_LOGICAL; - break; - case PLUSPLUS: - case MINMIN: - ch3incr(expp, oper); - break; - case SIZEOF: - if (ISNAME(*expp) && (*expp)->VL_IDF->id_def->df_formal_array) - expr_warning(*expp, "sizeof formal array %s is sizeof pointer!", - (*expp)->VL_IDF->id_text); - expr = intexpr((*expp)->ex_class == String ? - (arith)((*expp)->SG_LEN) : - size_of_type((*expp)->ex_type, - symbol2str((*expp)->ex_type->tp_fund)) - , UNSIGNED); - expr->ex_flags |= EX_SIZEOF; - free_expression(*expp); - *expp = expr; - break; } } diff --git a/lang/cem/cemcom.ansi/ch3mon.h b/lang/cem/cemcom.ansi/ch3mon.h index e269f137d0..abbd19e1c5 100644 --- a/lang/cem/cemcom.ansi/ch3mon.h +++ b/lang/cem/cemcom.ansi/ch3mon.h @@ -1,22 +1,21 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-02-06 - * + * */ #ifndef CH3MON_H_ #define CH3MON_H_ struct expr; -void ch3mon(int oper, struct expr **expp); -void ch3bin(struct expr **expp, int oper, struct expr *expr); -void pntminuspnt(struct expr **expp, int oper, struct expr *expr); +void ch3mon(int oper, struct expr** expp); +void ch3bin(struct expr** expp, int oper, struct expr* expr); +void pntminuspnt(struct expr** expp, int oper, struct expr* expr); int arg_switched(int oper); -void mk_binop(struct expr **expp, int oper, struct expr *expr, int commutative); -void pointer_arithmetic(struct expr **expp1, int oper, struct expr **expp2); -void pointer_binary(struct expr **expp, int oper, struct expr *expr); - +void mk_binop(struct expr** expp, int oper, struct expr* expr, int commutative); +void pointer_arithmetic(struct expr** expp1, int oper, struct expr** expp2); +void pointer_binary(struct expr** expp, int oper, struct expr* expr); #endif /* CH3MON_H_ */ diff --git a/lang/cem/cemcom.ansi/class.h b/lang/cem/cemcom.ansi/class.h index 18c317ff33..cb0f71b8c4 100644 --- a/lang/cem/cemcom.ansi/class.h +++ b/lang/cem/cemcom.ansi/class.h @@ -6,42 +6,42 @@ /* U S E O F C H A R A C T E R C L A S S E S */ /* As a starter, chars are divided into classes, according to which - token they can be the start of. - At present such a class number is supposed to fit in 4 bits. + token they can be the start of. + At present such a class number is supposed to fit in 4 bits. */ -#define class(ch) (tkclass[ch]) +#define class(ch) (tkclass[ch]) /* Being the start of a token is, fortunately, a mutual exclusive - property, so, as there are less than 16 classes they can be - packed in 4 bits. + property, so, as there are less than 16 classes they can be + packed in 4 bits. */ -#define STSKIP 0 /* spaces and so on: skipped characters */ -#define STNL 1 /* newline character(s): update linenumber etc. */ -#define STGARB 2 /* garbage ascii character: not allowed in C */ -#define STSIMP 3 /* this character can occur as token in C */ -#define STCOMP 4 /* this one can start a compound token in C */ -#define STELL 5 /* wide character- or string- constant prefix */ -#define STIDF 6 /* being the initial character of an identifier */ -#define STCHAR 7 /* the starter of a character constant */ -#define STSTR 8 /* the starter of a string */ -#define STNUM 9 /* the starter of a numeric constant */ -#define STEOI 10 /* End-Of-Information mark */ -#define STMSPEC 11 /* special class for token expansion */ +#define STSKIP 0 /* spaces and so on: skipped characters */ +#define STNL 1 /* newline character(s): update linenumber etc. */ +#define STGARB 2 /* garbage ascii character: not allowed in C */ +#define STSIMP 3 /* this character can occur as token in C */ +#define STCOMP 4 /* this one can start a compound token in C */ +#define STELL 5 /* wide character- or string- constant prefix */ +#define STIDF 6 /* being the initial character of an identifier */ +#define STCHAR 7 /* the starter of a character constant */ +#define STSTR 8 /* the starter of a string */ +#define STNUM 9 /* the starter of a numeric constant */ +#define STEOI 10 /* End-Of-Information mark */ +#define STMSPEC 11 /* special class for token expansion */ -#define NOEXPM '\003' /* don't expand the next macro identifier */ -#define TOKSEP '\004' /* the token separator */ +#define NOEXPM '\003' /* don't expand the next macro identifier */ +#define TOKSEP '\004' /* the token separator */ /* But occurring inside a token is not, so we need 1 bit for each - class. This is implemented as a collection of tables to speed up - the decision whether a character has a special meaning. + class. This is implemented as a collection of tables to speed up + the decision whether a character has a special meaning. */ -#define in_idf(ch) (inidf[ch]) -#define is_oct(ch) (isoct[ch]) -#define is_dig(ch) (isdig[ch]) -#define is_hex(ch) (ishex[ch]) -#define is_wsp(ch) (iswsp[ch]) +#define in_idf(ch) (inidf[ch]) +#define is_oct(ch) (isoct[ch]) +#define is_dig(ch) (isdig[ch]) +#define is_hex(ch) (ishex[ch]) +#define is_wsp(ch) (iswsp[ch]) extern char tkclass[]; extern char inidf[], isoct[], isdig[], ishex[], iswsp[]; diff --git a/lang/cem/cemcom.ansi/code.c b/lang/cem/cemcom.ansi/code.c index 9975d268a0..bcdbda8ba8 100644 --- a/lang/cem/cemcom.ansi/code.c +++ b/lang/cem/cemcom.ansi/code.c @@ -5,51 +5,52 @@ /* $Id$ */ /* C O D E - G E N E R A T I N G R O U T I N E S */ -#include -#include -#include -#include "parameters.h" -#ifndef LINT -#include +#include +#include +#include +#include +#include "parameters.h" +#ifndef LINT +#include #else -#include "l_em.h" -#include "l_lint.h" -#endif /* LINT */ -#include -#include -#include "idf.h" -#include "arith.h" -#include "type.h" -#include "label.h" -#include "code.h" -#include "stmt.h" -#include "def.h" -#include "expr.h" -#include "sizes.h" -#include "stack.h" -#include "blocks.h" -#include "struct.h" -#include "level.h" -#include "dataflow.h" -#include "conversion.h" -#include "decspecs.h" -#include "declar.h" -#include "Lpars.h" -#include "specials.h" -#include "atw.h" -#include "ch3.h" -#include "eval.h" -#include "stab.h" -#include "LLlex.h" -#include "align.h" -#include "util.h" -#include "error.h" - -#ifdef LINT -#include "l_lint.h" -#endif /* LINT */ +#include "l_em.h" +#include "l_lint.h" +#endif /* LINT */ +#include +#include +#include "idf.h" +#include "arith.h" +#include "type.h" +#include "label.h" +#include "code.h" +#include "stmt.h" +#include "def.h" +#include "expr.h" +#include "sizes.h" +#include "stack.h" +#include "blocks.h" +#include "struct.h" +#include "level.h" +#include "dataflow.h" +#include "conversion.h" +#include "decspecs.h" +#include "declar.h" +#include "Lpars.h" +#include "specials.h" +#include "atw.h" +#include "ch3.h" +#include "eval.h" +#include "stab.h" +#include "LLlex.h" +#include "align.h" +#include "util.h" +#include "error.h" + +#ifdef LINT +#include "l_lint.h" +#endif /* LINT */ #ifdef DBSYMTAB -#include +#include #endif /* DBSYMTAB */ label lab_count = 1; @@ -57,31 +58,29 @@ label datlab_count = 1; int fp_used; -extern void str_cst(char *, int, int); /* ival.c */ - - +extern void str_cst(char*, int, int); /* ival.c */ /* global function info */ -char *func_name; -struct type *func_type; +char* func_name; +struct type* func_type; #ifdef LINT int func_notypegiven; #endif #ifdef USE_TMP -static int tmp_id; -static int pro_id; +static int tmp_id; +static int pro_id; #endif /* USE_TMP */ extern char options[]; -extern char *source; +extern char* source; -#ifndef LINT -void init_code(char *dst_file) +#ifndef LINT +void init_code(char* dst_file) { /* init_code() initialises the output file on which the - compact EM code is written + compact EM code is written */ C_init(word_size, pointer_size); /* initialise EM module */ if (C_open(dst_file) == 0) @@ -89,7 +88,8 @@ void init_code(char *dst_file) C_magic(); C_ms_emx(word_size, pointer_size); #ifdef DBSYMTAB - if (options['g']) { + if (options['g']) + { C_ms_std(source, N_SO, 0); stb_typedef(int_type, "int"); stb_typedef(schar_type, "char"); @@ -99,7 +99,8 @@ void init_code(char *dst_file) stb_typedef(ushort_type, "unsigned short"); stb_typedef(ulong_type, "unsigned long"); stb_typedef(uint_type, "unsigned int"); - if (lnglng_size >= 0) { + if (lnglng_size >= 0) + { stb_typedef(lnglng_type, "long long"); stb_typedef(ulnglng_type, "unsigned long long"); } @@ -112,16 +113,16 @@ void init_code(char *dst_file) #ifdef USE_TMP #ifdef PREPEND_SCOPES C_insertpart(tmp_id = C_getid()); -#endif /* PREPEND_SCOPES */ -#endif /* USE_TMP */ +#endif /* PREPEND_SCOPES */ +#endif /* USE_TMP */ } -#endif /* LINT */ +#endif /* LINT */ -struct string_cst *str_list = 0; +struct string_cst* str_list = 0; label code_string(char* val, int len) { - struct string_cst *sc = new_string_cst(); + struct string_cst* sc = new_string_cst(); label dlb = data_label(); C_ina_dlb(dlb); @@ -133,13 +134,14 @@ label code_string(char* val, int len) return dlb; } -void def_strings(struct string_cst *sc) +void def_strings(struct string_cst* sc) { - while (sc) { - struct string_cst *sc1 = sc; + while (sc) + { + struct string_cst* sc1 = sc; C_df_dlb(sc->sc_dlb); - str_cst(sc->sc_value, sc->sc_len, 1); /* string in rom */ + str_cst(sc->sc_value, sc->sc_len, 1); /* string in rom */ sc = sc->next; free(sc1->sc_value); free_string_cst(sc1); @@ -147,44 +149,49 @@ void def_strings(struct string_cst *sc) } /* flush_strings() is called from program.g after each external definition */ -void flush_strings(void) { - if (str_list) { +void flush_strings(void) +{ + if (str_list) + { def_strings(str_list); str_list = 0; } } -#ifndef LINT +#ifndef LINT void end_code(void) { /* end_code() performs the actions to be taken when closing - the output stream. + the output stream. */ - if (fp_used) { + if (fp_used) + { /* floating point used */ C_ms_flt(); } C_ms_src((int)(LineNumber - 2), source); C_close(); } -#endif /* LINT */ +#endif /* LINT */ -#ifdef PREPEND_SCOPES +#ifdef PREPEND_SCOPES void prepend_scopes(void) { /* prepend_scopes() runs down the list of global idf's - and generates those exa's, exp's, ina's and inp's - that superior hindsight has provided. + and generates those exa's, exp's, ina's and inp's + that superior hindsight has provided. */ - struct stack_entry *se = local_level->sl_entry; + struct stack_entry* se = local_level->sl_entry; #ifdef USE_TMP C_beginpart(tmp_id); #endif /* USE_TMP */ - while (se != 0) { - struct def *df = se->se_idf->id_def; - - if (df && (df->df_initialized || df->df_used || df->df_alloc)) { + while (se != 0) + { + struct def* df = se->se_idf->id_def; + + if (df && (df->df_initialized || df->df_used || df->df_alloc)) + { code_scope(se->se_idf->id_text, df); } se = se->next; @@ -193,29 +200,30 @@ void prepend_scopes(void) C_endpart(tmp_id); #endif /* USE_TMP */ } -#endif /* PREPEND_SCOPES */ +#endif /* PREPEND_SCOPES */ -void code_scope(char* text, struct def *def) +void code_scope(char* text, struct def* def) { /* generates code for one name, text, of the storage class - as given by def, if meaningful. + as given by def, if meaningful. */ int fund = def->df_type->tp_fund; - - switch (def->df_sc) { - case EXTERN: - case GLOBAL: - if (fund == FUNCTION) - C_exp(text); - else - C_exa_dnam(text); - break; - case STATIC: - if (fund == FUNCTION) - C_inp(text); - else - C_ina_dnam(text); - break; + + switch (def->df_sc) + { + case EXTERN: + case GLOBAL: + if (fund == FUNCTION) + C_exp(text); + else + C_exa_dnam(text); + break; + case STATIC: + if (fund == FUNCTION) + C_inp(text); + else + C_ina_dnam(text); + break; } } @@ -223,34 +231,36 @@ static label return_label, return2_label; static char return_expr_occurred; static arith func_size; static int struct_return; -static char *last_fn_given = (char *)0; +static char* last_fn_given = (char*)0; static label file_name_label; -void begin_proc(struct decspecs *ds, struct idf *idf) /* to be called when entering a procedure */ +void begin_proc(struct decspecs* ds, struct idf* idf) /* to be called when entering a procedure */ { /* begin_proc() is called at the entrance of a new function - and performs the necessary code generation: - - a scope indicator (if needed) exp/inp - - the procedure entry pro $name - - reserves some space if the result of the function - does not fit in the return area - - a fil pseudo instruction + and performs the necessary code generation: + - a scope indicator (if needed) exp/inp + - the procedure entry pro $name + - reserves some space if the result of the function + does not fit in the return area + - a fil pseudo instruction */ - char *name = idf->id_text; - struct def *def = idf->id_def; + char* name = idf->id_text; + struct def* def = idf->id_def; /* idf->id_def does not indicate the right def structure * when the function being defined has a parameter of the * same name in an old-style function definition. */ - while (def->df_level != L_GLOBAL) def = def->next; + while (def->df_level != L_GLOBAL) + def = def->next; /* When we have a new-style function definition, the parameters * are defined first, which means that it may look as if they have * the greatest scope. Correct this. */ - if (idf->id_def == def && def->next && def->next->df_level == L_PROTO) { - struct def *tmpdef = def->next; + if (idf->id_def == def && def->next && def->next->df_level == L_PROTO) + { + struct def* tmpdef = def->next; def->next = tmpdef->next; tmpdef->next = def; @@ -258,16 +268,16 @@ void begin_proc(struct decspecs *ds, struct idf *idf) /* to be called when ente } #ifndef PREPEND_SCOPES code_scope(name, def); -#endif /* PREPEND_SCOPES */ -#ifdef DATAFLOW +#endif /* PREPEND_SCOPES */ +#ifdef DATAFLOW if (options['d']) DfaStartFunction(name); -#endif /* DATAFLOW */ - +#endif /* DATAFLOW */ /* set global function info */ func_name = name; - if (def->df_type->tp_fund != FUNCTION) { + if (def->df_type->tp_fund != FUNCTION) + { error("making function body for non-function"); def->df_type = error_type; } @@ -283,41 +293,48 @@ void begin_proc(struct decspecs *ds, struct idf *idf) /* to be called when ente #else C_insertpart(pro_id = C_getid()); #endif - if (is_struct_or_union(func_type->tp_fund)) { - if (func_size <= 0) { + if (is_struct_or_union(func_type->tp_fund)) + { + if (func_size <= 0) + { error("unknown return type for function %s", name); - } else { + } + else + { struct_return = 1; } } else struct_return = 0; /* Special arrangements if the function result doesn't fit in - the function return area of the EM machine. The size of - the function return area is implementation dependent. + the function return area of the EM machine. The size of + the function return area is implementation dependent. */ - lab_count = (label) 1; + lab_count = (label)1; return_label = text_label(); return2_label = text_label(); return_expr_occurred = 0; LocalInit(); prc_entry(name); - if (! options['L']) { /* profiling */ - if (!last_fn_given || strcmp(last_fn_given, FileName) != 0) { + if (!options['L']) + { /* profiling */ + if (!last_fn_given || strcmp(last_fn_given, FileName) != 0) + { /* previous function came from other file */ C_df_dlb(file_name_label = data_label()); - C_con_scon(last_fn_given = FileName, - (arith)(strlen(FileName) + 1)); + C_con_scon(last_fn_given = FileName, (arith)(strlen(FileName) + 1)); } /* enable debug trace of EM source */ C_fil_dlb(file_name_label, (arith)0); C_lin((arith)LineNumber); } #ifdef DBSYMTAB - if (options['g']) { + if (options['g']) + { stb_string(def, FUNCTION, name); - if (! strcmp(name, "main")) { - C_ms_stb_cst(name, N_MAIN, 0, (arith) 0); + if (!strcmp(name, "main")) + { + C_ms_stb_cst(name, N_MAIN, 0, (arith)0); } } #endif @@ -326,39 +343,43 @@ void begin_proc(struct decspecs *ds, struct idf *idf) /* to be called when ente void end_proc(arith fbytes) { /* end_proc() deals with the code to be generated at the end of - a function, as there is: - - the EM ret instruction: "ret 0" - - loading of the function result in the function - result area if there has been a return - in the function body (see do_return_expr()) - - indication of the use of floating points - - indication of the number of bytes used for - formal parameters - - use of special identifiers such as "__setjmp" - - "end" + number of bytes used for local variables + a function, as there is: + - the EM ret instruction: "ret 0" + - loading of the function result in the function + result area if there has been a return + in the function body (see do_return_expr()) + - indication of the use of floating points + - indication of the number of bytes used for + formal parameters + - use of special identifiers such as "__setjmp" + - "end" + number of bytes used for local variables */ arith nbytes; char optionsn = options['n']; -#ifdef DATAFLOW +#ifdef DATAFLOW if (options['d']) DfaEndFunction(); -#endif /* DATAFLOW */ +#endif /* DATAFLOW */ C_df_ilb(return2_label); - if (return_expr_occurred && struct_return == 0) { - C_asp(-func_size); + if (return_expr_occurred && struct_return == 0) + { + C_asp(-func_size); } C_df_ilb(return_label); prc_exit(); - if (return_expr_occurred) { - if (struct_return != 0) { - LoadLocal((arith) 0, pointer_size); + if (return_expr_occurred) + { + if (struct_return != 0) + { + LoadLocal((arith)0, pointer_size); C_ret(pointer_size); } else C_ret(func_size); } - else C_ret((arith) 0); + else + C_ret((arith)0); /* getting the number of "local" bytes is posponed until here, because copying the function result may need temporaries! @@ -366,17 +387,18 @@ void end_proc(arith fbytes) L_LOCAL is already unstacked. Therefore, "unstack_level" must also pass "sl_max_block" to the level above L_LOCAL. */ - nbytes = ATW(- local_level->sl_max_block); + nbytes = ATW(-local_level->sl_max_block); #ifdef USE_TMP C_beginpart(pro_id); C_pro(func_name, nbytes); #endif - if (fbytes > max_int) { - error("%s has more than %ld parameter bytes", - func_name, (long) max_int); + if (fbytes > max_int) + { + error("%s has more than %ld parameter bytes", func_name, (long)max_int); } - C_ms_par(fbytes); /* # bytes for formals */ - if (sp_occurred[SP_SETJMP]) { /* indicate use of "__setjmp" */ + C_ms_par(fbytes); /* # bytes for formals */ + if (sp_occurred[SP_SETJMP]) + { /* indicate use of "__setjmp" */ options['n'] = 1; C_ms_gto(); sp_occurred[SP_SETJMP] = 0; @@ -386,9 +408,9 @@ void end_proc(arith fbytes) #endif LocalFinish(); C_end(nbytes); - if (nbytes > max_int) { - error("%s has more than %ld bytes of local variables", - func_name, (long) max_int); + if (nbytes > max_int) + { + error("%s has more than %ld bytes of local variables", func_name, (long)max_int); } options['n'] = optionsn; } @@ -396,80 +418,84 @@ void end_proc(arith fbytes) void do_return(void) { /* do_return handles the case of a return without expression. - This version branches to the return label, which is - probably smarter than generating a direct return. - Return sequences may be expensive. + This version branches to the return label, which is + probably smarter than generating a direct return. + Return sequences may be expensive. */ #ifdef DBSYMTAB - if (options['g']) db_line(dot.tk_file, dot.tk_line); + if (options['g']) + db_line(dot.tk_file, dot.tk_line); #endif /* DBSYMTAB */ C_bra(return2_label); } -void do_return_expr(struct expr *expr) +void do_return_expr(struct expr* expr) { /* do_return_expr() generates the expression and the jump for - a return statement with an expression. + a return statement with an expression. */ ch3cast(&expr, RETURN, func_type); - code_expr(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); - if (struct_return != 0) { - LoadLocal((arith) 0, pointer_size); + code_expr(expr, RVAL, true, NO_LABEL, NO_LABEL); + if (struct_return != 0) + { + LoadLocal((arith)0, pointer_size); store_block(func_type->tp_size, func_type->tp_align); } C_bra(return_label); return_expr_occurred = 1; } -void -code_declaration( - struct idf *idf, /* idf to be declared */ - struct expr *expr, /* initialisation; NULL if absent */ - int lvl, /* declaration level */ - int sc) /* storage class, as in the declaration */ +void code_declaration( + struct idf* idf, /* idf to be declared */ + struct expr* expr, /* initialisation; NULL if absent */ + int lvl, /* declaration level */ + int sc) /* storage class, as in the declaration */ { /* code_declaration() does the actual declaration of the - variable indicated by "idf" on declaration level "lvl". - If the variable is initialised, the expression is given - in "expr", but for global and static initialisations it - is just non-zero, as the expression is not parsed yet. - There are some cases to be considered: - - filter out typedefs, they don't correspond to code; - - global variables, coded only if initialized; - - local static variables; - - local automatic variables; - Since the expression may be modified in the process, - code_declaration() frees it after use, as the caller can - no longer do so. - - If there is a storage class indication (EXTERN/STATIC), - code_declaration() will generate an exa or ina. - The sc is the actual storage class, as given in the - declaration. + variable indicated by "idf" on declaration level "lvl". + If the variable is initialised, the expression is given + in "expr", but for global and static initialisations it + is just non-zero, as the expression is not parsed yet. + There are some cases to be considered: + - filter out typedefs, they don't correspond to code; + - global variables, coded only if initialized; + - local static variables; + - local automatic variables; + Since the expression may be modified in the process, + code_declaration() frees it after use, as the caller can + no longer do so. + + If there is a storage class indication (EXTERN/STATIC), + code_declaration() will generate an exa or ina. + The sc is the actual storage class, as given in the + declaration. */ - struct def *def = idf->id_def; + struct def* def = idf->id_def; arith size = def->df_type->tp_size; int fund = def->df_type->tp_fund; int def_sc = def->df_sc; - - if (def_sc == TYPEDEF) { /* no code for typedefs */ + + if (def_sc == TYPEDEF) + { /* no code for typedefs */ #ifdef DBSYMTAB - if (options['g']) { + if (options['g']) + { stb_typedef(def->df_type, idf->id_text); } #endif /* DBSYMTAB */ return; } - if (lvl == L_GLOBAL) { /* global variable */ + if (lvl == L_GLOBAL) + { /* global variable */ /* is this an allocating declaration? */ - if ( (sc == 0 || sc == STATIC) - && fund != FUNCTION - ) + if ((sc == 0 || sc == STATIC) && fund != FUNCTION) def->df_alloc = ALLOC_SEEN; - if (expr && def_sc == STATIC && sc == EXTERN) { + if (expr && def_sc == STATIC && sc == EXTERN) + { warning("%s has internal linkage", idf->id_text); } - if (expr) { /* code only if initialized */ + if (expr) + { /* code only if initialized */ #ifndef PREPEND_SCOPES code_scope(idf->id_text, def); #endif /* PREPEND_SCOPES */ @@ -477,238 +503,255 @@ code_declaration( C_df_dnam(idf->id_text); } } - else - if (lvl >= L_LOCAL) { /* local variable */ + else if (lvl >= L_LOCAL) + { /* local variable */ /* STATIC, EXTERN, GLOBAL, AUTO or REGISTER */ - switch (def_sc) { - case STATIC: - if (fund == FUNCTION) { - /* should produce "inp $function" ??? */ - break; - } - /* they are handled on the spot and get an - integer label in EM. - */ + switch (def_sc) + { + case STATIC: + if (fund == FUNCTION) + { + /* should produce "inp $function" ??? */ + break; + } + /* they are handled on the spot and get an + integer label in EM. + */ #ifdef DBSYMTAB - if (options['g'] && ! expr) { - stb_string(def, sc, idf->id_text); - } + if (options['g'] && !expr) + { + stb_string(def, sc, idf->id_text); + } #endif /* DBSYMTAB */ - C_df_dlb((label)def->df_address); - if (expr) { /* there is an initialisation */ - } - else { /* produce blank space */ - if (size <= 0) { - error("size of %s unknown", idf->id_text); - size = (arith)0; + C_df_dlb((label)def->df_address); + if (expr) + { /* there is an initialisation */ } - C_bss_cst(ATW(size), (arith)0, 1); - } - break; - case EXTERN: - if (expr && !is_anon_idf(idf) && level != L_GLOBAL) - error("cannot initialize extern %s in block" - , idf->id_text); - case GLOBAL: - /* we are sure there is no expression */ - break; - case AUTO: - case REGISTER: + else + { /* produce blank space */ + if (size <= 0) + { + error("size of %s unknown", idf->id_text); + size = (arith)0; + } + C_bss_cst(ATW(size), (arith)0, 1); + } + break; + case EXTERN: + if (expr && !is_anon_idf(idf) && level != L_GLOBAL) + error("cannot initialize extern %s in block", idf->id_text); + case GLOBAL: + /* we are sure there is no expression */ + break; + case AUTO: + case REGISTER: #ifdef DBSYMTAB - if (options['g']) { - stb_string(def, sc, idf->id_text); - } + if (options['g']) + { + stb_string(def, sc, idf->id_text); + } #endif /* DBSYMTAB */ - if (expr) - loc_init(expr, idf); - else if ((fund == ARRAY) - && (def->df_type->tp_size == (arith)-1)) { - error("size for local %s unknown" - , idf->id_text); - } - break; - default: - crash("bad local storage class"); - UNREACHABLE_CODE; + if (expr) + loc_init(expr, idf); + else if ((fund == ARRAY) && (def->df_type->tp_size == (arith)-1)) + { + error("size for local %s unknown", idf->id_text); + } + break; + default: + crash("bad local storage class"); + UNREACHABLE_CODE; } } } -void loc_init(struct expr *expr, struct idf *id) +void loc_init(struct expr* expr, struct idf* id) { /* loc_init() generates code for the assignment of - expression expr to the local variable described by id. - It frees the expression afterwards. + expression expr to the local variable described by id. + It frees the expression afterwards. */ - struct expr *e = expr; - struct def *df = id->id_def; - struct type *tp = df->df_type; + struct expr* e = expr; + struct def* df = id->id_def; + struct type* tp = df->df_type; static arith tmpoffset = 0; static arith unknownsize = 0; - + assert(df->df_sc != STATIC); - switch (tp->tp_fund) { - case ARRAY: - if (tp->tp_size == (arith) -1) - unknownsize = 1; - case STRUCT: - case UNION: - if (e != (struct expr *) 0) { - break; /* switch */ - } else if (!tmpoffset) {/* first time for this variable */ - tmpoffset = df->df_address; - if (unknownsize) tmpoffset = -1; - df->df_address = data_label(); - C_df_dlb((label)df->df_address); - } else { - C_lae_dlb((label)df->df_address, (arith)0); - load_block(tp->tp_size, word_align); - if (unknownsize) { - /* tmpoffset += tp->tp_size; */ - unknownsize = 0; - - tmpoffset = NewLocal(tp->tp_size - , tp->tp_align - , regtype(tp) - , df->df_sc); + switch (tp->tp_fund) + { + case ARRAY: + if (tp->tp_size == (arith)-1) + unknownsize = 1; + case STRUCT: + case UNION: + if (e != (struct expr*)0) + { + break; /* switch */ + } + else if (!tmpoffset) + { /* first time for this variable */ + tmpoffset = df->df_address; + if (unknownsize) + tmpoffset = -1; + df->df_address = data_label(); + C_df_dlb((label)df->df_address); + } + else + { + C_lae_dlb((label)df->df_address, (arith)0); + load_block(tp->tp_size, word_align); + if (unknownsize) + { + /* tmpoffset += tp->tp_size; */ + unknownsize = 0; + + tmpoffset = NewLocal(tp->tp_size, tp->tp_align, regtype(tp), df->df_sc); + } + C_lal(tmpoffset); + store_block(tp->tp_size, tmpoffset % word_align ? 1 : word_align); + df->df_address = tmpoffset; + tmpoffset = 0; } - C_lal(tmpoffset); - store_block(tp->tp_size, tmpoffset % word_align ? 1 : word_align); - df->df_address = tmpoffset; - tmpoffset = 0; - } #ifdef DBSYMTAB - if (options['g']) { - stb_string(df, AUTO, id->id_text); - - } + if (options['g']) + { + stb_string(df, AUTO, id->id_text); + } #endif /* DBSYMTAB */ - return; + return; } - if (ISCOMMA(e)) { /* embraced: int i = {12}; */ - while (e) { + if (ISCOMMA(e)) + { /* embraced: int i = {12}; */ + while (e) + { loc_init(e->OP_LEFT, id); e = e->OP_RIGHT; } } - else { /* not embraced */ - ch3cast(&expr, '=', tp); /* may modify expr */ -#ifndef LINT + else + { /* not embraced */ + ch3cast(&expr, '=', tp); /* may modify expr */ +#ifndef LINT { struct value vl; - EVAL(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); + EVAL(expr, RVAL, true, NO_LABEL, NO_LABEL); vl.vl_class = Name; vl.vl_data.vl_idf = id; vl.vl_value = 0; store_val(&vl, tp); } -#else /* LINT */ +#else /* LINT */ id->id_def->df_set = 1; -#endif /* LINT */ +#endif /* LINT */ free_expression(expr); } } -void bss(struct idf *idf) +void bss(struct idf* idf) { /* bss() allocates bss space for the global idf. - */ - struct def *df = idf->id_def; - -#ifndef PREPEND_SCOPES + */ + struct def* df = idf->id_def; + +#ifndef PREPEND_SCOPES code_scope(idf->id_text, df); -#endif /* PREPEND_SCOPES */ +#endif /* PREPEND_SCOPES */ #ifdef DBSYMTAB - if (options['g']) { + if (options['g']) + { stb_string(df, df->df_sc, idf->id_text); } #endif /* DBSYMTAB */ - if (df->df_type->tp_size <= 0) { - if (df->df_sc != STATIC && - df->df_type->tp_fund == ARRAY && - df->df_type->tp_up && - df->df_type->tp_up->tp_size >= 0) { + if (df->df_type->tp_size <= 0) + { + if (df->df_sc != STATIC && df->df_type->tp_fund == ARRAY && df->df_type->tp_up + && df->df_type->tp_up->tp_size >= 0) + { C_df_dnam(idf->id_text); C_bss_cst(ATW(df->df_type->tp_up->tp_size), (arith)0, 1); } - else error("size of %s unknown (\"%s\", line %d)" - , idf->id_text, df->df_file, df->df_line); - } else { + else + error("size of %s unknown (\"%s\", line %d)", idf->id_text, df->df_file, df->df_line); + } + else + { C_df_dnam(idf->id_text); C_bss_cst(ATW(df->df_type->tp_size), (arith)0, 1); } } -void formal_cvt(int hasproto, struct def *df) +void formal_cvt(int hasproto, struct def* df) { /* formal_cvt() converts a formal parameter of type char or - short from int to that type. It also converts a formal - parameter of type float from a double to a float. + short from int to that type. It also converts a formal + parameter of type float from a double to a float. */ - struct type *tp = df->df_type; + struct type* tp = df->df_type; - if (tp->tp_size != int_size && - (tp->tp_fund == CHAR || tp->tp_fund == SHORT) - ) { + if (tp->tp_size != int_size && (tp->tp_fund == CHAR || tp->tp_fund == SHORT)) + { LoadLocal(df->df_address, int_size); /* conversion(int_type, df->df_type); ??? No, you can't do this on the stack! (CJ) */ StoreLocal(df->df_address, tp->tp_size); - } else if (tp->tp_size != double_size - && tp->tp_fund == FLOAT - && !hasproto) { + } + else if (tp->tp_size != double_size && tp->tp_fund == FLOAT && !hasproto) + { LoadLocal(df->df_address, double_size); -#ifndef LINT +#ifndef LINT conversion(double_type, float_type); -#endif /* LINT */ +#endif /* LINT */ StoreLocal(df->df_address, tp->tp_size); } } -#ifdef LINT +#ifdef LINT /*ARGSUSED*/ -#endif /* LINT */ -void code_expr(struct expr *expr, int val, int code, label tlbl, label flbl) +#endif /* LINT */ +void code_expr(struct expr* expr, int val, int code, label tlbl, label flbl) { /* code_expr() is the parser's interface to the expression code - generator. If line number trace is wanted, it generates a - lin instruction. EVAL() is called directly. + generator. If line number trace is wanted, it generates a + lin instruction. EVAL() is called directly. */ -#ifndef LINT - if (! options['L']) /* profiling */ +#ifndef LINT + if (!options['L']) /* profiling */ C_lin((arith)(expr->ex_line)); #ifdef DBSYMTAB - if (options['g']) db_line(expr->ex_file, (unsigned int)expr->ex_line); + if (options['g']) + db_line(expr->ex_file, (unsigned int)expr->ex_line); #endif EVAL(expr, val, code, tlbl, flbl); -#else /* LINT */ +#else /* LINT */ lint_expr(expr, code ? USED : IGNORED); -#endif /* LINT */ +#endif /* LINT */ } /* The FOR/WHILE/DO/SWITCH stacking mechanism: - stack_stmt() has to be called at the entrance of a - for, while, do or switch statement to indicate the - EM labels where a subsequent break or continue causes - the program to jump to. + stack_stmt() has to be called at the entrance of a + for, while, do or switch statement to indicate the + EM labels where a subsequent break or continue causes + the program to jump to. */ -static struct stmt_block *stmt_stack; /* top of statement stack */ +static struct stmt_block* stmt_stack; /* top of statement stack */ /* code_break() generates EM code needed at the occurrence of "break": - it generates a branch instruction to the break label of the - innermost statement in which break has a meaning. - As "break" is legal in any of 'while', 'do', 'for' or 'switch', - which are the only ones that are stacked, only the top of - the stack is interesting. + it generates a branch instruction to the break label of the + innermost statement in which break has a meaning. + As "break" is legal in any of 'while', 'do', 'for' or 'switch', + which are the only ones that are stacked, only the top of + the stack is interesting. */ void code_break(void) { - struct stmt_block *stmt_block = stmt_stack; + struct stmt_block* stmt_block = stmt_stack; #ifdef DBSYMTAB - if (options['g']) db_line(dot.tk_file, dot.tk_line); + if (options['g']) + db_line(dot.tk_file, dot.tk_line); #endif /* DBSYMTAB */ if (stmt_block) C_bra(stmt_block->st_break); @@ -717,19 +760,21 @@ void code_break(void) } /* code_continue() generates EM code needed at the occurrence of - "continue": - it generates a branch instruction to the continue label of the - innermost statement in which continue has a meaning. + "continue": + it generates a branch instruction to the continue label of the + innermost statement in which continue has a meaning. */ -void -code_continue(void) +void code_continue(void) { - struct stmt_block *stmt_block = stmt_stack; + struct stmt_block* stmt_block = stmt_stack; - while (stmt_block) { - if (stmt_block->st_continue) { + while (stmt_block) + { + if (stmt_block->st_continue) + { #ifdef DBSYMTAB - if (options['g']) db_line(dot.tk_file, dot.tk_line); + if (options['g']) + db_line(dot.tk_file, dot.tk_line); #endif /* DBSYMTAB */ C_bra(stmt_block->st_continue); return; @@ -741,7 +786,7 @@ code_continue(void) void stack_stmt(label break_label, label cont_label) { - struct stmt_block *stmt_block = new_stmt_block(); + struct stmt_block* stmt_block = new_stmt_block(); stmt_block->next = stmt_stack; stmt_block->st_break = break_label; @@ -752,9 +797,9 @@ void stack_stmt(label break_label, label cont_label) void unstack_stmt(void) { /* unstack_stmt() unstacks the data of a statement - which may contain break or continue + which may contain break or continue */ - struct stmt_block *sbp = stmt_stack; + struct stmt_block* sbp = stmt_stack; stmt_stack = sbp->next; free_stmt_block(sbp); } @@ -763,10 +808,11 @@ static label prc_name; void prc_entry(char* name) { - if (options['p']) { + if (options['p']) + { C_df_dlb(prc_name = data_label()); - C_rom_scon(name, (arith) (strlen(name) + 1)); - C_lae_dlb(prc_name, (arith) 0); + C_rom_scon(name, (arith)(strlen(name) + 1)); + C_lae_dlb(prc_name, (arith)0); C_cal("procentry"); C_asp(pointer_size); } @@ -774,21 +820,23 @@ void prc_entry(char* name) void prc_exit(void) { - if (options['p']) { - C_lae_dlb(prc_name, (arith) 0); + if (options['p']) + { + C_lae_dlb(prc_name, (arith)0); C_cal("procexit"); C_asp(pointer_size); } } #ifdef DBSYMTAB -void db_line(char *file, unsigned int line) +void db_line(char* file, unsigned int line) { static unsigned oldline; - static char *oldfile; + static char* oldfile; - if (file != oldfile || line != oldline) { - C_ms_std((char *) 0, N_SLINE, (int) line); + if (file != oldfile || line != oldline) + { + C_ms_std((char*)0, N_SLINE, (int)line); oldline = line; oldfile = file; } diff --git a/lang/cem/cemcom.ansi/code.str b/lang/cem/cemcom.ansi/code.str index 480d79e478..7f69b19f12 100644 --- a/lang/cem/cemcom.ansi/code.str +++ b/lang/cem/cemcom.ansi/code.str @@ -10,26 +10,25 @@ #include "arith.h" #include "label.h" - -struct string_cst { /* storing string constants */ - struct string_cst *next; - char *sc_value; +struct string_cst +{ /* storing string constants */ + struct string_cst* next; + char* sc_value; int sc_len; label sc_dlb; }; -extern struct string_cst *str_list; +extern struct string_cst* str_list; /* ALLOCDEF "string_cst" 5 */ -#define LVAL 0 -#define RVAL 1 -#define FALSE 0 -#define TRUE 1 - +#define LVAL 0 +#define RVAL 1 +#define FALSE 0 +#define TRUE 1 -#ifndef LINT -void init_code(char *dst_file); +#ifndef LINT +void init_code(char* dst_file); void end_code(void); #endif @@ -39,19 +38,18 @@ struct idf; struct decspecs; label code_string(char* val, int len); -void def_strings(register struct string_cst *sc); +void def_strings(register struct string_cst* sc); void flush_strings(void); -void code_scope(char* text, register struct def *def); -void begin_proc(struct decspecs *ds, struct idf *idf); +void code_scope(char* text, register struct def* def); +void begin_proc(struct decspecs* ds, struct idf* idf); void end_proc(arith fbytes); void do_return(void); -void do_return_expr(struct expr *expr); -void code_declaration(register struct idf *idf, struct expr *expr, - int lvl, int sc); -void loc_init(struct expr *expr, struct idf *id); -void bss(register struct idf *idf); -void formal_cvt(int hasproto, register struct def *df); -void code_expr(struct expr *expr, int val, int code, label tlbl, label flbl); +void do_return_expr(struct expr* expr); +void code_declaration(register struct idf* idf, struct expr* expr, int lvl, int sc); +void loc_init(struct expr* expr, struct idf* id); +void bss(register struct idf* idf); +void formal_cvt(int hasproto, register struct def* df); +void code_expr(struct expr* expr, int val, int code, label tlbl, label flbl); void code_break(void); void code_continue(void); void stack_stmt(label break_label, label cont_label); @@ -59,12 +57,12 @@ void unstack_stmt(void); void prc_entry(char* name); void prc_exit(void); -#ifdef PREPEND_SCOPES +#ifdef PREPEND_SCOPES void prepend_scopes(void); #endif #ifdef DBSYMTAB -void db_line(char *file, unsigned int line); +void db_line(char* file, unsigned int line); #endif #endif diff --git a/lang/cem/cemcom.ansi/conversion.c b/lang/cem/cemcom.ansi/conversion.c index 22986ef13b..ccb19102d9 100644 --- a/lang/cem/cemcom.ansi/conversion.c +++ b/lang/cem/cemcom.ansi/conversion.c @@ -5,148 +5,160 @@ /* $Id$ */ /* C O N V E R S I O N - C O D E G E N E R A T O R */ -#include "parameters.h" -#ifndef LINT +#include "parameters.h" +#ifndef LINT -#include "conversion.h" -#include -#include "interface.h" -#include "arith.h" -#include "type.h" -#include "sizes.h" -#include "Lpars.h" -#include "error.h" +#include +#include +#include "conversion.h" +#include +#include "interface.h" +#include "arith.h" +#include "type.h" +#include "sizes.h" +#include "Lpars.h" +#include "error.h" - -#define T_SIGNED 1 -#define T_UNSIGNED 2 -#define T_FLOATING 3 +#define T_SIGNED 1 +#define T_UNSIGNED 2 +#define T_FLOATING 3 /* conversion() generates the EM code for a conversion between - the types char, short, int, long, float, double and pointer. - There are three conversion types: signed, unsigned and floating. - The EM code to obtain this conversion looks like: - LOC sizeof(from_type) - LOC sizeof(to_type) - C?? + the types char, short, int, long, float, double and pointer. + There are three conversion types: signed, unsigned and floating. + The EM code to obtain this conversion looks like: + LOC sizeof(from_type) + LOC sizeof(to_type) + C?? */ -static int convtype(struct type *); +static int convtype(struct type*); -void conversion(struct type *from_type, struct type *to_type) +void conversion(struct type* from_type, struct type* to_type) { arith from_size = from_type->tp_size; arith to_size = to_type->tp_size; int from_cnvtype = convtype(from_type); int to_cnvtype = convtype(to_type); - if ((int)to_size < (int)word_size) to_size = word_size; - if ((int)from_size != (int)to_size || from_cnvtype != to_cnvtype) { - switch (from_cnvtype) { - case T_SIGNED: - switch (to_cnvtype) { - case T_SIGNED: - C_loc(from_size); - C_loc(to_size); - C_cii(); - break; - case T_UNSIGNED: - case T_FLOATING: - if ((int)from_size < (int)word_size) { + if ((int)to_size < (int)word_size) + to_size = word_size; + if ((int)from_size != (int)to_size || from_cnvtype != to_cnvtype) + { + switch (from_cnvtype) + { + case T_SIGNED: + switch (to_cnvtype) + { + case T_SIGNED: + C_loc(from_size); + C_loc(to_size); + C_cii(); + break; + case T_UNSIGNED: + case T_FLOATING: + if ((int)from_size < (int)word_size) + { + C_loc(from_size); + C_loc(word_size); + C_cii(); + from_size = word_size; + } + /* 3.2.1.2 */ + if (to_cnvtype == T_UNSIGNED && (int)from_size < (int)to_size) + { + C_loc(from_size); + C_loc(to_size); + C_cii(); + from_size = to_size; + } + C_loc(from_size); + C_loc(to_size); + if (to_cnvtype == T_UNSIGNED) + C_ciu(); + else + C_cif(); + break; + } + break; + case T_UNSIGNED: + if ((int)from_size < (int)word_size) + from_size = word_size; C_loc(from_size); - C_loc(word_size); - C_cii(); - from_size = word_size; - } - /* 3.2.1.2 */ - if (to_cnvtype == T_UNSIGNED - && (int)from_size < (int)to_size) { + C_loc(to_size); + switch (to_cnvtype) + { + case T_SIGNED: + C_cui(); + break; + case T_UNSIGNED: + C_cuu(); + break; + case T_FLOATING: + C_cuf(); + break; + } + break; + case T_FLOATING: C_loc(from_size); C_loc(to_size); - C_cii(); - from_size = to_size; - } - C_loc(from_size); - C_loc(to_size); - if (to_cnvtype == T_UNSIGNED) C_ciu(); - else C_cif(); - break; + switch (to_cnvtype) + { + case T_SIGNED: + C_cfi(); + break; + case T_UNSIGNED: + C_cfu(); + break; + case T_FLOATING: + C_cff(); + break; + } + break; + default: + crash("(conversion) illegal type conversion"); + UNREACHABLE_CODE; } - break; - case T_UNSIGNED: - if ((int)from_size < (int)word_size) from_size = word_size; - C_loc(from_size); - C_loc(to_size); - switch (to_cnvtype) { - case T_SIGNED: - C_cui(); - break; - case T_UNSIGNED: - C_cuu(); - break; - case T_FLOATING: - C_cuf(); - break; - } - break; - case T_FLOATING: - C_loc(from_size); - C_loc(to_size); - switch (to_cnvtype) { - case T_SIGNED: - C_cfi(); - break; - case T_UNSIGNED: - C_cfu(); - break; - case T_FLOATING: - C_cff(); - break; - } - break; - default: - crash("(conversion) illegal type conversion"); - UNREACHABLE_CODE; - } } - if ((int)(to_type->tp_size) < (int)word_size - && to_cnvtype != T_FLOATING - ) { - if (to_cnvtype == T_SIGNED) { + if ((int)(to_type->tp_size) < (int)word_size && to_cnvtype != T_FLOATING) + { + if (to_cnvtype == T_SIGNED) + { C_loc(to_type->tp_size); C_loc(word_size); C_cii(); } - else { - C_loc((arith) full_mask[(int)(to_type->tp_size)]); + else + { + C_loc((arith)full_mask[(int)(to_type->tp_size)]); C_and(word_size); } } } /* convtype() returns in which category a given type falls: - signed, unsigned or floating + signed, unsigned or floating */ -static int convtype(struct type *tp) +static int convtype(struct type* tp) { - switch (tp->tp_fund) { - case CHAR: - case SHORT: - case INT: - case ERRONEOUS: - case LONG: - case LNGLNG: - case ENUM: - return tp->tp_unsigned ? T_UNSIGNED : T_SIGNED; - case FLOAT: - case DOUBLE: - case LNGDBL: - return T_FLOATING; - case POINTER: - return T_UNSIGNED; + switch (tp->tp_fund) + { + case CHAR: + case SHORT: + case INT: + case ERRONEOUS: + case LONG: + case LNGLNG: + case ENUM: + return tp->tp_unsigned ? T_UNSIGNED : T_SIGNED; + case FLOAT: + case DOUBLE: + case LNGDBL: + return T_FLOATING; + case POINTER: + return T_UNSIGNED; } return 0; } -#endif /* LINT */ - +#endif /* LINT */ diff --git a/lang/cem/cemcom.ansi/conversion.h b/lang/cem/cemcom.ansi/conversion.h index 3c201109c0..ea21ef6774 100644 --- a/lang/cem/cemcom.ansi/conversion.h +++ b/lang/cem/cemcom.ansi/conversion.h @@ -1,15 +1,15 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-02-06 - * + * */ #ifndef CONVERSION_H_ #define CONVERSION_H_ struct type; -void conversion(struct type *from_type, struct type *to_type); +void conversion(struct type* from_type, struct type* to_type); #endif /* CONVERSION_H_ */ diff --git a/lang/cem/cemcom.ansi/cstoper.c b/lang/cem/cemcom.ansi/cstoper.c index d0e0818cf2..fcfe8a99b5 100644 --- a/lang/cem/cemcom.ansi/cstoper.c +++ b/lang/cem/cemcom.ansi/cstoper.c @@ -5,127 +5,132 @@ /* $Id$ */ /* C O N S T A N T E X P R E S S I O N H A N D L I N G */ -#include -#include "cstoper.h" -#include "parameters.h" -#include -#include "arith.h" -#include "type.h" -#include "label.h" -#include "expr.h" -#include "sizes.h" -#include "Lpars.h" -#include "error.h" +#include +#include +#include +#include "cstoper.h" +#include "parameters.h" +#include +#include "arith.h" +#include "type.h" +#include "label.h" +#include "expr.h" +#include "sizes.h" +#include "Lpars.h" +#include "error.h" /* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */ writh full_mask[MAXSIZE + 1]; #ifndef NOCROSS -arith max_int; /* maximum integer on target machine */ -arith max_unsigned; /* maximum unsigned on target machine */ +arith max_int; /* maximum integer on target machine */ +arith max_unsigned; /* maximum unsigned on target machine */ #endif /* NOCROSS */ extern int ResultKnown; -void cstbin(struct expr **expp, int oper, struct expr *expr) +void cstbin(struct expr** expp, int oper, struct expr* expr) { /* The operation oper is performed on the constant - expressions *expp(ld) and expr(ct), and the result restored in - *expp. + expressions *expp(ld) and expr(ct), and the result restored in + *expp. */ unsigned writh o1 = (unsigned writh)(*expp)->VL_VALUE; unsigned writh o2 = (unsigned writh)expr->VL_VALUE; int uns = (*expp)->ex_type->tp_unsigned; assert(is_ld_cst(*expp) && is_cp_cst(expr)); - switch (oper) { - case '*': - o1 *= o2; - break; - case '/': - if (o2 == 0) { - if (!ResultKnown) - expr_error(expr, "division by 0"); + switch (oper) + { + case '*': + o1 *= o2; + break; + case '/': + if (o2 == 0) + { + if (!ResultKnown) + expr_error(expr, "division by 0"); + else + expr_warning(expr, "division by 0"); + break; + } + if (uns) + o1 /= o2; else - expr_warning(expr, "division by 0"); + o1 = (unsigned writh)((writh)o1 / (writh)o2); break; - } - if (uns) - o1 /= o2; - else - o1 = (unsigned writh)((writh)o1 / (writh)o2); - break; - case '%': - if (o2 == 0) { - if (!ResultKnown) - expr_error(expr, "modulo by 0"); + case '%': + if (o2 == 0) + { + if (!ResultKnown) + expr_error(expr, "modulo by 0"); + else + expr_warning(expr, "modulo by 0"); + break; + } + if (uns) + o1 %= o2; else - expr_warning(expr, "modulo by 0"); + o1 = (unsigned writh)((writh)o1 % (writh)o2); break; - } - if (uns) - o1 %= o2; - else - o1 = (unsigned writh)((writh)o1 % (writh)o2); - break; - case '+': - o1 += o2; - break; - case '-': - o1 -= o2; - break; - case LEFT: - o1 <<= o2; - break; - case RIGHT: - if (o2 == 0) + case '+': + o1 += o2; break; - if (uns) - o1 >>= o2; - else - o1 = (unsigned writh)((writh)o1 >> (writh)o2); - break; - case '<': + case '-': + o1 -= o2; + break; + case LEFT: + o1 <<= o2; + break; + case RIGHT: + if (o2 == 0) + break; + if (uns) + o1 >>= o2; + else + o1 = (unsigned writh)((writh)o1 >> (writh)o2); + break; + case '<': { writh tmp = o1; o1 = o2; o2 = tmp; } - /* Fall through */ - case '>': - if (uns) - o1 = o1 > o2; - else - o1 = (writh)o1 > (writh)o2; - break; - case LESSEQ: + /* Fall through */ + case '>': + if (uns) + o1 = o1 > o2; + else + o1 = (writh)o1 > (writh)o2; + break; + case LESSEQ: { writh tmp = o1; o1 = o2; o2 = tmp; } - /* Fall through */ - case GREATEREQ: - if (uns) - o1 = o1 >= o2; - else - o1 = (writh)o1 >= (writh)o2; - break; - case EQUAL: - o1 = o1 == o2; - break; - case NOTEQUAL: - o1 = o1 != o2; - break; - case '&': - o1 &= o2; - break; - case '|': - o1 |= o2; - break; - case '^': - o1 ^= o2; - break; + /* Fall through */ + case GREATEREQ: + if (uns) + o1 = o1 >= o2; + else + o1 = (writh)o1 >= (writh)o2; + break; + case EQUAL: + o1 = o1 == o2; + break; + case NOTEQUAL: + o1 = o1 != o2; + break; + case '&': + o1 &= o2; + break; + case '|': + o1 |= o2; + break; + case '^': + o1 ^= o2; + break; } (*expp)->VL_VALUE = (writh)o1; cut_size(*expp); @@ -134,37 +139,39 @@ void cstbin(struct expr **expp, int oper, struct expr *expr) free_expression(expr); } -void cut_size(struct expr *expr) +void cut_size(struct expr* expr) { /* The constant value of the expression expr is made to - conform to the size of the type of the expression. + conform to the size of the type of the expression. */ writh o1 = expr->VL_VALUE; int uns = expr->ex_type->tp_unsigned; - int size = (int) expr->ex_type->tp_size; + int size = (int)expr->ex_type->tp_size; assert(expr->ex_class == Value); - if (expr->ex_type->tp_fund == POINTER) { + if (expr->ex_type->tp_fund == POINTER) + { /* why warn on "ptr-3" ? This quick hack fixes it */ uns = 0; } - if (uns) { + if (uns) + { if (o1 & ~full_mask[size]) - if (!ResultKnown) - expr_warning(expr, - "overflow in unsigned constant expression"); + if (!ResultKnown) + expr_warning(expr, "overflow in unsigned constant expression"); o1 &= full_mask[size]; } - else { - int nbits = (int) (sizeof(o1) - size) * 8; + else + { + int nbits = (int)(sizeof(o1) - size) * 8; writh remainder = o1 & ~full_mask[size]; if (remainder != 0 && remainder != ~full_mask[size]) - if (!ResultKnown) - expr_warning(expr,"overflow in constant expression"); - o1 = (o1 << nbits) >> nbits; /* ??? */ + if (!ResultKnown) + expr_warning(expr, "overflow in constant expression"); + o1 = (o1 << nbits) >> nbits; /* ??? */ } expr->VL_VALUE = o1; } @@ -174,15 +181,15 @@ void init_cst(void) int i = 0; unsigned writh bt = 0; - while (!((writh)bt < 0)) { + while (!((writh)bt < 0)) + { bt = (bt << 8) + 0377, i++; if (i > MAXSIZE) fatal("array full_mask too small for this machine"); full_mask[i] = bt; } /* signed comparison; lnglng_size might be -1 */ - if (long_size > (arith)sizeof(writh) || - lnglng_size > (arith)sizeof(writh)) + if (long_size > (arith)sizeof(writh) || lnglng_size > (arith)sizeof(writh)) fatal("sizeof(writh) insufficient on this machine"); #ifndef NOCROSS max_int = (arith)((unsigned writh)full_mask[(int)int_size] >> 1); diff --git a/lang/cem/cemcom.ansi/cstoper.h b/lang/cem/cemcom.ansi/cstoper.h index 68065b6e32..41391a6131 100644 --- a/lang/cem/cemcom.ansi/cstoper.h +++ b/lang/cem/cemcom.ansi/cstoper.h @@ -1,17 +1,17 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-02-06 - * + * */ #ifndef CSTOPER_H_ #define CSTOPER_H_ struct expr; -void cstbin(struct expr **expp, int oper, struct expr *expr); -void cut_size(struct expr *expr); +void cstbin(struct expr** expp, int oper, struct expr* expr); +void cut_size(struct expr* expr); void init_cst(void); #endif /* CSTOPER_H_ */ diff --git a/lang/cem/cemcom.ansi/dataflow.c b/lang/cem/cemcom.ansi/dataflow.c index c565359d5a..d54d74b2a5 100644 --- a/lang/cem/cemcom.ansi/dataflow.c +++ b/lang/cem/cemcom.ansi/dataflow.c @@ -6,15 +6,17 @@ /* DATAFLOW ANALYSIS ON C PROGRAMS */ /* Compile the C compiler with flag DATAFLOW. - Use the compiler option --d. + Use the compiler option --d. */ -#include -#include "parameters.h" /* UF */ -#include "dataflow.h" +#include +#include +#include +#include "parameters.h" /* UF */ +#include "dataflow.h" -#ifdef DATAFLOW -char *CurrentFunction = 0; +#ifdef DATAFLOW +char* CurrentFunction = 0; int NumberOfCalls; void DfaStartFunction(char* nm) @@ -34,4 +36,4 @@ void DfaCallFunction(char* s) printf("DFA: %s: %s\n", CurrentFunction, s); ++NumberOfCalls; } -#endif /* DATAFLOW */ +#endif /* DATAFLOW */ diff --git a/lang/cem/cemcom.ansi/dataflow.h b/lang/cem/cemcom.ansi/dataflow.h index e353b9ac8a..0131b389f0 100644 --- a/lang/cem/cemcom.ansi/dataflow.h +++ b/lang/cem/cemcom.ansi/dataflow.h @@ -1,14 +1,14 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-02-06 - * + * */ #ifndef DATAFLOW_H_ #define DATAFLOW_H_ -#ifdef DATAFLOW +#ifdef DATAFLOW void DfaStartFunction(char* nm); void DfaEndFunction(void); diff --git a/lang/cem/cemcom.ansi/declar.g b/lang/cem/cemcom.ansi/declar.g index bcf3877ab6..f75fa7c08d 100644 --- a/lang/cem/cemcom.ansi/declar.g +++ b/lang/cem/cemcom.ansi/declar.g @@ -7,6 +7,8 @@ { #include "parameters.h" +#include +#include #include #include #include "idf.h" diff --git a/lang/cem/cemcom.ansi/declar.str b/lang/cem/cemcom.ansi/declar.str index c8eb50f400..470cfe4e22 100644 --- a/lang/cem/cemcom.ansi/declar.str +++ b/lang/cem/cemcom.ansi/declar.str @@ -2,40 +2,42 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ - #ifndef DECLAR_H_ - #define DECLAR_H_ - +#ifndef DECLAR_H_ +#define DECLAR_H_ + /* $Id$ */ /* DEFINITION OF DECLARATOR DESCRIPTORS */ /* A 'declarator' consists of an idf and a linked list of - language-defined unary operations: *, [] and (), called - decl_unary's. + language-defined unary operations: *, [] and (), called + decl_unary's. */ -struct declarator { +struct declarator +{ /* struct declarator *next; */ - struct idf *dc_idf; - struct decl_unary *dc_decl_unary; - struct formal *dc_formal; /* params for function */ + struct idf* dc_idf; + struct decl_unary* dc_decl_unary; + struct formal* dc_formal; /* params for function */ }; -struct formal { /* list of formals */ - struct formal *next; - struct idf *fm_idf; +struct formal +{ /* list of formals */ + struct formal* next; + struct idf* fm_idf; }; /* ALLOCDEF "formal" 5 */ +#define NO_PARAMS ((struct formal*)0) -#define NO_PARAMS ((struct formal *) 0) - -struct decl_unary { - struct decl_unary *next; - int du_fund; /* POINTER, ARRAY or FUNCTION */ - int du_typequal; /* CONST, VOLATILE, or 0 */ - arith du_count; /* for ARRAYs only */ - struct proto *du_proto; /* params for function or prototype */ +struct decl_unary +{ + struct decl_unary* next; + int du_fund; /* POINTER, ARRAY or FUNCTION */ + int du_typequal; /* CONST, VOLATILE, or 0 */ + arith du_count; /* for ARRAYs only */ + struct proto* du_proto; /* params for function or prototype */ }; /* ALLOCDEF "decl_unary" 10 */ diff --git a/lang/cem/cemcom.ansi/declarator.c b/lang/cem/cemcom.ansi/declarator.c index 9e967be258..68e1b60cfe 100644 --- a/lang/cem/cemcom.ansi/declarator.c +++ b/lang/cem/cemcom.ansi/declarator.c @@ -5,66 +5,69 @@ /* $Id$ */ /* D E C L A R A T O R M A N I P U L A T I O N */ -#include "parameters.h" -#include "declarator.h" -#include -#include -#include "arith.h" -#include "type.h" -#include "proto.h" -#include "Lpars.h" -#include "declar.h" -#include "def.h" -#include "idf.h" -#include "label.h" -#include "expr.h" -#include "sizes.h" -#include "level.h" -#include "error.h" +#include "parameters.h" +#include +#include +#include "declarator.h" +#include +#include +#include "arith.h" +#include "type.h" +#include "proto.h" +#include "Lpars.h" +#include "declar.h" +#include "def.h" +#include "idf.h" +#include "label.h" +#include "expr.h" +#include "sizes.h" +#include "level.h" +#include "error.h" extern char options[]; struct declarator null_declarator; -struct type * -declare_type( - struct type *tp, - struct declarator *dc) +struct type* declare_type(struct type* tp, struct declarator* dc) { /* Applies the decl_unary list starting at dc->dc_decl_unary - to the type tp and returns the result. - Functions that are declared within a parameter type list - are purely prototypes. Simply add the type list to the - function node. + to the type tp and returns the result. + Functions that are declared within a parameter type list + are purely prototypes. Simply add the type list to the + function node. */ - struct decl_unary *du = dc->dc_decl_unary; + struct decl_unary* du = dc->dc_decl_unary; - while (du) { - tp = construct_type(du->du_fund, tp, du->du_typequal, - du->du_count, du->du_proto); + while (du) + { + tp = construct_type(du->du_fund, tp, du->du_typequal, du->du_count, du->du_proto); du = du->next; } return tp; } -void add_decl_unary(struct declarator *dc, int fund, int qual, arith count, struct formal *fm, struct proto *pl) +void add_decl_unary( + struct declarator* dc, int fund, int qual, arith count, struct formal* fm, struct proto* pl) { /* A decl_unary describing a constructor with fundamental - type fund and with size count is inserted in front of the - declarator dc. + type fund and with size count is inserted in front of the + declarator dc. */ - struct decl_unary *new = new_decl_unary(); + struct decl_unary* new = new_decl_unary(); new->next = dc->dc_decl_unary; new->du_fund = fund; new->du_count = count; new->du_typequal = qual; new->du_proto = pl; - if (fm) { - if (dc->dc_decl_unary) { + if (fm) + { + if (dc->dc_decl_unary) + { /* parameters only allowed at first decl_unary */ error("formal parameters list discarded"); } - else { + else + { /* register the proto */ dc->dc_formal = fm; } @@ -73,41 +76,47 @@ void add_decl_unary(struct declarator *dc, int fund, int qual, arith count, str dc->dc_decl_unary = new; } -void remove_declarator(struct declarator *dc) +void remove_declarator(struct declarator* dc) { /* The decl_unary list starting at dc->dc_decl_unary is - removed. + removed. */ - struct decl_unary *du = dc->dc_decl_unary; + struct decl_unary* du = dc->dc_decl_unary; - while (du) { - struct decl_unary *old_du = du; + while (du) + { + struct decl_unary* old_du = du; du = du->next; free_decl_unary(old_du); } } -void reject_params(struct declarator *dc) +void reject_params(struct declarator* dc) { /* The declarator is checked to have no parameters, if it - is an old-style function. If it is a new-style function, - the identifiers are removed. The function is not called in - case of a function definition. + is an old-style function. If it is a new-style function, + the identifiers are removed. The function is not called in + case of a function definition. */ - struct decl_unary *du = dc->dc_decl_unary; - int err_given = 0; + struct decl_unary* du = dc->dc_decl_unary; + int err_given = 0; - if (dc->dc_formal) { + if (dc->dc_formal) + { error("non_empty formal parameter pack"); free_formals(dc->dc_formal); dc->dc_formal = 0; err_given = 1; } - while (du) { - if (du->du_fund == FUNCTION) { - if (du->du_proto) remove_proto_idfs(du->du_proto); - else if (! err_given && ! options['o']) { + while (du) + { + if (du->du_fund == FUNCTION) + { + if (du->du_proto) + remove_proto_idfs(du->du_proto); + else if (!err_given && !options['o']) + { err_given = 1; warning("old-fashioned function declaration"); } @@ -116,20 +125,21 @@ void reject_params(struct declarator *dc) } } -void check_array_subscript(struct expr *expr) +void check_array_subscript(struct expr* expr) { writh size = expr->VL_VALUE; - if (size < 0) { + if (size < 0) + { error("array size is negative"); expr->VL_VALUE = 1; } - else - if (size == 0) { + else if (size == 0) + { strict("array size is 0"); } - else - if (size & ~max_unsigned) { /* absolutely ridiculous */ + else if (size & ~max_unsigned) + { /* absolutely ridiculous */ expr_error(expr, "overflow in array size"); expr->VL_VALUE = 1; } diff --git a/lang/cem/cemcom.ansi/declarator.h b/lang/cem/cemcom.ansi/declarator.h index c5eb51198d..8200474920 100644 --- a/lang/cem/cemcom.ansi/declarator.h +++ b/lang/cem/cemcom.ansi/declarator.h @@ -1,9 +1,9 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-02-06 - * + * */ #ifndef DECLARATOR_H_ #define DECLARATOR_H_ @@ -17,12 +17,11 @@ struct formal; struct proto; struct expr; -struct type * -declare_type(struct type *tp, struct declarator *dc); -void add_decl_unary(struct declarator *dc, int fund, int qual, - arith count, struct formal *fm, struct proto *pl); -void remove_declarator(struct declarator *dc); -void reject_params(struct declarator *dc); -void check_array_subscript(struct expr *expr); +struct type* declare_type(struct type* tp, struct declarator* dc); +void add_decl_unary( + struct declarator* dc, int fund, int qual, arith count, struct formal* fm, struct proto* pl); +void remove_declarator(struct declarator* dc); +void reject_params(struct declarator* dc); +void check_array_subscript(struct expr* expr); #endif /* DECLARATOR_H_ */ diff --git a/lang/cem/cemcom.ansi/decspecs.c b/lang/cem/cemcom.ansi/decspecs.c index 99d6380c74..6110d52e6c 100644 --- a/lang/cem/cemcom.ansi/decspecs.c +++ b/lang/cem/cemcom.ansi/decspecs.c @@ -5,27 +5,29 @@ /* $Id$ */ /* D E C L A R A T I O N S P E C I F I E R C H E C K I N G */ -#include -#include "decspecs.h" -#include "Lpars.h" -#include "arith.h" -#include "LLlex.h" -#include "type.h" -#include "level.h" -#include "def.h" -#include "error.h" +#include +#include +#include +#include "decspecs.h" +#include "Lpars.h" +#include "arith.h" +#include "LLlex.h" +#include "type.h" +#include "level.h" +#include "def.h" +#include "error.h" extern char options[]; extern int level; struct decspecs null_decspecs; -void do_decspecs(struct decspecs *ds) +void do_decspecs(struct decspecs* ds) { /* The provisional decspecs ds as obtained from the program is turned into a legal consistent decspecs. */ - struct type *tp = ds->ds_type; + struct type* tp = ds->ds_type; assert(level != L_FORMAL1); @@ -47,7 +49,7 @@ void do_decspecs(struct decspecs *ds) /* Since type qualifiers may be associated with types by means of typedefs, we have to perform same basic tests down here. */ - if (tp != (struct type *) 0) + if (tp != (struct type*)0) { if ((ds->ds_typequal & TQ_VOLATILE) && (tp->tp_typequal & TQ_VOLATILE)) error("indirect repeated type qualifier"); @@ -95,7 +97,8 @@ void do_decspecs(struct decspecs *ds) } else { - SIZE_ERROR: error("%s with illegal type", symbol2str(ds->ds_size)); + SIZE_ERROR: + error("%s with illegal type", symbol2str(ds->ds_size)); } ds->ds_notypegiven = 0; } @@ -137,8 +140,8 @@ void do_decspecs(struct decspecs *ds) } else { - SIGN_ERROR: error("%s with illegal type", - symbol2str(ds->ds_unsigned)); + SIGN_ERROR: + error("%s with illegal type", symbol2str(ds->ds_unsigned)); } ds->ds_notypegiven = 0; } @@ -151,9 +154,9 @@ void do_decspecs(struct decspecs *ds) In case of a complex type the top of the type list will be replaced by a qualified version. */ -struct type *qualifier_type(struct type *tp, int typequal) +struct type* qualifier_type(struct type* tp, int typequal) { - struct type *dtp = tp; + struct type* dtp = tp; int fund = tp->tp_fund; while (dtp && dtp->tp_typequal != typequal) @@ -174,32 +177,32 @@ struct type *qualifier_type(struct type *tp, int typequal) #endif switch (fund) { - case ARRAY: - if (typequal) - { - tp->tp_up = qualifier_type(tp->tp_up, typequal); - dtp->tp_typequal = typequal = 0; - } - goto nottagged; - case FIELD: - dtp->tp_field = tp->tp_field; - /* fallthrough */ - case POINTER: - case FUNCTION: /* dont't assign tp_proto */ - nottagged: dtp->tp_up = tp->tp_up; - break; - case STRUCT: - case UNION: - case ENUM: - dtp->tp_idf = tp->tp_idf; - dtp->tp_sdef = tp->tp_sdef; - break; - default: - break; + case ARRAY: + if (typequal) + { + tp->tp_up = qualifier_type(tp->tp_up, typequal); + dtp->tp_typequal = typequal = 0; + } + goto nottagged; + case FIELD: + dtp->tp_field = tp->tp_field; + /* fallthrough */ + case POINTER: + case FUNCTION: /* dont't assign tp_proto */ + nottagged: + dtp->tp_up = tp->tp_up; + break; + case STRUCT: + case UNION: + case ENUM: + dtp->tp_idf = tp->tp_idf; + dtp->tp_sdef = tp->tp_sdef; + break; + default: + break; } dtp->next = tp->next; /* don't know head or tail */ tp->next = dtp; } return (dtp); } - diff --git a/lang/cem/cemcom.ansi/decspecs.h b/lang/cem/cemcom.ansi/decspecs.h index 24ac7f0616..2bfa2aebd7 100644 --- a/lang/cem/cemcom.ansi/decspecs.h +++ b/lang/cem/cemcom.ansi/decspecs.h @@ -8,24 +8,25 @@ /* $Id$ */ /* DECLARATION SPECIFIER DEFINITION */ -struct decspecs { - struct decspecs *next; - struct type *ds_type; /* single type */ - int ds_notypegiven; /* set if type not given explicitly */ - int ds_typedef; /* 1 if type was a user typedef */ - int ds_sc_given; /* 1 if the st. class is explicitly given */ - int ds_sc; /* storage class, given or implied */ - int ds_size; /* LONG, SHORT or 0 */ - int ds_unsigned; /* SIGNED, UNSIGNED or 0 */ - int ds_typequal; /* type qualifiers - see type.str */ +struct decspecs +{ + struct decspecs* next; + struct type* ds_type; /* single type */ + int ds_notypegiven; /* set if type not given explicitly */ + int ds_typedef; /* 1 if type was a user typedef */ + int ds_sc_given; /* 1 if the st. class is explicitly given */ + int ds_sc; /* storage class, given or implied */ + int ds_size; /* LONG, SHORT or 0 */ + int ds_unsigned; /* SIGNED, UNSIGNED or 0 */ + int ds_typequal; /* type qualifiers - see type.str */ }; -extern struct type *qualifier_type(struct type* tp, int typequal); +extern struct type* qualifier_type(struct type* tp, int typequal); extern struct decspecs null_decspecs; struct type; -void do_decspecs(struct decspecs *ds); -struct type *qualifier_type(struct type *tp, int typequal); +void do_decspecs(struct decspecs* ds); +struct type* qualifier_type(struct type* tp, int typequal); #endif diff --git a/lang/cem/cemcom.ansi/def.str b/lang/cem/cemcom.ansi/def.str index 9907198a61..5bb8051f0c 100644 --- a/lang/cem/cemcom.ansi/def.str +++ b/lang/cem/cemcom.ansi/def.str @@ -8,38 +8,39 @@ /* $Id$ */ /* IDENTIFIER DEFINITION DESCRIPTOR */ -#include "alloc.h" -#include "parameters.h" +#include "alloc.h" +#include "parameters.h" -struct def { /* for ordinary tags */ - struct def *next; +struct def +{ /* for ordinary tags */ + struct def* next; int df_level; - struct type *df_type; - int df_sc; /* may be: - GLOBAL, STATIC, EXTERN, - TYPEDEF, - FORMAL, AUTO, - ENUM, LABEL - */ - char df_initialized; /* an initialization has been generated */ - char df_alloc; /* 0, ALLOC_SEEN or ALLOC_DONE */ - char df_used; /* set if idf is used */ - char df_formal_array; /* to warn if sizeof is taken */ - char *df_file; /* file containing the definition */ - unsigned int df_line; /* line number of the definition */ -#ifdef LINT + struct type* df_type; + int df_sc; /* may be: + GLOBAL, STATIC, EXTERN, + TYPEDEF, + FORMAL, AUTO, + ENUM, LABEL + */ + char df_initialized; /* an initialization has been generated */ + char df_alloc; /* 0, ALLOC_SEEN or ALLOC_DONE */ + char df_used; /* set if idf is used */ + char df_formal_array; /* to warn if sizeof is taken */ + char* df_file; /* file containing the definition */ + unsigned int df_line; /* line number of the definition */ +#ifdef LINT char df_set; - int df_firstbrace; /* brace number of its first occurrence */ - int df_minlevel; /* the lowest level needed for this def */ -#endif /* LINT */ + int df_firstbrace; /* brace number of its first occurrence */ + int df_minlevel; /* the lowest level needed for this def */ +#endif /* LINT */ arith df_address; }; -#define ALLOC_SEEN 1 /* an allocating declaration has been seen */ -#define ALLOC_DONE 2 /* the allocating declaration has been done */ +#define ALLOC_SEEN 1 /* an allocating declaration has been seen */ +#define ALLOC_DONE 2 /* the allocating declaration has been done */ -#define REG_DEFAULT 0 /* register candidate, not declared as such */ -#define REG_BONUS 10 /* register candidate, declared as such */ +#define REG_DEFAULT 0 /* register candidate, not declared as such */ +#define REG_BONUS 10 /* register candidate, declared as such */ /* ALLOCDEF "def" 50 */ diff --git a/lang/cem/cemcom.ansi/domacro.c b/lang/cem/cemcom.ansi/domacro.c index dc77827ea3..c789b73e19 100644 --- a/lang/cem/cemcom.ansi/domacro.c +++ b/lang/cem/cemcom.ansi/domacro.c @@ -5,6 +5,8 @@ /* $Id$ */ /* PREPROCESSOR: CONTROLLINE INTERPRETER */ +#include +#include #include #include #include diff --git a/lang/cem/cemcom.ansi/domacro.h b/lang/cem/cemcom.ansi/domacro.h index 75d6085a0b..ae890b8d30 100644 --- a/lang/cem/cemcom.ansi/domacro.h +++ b/lang/cem/cemcom.ansi/domacro.h @@ -1,16 +1,16 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-02-06 - * + * */ #ifndef DOMACRO_H_ #define DOMACRO_H_ struct idf; -struct idf* GetIdentifier(int skiponerr) ; +struct idf* GetIdentifier(int skiponerr); void domacro(void); #endif /* DOMACRO_H_ */ diff --git a/lang/cem/cemcom.ansi/dumpidf.c b/lang/cem/cemcom.ansi/dumpidf.c index aa4594478b..7fe308c202 100644 --- a/lang/cem/cemcom.ansi/dumpidf.c +++ b/lang/cem/cemcom.ansi/dumpidf.c @@ -5,25 +5,26 @@ /* $Id$ */ /* DUMP ROUTINES */ - -#include "parameters.h" -#ifdef DEBUG -#include -#include -#include -#include "arith.h" -#include "stack.h" -#include "def.h" -#include "idf.h" -#include "type.h" -#include "proto.h" -#include "struct.h" -#include "field.h" -#include "Lpars.h" -#include "label.h" -#include "expr.h" +#include +#include +#include "parameters.h" +#ifdef DEBUG +#include +#include +#include +#include "arith.h" +#include "stack.h" +#include "def.h" +#include "idf.h" +#include "type.h" +#include "proto.h" +#include "struct.h" +#include "field.h" +#include "Lpars.h" +#include "label.h" +#include "expr.h" /*#include "static.h"*/ -#include "declar.h" +#include "declar.h" /* Some routines (symbol2str, type2str, qual2str) which should have * yielded strings are written to yield a pointer to a transient piece @@ -33,37 +34,40 @@ * consumed immediately. Sometimes we need more than one of them, and * MAXTRANS is the maximum number we will need simultaneously. */ -#define MAXTRANS 6 +#define MAXTRANS 6 extern char options[]; +extern struct idf* idf_hashtable[]; -extern struct idf *idf_hashtable[]; - - -enum sdef_kind {selector, field}; /* parameter for dumpsdefs */ +enum sdef_kind +{ + selector, + field +}; /* parameter for dumpsdefs */ static int dumplevel; /* Forward declarations */ static void dumpstack(void); -static char *next_transient(void); -static char *qual2str(int); -static char *type2str(struct type *); +static char* next_transient(void); +static char* qual2str(int); +static char* type2str(struct type*); static void p1_indent(int); -static void dumpdefs(struct def *, int); -void dumpidf(struct idf *, int); -void dumptags(struct tag *); -void dumptype(struct type *); -void dumpsdefs(struct sdef *, enum sdef_kind); -static void p1_expr(int, struct expr *); +static void dumpdefs(struct def*, int); +void dumpidf(struct idf*, int); +void dumptags(struct tag*); +void dumptype(struct type*); +void dumpsdefs(struct sdef*, enum sdef_kind); +static void p1_expr(int, struct expr*); void newline(void) { int dl = dumplevel; - + printf("\n"); - while (dl >= 2) { + while (dl >= 2) + { printf("\t"); dl -= 2; } @@ -71,15 +75,13 @@ void newline(void) printf(" "); } - - void dumpidftab(char msg[], int opt) { /* Dumps the identifier table in readable form (but in - arbitrary order). - Unless opt & 1, macros are not dumped. - Unless opt & 2, reserved identifiers are not dumped. - Unless opt & 4, universal identifiers are not dumped. + arbitrary order). + Unless opt & 1, macros are not dumped. + Unless opt & 2, reserved identifiers are not dumped. + Unless opt & 4, universal identifiers are not dumped. */ printf(">>> DUMPIDF, %s (start)", msg); @@ -92,15 +94,17 @@ void dumpidftab(char msg[], int opt) static void dumpstack(void) { /* Dumps the identifier stack, starting at the top. - */ - struct stack_level *stl = local_level; - - while (stl) { - struct stack_entry *se = stl->sl_entry; - + */ + struct stack_level* stl = local_level; + + while (stl) + { + struct stack_entry* se = stl->sl_entry; + newline(); printf("%3d: ", stl->sl_level); - while (se) { + while (se) + { printf("%s ", se->se_idf->id_text); se = se->next; } @@ -109,38 +113,46 @@ static void dumpstack(void) printf("\n"); } -void dumpidf(struct idf *idf, int opt) +void dumpidf(struct idf* idf, int opt) { /* All information about the identifier idf is divulged in a - hopefully readable format. + hopefully readable format. */ int started = 0; - + if (!idf) return; - if ((opt&2) && idf->id_reserved) { - if (!started++) { + if ((opt & 2) && idf->id_reserved) + { + if (!started++) + { newline(); printf("%s:", idf->id_text); } printf(" reserved: %d;", idf->id_reserved); } - if (idf->id_def && ((opt&4) || idf->id_def->df_level)) { - if (!started++) { + if (idf->id_def && ((opt & 4) || idf->id_def->df_level)) + { + if (!started++) + { newline(); printf("%s:", idf->id_text); } dumpdefs(idf->id_def, opt); } - if (idf->id_sdef) { - if (!started++) { + if (idf->id_sdef) + { + if (!started++) + { newline(); printf("%s:", idf->id_text); } dumpsdefs(idf->id_sdef, selector); } - if (idf->id_tag) { - if (!started++) { + if (idf->id_tag) + { + if (!started++) + { newline(); printf("%s:", idf->id_text); } @@ -148,43 +160,41 @@ void dumpidf(struct idf *idf, int opt) } } -void dumpdefs(struct def *def, int opt) +void dumpdefs(struct def* def, int opt) { dumplevel++; - while (def && ((opt&4) || def->df_level)) { + while (def && ((opt & 4) || def->df_level)) + { newline(); - printf("L%d: %s %s%stype%s %lo; ", - def->df_level, - symbol2str(def->df_sc), - def->df_initialized ? "init'd " : "", - def->df_used ? "used " : "", - def->df_sc == ENUM ? ", =" : " at", - def->df_address - ); - printf("%s, line %u", - def->df_file ? def->df_file : "NO_FILE", def->df_line); + printf( + "L%d: %s %s%stype%s %lo; ", def->df_level, symbol2str(def->df_sc), + def->df_initialized ? "init'd " : "", def->df_used ? "used " : "", + def->df_sc == ENUM ? ", =" : " at", def->df_address); + printf("%s, line %u", def->df_file ? def->df_file : "NO_FILE", def->df_line); dumptype(def->df_type); def = def->next; } dumplevel--; } -void dumptags(struct tag *tag) +void dumptags(struct tag* tag) { dumplevel++; - while (tag) { - struct type *tp = tag->tg_type; + while (tag) + { + struct type* tp = tag->tg_type; int fund = tp->tp_fund; newline(); - printf("L%d: %s %s", - tag->tg_level, - fund == STRUCT ? "struct" : - fund == UNION ? "union" : - fund == ENUM ? "enum" : "", - tp->tp_idf->id_text - ); - if (is_struct_or_union(fund)) { + printf( + "L%d: %s %s", tag->tg_level, + fund == STRUCT ? "struct" + : fund == UNION ? "union" + : fund == ENUM ? "enum" + : "", + tp->tp_idf->id_text); + if (is_struct_or_union(fund)) + { printf(" {"); dumpsdefs(tp->tp_sdef, field); newline(); @@ -196,56 +206,57 @@ void dumptags(struct tag *tag) dumplevel--; } -void dumpsdefs(struct sdef *sdef, enum sdef_kind sdk) +void dumpsdefs(struct sdef* sdef, enum sdef_kind sdk) { /* Since sdef's are members of two chains, there are actually - two dumpsdefs's, one following the chain of all selectors - belonging to the same idf, starting at idf->id_sdef; - and the other following the chain of all selectors belonging - to the same struct, starting at stp->tp_sdef. + two dumpsdefs's, one following the chain of all selectors + belonging to the same idf, starting at idf->id_sdef; + and the other following the chain of all selectors belonging + to the same struct, starting at stp->tp_sdef. */ dumplevel++; - while (sdef) { + while (sdef) + { newline(); printf("L%d: ", sdef->sd_level); #ifndef NOBITFIELD if (sdk == selector) #endif /* NOBITFIELD */ - printf("selector %s at offset %lu in %s;", - type2str(sdef->sd_type), - sdef->sd_offset, type2str(sdef->sd_stype) - ); + printf( + "selector %s at offset %lu in %s;", type2str(sdef->sd_type), sdef->sd_offset, + type2str(sdef->sd_stype)); #ifndef NOBITFIELD - else printf("field %s at offset %lu;", - type2str(sdef->sd_type), sdef->sd_offset - ); + else + printf("field %s at offset %lu;", type2str(sdef->sd_type), sdef->sd_offset); #endif /* NOBITFIELD */ sdef = (sdk == selector ? sdef->next : sdef->sd_sdef); } dumplevel--; } -void dumpproto(struct proto *pl) +void dumpproto(struct proto* pl) { - struct type *type; + struct type* type; int argcnt = 0; newline(); printf("dump proto type list (start)"); newline(); - while (pl) { - printf("%d: %s", argcnt++, - pl->pl_flag & PL_FORMAL ? - (pl->pl_flag & PL_VOID ? "void" : "formal") - : (pl->pl_flag & PL_ELLIPSIS - ? "ellipsis" : "unknown" )); + while (pl) + { + printf( + "%d: %s", argcnt++, + pl->pl_flag & PL_FORMAL ? (pl->pl_flag & PL_VOID ? "void" : "formal") + : (pl->pl_flag & PL_ELLIPSIS ? "ellipsis" : "unknown")); newline(); - if ( (type = pl->pl_type) ){ + if ((type = pl->pl_type)) + { dumptype(type); newline(); } - if (pl->pl_idf) { + if (pl->pl_idf) + { dumplevel++; printf("idf:"); dumpidf(pl->pl_idf, 7); @@ -257,13 +268,14 @@ void dumpproto(struct proto *pl) printf("dump proto type list (end)\n"); } -void dumptype(struct type *tp) +void dumptype(struct type* tp) { int ops = 1; dumplevel++; newline(); - if (!tp) { + if (!tp) + { printf(""); newline(); dumplevel--; @@ -272,103 +284,107 @@ void dumptype(struct type *tp) printf("(@%lx, #%ld, &%d) ", tp, (long)tp->tp_size, tp->tp_align); - while (ops) { + while (ops) + { printf("%s", qual2str(tp->tp_typequal)); - switch (tp->tp_fund) { - case POINTER: - printf("pointer to "); - break; - case ARRAY: - printf("array [%ld] of ", tp->tp_size); - break; - case FUNCTION: - printf("function "); - if (tp->tp_proto) { - printf("with prototype"); - dumplevel++; - dumpproto(tp->tp_proto); - dumplevel--; - newline(); - } - printf("yielding "); - break; - default: - printf("%s%s ", tp->tp_unsigned ? "unsigned " : "", - symbol2str(tp->tp_fund)); - if (tp->tp_idf) - printf("%s ", tp->tp_idf->id_text); + switch (tp->tp_fund) + { + case POINTER: + printf("pointer to "); + break; + case ARRAY: + printf("array [%ld] of ", tp->tp_size); + break; + case FUNCTION: + printf("function "); + if (tp->tp_proto) + { + printf("with prototype"); + dumplevel++; + dumpproto(tp->tp_proto); + dumplevel--; + newline(); + } + printf("yielding "); + break; + default: + printf("%s%s ", tp->tp_unsigned ? "unsigned " : "", symbol2str(tp->tp_fund)); + if (tp->tp_idf) + printf("%s ", tp->tp_idf->id_text); #ifndef NOBITFIELD - if (tp->tp_fund == FIELD && tp->tp_field) { - struct field *fd = tp->tp_field; - - printf("[s=%ld,w=%ld] of ", - fd->fd_shift, fd->fd_width); - } - else + if (tp->tp_fund == FIELD && tp->tp_field) + { + struct field* fd = tp->tp_field; + + printf("[s=%ld,w=%ld] of ", fd->fd_shift, fd->fd_width); + } + else #endif /* NOBITFIELD */ - ops = 0; - break; + ops = 0; + break; } - if (ops) tp = tp->tp_up; + if (ops) + tp = tp->tp_up; } dumplevel--; } -static char *type2str(struct type *tp) +static char* type2str(struct type* tp) { /* Yields a pointer to a one-line description of the type tp. - */ - char *buf = next_transient(); + */ + char* buf = next_transient(); int ops = 1; buf[0] = '\0'; - if (!tp) { + if (!tp) + { sprintf(buf, ""); return buf; } - sprintf(buf, "%s(@%lx, #%ld, &%d) ", - buf, tp, (long)tp->tp_size, tp->tp_align); + sprintf(buf, "%s(@%lx, #%ld, &%d) ", buf, tp, (long)tp->tp_size, tp->tp_align); - while (ops) { + while (ops) + { sprintf(buf, "%s%s", buf, qual2str(tp->tp_typequal)); - switch (tp->tp_fund) { - case POINTER: - sprintf(buf, "%spointer to ", buf); - break; - case ARRAY: - sprintf(buf, "%sarray [%ld] of ", buf, tp->tp_size); - break; - case FUNCTION: - sprintf(buf, "%sfunction yielding ", buf); - break; - default: - sprintf(buf, "%s%s%s ", buf, - tp->tp_unsigned ? "unsigned " : "", - symbol2str(tp->tp_fund) - ); - if (tp->tp_idf) - sprintf(buf, "%s %s ", buf, - tp->tp_idf->id_text); + switch (tp->tp_fund) + { + case POINTER: + sprintf(buf, "%spointer to ", buf); + break; + case ARRAY: + sprintf(buf, "%sarray [%ld] of ", buf, tp->tp_size); + break; + case FUNCTION: + sprintf(buf, "%sfunction yielding ", buf); + break; + default: + sprintf( + buf, "%s%s%s ", buf, tp->tp_unsigned ? "unsigned " : "", + symbol2str(tp->tp_fund)); + if (tp->tp_idf) + sprintf(buf, "%s %s ", buf, tp->tp_idf->id_text); #ifndef NOBITFIELD - if (tp->tp_fund == FIELD && tp->tp_field) { - struct field *fd = tp->tp_field; - - sprintf(buf, "%s [s=%ld,w=%ld] of ", buf, - fd->fd_shift, fd->fd_width); - } - else + if (tp->tp_fund == FIELD && tp->tp_field) + { + struct field* fd = tp->tp_field; + + sprintf(buf, "%s [s=%ld,w=%ld] of ", buf, fd->fd_shift, fd->fd_width); + } + else #endif /* NOBITFIELD */ - ops = 0; - break; + ops = 0; + break; } - if (ops) tp = tp->tp_up; + if (ops) + tp = tp->tp_up; } return buf; } -static char *qual2str(int qual) +static char* qual2str(int qual) { - char *buf = next_transient(); + char* buf = next_transient(); *buf = '\0'; if (qual == 0) @@ -383,7 +399,7 @@ static char *qual2str(int qual) GSTATIC char trans_buf[MAXTRANS][300]; -static char * /* the ultimate transient buffer supplier */ +static char* /* the ultimate transient buffer supplier */ next_transient(void) { static int bnum; @@ -393,90 +409,84 @@ next_transient(void) return trans_buf[bnum]; } -void print_expr(char msg[], struct expr *expr) +void print_expr(char msg[], struct expr* expr) { /* Provisional routine to print an expression preceded by a - message msg. + message msg. */ - if (options['x']) { + if (options['x']) + { printf("\n%s: ", msg); printf("(L=line, T=type, r/lV=r/lvalue, F=flags, D=depth)\n"); p1_expr(0, expr); } } -static void p1_expr(int lvl, struct expr *expr) +static void p1_expr(int lvl, struct expr* expr) { p1_indent(lvl); - if (!expr) { + if (!expr) + { printf("NILEXPR\n"); return; } - printf("expr: L=%u, T=%s, %cV, F=%03o, D=%d, %s: ", - expr->ex_line, - type2str(expr->ex_type), - expr->ex_lvalue ? 'l' : 'r', - expr->ex_flags & 0xFF, - expr->ex_depth, - expr->ex_class == Value ? "Value" : - expr->ex_class == String ? "String" : - expr->ex_class == Float ? "Float" : - expr->ex_class == Oper ? "Oper" : - expr->ex_class == Type ? "Type" : "UNKNOWN CLASS" - ); - switch (expr->ex_class) { - struct oper *o; - case Value: - switch (expr->VL_CLASS) { - case Const: - printf("(Const) "); + printf( + "expr: L=%u, T=%s, %cV, F=%03o, D=%d, %s: ", expr->ex_line, type2str(expr->ex_type), + expr->ex_lvalue ? 'l' : 'r', expr->ex_flags & 0xFF, expr->ex_depth, + expr->ex_class == Value ? "Value" + : expr->ex_class == String ? "String" + : expr->ex_class == Float ? "Float" + : expr->ex_class == Oper ? "Oper" + : expr->ex_class == Type ? "Type" + : "UNKNOWN CLASS"); + switch (expr->ex_class) + { + struct oper* o; + case Value: + switch (expr->VL_CLASS) + { + case Const: + printf("(Const) "); + break; + case Name: + printf("(Name) %s + ", expr->VL_IDF->id_text); + break; + case Label: + printf("(Label) .%lu + ", expr->VL_LBL); + break; + default: + printf("(Unknown) "); + break; + } + printf("%s\n", writh2str(expr->VL_VALUE, expr->ex_type->tp_unsigned)); + break; + case String: + { + printf("\"%s\"\n", bts2str(expr->SG_VALUE, expr->SG_LEN - 1, next_transient())); break; - case Name: - printf("(Name) %s + ", expr->VL_IDF->id_text); + } + case Float: + { + char buf[FLT_STRLEN]; + + flt_flt2str(&(expr->FL_ARITH), buf, FLT_STRLEN); + printf("%s\n", buf); + break; + } + case Oper: + o = &expr->ex_object.ex_oper; + printf("\n"); + p1_expr(lvl + 1, o->op_left); + p1_indent(lvl); + printf("%s <%s>\n", symbol2str(o->op_oper), type2str(o->op_type)); + p1_expr(lvl + 1, o->op_right); break; - case Label: - printf("(Label) .%lu + ", expr->VL_LBL); + case Type: + printf("\n"); break; default: - printf("(Unknown) "); + printf("UNKNOWN CLASS\n"); break; - } - printf("%s\n", writh2str(expr->VL_VALUE, - expr->ex_type->tp_unsigned)); - break; - case String: - { - printf( - "\"%s\"\n", - bts2str(expr->SG_VALUE, expr->SG_LEN-1, - next_transient()) - ); - break; - } - case Float: - { - char buf[FLT_STRLEN]; - - flt_flt2str(&(expr->FL_ARITH), buf, FLT_STRLEN); - printf("%s\n", buf); - break; - } - case Oper: - o = &expr->ex_object.ex_oper; - printf("\n"); - p1_expr(lvl+1, o->op_left); - p1_indent(lvl); - printf("%s <%s>\n", symbol2str(o->op_oper), - type2str(o->op_type) - ); - p1_expr(lvl+1, o->op_right); - break; - case Type: - printf("\n"); - break; - default: - printf("UNKNOWN CLASS\n"); - break; } } @@ -485,4 +495,4 @@ static void p1_indent(int lvl) while (lvl--) printf(" "); } -#endif /* DEBUG */ +#endif /* DEBUG */ diff --git a/lang/cem/cemcom.ansi/error.c b/lang/cem/cemcom.ansi/error.c index 54176715fd..9bc36c5a23 100644 --- a/lang/cem/cemcom.ansi/error.c +++ b/lang/cem/cemcom.ansi/error.c @@ -5,64 +5,66 @@ /* $Id$ */ /* E R R O R A N D D I A G N O S T I C R O U T I N E S */ -#include "parameters.h" -#include "error.h" +#include +#include +#include "parameters.h" +#include "error.h" #if __STDC__ -#include +#include #else -#include +#include #endif -#include -#ifndef LINT -#include +#include +#ifndef LINT +#include #else -#include "l_em.h" -#endif /* LINT */ -#include -#include "tokenname.h" -#include -#include "interface.h" -#include "arith.h" -#include "label.h" -#include "expr.h" -#include "def.h" -#include "LLlex.h" +#include "l_em.h" +#endif /* LINT */ +#include +#include "tokenname.h" +#include +#include "interface.h" +#include "arith.h" +#include "label.h" +#include "expr.h" +#include "def.h" +#include "LLlex.h" /* This file contains the error-message and diagnostic - functions. Beware, they are called with a variable number of - arguments! + functions. Beware, they are called with a variable number of + arguments! */ /* error classes */ -#define STRICT 1 -#define WARNING 2 -#define ERROR 3 -#define CRASH 4 -#define FATAL 5 -#define DO_DEBUG 6 +#define STRICT 1 +#define WARNING 2 +#define ERROR 3 +#define CRASH 4 +#define FATAL 5 +#define DO_DEBUG 6 int err_occurred = 0; extern char options[]; -#ifdef LINT +#ifdef LINT extern char loptions[]; -#endif /* LINT */ +#endif /* LINT */ /* There are three general error-message functions: - lexerror() lexical and pre-processor error messages - error() syntactic and semantic error messages - expr_error() errors in expressions - The difference lies in the place where the file name and line - number come from. - Lexical errors report from the global variables LineNumber and - FileName, expression errors get their information from the - expression, whereas other errors use the information in the token. + lexerror() lexical and pre-processor error messages + error() syntactic and semantic error messages + expr_error() errors in expressions + The difference lies in the place where the file name and line + number come from. + Lexical errors report from the global variables LineNumber and + FileName, expression errors get their information from the + expression, whereas other errors use the information in the token. */ -static void _error(int, char *, unsigned int, char*, va_list); +static void _error(int, char*, unsigned int, char*, va_list); #if __STDC__ /*VARARGS*/ -void error(char *fmt, ...) +void error(char* fmt, ...) { va_list ap; @@ -74,13 +76,14 @@ void error(char *fmt, ...) } /*VARARGS*/ -void expr_error(struct expr *expr, char *fmt, ...) +void expr_error(struct expr* expr, char* fmt, ...) { va_list ap; va_start(ap, fmt); { - if (!(expr->ex_flags & EX_ERROR)) { + if (!(expr->ex_flags & EX_ERROR)) + { /* to prevent proliferation */ _error(ERROR, expr->ex_file, expr->ex_line, fmt, ap); expr->ex_flags |= EX_ERROR; @@ -90,7 +93,7 @@ void expr_error(struct expr *expr, char *fmt, ...) } /*VARARGS*/ -void lexstrict(char *fmt, ...) +void lexstrict(char* fmt, ...) { va_list ap; @@ -102,7 +105,7 @@ void lexstrict(char *fmt, ...) } /*VARARGS*/ -void strict(char *fmt, ...) +void strict(char* fmt, ...) { va_list ap; @@ -114,13 +117,14 @@ void strict(char *fmt, ...) } /*VARARGS*/ -void expr_strict(struct expr *expr, char *fmt, ...) +void expr_strict(struct expr* expr, char* fmt, ...) { va_list ap; va_start(ap, fmt); { - if (!(expr->ex_flags & EX_ERROR)) { + if (!(expr->ex_flags & EX_ERROR)) + { /* to prevent proliferation */ _error(STRICT, expr->ex_file, expr->ex_line, fmt, ap); } @@ -130,7 +134,7 @@ void expr_strict(struct expr *expr, char *fmt, ...) #ifdef DEBUG /*VARARGS*/ -void debug(char *fmt, ...) +void debug(char* fmt, ...) { va_list ap; @@ -143,7 +147,7 @@ void debug(char *fmt, ...) #endif /* DEBUG */ /*VARARGS*/ -void warning(char *fmt, ...) +void warning(char* fmt, ...) { va_list ap; @@ -155,13 +159,14 @@ void warning(char *fmt, ...) } /*VARARGS*/ -void expr_warning(struct expr *expr, char *fmt, ...) +void expr_warning(struct expr* expr, char* fmt, ...) { va_list ap; va_start(ap, fmt); { - if (!(expr->ex_flags & EX_ERROR)) { + if (!(expr->ex_flags & EX_ERROR)) + { /* to prevent proliferation */ _error(WARNING, expr->ex_file, expr->ex_line, fmt, ap); } @@ -169,10 +174,10 @@ void expr_warning(struct expr *expr, char *fmt, ...) va_end(ap); } -#ifdef LINT +#ifdef LINT /*VARARGS*/ -void def_warning(struct def *def, char *fmt, ...) +void def_warning(struct def* def, char* fmt, ...) { va_list ap; @@ -183,9 +188,8 @@ void def_warning(struct def *def, char *fmt, ...) va_end(ap); } - /*VARARGS*/ -void hwarning(char *fmt, ...) +void hwarning(char* fmt, ...) { va_list ap; @@ -198,7 +202,7 @@ void hwarning(char *fmt, ...) } /*VARARGS*/ -void awarning(char *fmt, ...) +void awarning(char* fmt, ...) { va_list ap; @@ -210,10 +214,10 @@ void awarning(char *fmt, ...) va_end(ap); } -#endif /* LINT */ +#endif /* LINT */ /*VARARGS*/ -void lexerror(char *fmt, ...) +void lexerror(char* fmt, ...) { va_list ap; @@ -225,7 +229,7 @@ void lexerror(char *fmt, ...) } /*VARARGS*/ -void lexwarning(char *fmt, ...) +void lexwarning(char* fmt, ...) { va_list ap; @@ -237,7 +241,7 @@ void lexwarning(char *fmt, ...) } /*VARARGS*/ -void crash(char *fmt, ...) +void crash(char* fmt, ...) { va_list ap; @@ -248,16 +252,16 @@ void crash(char *fmt, ...) va_end(ap); C_close(); -#ifdef DEBUG +#ifdef DEBUG abort(); -#else /* DEBUG */ +#else /* DEBUG */ exit(1); -#endif /* DEBUG */ +#endif /* DEBUG */ UNREACHABLE_CODE; } /*VARARGS*/ -void fatal(char *fmt, ...) +void fatal(char* fmt, ...) { va_list ap; @@ -267,37 +271,39 @@ void fatal(char *fmt, ...) } va_end(ap); - if (C_busy()) C_close(); + if (C_busy()) + C_close(); exit(1); UNREACHABLE_CODE; } #else /*VARARGS*/ -void error(va_alist) /* fmt, args */ - va_dcl +void error(va_alist) /* fmt, args */ + va_dcl { va_list ap; va_start(ap); { - char *fmt = va_arg(ap, char *); + char* fmt = va_arg(ap, char*); _error(ERROR, dot.tk_file, dot.tk_line, fmt, ap); } va_end(ap); } /*VARARGS*/ -void expr_error(va_alist) /* expr, fmt, args */ - va_dcl +void expr_error(va_alist) /* expr, fmt, args */ + va_dcl { va_list ap; va_start(ap); { - struct expr *expr = va_arg(ap, struct expr *); - char *fmt = va_arg(ap, char *); + struct expr* expr = va_arg(ap, struct expr*); + char* fmt = va_arg(ap, char*); - if (!(expr->ex_flags & EX_ERROR)) { + if (!(expr->ex_flags & EX_ERROR)) + { /* to prevent proliferation */ _error(ERROR, expr->ex_file, expr->ex_line, fmt, ap); expr->ex_flags |= EX_ERROR; @@ -307,45 +313,44 @@ void expr_error(va_alist) /* expr, fmt, args */ } /*VARARGS*/ -void lexstrict(va_alist) - va_dcl +void lexstrict(va_alist) va_dcl { va_list ap; va_start(ap); { - char *fmt = va_arg(ap, char *); + char* fmt = va_arg(ap, char*); _error(STRICT, FileName, LineNumber, fmt, ap); } va_end(ap); } /*VARARGS*/ -void strict(va_alist) - va_dcl +void strict(va_alist) va_dcl { va_list ap; va_start(ap); { - char *fmt = va_arg(ap, char *); + char* fmt = va_arg(ap, char*); _error(STRICT, dot.tk_file, dot.tk_line, fmt, ap); } va_end(ap); } /*VARARGS*/ -void expr_strict(va_alist) /* expr, fmt, args */ - va_dcl +void expr_strict(va_alist) /* expr, fmt, args */ + va_dcl { va_list ap; va_start(ap); { - struct expr *expr = va_arg(ap, struct expr *); - char *fmt = va_arg(ap, char *); + struct expr* expr = va_arg(ap, struct expr*); + char* fmt = va_arg(ap, char*); - if (!(expr->ex_flags & EX_ERROR)) { + if (!(expr->ex_flags & EX_ERROR)) + { /* to prevent proliferation */ _error(STRICT, expr->ex_file, expr->ex_line, fmt, ap); } @@ -355,14 +360,13 @@ void expr_strict(va_alist) /* expr, fmt, args */ #ifdef DEBUG /*VARARGS*/ -void debug(va_alist) - va_dcl +void debug(va_alist) va_dcl { va_list ap; va_start(ap); { - char *fmt = va_arg(ap, char *); + char* fmt = va_arg(ap, char*); _error(DO_DEBUG, dot.tk_file, dot.tk_line, fmt, ap); } va_end(ap); @@ -370,31 +374,31 @@ void debug(va_alist) #endif /* DEBUG */ /*VARARGS*/ -void warning(va_alist) - va_dcl +void warning(va_alist) va_dcl { va_list ap; va_start(ap); { - char *fmt = va_arg(ap, char *); + char* fmt = va_arg(ap, char*); _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap); } va_end(ap); } /*VARARGS*/ -void expr_warning(va_alist) /* expr, fmt, args */ - va_dcl +void expr_warning(va_alist) /* expr, fmt, args */ + va_dcl { va_list ap; va_start(ap); { - struct expr *expr = va_arg(ap, struct expr *); - char *fmt = va_arg(ap, char *); + struct expr* expr = va_arg(ap, struct expr*); + char* fmt = va_arg(ap, char*); - if (!(expr->ex_flags & EX_ERROR)) { + if (!(expr->ex_flags & EX_ERROR)) + { /* to prevent proliferation */ _error(WARNING, expr->ex_file, expr->ex_line, fmt, ap); } @@ -402,34 +406,33 @@ void expr_warning(va_alist) /* expr, fmt, args */ va_end(ap); } -#ifdef LINT +#ifdef LINT /*VARARGS*/ -void def_warning(va_alist) /* def, fmt, args */ - va_dcl +void def_warning(va_alist) /* def, fmt, args */ + va_dcl { va_list ap; va_start(ap); { - struct def *def = va_arg(ap, struct def *); - char *fmt = va_arg(ap, char *); + struct def* def = va_arg(ap, struct def*); + char* fmt = va_arg(ap, char*); _error(WARNING, def->df_file, def->df_line, fmt, ap); } va_end(ap); } - /*VARARGS*/ -void hwarning(va_alist) /* fmt, args */ - va_dcl +void hwarning(va_alist) /* fmt, args */ + va_dcl { va_list ap; va_start(ap); { - char *fmt = va_arg(ap, char *); + char* fmt = va_arg(ap, char*); if (loptions['h']) _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap); } @@ -437,181 +440,183 @@ void hwarning(va_alist) /* fmt, args */ } /*VARARGS*/ -void awarning(va_alist) /* fmt, args */ - va_dcl +void awarning(va_alist) /* fmt, args */ + va_dcl { va_list ap; va_start(ap); { - char *fmt = va_arg(ap, char *); + char* fmt = va_arg(ap, char*); if (loptions['a']) _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap); } va_end(ap); } -#endif /* LINT */ +#endif /* LINT */ /*VARARGS*/ -void lexerror(va_alist) /* fmt, args */ - va_dcl +void lexerror(va_alist) /* fmt, args */ + va_dcl { va_list ap; va_start(ap); { - char *fmt = va_arg(ap, char *); + char* fmt = va_arg(ap, char*); _error(ERROR, FileName, LineNumber, fmt, ap); } va_end(ap); } /*VARARGS*/ -void lexwarning(va_alist) /* fmt, args */ - va_dcl +void lexwarning(va_alist) /* fmt, args */ + va_dcl { va_list ap; va_start(ap); { - char *fmt = va_arg(ap, char *); + char* fmt = va_arg(ap, char*); _error(WARNING, FileName, LineNumber, fmt, ap); } va_end(ap); } /*VARARGS*/ -void crash(va_alist) /* fmt, args */ - va_dcl +void crash(va_alist) /* fmt, args */ + va_dcl { va_list ap; va_start(ap); { - char *fmt = va_arg(ap, char *); + char* fmt = va_arg(ap, char*); _error(CRASH, FileName, LineNumber, fmt, ap); } va_end(ap); C_close(); -#ifdef DEBUG +#ifdef DEBUG abort(); -#else /* DEBUG */ +#else /* DEBUG */ exit(1); -#endif /* DEBUG */ +#endif /* DEBUG */ UNREACHABLE_CODE; } /*VARARGS*/ -void fatal(va_alist) /* fmt, args */ - va_dcl +void fatal(va_alist) /* fmt, args */ + va_dcl { va_list ap; va_start(ap); { - char *fmt = va_arg(ap, char *); + char* fmt = va_arg(ap, char*); _error(FATAL, FileName, LineNumber, fmt, ap); } va_end(ap); - if (C_busy()) C_close(); + if (C_busy()) + C_close(); exit(1); UNREACHABLE_CODE; } #endif -static void _error(int class, char *fn, unsigned int ln, char* fmt, va_list ap) +static void _error(int class, char* fn, unsigned int ln, char* fmt, va_list ap) { - char *remark; - + char* remark; + /* check visibility of message */ - switch (class) { - case WARNING: - case ERROR: - case STRICT: - if (token_nmb < tk_nmb_at_last_syn_err + ERR_SHADOW) - /* warning or error message overshadowed */ - return; - break; + switch (class) + { + case WARNING: + case ERROR: + case STRICT: + if (token_nmb < tk_nmb_at_last_syn_err + ERR_SHADOW) + /* warning or error message overshadowed */ + return; + break; } /* Since name and number are gathered from different places - depending on the class, we first collect the relevant - values and then decide what to print. + depending on the class, we first collect the relevant + values and then decide what to print. */ /* preliminaries */ - switch (class) { - case WARNING: - if (options['w']) - return; - break; - - case STRICT: - if (options['s']) - return; - break; - - case ERROR: - case CRASH: - case FATAL: - if (C_busy()) - C_ms_err(); - err_occurred = 1; - break; + switch (class) + { + case WARNING: + if (options['w']) + return; + break; + + case STRICT: + if (options['s']) + return; + break; + + case ERROR: + case CRASH: + case FATAL: + if (C_busy()) + C_ms_err(); + err_occurred = 1; + break; } /* the remark */ - switch (class) { - case STRICT: - remark = "(strict)"; - break; - case WARNING: -#ifndef LINT - remark = "(warning)"; -#else /* LINT */ - remark = 0; -#endif /* LINT */ - break; - - case ERROR: - remark = 0; - break; - - case CRASH: - remark = "CRASH\007"; - break; - - case FATAL: - remark = "fatal error --"; - break; + switch (class) + { + case STRICT: + remark = "(strict)"; + break; + case WARNING: +#ifndef LINT + remark = "(warning)"; +#else /* LINT */ + remark = 0; +#endif /* LINT */ + break; + + case ERROR: + remark = 0; + break; + + case CRASH: + remark = "CRASH\007"; + break; + + case FATAL: + remark = "fatal error --"; + break; #ifdef DEBUG - case DO_DEBUG: - remark = "(debug)"; - break; + case DO_DEBUG: + remark = "(debug)"; + break; #endif /* DEBUG */ - default: - UNREACHABLE_CODE; - } - -#ifdef LINT - if ( /* there is a file name */ - fn - && /* the file name is global */ - fn[0] == '/' - && /* it is not a .c file */ - strcmp(&fn[strlen(fn)-2], ".c") != 0 - ) { + default: + UNREACHABLE_CODE; + } + +#ifdef LINT + if (/* there is a file name */ + fn && /* the file name is global */ + fn[0] == '/' && /* it is not a .c file */ + strcmp(&fn[strlen(fn) - 2], ".c") != 0) + { /* we skip this message */ return; } -#endif /* LINT */ - +#endif /* LINT */ + if (fn) fprintf(ERROUT, "\"%s\", line %u: ", fn, ln); if (remark) fprintf(ERROUT, "%s ", remark); - vfprintf(ERROUT, fmt, ap); /* contents of error */ + vfprintf(ERROUT, fmt, ap); /* contents of error */ fprintf(ERROUT, "\n"); } diff --git a/lang/cem/cemcom.ansi/error.h b/lang/cem/cemcom.ansi/error.h index 595cd2aba7..155afdc8e3 100644 --- a/lang/cem/cemcom.ansi/error.h +++ b/lang/cem/cemcom.ansi/error.h @@ -1,9 +1,9 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-02-06 - * + * */ #ifndef ERROR_H_ #define ERROR_H_ @@ -12,54 +12,54 @@ struct expr; #if __STDC__ /*VARARGS*/ -void error(char *fmt, ...); +void error(char* fmt, ...); /*VARARGS*/ -void expr_error(struct expr *expr, char *fmt, ...); +void expr_error(struct expr* expr, char* fmt, ...); /*VARARGS*/ -void lexstrict(char *fmt, ...); +void lexstrict(char* fmt, ...); /*VARARGS*/ -void strict(char *fmt, ...); +void strict(char* fmt, ...); /*VARARGS*/ -void expr_strict(struct expr *expr, char *fmt, ...); +void expr_strict(struct expr* expr, char* fmt, ...); #ifdef DEBUG /*VARARGS*/ -void debug(char *fmt, ...); +void debug(char* fmt, ...); #endif /* DEBUG */ /*VARARGS*/ -void warning(char *fmt, ...); +void warning(char* fmt, ...); /*VARARGS*/ -void expr_warning(struct expr *expr, char *fmt, ...); -#ifdef LINT +void expr_warning(struct expr* expr, char* fmt, ...); +#ifdef LINT /*VARARGS*/ -void def_warning(struct def *def, char *fmt, ...); +void def_warning(struct def* def, char* fmt, ...); /*VARARGS*/ -void hwarning(char *fmt, ...); +void hwarning(char* fmt, ...); /*VARARGS*/ -void awarning(char *fmt, ...); -#endif /* LINT */ +void awarning(char* fmt, ...); +#endif /* LINT */ /*VARARGS*/ -void lexerror(char *fmt, ...); +void lexerror(char* fmt, ...); /*VARARGS*/ -void lexwarning(char *fmt, ...); +void lexwarning(char* fmt, ...); /*VARARGS*/ -void crash(char *fmt, ...); +void crash(char* fmt, ...); /*VARARGS*/ -void fatal(char *fmt, ...); +void fatal(char* fmt, ...); #else /*VARARGS*/ -void error(va_alist); /* fmt, args */ +void error(va_alist); /* fmt, args */ /*VARARGS*/ -void expr_error(va_alist); /* expr, fmt, args */ +void expr_error(va_alist); /* expr, fmt, args */ /*VARARGS*/ void lexstrict(va_alist); /*VARARGS*/ void strict(va_alist); /*VARARGS*/ -void expr_strict(va_alist); /* expr, fmt, args */ +void expr_strict(va_alist); /* expr, fmt, args */ #ifdef DEBUG /*VARARGS*/ void debug(va_alist); @@ -68,27 +68,25 @@ void debug(va_alist); /*VARARGS*/ void warning(va_alist); /*VARARGS*/ -void expr_warning(va_alist); /* expr, fmt, args */ -#ifdef LINT +void expr_warning(va_alist); /* expr, fmt, args */ +#ifdef LINT /*VARARGS*/ -void def_warning(va_alist); /* def, fmt, args */ +void def_warning(va_alist); /* def, fmt, args */ /*VARARGS*/ -void hwarning(va_alist); /* fmt, args */ +void hwarning(va_alist); /* fmt, args */ /*VARARGS*/ -void awarning(va_alist); /* fmt, args */ -#endif /* LINT */ +void awarning(va_alist); /* fmt, args */ +#endif /* LINT */ /*VARARGS*/ -void lexerror(va_alist); /* fmt, args */ +void lexerror(va_alist); /* fmt, args */ /*VARARGS*/ -void lexwarning(va_alist); /* fmt, args */ +void lexwarning(va_alist); /* fmt, args */ /*VARARGS*/ -void crash(va_alist); /* fmt, args */ +void crash(va_alist); /* fmt, args */ /*VARARGS*/ -void fatal(va_alist); /* fmt, args */ +void fatal(va_alist); /* fmt, args */ #endif - - #endif /* ERROR_H_ */ diff --git a/lang/cem/cemcom.ansi/estack.str b/lang/cem/cemcom.ansi/estack.str index 0718cca647..8cbdddc8a2 100644 --- a/lang/cem/cemcom.ansi/estack.str +++ b/lang/cem/cemcom.ansi/estack.str @@ -2,25 +2,26 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ - #ifndef ESTACK_H_ - #define ESTACK_H_ - +#ifndef ESTACK_H_ +#define ESTACK_H_ + /* $Id$ */ /* EXPRESSION STACK */ /* Used for global initializations */ -struct e_stack { - struct e_stack *next; - arith s_cnt1, s_cnt2; - struct sdef *s_def; - struct type **s_tpp; - short s_nested; +struct e_stack +{ + struct e_stack* next; + arith s_cnt1, s_cnt2; + struct sdef* s_def; + struct type** s_tpp; + short s_nested; }; /* ALLOCDEF "e_stack" 5 */ -#define bytes_upto_here s_cnt1 -#define last_offset s_cnt2 -#define elem_count s_cnt1 -#define nelem s_cnt2 +#define bytes_upto_here s_cnt1 +#define last_offset s_cnt2 +#define elem_count s_cnt1 +#define nelem s_cnt2 #endif \ No newline at end of file diff --git a/lang/cem/cemcom.ansi/eval.c b/lang/cem/cemcom.ansi/eval.c index cf4900d225..e7e3aff71e 100644 --- a/lang/cem/cemcom.ansi/eval.c +++ b/lang/cem/cemcom.ansi/eval.c @@ -5,840 +5,901 @@ /* $Id$ */ /* EXPRESSION-CODE GENERATOR */ -#include "parameters.h" -#ifndef LINT +#include +#include +#include "parameters.h" +#ifndef LINT -#include -#include -#include -#include -#include -#include -#include "interface.h" -#include "eval.h" -#include "idf.h" -#include "arith.h" -#include "type.h" -#include "label.h" -#include "code.h" -#include "def.h" -#include "expr.h" -#include "sizes.h" -#include "field.h" -#include "Lpars.h" -#include "LLlex.h" -#include "level.h" -#include "conversion.h" -#include "stack.h" -#include "struct.h" -#include "align.h" -#include "mes.h" -#include "atw.h" -#include "ch3.h" -#include "util.h" -#include "blocks.h" -#include "dataflow.h" -#include "specials.h" -#include "error.h" +#include +#include +#include +#include +#include +#include +#include "interface.h" +#include "eval.h" +#include "idf.h" +#include "arith.h" +#include "type.h" +#include "label.h" +#include "code.h" +#include "def.h" +#include "expr.h" +#include "sizes.h" +#include "field.h" +#include "Lpars.h" +#include "LLlex.h" +#include "level.h" +#include "conversion.h" +#include "stack.h" +#include "struct.h" +#include "align.h" +#include "mes.h" +#include "atw.h" +#include "ch3.h" +#include "util.h" +#include "blocks.h" +#include "dataflow.h" +#include "specials.h" +#include "error.h" -#define CRASH() crash("EVAL: CRASH at line %u", __LINE__) - -#define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER) -extern int err_occurred; /* error.c */ +#define CRASH() crash("EVAL: CRASH at line %u", __LINE__) +#define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER) +extern int err_occurred; /* error.c */ /* Forward internal declarations */ -static void operands(struct expr *, int); +static void operands(struct expr*, int); static void ptr_add(arith size); static void truthvalue(int relop); static void compare(int relop, label lbl); /* EVAL() is the main expression-tree evaluator, which turns - any legal expression tree into EM code. parameters.h: + any legal expression tree into EM code. parameters.h: + + struct expr *expr + pointer to root of the expression tree to be evaluated + + int val + indicates whether the resulting expression is to be + dereferenced (if val == RVAL and expr->ex_lvalue == 1) + or not (val == LVAL). The latter case indicates that + the resulting expression is an lvalue expression which + should not be dereferenced by EVAL - struct expr *expr - pointer to root of the expression tree to be evaluated + int code + indicates whether the expression tree must be turned + into EM code or not. E.g. the expression statement "12;" + delivers the expression "12" to EVAL while this should + not result in any EM code - int val - indicates whether the resulting expression is to be - dereferenced (if val == RVAL and expr->ex_lvalue == 1) - or not (val == LVAL). The latter case indicates that - the resulting expression is an lvalue expression which - should not be dereferenced by EVAL - - int code - indicates whether the expression tree must be turned - into EM code or not. E.g. the expression statement "12;" - delivers the expression "12" to EVAL while this should - not result in any EM code - - label false_label, label true_label - if the expression is a logical or relational expression - and if the loop of the program depends on the resulting - value then EVAL generates jumps to the specified program - labels, in case they are specified (i.e. are non-zero) + label false_label, label true_label + if the expression is a logical or relational expression + and if the loop of the program depends on the resulting + value then EVAL generates jumps to the specified program + labels, in case they are specified (i.e. are non-zero) */ -void EVAL(struct expr *expr, int val, int code, label true_label, label false_label) +void EVAL(struct expr* expr, int val, int code, label true_label, label false_label) { - int vol = (code != TRUE && recurqual(expr->ex_type, TQ_VOLATILE)); - int gencode = code == TRUE; + int vol = (code != true && recurqual(expr->ex_type, TQ_VOLATILE)); + int gencode = code == true; - if (err_occurred) return; - switch (expr->ex_class) { - case Value: /* just a simple value */ - if (gencode) { - if (true_label) { - /* can only result from ','-expressions with - constant right-hand sides ??? - */ - assert(is_cp_cst(expr)); - C_bra(expr->VL_VALUE == 0 ? false_label : true_label); - } - else load_val(expr, val); - } - else if (vol) { - load_val(expr, val); - C_asp(ATW(expr->ex_type->tp_size)); - } - break; - case String: /* a string constant */ - if (gencode) { - string2pointer(expr); - C_lae_dlb(expr->VL_LBL, (arith)expr->VL_VALUE); - } - break; - case Float: /* a floating constant */ - if (gencode) { - label datlab = data_label(); - char buf[FLT_STRLEN]; - - fp_used = 1; - flt_flt2str(&(expr->FL_ARITH), buf, FLT_STRLEN); - C_df_dlb(datlab); - C_rom_fcon(buf, expr->ex_type->tp_size); - C_lae_dlb(datlab, (arith)0); - C_loi(expr->ex_type->tp_size); - } - break; - case Oper: /* compound expression */ + if (err_occurred) + return; + switch (expr->ex_class) { - int oper = expr->OP_OPER; - struct expr *left = expr->OP_LEFT; - struct expr *right = expr->OP_RIGHT; - struct type *tp = expr->OP_TYPE; - - switch (oper) { - case '+': - /* We have the following possibilities : - int + int, pointer + int, pointer + long, - long + long, long long + long long, - double + double - */ - operands(expr, gencode); - if (gencode) { - switch (tp->tp_fund) { - case INT: - case LONG: - case LNGLNG: - if (tp->tp_unsigned) - C_adu(tp->tp_size); - else - C_adi(tp->tp_size); - break; - case POINTER: - ptr_add(right->ex_type->tp_size); - break; - case FLOAT: - case DOUBLE: - case LNGDBL: - C_adf(tp->tp_size); - break; - default: - crash("bad type +"); - } - } - break; - case '-': - if (left == 0) { /* unary */ - EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); - if (gencode) { - switch (tp->tp_fund) { - case INT: - case LONG: - case LNGLNG: - case POINTER: - C_ngi(tp->tp_size); - break; - case FLOAT: - case DOUBLE: - case LNGDBL: - C_ngf(tp->tp_size); - break; - default: - CRASH(); - } + case Value: /* just a simple value */ + if (gencode) + { + if (true_label) + { + /* can only result from ','-expressions with + constant right-hand sides ??? + */ + assert(is_cp_cst(expr)); + C_bra(expr->VL_VALUE == 0 ? false_label : true_label); } - break; - } - /* else binary; we have the following flavours: - int - int, pointer - int, pointer - long, - pointer - pointer, long - long, - long long - long long, double - double - */ - operands(expr, gencode); - if (!gencode) - break; - switch (tp->tp_fund) { - case INT: - case LONG: - case LNGLNG: - if (tp->tp_unsigned) - C_sbu(tp->tp_size); else - C_sbi(tp->tp_size); - break; - case POINTER: - if (right->ex_type->tp_fund == POINTER) - C_sbs(pointer_size); - else { - C_ngi(right->ex_type->tp_size); - ptr_add(right->ex_type->tp_size); - } - break; - case FLOAT: - case DOUBLE: - case LNGDBL: - C_sbf(tp->tp_size); - break; - default: - crash("bad type -"); + load_val(expr, val); } - break; - case '*': - if (left == 0) { /* unary */ - EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); - if (gencode && right->ex_class == String) { - C_loi((arith)1); - } - break; - } - operands(expr, gencode); - if (gencode) { - switch (tp->tp_fund) { - case INT: - case LONG: - case LNGLNG: - case POINTER: - if (tp->tp_unsigned) - C_mlu(tp->tp_size); - else - C_mli(tp->tp_size); - break; - case FLOAT: - case DOUBLE: - case LNGDBL: - C_mlf(tp->tp_size); - break; - default: - crash("bad type *"); - } + else if (vol) + { + load_val(expr, val); + C_asp(ATW(expr->ex_type->tp_size)); } break; - case '/': - operands(expr, gencode); + case String: /* a string constant */ if (gencode) - switch (tp->tp_fund) { - case INT: - case LONG: - case LNGLNG: - case POINTER: - if (tp->tp_unsigned) - C_dvu(tp->tp_size); - else - C_dvi(tp->tp_size); - break; - case FLOAT: - case DOUBLE: - case LNGDBL: - /*C_dvf(double_size);*/ - C_dvf(tp->tp_size); - break; - default: - crash("bad type /"); - } - break; - case '%': - operands(expr, gencode); - assert(tp->tp_fund==INT || tp->tp_fund==LONG || - tp->tp_fund==LNGLNG); - if (gencode) - if (tp->tp_unsigned) - C_rmu(tp->tp_size); - else - C_rmi(tp->tp_size); - break; - case LEFT: - operands(expr, gencode); - if (gencode) - if (tp->tp_unsigned) - C_slu(tp->tp_size); - else - C_sli(tp->tp_size); + { + string2pointer(expr); + C_lae_dlb(expr->VL_LBL, (arith)expr->VL_VALUE); + } break; - case RIGHT: - operands(expr, gencode); + case Float: /* a floating constant */ if (gencode) - if (tp->tp_unsigned) - C_sru(tp->tp_size); - else - C_sri(tp->tp_size); + { + label datlab = data_label(); + char buf[FLT_STRLEN]; + + fp_used = 1; + flt_flt2str(&(expr->FL_ARITH), buf, FLT_STRLEN); + C_df_dlb(datlab); + C_rom_fcon(buf, expr->ex_type->tp_size); + C_lae_dlb(datlab, (arith)0); + C_loi(expr->ex_type->tp_size); + } break; - case '<': - case LESSEQ: - case '>': - case GREATEREQ: - case EQUAL: - case NOTEQUAL: - operands(expr, gencode); - if (gencode) { - /* The operands have the same type */ - arith size = left->ex_type->tp_size; - - switch (tp->tp_fund) { - case INT: - case LONG: - case LNGLNG: - if (left->ex_type->tp_unsigned) - C_cmu(size); - else - C_cmi(size); + case Oper: /* compound expression */ + { + int oper = expr->OP_OPER; + struct expr* left = expr->OP_LEFT; + struct expr* right = expr->OP_RIGHT; + struct type* tp = expr->OP_TYPE; + + switch (oper) + { + case '+': + /* We have the following possibilities : + int + int, pointer + int, pointer + long, + long + long, long long + long long, + double + double + */ + operands(expr, gencode); + if (gencode) + { + switch (tp->tp_fund) + { + case INT: + case LONG: + case LNGLNG: + if (tp->tp_unsigned) + C_adu(tp->tp_size); + else + C_adi(tp->tp_size); + break; + case POINTER: + ptr_add(right->ex_type->tp_size); + break; + case FLOAT: + case DOUBLE: + case LNGDBL: + C_adf(tp->tp_size); + break; + default: + crash("bad type +"); + } + } + break; + case '-': + if (left == 0) + { /* unary */ + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); + if (gencode) + { + switch (tp->tp_fund) + { + case INT: + case LONG: + case LNGLNG: + case POINTER: + C_ngi(tp->tp_size); + break; + case FLOAT: + case DOUBLE: + case LNGDBL: + C_ngf(tp->tp_size); + break; + default: + CRASH(); + } + } + break; + } + /* else binary; we have the following flavours: + int - int, pointer - int, pointer - long, + pointer - pointer, long - long, + long long - long long, double - double + */ + operands(expr, gencode); + if (!gencode) + break; + switch (tp->tp_fund) + { + case INT: + case LONG: + case LNGLNG: + if (tp->tp_unsigned) + C_sbu(tp->tp_size); + else + C_sbi(tp->tp_size); + break; + case POINTER: + if (right->ex_type->tp_fund == POINTER) + C_sbs(pointer_size); + else + { + C_ngi(right->ex_type->tp_size); + ptr_add(right->ex_type->tp_size); + } + break; + case FLOAT: + case DOUBLE: + case LNGDBL: + C_sbf(tp->tp_size); + break; + default: + crash("bad type -"); + } + break; + case '*': + if (left == 0) + { /* unary */ + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); + if (gencode && right->ex_class == String) + { + C_loi((arith)1); + } + break; + } + operands(expr, gencode); + if (gencode) + { + switch (tp->tp_fund) + { + case INT: + case LONG: + case LNGLNG: + case POINTER: + if (tp->tp_unsigned) + C_mlu(tp->tp_size); + else + C_mli(tp->tp_size); + break; + case FLOAT: + case DOUBLE: + case LNGDBL: + C_mlf(tp->tp_size); + break; + default: + crash("bad type *"); + } + } break; - case FLOAT: - case DOUBLE: - case LNGDBL: - C_cmf(size); + case '/': + operands(expr, gencode); + if (gencode) + switch (tp->tp_fund) + { + case INT: + case LONG: + case LNGLNG: + case POINTER: + if (tp->tp_unsigned) + C_dvu(tp->tp_size); + else + C_dvi(tp->tp_size); + break; + case FLOAT: + case DOUBLE: + case LNGDBL: + /*C_dvf(double_size);*/ + C_dvf(tp->tp_size); + break; + default: + crash("bad type /"); + } break; - case POINTER: - C_cmp(); + case '%': + operands(expr, gencode); + assert(tp->tp_fund == INT || tp->tp_fund == LONG || tp->tp_fund == LNGLNG); + if (gencode) + if (tp->tp_unsigned) + C_rmu(tp->tp_size); + else + C_rmi(tp->tp_size); break; - case ENUM: - C_cmi(size); + case LEFT: + operands(expr, gencode); + if (gencode) + if (tp->tp_unsigned) + C_slu(tp->tp_size); + else + C_sli(tp->tp_size); break; - default: - CRASH(); - } - if (true_label != 0) { - compare(oper, true_label); - C_bra(false_label); - } - else { - truthvalue(oper); - } - } - break; - case '&': - case '|': - case '^': - /* both operands should have type int */ - operands(expr, gencode); - if (gencode) { - arith size = tp->tp_size; + case RIGHT: + operands(expr, gencode); + if (gencode) + if (tp->tp_unsigned) + C_sru(tp->tp_size); + else + C_sri(tp->tp_size); + break; + case '<': + case LESSEQ: + case '>': + case GREATEREQ: + case EQUAL: + case NOTEQUAL: + operands(expr, gencode); + if (gencode) + { + /* The operands have the same type */ + arith size = left->ex_type->tp_size; - if ((int)size < (int)word_size) - size = word_size; - switch (oper) { - case '&': - C_and(size); + switch (tp->tp_fund) + { + case INT: + case LONG: + case LNGLNG: + if (left->ex_type->tp_unsigned) + C_cmu(size); + else + C_cmi(size); + break; + case FLOAT: + case DOUBLE: + case LNGDBL: + C_cmf(size); + break; + case POINTER: + C_cmp(); + break; + case ENUM: + C_cmi(size); + break; + default: + CRASH(); + } + if (true_label != 0) + { + compare(oper, true_label); + C_bra(false_label); + } + else + { + truthvalue(oper); + } + } break; + case '&': case '|': - C_ior(size); - break; case '^': - C_xor(size); + /* both operands should have type int */ + operands(expr, gencode); + if (gencode) + { + arith size = tp->tp_size; + + if ((int)size < (int)word_size) + size = word_size; + switch (oper) + { + case '&': + C_and(size); + break; + case '|': + C_ior(size); + break; + case '^': + C_xor(size); + break; + } + } break; - } - } - break; - case '=': + case '=': #ifndef NOBITFIELD - if (left->ex_type->tp_fund == FIELD) { - eval_field(expr, gencode); - break; - } + if (left->ex_type->tp_fund == FIELD) + { + eval_field(expr, gencode); + break; + } #endif /* NOBITFIELD */ - if (is_struct_or_union(tp->tp_fund) && ! gencode) { - EVAL(right, LVAL, TRUE, NO_LABEL, NO_LABEL); - EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); - copy_block(tp->tp_size, tp->tp_align); - break; - } - EVAL(right, RVAL, TRUE, NO_LABEL, NO_LABEL); - if (gencode && val == RVAL) - C_dup(ATW(tp->tp_size)); - if (left->ex_class != Value) { - EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); - if (gencode && val == LVAL) { - arith tmp = LocalPtrVar(); - C_dup(pointer_size); - StoreLocal(tmp, pointer_size); - store_block(tp->tp_size, tp->tp_align); - LoadLocal(tmp, pointer_size); - FreeLocal(tmp); - } - else store_block(tp->tp_size, tp->tp_align); - } - else { - store_val(&(left->EX_VALUE), left->ex_type); - if (gencode && val == LVAL) { - EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); - } - } - break; - case PLUSAB: - case MINAB: - case TIMESAB: - case DIVAB: - case MODAB: - case LEFTAB: - case RIGHTAB: - case ANDAB: - case XORAB: - case ORAB: - case POSTINCR: - case POSTDECR: - case PLUSPLUS: - case MINMIN: - { - arith tmp = 0; - int compl; /* Complexity of left operand */ - int right_done = 0; - int dupval; + if (is_struct_or_union(tp->tp_fund) && !gencode) + { + EVAL(right, LVAL, true, NO_LABEL, NO_LABEL); + EVAL(left, LVAL, true, NO_LABEL, NO_LABEL); + copy_block(tp->tp_size, tp->tp_align); + break; + } + EVAL(right, RVAL, true, NO_LABEL, NO_LABEL); + if (gencode && val == RVAL) + C_dup(ATW(tp->tp_size)); + if (left->ex_class != Value) + { + EVAL(left, LVAL, true, NO_LABEL, NO_LABEL); + if (gencode && val == LVAL) + { + arith tmp = LocalPtrVar(); + C_dup(pointer_size); + StoreLocal(tmp, pointer_size); + store_block(tp->tp_size, tp->tp_align); + LoadLocal(tmp, pointer_size); + FreeLocal(tmp); + } + else + store_block(tp->tp_size, tp->tp_align); + } + else + { + store_val(&(left->EX_VALUE), left->ex_type); + if (gencode && val == LVAL) + { + EVAL(left, LVAL, true, NO_LABEL, NO_LABEL); + } + } + break; + case PLUSAB: + case MINAB: + case TIMESAB: + case DIVAB: + case MODAB: + case LEFTAB: + case RIGHTAB: + case ANDAB: + case XORAB: + case ORAB: + case POSTINCR: + case POSTDECR: + case PLUSPLUS: + case MINMIN: + { + arith tmp = 0; + int compl; /* Complexity of left operand */ + int right_done = 0; + int dupval; #ifndef NOBITFIELD - if (left->ex_type->tp_fund == FIELD) { - eval_field(expr, gencode); - break; - } + if (left->ex_type->tp_fund == FIELD) + { + eval_field(expr, gencode); + break; + } #endif /* NOBITFIELD */ - if (left->ex_class == Value) { - compl = 0; /* Value */ - } - else if (left->ex_depth == 1 && - !(left->ex_flags & EX_SIDEEFFECTS)) { - compl = 1; - } - else compl = 2; + if (left->ex_class == Value) + { + compl = 0; /* Value */ + } + else if (left->ex_depth == 1 && !(left->ex_flags & EX_SIDEEFFECTS)) + { + compl = 1; + } + else + compl = 2; - /* evaluate right-hand side first when possible, - but not for POSTINCR or PLUSPLUS, because then - we might miss a chance for increment instructions. - */ - if (compl != 2 && - tp->tp_fund != POINTER && - (oper == PLUSAB || oper == TIMESAB || - oper == ANDAB || oper == XORAB || oper == ORAB)) { - right_done = 1; - EVAL(right, RVAL, TRUE, NO_LABEL, NO_LABEL); - } - if (compl == 0) { - load_val(left, RVAL); - } - else - if (compl == 1) { - EVAL(left, RVAL, TRUE, NO_LABEL, NO_LABEL); - } - else { - EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); - tmp = LocalPtrVar(); - C_dup(pointer_size); - StoreLocal(tmp, pointer_size); - C_loi(left->ex_type->tp_size); - } - if (gencode && (oper == POSTINCR || - oper == POSTDECR)) - C_dup(ATW(left->ex_type->tp_size)); - conversion(left->ex_type, tp); - if (! right_done) { - EVAL(right, RVAL, TRUE, NO_LABEL, NO_LABEL); - } - dupval = gencode && oper != POSTINCR && - oper != POSTDECR; - assop(tp, oper); - conversion(tp, left->ex_type); - if (compl == 0) { - store_val(&(left->EX_VALUE), - left->ex_type); - if (dupval) load_val(left, RVAL); - } - else if (compl == 1) { - EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); - C_sti(left->ex_type->tp_size); - if (dupval) { - EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); - C_loi(left->ex_type->tp_size); - } - } - else { - LoadLocal(tmp, pointer_size); - C_sti(left->ex_type->tp_size); - if (dupval) { - LoadLocal(tmp, pointer_size); - C_loi(left->ex_type->tp_size); + /* evaluate right-hand side first when possible, + but not for POSTINCR or PLUSPLUS, because then + we might miss a chance for increment instructions. + */ + if (compl != 2 && tp->tp_fund != POINTER + && (oper == PLUSAB || oper == TIMESAB || oper == ANDAB || oper == XORAB + || oper == ORAB)) + { + right_done = 1; + EVAL(right, RVAL, true, NO_LABEL, NO_LABEL); + } + if (compl == 0) + { + load_val(left, RVAL); + } + else if (compl == 1) + { + EVAL(left, RVAL, true, NO_LABEL, NO_LABEL); + } + else + { + EVAL(left, LVAL, true, NO_LABEL, NO_LABEL); + tmp = LocalPtrVar(); + C_dup(pointer_size); + StoreLocal(tmp, pointer_size); + C_loi(left->ex_type->tp_size); + } + if (gencode && (oper == POSTINCR || oper == POSTDECR)) + C_dup(ATW(left->ex_type->tp_size)); + conversion(left->ex_type, tp); + if (!right_done) + { + EVAL(right, RVAL, true, NO_LABEL, NO_LABEL); + } + dupval = gencode && oper != POSTINCR && oper != POSTDECR; + assop(tp, oper); + conversion(tp, left->ex_type); + if (compl == 0) + { + store_val(&(left->EX_VALUE), left->ex_type); + if (dupval) + load_val(left, RVAL); + } + else if (compl == 1) + { + EVAL(left, LVAL, true, NO_LABEL, NO_LABEL); + C_sti(left->ex_type->tp_size); + if (dupval) + { + EVAL(left, LVAL, true, NO_LABEL, NO_LABEL); + C_loi(left->ex_type->tp_size); + } + } + else + { + LoadLocal(tmp, pointer_size); + C_sti(left->ex_type->tp_size); + if (dupval) + { + LoadLocal(tmp, pointer_size); + C_loi(left->ex_type->tp_size); + } + FreeLocal(tmp); + } + break; } - FreeLocal(tmp); - } - break; - } - case '(': - { - struct expr *ex; - arith ParSize = (arith)0; - label setjmp_label = 0; - arith retspace = 0; + case '(': + { + struct expr* ex; + arith ParSize = (arith)0; + label setjmp_label = 0; + arith retspace = 0; - if (ISNAME(left)) { - if (left->VL_IDF->id_special == SP_SETJMP) { - label addr_label = data_label(); + if (ISNAME(left)) + { + if (left->VL_IDF->id_special == SP_SETJMP) + { + label addr_label = data_label(); - setjmp_label = text_label(); - C_df_dlb(addr_label); - C_rom_ilb(setjmp_label); - C_lae_dlb(addr_label, (arith) 0); - C_loi(pointer_size); - ParSize += pointer_size; - } - } - if ((ex = right) != NILEXPR) { - /* function call with parameters*/ - while ( ex->ex_class == Oper && - ex->OP_OPER == PARCOMMA - ) { - EVAL(ex->OP_RIGHT, RVAL, TRUE, - NO_LABEL, NO_LABEL); - ParSize += ATW(ex->OP_RIGHT->ex_type->tp_size); - ex = ex->OP_LEFT; - } - EVAL(ex, RVAL, TRUE, NO_LABEL, NO_LABEL); - ParSize += ATW(ex->ex_type->tp_size); - } - if (is_struct_or_union(tp->tp_fund)) { - retspace = NewLocal(tp->tp_size, tp->tp_align, - -1, 0); - C_lal(retspace); - ParSize += pointer_size; - } - if (ISNAME(left)) { - /* e.g., main() { (*((int (*)())0))(); } */ - C_cal(left->VL_IDF->id_text); - if (setjmp_label) { - C_df_ilb(setjmp_label); - } -#ifdef DATAFLOW - { extern char options[]; - if (options['d']) - DfaCallFunction( - left->VL_IDF->id_text); - } -#endif /* DATAFLOW */ - } - else { - EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); - C_cai(); - } - /* remove parameters from stack */ - if (ParSize > (arith)0) - C_asp(ParSize); - if (gencode) { - if (is_struct_or_union(tp->tp_fund)) { - C_lfr(pointer_size); - if (val == RVAL) { - load_block(tp->tp_size, (int) word_size); - FreeLocal(retspace); + setjmp_label = text_label(); + C_df_dlb(addr_label); + C_rom_ilb(setjmp_label); + C_lae_dlb(addr_label, (arith)0); + C_loi(pointer_size); + ParSize += pointer_size; + } + } + if ((ex = right) != NILEXPR) + { + /* function call with parameters*/ + while (ex->ex_class == Oper && ex->OP_OPER == PARCOMMA) + { + EVAL(ex->OP_RIGHT, RVAL, true, NO_LABEL, NO_LABEL); + ParSize += ATW(ex->OP_RIGHT->ex_type->tp_size); + ex = ex->OP_LEFT; + } + EVAL(ex, RVAL, true, NO_LABEL, NO_LABEL); + ParSize += ATW(ex->ex_type->tp_size); } + if (is_struct_or_union(tp->tp_fund)) + { + retspace = NewLocal(tp->tp_size, tp->tp_align, -1, 0); + C_lal(retspace); + ParSize += pointer_size; + } + if (ISNAME(left)) + { + /* e.g., main() { (*((int (*)())0))(); } */ + C_cal(left->VL_IDF->id_text); + if (setjmp_label) + { + C_df_ilb(setjmp_label); + } +#ifdef DATAFLOW + { + extern char options[]; + if (options['d']) + DfaCallFunction(left->VL_IDF->id_text); + } +#endif /* DATAFLOW */ + } + else + { + EVAL(left, LVAL, true, NO_LABEL, NO_LABEL); + C_cai(); + } + /* remove parameters from stack */ + if (ParSize > (arith)0) + C_asp(ParSize); + if (gencode) + { + if (is_struct_or_union(tp->tp_fund)) + { + C_lfr(pointer_size); + if (val == RVAL) + { + load_block(tp->tp_size, (int)word_size); + FreeLocal(retspace); + } + } + else + C_lfr(ATW(tp->tp_size)); + } + if (tp->tp_fund == FLOAT || tp->tp_fund == DOUBLE || tp->tp_fund == LNGDBL) + fp_used = 1; + /* ??? set filename and line number ??? */ + break; } - else - C_lfr(ATW(tp->tp_size)); - } - if (tp->tp_fund == FLOAT || tp->tp_fund == DOUBLE - || tp->tp_fund == LNGDBL) - fp_used = 1; - /* ??? set filename and line number ??? */ - break; - } - case '.': - case ARROW: - if (tp->tp_fund == FLOAT || tp->tp_fund == DOUBLE - || tp->tp_fund == LNGDBL) - fp_used = 1; - EVAL(left, oper == '.' ? LVAL : RVAL, gencode, - NO_LABEL, NO_LABEL); - assert(is_cp_cst(right)); - if (gencode) { - C_adp((arith)right->VL_VALUE); - } - break; - case ',': - EVAL(left, RVAL, FALSE, NO_LABEL, NO_LABEL); - EVAL(right, val, gencode, true_label, false_label); - break; - case '~': - EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); - if (gencode) - C_com(tp->tp_size); - break; - case '?': /* must be followed by ':' */ - { - label l_true = text_label(); - label l_false = text_label(); - label l_end = text_label(); + case '.': + case ARROW: + if (tp->tp_fund == FLOAT || tp->tp_fund == DOUBLE || tp->tp_fund == LNGDBL) + fp_used = 1; + EVAL(left, oper == '.' ? LVAL : RVAL, gencode, NO_LABEL, NO_LABEL); + assert(is_cp_cst(right)); + if (gencode) + { + C_adp((arith)right->VL_VALUE); + } + break; + case ',': + EVAL(left, RVAL, false, NO_LABEL, NO_LABEL); + EVAL(right, val, gencode, true_label, false_label); + break; + case '~': + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); + if (gencode) + C_com(tp->tp_size); + break; + case '?': /* must be followed by ':' */ + { + label l_true = text_label(); + label l_false = text_label(); + label l_end = text_label(); - EVAL(left, RVAL, TRUE, l_true, l_false); - C_df_ilb(l_true); - EVAL(right->OP_LEFT, val, gencode, NO_LABEL, NO_LABEL); - C_bra(l_end); - C_df_ilb(l_false); - EVAL(right->OP_RIGHT, val, gencode, NO_LABEL, NO_LABEL); - C_df_ilb(l_end); - break; - } - case OR: - case AND: { - label l_false, l_true, l_maybe; + EVAL(left, RVAL, true, l_true, l_false); + C_df_ilb(l_true); + EVAL(right->OP_LEFT, val, gencode, NO_LABEL, NO_LABEL); + C_bra(l_end); + C_df_ilb(l_false); + EVAL(right->OP_RIGHT, val, gencode, NO_LABEL, NO_LABEL); + C_df_ilb(l_end); + break; + } + case OR: + case AND: + { + label l_false, l_true, l_maybe; - l_maybe = text_label(); - if (true_label) { - l_false = false_label; - l_true = true_label; - } - else { - l_false = text_label(); - l_true = gencode ? text_label(): l_false; - } + l_maybe = text_label(); + if (true_label) + { + l_false = false_label; + l_true = true_label; + } + else + { + l_false = text_label(); + l_true = gencode ? text_label() : l_false; + } - EVAL(left, RVAL, TRUE, oper == AND ? l_maybe : l_true, - oper == AND ? l_false : l_maybe); - C_df_ilb(l_maybe); - EVAL(right, RVAL, gencode, l_true, l_false); - if (gencode && !true_label) { - label l_end = text_label(); + EVAL( + left, RVAL, true, oper == AND ? l_maybe : l_true, + oper == AND ? l_false : l_maybe); + C_df_ilb(l_maybe); + EVAL(right, RVAL, gencode, l_true, l_false); + if (gencode && !true_label) + { + label l_end = text_label(); - C_df_ilb(l_true); - C_loc((arith)1); - C_bra(l_end); - C_df_ilb(l_false); - C_loc((arith)0); - C_df_ilb(l_end); - } - else { - if (! true_label) C_df_ilb(l_false); - } - } - break; - case '!': - if (true_label == 0) { - EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); - if (gencode) { - C_teq(); + C_df_ilb(l_true); + C_loc((arith)1); + C_bra(l_end); + C_df_ilb(l_false); + C_loc((arith)0); + C_df_ilb(l_end); + } + else + { + if (!true_label) + C_df_ilb(l_false); + } } + break; + case '!': + if (true_label == 0) + { + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); + if (gencode) + { + C_teq(); + } + } + else + EVAL(right, RVAL, gencode, false_label, true_label); + break; + case INT2INT: + case INT2FLOAT: + case FLOAT2INT: + case FLOAT2FLOAT: + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); + if (gencode) + conversion(right->ex_type, left->ex_type); + break; + default: + crash("(EVAL) bad operator %s\n", symbol2str(oper)); + } + /* If the rvalue of the expression is required but + only its lvalue is evaluated, its rvalue is + loaded by the following statements: + */ + if (gencode && val == RVAL && expr->ex_lvalue == 1) + { + if (expr->ex_type->tp_fund == FLOAT || expr->ex_type->tp_fund == DOUBLE + || expr->ex_type->tp_fund == LNGDBL) + fp_used = 1; + load_block(expr->ex_type->tp_size, expr->ex_type->tp_align); } - else - EVAL(right, RVAL, gencode, false_label, - true_label); - break; - case INT2INT: - case INT2FLOAT: - case FLOAT2INT: - case FLOAT2FLOAT: - EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); - if (gencode) - conversion(right->ex_type, left->ex_type); break; - default: - crash("(EVAL) bad operator %s\n", symbol2str(oper)); - } - /* If the rvalue of the expression is required but - only its lvalue is evaluated, its rvalue is - loaded by the following statements: - */ - if (gencode && val == RVAL && expr->ex_lvalue == 1) { - if (expr->ex_type->tp_fund == FLOAT - || expr->ex_type->tp_fund == DOUBLE - || expr->ex_type->tp_fund == LNGDBL) - fp_used = 1; - load_block(expr->ex_type->tp_size, - expr->ex_type->tp_align); } - break; - } - default: - crash("(EVAL) bad expression class"); + default: + crash("(EVAL) bad expression class"); } - if (val == RVAL && ((expr->ex_flags & EX_VOLATILE) || vol)) C_nop(); + if (val == RVAL && ((expr->ex_flags & EX_VOLATILE) || vol)) + C_nop(); } /* compare() serves as an auxiliary function of EVAL */ static void compare(int relop, label lbl) { - switch (relop) { - case '<': - C_zlt(lbl); - break; - case LESSEQ: - C_zle(lbl); - break; - case '>': - C_zgt(lbl); - break; - case GREATEREQ: - C_zge(lbl); - break; - case EQUAL: - C_zeq(lbl); - break; - case NOTEQUAL: - C_zne(lbl); - break; - default: - CRASH(); + switch (relop) + { + case '<': + C_zlt(lbl); + break; + case LESSEQ: + C_zle(lbl); + break; + case '>': + C_zgt(lbl); + break; + case GREATEREQ: + C_zge(lbl); + break; + case EQUAL: + C_zeq(lbl); + break; + case NOTEQUAL: + C_zne(lbl); + break; + default: + CRASH(); } } /* truthvalue() serves as an auxiliary function of EVAL */ static void truthvalue(int relop) { - switch (relop) { - case '<': - C_tlt(); - break; - case LESSEQ: - C_tle(); - break; - case '>': - C_tgt(); - break; - case GREATEREQ: - C_tge(); - break; - case EQUAL: - C_teq(); - break; - case NOTEQUAL: - C_tne(); - break; - default: - CRASH(); + switch (relop) + { + case '<': + C_tlt(); + break; + case LESSEQ: + C_tle(); + break; + case '>': + C_tgt(); + break; + case GREATEREQ: + C_tge(); + break; + case EQUAL: + C_teq(); + break; + case NOTEQUAL: + C_tne(); + break; + default: + CRASH(); } } - /* assop() generates the opcode of an assignment operators op= */ -void assop(struct type *type, int oper) +void assop(struct type* type, int oper) { arith size; int uns = type->tp_unsigned; if ((int)(size = type->tp_size) < (int)word_size) size = word_size; - switch (type->tp_fund) { - case CHAR: - case SHORT: - case INT: - case LONG: - case LNGLNG: - case ENUM: - switch (oper) { - case PLUSAB: - case PLUSPLUS: - case POSTINCR: - if (uns) - C_adu(size); - else - C_adi(size); - break; - case MINAB: - case MINMIN: - case POSTDECR: - if (uns) - C_sbu(size); - else - C_sbi(size); - break; - case TIMESAB: - if (uns) - C_mlu(size); - else - C_mli(size); - break; - case DIVAB: - if (uns) - C_dvu(size); - else - C_dvi(size); - break; - case MODAB: - if (uns) - C_rmu(size); - else - C_rmi(size); - break; - case LEFTAB: - if (uns) - C_slu(size); - else - C_sli(size); - break; - case RIGHTAB: - if (uns) - C_sru(size); - else - C_sri(size); - break; - case ANDAB: - C_and(size); - break; - case XORAB: - C_xor(size); - break; - case ORAB: - C_ior(size); - break; - } - break; - case FLOAT: - case DOUBLE: - case LNGDBL: - switch (oper) { - case PLUSAB: - case PLUSPLUS: /* ??? etc... */ - case POSTINCR: - C_adf(size); - break; - case MINAB: - case MINMIN: - case POSTDECR: - C_sbf(size); + switch (type->tp_fund) + { + case CHAR: + case SHORT: + case INT: + case LONG: + case LNGLNG: + case ENUM: + switch (oper) + { + case PLUSAB: + case PLUSPLUS: + case POSTINCR: + if (uns) + C_adu(size); + else + C_adi(size); + break; + case MINAB: + case MINMIN: + case POSTDECR: + if (uns) + C_sbu(size); + else + C_sbi(size); + break; + case TIMESAB: + if (uns) + C_mlu(size); + else + C_mli(size); + break; + case DIVAB: + if (uns) + C_dvu(size); + else + C_dvi(size); + break; + case MODAB: + if (uns) + C_rmu(size); + else + C_rmi(size); + break; + case LEFTAB: + if (uns) + C_slu(size); + else + C_sli(size); + break; + case RIGHTAB: + if (uns) + C_sru(size); + else + C_sri(size); + break; + case ANDAB: + C_and(size); + break; + case XORAB: + C_xor(size); + break; + case ORAB: + C_ior(size); + break; + } break; - case TIMESAB: - C_mlf(size); + case FLOAT: + case DOUBLE: + case LNGDBL: + switch (oper) + { + case PLUSAB: + case PLUSPLUS: /* ??? etc... */ + case POSTINCR: + C_adf(size); + break; + case MINAB: + case MINMIN: + case POSTDECR: + C_sbf(size); + break; + case TIMESAB: + C_mlf(size); + break; + case DIVAB: + C_dvf(size); + break; + } break; - case DIVAB: - C_dvf(size); + case POINTER: + if (oper == MINAB || oper == MINMIN || oper == POSTDECR) + C_ngi(size); + ptr_add(size); break; - } - break; - case POINTER: - if (oper == MINAB || oper == MINMIN || oper == POSTDECR) - C_ngi(size); - ptr_add(size); - break; - default: - crash("(assop) bad type %s\n", symbol2str(type->tp_fund)); + default: + crash("(assop) bad type %s\n", symbol2str(type->tp_fund)); } } static void ptr_add(arith size) { - if (size != pointer_size) { + if (size != pointer_size) + { C_loc(size); C_loc(pointer_size); C_cuu(); @@ -847,193 +908,213 @@ static void ptr_add(arith size) } /* store_val() generates code for a store operation. - There are four ways of storing data: - - into a global variable - - into an automatic local variable - - into a local static variable - - absolute addressing + There are four ways of storing data: + - into a global variable + - into an automatic local variable + - into a local static variable + - absolute addressing */ -void store_val(struct value *vl, struct type *tp) +void store_val(struct value* vl, struct type* tp) { int inword = 0; int indword = 0; writh wval = vl->vl_value; arith val = (arith)wval; - if (vl->vl_class == Const) { /* absolute addressing */ + if (vl->vl_class == Const) + { /* absolute addressing */ load_cst(wval, pointer_size); store_block(tp->tp_size, tp->tp_align); return; } - if (tp->tp_align % word_align == 0) { - if (tp->tp_size == word_size) inword = 1; - else if (tp->tp_size == dword_size) indword = 1; + if (tp->tp_align % word_align == 0) + { + if (tp->tp_size == word_size) + inword = 1; + else if (tp->tp_size == dword_size) + indword = 1; } - if (vl->vl_class == Name) { - struct idf *id = vl->vl_data.vl_idf; - struct def *df = id->id_def; + if (vl->vl_class == Name) + { + struct idf* id = vl->vl_data.vl_idf; + struct def* df = id->id_def; /* if (df->df_level == L_GLOBAL) { // } ??? re-examine */ - if (df->df_sc == GLOBAL - || df->df_sc == EXTERN - || df->df_sc == STATIC) { + if (df->df_sc == GLOBAL || df->df_sc == EXTERN || df->df_sc == STATIC) + { if (inword) C_ste_dnam(id->id_text, val); - else - if (indword) + else if (indword) C_sde_dnam(id->id_text, val); - else { + else + { C_lae_dnam(id->id_text, val); store_block(tp->tp_size, tp->tp_align); } } - else { + else + { assert(df->df_sc != STATIC); if (inword || indword) StoreLocal(df->df_address + val, tp->tp_size); - else { + else + { AddrLocal(df->df_address + val); store_block(tp->tp_size, tp->tp_align); } } } - else { + else + { label dlb = vl->vl_data.vl_lbl; assert(vl->vl_class == Label); if (inword) C_ste_dlb(dlb, val); - else - if (indword) + else if (indword) C_sde_dlb(dlb, val); - else { + else + { C_lae_dlb(dlb, val); store_block(tp->tp_size, tp->tp_align); } } } - /* load_val() generates code for stacking a certain value (from ex), - which can be obtained in one of the following ways: - - value from absolute addressed memory - - constant value - - function result - - global variable - - static variable - - local variable + which can be obtained in one of the following ways: + - value from absolute addressed memory + - constant value + - function result + - global variable + - static variable + - local variable - rlval generate rlval or lval + rlval generate rlval or lval */ -void load_val(struct expr *expr, int rlval) +void load_val(struct expr* expr, int rlval) { - struct type *tp = expr->ex_type; + struct type* tp = expr->ex_type; int rvalue = (rlval == RVAL && expr->ex_lvalue != 0); int inword = 0, indword = 0; writh wval = expr->VL_VALUE; arith val = (arith)wval; - if (expr->ex_type->tp_fund == FLOAT - || expr->ex_type->tp_fund == DOUBLE + if (expr->ex_type->tp_fund == FLOAT || expr->ex_type->tp_fund == DOUBLE || expr->ex_type->tp_fund == LNGDBL) fp_used = 1; - if (expr->VL_CLASS == Const) { - if (rvalue) { /* absolute addressing */ + if (expr->VL_CLASS == Const) + { + if (rvalue) + { /* absolute addressing */ load_cst(wval, pointer_size); load_block(tp->tp_size, tp->tp_align); } - else /* integer, unsigned, long, enum etc */ + else /* integer, unsigned, long, enum etc */ load_cst(wval, tp->tp_size); return; } - if (rvalue) { - if (tp->tp_align % word_align == 0) { - if (tp->tp_size == word_size) inword = 1; - else if (tp->tp_size == dword_size) indword = 1; + if (rvalue) + { + if (tp->tp_align % word_align == 0) + { + if (tp->tp_size == word_size) + inword = 1; + else if (tp->tp_size == dword_size) + indword = 1; } } - if (expr->VL_CLASS == Label) { - if (rvalue) { + if (expr->VL_CLASS == Label) + { + if (rvalue) + { if (inword) C_loe_dlb(expr->VL_LBL, val); - else - if (indword) + else if (indword) C_lde_dlb(expr->VL_LBL, val); - else { + else + { C_lae_dlb(expr->VL_LBL, val); load_block(tp->tp_size, tp->tp_align); } - } - else { + else + { C_lae_dlb(expr->VL_LBL, (arith)0); C_adp(val); } } - else { - struct idf *id = expr->VL_IDF; - struct def *df = id->id_def; + else + { + struct idf* id = expr->VL_IDF; + struct def* df = id->id_def; int fund = df->df_type->tp_fund; assert(ISNAME(expr)); - if (fund == FUNCTION) { + if (fund == FUNCTION) + { /* the previous statement tried to catch a function - identifier, which may be cast to a pointer to a - function. - assert(!(rvalue)); ??? + identifier, which may be cast to a pointer to a + function. + assert(!(rvalue)); ??? */ C_lpi(id->id_text); } else - /* if (df->df_level == L_GLOBAL) { // } ??? re-examine */ - if ( df->df_sc == GLOBAL - || df->df_sc == STATIC - || df->df_sc == EXTERN) { - if (rvalue) { - if (inword) - C_loe_dnam(id->id_text, val); + /* if (df->df_level == L_GLOBAL) { // } ??? re-examine */ + if (df->df_sc == GLOBAL || df->df_sc == STATIC || df->df_sc == EXTERN) + { + if (rvalue) + { + if (inword) + C_loe_dnam(id->id_text, val); + else if (indword) + C_lde_dnam(id->id_text, val); + else + { + C_lae_dnam(id->id_text, val); + load_block(tp->tp_size, tp->tp_align); + } + } else - if (indword) - C_lde_dnam(id->id_text, val); - else { - C_lae_dnam(id->id_text, val); - load_block(tp->tp_size, tp->tp_align); + { + C_lae_dnam(id->id_text, (arith)0); + C_adp(val); } } - else { - C_lae_dnam(id->id_text, (arith)0); - C_adp(val); - } - } - else { - /* assert(df->df_sc != STATIC); */ - if (rvalue) { - if (inword || indword) - LoadLocal(df->df_address + val, tp->tp_size); - else { - AddrLocal(df->df_address + val); - load_block(tp->tp_size, tp->tp_align); + else + { + /* assert(df->df_sc != STATIC); */ + if (rvalue) + { + if (inword || indword) + LoadLocal(df->df_address + val, tp->tp_size); + else + { + AddrLocal(df->df_address + val); + load_block(tp->tp_size, tp->tp_align); + } + } + else + { + AddrLocal(df->df_address); + C_adp(val); } } - else { - AddrLocal(df->df_address); - C_adp(val); - } - } } } void load_cst(writh val, arith siz) { /* EM can't encode ldc with constant over 4 bytes. - Such a constant must go into rom. + Such a constant must go into rom. */ if ((int)siz <= (int)word_size) C_loc(val); - else - if ((int)siz == (int)dword_size && (int)dword_size <= 4) + else if ((int)siz == (int)dword_size && (int)dword_size <= 4) C_ldc(val); - else { + else + { label datlab; C_df_dlb(datlab = data_label()); @@ -1043,10 +1124,9 @@ void load_cst(writh val, arith siz) } } -static void operands(struct expr *expr, int gencode) +static void operands(struct expr* expr, int gencode) { EVAL(expr->OP_LEFT, RVAL, gencode, NO_LABEL, NO_LABEL); EVAL(expr->OP_RIGHT, RVAL, gencode, NO_LABEL, NO_LABEL); } -#endif /* LINT */ - +#endif /* LINT */ diff --git a/lang/cem/cemcom.ansi/eval.h b/lang/cem/cemcom.ansi/eval.h index 4bbea2bbe6..bf4ac8b7e1 100644 --- a/lang/cem/cemcom.ansi/eval.h +++ b/lang/cem/cemcom.ansi/eval.h @@ -1,15 +1,14 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-02-06 - * + * */ #ifndef EVAL_H_ #define EVAL_H_ -#ifndef LINT - +#ifndef LINT #include #include "arith.h" /* writh */ @@ -18,19 +17,19 @@ struct expr; struct value; struct type; -void EVAL(struct expr *expr, int val, int code, label true_label, label false_label); +void EVAL(struct expr* expr, int val, int code, label true_label, label false_label); /* assop() generates the opcode of an assignment operators op= */ -void assop(struct type *type, int oper); +void assop(struct type* type, int oper); /* store_val() generates code for a store operation. - There are four ways of storing data: - - into a global variable - - into an automatic local variable - - into a local static variable - - absolute addressing + There are four ways of storing data: + - into a global variable + - into an automatic local variable + - into a local static variable + - absolute addressing */ -void store_val(struct value *vl, struct type *tp); -void load_val(struct expr *expr, int rlval); +void store_val(struct value* vl, struct type* tp); +void load_val(struct expr* expr, int rlval); void load_cst(writh val, arith siz); #endif /* LINT */ diff --git a/lang/cem/cemcom.ansi/expr.c b/lang/cem/cemcom.ansi/expr.c index fddfabbf83..7ce5661d5c 100644 --- a/lang/cem/cemcom.ansi/expr.c +++ b/lang/cem/cemcom.ansi/expr.c @@ -5,27 +5,28 @@ /* $Id$ */ /* EXPRESSION TREE HANDLING */ -#include -#include -#include "parameters.h" -#include -#include -#include "expr.h" -#include "idf.h" -#include "arith.h" -#include "def.h" -#include "type.h" -#include "label.h" -#include "expr.h" -#include "LLlex.h" -#include "Lpars.h" -#include "decspecs.h" -#include "declar.h" -#include "sizes.h" -#include "level.h" -#include "cstoper.h" -#include "error.h" - +#include +#include +#include +#include +#include "parameters.h" +#include +#include +#include "expr.h" +#include "idf.h" +#include "arith.h" +#include "def.h" +#include "type.h" +#include "label.h" +#include "expr.h" +#include "LLlex.h" +#include "Lpars.h" +#include "decspecs.h" +#include "declar.h" +#include "sizes.h" +#include "level.h" +#include "cstoper.h" +#include "error.h" extern char options[]; extern int InSizeof; @@ -36,106 +37,106 @@ int rank_of(int oper) */ switch (oper) { - default: - return 0; /* INT2INT etc. */ - case '[': - case '(': - case '.': - case ARROW: - case PARCOMMA: - return 1; - case '!': - case PLUSPLUS: - case MINMIN: - case CAST: - case SIZEOF: - case ADDRESSOF: - return 2; /* monadic */ - case '*': - case '/': - case '%': - return 3; - case '+': - case '-': - return 4; - case LEFT: - case RIGHT: - return 5; - case '<': - case '>': - case LESSEQ: - case GREATEREQ: - return 6; - case EQUAL: - case NOTEQUAL: - return 7; - case '&': - return 8; - case '^': - return 9; - case '|': - return 10; - case AND: - return 11; - case OR: - return 12; - case '?': - case ':': - return 13; - case '=': - case PLUSAB: - case MINAB: - case TIMESAB: - case DIVAB: - case MODAB: - case RIGHTAB: - case LEFTAB: - case ANDAB: - case XORAB: - case ORAB: - return 14; - case ',': - return 15; + default: + return 0; /* INT2INT etc. */ + case '[': + case '(': + case '.': + case ARROW: + case PARCOMMA: + return 1; + case '!': + case PLUSPLUS: + case MINMIN: + case CAST: + case SIZEOF: + case ADDRESSOF: + return 2; /* monadic */ + case '*': + case '/': + case '%': + return 3; + case '+': + case '-': + return 4; + case LEFT: + case RIGHT: + return 5; + case '<': + case '>': + case LESSEQ: + case GREATEREQ: + return 6; + case EQUAL: + case NOTEQUAL: + return 7; + case '&': + return 8; + case '^': + return 9; + case '|': + return 10; + case AND: + return 11; + case OR: + return 12; + case '?': + case ':': + return 13; + case '=': + case PLUSAB: + case MINAB: + case TIMESAB: + case DIVAB: + case MODAB: + case RIGHTAB: + case LEFTAB: + case ANDAB: + case XORAB: + case ORAB: + return 14; + case ',': + return 15; } UNREACHABLE_CODE; } -void dot2expr(struct expr **expp) +void dot2expr(struct expr** expp) { /* The token in dot is converted into an expression, a pointer to which is stored in *expp. */ - struct expr *ex = new_expr(); + struct expr* ex = new_expr(); *expp = ex; ex->ex_file = dot.tk_file; ex->ex_line = dot.tk_line; switch (DOT) { - case IDENTIFIER: - idf2expr(ex); - break; - case INTEGER: - int2expr(ex); - break; - case FLOATING: - float2expr(ex); - break; - default: - crash("bad conversion to expression"); - UNREACHABLE_CODE; + case IDENTIFIER: + idf2expr(ex); + break; + case INTEGER: + int2expr(ex); + break; + case FLOATING: + float2expr(ex); + break; + default: + crash("bad conversion to expression"); + UNREACHABLE_CODE; } } -void idf2expr(struct expr *expr) +void idf2expr(struct expr* expr) { /* Dot contains an identifier which is turned into an expression. Note that this constitutes an applied occurrence of the identifier. */ - struct idf *idf = dot.tk_idf; /* != 0*/ - struct def *def = idf->id_def; + struct idf* idf = dot.tk_idf; /* != 0*/ + struct def* def = idf->id_def; if (def == 0) { @@ -156,7 +157,7 @@ void idf2expr(struct expr *expr) def = idf->id_def; } /* now def != 0 */ -#ifndef LINT +#ifndef LINT if (!InSizeof) { if (!def->df_used) @@ -167,15 +168,16 @@ void idf2expr(struct expr *expr) def->df_used = 1; } } -#endif /* LINT */ +#endif /* LINT */ expr->ex_type = def->df_type; if (expr->ex_type == error_type) { expr->ex_flags |= EX_ERROR; } - expr->ex_lvalue = - (def->df_type->tp_fund == FUNCTION || def->df_type->tp_fund == ARRAY - || def->df_sc == ENUM) ? 0 : 1; + expr->ex_lvalue = (def->df_type->tp_fund == FUNCTION || def->df_type->tp_fund == ARRAY + || def->df_sc == ENUM) + ? 0 + : 1; if (def->df_type->tp_typequal & TQ_CONST) expr->ex_flags |= EX_READONLY; if (def->df_type->tp_typequal & TQ_VOLATILE) @@ -186,14 +188,14 @@ void idf2expr(struct expr *expr) expr->VL_CLASS = Const; expr->VL_VALUE = (writh)def->df_address; } -#ifndef LINT +#ifndef LINT else if (def->df_sc == STATIC && def->df_level >= L_LOCAL) { expr->VL_CLASS = Label; expr->VL_LBL = def->df_address; expr->VL_VALUE = 0; } -#endif /* LINT */ +#endif /* LINT */ else { expr->VL_CLASS = Name; @@ -202,13 +204,13 @@ void idf2expr(struct expr *expr) } } -void string2expr(struct expr **expp, char *str, int len) +void string2expr(struct expr** expp, char* str, int len) { /* The string in the argument is converted into an expression, a pointer to which is stored in *expp. */ - struct expr *ex = new_expr(); + struct expr* ex = new_expr(); *expp = ex; ex->ex_file = dot.tk_file; @@ -222,7 +224,7 @@ void string2expr(struct expr **expp, char *str, int len) ex->SG_LEN = len; } -void int2expr(struct expr *expr) +void int2expr(struct expr* expr) { /* Dot contains an integer constant which is turned into an expression. @@ -230,7 +232,7 @@ void int2expr(struct expr *expr) fill_int_expr(expr, dot.tk_ival, dot.tk_fund); } -void float2expr(struct expr *expr) +void float2expr(struct expr* expr) { /* Dot contains a floating point constant which is turned into an expression. @@ -240,17 +242,17 @@ void float2expr(struct expr *expr) fund = dot.tk_fund; switch (fund) { - case FLOAT: - expr->ex_type = float_type; - break; - case DOUBLE: - expr->ex_type = double_type; - break; - case LNGDBL: - expr->ex_type = lngdbl_type; - break; - default: - crash("(float2expr) bad fund %s\n", symbol2str(fund)); + case FLOAT: + expr->ex_type = float_type; + break; + case DOUBLE: + expr->ex_type = double_type; + break; + case LNGDBL: + expr->ex_type = lngdbl_type; + break; + default: + crash("(float2expr) bad fund %s\n", symbol2str(fund)); } expr->ex_class = Float; flt_str2flt(dot.tk_fval, &(expr->FL_ARITH)); @@ -260,13 +262,12 @@ void float2expr(struct expr *expr) expr_warning(expr, "internal floating point overflow"); } -struct expr*intexpr( -arith ivalue, int fund) +struct expr* intexpr(arith ivalue, int fund) { /* The value ivalue is turned into an integer expression of the size indicated by fund. */ - struct expr *expr = new_expr(); + struct expr* expr = new_expr(); expr->ex_file = dot.tk_file; expr->ex_line = dot.tk_line; @@ -274,39 +275,38 @@ arith ivalue, int fund) return expr; } -void fill_int_expr(struct expr *ex, -writh ivalue, int fund) +void fill_int_expr(struct expr* ex, writh ivalue, int fund) { /* Details derived from ivalue and fund are put into the constant integer expression ex. */ switch (fund) { - case INT: - ex->ex_type = int_type; - break; - case UNSIGNED: - ex->ex_type = uint_type; - break; - case LONG: - ex->ex_type = long_type; - break; - case ULONG: - ex->ex_type = ulong_type; - break; - case LNGLNG: - ex->ex_type = lnglng_type; - break; - case ULNGLNG: - ex->ex_type = ulnglng_type; - break; - case ERRONEOUS: /* 123LL when no_long_long() */ - ex->ex_type = error_type; - ex->ex_flags |= EX_ERROR; - break; - default: - crash("(fill_int_expr) bad fund %s\n", symbol2str(fund)); - UNREACHABLE_CODE; + case INT: + ex->ex_type = int_type; + break; + case UNSIGNED: + ex->ex_type = uint_type; + break; + case LONG: + ex->ex_type = long_type; + break; + case ULONG: + ex->ex_type = ulong_type; + break; + case LNGLNG: + ex->ex_type = lnglng_type; + break; + case ULNGLNG: + ex->ex_type = ulnglng_type; + break; + case ERRONEOUS: /* 123LL when no_long_long() */ + ex->ex_type = error_type; + ex->ex_flags |= EX_ERROR; + break; + default: + crash("(fill_int_expr) bad fund %s\n", symbol2str(fund)); + UNREACHABLE_CODE; } ex->ex_class = Value; ex->VL_CLASS = Const; @@ -314,8 +314,7 @@ writh ivalue, int fund) cut_size(ex); } -struct expr *new_oper(struct type *tp, struct expr *e1, int oper, - struct expr *e2) +struct expr* new_oper(struct type* tp, struct expr* e1, int oper, struct expr* e2) { /* A new expression is constructed which consists of the operator oper which has e1 and e2 as operands; for a @@ -323,12 +322,12 @@ struct expr *new_oper(struct type *tp, struct expr *e1, int oper, During the construction of the right recursive initialisation tree it is possible for e2 to be NILEXPR. */ - struct expr *expr = new_expr(); - struct oper *op; + struct expr* expr = new_expr(); + struct oper* op; if (e2) { - struct expr *e = e2; + struct expr* e = e2; while (e->ex_class == Oper && e->OP_LEFT) e = e->OP_LEFT; @@ -337,7 +336,7 @@ struct expr *new_oper(struct type *tp, struct expr *e1, int oper, } else if (e1) { - struct expr *e = e1; + struct expr* e = e1; while (e->ex_class == Oper && e->OP_RIGHT) e = e->OP_RIGHT; @@ -358,10 +357,8 @@ struct expr *new_oper(struct type *tp, struct expr *e1, int oper, int e1_depth = e1 ? e1->ex_depth : 0; int e1_flags = e1 ? e1->ex_flags : 0; - expr->ex_depth = (e1_depth > e2->ex_depth ? e1_depth : e2->ex_depth) - + 1; - expr->ex_flags = (e1_flags | e2->ex_flags) - & ~(EX_PARENS | EX_READONLY | EX_VOLATILE); + expr->ex_depth = (e1_depth > e2->ex_depth ? e1_depth : e2->ex_depth) + 1; + expr->ex_flags = (e1_flags | e2->ex_flags) & ~(EX_PARENS | EX_READONLY | EX_VOLATILE); } /* * A function call should be evaluated first when possible. Just say @@ -376,13 +373,13 @@ struct expr *new_oper(struct type *tp, struct expr *e1, int oper, op->op_oper = oper; op->op_left = e1; op->op_right = e2; -#ifdef LINT +#ifdef LINT lint_new_oper(expr); -#endif /* LINT */ +#endif /* LINT */ return expr; } -void chk_cst_expr(struct expr **expp) +void chk_cst_expr(struct expr** expp) { /* The expression expr is checked for constancy. @@ -404,33 +401,33 @@ void chk_cst_expr(struct expr **expp) Special problems (of which there is only one, sizeof in Preprocessor #if) have to be dealt with locally */ - struct expr *expr = *expp; + struct expr* expr = *expp; -#ifdef DEBUG +#ifdef DEBUG print_expr("constant_expression", expr); -#endif /* DEBUG */ +#endif /* DEBUG */ switch (expr->ex_type->tp_fund) { - case CHAR: - case SHORT: - case INT: - case ENUM: - case LONG: - case LNGLNG: - if (is_ld_cst(expr)) - { - return; - } - expr_error(expr, "expression is not constant"); - break; - default: - expr_error(expr, "non-numerical constant expression"); - break; + case CHAR: + case SHORT: + case INT: + case ENUM: + case LONG: + case LNGLNG: + if (is_ld_cst(expr)) + { + return; + } + expr_error(expr, "expression is not constant"); + break; + default: + expr_error(expr, "non-numerical constant expression"); + break; } erroneous2int(expp); } -void init_expression(struct expr ***eppp, struct expr *expr) +void init_expression(struct expr*** eppp, struct expr* expr) { /* The expression expr is added to the tree designated indirectly by **eppp. @@ -448,19 +445,19 @@ void init_expression(struct expr ***eppp, struct expr *expr) *eppp = &(**eppp)->OP_RIGHT; } -int is_ld_cst(struct expr *expr) +int is_ld_cst(struct expr* expr) { /* An expression is a `load-time constant' if it is of the form +/- or . */ -#ifdef LINT +#ifdef LINT if (expr->ex_class == String) - return 1; -#endif /* LINT */ + return 1; +#endif /* LINT */ return expr->ex_lvalue == 0 && expr->ex_class == Value; } -int is_cp_cst(struct expr *expr) +int is_cp_cst(struct expr* expr) { /* An expression is a `compile-time constant' if it is a load-time constant, and the idf is not there. @@ -468,7 +465,7 @@ int is_cp_cst(struct expr *expr) return is_ld_cst(expr) && expr->VL_CLASS == Const; } -int is_fp_cst(struct expr *expr) +int is_fp_cst(struct expr* expr) { /* An expression is a `floating-point constant' if it consists of the float only. @@ -476,22 +473,22 @@ int is_fp_cst(struct expr *expr) return expr->ex_class == Float; } -int is_zero_cst(struct expr *expr) +int is_zero_cst(struct expr* expr) { flt_arith var; switch (expr->ex_class) { - case Value: - return expr->VL_VALUE == 0; - case Float: - flt_arith2flt((arith) 0, &var, 0); - return flt_cmp(&var, &(expr->FL_ARITH)) == 0; + case Value: + return expr->VL_VALUE == 0; + case Float: + flt_arith2flt((arith)0, &var, 0); + return flt_cmp(&var, &(expr->FL_ARITH)) == 0; } UNREACHABLE_CODE; } -void free_expression(struct expr *expr) +void free_expression(struct expr* expr) { /* The expression expr is freed recursively. */ diff --git a/lang/cem/cemcom.ansi/expr.str b/lang/cem/cemcom.ansi/expr.str index 51718ace6e..572f5b7024 100644 --- a/lang/cem/cemcom.ansi/expr.str +++ b/lang/cem/cemcom.ansi/expr.str @@ -13,51 +13,57 @@ #include "flt_arith.h" /* What we want to define is the struct expr, but since it contains - a union of various goodies, we define them first; so be patient. + a union of various goodies, we define them first; so be patient. */ /* classes of value */ -#define Const 1 -#define Name 2 -#define Label 3 - -struct value { - int vl_class; /* Const, Name or Label */ - writh vl_value; /* constant value or offset */ - union { - struct idf *vl_idf; /* external name */ - label vl_lbl; /* compiler-generated label */ +#define Const 1 +#define Name 2 +#define Label 3 + +struct value +{ + int vl_class; /* Const, Name or Label */ + writh vl_value; /* constant value or offset */ + union + { + struct idf* vl_idf; /* external name */ + label vl_lbl; /* compiler-generated label */ } vl_data; }; -struct string { - char *sg_value; /* row of bytes repr. the constant */ - int sg_len; /* length of the row */ +struct string +{ + char* sg_value; /* row of bytes repr. the constant */ + int sg_len; /* length of the row */ }; -struct oper { - struct type *op_type; /* resulting type of the operation */ - struct expr *op_left; - int op_oper; /* the symbol of the operator */ - struct expr *op_right; +struct oper +{ + struct type* op_type; /* resulting type of the operation */ + struct expr* op_left; + int op_oper; /* the symbol of the operator */ + struct expr* op_right; }; /* The following constants indicate the class of the expression: */ -#define Value 0 /* it is a value known at load time */ -#define String 1 /* it is a string constant */ -#define Float 2 /* it is a floating point constant */ -#define Oper 3 /* it is a run-time expression */ -#define Type 4 /* only its type is relevant */ - -struct expr { - char *ex_file; /* the file it (probably) comes from */ - unsigned int ex_line; /* the line it (probably) comes from */ - struct type *ex_type; +#define Value 0 /* it is a value known at load time */ +#define String 1 /* it is a string constant */ +#define Float 2 /* it is a floating point constant */ +#define Oper 3 /* it is a run-time expression */ +#define Type 4 /* only its type is relevant */ + +struct expr +{ + char* ex_file; /* the file it (probably) comes from */ + unsigned int ex_line; /* the line it (probably) comes from */ + struct type* ex_type; short ex_lvalue; short ex_flags; int ex_class; int ex_depth; - union { + union + { struct value ex_value; struct string ex_string; flt_arith ex_fl_arith; @@ -66,60 +72,58 @@ struct expr { }; /* some abbreviated selections */ -#define EX_VALUE ex_object.ex_value -#define VL_CLASS EX_VALUE.vl_class -#define VL_VALUE EX_VALUE.vl_value -#define VL_IDF EX_VALUE.vl_data.vl_idf -#define VL_LBL EX_VALUE.vl_data.vl_lbl -#define SG_VALUE ex_object.ex_string.sg_value -#define SG_LEN ex_object.ex_string.sg_len -#define FL_ARITH ex_object.ex_fl_arith -#define OP_TYPE ex_object.ex_oper.op_type -#define OP_LEFT ex_object.ex_oper.op_left -#define OP_OPER ex_object.ex_oper.op_oper -#define OP_RIGHT ex_object.ex_oper.op_right +#define EX_VALUE ex_object.ex_value +#define VL_CLASS EX_VALUE.vl_class +#define VL_VALUE EX_VALUE.vl_value +#define VL_IDF EX_VALUE.vl_data.vl_idf +#define VL_LBL EX_VALUE.vl_data.vl_lbl +#define SG_VALUE ex_object.ex_string.sg_value +#define SG_LEN ex_object.ex_string.sg_len +#define FL_ARITH ex_object.ex_fl_arith +#define OP_TYPE ex_object.ex_oper.op_type +#define OP_LEFT ex_object.ex_oper.op_left +#define OP_OPER ex_object.ex_oper.op_oper +#define OP_RIGHT ex_object.ex_oper.op_right /* some bits for the ex_flag field, to keep track of various - interesting properties of an expression. + interesting properties of an expression. */ -#define EX_SIZEOF 0x001 /* contains sizeof operator */ -#define EX_CAST 0x002 /* contains cast */ -#define EX_LOGICAL 0x004 /* contains logical operator */ -#define EX_COMMA 0x008 /* contains expression comma */ -#define EX_PARENS 0x010 /* the top level is parenthesized */ -#define EX_SIDEEFFECTS 0x020 /* expression has side effects */ -#define EX_READONLY 0x040 /* read only variabele */ -#define EX_VOLATILE 0x080 /* volatile variabele */ -#define EX_ILVALUE 0x100 /* an illegal lvalue e.g. f().x */ -#define EX_ERROR 0x200 /* the expression is wrong */ -#define EX_PTRDIFF 0x400 /* subtracting 2 pointers in expr. */ - -#define NILEXPR ((struct expr *)0) +#define EX_SIZEOF 0x001 /* contains sizeof operator */ +#define EX_CAST 0x002 /* contains cast */ +#define EX_LOGICAL 0x004 /* contains logical operator */ +#define EX_COMMA 0x008 /* contains expression comma */ +#define EX_PARENS 0x010 /* the top level is parenthesized */ +#define EX_SIDEEFFECTS 0x020 /* expression has side effects */ +#define EX_READONLY 0x040 /* read only variabele */ +#define EX_VOLATILE 0x080 /* volatile variabele */ +#define EX_ILVALUE 0x100 /* an illegal lvalue e.g. f().x */ +#define EX_ERROR 0x200 /* the expression is wrong */ +#define EX_PTRDIFF 0x400 /* subtracting 2 pointers in expr. */ + +#define NILEXPR ((struct expr*)0) /* some useful tests */ -#define ISNAME(e) ((e)->ex_class == Value && (e)->VL_CLASS == Name) -#define ISCOMMA(e) ((e)->ex_class == Oper && (e)->OP_OPER == INITCOMMA) +#define ISNAME(e) ((e)->ex_class == Value && (e)->VL_CLASS == Name) +#define ISCOMMA(e) ((e)->ex_class == Oper && (e)->OP_OPER == INITCOMMA) /* ALLOCDEF "expr" 20 */ - - int rank_of(int oper); -void dot2expr(struct expr **expp); -void idf2expr(register struct expr *expr); -void string2expr(register struct expr **expp, char *str, int len); -void int2expr(struct expr *expr); -void float2expr(register struct expr *expr); +void dot2expr(struct expr** expp); +void idf2expr(register struct expr* expr); +void string2expr(register struct expr** expp, char* str, int len); +void int2expr(struct expr* expr); +void float2expr(register struct expr* expr); struct expr* intexpr(arith ivalue, int fund); -void fill_int_expr(register struct expr *ex, writh ivalue, int fund); -struct expr *new_oper(struct type *tp, register struct expr *e1, int oper, - register struct expr *e2); -void chk_cst_expr(struct expr **expp); -void init_expression(register struct expr ***eppp, struct expr *expr); -int is_ld_cst(register struct expr *expr); -int is_cp_cst(struct expr *expr); -int is_fp_cst(struct expr *expr); -int is_zero_cst(register struct expr *expr); -void free_expression(register struct expr *expr); +void fill_int_expr(register struct expr* ex, writh ivalue, int fund); +struct expr* +new_oper(struct type* tp, register struct expr* e1, int oper, register struct expr* e2); +void chk_cst_expr(struct expr** expp); +void init_expression(register struct expr*** eppp, struct expr* expr); +int is_ld_cst(register struct expr* expr); +int is_cp_cst(struct expr* expr); +int is_fp_cst(struct expr* expr); +int is_zero_cst(register struct expr* expr); +void free_expression(register struct expr* expr); #endif \ No newline at end of file diff --git a/lang/cem/cemcom.ansi/field.c b/lang/cem/cemcom.ansi/field.c index 0f19030768..c202c4bf45 100644 --- a/lang/cem/cemcom.ansi/field.c +++ b/lang/cem/cemcom.ansi/field.c @@ -5,117 +5,118 @@ /* $Id$ */ /* BITFIELD EXPRESSION EVALUATOR */ -#include "parameters.h" -#ifndef LINT - +#include "parameters.h" +#ifndef LINT #ifndef NOBITFIELD -#include -#include -#include -#include -#include "arith.h" -#include "type.h" -#include "label.h" -#include "code.h" -#include "expr.h" -#include "sizes.h" -#include "align.h" -#include "Lpars.h" -#include "field.h" -#include "util.h" -#include "conversion.h" -#include "eval.h" - +#include +#include +#include +#include +#include +#include +#include "arith.h" +#include "type.h" +#include "label.h" +#include "code.h" +#include "expr.h" +#include "sizes.h" +#include "align.h" +#include "Lpars.h" +#include "field.h" +#include "util.h" +#include "conversion.h" +#include "eval.h" /* Eval_field() evaluates expressions involving bit fields. - The various instructions are not yet optimised in the expression - tree and are therefore dealt with in this function. - The actions taken at any operation are described clearly by the - code for this actions. - Notes - [1] the bitfields are packed in target machine integers! - [2] op is either an assignment operator or an increment/ - decrement operator - [3] atype: the type in which the bitfield arithmetic is done; - and in which bitfields are stored! + The various instructions are not yet optimised in the expression + tree and are therefore dealt with in this function. + The actions taken at any operation are described clearly by the + code for this actions. + Notes + [1] the bitfields are packed in target machine integers! + [2] op is either an assignment operator or an increment/ + decrement operator + [3] atype: the type in which the bitfield arithmetic is done; + and in which bitfields are stored! */ -void eval_field( - struct expr *expr, - int code) +void eval_field(struct expr* expr, int code) { int op = expr->OP_OPER; - struct expr *leftop = expr->OP_LEFT; - struct expr *rightop = expr->OP_RIGHT; - struct field *fd = leftop->ex_type->tp_field; - struct type *tp = leftop->ex_type->tp_up; + struct expr* leftop = expr->OP_LEFT; + struct expr* rightop = expr->OP_RIGHT; + struct field* fd = leftop->ex_type->tp_field; + struct type* tp = leftop->ex_type->tp_up; arith tmpvar = 0; - struct type *atype = ( tp->tp_unsigned - && fd->fd_width >= 8 * (int)word_size) - ? uword_type - : word_type; + struct type* atype + = (tp->tp_unsigned && fd->fd_width >= 8 * (int)word_size) ? uword_type : word_type; /* First some assertions to be sure that the rest is legal */ - assert(atype->tp_size == word_size); /* make sure that C_loc() is legal */ + assert(atype->tp_size == word_size); /* make sure that C_loc() is legal */ assert(leftop->ex_type->tp_fund == FIELD); - leftop->ex_type = atype; /* this is cheating but it works... */ - if (op == '=') { + leftop->ex_type = atype; /* this is cheating but it works... */ + if (op == '=') + { /* F = E: f = ((E & mask)<ex_type); - EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); + EVAL(rightop, RVAL, true, NO_LABEL, NO_LABEL); conversion(tp, atype); - store_field(fd, tp->tp_unsigned, code, leftop, (arith) 0); + store_field(fd, tp->tp_unsigned, code, leftop, (arith)0); } - else { /* treat ++F as F += 1 and --F as F -= 1 */ + else + { /* treat ++F as F += 1 and --F as F -= 1 */ /* F op= e: f = (((((f>>shift)&mask) op e)&mask)<ex_depth == 0) /* simple case */ + if (leftop->ex_depth == 0) /* simple case */ load_val(leftop, RVAL); - else { /* complex case */ - tmpvar = NewLocal(pointer_size, pointer_align, - reg_pointer, 0); - EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); + else + { /* complex case */ + tmpvar = NewLocal(pointer_size, pointer_align, reg_pointer, 0); + EVAL(leftop, LVAL, true, NO_LABEL, NO_LABEL); C_dup(pointer_size); StoreLocal(tmpvar, pointer_size); C_loi(word_size); } - if (tp->tp_unsigned) { + if (tp->tp_unsigned) + { C_loc((arith)fd->fd_shift); C_sru(word_size); C_loc(fd->fd_mask); C_and(word_size); } - else { + else + { arith sft = (int)word_size * 8 - fd->fd_width; C_loc(sft - fd->fd_shift); C_sli(word_size); C_loc(sft); C_sri(word_size); } - if (code == TRUE && (op == POSTINCR || op == POSTDECR)) + if (code == true && (op == POSTINCR || op == POSTDECR)) C_dup(word_size); conversion(atype, rightop->ex_type); - EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); + EVAL(rightop, RVAL, true, NO_LABEL, NO_LABEL); /* the 'op' operation: */ if (op == PLUSPLUS || op == POSTINCR) assop(rightop->ex_type, PLUSAB); - else - if (op == MINMIN || op == POSTDECR) + else if (op == MINMIN || op == POSTDECR) assop(rightop->ex_type, MINAB); else assop(rightop->ex_type, op); conversion(rightop->ex_type, atype); - store_field(fd, atype->tp_unsigned, - code == TRUE && op != POSTINCR && op != POSTDECR, - leftop, tmpvar); + store_field( + fd, atype->tp_unsigned, code == true && op != POSTINCR && op != POSTDECR, leftop, + tmpvar); } - if (code == TRUE) { + if (code == true) + { /* Take care that the effective value stored in - the bit field (i.e. the value that is got on - retrieval) is on top of stack. + the bit field (i.e. the value that is got on + retrieval) is on top of stack. */ - if (tp->tp_unsigned == 0) { /* sign extension */ + if (tp->tp_unsigned == 0) + { /* sign extension */ arith shift = (int)word_size * 8 - fd->fd_width; C_loc(shift); @@ -127,18 +128,13 @@ void eval_field( } } -void store_field( - struct field *fd, - int uns, - int code, - struct expr *leftop, - arith tmpvar) +void store_field(struct field* fd, int uns, int code, struct expr* leftop, arith tmpvar) { arith high_mask; C_loc(fd->fd_mask); C_and(word_size); - if (code == TRUE) + if (code == true) C_dup(word_size); C_loc((arith)fd->fd_shift); if (uns) @@ -147,17 +143,19 @@ void store_field( C_sli(word_size); high_mask = (arith)~full_mask[(int)word_size]; C_loc(~((fd->fd_mask << fd->fd_shift) | high_mask)); - if (leftop->ex_depth == 0) { /* simple case */ + if (leftop->ex_depth == 0) + { /* simple case */ load_val(leftop, RVAL); C_and(word_size); C_ior(word_size); store_val(&(leftop->EX_VALUE), uns ? uword_type : word_type); } - else { /* complex case */ - if (! tmpvar) { - tmpvar = NewLocal(pointer_size, pointer_align, - reg_pointer, 0); - EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); + else + { /* complex case */ + if (!tmpvar) + { + tmpvar = NewLocal(pointer_size, pointer_align, reg_pointer, 0); + EVAL(leftop, LVAL, true, NO_LABEL, NO_LABEL); StoreLocal(tmpvar, pointer_size); } LoadLocal(tmpvar, pointer_size); @@ -171,5 +169,4 @@ void store_field( } #endif /* NOBITFIELD */ -#endif /* LINT */ - +#endif /* LINT */ diff --git a/lang/cem/cemcom.ansi/field.str b/lang/cem/cemcom.ansi/field.str index 2c8635c43d..ec59339623 100644 --- a/lang/cem/cemcom.ansi/field.str +++ b/lang/cem/cemcom.ansi/field.str @@ -10,28 +10,28 @@ /* $Id$ */ /* FIELD DESCRIPTOR */ -struct field { /* for field specifiers */ +struct field +{ /* for field specifiers */ arith fd_mask; int fd_shift; int fd_width; - struct sdef *fd_sdef; /* upward pointer */ + struct sdef* fd_sdef; /* upward pointer */ }; /* ALLOCDEF "field" 10 */ -#ifndef LINT - +#ifndef LINT #ifndef NOBITFIELD struct expr; -void store_field(register struct field *fd, int uns, int code, - register struct expr *leftop, arith tmpvar); -void eval_field(struct expr *expr, int code); +void store_field( + register struct field* fd, int uns, int code, register struct expr* leftop, arith tmpvar); +void eval_field(struct expr* expr, int code); #endif /* NOBITFIELD */ -#endif /* LINT */ +#endif /* LINT */ #endif /* FIELD_H_ */ \ No newline at end of file diff --git a/lang/cem/cemcom.ansi/file_info.h b/lang/cem/cemcom.ansi/file_info.h index c1f6d8b15b..38f2abb7cc 100644 --- a/lang/cem/cemcom.ansi/file_info.h +++ b/lang/cem/cemcom.ansi/file_info.h @@ -8,18 +8,19 @@ #ifndef FILE_INFO_H #define FILE_INFO_H -struct file_info { - unsigned int fil_lino; - int fil_nestlow; - char *fil_name; - char *fil_wdir; +struct file_info +{ + unsigned int fil_lino; + int fil_nestlow; + char* fil_name; + char* fil_wdir; }; -#define nestlow finfo.fil_nestlow -#define LineNumber finfo.fil_lino -#define FileName finfo.fil_name -#define WorkingDir finfo.fil_wdir +#define nestlow finfo.fil_nestlow +#define LineNumber finfo.fil_lino +#define FileName finfo.fil_name +#define WorkingDir finfo.fil_wdir -extern struct file_info finfo; /* input.c */ +extern struct file_info finfo; /* input.c */ #endif diff --git a/lang/cem/cemcom.ansi/fltcstoper.c b/lang/cem/cemcom.ansi/fltcstoper.c index f029a425dc..ef6f8bccf5 100644 --- a/lang/cem/cemcom.ansi/fltcstoper.c +++ b/lang/cem/cemcom.ansi/fltcstoper.c @@ -6,28 +6,29 @@ /* C O N S T A N T E X P R E S S I O N H A N D L I N G */ /* F O R F L O A T I N G P O I N T N U M B E R S */ -#include -#include "parameters.h" -#include -#include -#include "fltcstoper.h" -#include "arith.h" -#include "type.h" -#include "label.h" -#include "expr.h" -#include "sizes.h" -#include "Lpars.h" -#include "LLlex.h" -#include "error.h" +#include +#include +#include +#include "parameters.h" +#include +#include +#include "fltcstoper.h" +#include "arith.h" +#include "type.h" +#include "label.h" +#include "expr.h" +#include "sizes.h" +#include "Lpars.h" +#include "LLlex.h" +#include "error.h" extern int ResultKnown; - -void fltcstbin(struct expr **expp, int oper, struct expr *expr) +void fltcstbin(struct expr** expp, int oper, struct expr* expr) { /* The operation oper is performed on the constant - expressions *expp(ld) and expr(ct), and the result restored in - *expp. + expressions *expp(ld) and expr(ct), and the result restored in + *expp. */ flt_arith o1, o2; int compar = 0; @@ -37,63 +38,80 @@ void fltcstbin(struct expr **expp, int oper, struct expr *expr) o2 = expr->FL_ARITH; assert(is_fp_cst(*expp) && is_fp_cst(expr)); - switch (oper) { - case '*': - flt_mul(&o1, &o2, &o1); - break; - case '/': - flt_div(&o1, &o2, &o1); - break; - case '+': - flt_add(&o1, &o2, &o1); - break; - case '-': - flt_sub(&o1, &o2, &o1); - break; - case '<': - case '>': - case LESSEQ: - case GREATEREQ: - case EQUAL: - case NOTEQUAL: - compar++; - cmpval = flt_cmp(&o1, &o2); - switch(oper) { - case '<': cmpval = (cmpval < 0); break; - case '>': cmpval = (cmpval > 0); break; - case LESSEQ: cmpval = (cmpval <= 0); break; - case GREATEREQ: cmpval = (cmpval >= 0); break; - case EQUAL: cmpval = (cmpval == 0); break; - case NOTEQUAL: cmpval = (cmpval != 0); break; - } - break; - default: - /* in case of situations like a += 3.0; where a undefined */ - flt_status = 0; - break; + switch (oper) + { + case '*': + flt_mul(&o1, &o2, &o1); + break; + case '/': + flt_div(&o1, &o2, &o1); + break; + case '+': + flt_add(&o1, &o2, &o1); + break; + case '-': + flt_sub(&o1, &o2, &o1); + break; + case '<': + case '>': + case LESSEQ: + case GREATEREQ: + case EQUAL: + case NOTEQUAL: + compar++; + cmpval = flt_cmp(&o1, &o2); + switch (oper) + { + case '<': + cmpval = (cmpval < 0); + break; + case '>': + cmpval = (cmpval > 0); + break; + case LESSEQ: + cmpval = (cmpval <= 0); + break; + case GREATEREQ: + cmpval = (cmpval >= 0); + break; + case EQUAL: + cmpval = (cmpval == 0); + break; + case NOTEQUAL: + cmpval = (cmpval != 0); + break; + } + break; + default: + /* in case of situations like a += 3.0; where a undefined */ + flt_status = 0; + break; } - switch (flt_status) { + switch (flt_status) + { case 0: - case FLT_UNFL: /* ignore underflow */ + case FLT_UNFL: /* ignore underflow */ break; case FLT_OVFL: if (!ResultKnown) - expr_warning(expr,"floating point overflow on %s" - , symbol2str(oper)); + expr_warning(expr, "floating point overflow on %s", symbol2str(oper)); break; case FLT_DIV0: if (!ResultKnown) - expr_error(expr,"division by 0.0"); + expr_error(expr, "division by 0.0"); else - expr_warning(expr,"division by 0.0"); + expr_warning(expr, "division by 0.0"); break; - default: /* there can't be another status */ + default: /* there can't be another status */ crash("(fltcstoper) bad status"); } - if (compar) { + if (compar) + { fill_int_expr(*expp, (arith)cmpval, INT); - } else { + } + else + { (*expp)->FL_ARITH = o1; } (*expp)->ex_flags |= expr->ex_flags; diff --git a/lang/cem/cemcom.ansi/fltcstoper.h b/lang/cem/cemcom.ansi/fltcstoper.h index 0506aac395..b48b5dfb1c 100644 --- a/lang/cem/cemcom.ansi/fltcstoper.h +++ b/lang/cem/cemcom.ansi/fltcstoper.h @@ -1,15 +1,15 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-02-07 - * + * */ #ifndef FLTCSTOPER_H_ #define FLTCSTOPER_H_ struct expr; -void fltcstbin(struct expr **expp, int oper, struct expr *expr); +void fltcstbin(struct expr** expp, int oper, struct expr* expr); #endif /* FLTCSTOPER_H_ */ diff --git a/lang/cem/cemcom.ansi/idf.c b/lang/cem/cemcom.ansi/idf.c index 96fdcace07..9b05b09ec4 100644 --- a/lang/cem/cemcom.ansi/idf.c +++ b/lang/cem/cemcom.ansi/idf.c @@ -5,65 +5,64 @@ /* $Id$ */ /* IDENTIFIER FIDDLING & SYMBOL TABLE HANDLING */ -#include -#include -#include -#include -#include "parameters.h" -#include -#include -#include "idf.h" -#include "arith.h" -#include "align.h" -#include "LLlex.h" -#include "level.h" -#include "stack.h" -#include "label.h" -#include "def.h" -#include "type.h" -#include "proto.h" -#include "struct.h" -#include "declar.h" -#include "declarator.h" -#include "decspecs.h" -#include "sizes.h" -#include "util.h" -#include "stab.h" -#include "code.h" -#include "error.h" -#include "ch3.h" -#include "Lpars.h" +#include +#include +#include +#include +#include +#include +#include "parameters.h" +#include +#include +#include "idf.h" +#include "arith.h" +#include "align.h" +#include "LLlex.h" +#include "level.h" +#include "stack.h" +#include "label.h" +#include "def.h" +#include "type.h" +#include "proto.h" +#include "struct.h" +#include "declar.h" +#include "declarator.h" +#include "decspecs.h" +#include "sizes.h" +#include "util.h" +#include "stab.h" +#include "code.h" +#include "error.h" +#include "ch3.h" +#include "Lpars.h" extern char options[]; - #ifdef DEBUG #define IDF_DEBUG #endif #include - - -struct idf *gen_idf(void) +struct idf* gen_idf(void) { /* A new idf is created out of nowhere, to serve as an anonymous name. */ static int name_cnt; - char *s = malloc(strlen(dot.tk_file) + 50); + char* s = malloc(strlen(dot.tk_file) + 50); sprintf(s, "#%d in %s, line %u", ++name_cnt, dot.tk_file, dot.tk_line); s = realloc(s, strlen(s) + 1); return str2idf(s, 0); } -int is_anon_idf(struct idf *idf) +int is_anon_idf(struct idf* idf) { return idf->id_text[0] == '#'; } -void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl) +void declare_idf(struct decspecs* ds, struct declarator* dc, int lvl) { /* The identifier inside dc is declared on the level lvl, with properties deduced from the decspecs ds and the declarator @@ -73,15 +72,15 @@ void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl) This routine implements the rich semantics of C declarations. */ - struct idf *idf = dc->dc_idf; + struct idf* idf = dc->dc_idf; int sc = ds->ds_sc; /* This local copy is essential: char b(), c; makes b GLOBAL and c AUTO. */ - struct def *def = idf->id_def; /* may be NULL */ - struct type *type; - struct stack_level *stl = stack_level_of(lvl); + struct def* def = idf->id_def; /* may be NULL */ + struct type* type; + struct stack_level* stl = stack_level_of(lvl); char formal_array = 0; /* determine the present type */ @@ -96,9 +95,9 @@ void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl) { /* combine the decspecs and the declarator into one type */ type = declare_type(ds->ds_type, dc); - if (type->tp_size <= (arith) 0 && actual_declaration(sc, type)) + if (type->tp_size <= (arith)0 && actual_declaration(sc, type)) { - if (type->tp_size == (arith) -1) + if (type->tp_size == (arith)-1) { /* the type is not yet known, but it has to be: @@ -121,24 +120,22 @@ void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl) { switch (type->tp_fund) { - case FUNCTION: - warning("%s is a function; cannot be formal", idf->id_text); - type = construct_type(POINTER, type, 0, (arith) 0, - NO_PROTO); - break; - case ARRAY: /* 3.7.1 */ - type = construct_type(POINTER, type->tp_up, 0, (arith) 0, - NO_PROTO); - formal_array = 1; - break; - case FLOAT: - case CHAR: - case SHORT: - /* The conversion is done in formal_cvt(). It is - * not done when the type is float and there is a - * prototype. - */ - break; + case FUNCTION: + warning("%s is a function; cannot be formal", idf->id_text); + type = construct_type(POINTER, type, 0, (arith)0, NO_PROTO); + break; + case ARRAY: /* 3.7.1 */ + type = construct_type(POINTER, type->tp_up, 0, (arith)0, NO_PROTO); + formal_array = 1; + break; + case FLOAT: + case CHAR: + case SHORT: + /* The conversion is done in formal_cvt(). It is + * not done when the type is float and there is a + * prototype. + */ + break; } } /* The tests on types, postponed from do_decspecs(), can now @@ -153,8 +150,7 @@ void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl) sc = GLOBAL; else if (sc != EXTERN && sc != TYPEDEF) { - error("illegal storage class %s for function with block-scope", - symbol2str(sc)); + error("illegal storage class %s for function with block-scope", symbol2str(sc)); ds->ds_sc = sc = EXTERN; } } @@ -162,22 +158,21 @@ void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl) sc = GLOBAL; } else /* non-FUNCTION */ - if (sc == 0) - sc = lvl == L_GLOBAL ? GLOBAL : - lvl == L_FORMAL1 || lvl == L_FORMAL2 ? FORMAL : AUTO; + if (sc == 0) + sc = lvl == L_GLOBAL ? GLOBAL : lvl == L_FORMAL1 || lvl == L_FORMAL2 ? FORMAL : AUTO; -#ifdef LINT +#ifdef LINT check_hiding(idf, lvl, sc); /* of some idf by this idf */ -#endif /* LINT */ +#endif /* LINT */ if (def && lvl == L_LOCAL && def->df_level == L_FORMAL2) { error("%s redeclared", idf->id_text); } if (def - && (def->df_level == lvl || (lvl != L_GLOBAL && def->df_level > lvl) - || (lvl == L_GLOBAL && def->df_level == L_PROTO && def->next - && def->next->df_level == L_GLOBAL))) + && (def->df_level == lvl || (lvl != L_GLOBAL && def->df_level > lvl) + || (lvl == L_GLOBAL && def->df_level == L_PROTO && def->next + && def->next->df_level == L_GLOBAL))) { /* There is already a declaration for idf on this level, or even more inside. @@ -185,83 +180,83 @@ void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl) */ switch (lvl) { - case L_GLOBAL: - global_redecl(idf, sc, type); - def->df_file = idf->id_file; - def->df_line = idf->id_line; - break; - case L_FORMAL1: /* formal declaration */ - error("formal %s redeclared", idf->id_text); - break; - case L_FORMAL2: /* formal definition */ - default: /* local */ - if (sc != EXTERN) - error("%s redeclared", idf->id_text); - break; + case L_GLOBAL: + global_redecl(idf, sc, type); + def->df_file = idf->id_file; + def->df_line = idf->id_line; + break; + case L_FORMAL1: /* formal declaration */ + error("formal %s redeclared", idf->id_text); + break; + case L_FORMAL2: /* formal definition */ + default: /* local */ + if (sc != EXTERN) + error("%s redeclared", idf->id_text); + break; } } else /* the idf is unknown on this level */ - if (lvl == L_FORMAL2 && sc != ENUM && good_formal(def, idf)) - { - /* formal declaration, update only */ - def->df_type = type; - def->df_formal_array = formal_array; - def->df_sc = sc; - def->df_level = L_FORMAL2; /* CJ */ - def->df_file = idf->id_file; - def->df_line = idf->id_line; - } - else - { /* fill in the def block */ - struct def *newdef = new_def(); - - newdef->next = def; - newdef->df_level = lvl; - newdef->df_type = type; - newdef->df_sc = sc; - newdef->df_file = idf->id_file; - newdef->df_line = idf->id_line; -#ifdef LINT - newdef->df_set = 0; - newdef->df_firstbrace = 0; -#endif /* LINT */ - /* link it into the name list in the proper place */ - idf->id_def = newdef; - update_ahead(idf); - stack_idf(idf, stl); - /* We now calculate the address. - Globals have names and don't get addresses, they - get numbers instead (through data_label()). - Formals are handled by declare_formals(). - So here we hand out local addresses only. - */ - if (lvl >= L_LOCAL) + if (lvl == L_FORMAL2 && sc != ENUM && good_formal(def, idf)) { - assert(sc); - switch (sc) + /* formal declaration, update only */ + def->df_type = type; + def->df_formal_array = formal_array; + def->df_sc = sc; + def->df_level = L_FORMAL2; /* CJ */ + def->df_file = idf->id_file; + def->df_line = idf->id_line; + } + else + { /* fill in the def block */ + struct def* newdef = new_def(); + + newdef->next = def; + newdef->df_level = lvl; + newdef->df_type = type; + newdef->df_sc = sc; + newdef->df_file = idf->id_file; + newdef->df_line = idf->id_line; +#ifdef LINT + newdef->df_set = 0; + newdef->df_firstbrace = 0; +#endif /* LINT */ + /* link it into the name list in the proper place */ + idf->id_def = newdef; + update_ahead(idf); + stack_idf(idf, stl); + /* We now calculate the address. + Globals have names and don't get addresses, they + get numbers instead (through data_label()). + Formals are handled by declare_formals(). + So here we hand out local addresses only. + */ + if (lvl >= L_LOCAL) { - case REGISTER: - case AUTO: - if (type->tp_size == (arith) -1 && type->tp_fund != ARRAY) - { - error("size of local %s unknown", idf->id_text); - /** type = idf->id_def->df_type = int_type; **/ - } - if (type->tp_size != (arith) -1) + assert(sc); + switch (sc) { - newdef->df_address = NewLocal(type->tp_size, type->tp_align, - regtype(type), sc); + case REGISTER: + case AUTO: + if (type->tp_size == (arith)-1 && type->tp_fund != ARRAY) + { + error("size of local %s unknown", idf->id_text); + /** type = idf->id_def->df_type = int_type; **/ + } + if (type->tp_size != (arith)-1) + { + newdef->df_address + = NewLocal(type->tp_size, type->tp_align, regtype(type), sc); + } + break; + case STATIC: + newdef->df_address = (arith)data_label(); + break; } - break; - case STATIC: - newdef->df_address = (arith) data_label(); - break; } } - } } -int actual_declaration(int sc, struct type *tp) +int actual_declaration(int sc, struct type* tp) { /* An actual_declaration needs space, right here and now. */ @@ -281,7 +276,7 @@ int actual_declaration(int sc, struct type *tp) return 1; } -void global_redecl(struct idf *idf, int new_sc, struct type *tp) +void global_redecl(struct idf* idf, int new_sc, struct type* tp) { /* A global identifier may be declared several times, provided the declarations do not conflict; they might @@ -289,7 +284,7 @@ void global_redecl(struct idf *idf, int new_sc, struct type *tp) an array) or they might conflict or supplement each other in storage class. */ - struct def *def = idf->id_def; + struct def* def = idf->id_def; while (def->df_level != L_GLOBAL) def = def->next; @@ -331,62 +326,62 @@ void global_redecl(struct idf *idf, int new_sc, struct type *tp) switch (def->df_sc) { /* the old storage class */ - case EXTERN: - switch (new_sc) - { /* the new storage class */ - case STATIC: - warning("%s redeclared static", idf->id_text); - /* fallthrough */ - case GLOBAL: - def->df_sc = new_sc; - /* fallthrough */ case EXTERN: + switch (new_sc) + { /* the new storage class */ + case STATIC: + warning("%s redeclared static", idf->id_text); + /* fallthrough */ + case GLOBAL: + def->df_sc = new_sc; + /* fallthrough */ + case EXTERN: + break; + default: + crash("bad storage class"); + UNREACHABLE_CODE; + } break; - default: - crash("bad storage class"); - UNREACHABLE_CODE; - } - break; - case GLOBAL: - switch (new_sc) - { /* the new storage class */ - case STATIC: /* linkage disagreement */ - warning("%s redeclared static", idf->id_text); - def->df_sc = new_sc; - /* fallthrough */ case GLOBAL: - case EXTERN: + switch (new_sc) + { /* the new storage class */ + case STATIC: /* linkage disagreement */ + warning("%s redeclared static", idf->id_text); + def->df_sc = new_sc; + /* fallthrough */ + case GLOBAL: + case EXTERN: + break; + default: + crash("bad storage class"); + UNREACHABLE_CODE; + } break; - default: - crash("bad storage class"); - UNREACHABLE_CODE; - } - break; - case STATIC: - switch (new_sc) - { /* the new storage class */ - case GLOBAL: /* linkage disagreement */ - case EXTERN: - warning("%s is already declared static", idf->id_text); - /* fallthrough */ case STATIC: + switch (new_sc) + { /* the new storage class */ + case GLOBAL: /* linkage disagreement */ + case EXTERN: + warning("%s is already declared static", idf->id_text); + /* fallthrough */ + case STATIC: + break; + default: + crash("bad storage class"); + UNREACHABLE_CODE; + } + break; + case ENUM: + case TYPEDEF: + error("illegal redeclaration of %s", idf->id_text); break; default: crash("bad storage class"); UNREACHABLE_CODE; - } - break; - case ENUM: - case TYPEDEF: - error("illegal redeclaration of %s", idf->id_text); - break; - default: - crash("bad storage class"); - UNREACHABLE_CODE; } } -int good_formal(struct def *def, struct idf *idf) +int good_formal(struct def* def, struct idf* idf) { /* Succeeds if def is a proper L_FORMAL1 definition and gives an error message otherwise. @@ -401,11 +396,11 @@ int good_formal(struct def *def, struct idf *idf) return 1; } -void declare_params(struct declarator *dc) +void declare_params(struct declarator* dc) { /* Declares the formal parameters if they exist. */ - struct formal *fm = dc->dc_formal; + struct formal* fm = dc->dc_formal; while (fm) { @@ -414,11 +409,11 @@ void declare_params(struct declarator *dc) } } -void idf_initialized(struct idf *idf) +void idf_initialized(struct idf* idf) { /* The topmost definition of idf is set to initialized. */ - struct def *def = idf->id_def; /* the topmost */ + struct def* def = idf->id_def; /* the topmost */ while (def->df_level <= L_PROTO) def = def->next; @@ -432,14 +427,14 @@ void idf_initialized(struct idf *idf) def->df_initialized = 1; } -void declare_parameter(struct idf *idf) +void declare_parameter(struct idf* idf) { /* idf is declared as a formal. */ add_def(idf, FORMAL, int_type, level); } -void declare_enum(struct type *tp, struct idf *idf, arith l) +void declare_enum(struct type* tp, struct idf* idf, arith l) { /* idf is declared as an enum constant with value l. */ @@ -447,11 +442,11 @@ void declare_enum(struct type *tp, struct idf *idf, arith l) idf->id_def->df_address = l; } -void check_formals(struct idf *idf, struct declarator *dc) +void check_formals(struct idf* idf, struct declarator* dc) { - struct formal *fm = dc->dc_formal; - struct proto *pl = idf->id_def->df_type->tp_proto; - struct decl_unary *du = dc->dc_decl_unary; + struct formal* fm = dc->dc_formal; + struct proto* pl = idf->id_def->df_type->tp_proto; + struct decl_unary* du = dc->dc_decl_unary; if (!du) { /* error or typdef'ed function */ @@ -459,8 +454,7 @@ void check_formals(struct idf *idf, struct declarator *dc) return; } - while (du - && (du->du_fund != FUNCTION || du->next != (struct decl_unary *) 0)) + while (du && (du->du_fund != FUNCTION || du->next != (struct decl_unary*)0)) { du = du->next; } @@ -487,12 +481,10 @@ void check_formals(struct idf *idf, struct declarator *dc) } while (fm && pl) { - if (!equal_type(promoted_type(fm->fm_idf->id_def->df_type), - pl->pl_type, -1, 1)) + if (!equal_type(promoted_type(fm->fm_idf->id_def->df_type), pl->pl_type, -1, 1)) { if (!(pl->pl_flag & PL_ERRGIVEN)) - error("incorrect type for parameter %s", - fm->fm_idf->id_text); + error("incorrect type for parameter %s", fm->fm_idf->id_text); pl->pl_flag |= PL_ERRGIVEN; } fm = fm->next; @@ -505,11 +497,10 @@ void check_formals(struct idf *idf, struct declarator *dc) } else { /* make a pseudo-prototype */ - struct proto *lpl = new_proto(); + struct proto* lpl = new_proto(); if (!options['o']) - warning("'%s' old-fashioned function definition", - dc->dc_idf->id_text); + warning("'%s' old-fashioned function definition", dc->dc_idf->id_text); while (fm) { @@ -537,20 +528,20 @@ void check_formals(struct idf *idf, struct declarator *dc) dc->dc_formal = 0; } -void declare_formals(struct idf *idf, arith *fp) +void declare_formals(struct idf* idf, arith* fp) { /* Declares those formals as int that haven't been declared by the user. An address is assigned to each formal parameter. The total size of the formals is returned in *fp; */ - struct stack_entry *se = stack_level_of(L_FORMAL1)->sl_entry; - arith f_offset = (arith) 0; + struct stack_entry* se = stack_level_of(L_FORMAL1)->sl_entry; + arith f_offset = (arith)0; int nparams = 0; int hasproto; - struct def *df = idf->id_def; + struct def* df = idf->id_def; - /* When one of the formals has the same name as the function, + /* When one of the formals has the same name as the function, it hides the function def. Get it. */ while (se) @@ -567,10 +558,10 @@ void declare_formals(struct idf *idf, arith *fp) hasproto = df->df_type->tp_proto != 0; -#ifdef DEBUG +#ifdef DEBUG if (options['t']) - dumpidftab("start declare_formals", 0); -#endif /* DEBUG */ + dumpidftab("start declare_formals", 0); +#endif /* DEBUG */ if (is_struct_or_union(df->df_type->tp_up->tp_fund)) { /* create space for address of return value */ @@ -592,15 +583,13 @@ void declare_formals(struct idf *idf, arith *fp) word boundaries, i.e. take care that the following parameter starts on a new word boundary. */ - if (!hasproto && df->df_type->tp_fund == FLOAT - && df->df_type->tp_size != double_size) + if (!hasproto && df->df_type->tp_fund == FLOAT && df->df_type->tp_size != double_size) { - f_offset = align(f_offset + double_size, (int) word_size); + f_offset = align(f_offset + double_size, (int)word_size); } else - f_offset = align(f_offset + df->df_type->tp_size, (int) word_size); - RegisterAccount(df->df_address, df->df_type->tp_size, - regtype(df->df_type), df->df_sc); + f_offset = align(f_offset + df->df_type->tp_size, (int)word_size); + RegisterAccount(df->df_address, df->df_type->tp_size, regtype(df->df_type), df->df_sc); /* cvt int to char or short and double to float, if necessary */ formal_cvt(hasproto, df); @@ -619,24 +608,24 @@ void declare_formals(struct idf *idf, arith *fp) *fp = f_offset; } -int regtype(struct type *tp) +int regtype(struct type* tp) { switch (tp->tp_fund) { - case INT: - case LONG: - return reg_any; - case FLOAT: - case DOUBLE: - case LNGDBL: - return reg_float; - case POINTER: - return reg_pointer; + case INT: + case LONG: + return reg_any; + case FLOAT: + case DOUBLE: + case LNGDBL: + return reg_float; + case POINTER: + return reg_pointer; } return -1; } -void add_def(struct idf *idf, int sc, struct type *tp, int lvl) +void add_def(struct idf* idf, int sc, struct type* tp, int lvl) { /* The identifier idf is declared on level lvl with storage class sc and type tp, through a faked C declaration. @@ -654,25 +643,22 @@ void add_def(struct idf *idf, int sc, struct type *tp, int lvl) declare_idf(&Ds, &Dc, lvl); } -void update_ahead(struct idf *idf) +void update_ahead(struct idf* idf) { /* The tk_symb of the token ahead is updated in the light of new information about the identifier idf. */ int tk_symb = AHEAD; - if ((tk_symb == IDENTIFIER || tk_symb == TYPE_IDENTIFIER) - && ahead.tk_idf == idf) - AHEAD = idf->id_def && idf->id_def->df_sc == TYPEDEF ? - TYPE_IDENTIFIER : - IDENTIFIER; + if ((tk_symb == IDENTIFIER || tk_symb == TYPE_IDENTIFIER) && ahead.tk_idf == idf) + AHEAD = idf->id_def && idf->id_def->df_sc == TYPEDEF ? TYPE_IDENTIFIER : IDENTIFIER; } -void free_formals(struct formal *fm) +void free_formals(struct formal* fm) { while (fm) { - struct formal *tmp = fm->next; + struct formal* tmp = fm->next; free_formal(fm); fm = tmp; diff --git a/lang/cem/cemcom.ansi/idf.str b/lang/cem/cemcom.ansi/idf.str index d26ebfe56f..f23c732dae 100644 --- a/lang/cem/cemcom.ansi/idf.str +++ b/lang/cem/cemcom.ansi/idf.str @@ -5,35 +5,35 @@ #ifndef IDF_H_ #define IDF_H_ - /* $Id$ */ /* IDENTIFIER DESCRIPTOR */ -#include "parameters.h" -#include "arith.h" +#include "parameters.h" +#include "arith.h" -struct id_u { - int idd_reserved; /* non-zero for reserved words */ - char *idd_file; /* file containing the occurrence */ - unsigned int idd_line; /* line number of the occurrence */ - struct def *idd_label; /* labels */ - struct def *idd_def; /* variables, typedefs, enum-constants */ - struct sdef *idd_sdef; /* selector tags */ - struct tag *idd_tag; /* struct, union, and enum tags */ - int idd_special; /* special action needed at occurrence */ +struct id_u +{ + int idd_reserved; /* non-zero for reserved words */ + char* idd_file; /* file containing the occurrence */ + unsigned int idd_line; /* line number of the occurrence */ + struct def* idd_label; /* labels */ + struct def* idd_def; /* variables, typedefs, enum-constants */ + struct sdef* idd_sdef; /* selector tags */ + struct tag* idd_tag; /* struct, union, and enum tags */ + int idd_special; /* special action needed at occurrence */ }; -#define IDF_TYPE struct id_u -#define id_macro id_user.idd_macro -#define id_resmac id_user.idd_resmac -#define id_reserved id_user.idd_reserved -#define id_file id_user.idd_file -#define id_line id_user.idd_line -#define id_label id_user.idd_label -#define id_def id_user.idd_def -#define id_sdef id_user.idd_sdef -#define id_tag id_user.idd_tag -#define id_special id_user.idd_special +#define IDF_TYPE struct id_u +#define id_macro id_user.idd_macro +#define id_resmac id_user.idd_resmac +#define id_reserved id_user.idd_reserved +#define id_file id_user.idd_file +#define id_line id_user.idd_line +#define id_label id_user.idd_label +#define id_def id_user.idd_def +#define id_sdef id_user.idd_sdef +#define id_tag id_user.idd_tag +#define id_special id_user.idd_special #include @@ -44,22 +44,21 @@ struct declarator; struct type; struct formal; - -struct idf *gen_idf(void); -int is_anon_idf(struct idf *idf); -void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl); -int actual_declaration(int sc, struct type *tp); -void global_redecl(register struct idf *idf, int new_sc, struct type *tp); -int good_formal(register struct def *def, register struct idf *idf); -void declare_params(struct declarator *dc); -void idf_initialized(register struct idf *idf); -void declare_parameter(struct idf *idf); -void declare_enum(struct type *tp, struct idf *idf, arith l); -void check_formals(struct idf *idf, struct declarator *dc); -void declare_formals(struct idf *idf, arith *fp); -int regtype(struct type *tp); -void add_def(struct idf *idf, int sc, struct type *tp, int lvl); -void update_ahead(register struct idf *idf); -void free_formals(register struct formal *fm); +struct idf* gen_idf(void); +int is_anon_idf(struct idf* idf); +void declare_idf(struct decspecs* ds, struct declarator* dc, int lvl); +int actual_declaration(int sc, struct type* tp); +void global_redecl(register struct idf* idf, int new_sc, struct type* tp); +int good_formal(register struct def* def, register struct idf* idf); +void declare_params(struct declarator* dc); +void idf_initialized(register struct idf* idf); +void declare_parameter(struct idf* idf); +void declare_enum(struct type* tp, struct idf* idf, arith l); +void check_formals(struct idf* idf, struct declarator* dc); +void declare_formals(struct idf* idf, arith* fp); +int regtype(struct type* tp); +void add_def(struct idf* idf, int sc, struct type* tp, int lvl); +void update_ahead(register struct idf* idf); +void free_formals(register struct formal* fm); #endif \ No newline at end of file diff --git a/lang/cem/cemcom.ansi/input.c b/lang/cem/cemcom.ansi/input.c index e5d019bb4c..6f3c4ac176 100644 --- a/lang/cem/cemcom.ansi/input.c +++ b/lang/cem/cemcom.ansi/input.c @@ -4,6 +4,8 @@ */ /* $Id$ */ +#include +#include #include "parameters.h" #include #include @@ -12,24 +14,25 @@ #include "input.h" #include "error.h" -#define INP_PUSHBACK 3 -#define INP_TYPE struct file_info -#define INP_VAR finfo -struct file_info finfo; +#define INP_PUSHBACK 3 +#define INP_TYPE struct file_info +#define INP_VAR finfo +struct file_info finfo; #include #include -int NoUnstack; +int NoUnstack; int AtEoIT(void) { return 0; } -extern char *source; +extern char* source; int AtEoIF(void) { - if (NoUnstack) lexerror("unexpected EOF"); + if (NoUnstack) + lexerror("unexpected EOF"); return 0; } diff --git a/lang/cem/cemcom.ansi/input.h b/lang/cem/cemcom.ansi/input.h index 4ffbe0f5c6..4e18ba5c59 100644 --- a/lang/cem/cemcom.ansi/input.h +++ b/lang/cem/cemcom.ansi/input.h @@ -8,8 +8,7 @@ #include /* Note: The following macro only garuantees one PushBack. -*/ -#define UnGetChar() ((LexSave != EOI) ? ChPushBack(LexSave) : 0) - -extern int LexSave; /* last character read by GetChar */ + */ +#define UnGetChar() ((LexSave != EOI) ? ChPushBack(LexSave) : 0) +extern int LexSave; /* last character read by GetChar */ diff --git a/lang/cem/cemcom.ansi/interface.h b/lang/cem/cemcom.ansi/interface.h index 155cbe1acc..cfa7353f08 100644 --- a/lang/cem/cemcom.ansi/interface.h +++ b/lang/cem/cemcom.ansi/interface.h @@ -3,14 +3,13 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -#define static static /* or not */ -#define IMPORT extern +#define static static /* or not */ +#define IMPORT extern #define EXPORT /* Here to avoid creating another header "notreached.h" */ #ifndef NDEBUG -#define NOTREACHED() crash("in %s, %u: unreachable statement reached", \ - __FILE__, __LINE__) +#define NOTREACHED() crash("in %s, %u: unreachable statement reached", __FILE__, __LINE__) #else #define NOTREACHED() -#endif /* NDEBUG */ +#endif /* NDEBUG */ diff --git a/lang/cem/cemcom.ansi/l_brace.str b/lang/cem/cemcom.ansi/l_brace.str index f074714966..261140a1a2 100644 --- a/lang/cem/cemcom.ansi/l_brace.str +++ b/lang/cem/cemcom.ansi/l_brace.str @@ -5,24 +5,24 @@ /* $Id$ */ /* To determine the minimum scope of a local variable, all (braced) - scopes are numbered consecutively. Next we maintain an array which - maps the nesting depth (level) onto the scope number; we record - the scope number of the first application of a local variable - in its definition. Each further application requires that the - level of the variable be at least large enough to comprise both - the present scope and that of its first application. That level - number is determined by searching the array and is then recorded in - the definition (beacuse it is always equal to or smaller than the - level already there). + scopes are numbered consecutively. Next we maintain an array which + maps the nesting depth (level) onto the scope number; we record + the scope number of the first application of a local variable + in its definition. Each further application requires that the + level of the variable be at least large enough to comprise both + the present scope and that of its first application. That level + number is determined by searching the array and is then recorded in + the definition (beacuse it is always equal to or smaller than the + level already there). - The array is implemented as a linked list of struct brace. + The array is implemented as a linked list of struct brace. */ -struct brace { - struct brace *next; +struct brace +{ + struct brace* next; int br_count; int br_level; }; /* ALLOCDEF "brace" 10 */ - diff --git a/lang/cem/cemcom.ansi/l_class.h b/lang/cem/cemcom.ansi/l_class.h index d1539d9463..83eff90e21 100644 --- a/lang/cem/cemcom.ansi/l_class.h +++ b/lang/cem/cemcom.ansi/l_class.h @@ -6,23 +6,22 @@ /* Lint class constants */ -#define LFDF 'a' /* Library Function Definition */ -#define LVDF 'b' /* Library Variable Definition */ +#define LFDF 'a' /* Library Function Definition */ +#define LVDF 'b' /* Library Variable Definition */ -#define PFDF 'd' /* Prototype Function Definition */ +#define PFDF 'd' /* Prototype Function Definition */ -#define EFDF 'f' /* External Function Definition */ -#define EVDF 'g' /* External Variable Definition */ -#define EFDC 'h' /* External Function Declaration */ -#define EVDC 'i' /* External Variable Declaration */ +#define EFDF 'f' /* External Function Definition */ +#define EVDF 'g' /* External Variable Definition */ +#define EFDC 'h' /* External Function Declaration */ +#define EVDC 'i' /* External Variable Declaration */ -#define IFDC 'm' /* Implicit Function Declaration */ +#define IFDC 'm' /* Implicit Function Declaration */ -#define SFDF 'q' /* Static Function Definition */ -#define SVDF 'r' /* Static Variable Definition */ +#define SFDF 'q' /* Static Function Definition */ +#define SVDF 'r' /* Static Variable Definition */ -#define FC 'u' /* Function Call */ -#define VU 'v' /* Variable Usage */ - -#define XXDF 'z' /* Ignore Class */ +#define FC 'u' /* Function Call */ +#define VU 'v' /* Variable Usage */ +#define XXDF 'z' /* Ignore Class */ diff --git a/lang/cem/cemcom.ansi/l_comment.c b/lang/cem/cemcom.ansi/l_comment.c index c944d8680e..944839b7c3 100644 --- a/lang/cem/cemcom.ansi/l_comment.c +++ b/lang/cem/cemcom.ansi/l_comment.c @@ -5,23 +5,25 @@ /* $Id$ */ /* Lint-specific comment handling */ -#include "parameters.h" -#include +#include "parameters.h" +#include +#include +#include -#ifdef LINT +#ifdef LINT -#include -#include "interface.h" -#include "arith.h" -#include "l_state.h" -#include "l_comment.h" +#include +#include "interface.h" +#include "arith.h" +#include "l_state.h" +#include "l_comment.h" extern char loptions[]; /* Since the lexical analyser does a one-token look-ahead, pseudo- - comments are read too soon. This is remedied by first storing them - in static variables and then moving them to the real variables - one token later. + comments are read too soon. This is remedied by first storing them + in static variables and then moving them to the real variables + one token later. */ static int notreached; @@ -29,19 +31,19 @@ static int varargsN = -1; static int argsused; static int formatN; static int formatVAR; -static char *format; -static char *prev_format; +static char* format; +static char* prev_format; static make_format(); -int LINTLIB; /* file is lint library */ -int s_NOTREACHED; /* statement not reached */ -int f_VARARGSn; /* function with variable # of args */ -int f_ARGSUSED; /* function does not use all args */ -int f_FORMATn; /* argument f_FORMATn is f_FORMAT */ -char *f_FORMAT; -int f_FORMATvar; /* but the formal argument may be - absent because of varargs.h */ +int LINTLIB; /* file is lint library */ +int s_NOTREACHED; /* statement not reached */ +int f_VARARGSn; /* function with variable # of args */ +int f_ARGSUSED; /* function does not use all args */ +int f_FORMATn; /* argument f_FORMATn is f_FORMAT */ +char* f_FORMAT; +int f_FORMATvar; /* but the formal argument may be + absent because of varargs.h */ lint_init_comment() { @@ -74,18 +76,17 @@ lint_comment_function() } static char buf[1000]; -static char *bufpos; /* next free position in buf */ +static char* bufpos; /* next free position in buf */ lint_start_comment() { bufpos = &buf[0]; } -lint_comment_char(c) - int c; +lint_comment_char(c) int c; { -/* This function is called with every character between /_* and *_/ */ - if (bufpos - &buf[0] < sizeof(buf)-1) + /* This function is called with every character between /_* and *_/ */ + if (bufpos - &buf[0] < sizeof(buf) - 1) *bufpos++ = (char)c; } @@ -95,73 +96,77 @@ lint_end_comment() bufpos = &buf[0]; /* skip initial blanks */ - while (*bufpos && isspace(*bufpos)) { + while (*bufpos && isspace(*bufpos)) + { bufpos++; } /* now test for one of the pseudo-comments */ - if (strncmp(bufpos, "NOTREACHED", 10) == 0) { + if (strncmp(bufpos, "NOTREACHED", 10) == 0) + { notreached = 1; } - else - if (strncmp(bufpos, "ARGSUSED", 8) == 0) { + else if (strncmp(bufpos, "ARGSUSED", 8) == 0) + { argsused = 1; } - else - if (strncmp(bufpos, "LINTLIBRARY", 11) == 0) { + else if (strncmp(bufpos, "LINTLIBRARY", 11) == 0) + { LINTLIB = 1; } - else - if (strncmp(bufpos, "VARARGS", 7) == 0) { + else if (strncmp(bufpos, "VARARGS", 7) == 0) + { bufpos += 7; varargsN = isdigit(*bufpos) ? atoi(bufpos) : 0; } - else - if (strncmp(bufpos, "FORMAT", 6) == 0 && isdigit(bufpos[6])) { + else if (strncmp(bufpos, "FORMAT", 6) == 0 && isdigit(bufpos[6])) + { int argn; bufpos += 6; argn = *bufpos++ - '0'; varargsN = argn + 1; - if (*bufpos == 'v') { + if (*bufpos == 'v') + { /* something like FORMAT3v */ formatVAR = 1; bufpos++; } make_format(argn, bufpos); - } } /* We use a small FSA to skip layout inside formats, but to preserve - a space between letters and digits. + a space between letters and digits. */ -#define NONE 0 -#define LETGIT 1 -#define LETGITSPACE 2 +#define NONE 0 +#define LETGIT 1 +#define LETGITSPACE 2 -static -make_format(argn, oldf) - int argn; - char *oldf; +static make_format(argn, oldf) int argn; +char* oldf; { - char *newf; + char* newf; int last_stat; - while (*oldf && *oldf != '$') { + while (*oldf && *oldf != '$') + { oldf++; } - if (!*oldf) { + if (!*oldf) + { /* no format given, repeat previous format */ - if (!prev_format) { + if (!prev_format) + { warning("format missing and no previous format"); } formatN = argn; format = prev_format; return; } - if (*oldf++ != '$') { + if (*oldf++ != '$') + { warning("no format in FORMAT pseudo-comment"); format = 0; return; @@ -169,37 +174,42 @@ make_format(argn, oldf) /* there is a new format to be composed */ newf = malloc(strlen(oldf)); - /* certainly enough and probably not overly too much */ + /* certainly enough and probably not overly too much */ formatN = argn; format = newf; last_stat = NONE; - while (*oldf && *oldf != '$') { + while (*oldf && *oldf != '$') + { char ch = *oldf++; - if (isspace(ch)) { + if (isspace(ch)) + { if (last_stat == LETGIT) last_stat = LETGITSPACE; } - else - if (isalnum(ch)) { - switch (last_stat) { - case NONE: - last_stat = LETGIT; - break; - case LETGITSPACE: - *newf++ = ' '; - last_stat = LETGIT; - break; + else if (isalnum(ch)) + { + switch (last_stat) + { + case NONE: + last_stat = LETGIT; + break; + case LETGITSPACE: + *newf++ = ' '; + last_stat = LETGIT; + break; } *newf++ = ch; } - else { + else + { last_stat = NONE; *newf++ = ch; } } - if (*oldf != '$') { + if (*oldf != '$') + { warning("no end of format in FORMAT pseudo-comment"); format = 0; return; @@ -207,4 +217,4 @@ make_format(argn, oldf) *newf++ = '\0'; } -#endif /* LINT */ +#endif /* LINT */ diff --git a/lang/cem/cemcom.ansi/l_comment.h b/lang/cem/cemcom.ansi/l_comment.h index 047f2a9f25..1d85355aba 100644 --- a/lang/cem/cemcom.ansi/l_comment.h +++ b/lang/cem/cemcom.ansi/l_comment.h @@ -4,12 +4,11 @@ */ /* $Id$ */ -extern int LINTLIB; /* file is lint library */ -extern int s_NOTREACHED; /* statement not reached */ -extern int f_VARARGSn; /* function with variable # of args */ -extern int f_ARGSUSED; /* function does not use all args */ -extern int f_FORMATn; /* argument f_FORMATn is f_FORMAT */ -extern char *f_FORMAT; -extern int f_FORMATvar; /* but the formal argument may be - absent because of varargs.h */ - +extern int LINTLIB; /* file is lint library */ +extern int s_NOTREACHED; /* statement not reached */ +extern int f_VARARGSn; /* function with variable # of args */ +extern int f_ARGSUSED; /* function does not use all args */ +extern int f_FORMATn; /* argument f_FORMATn is f_FORMAT */ +extern char* f_FORMAT; +extern int f_FORMATvar; /* but the formal argument may be + absent because of varargs.h */ diff --git a/lang/cem/cemcom.ansi/l_em.h b/lang/cem/cemcom.ansi/l_em.h index 5c0b90a41d..5bf9650adb 100644 --- a/lang/cem/cemcom.ansi/l_em.h +++ b/lang/cem/cemcom.ansi/l_em.h @@ -14,64 +14,63 @@ * to terminate the compilation process. */ -#define store_block(sz, al) -#define load_block(sz, al) +#define store_block(sz, al) +#define load_block(sz, al) -#define C_asp(c) -#define C_bra(b) -#define C_cal(p) -#define C_csa(w) -#define C_csb(w) -#define C_fil_dlb(g,o) -#define C_lae_dlb(g,o) -#define C_lal(c) -#define C_lin(c) -#define C_loi(c) -#define C_lol(c) -#define C_ret(c) -#define C_sdl(c) -#define C_sti(c) -#define C_stl(c) +#define C_asp(c) +#define C_bra(b) +#define C_cal(p) +#define C_csa(w) +#define C_csb(w) +#define C_fil_dlb(g, o) +#define C_lae_dlb(g, o) +#define C_lal(c) +#define C_lin(c) +#define C_loi(c) +#define C_lol(c) +#define C_ret(c) +#define C_sdl(c) +#define C_sti(c) +#define C_stl(c) -#define C_busy() 0 -#define C_close() +#define C_busy() 0 +#define C_close() -#define C_df_dlb(l) -#define C_df_dnam(s) -#define C_df_ilb(l) +#define C_df_dlb(l) +#define C_df_dnam(s) +#define C_df_ilb(l) -#define C_pro_narg(s) -#define C_end(l) +#define C_pro_narg(s) +#define C_end(l) -#define C_exa_dnam(s) -#define C_ina_dnam(s) -#define C_ina_dlb(l) -#define C_exp(s) -#define C_inp(s) +#define C_exa_dnam(s) +#define C_ina_dnam(s) +#define C_ina_dlb(l) +#define C_exp(s) +#define C_inp(s) -#define C_bss_cst(n,w,i) +#define C_bss_cst(n, w, i) -#define C_con_cst(v) -#define C_con_icon(v,s) -#define C_con_ucon(v,s) -#define C_con_fcon(v,s) -#define C_con_scon(v,s) -#define C_con_dnam(v,s) -#define C_con_dlb(v,s) -#define C_con_pnam(v) +#define C_con_cst(v) +#define C_con_icon(v, s) +#define C_con_ucon(v, s) +#define C_con_fcon(v, s) +#define C_con_scon(v, s) +#define C_con_dnam(v, s) +#define C_con_dlb(v, s) +#define C_con_pnam(v) -#define C_rom_cst(v) -#define C_rom_icon(v,s) -#define C_rom_scon(v,s) -#define C_rom_ilb(v) +#define C_rom_cst(v) +#define C_rom_icon(v, s) +#define C_rom_scon(v, s) +#define C_rom_ilb(v) -#define C_ldl(l) +#define C_ldl(l) -#define C_mes_begin(ms) -#define C_mes_end() - -#define C_ms_gto() -#define C_ms_par(b) -#define C_ms_reg(o,s,t,c) -#define C_ms_err() +#define C_mes_begin(ms) +#define C_mes_end() +#define C_ms_gto() +#define C_ms_par(b) +#define C_ms_reg(o, s, t, c) +#define C_ms_err() diff --git a/lang/cem/cemcom.ansi/l_ev_ord.c b/lang/cem/cemcom.ansi/l_ev_ord.c index e461e53063..a10305a730 100644 --- a/lang/cem/cemcom.ansi/l_ev_ord.c +++ b/lang/cem/cemcom.ansi/l_ev_ord.c @@ -5,55 +5,54 @@ /* $Id$ */ /* Lint evaluation order checking */ -#include "parameters.h" +#include "parameters.h" +#include +#include -#ifdef LINT +#ifdef LINT -#include /* for st_free */ -#include "interface.h" +#include /* for st_free */ +#include "interface.h" #ifdef ANSI -#include +#include #endif /* ANSI */ -#include "arith.h" /* definition arith */ -#include "label.h" /* definition label */ -#include "expr.h" -#include "def.h" -#include "code.h" /* RVAL etc */ -#include "LLlex.h" -#include "Lpars.h" -#include "stack.h" -#include "type.h" -#include "level.h" -#include "l_lint.h" -#include "l_state.h" - - +#include "arith.h" /* definition arith */ +#include "label.h" /* definition label */ +#include "expr.h" +#include "def.h" +#include "code.h" /* RVAL etc */ +#include "LLlex.h" +#include "Lpars.h" +#include "stack.h" +#include "type.h" +#include "level.h" +#include "l_lint.h" +#include "l_state.h" static check_ev_order(); -check_and_merge(expr, espp, esp) - struct expr *expr; - struct expr_state **espp, *esp; +check_and_merge(expr, espp, esp) struct expr* expr; +struct expr_state **espp, *esp; { -/* Checks for undefined evaluation orders in case of a non-sequencing operator. - * In addition the sets of used and set variables of both expressions are - * united. - * *espp will be pointing to this new list. esp is used for this list. - */ + /* Checks for undefined evaluation orders in case of a non-sequencing operator. + * In addition the sets of used and set variables of both expressions are + * united. + * *espp will be pointing to this new list. esp is used for this list. + */ struct expr_state **pp, *p1, *p2; int oper = expr->OP_OPER; - int is_sequencer = - (oper == '?' || oper == OR || oper == AND || oper ==','); + int is_sequencer = (oper == '?' || oper == OR || oper == AND || oper == ','); - for (p1 = *espp; p1; p1 = p1->next) { + for (p1 = *espp; p1; p1 = p1->next) + { /* scan the list esp for the same variable */ p2 = esp; pp = &esp; - while (p2) { - if ( /* p1 and p2 refer to the same location */ - p1->es_idf == p2->es_idf - && p1->es_offset == p2->es_offset - ) { + while (p2) + { + if (/* p1 and p2 refer to the same location */ + p1->es_idf == p2->es_idf && p1->es_offset == p2->es_offset) + { /* check */ if (!is_sequencer) check_ev_order(p1, p2, expr); @@ -68,7 +67,8 @@ check_and_merge(expr, espp, esp) free_expr_state(p2); p2 = *pp; } - else { + else + { /* skip over the entry in esp */ pp = &p2->next; p2 = p2->next; @@ -76,8 +76,8 @@ check_and_merge(expr, espp, esp) } } /* If there is anything left in the list esp, this is put in - front of the list *espp is now pointing to, and *espp will be - left pointing to this new list. + front of the list *espp is now pointing to, and *espp will be + left pointing to this new list. */ if (!esp) return; @@ -88,20 +88,16 @@ check_and_merge(expr, espp, esp) esp->next = p1; } -static -check_ev_order(esp1, esp2, expr) - struct expr_state *esp1, *esp2; - struct expr *expr; +static check_ev_order(esp1, esp2, expr) struct expr_state* esp1, *esp2; +struct expr* expr; { - if ( (esp1->es_used && esp2->es_set) - || (esp1->es_set && esp2->es_used) - || (esp1->es_set && esp2->es_set) - ) { - expr_warning(expr, - "result of %s depends on evaluation order on %s", - symbol2str(expr->OP_OPER), - esp1->es_idf->id_text); + if ((esp1->es_used && esp2->es_set) || (esp1->es_set && esp2->es_used) + || (esp1->es_set && esp2->es_set)) + { + expr_warning( + expr, "result of %s depends on evaluation order on %s", symbol2str(expr->OP_OPER), + esp1->es_idf->id_text); } } -#endif /* LINT */ +#endif /* LINT */ diff --git a/lang/cem/cemcom.ansi/l_lint.c b/lang/cem/cemcom.ansi/l_lint.c index 7de31e0805..c4c1c76b69 100644 --- a/lang/cem/cemcom.ansi/l_lint.c +++ b/lang/cem/cemcom.ansi/l_lint.c @@ -5,36 +5,35 @@ /* $Id$ */ /* Lint main routines */ -#include "parameters.h" +#include "parameters.h" -#ifdef LINT +#ifdef LINT -#include -#include /* for st_free */ -#include "interface.h" +#include +#include /* for st_free */ +#include "interface.h" #ifdef ANSI -#include +#include #endif /* ANSI */ -#include "arith.h" /* definition arith */ -#include "label.h" /* definition label */ -#include "expr.h" -#include "def.h" -#include "code.h" /* RVAL etc */ -#include "LLlex.h" -#include "Lpars.h" -#include "stack.h" -#include "type.h" -#include "level.h" -#include "l_lint.h" -#include "l_state.h" -#include "l_outdef.h" +#include "arith.h" /* definition arith */ +#include "label.h" /* definition label */ +#include "expr.h" +#include "def.h" +#include "code.h" /* RVAL etc */ +#include "LLlex.h" +#include "Lpars.h" +#include "stack.h" +#include "type.h" +#include "level.h" +#include "l_lint.h" +#include "l_state.h" +#include "l_outdef.h" extern char options[128]; - -static struct expr_state *expr2state(); -static struct expr_state *value2state(); -static struct expr_state *oper2state(); +static struct expr_state* expr2state(); +static struct expr_state* value2state(); +static struct expr_state* oper2state(); static expr_ignored(); static add_expr_state(); static referred_esp(); @@ -46,253 +45,113 @@ lint_init() lint_init_stack(); } -lint_expr(expr, used) - struct expr *expr; - int used; /* USED or IGNORED */ +lint_expr(expr, used) struct expr* expr; +int used; /* USED or IGNORED */ { - struct expr_state *esp; + struct expr_state* esp; esp = expr2state(expr, RVAL, used); referred_esp(esp); free_expr_states(esp); } -static struct expr_state * -expr2state(expr, val, used) - struct expr *expr; - int val; /* RVAL or LVAL */ - int used; /* USED or IGNORED */ +static struct expr_state* expr2state(expr, val, used) +struct expr* expr; +int val; /* RVAL or LVAL */ +int used; /* USED or IGNORED */ { -/* Main function to process an expression tree. - * It returns a structure containing information about which variables - * are set and which are used in the expression. - * In addition it sets 'used' and 'set' fields of the corresponding - * variables in the current state. - * If the value of an operation without side-effects is not used, - * a warning is given. - */ - if (used == IGNORED) { + /* Main function to process an expression tree. + * It returns a structure containing information about which variables + * are set and which are used in the expression. + * In addition it sets 'used' and 'set' fields of the corresponding + * variables in the current state. + * If the value of an operation without side-effects is not used, + * a warning is given. + */ + if (used == IGNORED) + { expr_ignored(expr); } - switch (expr->ex_class) { - case Value: - return value2state(expr, val); + switch (expr->ex_class) + { + case Value: + return value2state(expr, val); - case Oper: - return oper2state(expr, val, used); + case Oper: + return oper2state(expr, val, used); - default: /* String, Float, Type */ - return 0; + default: /* String, Float, Type */ + return 0; } } -static struct expr_state * -value2state(expr, val) - struct expr *expr; - int val; /* RVAL or LVAL */ +static struct expr_state* value2state(expr, val) +struct expr* expr; +int val; /* RVAL or LVAL */ { - switch (expr->VL_CLASS) { - case Const: - case Label: - return 0; - - case Name: + switch (expr->VL_CLASS) { - struct idf *idf = expr->VL_IDF; - struct expr_state *esp = 0; - - if (!idf || !idf->id_def) + case Const: + case Label: return 0; - if (val == RVAL && expr->ex_lvalue == 1) { - /* value of identifier used */ - change_state(idf, USED); - add_expr_state(expr->EX_VALUE, USED, &esp); - } - if (val == RVAL && expr->ex_lvalue == 0) { - /* address of identifier used */ - add_expr_state(expr->EX_VALUE, REFERRED, &esp); + case Name: + { + struct idf* idf = expr->VL_IDF; + struct expr_state* esp = 0; + + if (!idf || !idf->id_def) + return 0; + + if (val == RVAL && expr->ex_lvalue == 1) + { + /* value of identifier used */ + change_state(idf, USED); + add_expr_state(expr->EX_VALUE, USED, &esp); + } + if (val == RVAL && expr->ex_lvalue == 0) + { + /* address of identifier used */ + add_expr_state(expr->EX_VALUE, REFERRED, &esp); + } + return esp; } - return esp; - } - default: - NOTREACHED(); - UNREACHABLE_CODE; + default: + NOTREACHED(); + UNREACHABLE_CODE; } } /* Let's get this straight. - An assignment is performed by elaborating the LHS and the RHS - collaterally, to use the A68 terminology, and then serially do the - actual assignment. This means: - 1. evaluate the LHS as an LVAL, - 2. evaluate the RHS as an RVAL, - 3. merge them checking for interference, - 4. set the result of the LHS to SET, if it is a named variable + An assignment is performed by elaborating the LHS and the RHS + collaterally, to use the A68 terminology, and then serially do the + actual assignment. This means: + 1. evaluate the LHS as an LVAL, + 2. evaluate the RHS as an RVAL, + 3. merge them checking for interference, + 4. set the result of the LHS to SET, if it is a named variable */ -static struct expr_state * -oper2state(expr, val, used) - struct expr *expr; - int val; /* RVAL or LVAL */ - int used; /* USED or IGNORED */ +static struct expr_state* oper2state(expr, val, used) +struct expr* expr; +int val; /* RVAL or LVAL */ +int used; /* USED or IGNORED */ { int oper = expr->OP_OPER; - struct expr *left = expr->OP_LEFT; - struct expr *right = expr->OP_RIGHT; - struct expr_state *esp_l = 0; - struct expr_state *esp_r = 0; - - switch (oper) { - - /* assignments */ - case '=': - case PLUSAB: - case MINAB: - case TIMESAB: - case DIVAB: - case MODAB: - case LEFTAB: - case RIGHTAB: - case ANDAB: - case XORAB: - case ORAB: - /* evaluate the LHS, only once; see RM 7.14 */ - esp_l = expr2state(left, (oper == '=' ? LVAL : RVAL), USED); - - /* evaluate the RHS as an RVAL and merge */ - esp_r = expr2state(right, RVAL, USED); - check_and_merge(expr, &esp_l, esp_r); - - /* set resulting variable, if any */ - if (ISNAME(left)) { - change_state(left->VL_IDF, SET); - add_expr_state(left->EX_VALUE, SET, &esp_l); - } - - return esp_l; - - case POSTINCR: - case POSTDECR: - case PLUSPLUS: - case MINMIN: - esp_l = expr2state(left, RVAL, USED); - - /* set resulting variable, if any */ - if (ISNAME(left)) { - change_state(left->VL_IDF, SET); - add_expr_state(left->EX_VALUE, SET, &esp_l); - } - - return esp_l; - - case '?': - esp_l = expr2state(left, RVAL, USED); - esp_r = expr2state(right->OP_LEFT, RVAL, USED); - check_and_merge(expr, &esp_l, esp_r); - esp_r = expr2state(right->OP_RIGHT, RVAL, USED); - check_and_merge(expr, &esp_l, esp_r); - return esp_l; - - case '(': - if (right != 0) { - /* function call with parameters */ - struct expr *ex = right; - - while ( ex->ex_class == Oper - && ex->OP_OPER == PARCOMMA - ) { - esp_r = expr2state(ex->OP_RIGHT, RVAL, USED); - check_and_merge(expr, &esp_l, esp_r); - ex = ex->OP_LEFT; - } - esp_r = expr2state(ex, RVAL, USED); - check_and_merge(expr, &esp_l, esp_r); - } - - if (ISNAME(left)) { - fill_outcall(expr, - expr->ex_type->tp_fund == VOID ? - VOIDED : used - ); - outcall(); - left->VL_IDF->id_def->df_used = 1; - } - else { - esp_r = expr2state(left, RVAL, USED); - check_and_merge(expr, &esp_l, esp_r); - } - referred_esp(esp_l); - return esp_l; - - case '.': - return expr2state(left, val, USED); - - case ARROW: - return expr2state(left, RVAL, USED); - - case INT2INT: - case INT2FLOAT: - case FLOAT2INT: - case FLOAT2FLOAT: - return expr2state(right, RVAL, USED); + struct expr* left = expr->OP_LEFT; + struct expr* right = expr->OP_RIGHT; + struct expr_state* esp_l = 0; + struct expr_state* esp_r = 0; - /* monadic operators */ - case '-': - case '*': - if (left) - goto dyadic; - case '~': - case '!': - return expr2state(right, RVAL, USED); - - /* relational operators */ - case '<': - case '>': - case LESSEQ: - case GREATEREQ: - case EQUAL: - case NOTEQUAL: - goto dyadic; - - /* dyadic operators */ - dyadic: - case '+': - case '/': - case '%': - case ',': - case LEFT: - case RIGHT: - case '&': - case '|': - case '^': - case OR: - case AND: - esp_l = expr2state(left, RVAL, - oper == ',' ? IGNORED : USED); - esp_r = expr2state(right, RVAL, - oper == ',' ? used : USED); - check_and_merge(expr, &esp_l, esp_r); - - return esp_l; - - default: - return 0; /* for initcomma */ - } -} + switch (oper) + { -static -expr_ignored(expr) - struct expr *expr; -{ - switch (expr->ex_class) { - int oper; - case Oper: - oper = expr->OP_OPER; - switch (oper) { + /* assignments */ case '=': + case PLUSAB: + case MINAB: case TIMESAB: case DIVAB: case MODAB: @@ -301,83 +160,222 @@ expr_ignored(expr) case ANDAB: case XORAB: case ORAB: - case AND: /* doubtful but useful */ - case OR: /* doubtful but useful */ - case '(': - case '?': - case ',': - oper = 0; /* ignore the ignoring */ - break; + /* evaluate the LHS, only once; see RM 7.14 */ + esp_l = expr2state(left, (oper == '=' ? LVAL : RVAL), USED); + + /* evaluate the RHS as an RVAL and merge */ + esp_r = expr2state(right, RVAL, USED); + check_and_merge(expr, &esp_l, esp_r); + + /* set resulting variable, if any */ + if (ISNAME(left)) + { + change_state(left->VL_IDF, SET); + add_expr_state(left->EX_VALUE, SET, &esp_l); + } + + return esp_l; - case PLUSAB: - case MINAB: case POSTINCR: case POSTDECR: case PLUSPLUS: case MINMIN: - oper = 0; /* ignore in priciple */ - /* may, however, hide the operator '*' */ - if ( /* operation on a pointer */ - expr->OP_TYPE->tp_fund == POINTER - && /* the result is dereferenced, e.g. *p++; */ - expr->ex_type == expr->OP_TYPE->tp_up - ) { - oper = '*'; + esp_l = expr2state(left, RVAL, USED); + + /* set resulting variable, if any */ + if (ISNAME(left)) + { + change_state(left->VL_IDF, SET); + add_expr_state(left->EX_VALUE, SET, &esp_l); + } + + return esp_l; + + case '?': + esp_l = expr2state(left, RVAL, USED); + esp_r = expr2state(right->OP_LEFT, RVAL, USED); + check_and_merge(expr, &esp_l, esp_r); + esp_r = expr2state(right->OP_RIGHT, RVAL, USED); + check_and_merge(expr, &esp_l, esp_r); + return esp_l; + + case '(': + if (right != 0) + { + /* function call with parameters */ + struct expr* ex = right; + + while (ex->ex_class == Oper && ex->OP_OPER == PARCOMMA) + { + esp_r = expr2state(ex->OP_RIGHT, RVAL, USED); + check_and_merge(expr, &esp_l, esp_r); + ex = ex->OP_LEFT; + } + esp_r = expr2state(ex, RVAL, USED); + check_and_merge(expr, &esp_l, esp_r); } - break; + if (ISNAME(left)) + { + fill_outcall(expr, expr->ex_type->tp_fund == VOID ? VOIDED : used); + outcall(); + left->VL_IDF->id_def->df_used = 1; + } + else + { + esp_r = expr2state(left, RVAL, USED); + check_and_merge(expr, &esp_l, esp_r); + } + referred_esp(esp_l); + return esp_l; + + case '.': + return expr2state(left, val, USED); + + case ARROW: + return expr2state(left, RVAL, USED); + + case INT2INT: + case INT2FLOAT: + case FLOAT2INT: + case FLOAT2FLOAT: + return expr2state(right, RVAL, USED); + + /* monadic operators */ + case '-': + case '*': + if (left) + goto dyadic; + case '~': + case '!': + return expr2state(right, RVAL, USED); + + /* relational operators */ + case '<': + case '>': + case LESSEQ: + case GREATEREQ: + case EQUAL: + case NOTEQUAL: + goto dyadic; + + /* dyadic operators */ + dyadic: + case '+': case '/': - /* this is a specially weird case: the '/' may - result from pointer subtraction - */ - if ( expr->OP_TYPE->tp_fund == INT - && expr->OP_LEFT->OP_OPER == '-' - && expr->OP_LEFT->OP_TYPE->tp_fund == POINTER - ) { - oper = '-'; + case '%': + case ',': + case LEFT: + case RIGHT: + case '&': + case '|': + case '^': + case OR: + case AND: + esp_l = expr2state(left, RVAL, oper == ',' ? IGNORED : USED); + esp_r = expr2state(right, RVAL, oper == ',' ? used : USED); + check_and_merge(expr, &esp_l, esp_r); + + return esp_l; + + default: + return 0; /* for initcomma */ + } +} + +static expr_ignored(expr) struct expr* expr; +{ + switch (expr->ex_class) + { + int oper; + case Oper: + oper = expr->OP_OPER; + switch (oper) + { + case '=': + case TIMESAB: + case DIVAB: + case MODAB: + case LEFTAB: + case RIGHTAB: + case ANDAB: + case XORAB: + case ORAB: + case AND: /* doubtful but useful */ + case OR: /* doubtful but useful */ + case '(': + case '?': + case ',': + oper = 0; /* ignore the ignoring */ + break; + + case PLUSAB: + case MINAB: + case POSTINCR: + case POSTDECR: + case PLUSPLUS: + case MINMIN: + oper = 0; /* ignore in priciple */ + /* may, however, hide the operator '*' */ + if (/* operation on a pointer */ + expr->OP_TYPE->tp_fund == POINTER + && /* the result is dereferenced, e.g. *p++; */ + expr->ex_type == expr->OP_TYPE->tp_up) + { + oper = '*'; + } + break; + + case '/': + /* this is a specially weird case: the '/' may + result from pointer subtraction + */ + if (expr->OP_TYPE->tp_fund == INT && expr->OP_LEFT->OP_OPER == '-' + && expr->OP_LEFT->OP_TYPE->tp_fund == POINTER) + { + oper = '-'; + } + break; + } + if (oper) + { + hwarning("result of %s ignored", symbol2str(oper)); } break; - } - if (oper) { - hwarning("result of %s ignored", symbol2str(oper)); - } - break; - case Value: - if (expr->VL_CLASS == Const) { - hwarning("constant expression ignored"); - } - else { - hwarning("value ignored"); - } - break; + case Value: + if (expr->VL_CLASS == Const) + { + hwarning("constant expression ignored"); + } + else + { + hwarning("value ignored"); + } + break; - default: /* String Float */ - hwarning("constant ignored"); - break; + default: /* String Float */ + hwarning("constant ignored"); + break; } } -static -add_expr_state(value, to_state, espp) - struct value value; - struct expr_state **espp; +static add_expr_state(value, to_state, espp) struct value value; +struct expr_state** espp; { - struct expr_state *esp = *espp; + struct expr_state* esp = *espp; assert(value.vl_class == Name); /* try to find the esp */ - while ( esp - && !( esp->es_idf == value.vl_data.vl_idf - && esp->es_offset == value.vl_value - ) - ) { + while (esp && !(esp->es_idf == value.vl_data.vl_idf && esp->es_offset == value.vl_value)) + { esp = esp->next; } /* if not found, add it */ - if (!esp) { + if (!esp) + { esp = new_expr_state(); esp->es_idf = value.vl_data.vl_idf; esp->es_offset = value.vl_value; @@ -386,29 +384,30 @@ add_expr_state(value, to_state, espp) } /* set state */ - switch (to_state) { - case USED: - esp->es_used = 1; - break; - case REFERRED: - esp->es_referred = 1; - break; - case SET: - esp->es_set = 1; - break; - default: - NOTREACHED(); - UNREACHABLE_CODE; + switch (to_state) + { + case USED: + esp->es_used = 1; + break; + case REFERRED: + esp->es_referred = 1; + break; + case SET: + esp->es_set = 1; + break; + default: + NOTREACHED(); + UNREACHABLE_CODE; } } -static -referred_esp(esp) - struct expr_state *esp; +static referred_esp(esp) struct expr_state* esp; { /* raises all REFERRED items to SET and USED status */ - while (esp) { - if (esp->es_referred) { + while (esp) + { + if (esp->es_referred) + { esp->es_set = 1; change_state(esp->es_idf, SET); esp->es_used = 1; @@ -419,35 +418,31 @@ referred_esp(esp) } } -static -free_expr_states(esp) - struct expr_state *esp; +static free_expr_states(esp) struct expr_state* esp; { - while (esp) { - struct expr_state *esp2 = esp; + while (esp) + { + struct expr_state* esp2 = esp; esp = esp->next; free_expr_state(esp2); } } -#ifdef DEBUG -print_esp(msg, esp) - char *msg; - struct expr_state *esp; +#ifdef DEBUG +print_esp(msg, esp) char* msg; +struct expr_state* esp; { printf("%s: <", msg); - while (esp) { - printf(" %s[%d]%c%c%c ", - esp->es_idf->id_text, esp->es_offset, - (esp->es_used ? 'U' : ' '), - (esp->es_referred ? 'R' : ' '), - (esp->es_set ? 'S' : ' ') - ); + while (esp) + { + printf( + " %s[%d]%c%c%c ", esp->es_idf->id_text, esp->es_offset, (esp->es_used ? 'U' : ' '), + (esp->es_referred ? 'R' : ' '), (esp->es_set ? 'S' : ' ')); esp = esp->next; } printf(">\n"); } -#endif /* DEBUG */ +#endif /* DEBUG */ -#endif /* LINT */ +#endif /* LINT */ diff --git a/lang/cem/cemcom.ansi/l_lint.h b/lang/cem/cemcom.ansi/l_lint.h index 362954ed38..25f2507204 100644 --- a/lang/cem/cemcom.ansi/l_lint.h +++ b/lang/cem/cemcom.ansi/l_lint.h @@ -5,14 +5,13 @@ /* $Id$ */ /* LINT FLAGS */ -#define USED 0 -#define IGNORED 1 -#define SET 2 -#define VOIDED 3 -#define REFERRED 4 +#define USED 0 +#define IGNORED 1 +#define SET 2 +#define VOIDED 3 +#define REFERRED 4 /* for od_valreturned */ -#define NOVALRETURNED 0 -#define VALRETURNED 1 -#define NORETURN 2 /* end of function NOTREACHED */ - +#define NOVALRETURNED 0 +#define VALRETURNED 1 +#define NORETURN 2 /* end of function NOTREACHED */ diff --git a/lang/cem/cemcom.ansi/l_misc.c b/lang/cem/cemcom.ansi/l_misc.c index e3ef9b04f2..d8f59e43e8 100644 --- a/lang/cem/cemcom.ansi/l_misc.c +++ b/lang/cem/cemcom.ansi/l_misc.c @@ -5,288 +5,273 @@ /* $Id$ */ /* Lint miscellaneous routines */ -#include "parameters.h" +#include "parameters.h" +#include +#include -#ifdef LINT +#ifdef LINT -#include /* for st_free */ -#include "interface.h" +#include /* for st_free */ +#include "interface.h" #ifdef ANSI -#include +#include #endif /* ANSI */ -#include "arith.h" /* definition arith */ -#include "label.h" /* definition label */ -#include "expr.h" -#include "def.h" -#include "code.h" /* RVAL etc */ -#include "LLlex.h" -#include "Lpars.h" -#include "stack.h" -#include "type.h" -#include "level.h" -#include "l_state.h" - - -extern struct type *func_type; +#include "arith.h" /* definition arith */ +#include "label.h" /* definition label */ +#include "expr.h" +#include "def.h" +#include "code.h" /* RVAL etc */ +#include "LLlex.h" +#include "Lpars.h" +#include "stack.h" +#include "type.h" +#include "level.h" +#include "l_state.h" + +extern struct type* func_type; static lint_enum_arith(); static lint_conversion(); static int numsize(); -check_hiding(idf, lvl, sc) - struct idf *idf; - int lvl; - int sc; +check_hiding(idf, lvl, sc) struct idf* idf; +int lvl; +int sc; { /* Checks if there is already a definition for this non-extern - name on a more global level. + name on a more global level. */ - struct def *def = idf->id_def; - - if ( def && def->df_level < lvl - && ! ( lvl == L_FORMAL2 - || def->df_level == L_UNIVERSAL - || sc == GLOBAL - || sc == EXTERN - ) - ) { - warning("%s is already defined as a %s", - idf->id_text, - def->df_level == L_GLOBAL ? "global" : - def->df_level == L_FORMAL2 ? "formal" : - "more global local" - ); + struct def* def = idf->id_def; + + if (def && def->df_level < lvl + && !(lvl == L_FORMAL2 || def->df_level == L_UNIVERSAL || sc == GLOBAL || sc == EXTERN)) + { + warning( + "%s is already defined as a %s", idf->id_text, + def->df_level == L_GLOBAL ? "global" + : def->df_level == L_FORMAL2 ? "formal" + : "more global local"); } } -lint_new_oper(expr) - struct expr *expr; +lint_new_oper(expr) struct expr* expr; { /* Does additional checking on a newly constructed expr node - of class Oper. + of class Oper. - Some code in this routine could be contracted, but since - I am not sure we have covered the entire ground, we'll - leave the contracting for some rainy day. + Some code in this routine could be contracted, but since + I am not sure we have covered the entire ground, we'll + leave the contracting for some rainy day. */ - struct expr *left = expr->OP_LEFT; - struct expr *right = expr->OP_RIGHT; + struct expr* left = expr->OP_LEFT; + struct expr* right = expr->OP_RIGHT; int oper = expr->OP_OPER; - int l_fund = - left == 0 ? 0 : /* for monadics */ - left->ex_type->tp_fund; - int r_fund = - right == 0 ? 0 : /* for ( without parameters */ - right->ex_type->tp_fund; + int l_fund = left == 0 ? 0 : /* for monadics */ + left->ex_type->tp_fund; + int r_fund = right == 0 ? 0 : /* for ( without parameters */ + right->ex_type->tp_fund; /* In ch7.c, in ch7asgn(), a combined operator/assignment - is hammered into correctness by repeated application of - ch7bin(), which calls new_oper(), which calls lint_new_oper(). - These spurious calls understandably cause spurious error - messages, which we don't like. So we try to suppress these - wierd calls here. This refers to the code marked - this is really $#@&*%$# ! - in ch7asgn(). + is hammered into correctness by repeated application of + ch7bin(), which calls new_oper(), which calls lint_new_oper(). + These spurious calls understandably cause spurious error + messages, which we don't like. So we try to suppress these + wierd calls here. This refers to the code marked + this is really $#@&*%$# ! + in ch7asgn(). */ - switch (oper) { - case PLUSAB: - case MINAB: - case TIMESAB: - case DIVAB: - case MODAB: - case LEFTAB: - case RIGHTAB: - case ANDAB: - case XORAB: - case ORAB: - /* is the left operand wierd? */ - if ( left->ex_class == Value - && left->VL_CLASS == Const - && left->VL_VALUE == 0 - ) { - return; - } + switch (oper) + { + case PLUSAB: + case MINAB: + case TIMESAB: + case DIVAB: + case MODAB: + case LEFTAB: + case RIGHTAB: + case ANDAB: + case XORAB: + case ORAB: + /* is the left operand wierd? */ + if (left->ex_class == Value && left->VL_CLASS == Const && left->VL_VALUE == 0) + { + return; + } } - switch (oper) { - case '=': - lint_conversion(right, l_fund); - break; - - case PLUSAB: - lint_conversion(right, l_fund); - case '+': - lint_enum_arith(l_fund, oper, r_fund); - break; - - case MINAB: - lint_conversion(right, l_fund); - case '-': - if (left == 0) { - /* unary */ - if (r_fund == ENUM) - warning("negating an enum"); - } - else { - /* binary */ - if (l_fund == ENUM && r_fund == ENUM) { - if (left->ex_type != right->ex_type) - warning("subtracting enums of different type"); - /* update the type, cem does not do it */ - expr->ex_type = int_type; - } + switch (oper) + { + case '=': + lint_conversion(right, l_fund); + break; + + case PLUSAB: + lint_conversion(right, l_fund); + case '+': lint_enum_arith(l_fund, oper, r_fund); - } - break; + break; + + case MINAB: + lint_conversion(right, l_fund); + case '-': + if (left == 0) + { + /* unary */ + if (r_fund == ENUM) + warning("negating an enum"); + } + else + { + /* binary */ + if (l_fund == ENUM && r_fund == ENUM) + { + if (left->ex_type != right->ex_type) + warning("subtracting enums of different type"); + /* update the type, cem does not do it */ + expr->ex_type = int_type; + } + lint_enum_arith(l_fund, oper, r_fund); + } + break; + + case TIMESAB: + lint_conversion(right, l_fund); + case '*': + if (left == 0) + { + /* unary */ + } + else + { + /* binary */ + if (l_fund == ENUM || r_fund == ENUM) + warning("multiplying enum"); + } + break; - case TIMESAB: - lint_conversion(right, l_fund); - case '*': - if (left == 0) { - /* unary */ - } - else { - /* binary */ + case DIVAB: + lint_conversion(right, l_fund); + case '/': if (l_fund == ENUM || r_fund == ENUM) - warning("multiplying enum"); - } - break; - - case DIVAB: - lint_conversion(right, l_fund); - case '/': - if (l_fund == ENUM || r_fund == ENUM) - warning("division on enum"); - break; - - case MODAB: - lint_conversion(right, l_fund); - case '%': - if (l_fund == ENUM || r_fund == ENUM) - warning("modulo on enum"); - break; - - case '~': - if (r_fund == ENUM || r_fund == FLOAT || r_fund == DOUBLE) - warning("~ on %s", symbol2str(r_fund)); - break; - - case '!': - if (r_fund == ENUM) - warning("! on enum"); - break; - - case INT2INT: - case INT2FLOAT: - case FLOAT2INT: - case FLOAT2FLOAT: - lint_conversion(right, l_fund); - break; - - case '<': - case '>': - case LESSEQ: - case GREATEREQ: - case EQUAL: - case NOTEQUAL: - if ( (l_fund == ENUM || r_fund == ENUM) - && left->ex_type != right->ex_type - ) { - warning("comparing enum with non-enum"); - } - lint_relop(left, right, oper); - lint_relop(right, left, - oper == '<' ? '>' : - oper == '>' ? '<' : - oper == LESSEQ ? GREATEREQ : - oper == GREATEREQ ? LESSEQ : - oper - ); - break; - - case LEFTAB: - case RIGHTAB: - lint_conversion(right, l_fund); - case LEFT: - case RIGHT: - if (l_fund == ENUM || r_fund == ENUM) - warning("shift on enum"); - break; - - case ANDAB: - case ORAB: - case XORAB: - lint_conversion(right, l_fund); - case '&': - case '|': - case '^': - if (l_fund == ENUM || r_fund == ENUM) - warning("bit operations on enum"); - break; - - case ',': - case '?': - case ':': - case AND: - case OR: - case POSTINCR: - case POSTDECR: - case PLUSPLUS: - case MINMIN: - case '(': - case '.': - case ARROW: - default: - /* OK with lint */ - break; + warning("division on enum"); + break; + + case MODAB: + lint_conversion(right, l_fund); + case '%': + if (l_fund == ENUM || r_fund == ENUM) + warning("modulo on enum"); + break; + + case '~': + if (r_fund == ENUM || r_fund == FLOAT || r_fund == DOUBLE) + warning("~ on %s", symbol2str(r_fund)); + break; + + case '!': + if (r_fund == ENUM) + warning("! on enum"); + break; + + case INT2INT: + case INT2FLOAT: + case FLOAT2INT: + case FLOAT2FLOAT: + lint_conversion(right, l_fund); + break; + + case '<': + case '>': + case LESSEQ: + case GREATEREQ: + case EQUAL: + case NOTEQUAL: + if ((l_fund == ENUM || r_fund == ENUM) && left->ex_type != right->ex_type) + { + warning("comparing enum with non-enum"); + } + lint_relop(left, right, oper); + lint_relop( + right, left, + oper == '<' ? '>' + : oper == '>' ? '<' + : oper == LESSEQ ? GREATEREQ + : oper == GREATEREQ ? LESSEQ + : oper); + break; + + case LEFTAB: + case RIGHTAB: + lint_conversion(right, l_fund); + case LEFT: + case RIGHT: + if (l_fund == ENUM || r_fund == ENUM) + warning("shift on enum"); + break; + + case ANDAB: + case ORAB: + case XORAB: + lint_conversion(right, l_fund); + case '&': + case '|': + case '^': + if (l_fund == ENUM || r_fund == ENUM) + warning("bit operations on enum"); + break; + + case ',': + case '?': + case ':': + case AND: + case OR: + case POSTINCR: + case POSTDECR: + case PLUSPLUS: + case MINMIN: + case '(': + case '.': + case ARROW: + default: + /* OK with lint */ + break; } } -static -lint_enum_arith(l_fund, oper, r_fund) - int l_fund, oper, r_fund; +static lint_enum_arith(l_fund, oper, r_fund) int l_fund, oper, r_fund; { - if ( l_fund == ENUM - && r_fund != CHAR - && r_fund != SHORT - && r_fund != INT - ) { - warning("%s on enum and %s", - symbol2str(oper), symbol2str(r_fund)); + if (l_fund == ENUM && r_fund != CHAR && r_fund != SHORT && r_fund != INT) + { + warning("%s on enum and %s", symbol2str(oper), symbol2str(r_fund)); } - else - if ( r_fund == ENUM - && l_fund != CHAR - && l_fund != SHORT - && l_fund != INT - ) { - warning("%s on %s and enum", - symbol2str(oper), symbol2str(l_fund)); + else if (r_fund == ENUM && l_fund != CHAR && l_fund != SHORT && l_fund != INT) + { + warning("%s on %s and enum", symbol2str(oper), symbol2str(l_fund)); } } -static -lint_conversion(from_expr, to_fund) - struct expr *from_expr; - int to_fund; +static lint_conversion(from_expr, to_fund) struct expr* from_expr; +int to_fund; { int from_fund = from_expr->ex_type->tp_fund; /* was there an attempt to reduce the type of the from_expr - of the form - expr & 0377 - or something like this? + of the form + expr & 0377 + or something like this? */ - if (from_expr->ex_class == Oper && from_expr->OP_OPER == INT2INT) { + if (from_expr->ex_class == Oper && from_expr->OP_OPER == INT2INT) + { from_expr = from_expr->OP_LEFT; } - if (from_expr->ex_class == Oper && from_expr->OP_OPER == '&') { - struct expr *bits = - is_cp_cst(from_expr->OP_LEFT) ? from_expr->OP_LEFT : - is_cp_cst(from_expr->OP_RIGHT) ? from_expr->OP_RIGHT : - 0; - - if (bits) { + if (from_expr->ex_class == Oper && from_expr->OP_OPER == '&') + { + struct expr* bits = is_cp_cst(from_expr->OP_LEFT) ? from_expr->OP_LEFT + : is_cp_cst(from_expr->OP_RIGHT) ? from_expr->OP_RIGHT + : 0; + + if (bits) + { arith val = bits->VL_VALUE; if (val < 256) @@ -295,41 +280,49 @@ lint_conversion(from_expr, to_fund) from_fund = SHORT; } } - if (numsize(from_fund) > numsize(to_fund)) { - awarning("conversion from %s to %s may lose accuracy", - symbol2str(from_fund), symbol2str(to_fund)); + if (numsize(from_fund) > numsize(to_fund)) + { + awarning( + "conversion from %s to %s may lose accuracy", symbol2str(from_fund), + symbol2str(to_fund)); } } -static int -numsize(fund) +static int numsize(fund) { - switch (fund) { - case CHAR: return 1; - case SHORT: return 2; - case INT: return 3; - case ENUM: return 3; - case LONG: return 4; - case FLOAT: return 5; - case DOUBLE: return 6; - default: return 0; + switch (fund) + { + case CHAR: + return 1; + case SHORT: + return 2; + case INT: + return 3; + case ENUM: + return 3; + case LONG: + return 4; + case FLOAT: + return 5; + case DOUBLE: + return 6; + default: + return 0; } } -lint_ret_conv(from_expr) - struct expr *from_expr; +lint_ret_conv(from_expr) struct expr* from_expr; { lint_conversion(from_expr, func_type->tp_fund); } -lint_ptr_conv(from, to) - short from, to; +lint_ptr_conv(from, to) short from, to; { -/* X -> X ok -- this includes struct -> struct, of any size - * X -> CHAR ok - * DOUBLE -> X ok - * FLOAT -> LONG -> INT -> SHORT ok - */ + /* X -> X ok -- this includes struct -> struct, of any size + * X -> CHAR ok + * DOUBLE -> X ok + * FLOAT -> LONG -> INT -> SHORT ok + */ if (from == to) return; @@ -342,88 +335,89 @@ lint_ptr_conv(from, to) if (from == DOUBLE) return; - switch (from) { - case FLOAT: - switch (to) { + switch (from) + { + case FLOAT: + switch (to) + { + case LONG: + case INT: + case SHORT: + return; + } + break; case LONG: + switch (to) + { + case INT: + case SHORT: + return; + } + break; case INT: - case SHORT: - return; - } - break; - case LONG: - switch (to) { - case INT: - case SHORT: - return; - } - break; - case INT: - switch (to) { - case SHORT: - return; - } - break; + switch (to) + { + case SHORT: + return; + } + break; } - if (from == VOID) { + if (from == VOID) + { /* OK any which way */ } - else - if (from == CHAR) { - hwarning("pointer to char may not align correctly for a %s", - symbol2str(to)); + else if (from == CHAR) + { + hwarning("pointer to char may not align correctly for a %s", symbol2str(to)); } - else { - warning("pointer to %s may not align correctly for a %s", - symbol2str(from), symbol2str(to)); + else + { + warning("pointer to %s may not align correctly for a %s", symbol2str(from), symbol2str(to)); } } -lint_relop(left, right, oper) - struct expr *left, *right; - int oper; /* '<', '>', LESSEQ, GREATEREQ, EQUAL, NOTEQUAL */ +lint_relop(left, right, oper) struct expr* left, *right; +int oper; /* '<', '>', LESSEQ, GREATEREQ, EQUAL, NOTEQUAL */ { /* left operand may be converted */ - if ( left->ex_class == Oper - && left->OP_OPER == INT2INT - ) { + if (left->ex_class == Oper && left->OP_OPER == INT2INT) + { left = left->OP_RIGHT; } /* is doubtful */ - if ( left->ex_type->tp_unsigned - && right->ex_class == Value - && right->VL_CLASS == Const - ) { - if (!right->ex_type->tp_unsigned && right->VL_VALUE < 0) { + if (left->ex_type->tp_unsigned && right->ex_class == Value && right->VL_CLASS == Const) + { + if (!right->ex_type->tp_unsigned && right->VL_VALUE < 0) + { warning("unsigned compared to negative constant"); } - if (right->VL_VALUE == 0) { - switch (oper) { - case '<': - warning("unsigned < 0 will always fail"); - break; - - case LESSEQ: - warning("unsigned <= 0 is probably wrong"); - break; - - case GREATEREQ: - warning("unsigned >= 0 will always succeed"); - break; + if (right->VL_VALUE == 0) + { + switch (oper) + { + case '<': + warning("unsigned < 0 will always fail"); + break; + + case LESSEQ: + warning("unsigned <= 0 is probably wrong"); + break; + + case GREATEREQ: + warning("unsigned >= 0 will always succeed"); + break; } } } /* is undefined */ - if ( left->ex_type->tp_fund == CHAR - && right->ex_class == Value - && right->VL_CLASS == Const - && (right->VL_VALUE < 0 || right->VL_VALUE > 127) - ) { + if (left->ex_type->tp_fund == CHAR && right->ex_class == Value && right->VL_CLASS == Const + && (right->VL_VALUE < 0 || right->VL_VALUE > 127)) + { warning("character compared to negative constant"); } } -#endif /* LINT */ +#endif /* LINT */ diff --git a/lang/cem/cemcom.ansi/l_outdef.c b/lang/cem/cemcom.ansi/l_outdef.c index 381c6a5652..488aa6e54d 100644 --- a/lang/cem/cemcom.ansi/l_outdef.c +++ b/lang/cem/cemcom.ansi/l_outdef.c @@ -5,40 +5,40 @@ /* $Id$ */ /* Lint outdef construction */ -#include "parameters.h" +#include "parameters.h" +#include +#include -#ifdef LINT +#ifdef LINT -#include -#include -#include -#include "interface.h" +#include +#include +#include +#include "interface.h" #ifdef ANSI -#include +#include #endif /* ANSI */ -#include "arith.h" -#include "type.h" -#include "proto.h" -#include "declar.h" -#include "decspecs.h" -#include "LLlex.h" -#include "Lpars.h" -#include "stack.h" -#include "def.h" -#include "struct.h" -#include "field.h" -#include "level.h" -#include "label.h" -#include "code.h" -#include "expr.h" -#include "l_lint.h" -#include "l_comment.h" -#include "l_outdef.h" -#include "l_class.h" - - - -int stat_number = 9999; /* static scope number */ +#include "arith.h" +#include "type.h" +#include "proto.h" +#include "declar.h" +#include "decspecs.h" +#include "LLlex.h" +#include "Lpars.h" +#include "stack.h" +#include "def.h" +#include "struct.h" +#include "field.h" +#include "level.h" +#include "label.h" +#include "code.h" +#include "expr.h" +#include "l_lint.h" +#include "l_comment.h" +#include "l_outdef.h" +#include "l_class.h" + +int stat_number = 9999; /* static scope number */ struct outdef OutDef; static struct outdef OutCall; @@ -52,31 +52,30 @@ static outargtype(); static add_expr_arg(); static def2decl(); -lint_declare_idf(idf, sc) - struct idf *idf; - int sc; +lint_declare_idf(idf, sc) struct idf* idf; +int sc; { - struct def *def = idf->id_def; + struct def* def = idf->id_def; int is_function = def->df_type->tp_fund == FUNCTION; - if (level == L_GLOBAL) { + if (level == L_GLOBAL) + { lint_ext_def(idf, sc); if (is_function) def2decl(sc); if (sc != TYPEDEF) outdef(); } - else - if (level >= L_LOCAL && sc != STATIC && is_function) { + else if (level >= L_LOCAL && sc != STATIC && is_function) + { local_EFDC(idf); } } -lint_non_function_decl(ds, dc) - struct decspecs *ds; - struct declarator *dc; +lint_non_function_decl(ds, dc) struct decspecs* ds; +struct declarator* dc; { - struct def *def = dc->dc_idf->id_def; + struct def* def = dc->dc_idf->id_def; int is_function = def->df_type->tp_fund == FUNCTION; if (is_function) @@ -85,40 +84,38 @@ lint_non_function_decl(ds, dc) outdef(); } -lint_ext_def(idf, sc) - struct idf *idf; +lint_ext_def(idf, sc) struct idf* idf; { -/* At this place the following fields of the output definition can be - * filled: - * od_name, od_statnr, od_class, od_file, od_line, od_type. - * For variable definitions and declarations this will be all. - * For functions the fields od_nrargs and od_arg are filled after parsing - * the arguments. - * The od_valreturned field is known at the end of the function definition. - * sc indicates the storage class defined by the declaration specifier. - */ - struct def *def = idf->id_def; - struct type *type = def->df_type; + /* At this place the following fields of the output definition can be + * filled: + * od_name, od_statnr, od_class, od_file, od_line, od_type. + * For variable definitions and declarations this will be all. + * For functions the fields od_nrargs and od_arg are filled after parsing + * the arguments. + * The od_valreturned field is known at the end of the function definition. + * sc indicates the storage class defined by the declaration specifier. + */ + struct def* def = idf->id_def; + struct type* type = def->df_type; OutDef.od_name = idf->id_text; OutDef.od_statnr = (sc == STATIC ? stat_number : 0); - switch (type->tp_fund) { - case ERRONEOUS: - OutDef.od_class = XXDF; - break; - case FUNCTION: - /* For the moment assume it will be a definition. - * If no compound_statement follows, it is a declaration, - * in which case the class will be adjusted by def2decl(). - */ - OutDef.od_class = (sc == STATIC ? SFDF : EFDF); - break; - default: /* a variable */ - OutDef.od_class = - sc == EXTERN ? EVDC : - sc == STATIC ? SVDF : EVDF; - break; + switch (type->tp_fund) + { + case ERRONEOUS: + OutDef.od_class = XXDF; + break; + case FUNCTION: + /* For the moment assume it will be a definition. + * If no compound_statement follows, it is a declaration, + * in which case the class will be adjusted by def2decl(). + */ + OutDef.od_class = (sc == STATIC ? SFDF : EFDF); + break; + default: /* a variable */ + OutDef.od_class = sc == EXTERN ? EVDC : sc == STATIC ? SVDF : EVDF; + break; } OutDef.od_file = def->df_file; OutDef.od_line = def->df_line; @@ -126,14 +123,12 @@ lint_ext_def(idf, sc) OutDef.od_valreturned = NORETURN; } -static -def2decl(sc) - int sc; +static def2decl(sc) int sc; { -/* It was assumed we were parsing a function definition. - * There was no compound statement following, so actually it was a - * declaration. This function updates the class. - */ + /* It was assumed we were parsing a function definition. + * There was no compound statement following, so actually it was a + * declaration. This function updates the class. + */ OutDef.od_class = (sc == STATIC ? XXDF : EFDC); } @@ -142,9 +137,7 @@ set_od_valreturned(n) OutDef.od_valreturned = n; } -static -local_EFDC(idf) - struct idf *idf; +static local_EFDC(idf) struct idf* idf; { struct outdef od; @@ -160,25 +153,23 @@ local_EFDC(idf) lint_formals() { -/* Make a list of 'struct argument's containing the types of the formal - * parameters of the function definition just parsed. - */ - struct stack_entry *se = stack_level_of(L_FORMAL1)->sl_entry; - struct argument **hook = &OutDef.od_arg; + /* Make a list of 'struct argument's containing the types of the formal + * parameters of the function definition just parsed. + */ + struct stack_entry* se = stack_level_of(L_FORMAL1)->sl_entry; + struct argument** hook = &OutDef.od_arg; int nrargs = 0; - while (se) { - struct type *type = se->se_idf->id_def->df_type; - struct argument *arg = new_argument(); - - if (f_FORMAT && nrargs == f_FORMATn) { - if ( !f_FORMATvar - && ( type->tp_fund != POINTER - || type->tp_up->tp_fund != CHAR - ) - ) { - warning("format parameter %d is not pointer to char", - nrargs); + while (se) + { + struct type* type = se->se_idf->id_def->df_type; + struct argument* arg = new_argument(); + + if (f_FORMAT && nrargs == f_FORMATn) + { + if (!f_FORMATvar && (type->tp_fund != POINTER || type->tp_up->tp_fund != CHAR)) + { + warning("format parameter %d is not pointer to char", nrargs); } arg->ar_type = string_type; arg->ar_class = ArgString; @@ -186,7 +177,8 @@ lint_formals() arg->CAS_LEN = strlen(f_FORMAT); f_FORMAT = 0; } - else { + else + { arg->ar_type = type; arg->ar_class = ArgFormal; } @@ -197,29 +189,33 @@ lint_formals() se = se->next; } - if (f_FORMAT) { + if (f_FORMAT) + { /* f_FORMAT has not been consumed, perhaps due to - a varargs-like construction; add erroneous ArgFormals - until f_FORMATn, then an ArgString, if necessary. + a varargs-like construction; add erroneous ArgFormals + until f_FORMATn, then an ArgString, if necessary. */ - if (!f_FORMATvar) { - warning("FORMAT%d function has only %d argument%s", - f_FORMATn, nrargs, nrargs == 1 ? "" : "s" - ); + if (!f_FORMATvar) + { + warning( + "FORMAT%d function has only %d argument%s", f_FORMATn, nrargs, + nrargs == 1 ? "" : "s"); } - while (nrargs < f_FORMATn) { - struct argument *arg = new_argument(); - + while (nrargs < f_FORMATn) + { + struct argument* arg = new_argument(); + arg->ar_type = error_type; arg->ar_class = ArgFormal; *hook = arg; hook = &arg->next; nrargs++; } - if (nrargs == f_FORMATn) { - struct argument *arg = new_argument(); - + if (nrargs == f_FORMATn) + { + struct argument* arg = new_argument(); + arg->ar_type = string_type; arg->ar_class = ArgString; arg->CAS_VALUE = f_FORMAT; @@ -232,24 +228,25 @@ lint_formals() /* life is full of duplicated code; this is no good */ } - if (f_VARARGSn > nrargs) { - warning("VARARGS%d function has only %d argument%s", - f_VARARGSn, nrargs, nrargs == 1 ? "" : "s" - ); + if (f_VARARGSn > nrargs) + { + warning( + "VARARGS%d function has only %d argument%s", f_VARARGSn, nrargs, + nrargs == 1 ? "" : "s"); f_VARARGSn = nrargs; } OutDef.od_nrargs = nrargs; } -output_proto(idf, def) - struct idf *idf; - struct def *def; +output_proto(idf, def) struct idf* idf; +struct def* def; { /* fund == FUNCTION && sc != STATIC */ - struct proto *pl = def->df_type->tp_proto; + struct proto* pl = def->df_type->tp_proto; int nrargs = 0; - if (!pl) return; + if (!pl) + return; OutDef.od_name = idf->id_text; OutDef.od_statnr = 0; @@ -257,17 +254,20 @@ output_proto(idf, def) OutDef.od_file = def->df_file; OutDef.od_line = def->df_line; OutDef.od_type = def->df_type->tp_up; - OutDef.od_valreturned = NORETURN;/*???*/ + OutDef.od_valreturned = NORETURN; /*???*/ - while (pl) { - struct type *type = pl->pl_type; - struct argument *arg = new_argument(); + while (pl) + { + struct type* type = pl->pl_type; + struct argument* arg = new_argument(); - if (type) { + if (type) + { arg->ar_type = type; arg->ar_class = ArgFormal; } - else { + else + { arg->ar_class = ArgEllipsis; } arg->next = OutDef.od_arg; @@ -281,11 +281,10 @@ output_proto(idf, def) outdef(); } -output_use(idf) - struct idf *idf; +output_use(idf) struct idf* idf; { -/* Output the usage-definition of the variable described by idf. - */ + /* Output the usage-definition of the variable described by idf. + */ OutDef.od_name = idf->id_text; OutDef.od_statnr = (idf->id_def->df_sc == STATIC ? stat_number : 0); OutDef.od_class = VU; @@ -305,85 +304,88 @@ outcall() output_def(&OutCall); } -static -output_def(od) - struct outdef *od; +static output_def(od) struct outdef* od; { -/* As the types are output the 'struct argument's are freed, because they - * are then not needed anymore. - */ + /* As the types are output the 'struct argument's are freed, because they + * are then not needed anymore. + */ if (od->od_class == XXDF || !od->od_name || od->od_name[0] == '#') return; - if (LINTLIB) { - switch (od->od_class) { - case EFDF: - od->od_class = LFDF; - break; - case EVDF: - od->od_class = LVDF; - break; - case SFDF: - /* free the 'struct argument's */ - while (od->od_arg) { - struct argument *tmp = od->od_arg; - od->od_arg = od->od_arg->next; - free_argument(tmp); - } - return; - default: - return; + if (LINTLIB) + { + switch (od->od_class) + { + case EFDF: + od->od_class = LFDF; + break; + case EVDF: + od->od_class = LVDF; + break; + case SFDF: + /* free the 'struct argument's */ + while (od->od_arg) + { + struct argument* tmp = od->od_arg; + od->od_arg = od->od_arg->next; + free_argument(tmp); + } + return; + default: + return; } } printf("%s:%d:%c", od->od_name, od->od_statnr, od->od_class); - switch (od->od_class) { - case LFDF: - case PFDF: - case EFDF: - case SFDF: - if (f_VARARGSn != -1) { - printf(":%d", -1 - f_VARARGSn); - outargs(od->od_arg, f_VARARGSn); - } - else { + switch (od->od_class) + { + case LFDF: + case PFDF: + case EFDF: + case SFDF: + if (f_VARARGSn != -1) + { + printf(":%d", -1 - f_VARARGSn); + outargs(od->od_arg, f_VARARGSn); + } + else + { + printf(":%d", od->od_nrargs); + outargs(od->od_arg, od->od_nrargs); + } + od->od_arg = 0; + printf(":%d", od->od_valreturned); + break; + case FC: printf(":%d", od->od_nrargs); outargs(od->od_arg, od->od_nrargs); - } - od->od_arg = 0; - printf(":%d", od->od_valreturned); - break; - case FC: - printf(":%d", od->od_nrargs); - outargs(od->od_arg, od->od_nrargs); - od->od_arg = 0; - printf(":%d", od->od_valused); - break; - case EVDF: - case SVDF: - case LVDF: - case EFDC: - case EVDC: - case IFDC: - case VU: - break; - default: - NOTREACHED(); - UNREACHABLE_CODE; + od->od_arg = 0; + printf(":%d", od->od_valused); + break; + case EVDF: + case SVDF: + case LVDF: + case EFDC: + case EVDC: + case IFDC: + case VU: + break; + default: + NOTREACHED(); + UNREACHABLE_CODE; } printf(":"); outargtype(od->od_type); printf(":%u:%s\n", od->od_line, od->od_file); } -static -outargs(arg, n) - struct argument *arg; +static outargs(arg, n) struct argument* arg; { -/* Output the n arguments in the argument list and remove them */ + /* Output the n arguments in the argument list and remove them */ - struct argument *tmp; + struct argument* tmp; - while (n--) { + while (n--) + { assert(arg); outarg(arg); tmp = arg; @@ -391,139 +393,138 @@ outargs(arg, n) free_argument(tmp); } /* remove the remaining entries */ - while (arg) { + while (arg) + { tmp = arg; arg = arg->next; free_argument(tmp); } } -static -outarg(arg) - struct argument *arg; +static outarg(arg) struct argument* arg; { printf(":"); - switch (arg->ar_class) { - case ArgConst: - if (arg->CAA_VALUE >= 0) { - /* constant non-negative actual parameter */ - printf("+"); - } - outargtype(arg->ar_type); - break; - - case ArgString: - outargstring(arg); - break; - - case ArgFormal: - case ArgExpr: - outargtype(arg->ar_type); - if (arg->ar_type->tp_fund == FUNCTION) { - /* UGLY PATCH !!! ??? */ - /* function names as operands are sometimes - FUNCTION and sometimes POINTER to FUNCTION, - depending on opaque circumstances. E.g., in - f(main, main); - the first main is PtF and the second is F. - */ - printf("*"); - } - break; + switch (arg->ar_class) + { + case ArgConst: + if (arg->CAA_VALUE >= 0) + { + /* constant non-negative actual parameter */ + printf("+"); + } + outargtype(arg->ar_type); + break; - case ArgEllipsis: - printf("."); /* one is enough for computers */ - break; + case ArgString: + outargstring(arg); + break; - default: - NOTREACHED(); - UNREACHABLE_CODE; + case ArgFormal: + case ArgExpr: + outargtype(arg->ar_type); + if (arg->ar_type->tp_fund == FUNCTION) + { + /* UGLY PATCH !!! ??? */ + /* function names as operands are sometimes + FUNCTION and sometimes POINTER to FUNCTION, + depending on opaque circumstances. E.g., in + f(main, main); + the first main is PtF and the second is F. + */ + printf("*"); + } + break; + + case ArgEllipsis: + printf("."); /* one is enough for computers */ + break; + + default: + NOTREACHED(); + UNREACHABLE_CODE; } } -static -outargstring(arg) - struct argument *arg; +static outargstring(arg) struct argument* arg; { char buff[1000]; - char *p; + char* p; bts2str(arg->CAS_VALUE, arg->CAS_LEN, buff); - for (p = &buff[0]; *p; p++) { + for (p = &buff[0]; *p; p++) + { if (*p == '"' || *p == ':') *p = ' '; } printf("\"%s\"", buff); } -static -outargtype(tp) - struct type *tp; +static outargtype(tp) struct type* tp; { - switch (tp->tp_fund) { - case POINTER: - outargtype(tp->tp_up); - printf("*"); - break; - - case ARRAY: - outargtype(tp->tp_up); - printf("*"); /* compatible with [] */ - break; - - case FUNCTION: - outargtype(tp->tp_up); - printf("()"); - break; - - case STRUCT: - case UNION: - case ENUM: - /* watch out for anonymous identifiers; the count field does - not have to be the same for all compilation units. - Remove it, so that pass 2 does not see it. The only - problem with this is that pass2 will not see a difference - between two non-tagged types declared on the same line. - */ - printf("%s ", symbol2str(tp->tp_fund)); - if (is_anon_idf(tp->tp_idf)) { - /* skip the #, replace it by '#anonymous id' */ - printf("#anonymous id%s", - strchr(tp->tp_idf->id_text, ' ') - ); - } - else { - printf(tp->tp_idf->id_text); - } - break; - - case CHAR: - case INT: - case SHORT: - case LONG: - case ULONG: - case FLOAT: - case DOUBLE: - case LNGDBL: - case VOID: - case ERRONEOUS: - if (tp->tp_unsigned) { - printf("unsigned "); - } - printf("%s", symbol2str(tp->tp_fund)); - break; - default: - NOTREACHED(); - UNREACHABLE_CODE; + switch (tp->tp_fund) + { + case POINTER: + outargtype(tp->tp_up); + printf("*"); + break; + + case ARRAY: + outargtype(tp->tp_up); + printf("*"); /* compatible with [] */ + break; + + case FUNCTION: + outargtype(tp->tp_up); + printf("()"); + break; + + case STRUCT: + case UNION: + case ENUM: + /* watch out for anonymous identifiers; the count field does + not have to be the same for all compilation units. + Remove it, so that pass 2 does not see it. The only + problem with this is that pass2 will not see a difference + between two non-tagged types declared on the same line. + */ + printf("%s ", symbol2str(tp->tp_fund)); + if (is_anon_idf(tp->tp_idf)) + { + /* skip the #, replace it by '#anonymous id' */ + printf("#anonymous id%s", strchr(tp->tp_idf->id_text, ' ')); + } + else + { + printf(tp->tp_idf->id_text); + } + break; + + case CHAR: + case INT: + case SHORT: + case LONG: + case ULONG: + case FLOAT: + case DOUBLE: + case LNGDBL: + case VOID: + case ERRONEOUS: + if (tp->tp_unsigned) + { + printf("unsigned "); + } + printf("%s", symbol2str(tp->tp_fund)); + break; + default: + NOTREACHED(); + UNREACHABLE_CODE; } } -#ifdef IMPLICIT -static -implicit_func_decl(idf, file, line) - struct idf *idf; - char *file; - unsigned int line; +#ifdef IMPLICIT +static implicit_func_decl(idf, file, line) struct idf* idf; +char* file; +unsigned int line; { struct outdef od; @@ -536,21 +537,21 @@ implicit_func_decl(idf, file, line) output_def(&od); /* The other fields are not used for this class. */ } -#endif /* IMPLICIT */ +#endif /* IMPLICIT */ -fill_outcall(ex, used) - struct expr *ex; - int used; +fill_outcall(ex, used) struct expr* ex; +int used; { - struct idf *idf = ex->OP_LEFT->VL_IDF; - struct def *def = idf->id_def; + struct idf* idf = ex->OP_LEFT->VL_IDF; + struct def* def = idf->id_def; -#ifdef IMPLICIT - if (def->df_sc == IMPLICIT && !idf->id_def->df_used) { +#ifdef IMPLICIT + if (def->df_sc == IMPLICIT && !idf->id_def->df_used) + { /* IFDC, first time */ implicit_func_decl(idf, ex->ex_file, ex->ex_line); } -#endif /* IMPLICIT */ +#endif /* IMPLICIT */ OutCall.od_type = def->df_type->tp_up; OutCall.od_statnr = (def->df_sc == STATIC ? stat_number : 0); @@ -558,56 +559,59 @@ fill_outcall(ex, used) OutCall.od_name = idf->id_text; OutCall.od_file = ex->ex_file; OutCall.od_line = ex->ex_line; - OutCall.od_arg = (struct argument *)0; + OutCall.od_arg = (struct argument*)0; OutCall.od_nrargs = 0; - if ((ex = ex->OP_RIGHT) != 0) { + if ((ex = ex->OP_RIGHT) != 0) + { /* function call with arguments: */ /* store types of argument expressions in 'struct argument's */ - while (ex->ex_class == Oper && ex->OP_OPER == PARCOMMA) { + while (ex->ex_class == Oper && ex->OP_OPER == PARCOMMA) + { add_expr_arg(ex->OP_RIGHT); ex = ex->OP_LEFT; } add_expr_arg(ex); } - OutCall.od_valused = used; /* USED, IGNORED or VOIDED */ + OutCall.od_valused = used; /* USED, IGNORED or VOIDED */ } -static -add_expr_arg(e) - struct expr *e; +static add_expr_arg(e) struct expr* e; { - struct argument *arg; + struct argument* arg; arg = new_argument(); arg->ar_type = e->ex_type; - if (is_cp_cst(e)) { + if (is_cp_cst(e)) + { arg->ar_class = ArgConst; arg->CAA_VALUE = e->VL_VALUE; } - else if ( e->ex_type == string_type - && e->ex_class == Value - && e->VL_CLASS == Label - ) { + else if (e->ex_type == string_type && e->ex_class == Value && e->VL_CLASS == Label) + { /* it may be a string; let's look it up */ - struct string_cst *sc = str_list; + struct string_cst* sc = str_list; - while (sc) { + while (sc) + { if (sc->sc_dlb == e->VL_LBL) break; sc = sc->next; } - if (sc) { + if (sc) + { /* it was a string */ arg->ar_class = ArgString; arg->CAS_VALUE = sc->sc_value; - arg->CAS_LEN = sc->sc_len - 1; /* included the \0 */ + arg->CAS_LEN = sc->sc_len - 1; /* included the \0 */ } - else { + else + { arg->ar_class = ArgExpr; } } - else { + else + { arg->ar_class = ArgExpr; } arg->next = OutCall.od_arg; @@ -615,4 +619,4 @@ add_expr_arg(e) OutCall.od_nrargs++; } -#endif /* LINT */ +#endif /* LINT */ diff --git a/lang/cem/cemcom.ansi/l_outdef.str b/lang/cem/cemcom.ansi/l_outdef.str index d7494ddad3..67e4ab8cd1 100644 --- a/lang/cem/cemcom.ansi/l_outdef.str +++ b/lang/cem/cemcom.ansi/l_outdef.str @@ -6,43 +6,47 @@ /* Lint output definition */ /* Values for ar_class */ -#define ArgFormal 0 -#define ArgExpr 1 /* actual */ -#define ArgConst 2 /* integer constant */ -#define ArgString 3 /* string */ -#define ArgEllipsis 4 /* ellipsis */ +#define ArgFormal 0 +#define ArgExpr 1 /* actual */ +#define ArgConst 2 /* integer constant */ +#define ArgString 3 /* string */ +#define ArgEllipsis 4 /* ellipsis */ -struct argument { - struct argument *next; - struct type *ar_type; - int ar_class; /* for constant parameters */ - union const_arg { +struct argument +{ + struct argument* next; + struct type* ar_type; + int ar_class; /* for constant parameters */ + union const_arg + { arith ca_value; - struct { - char *cas_value; + struct + { + char* cas_value; int cas_len; } ca_string; } ar_object; }; -#define CAA_VALUE ar_object.ca_value -#define CAS_VALUE ar_object.ca_string.cas_value -#define CAS_LEN ar_object.ca_string.cas_len +#define CAA_VALUE ar_object.ca_value +#define CAS_VALUE ar_object.ca_string.cas_value +#define CAS_LEN ar_object.ca_string.cas_len /* ALLOCDEF "argument" 10 */ -struct outdef { +struct outdef +{ char od_class; int od_statnr; - char *od_name; - char *od_file; + char* od_name; + char* od_file; unsigned int od_line; int od_nrargs; - struct argument *od_arg; /* a list of the types of the - * formal parameters */ + struct argument* od_arg; /* a list of the types of the + * formal parameters */ int od_valreturned; - /* NOVALRETURNED, VALRETURNED, NORETURN; see l_lint.h */ + /* NOVALRETURNED, VALRETURNED, NORETURN; see l_lint.h */ int od_valused; - /* USED, IGNORED, SET, VOIDED; see l_lint.h */ - struct type *od_type; + /* USED, IGNORED, SET, VOIDED; see l_lint.h */ + struct type* od_type; }; diff --git a/lang/cem/cemcom.ansi/l_state.str b/lang/cem/cemcom.ansi/l_state.str index 610e74d963..0ab447825e 100644 --- a/lang/cem/cemcom.ansi/l_state.str +++ b/lang/cem/cemcom.ansi/l_state.str @@ -12,66 +12,72 @@ * control of the program. */ -#define TEST_VAR 0 /* not a constant */ -#define TEST_TRUE 1 /* always true */ -#define TEST_FALSE 2 /* always false */ +#define TEST_VAR 0 /* not a constant */ +#define TEST_TRUE 1 /* always true */ +#define TEST_FALSE 2 /* always false */ -struct loop_state { /* used in lint_end_state only */ - int lps_test; /* is the test a constant? */ - struct state *lps_body; - struct state *lps_loop; +struct loop_state +{ /* used in lint_end_state only */ + int lps_test; /* is the test a constant? */ + struct state* lps_body; + struct state* lps_loop; }; -struct switch_state { /* used in lint_end_state only */ - struct state *sws_case; - struct state *sws_break; +struct switch_state +{ /* used in lint_end_state only */ + struct state* sws_case; + struct state* sws_break; int sws_default_met; }; /* This union describes the (possibly incomplete) state at the end of the - mentioned construct. + mentioned construct. */ -union lint_end_state { /* used in lint_stack_entry only */ - struct state *ule_if; +union lint_end_state +{ /* used in lint_stack_entry only */ + struct state* ule_if; struct loop_state ule_loop; struct switch_state ule_switch; }; -struct lint_stack_entry { - struct lint_stack_entry *next; - struct lint_stack_entry *ls_previous; +struct lint_stack_entry +{ + struct lint_stack_entry* next; + struct lint_stack_entry* ls_previous; int ls_level; - struct state *ls_current; /* used by all classes */ - short ls_class; /* IF, WHILE, DO, FOR, SWITCH, CASE */ + struct state* ls_current; /* used by all classes */ + short ls_class; /* IF, WHILE, DO, FOR, SWITCH, CASE */ union lint_end_state ls_end; }; /* ALLOCDEF "lint_stack_entry" 10 */ /* macros to access the union */ -#define LS_IF ls_end.ule_if -#define LS_TEST ls_end.ule_loop.lps_test -#define LS_BODY ls_end.ule_loop.lps_body -#define LS_LOOP ls_end.ule_loop.lps_loop -#define LS_CASE ls_end.ule_switch.sws_case -#define LS_BREAK ls_end.ule_switch.sws_break -#define LS_DEFAULT_MET ls_end.ule_switch.sws_default_met +#define LS_IF ls_end.ule_if +#define LS_TEST ls_end.ule_loop.lps_test +#define LS_BODY ls_end.ule_loop.lps_body +#define LS_LOOP ls_end.ule_loop.lps_loop +#define LS_CASE ls_end.ule_switch.sws_case +#define LS_BREAK ls_end.ule_switch.sws_break +#define LS_DEFAULT_MET ls_end.ule_switch.sws_default_met /* describes a branch in the program, with its local idfs */ -struct state { - struct state *next; /* only used by memory allocator */ - struct auto_def *st_auto_list; - int st_notreached; /* set if not reached */ - int st_warned; /* set if warning issued */ +struct state +{ + struct state* next; /* only used by memory allocator */ + struct auto_def* st_auto_list; + int st_notreached; /* set if not reached */ + int st_warned; /* set if warning issued */ }; /* ALLOCDEF "state" 15 */ /* describes the state of a local idf in a given branch of the program */ -struct auto_def { - struct auto_def *next; - struct idf *ad_idf; - struct def *ad_def; +struct auto_def +{ + struct auto_def* next; + struct idf* ad_idf; + struct def* ad_def; int ad_used; int ad_set; int ad_maybe_set; @@ -80,14 +86,14 @@ struct auto_def { /* ALLOCDEF "auto_def" 20 */ /* describes the state of an idf during expression evaluation */ -struct expr_state { /*actually concerns idfs only */ - struct expr_state *next; - struct idf *es_idf; /* the idf with its offset */ +struct expr_state +{ /*actually concerns idfs only */ + struct expr_state* next; + struct idf* es_idf; /* the idf with its offset */ arith es_offset; - int es_used; /* value has been used */ - int es_referred; /* address has been taken */ - int es_set; /* has been assigned to */ + int es_used; /* value has been used */ + int es_referred; /* address has been taken */ + int es_set; /* has been assigned to */ }; /* ALLOCDEF "expr_state" 20 */ - diff --git a/lang/cem/cemcom.ansi/l_states.c b/lang/cem/cemcom.ansi/l_states.c index c4b2ff9d2d..df1d532b6e 100644 --- a/lang/cem/cemcom.ansi/l_states.c +++ b/lang/cem/cemcom.ansi/l_states.c @@ -5,54 +5,55 @@ /* $Id$ */ /* Lint status checking */ -#include "parameters.h" +#include "parameters.h" +#include +#include -#ifdef LINT +#ifdef LINT -#include -#include /* for st_free */ -#include "interface.h" +#include +#include /* for st_free */ +#include "interface.h" #ifdef ANSI -#include +#include #endif /* ANSI */ -#include "arith.h" -#include "label.h" -#include "expr.h" -#include "def.h" -#include "code.h" /* RVAL etc */ -#include "LLlex.h" -#include "Lpars.h" -#include "stack.h" -#include "type.h" -#include "level.h" -#include "l_lint.h" -#include "l_brace.h" -#include "l_state.h" -#include "l_comment.h" -#include "l_outdef.h" - -#ifdef DEBUG -#define dbg_lint_stack(m) /*print_lint_stack(m) /* or not */ +#include "arith.h" +#include "label.h" +#include "expr.h" +#include "def.h" +#include "code.h" /* RVAL etc */ +#include "LLlex.h" +#include "Lpars.h" +#include "stack.h" +#include "type.h" +#include "level.h" +#include "l_lint.h" +#include "l_brace.h" +#include "l_state.h" +#include "l_comment.h" +#include "l_outdef.h" + +#ifdef DEBUG +#define dbg_lint_stack(m) /*print_lint_stack(m) /* or not */ #else -#define dbg_lint_stack(m) -#endif /* DEBUG */ +#define dbg_lint_stack(m) +#endif /* DEBUG */ - -extern char *func_name; -extern struct type *func_type; +extern char* func_name; +extern struct type* func_type; extern int func_notypegiven; extern char loptions[]; -extern struct stack_level *local_level; +extern struct stack_level* local_level; /* global variables for the lint_stack */ -static struct lint_stack_entry *top_ls; +static struct lint_stack_entry* top_ls; /* global variables for the brace stack */ static int brace_count; -static struct brace *top_br; +static struct brace* top_br; /* global variables for the function return */ -static int valreturned; /* see l_lint.h */ +static int valreturned; /* see l_lint.h */ static int return_warned; static end_brace(); @@ -60,31 +61,31 @@ static lint_1_local(); static lint_1_global(); static start_loop_stmt(); static check_autos(); -static struct auto_def *copy_auto_list(); +static struct auto_def* copy_auto_list(); static free_auto_list(); -static struct state *copy_state(); +static struct state* copy_state(); static Free_state(); static remove_settings(); -static struct auto_def *merge_autos(); +static struct auto_def* merge_autos(); static merge_states(); static struct lint_stack_entry *find_wdf(), *find_wdfc(), *find_cs(); static cont_merge(); static break_merge(); -static struct lint_stack_entry *mk_lint_stack_entry(); +static struct lint_stack_entry* mk_lint_stack_entry(); static lint_push(); static lint_pop(); lint_init_stack() { -/* Allocate memory for the global lint-stack elements. -*/ + /* Allocate memory for the global lint-stack elements. + */ top_ls = new_lint_stack_entry(); top_ls->ls_current = new_state(); } lint_start_local() { - struct brace *br = new_brace(); + struct brace* br = new_brace(); dbg_lint_stack("lint_start_local"); brace_count++; @@ -92,20 +93,21 @@ lint_start_local() br->br_level = level; br->next = top_br; top_br = br; -} +} -lint_end_local(stl) - struct stack_level *stl; +lint_end_local(stl) struct stack_level* stl; { dbg_lint_stack("lint_end_local"); - if (s_NOTREACHED) { + if (s_NOTREACHED) + { top_ls->ls_current->st_notreached = 1; top_ls->ls_current->st_warned = 0; s_NOTREACHED = 0; } - if (top_ls->ls_class == CASE && level == top_ls->ls_level) { + if (top_ls->ls_class == CASE && level == top_ls->ls_level) + { /* supply missing break; at end of switch */ lint_break_stmt(); } @@ -114,23 +116,24 @@ lint_end_local(stl) end_brace(stl); } -static -end_brace(stl) - struct stack_level *stl; +static end_brace(stl) struct stack_level* stl; { /* Check if static variables and labels are used and/or set. - Automatic vars have already been checked by check_autos(). + Automatic vars have already been checked by check_autos(). */ - struct stack_entry *se = stl->sl_entry; - struct brace *br; + struct stack_entry* se = stl->sl_entry; + struct brace* br; - while (se) { - struct idf *idf = se->se_idf; + while (se) + { + struct idf* idf = se->se_idf; - if (idf->id_def) { + if (idf->id_def) + { lint_1_local(idf, idf->id_def); } - if (stl->sl_level == L_LOCAL && idf->id_label) { + if (stl->sl_level == L_LOCAL && idf->id_label) + { lint_1_local(idf, idf->id_label); } se = se->next; @@ -142,162 +145,155 @@ end_brace(stl) free_brace(br); } -static -lint_1_local(idf, def) - struct idf *idf; - struct def *def; +static lint_1_local(idf, def) struct idf* idf; +struct def* def; { int sc = def->df_sc; - if ( (sc == STATIC || sc == LABEL) - && !def->df_used - && !is_anon_idf(idf) - ) { - def_warning(def, "%s %s not applied anywhere in function %s", - symbol2str(sc), idf->id_text, func_name); + if ((sc == STATIC || sc == LABEL) && !def->df_used && !is_anon_idf(idf)) + { + def_warning( + def, "%s %s not applied anywhere in function %s", symbol2str(sc), idf->id_text, + func_name); } - if ( loptions['h'] - && sc == AUTO - && !def->df_initialized - && def->df_firstbrace != 0 - && def->df_minlevel != level - && !is_anon_idf(idf) - ) { + if (loptions['h'] && sc == AUTO && !def->df_initialized && def->df_firstbrace != 0 + && def->df_minlevel != level && !is_anon_idf(idf)) + { int diff = def->df_minlevel - level; - def_warning(def, - "local %s could be declared %d level%s deeper", - idf->id_text, diff, (diff == 1 ? "" : "s") - ); + def_warning( + def, "local %s could be declared %d level%s deeper", idf->id_text, diff, + (diff == 1 ? "" : "s")); } } -lint_end_global(stl) - struct stack_level *stl; +lint_end_global(stl) struct stack_level* stl; { - struct stack_entry *se = stl->sl_entry; + struct stack_entry* se = stl->sl_entry; dbg_lint_stack("lint_end_global"); assert(level == L_GLOBAL); - while (se) { - struct idf *idf = se->se_idf; - struct def *def = idf->id_def; + while (se) + { + struct idf* idf = se->se_idf; + struct def* def = idf->id_def; - if (def) { + if (def) + { lint_1_global(idf, def); } se = se->next; } } -static -lint_1_global(idf, def) - struct idf *idf; - struct def *def; +static lint_1_global(idf, def) struct idf* idf; +struct def* def; { int sc = def->df_sc; - struct type *tp = def->df_type; + struct type* tp = def->df_type; int fund = tp->tp_fund; - switch (sc) { - case STATIC: - case EXTERN: - case GLOBAL: -#ifdef IMPLICIT - case IMPLICIT: -#endif /* IMPLICIT */ - if (fund == ERRONEOUS) - break; - - if (fund == FUNCTION && sc != STATIC) { - output_proto(idf, def); - } + switch (sc) + { + case STATIC: + case EXTERN: + case GLOBAL: +#ifdef IMPLICIT + case IMPLICIT: +#endif /* IMPLICIT */ + if (fund == ERRONEOUS) + break; + + if (fund == FUNCTION && sc != STATIC) + { + output_proto(idf, def); + } - if (def->df_set || def->df_used) { - /* Output a line to the intermediate file for - * used external variables (including functions) - */ - output_use(idf); - } + if (def->df_set || def->df_used) + { + /* Output a line to the intermediate file for + * used external variables (including functions) + */ + output_use(idf); + } - if (sc == STATIC && !def->df_used) { - if (def->df_set) { - if (!is_anon_idf(idf) && fund != ERRONEOUS) { - def_warning(def, - "%s %s %s set but not used", - symbol2str(sc), - symbol2str(fund), - idf->id_text); + if (sc == STATIC && !def->df_used) + { + if (def->df_set) + { + if (!is_anon_idf(idf) && fund != ERRONEOUS) + { + def_warning( + def, "%s %s %s set but not used", symbol2str(sc), symbol2str(fund), + idf->id_text); + } } - } - else { - if (!is_anon_idf(idf) && fund != ERRONEOUS) { - def_warning(def, - "%s %s %s not used anywhere", - symbol2str(sc), - symbol2str(fund), - idf->id_text); + else + { + if (!is_anon_idf(idf) && fund != ERRONEOUS) + { + def_warning( + def, "%s %s %s not used anywhere", symbol2str(sc), symbol2str(fund), + idf->id_text); + } } } - } - if (loptions['x']) { - char *fn = def->df_file; - - if ( (sc == EXTERN || sc == GLOBAL) - && def->df_alloc == 0 - && !def->df_set - && !def->df_initialized - && !def->df_used - && strcmp(&fn[strlen(fn)-2], ".c") == 0 - && !is_anon_idf(idf) - && fund != ERRONEOUS - ) { - def_warning(def, - "%s %s %s not used anywhere", - symbol2str(sc), - symbol2str(fund), - idf->id_text); + if (loptions['x']) + { + char* fn = def->df_file; + + if ((sc == EXTERN || sc == GLOBAL) && def->df_alloc == 0 && !def->df_set + && !def->df_initialized && !def->df_used + && strcmp(&fn[strlen(fn) - 2], ".c") == 0 && !is_anon_idf(idf) + && fund != ERRONEOUS) + { + def_warning( + def, "%s %s %s not used anywhere", symbol2str(sc), symbol2str(fund), + idf->id_text); + } } - } - break; + break; } } -change_state(idf, to_state) - struct idf *idf; - int to_state; /* SET or USED */ +change_state(idf, to_state) struct idf* idf; +int to_state; /* SET or USED */ { -/* Changes the state of the variable identified by idf in the current state - * on top of the stack. - * The fields in the def-descriptor are set too. - */ - struct def *def = idf->id_def; - struct auto_def *a = top_ls->ls_current->st_auto_list; + /* Changes the state of the variable identified by idf in the current state + * on top of the stack. + * The fields in the def-descriptor are set too. + */ + struct def* def = idf->id_def; + struct auto_def* a = top_ls->ls_current->st_auto_list; assert(def); - switch (to_state) { - case SET: - def->df_set = 1; - break; - case USED: - def->df_used = 1; - break; + switch (to_state) + { + case SET: + def->df_set = 1; + break; + case USED: + def->df_used = 1; + break; } /* adjust minimum required brace level */ - if (def->df_firstbrace == 0) { + if (def->df_firstbrace == 0) + { def->df_firstbrace = brace_count; def->df_minlevel = level; } - else { - struct brace *br = top_br; + else + { + struct brace* br = top_br; /* find the smallest brace range from which - firstbrace is visible + firstbrace is visible */ - while (br && br->br_count > def->df_firstbrace) { + while (br && br->br_count > def->df_firstbrace) + { br = br->next; } assert(br && def->df_minlevel >= br->br_level); @@ -305,90 +301,92 @@ change_state(idf, to_state) } /* search auto_list */ - while(a && a->ad_idf != idf) + while (a && a->ad_idf != idf) a = a->next; - if (a == 0) /* identifier not in list, global definition */ + if (a == 0) /* identifier not in list, global definition */ return; - switch (to_state) { - case SET: - a->ad_maybe_set = 0; - a->ad_set = 1; - break; - case USED: - if (!a->ad_set) { - if (!is_anon_idf(idf)) { - warning("variable %s%s uninitialized", - idf->id_text, - (a->ad_maybe_set ? " possibly" : "") - ); - } + switch (to_state) + { + case SET: a->ad_maybe_set = 0; - a->ad_set = 1; /* one warning */ - } - a->ad_used = 1; - break; + a->ad_set = 1; + break; + case USED: + if (!a->ad_set) + { + if (!is_anon_idf(idf)) + { + warning( + "variable %s%s uninitialized", idf->id_text, + (a->ad_maybe_set ? " possibly" : "")); + } + a->ad_maybe_set = 0; + a->ad_set = 1; /* one warning */ + } + a->ad_used = 1; + break; } } -add_auto(idf) /* to current state on top of lint_stack */ - struct idf *idf; +add_auto(idf) /* to current state on top of lint_stack */ + struct idf* idf; { -/* Check if idf's definition is really an auto (or register). - * It could be a static or extern too. - * Watch out for formal parameters. - */ - struct def *def = idf->id_def; + /* Check if idf's definition is really an auto (or register). + * It could be a static or extern too. + * Watch out for formal parameters. + */ + struct def* def = idf->id_def; assert(def); - switch (def->df_sc) { - struct auto_def *a; - case AUTO: - case REGISTER: - if (def->df_level < L_LOCAL) - return; /* a formal */ + switch (def->df_sc) + { + struct auto_def* a; + case AUTO: + case REGISTER: + if (def->df_level < L_LOCAL) + return; /* a formal */ - a = new_auto_def(); + a = new_auto_def(); - a->ad_idf = idf; - a->ad_def = def; - a->ad_used = def->df_used; - a->ad_set = def->df_set; + a->ad_idf = idf; + a->ad_def = def; + a->ad_used = def->df_used; + a->ad_set = def->df_set; - a->next = top_ls->ls_current->st_auto_list; - top_ls->ls_current->st_auto_list = a; + a->next = top_ls->ls_current->st_auto_list; + top_ls->ls_current->st_auto_list = a; } } -static -check_autos() +static check_autos() { -/* Before leaving a block, remove the auto_defs of the automatic - * variables on this level and check if they are used - */ - struct auto_def *a = top_ls->ls_current->st_auto_list; + /* Before leaving a block, remove the auto_defs of the automatic + * variables on this level and check if they are used + */ + struct auto_def* a = top_ls->ls_current->st_auto_list; assert(!(a && a->ad_def->df_level > level)); - while (a && a->ad_def->df_level == level) { - struct idf *idf = a->ad_idf; - struct def *def = idf->id_def; - - if (!def->df_used && !is_anon_idf(idf)) { - if (def->df_set || a->ad_maybe_set) { - def_warning(def, - "%s set but not used in function %s", - idf->id_text, func_name); + while (a && a->ad_def->df_level == level) + { + struct idf* idf = a->ad_idf; + struct def* def = idf->id_def; + + if (!def->df_used && !is_anon_idf(idf)) + { + if (def->df_set || a->ad_maybe_set) + { + def_warning(def, "%s set but not used in function %s", idf->id_text, func_name); } - else { - def_warning(def, - "%s not used anywhere in function %s", - idf->id_text, func_name); + else + { + def_warning(def, "%s not used anywhere in function %s", idf->id_text, func_name); } } - { /* free a */ - struct auto_def *aux = a; + { /* free a */ + struct auto_def* aux = a; a = a->next; free_auto_def(aux); } @@ -398,39 +396,38 @@ check_autos() lint_end_formals() { - struct stack_entry *se = local_level->sl_entry; + struct stack_entry* se = local_level->sl_entry; dbg_lint_stack("lint_end_formals"); assert(level == L_FORMAL1); - while (se) { - struct def *def = se->se_idf->id_def; - - if ( (def && !def->df_used) - && !(f_ARGSUSED || LINTLIB) - && !is_anon_idf(se->se_idf) - ) { - def_warning(def, "argument %s not used in function %s", - se->se_idf->id_text, func_name); + while (se) + { + struct def* def = se->se_idf->id_def; + + if ((def && !def->df_used) && !(f_ARGSUSED || LINTLIB) && !is_anon_idf(se->se_idf)) + { + def_warning(def, "argument %s not used in function %s", se->se_idf->id_text, func_name); } se = se->next; } } -static struct auto_def * -copy_auto_list(from_al, lvl) - struct auto_def *from_al; - int lvl; +static struct auto_def* copy_auto_list(from_al, lvl) +struct auto_def* from_al; +int lvl; { - struct auto_def *start = 0; - struct auto_def **hook = &start; + struct auto_def* start = 0; + struct auto_def** hook = &start; /* skip too high levels */ - while (from_al && from_al->ad_def->df_level > lvl) { + while (from_al && from_al->ad_def->df_level > lvl) + { from_al = from_al->next; } - while (from_al) { - struct auto_def *a = new_auto_def(); + while (from_al) + { + struct auto_def* a = new_auto_def(); *hook = a; *a = *from_al; @@ -441,26 +438,24 @@ copy_auto_list(from_al, lvl) return start; } -static -free_auto_list(a) - struct auto_def *a; +static free_auto_list(a) struct auto_def* a; { - while (a) { - struct auto_def *aux = a; + while (a) + { + struct auto_def* aux = a; a = a->next; free_auto_def(aux); } } -static struct state * -copy_state(from_st, lvl) - struct state *from_st; - int lvl; +static struct state* copy_state(from_st, lvl) +struct state* from_st; +int lvl; { -/* Memory for the struct state and the struct auto_defs is allocated - * by this function - */ - struct state *st = new_state(); + /* Memory for the struct state and the struct auto_defs is allocated + * by this function + */ + struct state* st = new_state(); st->st_auto_list = copy_auto_list(from_st->st_auto_list, lvl); st->st_notreached = from_st->st_notreached; @@ -468,119 +463,113 @@ copy_state(from_st, lvl) return st; } -static -Free_state(stp) - struct state **stp; +static Free_state(stp) struct state** stp; { -/* This function also frees the list of auto_defs - */ + /* This function also frees the list of auto_defs + */ free_auto_list((*stp)->st_auto_list); free_state(*stp); *stp = 0; } -static -remove_settings(st, lvl) - struct state *st; - int lvl; +static remove_settings(st, lvl) struct state* st; +int lvl; { -/* The states of all variables on this level are set to 'not set' and - * 'not maybe set'. (I think you have to read this twice.) - */ - struct auto_def *a = st->st_auto_list; + /* The states of all variables on this level are set to 'not set' and + * 'not maybe set'. (I think you have to read this twice.) + */ + struct auto_def* a = st->st_auto_list; - while (a && a->ad_def->df_level == lvl) { + while (a && a->ad_def->df_level == lvl) + { a->ad_set = a->ad_maybe_set = 0; a = a->next; } } - /******** M E R G E ********/ /* modes for merging */ -#define NORMAL 0 -#define CASE_BREAK 1 -#define USE_ONLY 2 - -static -merge_states(st1, st2, lvl, mode) - struct state *st1, *st2; - int lvl; - int mode; /* NORMAL or CASE_BREAK */ +#define NORMAL 0 +#define CASE_BREAK 1 +#define USE_ONLY 2 + +static merge_states(st1, st2, lvl, mode) struct state* st1, *st2; +int lvl; +int mode; /* NORMAL or CASE_BREAK */ { -/* st2 becomes the result. - * st1 is left unchanged. - * The resulting state is the state the program gets in if st1 OR st2 - * becomes the state. (E.g. the states at the end of an if-part and an - * end-part are merged by this function.) - */ - if (st1->st_notreached) { - if (mode == NORMAL || st2->st_notreached) { - st2->st_auto_list = - merge_autos(st1->st_auto_list, - st2->st_auto_list, lvl, USE_ONLY); + /* st2 becomes the result. + * st1 is left unchanged. + * The resulting state is the state the program gets in if st1 OR st2 + * becomes the state. (E.g. the states at the end of an if-part and an + * end-part are merged by this function.) + */ + if (st1->st_notreached) + { + if (mode == NORMAL || st2->st_notreached) + { + st2->st_auto_list = merge_autos(st1->st_auto_list, st2->st_auto_list, lvl, USE_ONLY); } } - else - if (st2->st_notreached) { - struct auto_def *tmp = st2->st_auto_list; + else if (st2->st_notreached) + { + struct auto_def* tmp = st2->st_auto_list; st2->st_auto_list = copy_auto_list(st1->st_auto_list, lvl); st2->st_notreached = 0; st2->st_warned = 0; - st2->st_auto_list = merge_autos(tmp, st2->st_auto_list, - lvl, USE_ONLY); + st2->st_auto_list = merge_autos(tmp, st2->st_auto_list, lvl, USE_ONLY); free_auto_list(tmp); } - else { + else + { /* both st1 and st2 reached */ - st2->st_auto_list = - merge_autos(st1->st_auto_list, st2->st_auto_list, - lvl, mode); + st2->st_auto_list = merge_autos(st1->st_auto_list, st2->st_auto_list, lvl, mode); } } -static struct auto_def * -merge_autos(a1, a2, lvl, mode) - struct auto_def *a1, *a2; - int lvl; - int mode; +static struct auto_def* merge_autos(a1, a2, lvl, mode) +struct auto_def *a1, *a2; +int lvl; +int mode; { -/* Returns a pointer to the result. - * a1 is left unchanged. - * a2 is used to create this result. - * The fields are set as follows: - * a1_set + a2_set -> set - * + a?_maybe_set -> maybe set - * ELSE -> NOT set && NOT maybe set - * * + a?_used -> used - * - * For mode == CASE_BREAK: - * First a2 is taken as the result, then - * variables NOT set in a2 and set or maybe set in a1 become 'maybe set' - * - * For mode == USE_ONLY: - * Start with a2 as the result. - * Variables used in a1 become used in a2. - * The rest of the result is not changed. - */ - struct auto_def *a; + /* Returns a pointer to the result. + * a1 is left unchanged. + * a2 is used to create this result. + * The fields are set as follows: + * a1_set + a2_set -> set + * + a?_maybe_set -> maybe set + * ELSE -> NOT set && NOT maybe set + * * + a?_used -> used + * + * For mode == CASE_BREAK: + * First a2 is taken as the result, then + * variables NOT set in a2 and set or maybe set in a1 become 'maybe set' + * + * For mode == USE_ONLY: + * Start with a2 as the result. + * Variables used in a1 become used in a2. + * The rest of the result is not changed. + */ + struct auto_def* a; /* skip too local entries */ - while (a1 && a1->ad_def->df_level > lvl) { + while (a1 && a1->ad_def->df_level > lvl) + { a1 = a1->next; } /* discard too local entries */ - while (a2 && a2->ad_def->df_level > lvl) { - struct auto_def *aux = a2; + while (a2 && a2->ad_def->df_level > lvl) + { + struct auto_def* aux = a2; a2 = a2->next; free_auto_def(aux); } - a = a2; /* pointer to the result */ - while (a1) { + a = a2; /* pointer to the result */ + while (a1) + { assert(a2); /* merge the auto_defs for one idf */ @@ -588,15 +577,11 @@ merge_autos(a1, a2, lvl, mode) if (a1->ad_used) a2->ad_used = 1; - if (mode != USE_ONLY) { - if ( ( !a2->ad_set - && (a1->ad_set || a1->ad_maybe_set) - ) - || ( mode == NORMAL - && !a1->ad_set - && (a2->ad_set || a2->ad_maybe_set) - ) - ) { + if (mode != USE_ONLY) + { + if ((!a2->ad_set && (a1->ad_set || a1->ad_maybe_set)) + || (mode == NORMAL && !a1->ad_set && (a2->ad_set || a2->ad_maybe_set))) + { a2->ad_set = 0; a2->ad_maybe_set = 1; } @@ -609,58 +594,60 @@ merge_autos(a1, a2, lvl, mode) return a; } - /******** L I N T S T A C K S E A R C H I N G ********/ /* The next four find-functions search the lint_stack for an entry. * The letters mean : w: WHILE; d: DO; f: FOR; s: SWITCH; c: CASE. */ -static struct lint_stack_entry * -find_wdf() +static struct lint_stack_entry* find_wdf() { - struct lint_stack_entry *lse = top_ls; - - while (lse) { - switch (lse->ls_class) { - case WHILE: - case DO: - case FOR: - return lse; + struct lint_stack_entry* lse = top_ls; + + while (lse) + { + switch (lse->ls_class) + { + case WHILE: + case DO: + case FOR: + return lse; } lse = lse->ls_previous; } return 0; } -static struct lint_stack_entry * -find_wdfc() +static struct lint_stack_entry* find_wdfc() { - struct lint_stack_entry *lse = top_ls; - - while (lse) { - switch (lse->ls_class) { - case WHILE: - case DO: - case FOR: - case CASE: - return lse; + struct lint_stack_entry* lse = top_ls; + + while (lse) + { + switch (lse->ls_class) + { + case WHILE: + case DO: + case FOR: + case CASE: + return lse; } lse = lse->ls_previous; } return 0; } -static struct lint_stack_entry * -find_cs() +static struct lint_stack_entry* find_cs() { - struct lint_stack_entry *lse = top_ls; - - while (lse) { - switch (lse->ls_class) { - case CASE: - case SWITCH: - return lse; + struct lint_stack_entry* lse = top_ls; + + while (lse) + { + switch (lse->ls_class) + { + case CASE: + case SWITCH: + return lse; } lse = lse->ls_previous; } @@ -671,48 +658,47 @@ find_cs() start_if_part(cst) { - struct lint_stack_entry *new = mk_lint_stack_entry(IF); + struct lint_stack_entry* new = mk_lint_stack_entry(IF); dbg_lint_stack("start_if_part"); if (cst) hwarning("condition in if statement is constant"); lint_push(new); -/* ls_current: the state at the start of the if-part -*/ + /* ls_current: the state at the start of the if-part + */ } start_else_part() { -/* ls_current: the state at the end of the if-part - ls_previous->ls_current: the state before the if-part -*/ + /* ls_current: the state at the end of the if-part + ls_previous->ls_current: the state before the if-part + */ dbg_lint_stack("start_else_part"); - if (s_NOTREACHED) { + if (s_NOTREACHED) + { top_ls->ls_current->st_notreached = 1; top_ls->ls_current->st_warned = 0; s_NOTREACHED = 0; } top_ls->LS_IF = top_ls->ls_current; /* this is the reason why ls_current is a pointer */ - top_ls->ls_current = - copy_state(top_ls->ls_previous->ls_current, level); + top_ls->ls_current = copy_state(top_ls->ls_previous->ls_current, level); top_ls->ls_level = level; -/* ls_current: the state before the if-part and the else-part - LS_IF: the state at the end of the if-part -*/ + /* ls_current: the state before the if-part and the else-part + LS_IF: the state at the end of the if-part + */ } end_if_else_stmt() { -/* ls_current: state at the end of the else-part - LS_IF: state at the end of the if-part -*/ + /* ls_current: state at the end of the else-part + LS_IF: state at the end of the if-part + */ dbg_lint_stack("end_if_else_stmt"); - merge_states(top_ls->LS_IF, top_ls->ls_current, - top_ls->ls_level, NORMAL); + merge_states(top_ls->LS_IF, top_ls->ls_current, top_ls->ls_level, NORMAL); Free_state(&top_ls->LS_IF); Free_state(&top_ls->ls_previous->ls_current); top_ls->ls_previous->ls_current = top_ls->ls_current; @@ -721,26 +707,26 @@ end_if_else_stmt() end_if_stmt() { -/* No else-part met. - ls_current: state at the end of the if-part -*/ + /* No else-part met. + ls_current: state at the end of the if-part + */ dbg_lint_stack("end_if_stmt"); - merge_states(top_ls->ls_current, top_ls->ls_previous->ls_current, - top_ls->ls_level, NORMAL); + merge_states(top_ls->ls_current, top_ls->ls_previous->ls_current, top_ls->ls_level, NORMAL); Free_state(&top_ls->ls_current); lint_pop(); } /******** A C T I O N S : L O O P S ********/ -start_while_stmt(expr) - struct expr *expr; +start_while_stmt(expr) struct expr* expr; { - if (is_cp_cst(expr)) { + if (is_cp_cst(expr)) + { start_loop_stmt(WHILE, 1, expr->VL_VALUE != (arith)0); } - else { + else + { start_loop_stmt(WHILE, 0, 0); } } @@ -750,60 +736,62 @@ start_do_stmt() start_loop_stmt(DO, 1, 1); } -start_for_stmt(expr) - struct expr *expr; +start_for_stmt(expr) struct expr* expr; { - if (!expr) { + if (!expr) + { start_loop_stmt(FOR, 1, 1); } - else - if (is_cp_cst(expr)) { + else if (is_cp_cst(expr)) + { start_loop_stmt(FOR, 1, expr->VL_VALUE != (arith)0); } - else { + else + { start_loop_stmt(FOR, 0, 0); } } -static -start_loop_stmt(looptype, cst, cond) +static start_loop_stmt(looptype, cst, cond) { -/* If cst, the condition is a constant and its value is cond -*/ - struct lint_stack_entry *new = mk_lint_stack_entry(looptype); + /* If cst, the condition is a constant and its value is cond + */ + struct lint_stack_entry* new = mk_lint_stack_entry(looptype); dbg_lint_stack("start_loop_stmt"); - if (cst && !cond) { + if (cst && !cond) + { /* while (0) | for (;0;) */ - hwarning("condition in %s statement is always false", - symbol2str(looptype)); + hwarning("condition in %s statement is always false", symbol2str(looptype)); new->ls_current->st_notreached = 1; } - if (cst && cond) { + if (cst && cond) + { /* while (1) | for (;;) | do */ /* omitting the copy for LS_LOOP will force this loop - to be treated as a do loop + to be treated as a do loop */ top_ls->ls_current->st_notreached = 1; top_ls->ls_current->st_warned = 0; } - else { + else + { new->LS_LOOP = copy_state(top_ls->ls_current, level); } new->LS_TEST = (!cst ? TEST_VAR : cond ? TEST_TRUE : TEST_FALSE); lint_push(new); -/* ls_current: the state at the start of the body - LS_TEST: info about the loop test - LS_BODY: 0, the state at the end of the body - LS_LOOP: the state at the end of the loop, or 0 if the loop - does not end -*/ + /* ls_current: the state at the start of the body + LS_TEST: info about the loop test + LS_BODY: 0, the state at the end of the body + LS_LOOP: the state at the end of the loop, or 0 if the loop + does not end + */ } end_loop_body() { - struct lint_stack_entry *lse = find_wdf(); + struct lint_stack_entry* lse = find_wdf(); dbg_lint_stack("end_loop_body"); assert(lse == top_ls); @@ -813,7 +801,7 @@ end_loop_body() end_loop_stmt() { - struct lint_stack_entry *lse = find_wdf(); + struct lint_stack_entry* lse = find_wdf(); dbg_lint_stack("end_loop_stmt"); assert(lse == top_ls); @@ -821,12 +809,14 @@ end_loop_stmt() break_merge(lse); dbg_lint_stack("end_loop_stmt after break_merge"); - if (!top_ls->LS_LOOP) { + if (!top_ls->LS_LOOP) + { /* no break met; this is really an endless loop */ hwarning("endless %s loop", symbol2str(top_ls->ls_class)); Free_state(&top_ls->ls_current); } - else { + else + { Free_state(&top_ls->ls_current); Free_state(&top_ls->ls_previous->ls_current); top_ls->ls_previous->ls_current = top_ls->LS_LOOP; @@ -836,25 +826,25 @@ end_loop_stmt() end_do_stmt(cst, cond) { - struct lint_stack_entry *lse = find_wdf(); + struct lint_stack_entry* lse = find_wdf(); dbg_lint_stack("end_do_stmt"); - if (cst && !cond) { + if (cst && !cond) + { /* do ... while (0) */ hwarning("condition in do statement is always false"); } lse->LS_TEST = (!cst ? TEST_VAR : cond ? TEST_TRUE : TEST_FALSE); end_loop_stmt(); - } lint_continue_stmt() { - struct lint_stack_entry *lse = find_wdf(); + struct lint_stack_entry* lse = find_wdf(); dbg_lint_stack("lint_continue_stmt"); if (!lse) - return; /* not inside a loop statement */ + return; /* not inside a loop statement */ cont_merge(lse); top_ls->ls_current->st_notreached = 1; @@ -865,12 +855,12 @@ lint_continue_stmt() start_switch_part(cst) { -/* ls_current of a SWITCH entry has different meaning from ls_current of - * other entries. It keeps track of which variables are used in all - * following case parts. (Needed for variables declared in a compound - * switch-block.) - */ - struct lint_stack_entry *new = mk_lint_stack_entry(SWITCH); + /* ls_current of a SWITCH entry has different meaning from ls_current of + * other entries. It keeps track of which variables are used in all + * following case parts. (Needed for variables declared in a compound + * switch-block.) + */ + struct lint_stack_entry* new = mk_lint_stack_entry(SWITCH); dbg_lint_stack("start_switch_part"); if (cst) @@ -888,38 +878,42 @@ end_switch_stmt() { dbg_lint_stack("end_switch_stmt"); - if (top_ls->ls_class == CASE) { + if (top_ls->ls_class == CASE) + { /* no break after last case or default */ - lint_break_stmt(); /* introduce break */ + lint_break_stmt(); /* introduce break */ } - if (!top_ls->LS_DEFAULT_MET) { + if (!top_ls->LS_DEFAULT_MET) + { top_ls->ls_current->st_notreached = 0; - if (top_ls->LS_BREAK) { - merge_states(top_ls->ls_current, top_ls->LS_BREAK, - top_ls->ls_level, NORMAL); + if (top_ls->LS_BREAK) + { + merge_states(top_ls->ls_current, top_ls->LS_BREAK, top_ls->ls_level, NORMAL); Free_state(&top_ls->ls_current); } - else { + else + { top_ls->LS_BREAK = top_ls->ls_current; } } - else { + else + { Free_state(&top_ls->ls_current); } - if (top_ls->LS_BREAK) { - merge_states(top_ls->LS_CASE, top_ls->LS_BREAK, - top_ls->ls_level, CASE_BREAK); + if (top_ls->LS_BREAK) + { + merge_states(top_ls->LS_CASE, top_ls->LS_BREAK, top_ls->ls_level, CASE_BREAK); Free_state(&top_ls->LS_CASE); } - else { + else + { top_ls->LS_BREAK = top_ls->LS_CASE; } - top_ls->LS_BREAK->st_notreached = - top_ls->ls_previous->ls_current->st_notreached; - /* yack */ + top_ls->LS_BREAK->st_notreached = top_ls->ls_previous->ls_current->st_notreached; + /* yack */ Free_state(&top_ls->ls_previous->ls_current); if (!top_ls->LS_DEFAULT_MET) @@ -931,127 +925,132 @@ end_switch_stmt() lint_case_stmt(dflt) { -/* A default statement is just a special case statement */ - struct lint_stack_entry *cs_entry = find_cs(); + /* A default statement is just a special case statement */ + struct lint_stack_entry* cs_entry = find_cs(); dbg_lint_stack("lint_case_stmt"); if (!cs_entry) - return; /* not inside switch */ + return; /* not inside switch */ - if (cs_entry != top_ls) { - warning("%s statement in strange context", - dflt ? "default" : "case"); + if (cs_entry != top_ls) + { + warning("%s statement in strange context", dflt ? "default" : "case"); return; } - switch (cs_entry->ls_class) { - struct lint_stack_entry *new; + switch (cs_entry->ls_class) + { + struct lint_stack_entry* new; - case SWITCH: - if (dflt) { - cs_entry->LS_DEFAULT_MET = 1; - } + case SWITCH: + if (dflt) + { + cs_entry->LS_DEFAULT_MET = 1; + } - new = mk_lint_stack_entry(CASE); - remove_settings(new->ls_current, level); - lint_push(new); - break; + new = mk_lint_stack_entry(CASE); + remove_settings(new->ls_current, level); + lint_push(new); + break; - case CASE: - assert(top_ls->ls_previous->ls_class == SWITCH); - if (dflt) { - cs_entry->ls_previous->LS_DEFAULT_MET = 1; - } - merge_states(top_ls->ls_current, top_ls->ls_previous->LS_CASE, - top_ls->ls_previous->ls_level, NORMAL); - merge_states(top_ls->ls_current, - top_ls->ls_previous->ls_current, - top_ls->ls_previous->ls_level, NORMAL); - Free_state(&top_ls->ls_current); - top_ls->ls_current = - copy_state(top_ls->ls_previous->ls_current, - top_ls->ls_previous->ls_level); - remove_settings(top_ls->ls_current, top_ls->ls_level); - break; - - default: - NOTREACHED(); - UNREACHABLE_CODE; + case CASE: + assert(top_ls->ls_previous->ls_class == SWITCH); + if (dflt) + { + cs_entry->ls_previous->LS_DEFAULT_MET = 1; + } + merge_states( + top_ls->ls_current, top_ls->ls_previous->LS_CASE, top_ls->ls_previous->ls_level, + NORMAL); + merge_states( + top_ls->ls_current, top_ls->ls_previous->ls_current, top_ls->ls_previous->ls_level, + NORMAL); + Free_state(&top_ls->ls_current); + top_ls->ls_current + = copy_state(top_ls->ls_previous->ls_current, top_ls->ls_previous->ls_level); + remove_settings(top_ls->ls_current, top_ls->ls_level); + break; + + default: + NOTREACHED(); + UNREACHABLE_CODE; } } lint_break_stmt() { - struct lint_stack_entry *lse = find_wdfc(); + struct lint_stack_entry* lse = find_wdfc(); dbg_lint_stack("lint_break_stmt"); if (!lse) return; - switch (lse->ls_class) { - case WHILE: - case FOR: - case DO: - /* loop break */ - lse->ls_previous->ls_current->st_notreached = 0; - break_merge(lse); - break; + switch (lse->ls_class) + { + case WHILE: + case FOR: + case DO: + /* loop break */ + lse->ls_previous->ls_current->st_notreached = 0; + break_merge(lse); + break; - case CASE: - /* case break */ - if (!top_ls->ls_current->st_notreached) { - lse->ls_previous->ls_previous->ls_current->st_notreached = 0; - } - merge_states(lse->ls_current, lse->ls_previous->ls_current, - lse->ls_previous->ls_level, NORMAL); - if (lse->ls_previous->LS_BREAK) { - merge_states(top_ls->ls_current, - lse->ls_previous->LS_BREAK, - lse->ls_previous->ls_level, NORMAL); - } - else { - lse->ls_previous->LS_BREAK = - copy_state(top_ls->ls_current, - lse->ls_previous->ls_level); - } - if (lse == top_ls) { - Free_state(&lse->ls_current); - lint_pop(); - } - break; + case CASE: + /* case break */ + if (!top_ls->ls_current->st_notreached) + { + lse->ls_previous->ls_previous->ls_current->st_notreached = 0; + } + merge_states( + lse->ls_current, lse->ls_previous->ls_current, lse->ls_previous->ls_level, NORMAL); + if (lse->ls_previous->LS_BREAK) + { + merge_states( + top_ls->ls_current, lse->ls_previous->LS_BREAK, lse->ls_previous->ls_level, + NORMAL); + } + else + { + lse->ls_previous->LS_BREAK + = copy_state(top_ls->ls_current, lse->ls_previous->ls_level); + } + if (lse == top_ls) + { + Free_state(&lse->ls_current); + lint_pop(); + } + break; - default: - NOTREACHED(); - UNREACHABLE_CODE; + default: + NOTREACHED(); + UNREACHABLE_CODE; } top_ls->ls_current->st_notreached = 1; top_ls->ls_current->st_warned = 0; } -static -cont_merge(lse) - struct lint_stack_entry *lse; +static cont_merge(lse) struct lint_stack_entry* lse; { /* merge for continue statements */ - if (lse->LS_BODY) { - merge_states(top_ls->ls_current, lse->LS_BODY, - lse->ls_level, NORMAL); + if (lse->LS_BODY) + { + merge_states(top_ls->ls_current, lse->LS_BODY, lse->ls_level, NORMAL); } - else { + else + { lse->LS_BODY = copy_state(top_ls->ls_current, lse->ls_level); } } -static -break_merge(lse) - struct lint_stack_entry *lse; +static break_merge(lse) struct lint_stack_entry* lse; { /* merge for break statements */ - if (lse->LS_LOOP) { - merge_states(top_ls->ls_current, lse->LS_LOOP, - lse->ls_level, NORMAL); + if (lse->LS_LOOP) + { + merge_states(top_ls->ls_current, lse->LS_LOOP, lse->ls_level, NORMAL); } - else { + else + { lse->LS_LOOP = copy_state(top_ls->ls_current, lse->ls_level); } } @@ -1062,7 +1061,7 @@ lint_start_function() { dbg_lint_stack("lint_start_function"); - valreturned = NORETURN; /* initialization */ + valreturned = NORETURN; /* initialization */ return_warned = 0; lint_comment_function(); } @@ -1090,44 +1089,39 @@ lint_implicit_return() { dbg_lint_stack("lint_implicit_return"); - if (!top_ls->ls_current->st_notreached) { + if (!top_ls->ls_current->st_notreached) + { lint_return_stmt(NOVALRETURNED); } } -lint_return_stmt(e) - int e; +lint_return_stmt(e) int e; { dbg_lint_stack("lint_return_stmt"); - if (valreturned == NORETURN) { + if (valreturned == NORETURN) + { /* first return met */ int fund = func_type->tp_fund; - if ( e == NOVALRETURNED - && !func_notypegiven - && fund != VOID - && fund != ERRONEOUS - ) { - warning("function %s declared %s%s but no value returned", - func_name, - (func_type->tp_unsigned && fund != POINTER) ? - "unsigned " : "", - symbol2str(fund) - ); + if (e == NOVALRETURNED && !func_notypegiven && fund != VOID && fund != ERRONEOUS) + { + warning( + "function %s declared %s%s but no value returned", func_name, + (func_type->tp_unsigned && fund != POINTER) ? "unsigned " : "", symbol2str(fund)); /* adjust */ e = VALRETURNED; } valreturned = e; } - else - if (valreturned != e && !return_warned) { - warning("function %s does not always return a value", - func_name); + else if (valreturned != e && !return_warned) + { + warning("function %s does not always return a value", func_name); return_warned = 1; } - if (!top_ls->ls_current->st_notreached) { + if (!top_ls->ls_current->st_notreached) + { set_od_valreturned(valreturned); } top_ls->ls_current->st_notreached = 1; @@ -1136,8 +1130,7 @@ lint_return_stmt(e) /******** A C T I O N S : J U M P ********/ -lint_jump_stmt(idf) - struct idf *idf; +lint_jump_stmt(idf) struct idf* idf; { dbg_lint_stack("lint_jump_stmt"); @@ -1149,15 +1142,16 @@ lint_jump_stmt(idf) lint_label() { -/* When meeting a label, we should take the intersection of all - settings at all goto's leading this way, but this cannot reasonably - be done. So we assume that the user knows what he is doing and set - all automatic variables to set. -*/ - struct auto_def *a = top_ls->ls_current->st_auto_list; + /* When meeting a label, we should take the intersection of all + settings at all goto's leading this way, but this cannot reasonably + be done. So we assume that the user knows what he is doing and set + all automatic variables to set. + */ + struct auto_def* a = top_ls->ls_current->st_auto_list; dbg_lint_stack("lint_label"); - while (a) { + while (a) + { a->ad_maybe_set = 0; a->ad_set = 1; a = a->next; @@ -1168,11 +1162,12 @@ lint_label() lint_statement() { -/* Check if this statement can be reached -*/ + /* Check if this statement can be reached + */ dbg_lint_stack("lint_statement"); - if (s_NOTREACHED) { + if (s_NOTREACHED) + { top_ls->ls_current->st_notreached = 1; top_ls->ls_current->st_warned = 0; s_NOTREACHED = 0; @@ -1181,28 +1176,30 @@ lint_statement() return; if (top_ls->ls_current->st_warned) return; - if (top_ls->ls_current->st_notreached) { - if (DOT != CASE && DOT != DEFAULT && AHEAD != ':') { + if (top_ls->ls_current->st_notreached) + { + if (DOT != CASE && DOT != DEFAULT && AHEAD != ':') + { if (DOT != BREAK || loptions['b']) warning("statement cannot be reached"); top_ls->ls_current->st_warned = 1; } - else { + else + { top_ls->ls_current->st_notreached = 0; top_ls->ls_current->st_warned = 0; } } } -static struct lint_stack_entry * -mk_lint_stack_entry(cl) - int cl; +static struct lint_stack_entry* mk_lint_stack_entry(cl) +int cl; { -/* Prepare a new stack entry for the lint_stack with class cl. - Copy the top ls_current to this entry and set its level. -*/ - struct lint_stack_entry *new = new_lint_stack_entry(); - + /* Prepare a new stack entry for the lint_stack with class cl. + Copy the top ls_current to this entry and set its level. + */ + struct lint_stack_entry* new = new_lint_stack_entry(); + new->ls_class = cl; new->ls_current = copy_state(top_ls->ls_current, level); new->ls_level = level; @@ -1210,104 +1207,98 @@ mk_lint_stack_entry(cl) return new; } -static -lint_push(lse) - struct lint_stack_entry *lse; +static lint_push(lse) struct lint_stack_entry* lse; { lse->ls_previous = top_ls; top_ls->next = lse; top_ls = lse; } -static -lint_pop() +static lint_pop() { top_ls = top_ls->ls_previous; free_lint_stack_entry(top_ls->next); } -#ifdef DEBUG +#ifdef DEBUG /* FOR DEBUGGING */ -static -print_autos(a) - struct auto_def *a; +static print_autos(a) struct auto_def* a; { - while (a) { - struct idf *idf = a->ad_idf; - struct def *def = idf->id_def; + while (a) + { + struct idf* idf = a->ad_idf; + struct def* def = idf->id_def; printf("%s", idf->id_text); printf("(lvl=%d)", a->ad_def->df_level); - printf("(u%ds%dm%d U%dS%d) ", - a->ad_used, a->ad_set, a->ad_maybe_set, - def->df_used, def->df_set - ); + printf( + "(u%ds%dm%d U%dS%d) ", a->ad_used, a->ad_set, a->ad_maybe_set, def->df_used, + def->df_set); a = a->next; } } -static -pr_lint_state(nm, st) - char *nm; - struct state *st; +static pr_lint_state(nm, st) char* nm; +struct state* st; { printf("%s: ", nm); - if (st) { + if (st) + { printf("notreached == %d ", st->st_notreached); print_autos(st->st_auto_list); } - else { + else + { printf("NULL"); } printf("\n"); } -print_lint_stack(msg) - char *msg; +print_lint_stack(msg) char* msg; { - struct lint_stack_entry *lse = top_ls; + struct lint_stack_entry* lse = top_ls; printf("Lint stack: %s(level=%d)\n", msg, level); - while (lse) { - printf(" |-------------- level %d ------------\n", - lse->ls_level); + while (lse) + { + printf(" |-------------- level %d ------------\n", lse->ls_level); pr_lint_state(" |current", lse->ls_current); - printf(" |class == %s\n", - lse->ls_class ? symbol2str(lse->ls_class) : "{"); - - switch (lse->ls_class) { - case SWITCH: - pr_lint_state(" |LS_BREAK", lse->LS_BREAK); - pr_lint_state(" |LS_CASE", lse->LS_CASE); - break; - - case DO: - case WHILE: - case FOR: - printf(" |LS_TEST == %s\n", - lse->LS_TEST == TEST_VAR ? "TEST_VAR" : - lse->LS_TEST == TEST_TRUE ? "TEST_TRUE" : - lse->LS_TEST == TEST_FALSE ? "TEST_FALSE" : - "<>" - ); - pr_lint_state(" |LS_BODY", lse->LS_BODY); - pr_lint_state(" |LS_LOOP", lse->LS_LOOP); - break; - - case IF: - pr_lint_state(" |LS_IF", lse->LS_IF); - break; - - default: - break; + printf(" |class == %s\n", lse->ls_class ? symbol2str(lse->ls_class) : "{"); + + switch (lse->ls_class) + { + case SWITCH: + pr_lint_state(" |LS_BREAK", lse->LS_BREAK); + pr_lint_state(" |LS_CASE", lse->LS_CASE); + break; + + case DO: + case WHILE: + case FOR: + printf( + " |LS_TEST == %s\n", + lse->LS_TEST == TEST_VAR ? "TEST_VAR" + : lse->LS_TEST == TEST_TRUE ? "TEST_TRUE" + : lse->LS_TEST == TEST_FALSE ? "TEST_FALSE" + : "<>"); + pr_lint_state(" |LS_BODY", lse->LS_BODY); + pr_lint_state(" |LS_LOOP", lse->LS_LOOP); + break; + + case IF: + pr_lint_state(" |LS_IF", lse->LS_IF); + break; + + default: + break; } lse = lse->ls_previous; } printf(" |--------------\n\n"); } -#endif /* DEBUG */ +#endif /* DEBUG */ -#endif /* LINT */ +#endif /* LINT */ diff --git a/lang/cem/cemcom.ansi/label.c b/lang/cem/cemcom.ansi/label.c index 3081d5685b..f8e84dc922 100644 --- a/lang/cem/cemcom.ansi/label.c +++ b/lang/cem/cemcom.ansi/label.c @@ -5,34 +5,37 @@ /* $Id$ */ /* L A B E L H A N D L I N G */ -#include "parameters.h" -#include "idf.h" -#include "Lpars.h" -#include "level.h" -#include "label.h" -#include "arith.h" -#include "def.h" -#include "type.h" -#include "stack.h" -#include "error.h" - +#include +#include +#include "parameters.h" +#include "idf.h" +#include "Lpars.h" +#include "level.h" +#include "label.h" +#include "arith.h" +#include "def.h" +#include "type.h" +#include "stack.h" +#include "error.h" extern char options[]; -void enter_label(struct idf *idf, int defining) +void enter_label(struct idf* idf, int defining) { /* The identifier idf is entered as a label. If it is new, - it is entered into the idf list with the largest possible - scope, i.e., on the lowest possible level. - If defining, the label comes from a label statement. + it is entered into the idf list with the largest possible + scope, i.e., on the lowest possible level. + If defining, the label comes from a label statement. */ - struct def *def = idf->id_label; + struct def* def = idf->id_label; - if (def) { + if (def) + { if (defining && def->df_initialized) error("redeclaration of label %s", idf->id_text); } - else { + else + { stack_idf(idf, stack_level_of(L_LOCAL)); def = new_def(); def->df_sc = LABEL; @@ -41,15 +44,15 @@ void enter_label(struct idf *idf, int defining) def->df_line = idf->id_line; } if (def->df_address == 0) - def->df_address = (arith) text_label(); + def->df_address = (arith)text_label(); if (defining) def->df_initialized = 1; } -void unstack_label(struct idf *idf) +void unstack_label(struct idf* idf) { /* The scope in which the label idf occurred is left. - */ + */ if (!idf->id_label->df_initialized && !is_anon_idf(idf)) error("label %s not defined", idf->id_text); } diff --git a/lang/cem/cemcom.ansi/label.h b/lang/cem/cemcom.ansi/label.h index e76502c81f..eeb7f98cb6 100644 --- a/lang/cem/cemcom.ansi/label.h +++ b/lang/cem/cemcom.ansi/label.h @@ -7,31 +7,31 @@ #ifndef LABEL_H_ #define LABEL_H_ -#include /* obtain definition of "label" */ +#include /* obtain definition of "label" */ -#define NO_LABEL (label) 0 +#define NO_LABEL (label)0 extern label lab_count; -#define text_label() (lab_count++) /* returns a new text label */ +#define text_label() (lab_count++) /* returns a new text label */ extern label datlab_count; -#define data_label() (datlab_count++) /* returns a new data label */ +#define data_label() (datlab_count++) /* returns a new data label */ #define define_label(idf) enter_label(idf, 1); - /* The identifier idf is defined as a label. If it is new, - it is entered into the idf list with the largest possible - scope, i.e., on the lowest possible level. - */ +/* The identifier idf is defined as a label. If it is new, + it is entered into the idf list with the largest possible + scope, i.e., on the lowest possible level. +*/ #define apply_label(idf) enter_label(idf, 0); - /* The identifier idf is applied as a label. It may or may - not be there, and if it is there, it may be from a - declaration or another application. - */ +/* The identifier idf is applied as a label. It may or may + not be there, and if it is there, it may be from a + declaration or another application. +*/ struct idf; -void enter_label(struct idf *idf, int defining); -void unstack_label(struct idf *idf); +void enter_label(struct idf* idf, int defining); +void unstack_label(struct idf* idf); #endif /* LABEL_H_ */ diff --git a/lang/cem/cemcom.ansi/level.h b/lang/cem/cemcom.ansi/level.h index 70ac7453f2..8819de525e 100644 --- a/lang/cem/cemcom.ansi/level.h +++ b/lang/cem/cemcom.ansi/level.h @@ -6,18 +6,18 @@ /* LEVEL DEFINITIONS */ /* The level of the top-most stack_level is kept in a global variable - with the obvious name 'level'. Although this variable is consulted - by a variety of routines, it turns out that its actual value is of - importance in only a very few files. Therefore the names of the - values are put in a separate include-file. - The L_PROTO level is a dummy level, which only occurs within - prototype declarations. When the declaration is really declared - the level is turned into L_FORMAL2. + with the obvious name 'level'. Although this variable is consulted + by a variety of routines, it turns out that its actual value is of + importance in only a very few files. Therefore the names of the + values are put in a separate include-file. + The L_PROTO level is a dummy level, which only occurs within + prototype declarations. When the declaration is really declared + the level is turned into L_FORMAL2. */ -#define L_PROTO (-1) /* prototype declaration */ -#define L_UNIVERSAL 0 -#define L_GLOBAL 1 -#define L_FORMAL1 2 /* formal declaration */ -#define L_FORMAL2 3 /* formal definition */ -#define L_LOCAL 4 /* and up */ +#define L_PROTO (-1) /* prototype declaration */ +#define L_UNIVERSAL 0 +#define L_GLOBAL 1 +#define L_FORMAL1 2 /* formal declaration */ +#define L_FORMAL2 3 /* formal definition */ +#define L_LOCAL 4 /* and up */ diff --git a/lang/cem/cemcom.ansi/macro.str b/lang/cem/cemcom.ansi/macro.str index 6f96c3d8f4..de714ff2f5 100644 --- a/lang/cem/cemcom.ansi/macro.str +++ b/lang/cem/cemcom.ansi/macro.str @@ -5,4 +5,4 @@ /* $Id$ */ /* PREPROCESSOR: DEFINITION OF MACRO DESCRIPTOR */ -#include "parameters.h" +#include "parameters.h" diff --git a/lang/cem/cemcom.ansi/main.c b/lang/cem/cemcom.ansi/main.c index 60c40a378c..5af94f2cac 100644 --- a/lang/cem/cemcom.ansi/main.c +++ b/lang/cem/cemcom.ansi/main.c @@ -5,88 +5,71 @@ /* $Id$ */ /* MAIN PROGRAM */ -#include -#include "parameters.h" -#include -#include -#include "idf.h" -#include "input.h" -#include "level.h" -#include "arith.h" -#include "type.h" -#include "proto.h" -#include "declar.h" -#include "tokenname.h" -#include "Lpars.h" -#include "LLlex.h" -#include -#include "specials.h" -#include "sizes.h" -#include "align.h" -#include "stack.h" -#include "macro.h" -#include "options.h" -#include "error.h" -#include "code.h" -#include "cstoper.h" -#include "tokenname.h" +#include +#include +#include +#include "parameters.h" +#include +#include +#include "idf.h" +#include "input.h" +#include "level.h" +#include "arith.h" +#include "type.h" +#include "proto.h" +#include "declar.h" +#include "tokenname.h" +#include "Lpars.h" +#include "LLlex.h" +#include +#include "specials.h" +#include "sizes.h" +#include "align.h" +#include "stack.h" +#include "macro.h" +#include "options.h" +#include "error.h" +#include "code.h" +#include "cstoper.h" +#include "tokenname.h" extern struct tokenname tkidf[]; extern char options[128]; -struct sp_id special_ids[] = { - {"__setjmp", SP_SETJMP}, /* non-local goto's are registered */ - {0, 0} -}; +struct sp_id special_ids[] = { { "__setjmp", SP_SETJMP }, /* non-local goto's are registered */ + { 0, 0 } }; -void compile(int argc, char *argv[]); +void compile(int argc, char* argv[]); static void init(void); -static void init_specials(struct sp_id *si); +static void init_specials(struct sp_id* si); #ifdef DEBUG void Info(void); #endif extern void C_program(void); /* program.c */ - #ifndef NOCROSS -arith - short_size = SZ_SHORT, - word_size = SZ_WORD, - dword_size = (2 * SZ_WORD), - int_size = SZ_INT, - long_size = SZ_LONG, - lnglng_size = SZ_LNGLNG, - float_size = SZ_FLOAT, - double_size = SZ_DOUBLE, - lngdbl_size = SZ_LNGDBL, - pointer_size = SZ_POINTER; - -int - short_align = AL_SHORT, - word_align = AL_WORD, - int_align = AL_INT, - long_align = AL_LONG, - lnglng_align = AL_LNGLNG, - float_align = AL_FLOAT, - double_align = AL_DOUBLE, - lngdbl_align = AL_LNGDBL, - pointer_align = AL_POINTER, - struct_align = AL_STRUCT, - union_align = AL_UNION; +arith short_size = SZ_SHORT, word_size = SZ_WORD, dword_size = (2 * SZ_WORD), int_size = SZ_INT, + long_size = SZ_LONG, lnglng_size = SZ_LNGLNG, float_size = SZ_FLOAT, double_size = SZ_DOUBLE, + lngdbl_size = SZ_LNGDBL, pointer_size = SZ_POINTER; + +int short_align = AL_SHORT, word_align = AL_WORD, int_align = AL_INT, long_align = AL_LONG, + lnglng_align = AL_LNGLNG, float_align = AL_FLOAT, double_align = AL_DOUBLE, + lngdbl_align = AL_LNGDBL, pointer_align = AL_POINTER, struct_align = AL_STRUCT, + union_align = AL_UNION; #endif /* NOCROSS */ -char *prog_name; +char* prog_name; -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { /* parse and interpret the command line options */ prog_name = argv[0]; /* Note: source file "-" indicates that the source is supplied - as standard input. This is only allowed if INP_READ_IN_ONE is - not defined! + as standard input. This is only allowed if INP_READ_IN_ONE is + not defined! */ #ifdef INP_READ_IN_ONE while (argc > 1 && *argv[1] == '-') @@ -94,92 +77,93 @@ int main(int argc, char *argv[]) while (argc > 1 && *argv[1] == '-' && argv[1][1] != '\0') #endif /* INP_READ_IN_ONE */ { - char *par = &argv[1][1]; + char* par = &argv[1][1]; do_option(par); argc--, argv++; } -#ifdef LINT +#ifdef LINT lint_init(); -#endif /* LINT */ +#endif /* LINT */ compile(argc - 1, &argv[1]); -#ifdef DEBUG - if (options['h']) hash_stat(); - if (options['m']) Info(); -#endif /* DEBUG */ +#ifdef DEBUG + if (options['h']) + hash_stat(); + if (options['m']) + Info(); +#endif /* DEBUG */ exit(err_occurred ? 1 : 0); UNREACHABLE_CODE; } -char *source = 0; +char* source = 0; #ifdef GEN_NM_LIST -char *nmlist = 0; +char* nmlist = 0; #endif /* GEN_NM_LIST */ -void compile(int argc, char *argv[]) +void compile(int argc, char* argv[]) { - char *result; -#ifndef LINT - char *destination = 0; -#endif /* LINT */ - - switch (argc) { - case 1: -#ifndef LINT + char* result; +#ifndef LINT + char* destination = 0; +#endif /* LINT */ + + switch (argc) + { + case 1: +#ifndef LINT #ifdef DEBUG #endif fatal("%s: destination file not specified", prog_name); -#endif /* LINT */ - break; +#endif /* LINT */ + break; -#ifndef LINT - case 2: - destination = argv[1]; - break; +#ifndef LINT + case 2: + destination = argv[1]; + break; #ifdef GEN_NM_LIST - case 3: - nmlist = argv[2]; - destination = argv[1]; - break; + case 3: + nmlist = argv[2]; + destination = argv[1]; + break; #endif /* GEN_NM_LIST */ -#endif /* LINT */ +#endif /* LINT */ - default: -#ifndef LINT + default: +#ifndef LINT #ifdef GEN_NM_LIST - fatal("use: %s source destination [namelist]", prog_name); + fatal("use: %s source destination [namelist]", prog_name); #else /* GEN_NM_LIST */ - fatal("use: %s source destination", prog_name); + fatal("use: %s source destination", prog_name); #endif /* GEN_NM_LIST */ -#else /* LINT */ - fatal("use: %s source", prog_name); -#endif /* LINT */ - break; +#else /* LINT */ + fatal("use: %s source", prog_name); +#endif /* LINT */ + break; } if (strcmp(argv[0], "-")) FileName = source = argv[0]; - else { + else + { source = 0; FileName = strdup("standard input"); } - if (!InsertFile(source, (char **) 0, &result)) /* read the source file */ + if (!InsertFile(source, (char**)0, &result)) /* read the source file */ fatal("%s: no source file %s\n", prog_name, FileName); File_Inserted = 1; init(); LineNumber = 0; nestlow = -1; -#ifndef LINT - init_code(destination - && strcmp(destination, "-") != 0 - ? destination - : 0); -#endif /* LINT */ +#ifndef LINT + init_code(destination && strcmp(destination, "-") != 0 ? destination : 0); +#endif /* LINT */ GetToken(&ahead); { @@ -190,25 +174,26 @@ void compile(int argc, char *argv[]) prepend_scopes(); #endif /* PREPEND_SCOPES */ -#ifndef LINT +#ifndef LINT end_code(); -#endif /* LINT */ +#endif /* LINT */ -#ifdef DEBUG - if (options['u']) { - unstack_level(); /* unstack L_GLOBAL */ +#ifdef DEBUG + if (options['u']) + { + unstack_level(); /* unstack L_GLOBAL */ } if (options['f'] || options['t']) dumpidftab("end of main", options['f'] ? 7 : 0); -#endif /* DEBUG */ +#endif /* DEBUG */ } } static void init(void) { - init_cst(); /* initialize variables of "cstoper.c" */ - reserve(tkidf); /* mark the C reserved words as such */ - init_specials(special_ids); /* mark special ids as such */ + init_cst(); /* initialize variables of "cstoper.c" */ + reserve(tkidf); /* mark the C reserved words as such */ + init_specials(special_ids); /* mark special ids as such */ schar_type = standard_type(CHAR, 0, 1, (arith)1); uchar_type = standard_type(CHAR, UNSIGNED, 1, (arith)1); @@ -217,8 +202,8 @@ static void init(void) ushort_type = standard_type(SHORT, UNSIGNED, short_align, short_size); /* Treat type `word' as `int', having its own size and - alignment requirements. - This type is transparent to the user. + alignment requirements. + This type is transparent to the user. */ word_type = standard_type(INT, 0, word_align, word_size); uword_type = standard_type(INT, UNSIGNED, word_align, word_size); @@ -230,8 +215,7 @@ static void init(void) ulong_type = standard_type(LONG, UNSIGNED, long_align, long_size); lnglng_type = standard_type(LNGLNG, 0, lnglng_align, lnglng_size); - ulnglng_type = standard_type(LNGLNG, UNSIGNED, lnglng_align, - lnglng_size); + ulnglng_type = standard_type(LNGLNG, UNSIGNED, lnglng_align, lnglng_size); float_type = standard_type(FLOAT, 0, float_align, float_size); double_type = standard_type(DOUBLE, 0, double_align, double_size); @@ -241,14 +225,13 @@ static void init(void) error_type->tp_up = error_type; /* Pointer Arithmetic type: all arithmetics concerning - pointers is supposed to be performed in the - pointer arithmetic type which is equal to either - int_type or long_type, depending on the pointer_size + pointers is supposed to be performed in the + pointer arithmetic type which is equal to either + int_type or long_type, depending on the pointer_size */ if ((int)pointer_size == (int)int_size) pa_type = int_type; - else - if ((int)pointer_size == (int)long_size) + else if ((int)pointer_size == (int)long_size) pa_type = long_type; else fatal("pointer size incompatible with any integral size"); @@ -273,10 +256,11 @@ static void init(void) stack_level(); } -static void init_specials(struct sp_id *si) +static void init_specials(struct sp_id* si) { - while (si->si_identifier) { - struct idf *idf = str2idf(si->si_identifier, 0); + while (si->si_identifier) + { + struct idf* idf = str2idf(si->si_identifier, 0); if (idf->id_special) fatal("maximum identifier length insufficient"); @@ -288,15 +272,12 @@ static void init_specials(struct sp_id *si) #ifdef DEBUG void Info(void) { - extern int cnt_string_cst, cnt_formal, - cnt_decl_unary, cnt_def, cnt_expr, cnt_field, - cnt_e_stack, cnt_localvar, cnt_proto, - cnt_stack_level, - cnt_stack_entry, cnt_stmt_block, cnt_sdef, cnt_tag, - cnt_switch_hdr, cnt_case_entry, cnt_type, cnt_brace, - cnt_lint_stack_entry, cnt_state, cnt_auto_def, - cnt_expr_state, cnt_argument; - printf("\ + extern int cnt_string_cst, cnt_formal, cnt_decl_unary, cnt_def, cnt_expr, cnt_field, + cnt_e_stack, cnt_localvar, cnt_proto, cnt_stack_level, cnt_stack_entry, cnt_stmt_block, + cnt_sdef, cnt_tag, cnt_switch_hdr, cnt_case_entry, cnt_type, cnt_brace, + cnt_lint_stack_entry, cnt_state, cnt_auto_def, cnt_expr_state, cnt_argument; + printf( + "\ %6d string_cst\n%6d formal\n\ %6d decl_unary\n%6d def\n%6d expr\n%6d field\n\ %6d e_stack\n%6d localvar\n%6d proto\n\ @@ -305,21 +286,14 @@ void Info(void) %6d switch_hdr\n%6d case_entry\n%6d type\n%6d brace\n\ %6d lint_stack_entry\n%6d state\n%6d auto_def\n\ %6d expr_state\n%6d argument\n", - cnt_string_cst, cnt_formal, - cnt_decl_unary, cnt_def, cnt_expr, cnt_field, - cnt_e_stack, cnt_localvar, cnt_proto, - cnt_stack_level, - cnt_stack_entry, cnt_stmt_block, cnt_sdef, cnt_tag, - cnt_switch_hdr, cnt_case_entry, cnt_type, cnt_brace, - cnt_lint_stack_entry, cnt_state, cnt_auto_def, - cnt_expr_state, cnt_argument); - - + cnt_string_cst, cnt_formal, cnt_decl_unary, cnt_def, cnt_expr, cnt_field, cnt_e_stack, + cnt_localvar, cnt_proto, cnt_stack_level, cnt_stack_entry, cnt_stmt_block, cnt_sdef, + cnt_tag, cnt_switch_hdr, cnt_case_entry, cnt_type, cnt_brace, cnt_lint_stack_entry, + cnt_state, cnt_auto_def, cnt_expr_state, cnt_argument); } #endif /* DEBUG */ -void C_failed(void) /* called by EM_code module */ +void C_failed(void) /* called by EM_code module */ { fatal("write failed"); } - diff --git a/lang/cem/cemcom.ansi/mes.h b/lang/cem/cemcom.ansi/mes.h index 173d00460e..9749635a8c 100644 --- a/lang/cem/cemcom.ansi/mes.h +++ b/lang/cem/cemcom.ansi/mes.h @@ -5,4 +5,4 @@ /* $Id$ */ /* MESSAGE ADMINISTRATION */ -extern int fp_used; /* code.c */ +extern int fp_used; /* code.c */ diff --git a/lang/cem/cemcom.ansi/options.c b/lang/cem/cemcom.ansi/options.c index 1cb30fd7c4..4561837cdb 100644 --- a/lang/cem/cemcom.ansi/options.c +++ b/lang/cem/cemcom.ansi/options.c @@ -5,227 +5,234 @@ /* $Id$ */ /* U S E R O P T I O N - H A N D L I N G */ -#include "parameters.h" -#include -#include -#include -#include "options.h" -#include "class.h" -#include "macro.h" -#include "idf.h" -#include "arith.h" -#include "sizes.h" -#include "align.h" -#include "error.h" - -char options[128]; /* one for every char */ -#ifdef LINT -char loptions[128]; /* one for every char */ -#endif /* LINT */ +#include +#include +#include "parameters.h" +#include +#include +#include +#include "options.h" +#include "class.h" +#include "macro.h" +#include "idf.h" +#include "arith.h" +#include "sizes.h" +#include "align.h" +#include "error.h" + +char options[128]; /* one for every char */ +#ifdef LINT +char loptions[128]; /* one for every char */ +#endif /* LINT */ extern int idfsize; extern int density; +static int txt2int(char**); - -static int txt2int(char **); - -void do_option(char *text) +void do_option(char* text) { char opt; -next_option: /* to allow combined one-char options */ - switch (opt = *text++) { +next_option: /* to allow combined one-char options */ + switch (opt = *text++) + { - case 0: /* to end the goto next_option loop */ - break; + case 0: /* to end the goto next_option loop */ + break; - default: -#ifndef LINT - fatal("illegal option: %c", opt); -#else /* LINT */ - warning("illegal option: %c", opt); -#endif /* LINT */ - break; + default: +#ifndef LINT + fatal("illegal option: %c", opt); +#else /* LINT */ + warning("illegal option: %c", opt); +#endif /* LINT */ + break; - case '-': - options[(int)*text++] = 1; /* flags, debug options etc. */ - goto next_option; + case '-': + options[(int)*text++] = 1; /* flags, debug options etc. */ + goto next_option; #ifndef LINT #endif /* LINT */ #ifdef DBSYMTAB - case 'g': /* symbol table for debugger */ - options['g'] = 1; - options['n'] = 1; - break; + case 'g': /* symbol table for debugger */ + options['g'] = 1; + options['n'] = 1; + break; #endif /* DBSYMTAB */ -#ifndef LINT -#ifdef DATAFLOW - case 'd': -#endif /* DATAFLOW */ - case 'p': /* procentry/procexit */ - case 'L' : /* no fil/lin */ - case 'n': /* use no registers */ - case 'w': /* no warnings will be given */ - case 's': /* no stricts will be given */ - case 'o': /* no complaints about old-style */ - options[opt] = 1; - goto next_option; - case 'a': /* suppress all but errors diagnostics */ - options['w'] = 1; /* implies -a */ - options['s'] = 1; - goto next_option; -#endif /* LINT */ - -#ifdef LINT - case 'h': /* heuristic tests */ - case 'v': /* no complaints about unused arguments */ - case 'a': /* check long->int int->long conversions */ - case 'b': /* don't report unreachable break-statements */ - case 'x': /* complain about unused extern declared variables */ - case 'u': /* no "used but not defined"; for pass 2 */ - case 'L': /* lintlibrary */ - loptions[opt] = 1; - goto next_option; -#endif /* LINT */ - - case 'M': /* maximum identifier length */ - idfsize = txt2int(&text); - if (*text || idfsize <= 0) - fatal("malformed -M option"); - if (idfsize > IDFSIZE) - fatal("maximum identifier length is %d", IDFSIZE); - break; - -#ifdef LINT - case 'S' : { /* -Sint : static scope number for lint */ - extern int stat_number; - stat_number = txt2int(&text); - break; - } -#endif /* LINT */ +#ifndef LINT +#ifdef DATAFLOW + case 'd': +#endif /* DATAFLOW */ + case 'p': /* procentry/procexit */ + case 'L': /* no fil/lin */ + case 'n': /* use no registers */ + case 'w': /* no warnings will be given */ + case 's': /* no stricts will be given */ + case 'o': /* no complaints about old-style */ + options[opt] = 1; + goto next_option; + case 'a': /* suppress all but errors diagnostics */ + options['w'] = 1; /* implies -a */ + options['s'] = 1; + goto next_option; +#endif /* LINT */ + +#ifdef LINT + case 'h': /* heuristic tests */ + case 'v': /* no complaints about unused arguments */ + case 'a': /* check long->int int->long conversions */ + case 'b': /* don't report unreachable break-statements */ + case 'x': /* complain about unused extern declared variables */ + case 'u': /* no "used but not defined"; for pass 2 */ + case 'L': /* lintlibrary */ + loptions[opt] = 1; + goto next_option; +#endif /* LINT */ + + case 'M': /* maximum identifier length */ + idfsize = txt2int(&text); + if (*text || idfsize <= 0) + fatal("malformed -M option"); + if (idfsize > IDFSIZE) + fatal("maximum identifier length is %d", IDFSIZE); + break; + +#ifdef LINT + case 'S': + { /* -Sint : static scope number for lint */ + extern int stat_number; + stat_number = txt2int(&text); + break; + } +#endif /* LINT */ - case 'T' : { + case 'T': + { #ifdef USE_TMP - extern char *C_tmpdir; - if (*text) - C_tmpdir = text; - else - C_tmpdir = "."; + extern char* C_tmpdir; + if (*text) + C_tmpdir = text; + else + C_tmpdir = "."; #else /* USE_TMP */ - warning("-T option ignored"); + warning("-T option ignored"); #endif /* USE_TMP */ - break; - } - -#ifndef LINT + break; + } + +#ifndef LINT #ifndef NOCROSS - case 'V' : /* set object sizes and alignment requirements */ - { - arith sz, algn; - char c; - - while ( (c = *text++) !=0) { - sz = txt2int(&text); - algn = 0; - if (*text == '.') { - text++; - algn = txt2int(&text); - } - switch (c) { - case 's': /* short */ - if (sz != (arith)0) - short_size = sz; - if (algn != 0) - short_align = algn; - break; - case 'w': /* word */ - if (sz != (arith)0) - dword_size = (word_size = sz) << 1; - if (algn != 0) - word_align = algn; - break; - case 'i': /* int */ - if (sz != (arith)0) - int_size = sz; - if (algn != 0) - int_align = algn; - break; - case 'l': /* long */ - if (sz != (arith)0) - long_size = sz; - if (algn != 0) - long_align = algn; - break; - case 'q': /* long long */ - if (sz != (arith)0) - lnglng_size = sz; - if (algn != 0) - lnglng_align = algn; - break; - case 'f': /* float */ - if (sz != (arith)0) - float_size = sz; - if (algn != 0) - float_align = algn; - break; - case 'd': /* double */ - if (sz != (arith)0) - double_size = sz; - if (algn != 0) - double_align = algn; - break; - case 'x': /* long double */ - if (sz != (arith)0) - lngdbl_size = sz; - if (algn != 0) - lngdbl_align = algn; - break; - case 'p': /* pointer */ - if (sz != (arith)0) - pointer_size = sz; - if (algn != 0) - pointer_align = algn; - break; - case 'r': /* adjust bitfields right */ + case 'V': /* set object sizes and alignment requirements */ + { + arith sz, algn; + char c; + + while ((c = *text++) != 0) + { + sz = txt2int(&text); + algn = 0; + if (*text == '.') + { + text++; + algn = txt2int(&text); + } + switch (c) + { + case 's': /* short */ + if (sz != (arith)0) + short_size = sz; + if (algn != 0) + short_align = algn; + break; + case 'w': /* word */ + if (sz != (arith)0) + dword_size = (word_size = sz) << 1; + if (algn != 0) + word_align = algn; + break; + case 'i': /* int */ + if (sz != (arith)0) + int_size = sz; + if (algn != 0) + int_align = algn; + break; + case 'l': /* long */ + if (sz != (arith)0) + long_size = sz; + if (algn != 0) + long_align = algn; + break; + case 'q': /* long long */ + if (sz != (arith)0) + lnglng_size = sz; + if (algn != 0) + lnglng_align = algn; + break; + case 'f': /* float */ + if (sz != (arith)0) + float_size = sz; + if (algn != 0) + float_align = algn; + break; + case 'd': /* double */ + if (sz != (arith)0) + double_size = sz; + if (algn != 0) + double_align = algn; + break; + case 'x': /* long double */ + if (sz != (arith)0) + lngdbl_size = sz; + if (algn != 0) + lngdbl_align = algn; + break; + case 'p': /* pointer */ + if (sz != (arith)0) + pointer_size = sz; + if (algn != 0) + pointer_align = algn; + break; + case 'r': /* adjust bitfields right */ #ifndef NOBITFIELD - options['r'] = 1; + options['r'] = 1; #else /* NOBITFIELD */ - warning("bitfields are not implemented"); + warning("bitfields are not implemented"); #endif /* NOBITFIELD */ - break; - case 'S': /* initial struct alignment */ - if (sz != (arith)0) - struct_align = sz; - break; - case 'U': /* initial union alignment */ - if (sz != (arith)0) - union_align = sz; - break; - default: - error("-V: bad type indicator %c\n", c); + break; + case 'S': /* initial struct alignment */ + if (sz != (arith)0) + struct_align = sz; + break; + case 'U': /* initial union alignment */ + if (sz != (arith)0) + union_align = sz; + break; + default: + error("-V: bad type indicator %c\n", c); + } } + break; } - break; - } - case 'S': - density = txt2int(&text); - break; + case 'S': + density = txt2int(&text); + break; #endif /* NOCROSS */ -#endif /* LINT */ +#endif /* LINT */ } } -static int txt2int(char **tp) +static int txt2int(char** tp) { /* the integer pointed to by *tp is read, while increasing - *tp; the resulting value is yielded. - */ + *tp; the resulting value is yielded. + */ int val = 0, ch; - - while (ch = **tp, ch >= '0' && ch <= '9') { + + while (ch = **tp, ch >= '0' && ch <= '9') + { val = val * 10 + ch - '0'; (*tp)++; } diff --git a/lang/cem/cemcom.ansi/options.h b/lang/cem/cemcom.ansi/options.h index ade29ed886..7ab53c6d38 100644 --- a/lang/cem/cemcom.ansi/options.h +++ b/lang/cem/cemcom.ansi/options.h @@ -1,13 +1,13 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-02-07 - * + * */ #ifndef OPTIONS_H_ #define OPTIONS_H_ -void do_option(char *text); +void do_option(char* text); #endif /* OPTIONS_H_ */ diff --git a/lang/cem/cemcom.ansi/pragma.c b/lang/cem/cemcom.ansi/pragma.c index d6432a3e7a..1f0532bf53 100644 --- a/lang/cem/cemcom.ansi/pragma.c +++ b/lang/cem/cemcom.ansi/pragma.c @@ -5,36 +5,36 @@ /* $Id$ */ /* PREPROCESSOR: PRAGMA INTERPRETER */ -#include "parameters.h" -#include "pragma.h" -#include "skip.h" -#include "domacro.h" +#include +#include +#include "parameters.h" +#include "pragma.h" +#include "skip.h" +#include "domacro.h" -#define P_UNKNOWN 0 -#define NR_PRAGMAS 0 +#define P_UNKNOWN 0 +#define NR_PRAGMAS 0 struct pkey { - char *pk_name; + char* pk_name; int pk_key; -} pragmas[NR_PRAGMAS + 1] = -{ -{ 0, P_UNKNOWN } }; +} pragmas[NR_PRAGMAS + 1] = { { 0, P_UNKNOWN } }; void do_pragma(void) { -#if NR_PRAGMAS - struct pkey *pkp = &pragmas[0]; +#if NR_PRAGMAS + struct pkey* pkp = &pragmas[0]; #endif - struct idf *id = GetIdentifier(1); + struct idf* id = GetIdentifier(1); - if (id != (struct idf *) 0) + if (id != (struct idf*)0) { -#if NR_PRAGMAS - while(pkp->pk_name) +#if NR_PRAGMAS + while (pkp->pk_name) { if (strcmp(pkp->pk_name, id->id_text) == 0) - break; + break; pkp++; } @@ -42,7 +42,7 @@ void do_pragma(void) { case P_UNKNOWN: default: - break; + break; } #endif SkipToNewLine(); diff --git a/lang/cem/cemcom.ansi/pragma.h b/lang/cem/cemcom.ansi/pragma.h index df62ad6c0f..ab22896d86 100644 --- a/lang/cem/cemcom.ansi/pragma.h +++ b/lang/cem/cemcom.ansi/pragma.h @@ -1,9 +1,9 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-02-07 - * + * */ #ifndef PRAGMA_H_ #define PRAGMA_H_ diff --git a/lang/cem/cemcom.ansi/program.g b/lang/cem/cemcom.ansi/program.g index bf4bc922d6..07f1df5498 100644 --- a/lang/cem/cemcom.ansi/program.g +++ b/lang/cem/cemcom.ansi/program.g @@ -45,6 +45,8 @@ %start If_expr, control_if_expression; { +#include +#include #include "parameters.h" #include #include "arith.h" diff --git a/lang/cem/cemcom.ansi/proto.c b/lang/cem/cemcom.ansi/proto.c index 3453cd079f..e548bded8e 100644 --- a/lang/cem/cemcom.ansi/proto.c +++ b/lang/cem/cemcom.ansi/proto.c @@ -5,32 +5,34 @@ /* $Id$ */ /* P R O T O T Y P E F I D D L I N G */ -#include -#include "parameters.h" -#include -#include "idf.h" -#include "Lpars.h" -#include "level.h" -#include -#include "arith.h" -#include "LLlex.h" -#include "align.h" -#include "stack.h" -#include "def.h" -#include "type.h" -#include "struct.h" -#include "label.h" -#include "expr.h" -#include "declar.h" -#include "declarator.h" -#include "decspecs.h" -#include "proto.h" -#include "error.h" -#include "ch3.h" +#include +#include +#include +#include "parameters.h" +#include +#include "idf.h" +#include "Lpars.h" +#include "level.h" +#include +#include "arith.h" +#include "LLlex.h" +#include "align.h" +#include "stack.h" +#include "def.h" +#include "type.h" +#include "struct.h" +#include "label.h" +#include "expr.h" +#include "declar.h" +#include "declarator.h" +#include "decspecs.h" +#include "proto.h" +#include "error.h" +#include "ch3.h" extern char options[]; -void check_for_void(struct proto *pl) +void check_for_void(struct proto* pl) { int errcnt = 0; @@ -52,8 +54,7 @@ void check_for_void(struct proto *pl) } } -void add_proto(struct proto *pl, struct decspecs *ds, struct declarator *dc, - int lvl) +void add_proto(struct proto* pl, struct decspecs* ds, struct declarator* dc, int lvl) { /* The full typed identifier or abstract type, described by the structures decspecs and declarator are turned @@ -62,24 +63,24 @@ void add_proto(struct proto *pl, struct decspecs *ds, struct declarator *dc, later on it's decided whether they were prototypes or actual declarations. */ - struct idf *idf = dc->dc_idf; - struct def *def = idf ? idf->id_def : (struct def *) 0; + struct idf* idf = dc->dc_idf; + struct def* def = idf ? idf->id_def : (struct def*)0; int sc = ds->ds_sc; - struct type *type; + struct type* type; char formal_array = 0; - assert(ds->ds_type != (struct type * )0); + assert(ds->ds_type != (struct type*)0); pl->pl_flag = PL_FORMAL; type = declare_type(ds->ds_type, dc); - if (type->tp_size < (arith) 0 && actual_declaration(sc, type)) + if (type->tp_size < (arith)0 && actual_declaration(sc, type)) { - + if (type->tp_fund != VOID) error("unknown %s-type", symbol2str(type->tp_fund)); else { - if (idf != (struct idf *) 0 || ds->ds_sc_given || ds->ds_typequal) + if (idf != (struct idf*)0 || ds->ds_sc_given || ds->ds_typequal) { error("illegal use of void in argument list"); pl->pl_flag |= PL_ERRGIVEN; @@ -107,11 +108,11 @@ void add_proto(struct proto *pl, struct decspecs *ds, struct declarator *dc, */ if (type->tp_fund == FUNCTION) { - type = construct_type(POINTER, type, 0, (arith) 0, NO_PROTO); + type = construct_type(POINTER, type, 0, (arith)0, NO_PROTO); } else if (type->tp_fund == ARRAY) { - type = construct_type(POINTER, type->tp_up, 0, (arith) 0, NO_PROTO); + type = construct_type(POINTER, type->tp_up, 0, (arith)0, NO_PROTO); formal_array = 1; } @@ -122,19 +123,18 @@ void add_proto(struct proto *pl, struct decspecs *ds, struct declarator *dc, and therefore we can't complain up there. So we build up the storage class, and keep quiet until we reach declare_protos. */ - sc = (ds->ds_sc_given && ds->ds_sc != REGISTER) ? 0 : - sc == 0 ? FORMAL : REGISTER; + sc = (ds->ds_sc_given && ds->ds_sc != REGISTER) ? 0 : sc == 0 ? FORMAL : REGISTER; if (def && (def->df_level == lvl /* || def->df_level < L_PROTO */)) { /* redeclaration at the same level */ error("parameter %s redeclared", idf->id_text); } - else if (idf != (struct idf *) 0) + else if (idf != (struct idf*)0) { /* New definition, redefinition hides earlier one */ - struct def *newdef = new_def(); + struct def* newdef = new_def(); newdef->next = def; newdef->df_level = lvl; @@ -178,9 +178,9 @@ void add_proto(struct proto *pl, struct decspecs *ds, struct declarator *dc, pl->pl_type = type; } -static struct tag * gettag(struct type *tp, struct idf **idpp) +static struct tag* gettag(struct type* tp, struct idf** idpp) { - struct tag *tg = (struct tag *) 0; + struct tag* tg = (struct tag*)0; int fund = tp->tp_fund; while (fund == FIELD || fund == POINTER || fund == ARRAY || fund == FUNCTION) @@ -191,36 +191,36 @@ static struct tag * gettag(struct type *tp, struct idf **idpp) *idpp = tp->tp_idf; switch (tp->tp_fund) { - case ENUM: - case UNION: - case STRUCT: - tg = tp->tp_idf->id_tag; - break; + case ENUM: + case UNION: + case STRUCT: + tg = tp->tp_idf->id_tag; + break; } return tg; } -void declare_protos(struct declarator *dc) +void declare_protos(struct declarator* dc) { /* At this points we know that the idf's in protolist are formal parameters. So it's time to declare them at level L_FORMAL2. */ - struct stack_level *stl = stack_level_of(L_FORMAL1); - struct decl_unary *du; - struct type *type; - struct proto *pl; - struct def *def; + struct stack_level* stl = stack_level_of(L_FORMAL1); + struct decl_unary* du; + struct type* type; + struct proto* pl; + struct def* def; -#ifdef DEBUG +#ifdef DEBUG if (options['t']) - dumpidftab("start declare_protos", 0); -#endif /* DEBUG */ + dumpidftab("start declare_protos", 0); +#endif /* DEBUG */ du = dc->dc_decl_unary; while (du) { if (du->du_fund == FUNCTION) { - if (du->next != (struct decl_unary *) 0) + if (du->next != (struct decl_unary*)0) { remove_proto_idfs(du->du_proto); du->du_proto = 0; @@ -233,13 +233,13 @@ void declare_protos(struct declarator *dc) pl = du ? du->du_proto : NO_PROTO; if (pl) { -#if 0 /* the id_proto member is deleted (???) */ +#if 0 /* the id_proto member is deleted (???) */ idf->id_proto = 0; -#endif /* 0 */ +#endif /* 0 */ do { - struct tag *tg; - struct idf *idp = 0; + struct tag* tg; + struct idf* idp = 0; type = pl->pl_type; @@ -278,13 +278,13 @@ void declare_protos(struct declarator *dc) } } while (pl); } -#ifdef DEBUG +#ifdef DEBUG if (options['t']) - dumpidftab("end declare_protos", 0); -#endif /* DEBUG */ + dumpidftab("end declare_protos", 0); +#endif /* DEBUG */ } -void update_proto(struct type *tp, struct type *otp) +void update_proto(struct type* tp, struct type* otp) { /* This routine performs the proto type updates. Consider the following code: @@ -345,9 +345,9 @@ void update_proto(struct type *tp, struct type *otp) /* struct/union and enum tags can be declared inside prototypes * remove them from the symbol-table */ -static void remove_proto_tag(struct type *tp) +static void remove_proto_tag(struct type* tp) { - struct idf *ident; + struct idf* ident; struct tag *tgp, **tgpp; int fund = tp->tp_fund; @@ -360,13 +360,13 @@ static void remove_proto_tag(struct type *tp) ident = tp->tp_idf; switch (tp->tp_fund) { - case ENUM: - case STRUCT: - case UNION: - tgpp = &(ident->id_tag); - break; - default: - return; + case ENUM: + case STRUCT: + case UNION: + tgpp = &(ident->id_tag); + break; + default: + return; } while ((*tgpp) && (*tgpp)->tg_type != tp) @@ -382,8 +382,7 @@ static void remove_proto_tag(struct type *tp) #ifdef DEBUG if (options['t']) - printf("Removing idf %s from list\n", - ident->id_text); + printf("Removing idf %s from list\n", ident->id_text); #endif (*tgpp) = tgp->next; @@ -391,11 +390,11 @@ static void remove_proto_tag(struct type *tp) } /* Remove all the identifier definitions from the - prototype list. */ -void remove_proto_idfs(struct proto *pl) + prototype list. */ +void remove_proto_idfs(struct proto* pl) { - struct def *def; + struct def* def; while (pl) { @@ -403,8 +402,7 @@ void remove_proto_idfs(struct proto *pl) { #ifdef DEBUG if (options['t']) - printf("Removing idf %s from list\n", - pl->pl_idf->id_text); + printf("Removing idf %s from list\n", pl->pl_idf->id_text); #endif def = pl->pl_idf->id_def; if (def && def->df_level <= L_PROTO) @@ -412,7 +410,7 @@ void remove_proto_idfs(struct proto *pl) pl->pl_idf->id_def = def->next; free_def(def); } - pl->pl_idf = (struct idf *) 0; + pl->pl_idf = (struct idf*)0; } if (pl->pl_type) { @@ -422,7 +420,7 @@ void remove_proto_idfs(struct proto *pl) } } -void call_proto(struct expr **expp) +void call_proto(struct expr** expp) { /* If the function specified by (*expp)->OP_LEFT has a prototype, the parameters are converted according the rules specified in @@ -431,15 +429,14 @@ void call_proto(struct expr **expp) under ellipsis clause the old parameters conversion stuff applies. */ - struct expr *left = (*expp)->OP_LEFT; - struct expr *right = (*expp)->OP_RIGHT; - struct proto *pl = NO_PROTO; - static struct proto ellipsis = - { 0, 0, 0, PL_ELLIPSIS }; + struct expr* left = (*expp)->OP_LEFT; + struct expr* right = (*expp)->OP_RIGHT; + struct proto* pl = NO_PROTO; + static struct proto ellipsis = { 0, 0, 0, PL_ELLIPSIS }; if (left != NILEXPR) { /* in case of an error */ - struct type *tp = left->ex_type; + struct type* tp = left->ex_type; while (tp && tp->tp_fund != FUNCTION && tp != error_type) tp = tp->tp_up; @@ -449,10 +446,10 @@ void call_proto(struct expr **expp) if (right != NILEXPR) { /* function call with parameters */ - struct expr **ep = &((*expp)->OP_RIGHT); + struct expr** ep = &((*expp)->OP_RIGHT); int ecnt = 0, pcnt = 0; - struct expr **estack[NPARAMS]; - struct proto *pstack[NPARAMS]; + struct expr** estack[NPARAMS]; + struct proto* pstack[NPARAMS]; /* stack up the parameter expressions */ while (right->ex_class == Oper && right->OP_OPER == PARCOMMA) @@ -504,8 +501,7 @@ void call_proto(struct expr **expp) */ if (pcnt < 0) { - expr_error(*expp, - "more parameters than specified in prototype"); + expr_error(*expp, "more parameters than specified in prototype"); break; } else if (!(pstack[pcnt]->pl_flag & PL_ELLIPSIS)) diff --git a/lang/cem/cemcom.ansi/proto.str b/lang/cem/cemcom.ansi/proto.str index 690588265f..6695e465ca 100644 --- a/lang/cem/cemcom.ansi/proto.str +++ b/lang/cem/cemcom.ansi/proto.str @@ -8,19 +8,20 @@ /* $Id$ */ /* PARAMETER TYPE LIST DEFINITION */ -struct proto { - struct proto *next; - struct type *pl_type; /* parameter type */ - struct idf *pl_idf; /* parameter identifier */ - short pl_flag; /* see define's */ +struct proto +{ + struct proto* next; + struct type* pl_type; /* parameter type */ + struct idf* pl_idf; /* parameter identifier */ + short pl_flag; /* see define's */ }; -#define NO_PROTO ((struct proto *)0) +#define NO_PROTO ((struct proto*)0) -#define PL_VOID 0x01 -#define PL_FORMAL 0x02 -#define PL_ELLIPSIS 0x04 -#define PL_ERRGIVEN 0x08 +#define PL_VOID 0x01 +#define PL_FORMAL 0x02 +#define PL_ELLIPSIS 0x04 +#define PL_ERRGIVEN 0x08 /* ALLOCDEF "proto" 20 */ @@ -30,13 +31,11 @@ struct type; struct declarator; struct decspecs; - -void remove_proto_idfs(register struct proto *pl); -void call_proto(register struct expr **expp); -void update_proto(register struct type *tp, register struct type *otp); -void declare_protos(register struct declarator *dc); -void add_proto(struct proto *pl, struct decspecs *ds, struct declarator *dc, - int lvl); -void check_for_void(register struct proto *pl); +void remove_proto_idfs(register struct proto* pl); +void call_proto(register struct expr** expp); +void update_proto(register struct type* tp, register struct type* otp); +void declare_protos(register struct declarator* dc); +void add_proto(struct proto* pl, struct decspecs* ds, struct declarator* dc, int lvl); +void check_for_void(register struct proto* pl); #endif diff --git a/lang/cem/cemcom.ansi/sizes.h b/lang/cem/cemcom.ansi/sizes.h index f943d184b8..42b9cf3904 100644 --- a/lang/cem/cemcom.ansi/sizes.h +++ b/lang/cem/cemcom.ansi/sizes.h @@ -8,31 +8,27 @@ #include "parameters.h" #ifndef NOCROSS -extern arith - short_size, word_size, dword_size, int_size, long_size, - lnglng_size, - float_size, double_size, lngdbl_size, - pointer_size; +extern arith short_size, word_size, dword_size, int_size, long_size, lnglng_size, float_size, + double_size, lngdbl_size, pointer_size; -extern arith max_int, max_unsigned; /* cstoper.c */ +extern arith max_int, max_unsigned; /* cstoper.c */ #else /* NOCROSS */ -#define short_size ((arith)SZ_SHORT) -#define word_size ((arith)SZ_WORD) -#define dword_size ((arith)2*SZ_WORD) -#define int_size ((arith)SZ_INT) -#define long_size ((arith)SZ_LONG) -#define lnglng_size ((arith)SZ_LNGLNG) -#define float_size ((arith)SZ_FLOAT) -#define double_size ((arith)SZ_DOUBLE) -#define lngdbl_size ((arith)SZ_LNGDBL) -#define pointer_size ((arith)SZ_POINTER) +#define short_size ((arith)SZ_SHORT) +#define word_size ((arith)SZ_WORD) +#define dword_size ((arith)2 * SZ_WORD) +#define int_size ((arith)SZ_INT) +#define long_size ((arith)SZ_LONG) +#define lnglng_size ((arith)SZ_LNGLNG) +#define float_size ((arith)SZ_FLOAT) +#define double_size ((arith)SZ_DOUBLE) +#define lngdbl_size ((arith)SZ_LNGDBL) +#define pointer_size ((arith)SZ_POINTER) #if SZ_INT == 2 -#define max_int ((arith)32767) -#define max_unsigned ((arith)65535) +#define max_int ((arith)32767) +#define max_unsigned ((arith)65535) #else /* SZ_INT == 4 */ -#define max_int ((arith)2147483647) -#define max_unsigned ((arith)4294967295) +#define max_int ((arith)2147483647) +#define max_unsigned ((arith)4294967295) #endif #endif /* NOCROSS */ - diff --git a/lang/cem/cemcom.ansi/skip.c b/lang/cem/cemcom.ansi/skip.c index d104e34907..81029be4f0 100644 --- a/lang/cem/cemcom.ansi/skip.c +++ b/lang/cem/cemcom.ansi/skip.c @@ -5,6 +5,8 @@ /* $Id$ */ /* PREPROCESSOR: INPUT SKIP FUNCTIONS */ +#include +#include #include "parameters.h" #include "arith.h" #include "LLlex.h" @@ -12,7 +14,6 @@ #include "input.h" #include "skip.h" - int SkipToNewLine(void) { int ch; diff --git a/lang/cem/cemcom.ansi/skip.h b/lang/cem/cemcom.ansi/skip.h index 52ef8cbdab..86707b178d 100644 --- a/lang/cem/cemcom.ansi/skip.h +++ b/lang/cem/cemcom.ansi/skip.h @@ -1,9 +1,9 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-02-07 - * + * */ #ifndef SKIP_H_ #define SKIP_H_ diff --git a/lang/cem/cemcom.ansi/specials.h b/lang/cem/cemcom.ansi/specials.h index 947d1c7a18..c84d91e806 100644 --- a/lang/cem/cemcom.ansi/specials.h +++ b/lang/cem/cemcom.ansi/specials.h @@ -5,14 +5,15 @@ /* $Id$ */ /* OCCURANCES OF SPECIAL IDENTIFIERS */ -#define SP_SETJMP 1 +#define SP_SETJMP 1 -#define SP_TOTAL 1 +#define SP_TOTAL 1 -struct sp_id { - char *si_identifier; /* its name */ - int si_flag; /* index into sp_occurred array */ +struct sp_id +{ + char* si_identifier; /* its name */ + int si_flag; /* index into sp_occurred array */ }; -extern char sp_occurred[]; /* idf.c */ -extern struct sp_id special_ids[]; /* main.c */ +extern char sp_occurred[]; /* idf.c */ +extern struct sp_id special_ids[]; /* main.c */ diff --git a/lang/cem/cemcom.ansi/stab.c b/lang/cem/cemcom.ansi/stab.c index e99a7bf005..308cfebc4b 100644 --- a/lang/cem/cemcom.ansi/stab.c +++ b/lang/cem/cemcom.ansi/stab.c @@ -9,6 +9,8 @@ /* $Id$ */ +#include +#include #include #include #include "parameters.h" diff --git a/lang/cem/cemcom.ansi/stab.h b/lang/cem/cemcom.ansi/stab.h index d8664410f0..8b9a40b111 100644 --- a/lang/cem/cemcom.ansi/stab.h +++ b/lang/cem/cemcom.ansi/stab.h @@ -1,20 +1,19 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-02-07 - * + * */ #ifndef STAB_H_ #define STAB_H_ - struct def; struct type; struct tag; -void stb_tag(struct tag *tg, char *str); -void stb_typedef(struct type *tp, char *str); -void stb_string(struct def *df, int kind, char* str); +void stb_tag(struct tag* tg, char* str); +void stb_typedef(struct type* tp, char* str); +void stb_string(struct def* df, int kind, char* str); #endif /* STAB_H_ */ diff --git a/lang/cem/cemcom.ansi/stack.c b/lang/cem/cemcom.ansi/stack.c index 670494f286..c52284c411 100644 --- a/lang/cem/cemcom.ansi/stack.c +++ b/lang/cem/cemcom.ansi/stack.c @@ -5,73 +5,76 @@ /* $Id$ */ /* S T A C K / U N S T A C K R O U T I N E S */ -#include "parameters.h" -#include -#ifndef LINT -#include +#include +#include +#include "parameters.h" +#include +#ifndef LINT +#include #else -#include "l_em.h" -#endif /* LINT */ -#include -#include "idf.h" -#include "Lpars.h" -#include "arith.h" -#include "stack.h" -#include "type.h" -#include "def.h" -#include "struct.h" -#include "level.h" -#include "mes.h" -#include "code.h" -#include "util.h" -#include "error.h" +#include "l_em.h" +#endif /* LINT */ +#include +#include "idf.h" +#include "Lpars.h" +#include "arith.h" +#include "stack.h" +#include "type.h" +#include "def.h" +#include "struct.h" +#include "level.h" +#include "mes.h" +#include "code.h" +#include "util.h" +#include "error.h" /* #include */ extern char options[]; static struct stack_level UniversalLevel; -struct stack_level *local_level = &UniversalLevel; +struct stack_level* local_level = &UniversalLevel; /* The main reason for having this secondary stacking - mechanism besides the linked lists pointed to by the idf's - is efficiency. - To remove the idf's of a given level, one could scan the - hash table and chase down the idf chains; with a hash - table size of 100 this is feasible, but with a size of say - 100000 this becomes painful. Therefore all idf's are also - kept in a stack of sets, one set for each level. + mechanism besides the linked lists pointed to by the idf's + is efficiency. + To remove the idf's of a given level, one could scan the + hash table and chase down the idf chains; with a hash + table size of 100 this is feasible, but with a size of say + 100000 this becomes painful. Therefore all idf's are also + kept in a stack of sets, one set for each level. */ -int level; /* Always equal to local_level->sl_level. */ +int level; /* Always equal to local_level->sl_level. */ -void stack_level(void) { +void stack_level(void) +{ /* A new level is added on top of the identifier stack. - */ - struct stack_level *stl = new_stack_level(); - struct stack_level *loclev = local_level; - + */ + struct stack_level* stl = new_stack_level(); + struct stack_level* loclev = local_level; + loclev->sl_next = stl; stl->sl_previous = loclev; stl->sl_level = ++level; stl->sl_max_block = loclev->sl_max_block; local_level = stl; -#ifdef LINT +#ifdef LINT lint_start_local(); -#endif /* LINT */ +#endif /* LINT */ } -void stack_idf( - struct idf *idf, - struct stack_level *stl) +void stack_idf(struct idf* idf, struct stack_level* stl) { /* The identifier idf is inserted in the stack on level stl, - but only if it is not already present at this level. + but only if it is not already present at this level. */ - struct stack_entry *se; - + struct stack_entry* se; + se = stl->sl_entry; - while (se) { - if (se->se_idf == idf) return; + while (se) + { + if (se->se_idf == idf) + return; se = se->next; } @@ -83,19 +86,20 @@ void stack_idf( stl->sl_entry = se; } -struct stack_level *stack_level_of(int lvl) +struct stack_level* stack_level_of(int lvl) { /* The stack_level corresponding to level lvl is returned. - The stack should probably be an array, to be extended with - realloc where needed. + The stack should probably be an array, to be extended with + realloc where needed. */ - struct stack_level *stl; + struct stack_level* stl; if (lvl == level) return local_level; stl = &UniversalLevel; - - while (stl->sl_level != lvl) { + + while (stl->sl_level != lvl) + { stl = stl->sl_next; } return stl; @@ -104,38 +108,41 @@ struct stack_level *stack_level_of(int lvl) void unstack_level(void) { /* The top level of the identifier stack is removed. - */ - struct stack_level *lastlvl; + */ + struct stack_level* lastlvl; -#ifdef DEBUG +#ifdef DEBUG if (options['t']) dumpidftab("before unstackidfs", 0); -#endif /* DEBUG */ +#endif /* DEBUG */ -#ifdef LINT +#ifdef LINT lint_end_local(local_level); -#endif /* LINT */ +#endif /* LINT */ /* The implementation below is more careful than strictly - necessary. Optimists may optimize it afterwards. + necessary. Optimists may optimize it afterwards. */ - while (local_level->sl_entry) { - struct stack_entry *se = local_level->sl_entry; - struct idf *idf = se->se_idf; - struct def *def; - struct sdef *sdef; - struct tag *tag; + while (local_level->sl_entry) + { + struct stack_entry* se = local_level->sl_entry; + struct idf* idf = se->se_idf; + struct def* def; + struct sdef* sdef; + struct tag* tag; /* unlink it from the local stack level */ local_level->sl_entry = se->next; free_stack_entry(se); - if (level == L_LOCAL && (def = idf->id_label)) { + if (level == L_LOCAL && (def = idf->id_label)) + { unstack_label(idf); free_def(def); idf->id_label = 0; } - while ((def = idf->id_def) && def->df_level >= level) { + while ((def = idf->id_def) && def->df_level >= level) + { /* unlink it from the def list under the idf block */ if (def->df_sc == REGISTER || def->df_sc == AUTO) FreeLocal(def->df_address); @@ -143,125 +150,123 @@ void unstack_level(void) free_def(def); update_ahead(idf); } - while ( (sdef = idf->id_sdef) - && sdef->sd_level >= level - ) { + while ((sdef = idf->id_sdef) && sdef->sd_level >= level) + { /* unlink it from the sdef list under the idf block */ idf->id_sdef = sdef->next; free_sdef(sdef); } - while ( (tag = idf->id_tag) - && tag->tg_level >= level - ) { + while ((tag = idf->id_tag) && tag->tg_level >= level) + { /* unlink it from the struct list under the idf block */ idf->id_tag = tag->next; free_tag(tag); } } /* Unlink the local stack level from the stack. - */ + */ lastlvl = local_level; local_level = local_level->sl_previous; - if (level >= L_LOCAL) { + if (level >= L_LOCAL) + { local_level->sl_max_block = lastlvl->sl_max_block; } free_stack_level(lastlvl); - local_level->sl_next = (struct stack_level *) 0; + local_level->sl_next = (struct stack_level*)0; level = local_level->sl_level; -#ifdef DEBUG +#ifdef DEBUG if (options['t']) dumpidftab("after unstackidfs", 0); -#endif /* DEBUG */ +#endif /* DEBUG */ } void unstack_world(void) { /* The global level of identifiers is scanned, and final - decisions are taken about such issues as - extern/static/global and un/initialized. - Effects on the code generator: initialised variables - have already been encoded while the uninitialised ones - are not and have to be encoded at this moment. + decisions are taken about such issues as + extern/static/global and un/initialized. + Effects on the code generator: initialised variables + have already been encoded while the uninitialised ones + are not and have to be encoded at this moment. */ - struct stack_entry *se = local_level->sl_entry; + struct stack_entry* se = local_level->sl_entry; -#ifdef LINT +#ifdef LINT lint_end_global(local_level); -#endif /* LINT */ +#endif /* LINT */ #ifdef GEN_NM_LIST open_name_list(); #endif /* GEN_NM_LIST */ - while (se) { - struct idf *idf = se->se_idf; - struct def *def = idf->id_def; - - if (!def) { + while (se) + { + struct idf* idf = se->se_idf; + struct def* def = idf->id_def; + + if (!def) + { /* global selectors, etc. */ se = se->next; continue; } - + #ifdef DEBUG - if (options['a']) { - char *symbol2str(); - - printf("\"%s\", %s, %s, %s, %s\n", - idf->id_text, - (def->df_alloc == 0) ? "no alloc" : - (def->df_alloc == ALLOC_SEEN) ? "alloc seen" : - (def->df_alloc == ALLOC_DONE) ? "alloc done" : - "illegal alloc info", - symbol2str(def->df_sc), - def->df_initialized ? "init" : "no init", - def->df_used ? "used" : "not used"); + if (options['a']) + { + char* symbol2str(); + + printf( + "\"%s\", %s, %s, %s, %s\n", idf->id_text, + (def->df_alloc == 0) ? "no alloc" + : (def->df_alloc == ALLOC_SEEN) ? "alloc seen" + : (def->df_alloc == ALLOC_DONE) ? "alloc done" + : "illegal alloc info", + symbol2str(def->df_sc), def->df_initialized ? "init" : "no init", + def->df_used ? "used" : "not used"); } #endif /* DEBUG */ - if (def->df_sc == STATIC - && def->df_type->tp_fund == FUNCTION - && !def->df_initialized) { + if (def->df_sc == STATIC && def->df_type->tp_fund == FUNCTION && !def->df_initialized) + { /* orphaned static function */ - warning("static function %s never defined, %s" - , idf->id_text - , "changed to extern"); + warning("static function %s never defined, %s", idf->id_text, "changed to extern"); def->df_sc = EXTERN; } - - if (def->df_alloc == ALLOC_SEEN - && !def->df_initialized) { + + if (def->df_alloc == ALLOC_SEEN && !def->df_initialized) + { /* space must be allocated */ bss(idf); #ifdef GEN_NM_LIST if (def->df_sc != STATIC) - namelist(idf->id_text); /* may be common */ + namelist(idf->id_text); /* may be common */ #endif /* GEN_NM_LIST */ - def->df_alloc = ALLOC_DONE; /* see Note below */ + def->df_alloc = ALLOC_DONE; /* see Note below */ } se = se->next; } /* Note: - df_alloc must be set to ALLOC_DONE because the idf entry - may occur several times in the list. - The reason for this is that the same name may be used - for different purposes on the same level, e.g. - struct s {int s;} s; - is a legal definition and contains 3 defining occurrences - of s. - Each definition has been entered into the identifier stack. - Although only one of them concerns a variable, we meet the - s 3 times when scanning the identifier stack. + df_alloc must be set to ALLOC_DONE because the idf entry + may occur several times in the list. + The reason for this is that the same name may be used + for different purposes on the same level, e.g. + struct s {int s;} s; + is a legal definition and contains 3 defining occurrences + of s. + Each definition has been entered into the identifier stack. + Although only one of them concerns a variable, we meet the + s 3 times when scanning the identifier stack. */ } #ifdef GEN_NM_LIST /* A list of potential common names is kept, to be fed to - an understanding loader. The list is written to a file - the name of which is nmlist. If nmlist == NULL, no name - list is generated. + an understanding loader. The list is written to a file + the name of which is nmlist. If nmlist == NULL, no name + list is generated. */ -extern char *nmlist; /* BAH! -- main.c */ +extern char* nmlist; /* BAH! -- main.c */ static FILE* nfp = 0; void open_name_list(void) @@ -270,9 +275,10 @@ void open_name_list(void) fatal("cannot create namelist %s", nmlist); } -void namelist(char *nm) +void namelist(char* nm) { - if (nmlist) { + if (nmlist) + { sys_write(nfp, nm, strlen(nm)); sys_write(nfp, "\n", 1); } diff --git a/lang/cem/cemcom.ansi/stack.str b/lang/cem/cemcom.ansi/stack.str index a7f59d1db7..04d7dd6638 100644 --- a/lang/cem/cemcom.ansi/stack.str +++ b/lang/cem/cemcom.ansi/stack.str @@ -11,50 +11,52 @@ struct idf; /* The identifier stack is implemented as a stack of sets. - The stack is implemented by a doubly linked list, - the sets by singly linked lists. + The stack is implemented by a doubly linked list, + the sets by singly linked lists. */ -struct stack_level { +struct stack_level +{ /* struct stack_level *next; */ - struct stack_level *sl_next; /* upward link */ - struct stack_level *sl_previous; /* downward link */ - struct stack_entry *sl_entry; /* sideward link */ - arith sl_local_offset; /* @ for first coming object */ - arith sl_max_block; /* maximum size of sub-block */ + struct stack_level* sl_next; /* upward link */ + struct stack_level* sl_previous; /* downward link */ + struct stack_entry* sl_entry; /* sideward link */ + arith sl_local_offset; /* @ for first coming object */ + arith sl_max_block; /* maximum size of sub-block */ int sl_level; }; /* ALLOCDEF "stack_level" 5 */ -struct stack_entry { - struct stack_entry *next; - struct idf *se_idf; +struct stack_entry +{ + struct stack_entry* next; + struct idf* se_idf; }; /* ALLOCDEF "stack_entry" 50 */ -extern struct stack_level *local_level; +extern struct stack_level* local_level; extern int level; /* A new level is added on top of the identifier stack. */ void stack_level(void); /* The identifier idf is inserted in the stack on level stl, - but only if it is not already present at this level. + but only if it is not already present at this level. */ -void stack_idf(struct idf *idf, register struct stack_level *stl); +void stack_idf(struct idf* idf, register struct stack_level* stl); /*The stack_level corresponding to level lvl is returned. The stack should probably be an array, to be extended with realloc where needed. */ -struct stack_level *stack_level_of(int lvl); +struct stack_level* stack_level_of(int lvl); /* The top level of the identifier stack is removed. */ void unstack_level(void); void unstack_world(void); #ifdef GEN_NM_LIST void open_name_list(void); -void namelist(char *nm); +void namelist(char* nm); #endif /* GEN_NM_LIST */ -#endif +#endif diff --git a/lang/cem/cemcom.ansi/stb.c b/lang/cem/cemcom.ansi/stb.c index 1e43a15dde..c4a94ff77a 100644 --- a/lang/cem/cemcom.ansi/stb.c +++ b/lang/cem/cemcom.ansi/stb.c @@ -4,9 +4,11 @@ */ /* $Id$ */ +#include +#include /* library routine for copying structs */ -void __stb(int n, char *f, char *t) +void __stb(int n, char* f, char* t) { if (n > 0) do diff --git a/lang/cem/cemcom.ansi/stmt.str b/lang/cem/cemcom.ansi/stmt.str index aea09b36b3..c4d76c6631 100644 --- a/lang/cem/cemcom.ansi/stmt.str +++ b/lang/cem/cemcom.ansi/stmt.str @@ -8,8 +8,9 @@ /* $Id$ */ /* S T A T E M E N T - B L O C K D E F I N I T I O N S */ -struct stmt_block { - struct stmt_block *next; +struct stmt_block +{ + struct stmt_block* next; label st_break; label st_continue; }; diff --git a/lang/cem/cemcom.ansi/struct.c b/lang/cem/cemcom.ansi/struct.c index e62c99eb5d..0a799fb8e5 100644 --- a/lang/cem/cemcom.ansi/struct.c +++ b/lang/cem/cemcom.ansi/struct.c @@ -5,56 +5,58 @@ /* $Id$ */ /* ADMINISTRATION OF STRUCT AND UNION DECLARATIONS */ -#include "parameters.h" -#include -#include "idf.h" -#include "arith.h" -#include "stack.h" -#include "def.h" -#include "type.h" -#include "proto.h" -#include "struct.h" -#include "field.h" -#include "LLlex.h" -#include "Lpars.h" -#include "align.h" -#include "level.h" -#include "ch3.h" -#include "sizes.h" -#include "error.h" +#include +#include +#include "parameters.h" +#include +#include "idf.h" +#include "arith.h" +#include "stack.h" +#include "def.h" +#include "type.h" +#include "proto.h" +#include "struct.h" +#include "field.h" +#include "LLlex.h" +#include "Lpars.h" +#include "align.h" +#include "level.h" +#include "ch3.h" +#include "sizes.h" +#include "error.h" /* Type of previous selector declared with a field width specified, - if any. If a selector is declared with no field with it is set to 0. + if any. If a selector is declared with no field with it is set to 0. */ static int field_busy = 0; extern char options[]; -static void check_selector(struct idf *, struct type *); +static void check_selector(struct idf*, struct type*); /* Greatest Common Divisor */ -static int gcd(int , int ); +static int gcd(int, int); /* Least Common Multiple */ static int lcm(int, int); /* The semantics of the identification of structure/union tags is - obscure. Some highly regarded compilers are found out to accept, - e.g.: - f(xp) struct aap *xp; { - struct aap {char *za;}; - xp->za; - } - Equally highly regarded software uses this feature, so we shall - humbly oblige. - The rules we use are: - 1. A structure definition applies at the level where it is - found, unless there is a structure declaration without a - definition on an outer level, in which case the definition - is applied at that level. - 2. A selector is applied on the same level as on which its - structure is being defined. - - If below struct is mentioned, union is implied (and sometimes enum - as well). + obscure. Some highly regarded compilers are found out to accept, + e.g.: + f(xp) struct aap *xp; { + struct aap {char *za;}; + xp->za; + } + Equally highly regarded software uses this feature, so we shall + humbly oblige. + The rules we use are: + 1. A structure definition applies at the level where it is + found, unless there is a structure declaration without a + definition on an outer level, in which case the definition + is applied at that level. + 2. A selector is applied on the same level as on which its + structure is being defined. + + If below struct is mentioned, union is implied (and sometimes enum + as well). */ void add_sel( /* this is horrible */ @@ -66,28 +68,31 @@ void add_sel( /* this is horrible */ struct field *fd) { /* The selector idf with type tp is added to two chains: the - selector identification chain starting at idf->id_sdef, - and to the end of the member list starting at stp->tp_sdef. - The address of the hook in the latest member (sdef) is - given in sdefpp; the hook itself must still be empty. + selector identification chain starting at idf->id_sdef, + and to the end of the member list starting at stp->tp_sdef. + The address of the hook in the latest member (sdef) is + given in sdefpp; the hook itself must still be empty. */ arith offset; - struct tag *tg = stp->tp_idf->id_tag; /* or union */ - struct sdef *sdef = idf->id_sdef; - struct sdef *newsdef; + struct tag* tg = stp->tp_idf->id_tag; /* or union */ + struct sdef* sdef = idf->id_sdef; + struct sdef* newsdef; int lvl = tg->tg_level; - - if (stp->tp_fund == STRUCT) { + + if (stp->tp_fund == STRUCT) + { #ifndef NOBITFIELD - if (fd == 0) { /* no field width specified */ + if (fd == 0) + { /* no field width specified */ offset = align(*szp, tp->tp_align); field_busy = 0; } - else { + else + { /* if something is wrong, the type of the - specified selector remains unchanged; its - bitfield specifier, however, is thrown away. + specified selector remains unchanged; its + bitfield specifier, however, is thrown away. */ offset = add_field(szp, fd, &tp, idf, stp); } @@ -96,18 +101,20 @@ void add_sel( /* this is horrible */ field_busy = 0; #endif /* NOBITFIELD */ } - else { /* (stp->tp_fund == UNION) */ - if (fd) offset = add_field(szp, fd, &tp, idf, stp); + else + { /* (stp->tp_fund == UNION) */ + if (fd) + offset = add_field(szp, fd, &tp, idf, stp); offset = (arith)0; } - + check_selector(idf, stp); newsdef = new_sdef(); /* newsdef->sd_sdef = (struct sdef *) 0; */ /* link into selector descriptor list of this id - */ + */ newsdef->next = sdef; idf->id_sdef = newsdef; @@ -125,22 +132,23 @@ void add_sel( /* this is horrible */ stack_idf(idf, stack_level_of(lvl)); /* link into selector definition list of the struct/union - */ + */ **sdefpp = newsdef; *sdefpp = &newsdef->sd_sdef; /* update the size of the struct/union upward */ - if (stp->tp_fund == STRUCT && fd == 0) { + if (stp->tp_fund == STRUCT && fd == 0) + { /* Note: the case that a bitfield is declared is - handled by add_field() ! + handled by add_field() ! */ *szp = offset + size_of_type(tp, "member"); stp->tp_align = lcm(stp->tp_align, tp->tp_align); } - else - if (stp->tp_fund == UNION && fd == 0) { + else if (stp->tp_fund == UNION && fd == 0) + { /* Note: the case that a bitfield is declared is - handled by add_field() ! + handled by add_field() ! */ arith sel_size = size_of_type(tp, "member"); @@ -150,107 +158,106 @@ void add_sel( /* this is horrible */ } } -static void check_selector(struct idf *idf, struct type *stp) +static void check_selector(struct idf* idf, struct type* stp) { /* checks if idf occurs already as a selector in - struct or union *stp. "stp" indicates the type - of the struct. + struct or union *stp. "stp" indicates the type + of the struct. */ - struct sdef *sdef = stp->tp_sdef; - - while (sdef) { + struct sdef* sdef = stp->tp_sdef; + + while (sdef) + { if (sdef->sd_idf == idf) error("multiple selector %s", idf->id_text); sdef = sdef->sd_sdef; } } -void declare_struct(int fund, struct idf *idf, struct type **tpp) +void declare_struct(int fund, struct idf* idf, struct type** tpp) { /* A struct, union or enum (depending on fund) with tag (!) - idf is declared, and its type (incomplete as it may be) is - returned in *tpp. - The idf may be missing (i.e. idf == 0), in which case an - anonymous struct etc. is defined. + idf is declared, and its type (incomplete as it may be) is + returned in *tpp. + The idf may be missing (i.e. idf == 0), in which case an + anonymous struct etc. is defined. */ - struct tag **tgp; - struct tag *tg; + struct tag** tgp; + struct tag* tg; - - if (*tpp) error("multiple types in declaration"); + if (*tpp) + error("multiple types in declaration"); if (!idf) idf = gen_idf(); tgp = &idf->id_tag; tg = *tgp; - if (tg - && tg->tg_type->tp_size < 0 - && tg->tg_type->tp_fund == fund + if (tg && tg->tg_type->tp_size < 0 && tg->tg_type->tp_fund == fund && (tg->tg_level == level - || (level >= L_FORMAL2 - && level <= L_LOCAL - && tg->tg_level == L_FORMAL2))) { + || (level >= L_FORMAL2 && level <= L_LOCAL && tg->tg_level == L_FORMAL2))) + { /* An unfinished declaration has preceded it. - We just fill in the answer. + We just fill in the answer. */ - if (tg->tg_busy) { - error("recursive declaration of struct/union %s", - idf->id_text); + if (tg->tg_busy) + { + error("recursive declaration of struct/union %s", idf->id_text); declare_struct(fund, gen_idf(), tpp); } - else { + else + { /* hint: if (level <= L_PROTO) */ *tpp = tg->tg_type; } } - else if (tg && tg->tg_level == level && tg->tg_type->tp_size >= 0) { + else if (tg && tg->tg_level == level && tg->tg_type->tp_size >= 0) + { /* There is an already defined struct/union of this name - on our level! + on our level! */ error("redeclaration of struct/union %s", idf->id_text); declare_struct(fund, gen_idf(), tpp); /* to allow a second struct_declaration_pack */ } - else { + else + { /* The struct is new. */ /* Hook in a new struct tag */ if (level <= L_PROTO) - warning("declaration of %s-tag inside parameter list", - symbol2str(fund)); + warning("declaration of %s-tag inside parameter list", symbol2str(fund)); tg = new_tag(); tg->next = *tgp; *tgp = tg; tg->tg_level = level; /* and supply room for a type */ tg->tg_type = create_type(fund); - tg->tg_type->tp_align = - fund == ENUM ? int_align : - fund == STRUCT ? struct_align : - /* fund == UNION */ union_align; + tg->tg_type->tp_align = fund == ENUM ? int_align + : fund == STRUCT ? struct_align + : + /* fund == UNION */ union_align; tg->tg_type->tp_idf = idf; *tpp = tg->tg_type; stack_idf(idf, local_level); } } -void apply_struct(int fund, - struct idf *idf, - struct type **tpp) +void apply_struct(int fund, struct idf* idf, struct type** tpp) { /* The occurrence of a struct, union or enum (depending on - fund) with tag idf is noted. It may or may not have been - declared before. Its type (complete or incomplete) is - returned in *tpp. + fund) with tag idf is noted. It may or may not have been + declared before. Its type (complete or incomplete) is + returned in *tpp. */ - struct tag **tgp; + struct tag** tgp; tgp = &idf->id_tag; - if (*tgp) { - if (fund != (*tgp)->tg_type->tp_fund) { - error("tag %s indicates a %s, not a %s", - idf->id_text, - symbol2str((*tgp)->tg_type->tp_fund), - symbol2str(fund)); + if (*tgp) + { + if (fund != (*tgp)->tg_type->tp_fund) + { + error( + "tag %s indicates a %s, not a %s", idf->id_text, + symbol2str((*tgp)->tg_type->tp_fund), symbol2str(fund)); } *tpp = (*tgp)->tg_type; } @@ -258,33 +265,33 @@ void apply_struct(int fund, declare_struct(fund, idf, tpp); } -struct sdef *idf2sdef( - struct idf *idf, - struct type *tp) +struct sdef* idf2sdef(struct idf* idf, struct type* tp) { /* The identifier idf is identified as a selector - in the struct tp. - If there is no such member, give a member with the same - name. - If this fails too, a selector of type error_type is - created. + in the struct tp. + If there is no such member, give a member with the same + name. + If this fails too, a selector of type error_type is + created. */ struct sdef **sdefp = &idf->id_sdef, *sdef; - + /* Follow chain from idf, to meet tp. */ - while ((sdef = *sdefp)) { - if (equal_type(sdef->sd_stype, tp, -999, 0)) /* ??? hack */ + while ((sdef = *sdefp)) + { + if (equal_type(sdef->sd_stype, tp, -999, 0)) /* ??? hack */ return sdef; sdefp = &(*sdefp)->next; } - + /* Tp not met; take an identification. */ - if ( (sdef = idf->id_sdef) ) { + if ((sdef = idf->id_sdef)) + { /* There is an identification */ error("illegal use of selector %s", idf->id_text); return sdef; } - + /* No luck; create an error entry. */ if (!is_anon_idf(idf)) error("unknown selector %s", idf->id_text); @@ -294,7 +301,7 @@ struct sdef *idf2sdef( return sdef; } -#if 0 +#if 0 int uniq_selector(struct sdef *idf_sdef) { /* Returns true if idf_sdef (which is guaranteed to exist) @@ -320,68 +327,67 @@ int uniq_selector(struct sdef *idf_sdef) #endif #ifndef NOBITFIELD -arith -add_field( - arith *szp, /* size of struct upto here */ - struct field *fd, /* bitfield, containing width */ - struct type **fdtpp, /* type of selector */ - struct idf *idf, /* name of selector */ - struct type *stp) /* current struct descriptor */ +arith add_field( + arith* szp, /* size of struct upto here */ + struct field* fd, /* bitfield, containing width */ + struct type** fdtpp, /* type of selector */ + struct idf* idf, /* name of selector */ + struct type* stp) /* current struct descriptor */ { /* The address where this selector is put is returned. If the - selector with specified width does not fit in the word, or - an explicit alignment is given, a new address is needed. - Note that the fields are packed into machine words. + selector with specified width does not fit in the word, or + an explicit alignment is given, a new address is needed. + Note that the fields are packed into machine words. */ - int bits_in_type = (int) (*fdtpp)->tp_size * 8; + int bits_in_type = (int)(*fdtpp)->tp_size * 8; static int field_offset = (arith)0; - static struct type *current_struct = 0; - static int bits_declared; /* nr of bits used in *field_offset */ + static struct type* current_struct = 0; + static int bits_declared; /* nr of bits used in *field_offset */ - if (current_struct != stp) { + if (current_struct != stp) + { /* This struct differs from the last one - */ + */ field_busy = 0; current_struct = stp; } - if ( fd->fd_width < 0 || - (fd->fd_width == 0 && !is_anon_idf(idf)) || - fd->fd_width > bits_in_type - ) { + if (fd->fd_width < 0 || (fd->fd_width == 0 && !is_anon_idf(idf)) || fd->fd_width > bits_in_type) + { error("illegal field-width specified"); *fdtpp = error_type; return field_offset; } - switch ((*fdtpp)->tp_fund) { - case CHAR: - case SHORT: - case ENUM: - case LONG: - case LNGLNG: - strict("non-portable field type"); - case INT: - /* right type; size OK? */ - if ((int) (*fdtpp)->tp_size > (int) word_size) { - error("bit field type %s does not fit in a word", - symbol2str((*fdtpp)->tp_fund)); + switch ((*fdtpp)->tp_fund) + { + case CHAR: + case SHORT: + case ENUM: + case LONG: + case LNGLNG: + strict("non-portable field type"); + case INT: + /* right type; size OK? */ + if ((int)(*fdtpp)->tp_size > (int)word_size) + { + error("bit field type %s does not fit in a word", symbol2str((*fdtpp)->tp_fund)); + *fdtpp = error_type; + return field_offset; + } + break; + + default: + /* wrong type altogether */ + error("field type cannot be %s", symbol2str((*fdtpp)->tp_fund)); *fdtpp = error_type; return field_offset; - } - break; - - default: - /* wrong type altogether */ - error("field type cannot be %s", - symbol2str((*fdtpp)->tp_fund)); - *fdtpp = error_type; - return field_offset; } - if (field_busy == 0) { + if (field_busy == 0) + { /* align this selector on the next boundary : - the previous selector wasn't a bitfield. + the previous selector wasn't a bitfield. */ field_offset = align(*szp, int_align); *szp = field_offset + int_size; @@ -390,46 +396,49 @@ add_field( field_busy = 1; } - if (fd->fd_width > bits_in_type - bits_declared) { + if (fd->fd_width > bits_in_type - bits_declared) + { /* field overflow: fetch next memory unit - */ + */ field_offset = align(*szp, int_align); *szp = field_offset + int_size; stp->tp_align = lcm(stp->tp_align, int_align); bits_declared = fd->fd_width; } - else - if (fd->fd_width == 0) + else if (fd->fd_width == 0) /* next field should be aligned on the next boundary. - This will take care that no field will fit in the - space allocated upto here. + This will take care that no field will fit in the + space allocated upto here. */ bits_declared = bits_in_type + 1; - else /* the bitfield fits in the current field */ + else /* the bitfield fits in the current field */ bits_declared += fd->fd_width; - + /* Arrived here, the place where the selector is stored in the - struct is computed. - Now we need a mask to use its value in expressions. + struct is computed. + Now we need a mask to use its value in expressions. */ *fdtpp = construct_type(FIELD, *fdtpp, 0, (arith)0, NO_PROTO); (*fdtpp)->tp_field = fd; /* Set the mask right shifted. This solution avoids the - problem of having sign extension when using the mask for - extracting the value from the field-int. - Sign extension could occur on some machines when shifting - the mask to the left. + problem of having sign extension when using the mask for + extracting the value from the field-int. + Sign extension could occur on some machines when shifting + the mask to the left. */ - if (fd->fd_width >= 8*sizeof(arith)) fd->fd_mask = -1; - else fd->fd_mask = (1L << fd->fd_width) - 1; + if (fd->fd_width >= 8 * sizeof(arith)) + fd->fd_mask = -1; + else + fd->fd_mask = (1L << fd->fd_width) - 1; - if (options['r']) /* adjust the field at the right */ + if (options['r']) /* adjust the field at the right */ fd->fd_shift = bits_declared - fd->fd_width; - else /* adjust the field at the left */ + else /* adjust the field at the left */ fd->fd_shift = bits_in_type - bits_declared; - - if (stp->tp_fund == UNION) bits_declared = 0; + + if (stp->tp_fund == UNION) + bits_declared = 0; return field_offset; } @@ -445,7 +454,8 @@ static int gcd(int m, int n) { int r; - while (n) { + while (n) + { r = m % n; m = n; n = r; @@ -453,7 +463,6 @@ static int gcd(int m, int n) return m; } - static int lcm(int m, int n) { return m * (n / gcd(m, n)); diff --git a/lang/cem/cemcom.ansi/struct.str b/lang/cem/cemcom.ansi/struct.str index c0a95244df..3d3ec10c0e 100644 --- a/lang/cem/cemcom.ansi/struct.str +++ b/lang/cem/cemcom.ansi/struct.str @@ -15,48 +15,48 @@ struct field; /* SELECTOR DESCRIPTOR */ -struct sdef { /* for selectors */ - struct sdef *next; +struct sdef +{ /* for selectors */ + struct sdef* next; int sd_level; - struct idf *sd_idf; /* its name */ - struct sdef *sd_sdef; /* the next selector */ - struct type *sd_stype; /* the struct it belongs to */ - struct type *sd_type; /* its type */ + struct idf* sd_idf; /* its name */ + struct sdef* sd_sdef; /* the next selector */ + struct type* sd_stype; /* the struct it belongs to */ + struct type* sd_type; /* its type */ arith sd_offset; }; /* ALLOCDEF "sdef" 50 */ -struct tag { /* for struct-, union- and enum tags */ - struct tag *next; +struct tag +{ /* for struct-, union- and enum tags */ + struct tag* next; int tg_level; - int tg_busy; /* non-zero during declaration of struct/union pack */ - struct type *tg_type; + int tg_busy; /* non-zero during declaration of struct/union pack */ + struct type* tg_type; }; - /* ALLOCDEF "tag" 10 */ -struct sdef *idf2sdef(register struct idf *idf, struct type *tp); +struct sdef* idf2sdef(register struct idf* idf, struct type* tp); void add_sel( - register struct type *stp, /* type of the structure */ - struct type *tp, /* type of the selector */ - register struct idf *idf, /* idf of the selector */ - struct sdef ***sdefpp, /* address of hook to selector definition */ - arith *szp, /* pointer to struct size upto here */ - struct field *fd); -void declare_struct(int fund, register struct idf *idf, struct type **tpp); -void apply_struct(int fund, register struct idf *idf, struct type **tpp); + register struct type* stp, /* type of the structure */ + struct type* tp, /* type of the selector */ + register struct idf* idf, /* idf of the selector */ + struct sdef*** sdefpp, /* address of hook to selector definition */ + arith* szp, /* pointer to struct size upto here */ + struct field* fd); +void declare_struct(int fund, register struct idf* idf, struct type** tpp); +void apply_struct(int fund, register struct idf* idf, struct type** tpp); int is_struct_or_union(register int fund); #ifndef NOBITFIELD -arith -add_field( - arith *szp, /* size of struct upto here */ - register struct field *fd, /* bitfield, containing width */ - register struct type **fdtpp, /* type of selector */ - struct idf *idf, /* name of selector */ - register struct type *stp); /* current struct descriptor */ -#endif +arith add_field( + arith* szp, /* size of struct upto here */ + register struct field* fd, /* bitfield, containing width */ + register struct type** fdtpp, /* type of selector */ + struct idf* idf, /* name of selector */ + register struct type* stp); /* current struct descriptor */ +#endif #endif diff --git a/lang/cem/cemcom.ansi/switch.c b/lang/cem/cemcom.ansi/switch.c index 4dfcce6aeb..46164cd353 100644 --- a/lang/cem/cemcom.ansi/switch.c +++ b/lang/cem/cemcom.ansi/switch.c @@ -5,153 +5,166 @@ /* $Id$ */ /* S W I T C H - S T A T E M E N T A D M I N I S T R A T I O N */ -#include -#include "parameters.h" -#ifndef LINT -#include +#include +#include +#include +#include +#include "parameters.h" +#ifndef LINT +#include #else -#include "l_em.h" -#endif /* LINT */ -#include -#include -#include "Lpars.h" -#include "label.h" -#include -#include "arith.h" -#include "switch.h" -#include "code.h" -#include "expr.h" -#include "type.h" -#include "sizes.h" -#include "switch.h" -#include "eval.h" -#include "ch3.h" -#include "error.h" +#include "l_em.h" +#endif /* LINT */ +#include +#include +#include "Lpars.h" +#include "label.h" +#include +#include "arith.h" +#include "switch.h" +#include "code.h" +#include "expr.h" +#include "type.h" +#include "sizes.h" +#include "switch.h" +#include "eval.h" +#include "ch3.h" +#include "error.h" extern char options[]; -int density = DENSITY; +int density = DENSITY; static int compact(int nr, writh low, writh up) { /* Careful! up - low might not fit in an arith. And then, - the test "up-low < 0" might also not work to detect this - situation! Or is this just a bug in the M68020/M68000? + the test "up-low < 0" might also not work to detect this + situation! Or is this just a bug in the M68020/M68000? */ writh diff = up - low; return (nr == 0 || (diff >= 0 && diff / nr <= (density - 1))); } -static struct switch_hdr *switch_stack = 0; +static struct switch_hdr* switch_stack = 0; /* (EB 86.05.20) The following rules hold for switch statements: - - the expression E in "switch(E)" shall have integral type (3.6.4.2) - - the expression E in "case E:" is converted to the promoted type - of the controlling expression - For simplicity, we suppose int_size == word_size. + - the expression E in "switch(E)" shall have integral type (3.6.4.2) + - the expression E in "case E:" is converted to the promoted type + of the controlling expression + For simplicity, we suppose int_size == word_size. */ -void code_startswitch(struct expr **expp) +void code_startswitch(struct expr** expp) { /* Check the expression, stack a new case header and - fill in the necessary fields. + fill in the necessary fields. */ label l_table = text_label(); label l_break = text_label(); - struct switch_hdr *sh = new_switch_hdr(); + struct switch_hdr* sh = new_switch_hdr(); int fund = any2arith(expp, SWITCH); - /* INT, LONG, LNGLNG, FLOAT, DOUBLE or LNGDBL */ - - switch (fund) { - case FLOAT: - case DOUBLE: - case LNGDBL: - error("floating point type in switch"); - erroneous2int(expp); - break; + /* INT, LONG, LNGLNG, FLOAT, DOUBLE or LNGDBL */ + + switch (fund) + { + case FLOAT: + case DOUBLE: + case LNGDBL: + error("floating point type in switch"); + erroneous2int(expp); + break; } stack_stmt(l_break, NO_LABEL); sh->sh_break = l_break; /* sh->sh_default = 0; */ sh->sh_table = l_table; /* sh->sh_nrofentries = 0; */ - sh->sh_type = (*expp)->ex_type; /* the expression switched */ + sh->sh_type = (*expp)->ex_type; /* the expression switched */ /* sh->sh_entries = (struct case_entry *) 0; -- case-entry list */ sh->sh_expr = *expp; #ifdef LINT - code_expr(sh->sh_expr, RVAL, TRUE, NO_LABEL, NO_LABEL); + code_expr(sh->sh_expr, RVAL, true, NO_LABEL, NO_LABEL); #endif - sh->next = switch_stack; /* push onto switch-stack */ + sh->next = switch_stack; /* push onto switch-stack */ switch_stack = sh; - C_bra(l_table); /* goto start of switch_table */ + C_bra(l_table); /* goto start of switch_table */ } void code_endswitch(void) { - struct switch_hdr *sh = switch_stack; + struct switch_hdr* sh = switch_stack; label tablabel; - struct case_entry *ce; + struct case_entry* ce; arith size = sh->sh_type->tp_size; - if (sh->sh_default == 0) /* no default occurred yet */ + if (sh->sh_default == 0) /* no default occurred yet */ sh->sh_default = sh->sh_break; #ifndef LINT - C_bra(sh->sh_break); /* skip the switch table now */ - C_df_ilb(sh->sh_table); /* switch table entry */ + C_bra(sh->sh_break); /* skip the switch table now */ + C_df_ilb(sh->sh_table); /* switch table entry */ /* evaluate the switch expr. */ - code_expr(sh->sh_expr, RVAL, TRUE, NO_LABEL, NO_LABEL); - if (sh->sh_nrofentries <= 1) { - if (sh->sh_nrofentries) { + code_expr(sh->sh_expr, RVAL, true, NO_LABEL, NO_LABEL); + if (sh->sh_nrofentries <= 1) + { + if (sh->sh_nrofentries) + { load_cst(sh->sh_lowerbd, size); C_cms(size); C_zeq(sh->sh_entries->ce_label); } - else C_asp(size); + else + C_asp(size); C_bra(sh->sh_default); } - else { - tablabel = data_label(); /* the rom must have a label */ - C_df_dlb(tablabel); - C_rom_ilb(sh->sh_default); - if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) { - /* CSA */ - writh val; - - C_rom_icon(writh2str(sh->sh_lowerbd, 0), size); - C_rom_icon(writh2str(sh->sh_upperbd - sh->sh_lowerbd, 0), - size); - ce = sh->sh_entries; - for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) { - assert(ce); - if (val == ce->ce_value) { - C_rom_ilb(ce->ce_label); - ce = ce->next; + else + { + tablabel = data_label(); /* the rom must have a label */ + C_df_dlb(tablabel); + C_rom_ilb(sh->sh_default); + if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) + { + /* CSA */ + writh val; + + C_rom_icon(writh2str(sh->sh_lowerbd, 0), size); + C_rom_icon(writh2str(sh->sh_upperbd - sh->sh_lowerbd, 0), size); + ce = sh->sh_entries; + for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) + { + assert(ce); + if (val == ce->ce_value) + { + C_rom_ilb(ce->ce_label); + ce = ce->next; + } + else + C_rom_ilb(sh->sh_default); } - else - C_rom_ilb(sh->sh_default); + C_lae_dlb(tablabel, (arith)0); /* perform the switch */ + C_csa(size); } - C_lae_dlb(tablabel, (arith)0); /* perform the switch */ - C_csa(size); - } - else { /* CSB */ - C_rom_icon(writh2str(sh->sh_nrofentries, 0), size); - for (ce = sh->sh_entries; ce; ce = ce->next) { - /* generate the entries: value + prog.label */ - C_rom_icon(writh2str(ce->ce_value, 0), size); - C_rom_ilb(ce->ce_label); + else + { /* CSB */ + C_rom_icon(writh2str(sh->sh_nrofentries, 0), size); + for (ce = sh->sh_entries; ce; ce = ce->next) + { + /* generate the entries: value + prog.label */ + C_rom_icon(writh2str(ce->ce_value, 0), size); + C_rom_ilb(ce->ce_label); + } + C_lae_dlb(tablabel, (arith)0); /* perform the switch */ + C_csb(size); } - C_lae_dlb(tablabel, (arith)0); /* perform the switch */ - C_csb(size); - } } C_df_ilb(sh->sh_break); #endif - switch_stack = sh->next; /* unstack the switch descriptor */ - for (ce = sh->sh_entries; ce;) { /* free allocated switch structure */ - struct case_entry *tmp = ce->next; + switch_stack = sh->next; /* unstack the switch descriptor */ + for (ce = sh->sh_entries; ce;) + { /* free allocated switch structure */ + struct case_entry* tmp = ce->next; free_case_entry(ce); ce = tmp; @@ -160,14 +173,15 @@ void code_endswitch(void) unstack_stmt(); } -void code_case(struct expr *expr) +void code_case(struct expr* expr) { writh val; - struct case_entry *ce; - struct switch_hdr *sh = switch_stack; - + struct case_entry* ce; + struct switch_hdr* sh = switch_stack; + assert(is_cp_cst(expr)); - if (sh == 0) { + if (sh == 0) + { error("case statement not in switch"); return; } @@ -177,50 +191,56 @@ void code_case(struct expr *expr) ce = new_case_entry(); C_df_ilb(ce->ce_label = text_label()); ce->ce_value = val = expr->VL_VALUE; - if (sh->sh_entries == 0) { /* first case entry */ + if (sh->sh_entries == 0) + { /* first case entry */ /* ce->next = (struct case_entry *) 0; */ sh->sh_entries = ce; sh->sh_lowerbd = sh->sh_upperbd = val; sh->sh_nrofentries = 1; } - else { /* second etc. case entry; put ce into proper place */ + else + { /* second etc. case entry; put ce into proper place */ struct case_entry *c1 = sh->sh_entries, *c2 = 0; - + if (val < sh->sh_lowerbd) sh->sh_lowerbd = val; - else - if (val > sh->sh_upperbd) + else if (val > sh->sh_upperbd) sh->sh_upperbd = val; - while (c1 && c1->ce_value < ce->ce_value) { + while (c1 && c1->ce_value < ce->ce_value) + { c2 = c1; c1 = c1->next; } /* At this point three cases are possible: - 1: c1 != 0 && c2 != 0: insert ce somewhere in the middle - 2: c1 != 0 && c2 == 0: insert ce right after the head - 3: c1 == 0 && c2 != 0: append ce to last element - The case c1 == 0 && c2 == 0 cannot occur, since - the list is guaranteed to be non-empty. + 1: c1 != 0 && c2 != 0: insert ce somewhere in the middle + 2: c1 != 0 && c2 == 0: insert ce right after the head + 3: c1 == 0 && c2 != 0: append ce to last element + The case c1 == 0 && c2 == 0 cannot occur, since + the list is guaranteed to be non-empty. */ - if (c1) { - if (c1->ce_value == ce->ce_value) { - error("multiple case entry for value %ld", - ce->ce_value); + if (c1) + { + if (c1->ce_value == ce->ce_value) + { + error("multiple case entry for value %ld", ce->ce_value); free_case_entry(ce); return; } - if (c2) { + if (c2) + { ce->next = c2->next; c2->next = ce; } - else { + else + { ce->next = sh->sh_entries; sh->sh_entries = ce; } } - else { + else + { assert(c2); - ce->next = (struct case_entry *) 0; + ce->next = (struct case_entry*)0; c2->next = ce; } (sh->sh_nrofentries)++; @@ -229,13 +249,15 @@ void code_case(struct expr *expr) void code_default(void) { - struct switch_hdr *sh = switch_stack; + struct switch_hdr* sh = switch_stack; - if (sh == 0) { + if (sh == 0) + { error("default statement not in switch"); return; } - if (sh->sh_default != 0) { + if (sh->sh_default != 0) + { error("multiple entry for default in switch"); return; } diff --git a/lang/cem/cemcom.ansi/switch.str b/lang/cem/cemcom.ansi/switch.str index 3ba693498b..986a08845c 100644 --- a/lang/cem/cemcom.ansi/switch.str +++ b/lang/cem/cemcom.ansi/switch.str @@ -14,34 +14,34 @@ struct expr; /* S W I T C H - T A B L E - S T R U C T U R E */ -struct switch_hdr { - struct switch_hdr *next; +struct switch_hdr +{ + struct switch_hdr* next; label sh_break; label sh_default; label sh_table; int sh_nrofentries; - struct type *sh_type; - struct expr *sh_expr; + struct type* sh_type; + struct expr* sh_expr; writh sh_lowerbd; writh sh_upperbd; - struct case_entry *sh_entries; + struct case_entry* sh_entries; }; /* ALLOCDEF "switch_hdr" 2 */ -struct case_entry { - struct case_entry *next; +struct case_entry +{ + struct case_entry* next; label ce_label; writh ce_value; }; /* ALLOCDEF "case_entry" 20 */ -void code_startswitch(struct expr **expp); +void code_startswitch(struct expr** expp); void code_endswitch(void); -void code_case(struct expr *expr); +void code_case(struct expr* expr); void code_default(void); - - #endif \ No newline at end of file diff --git a/lang/cem/cemcom.ansi/tokenname.c b/lang/cem/cemcom.ansi/tokenname.c index 04553fff72..150998004d 100644 --- a/lang/cem/cemcom.ansi/tokenname.c +++ b/lang/cem/cemcom.ansi/tokenname.c @@ -5,6 +5,8 @@ /* $Id$ */ /* TOKEN NAME DEFINITIONS */ +#include +#include #include "parameters.h" #include "idf.h" #include "arith.h" diff --git a/lang/cem/cemcom.ansi/tokenname.h b/lang/cem/cemcom.ansi/tokenname.h index 1d953fc700..6c61ca7a78 100644 --- a/lang/cem/cemcom.ansi/tokenname.h +++ b/lang/cem/cemcom.ansi/tokenname.h @@ -7,11 +7,12 @@ #ifndef TOKENNAME_H_ #define TOKENNAME_H_ -struct tokenname { /* Used for defining the name of a - token as identified by its symbol - */ +struct tokenname +{ /* Used for defining the name of a +token as identified by its symbol +*/ int tn_symbol; - char *tn_name; + char* tn_name; }; void reserve(struct tokenname resv[]); diff --git a/lang/cem/cemcom.ansi/type.c b/lang/cem/cemcom.ansi/type.c index a0f41b3327..feda46bf9b 100644 --- a/lang/cem/cemcom.ansi/type.c +++ b/lang/cem/cemcom.ansi/type.c @@ -5,50 +5,49 @@ /* $Id$ */ /* T Y P E D E F I N I T I O N M E C H A N I S M */ -#include "parameters.h" -#include -#include "idf.h" -#include "Lpars.h" -#include "arith.h" -#include "type.h" -#include "def.h" -#include "proto.h" -#include "sizes.h" -#include "align.h" -#include "decspecs.h" -#include "error.h" - - +#include +#include +#include "parameters.h" +#include +#include +#include "idf.h" +#include "Lpars.h" +#include "arith.h" +#include "type.h" +#include "def.h" +#include "proto.h" +#include "sizes.h" +#include "align.h" +#include "decspecs.h" +#include "error.h" /* To be created dynamically in main() from defaults or from command line parameters. */ -struct type *schar_type, *uchar_type, *short_type, *ushort_type, *word_type, - *uword_type, *int_type, *uint_type, *long_type, *ulong_type, - *lnglng_type, *ulnglng_type, - *float_type, *double_type, *lngdbl_type, *void_type, *string_type, - *funint_type, *error_type; +struct type *schar_type, *uchar_type, *short_type, *ushort_type, *word_type, *uword_type, *int_type, + *uint_type, *long_type, *ulong_type, *lnglng_type, *ulnglng_type, *float_type, *double_type, + *lngdbl_type, *void_type, *string_type, *funint_type, *error_type; -struct type *pa_type; /* Pointer-Arithmetic type */ +struct type* pa_type; /* Pointer-Arithmetic type */ -struct type *create_type(int fund) +struct type* create_type(int fund) { /* A brand new struct type is created, and its tp_fund set to fund. */ - struct type *ntp = new_type(); + struct type* ntp = new_type(); ntp->tp_fund = fund; - ntp->tp_size = (arith) -1; + ntp->tp_size = (arith)-1; return ntp; } -struct type *promoted_type(struct type *tp) +struct type* promoted_type(struct type* tp) { if (tp->tp_fund == CHAR || tp->tp_fund == SHORT) { - if (tp->tp_unsigned && (int) tp->tp_size == (int) int_size) + if (tp->tp_unsigned && (int)tp->tp_size == (int)int_size) return uint_type; else return int_type; @@ -59,62 +58,65 @@ struct type *promoted_type(struct type *tp) return tp; } -struct type *construct_type(int fund, struct type *tp, int qual, -arith count, /* for fund == ARRAY only */ -struct proto *pl) +struct type* construct_type( + int fund, + struct type* tp, + int qual, + arith count, /* for fund == ARRAY only */ + struct proto* pl) { /* fund must be a type constructor: FIELD, FUNCTION, POINTER or ARRAY. The pointer to the constructed type is returned. */ - struct type *dtp; + struct type* dtp; switch (fund) { #ifndef NOBITFIELD - case FIELD: - dtp = field_of(tp, qual); - break; + case FIELD: + dtp = field_of(tp, qual); + break; #endif /* NOBITFIELD */ - case FUNCTION: - if (tp->tp_fund == FUNCTION) - { - error("function cannot yield function"); - return error_type; - } - if (tp->tp_fund == ARRAY) - { - error("function cannot yield array"); - return error_type; - } - - dtp = function_of(tp, pl, qual); - break; - case POINTER: - dtp = pointer_to(tp, qual); - break; - case ARRAY: - if (tp->tp_fund == VOID) - { - error("cannot construct array of void"); - count = (arith) -1; - } - dtp = array_of(tp, count, qual); - break; - default: - crash("bad constructor in construct_type"); - UNREACHABLE_CODE; + case FUNCTION: + if (tp->tp_fund == FUNCTION) + { + error("function cannot yield function"); + return error_type; + } + if (tp->tp_fund == ARRAY) + { + error("function cannot yield array"); + return error_type; + } + + dtp = function_of(tp, pl, qual); + break; + case POINTER: + dtp = pointer_to(tp, qual); + break; + case ARRAY: + if (tp->tp_fund == VOID) + { + error("cannot construct array of void"); + count = (arith)-1; + } + dtp = array_of(tp, count, qual); + break; + default: + crash("bad constructor in construct_type"); + UNREACHABLE_CODE; } return dtp; } -struct type *function_of(struct type *tp, struct proto *pl, int qual) +struct type* function_of(struct type* tp, struct proto* pl, int qual) { #if 0 /* See comment below */ struct type *dtp = tp->tp_function; #else - struct type *dtp; + struct type* dtp; #endif /* look for a type with the right qualifier */ @@ -151,9 +153,9 @@ struct type *function_of(struct type *tp, struct proto *pl, int qual) return dtp; } -struct type *pointer_to(struct type *tp, int qual) +struct type* pointer_to(struct type* tp, int qual) { - struct type *dtp = tp->tp_pointer; + struct type* dtp = tp->tp_pointer; /* look for a type with the right qualifier */ while (dtp && dtp->tp_typequal != qual) @@ -173,9 +175,9 @@ struct type *pointer_to(struct type *tp, int qual) return dtp; } -struct type * array_of(struct type *tp, arith count, int qual) +struct type* array_of(struct type* tp, arith count, int qual) { - struct type *dtp = tp->tp_array; + struct type* dtp = tp->tp_array; /* look for a type with the right size */ while (dtp && (dtp->tp_nel != count || dtp->tp_typequal != qual)) @@ -201,9 +203,9 @@ struct type * array_of(struct type *tp, arith count, int qual) } #ifndef NOBITFIELD -struct type * field_of(struct type *tp, int qual) +struct type* field_of(struct type* tp, int qual) { - struct type *dtp = create_type(FIELD); + struct type* dtp = create_type(FIELD); dtp->tp_up = tp; dtp->tp_align = tp->tp_align; @@ -213,30 +215,30 @@ struct type * field_of(struct type *tp, int qual) } #endif /* NOBITFIELD */ -arith size_of_type(struct type *tp, char nm[]) +arith size_of_type(struct type* tp, char nm[]) { arith sz = tp->tp_size; if (sz < 0) { error("size of %s unknown", nm); - sz = (arith) 1; + sz = (arith)1; } return sz; } -void idf2type(struct idf *idf, struct type **tpp) +void idf2type(struct idf* idf, struct type** tpp) { /* Decoding a typedef-ed identifier or basic type: if the size is yet unknown we have to make copy of the type descriptor to prevent garbage at the initialisation of arrays with unknown size. */ - struct type *tp = idf->id_def->df_type; + struct type* tp = idf->id_def->df_type; if (*tpp) error("multiple types in declaration"); - if (tp->tp_size < (arith) 0 && tp->tp_fund == ARRAY) + if (tp->tp_size < (arith)0 && tp->tp_fund == ARRAY) { *tpp = new_type(); **tpp = *tp; @@ -253,9 +255,9 @@ arith align(arith pos, int al) return ((pos + al - 1) / al) * al; } -struct type * standard_type(int fund, int sgn, int algn, arith sz) +struct type* standard_type(int fund, int sgn, int algn, arith sz) { - struct type *tp = create_type(fund); + struct type* tp = create_type(fund); tp->tp_unsigned = sgn != 0; tp->tp_align = algn; @@ -264,24 +266,24 @@ struct type * standard_type(int fund, int sgn, int algn, arith sz) return tp; } -void completed(struct type *tp) +void completed(struct type* tp) { - struct type *atp = tp->tp_array; - struct type *etp = tp; + struct type* atp = tp->tp_array; + struct type* etp = tp; switch (etp->tp_fund) { - case STRUCT: - case UNION: - case ENUM: - while ( (etp = etp->next) !=0) - { - if (!etp->tp_sdef) - etp->tp_sdef = tp->tp_sdef; - etp->tp_size = tp->tp_size; - etp->tp_align = tp->tp_align; - } - break; + case STRUCT: + case UNION: + case ENUM: + while ((etp = etp->next) != 0) + { + if (!etp->tp_sdef) + etp->tp_sdef = tp->tp_sdef; + etp->tp_size = tp->tp_size; + etp->tp_align = tp->tp_align; + } + break; } while (atp) { diff --git a/lang/cem/cemcom.ansi/type.str b/lang/cem/cemcom.ansi/type.str index ada3662315..59a0ed0ba1 100644 --- a/lang/cem/cemcom.ansi/type.str +++ b/lang/cem/cemcom.ansi/type.str @@ -7,20 +7,19 @@ #ifndef TYPE_H_ #define TYPE_H_ -#include "parameters.h" -#include "arith.h" +#include "parameters.h" +#include "arith.h" - - -struct type { - struct type *next; /* used for ARRAY and for qualifiers */ - short tp_fund; /* fundamental type */ +struct type +{ + struct type* next; /* used for ARRAY and for qualifiers */ + short tp_fund; /* fundamental type */ char tp_unsigned; - char tp_typequal; /* type qualifier */ + char tp_typequal; /* type qualifier */ int tp_align; - arith tp_size; /* -1 if declared but not defined */ - struct type *tp_pointer; /* to POINTER */ - struct type *tp_array; /* to ARRAY */ + arith tp_size; /* -1 if declared but not defined */ + struct type* tp_pointer; /* to POINTER */ + struct type* tp_array; /* to ARRAY */ #ifdef DBSYMTAB int tp_dbindex; #endif @@ -28,75 +27,74 @@ struct type { /* This field is not needed now; see comment in function_of() routine. */ struct type *tp_function; /* to FUNCTION */ #endif - union { - struct { - struct idf *tp__idf; /* name of STRUCT, UNION or ENUM */ - struct sdef *tp__sdef; /* to first selector */ - } tp_istagged; /* used with STRUCT, UNION & ENUM */ - struct { - /* tp__up: from FIELD, POINTER, ARRAY or FUNCTION to fund. */ - struct type *tp__up; - union { - arith tp__nel; /* # of elements for array */ - /* tp__field: field descriptor if fund == FIELD */ - struct field *tp__field; - struct { - /* prototype list (pseudoproto for old_style def) */ - struct proto *tp__proto; - struct proto *tp__pseudoproto; - } tp_isfunc; - } tp_f; /* FIELD or FUNCTION */ - } tp_nottagged; /* used with POINTER, FIELD, ARRAY & FUNCTION */ + union + { + struct + { + struct idf* tp__idf; /* name of STRUCT, UNION or ENUM */ + struct sdef* tp__sdef; /* to first selector */ + } tp_istagged; /* used with STRUCT, UNION & ENUM */ + struct + { + /* tp__up: from FIELD, POINTER, ARRAY or FUNCTION to fund. */ + struct type* tp__up; + union + { + arith tp__nel; /* # of elements for array */ + /* tp__field: field descriptor if fund == FIELD */ + struct field* tp__field; + struct + { + /* prototype list (pseudoproto for old_style def) */ + struct proto* tp__proto; + struct proto* tp__pseudoproto; + } tp_isfunc; + } tp_f; /* FIELD or FUNCTION */ + } tp_nottagged; /* used with POINTER, FIELD, ARRAY & FUNCTION */ } tp_union; }; -#define tp_idf tp_union.tp_istagged.tp__idf -#define tp_sdef tp_union.tp_istagged.tp__sdef -#define tp_up tp_union.tp_nottagged.tp__up -#define tp_field tp_union.tp_nottagged.tp_f.tp__field -#define tp_nel tp_union.tp_nottagged.tp_f.tp__nel -#define tp_proto tp_union.tp_nottagged.tp_f.tp_isfunc.tp__proto -#define tp_pseudoproto tp_union.tp_nottagged.tp_f.tp_isfunc.tp__pseudoproto +#define tp_idf tp_union.tp_istagged.tp__idf +#define tp_sdef tp_union.tp_istagged.tp__sdef +#define tp_up tp_union.tp_nottagged.tp__up +#define tp_field tp_union.tp_nottagged.tp_f.tp__field +#define tp_nel tp_union.tp_nottagged.tp_f.tp__nel +#define tp_proto tp_union.tp_nottagged.tp_f.tp_isfunc.tp__proto +#define tp_pseudoproto tp_union.tp_nottagged.tp_f.tp_isfunc.tp__pseudoproto /* Type qualifiers. Note: TQ_VOLATILE and TQ_CONST can be - 'ored' to specify: extern const volatile int a; + 'ored' to specify: extern const volatile int a; */ -#define TQ_VOLATILE 0x01 -#define TQ_CONST 0x02 +#define TQ_VOLATILE 0x01 +#define TQ_CONST 0x02 +extern struct type *schar_type, *uchar_type, *short_type, *ushort_type, *word_type, *uword_type, + *int_type, *uint_type, *long_type, *ulong_type, *lnglng_type, *ulnglng_type, *float_type, + *double_type, *lngdbl_type, *void_type, *string_type, *funint_type, *error_type; -extern struct type - *schar_type, *uchar_type, - *short_type, *ushort_type, - *word_type, *uword_type, - *int_type, *uint_type, - *long_type, *ulong_type, - *lnglng_type, *ulnglng_type, - *float_type, *double_type, *lngdbl_type, - *void_type, - *string_type, *funint_type, *error_type; +extern struct type* pa_type; /* type.c */ -extern struct type *pa_type; /* type.c */ - -struct type *create_type(int fund); -struct type *promoted_type(struct type *tp); -struct type *construct_type(int fund, register struct type *tp, int qual, -arith count, /* for fund == ARRAY only */ - register struct proto *pl); -struct type *function_of(register struct type *tp, struct proto *pl, int qual); -struct type *pointer_to(register struct type *tp, int qual); -struct type * array_of(register struct type *tp, arith count, int qual); +struct type* create_type(int fund); +struct type* promoted_type(struct type* tp); +struct type* construct_type( + int fund, + register struct type* tp, + int qual, + arith count, /* for fund == ARRAY only */ + register struct proto* pl); +struct type* function_of(register struct type* tp, struct proto* pl, int qual); +struct type* pointer_to(register struct type* tp, int qual); +struct type* array_of(register struct type* tp, arith count, int qual); #ifndef NOBITFIELD -struct type * field_of(register struct type *tp, int qual); +struct type* field_of(register struct type* tp, int qual); #endif /* NOBITFIELD */ -arith size_of_type(struct type *tp, char nm[]); -void idf2type(struct idf *idf, struct type **tpp); +arith size_of_type(struct type* tp, char nm[]); +void idf2type(struct idf* idf, struct type** tpp); arith align(arith pos, int al); -struct type * standard_type(int fund, int sgn, int algn, arith sz); -void completed(struct type *tp); +struct type* standard_type(int fund, int sgn, int algn, arith sz); +void completed(struct type* tp); int no_long_long(void); - /* ALLOCDEF "type" 50 */ #endif \ No newline at end of file diff --git a/lang/cem/cemcom.ansi/util.c b/lang/cem/cemcom.ansi/util.c index 53abc3c402..65fb699609 100644 --- a/lang/cem/cemcom.ansi/util.c +++ b/lang/cem/cemcom.ansi/util.c @@ -8,30 +8,32 @@ /* $Id$ */ /* Code for the allocation and de-allocation of temporary variables, - allowing re-use. + allowing re-use. */ -#include "parameters.h" -#ifndef LINT -#include +#include +#include +#include "parameters.h" +#ifndef LINT +#include #else -#include "l_em.h" -#endif /* LINT */ -#include -#include -#include -#include - -#include "util.h" -#include "sizes.h" -#include "align.h" -#include "stack.h" -#include "Lpars.h" -#include "def.h" - -static struct localvar *FreeTmps; +#include "l_em.h" +#endif /* LINT */ +#include +#include +#include +#include + +#include "util.h" +#include "sizes.h" +#include "align.h" +#include "stack.h" +#include "Lpars.h" +#include "def.h" + +static struct localvar* FreeTmps; #ifdef USE_TMP -static int loc_id; +static int loc_id; #endif /* USE_TMP */ #ifdef PEEPHOLE @@ -50,36 +52,38 @@ void LocalInit(void) arith LocalSpace(arith sz, int al) { - struct stack_level *stl = local_level; + struct stack_level* stl = local_level; - stl->sl_max_block = - align(sz - stl->sl_max_block, al); + stl->sl_max_block = -align(sz - stl->sl_max_block, al); return stl->sl_max_block; } #define TABSIZ 32 -static struct localvar *regs[TABSIZ]; +static struct localvar* regs[TABSIZ]; arith NewLocal(arith sz, int al, int regtype, int sc) { - struct localvar *tmp = FreeTmps; - struct localvar *prev = 0; + struct localvar* tmp = FreeTmps; + struct localvar* prev = 0; int index; - while (tmp) { - if (tmp->t_align >= al && - tmp->t_size >= sz && - tmp->t_sc == sc && - tmp->t_regtype == regtype) { - if (prev) { + while (tmp) + { + if (tmp->t_align >= al && tmp->t_size >= sz && tmp->t_sc == sc && tmp->t_regtype == regtype) + { + if (prev) + { prev->next = tmp->next; } - else FreeTmps = tmp->next; + else + FreeTmps = tmp->next; break; } prev = tmp; tmp = tmp->next; } - if (! tmp) { + if (!tmp) + { tmp = new_localvar(); tmp->t_offset = LocalSpace(sz, al); tmp->t_align = al; @@ -88,7 +92,7 @@ arith NewLocal(arith sz, int al, int regtype, int sc) tmp->t_regtype = regtype; tmp->t_count = REG_DEFAULT; } - index = (int) (tmp->t_offset >> 2) & (TABSIZ - 1); + index = (int)(tmp->t_offset >> 2) & (TABSIZ - 1); tmp->next = regs[index]; regs[index] = tmp; return tmp->t_offset; @@ -96,17 +100,21 @@ arith NewLocal(arith sz, int al, int regtype, int sc) void FreeLocal(arith off) { - int index = (int) (off >> 2) & (TABSIZ - 1); - struct localvar *tmp = regs[index]; - struct localvar *prev = 0; + int index = (int)(off >> 2) & (TABSIZ - 1); + struct localvar* tmp = regs[index]; + struct localvar* prev = 0; - while (tmp && tmp->t_offset != off) { + while (tmp && tmp->t_offset != off) + { prev = tmp; tmp = tmp->next; } - if (tmp) { - if (prev) prev->next = tmp->next; - else regs[index] = tmp->next; + if (tmp) + { + if (prev) + prev->next = tmp->next; + else + regs[index] = tmp->next; tmp->next = FreeTmps; FreeTmps = tmp; } @@ -121,26 +129,30 @@ void LocalFinish(void) C_beginpart(loc_id); #endif tmp = FreeTmps; - while (tmp) { + while (tmp) + { tmp1 = tmp; - if (tmp->t_sc == REGISTER) tmp->t_count += REG_BONUS; - if (! options['n'] && tmp->t_regtype >= 0) { + if (tmp->t_sc == REGISTER) + tmp->t_count += REG_BONUS; + if (!options['n'] && tmp->t_regtype >= 0) + { C_ms_reg(tmp->t_offset, tmp->t_size, tmp->t_regtype, tmp->t_count); } tmp = tmp->next; free_localvar(tmp1); } FreeTmps = 0; - for (i = 0; i < TABSIZ; i++) { + for (i = 0; i < TABSIZ; i++) + { tmp = regs[i]; - while (tmp) { - if (tmp->t_sc == REGISTER) tmp->t_count += REG_BONUS; + while (tmp) + { + if (tmp->t_sc == REGISTER) + tmp->t_count += REG_BONUS; tmp1 = tmp; - if (! options['n'] && tmp->t_regtype >= 0) { - C_ms_reg(tmp->t_offset, - tmp->t_size, - tmp->t_regtype, - tmp->t_count); + if (!options['n'] && tmp->t_regtype >= 0) + { + C_ms_reg(tmp->t_offset, tmp->t_size, tmp->t_regtype, tmp->t_count); } tmp = tmp->next; free_localvar(tmp1); @@ -148,7 +160,8 @@ void LocalFinish(void) regs[i] = 0; } #ifdef PEEPHOLE - if (! options['n']) { + if (!options['n']) + { C_mes_begin(ms_reg); C_mes_end(); } @@ -160,13 +173,14 @@ void LocalFinish(void) void RegisterAccount(arith offset, arith size, int regtype, int sc) { - struct localvar *p; + struct localvar* p; int index; - if (regtype < 0) return; + if (regtype < 0) + return; p = new_localvar(); - index = (int) (offset >> 2) & (TABSIZ - 1); + index = (int)(offset >> 2) & (TABSIZ - 1); p->t_offset = offset; p->t_regtype = regtype; p->t_count = REG_DEFAULT; @@ -176,28 +190,35 @@ void RegisterAccount(arith offset, arith size, int regtype, int sc) regs[index] = p; } -static struct localvar *find_reg(arith off) +static struct localvar* find_reg(arith off) { - struct localvar *p = regs[(int)(off >> 2) & (TABSIZ - 1)]; + struct localvar* p = regs[(int)(off >> 2) & (TABSIZ - 1)]; - while (p && p->t_offset != off) p = p->next; + while (p && p->t_offset != off) + p = p->next; return p; } void LoadLocal(arith off, arith sz) { - struct localvar *p = find_reg(off); + struct localvar* p = find_reg(off); #ifdef USE_TMP #ifdef REGCOUNT - if (p) p->t_count++; + if (p) + p->t_count++; #endif #endif - if (p && p->t_size != sz) p->t_regtype = -1; - if (sz == word_size) C_lol(off); - else if (sz == dword_size) C_ldl(off); - else { - if (p) p->t_regtype = -1; + if (p && p->t_size != sz) + p->t_regtype = -1; + if (sz == word_size) + C_lol(off); + else if (sz == dword_size) + C_ldl(off); + else + { + if (p) + p->t_regtype = -1; C_lal(off); C_loi(sz); } @@ -205,29 +226,36 @@ void LoadLocal(arith off, arith sz) void StoreLocal(arith off, arith sz) { - struct localvar *p = find_reg(off); + struct localvar* p = find_reg(off); #ifdef USE_TMP #ifdef REGCOUNT - if (p) p->t_count++; + if (p) + p->t_count++; #endif #endif - if (p && p->t_size != sz) p->t_regtype = -1; - if (sz == word_size) C_stl(off); - else if (sz == dword_size) C_sdl(off); - else { - if (p) p->t_regtype = -1; + if (p && p->t_size != sz) + p->t_regtype = -1; + if (sz == word_size) + C_stl(off); + else if (sz == dword_size) + C_sdl(off); + else + { + if (p) + p->t_regtype = -1; C_lal(off); C_sti(sz); } } -#ifndef LINT +#ifndef LINT void AddrLocal(arith off) { - struct localvar *p = find_reg(off); + struct localvar* p = find_reg(off); - if (p) p->t_regtype = -1; + if (p) + p->t_regtype = -1; C_lal(off); } -#endif /* LINT */ +#endif /* LINT */ diff --git a/lang/cem/cemcom.ansi/util.str b/lang/cem/cemcom.ansi/util.str index 1e3855e3cc..804433b0f3 100644 --- a/lang/cem/cemcom.ansi/util.str +++ b/lang/cem/cemcom.ansi/util.str @@ -3,14 +3,15 @@ #include "arith.h" -struct localvar { - struct localvar *next; - arith t_offset; /* offset from LocalBase */ - arith t_size; - int t_align; - int t_regtype; - int t_count; - int t_sc; /* storage class */ +struct localvar +{ + struct localvar* next; + arith t_offset; /* offset from LocalBase */ + arith t_size; + int t_align; + int t_regtype; + int t_count; + int t_sc; /* storage class */ }; /* ALLOCDEF "localvar" 10 */ @@ -24,7 +25,7 @@ void RegisterAccount(arith offset, arith size, int regtype, int sc); void LoadLocal(arith off, arith sz); void StoreLocal(arith off, arith sz); -#ifndef LINT +#ifndef LINT void AddrLocal(arith off); #endif diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index b753152720..3a899c98db 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -385,7 +385,7 @@ do_return_expr(expr) a return statement with an expression. */ ch7cast(&expr, RETURN, func_type); - code_expr(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); + code_expr(expr, RVAL, true, NO_LABEL, NO_LABEL); C_bra(return_label); return_expr_occurred = 1; } @@ -540,7 +540,7 @@ loc_init(expr, id) { struct value vl; - EVAL(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); + EVAL(expr, RVAL, true, NO_LABEL, NO_LABEL); vl.vl_class = Name; vl.vl_data.vl_idf = id; vl.vl_value = (arith)0; diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index 0a14ecf3b0..231db6a756 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -69,7 +69,7 @@ EVAL(expr, val, code, true_label, false_label) int val, code; label true_label, false_label; { - int gencode = (code == TRUE && expr->ex_type->tp_size > 0); + int gencode = (code == true && expr->ex_type->tp_size > 0); switch (expr->ex_class) { case Value: /* just a simple value */ @@ -523,7 +523,7 @@ EVAL(expr, val, code, true_label, false_label) #endif /* DATAFLOW */ } else { - EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); + EVAL(left, LVAL, true, NO_LABEL, NO_LABEL); C_cai(); } /* remove parameters from stack */ @@ -552,7 +552,7 @@ EVAL(expr, val, code, true_label, false_label) C_adp(right->VL_VALUE); break; case ',': - EVAL(left, RVAL, FALSE, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, false, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, true_label, false_label); break; case '~': @@ -566,7 +566,7 @@ EVAL(expr, val, code, true_label, false_label) label l_false = text_label(); label l_end = text_label(); - EVAL(left, RVAL, TRUE, l_true, l_false); + EVAL(left, RVAL, true, l_true, l_false); C_df_ilb(l_true); EVAL(right->OP_LEFT, RVAL, gencode, NO_LABEL, NO_LABEL); C_bra(l_end); @@ -589,7 +589,7 @@ EVAL(expr, val, code, true_label, false_label) l_true = gencode ? text_label(): l_false; } - EVAL(left, RVAL, TRUE, oper == AND ? l_maybe : l_true, + EVAL(left, RVAL, true, oper == AND ? l_maybe : l_true, oper == AND ? l_false : l_maybe); C_df_ilb(l_maybe); EVAL(right, RVAL, gencode, l_true, l_false); diff --git a/lang/cem/cemcom/field.c b/lang/cem/cemcom/field.c index 8ecdb22fc4..4ac4e47e7d 100644 --- a/lang/cem/cemcom/field.c +++ b/lang/cem/cemcom/field.c @@ -62,11 +62,11 @@ eval_field(expr, code) if (op == '=') { /* F = E: f = ((E & mask)<ex_type); - EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); + EVAL(rightop, RVAL, true, NO_LABEL, NO_LABEL); conversion(tp, atype); C_loc(fd->fd_mask); C_and(asize); - if (code == TRUE) + if (code == true) C_dup(asize); C_loc((arith)fd->fd_shift); if (atype->tp_unsigned) @@ -83,7 +83,7 @@ eval_field(expr, code) else { /* complex case */ tmpvar = NewLocal(pointer_size, pointer_align, reg_pointer, 0); - EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); + EVAL(leftop, LVAL, true, NO_LABEL, NO_LABEL); C_dup(pointer_size); StoreLocal(tmpvar, pointer_size); C_loi(asize); @@ -103,7 +103,7 @@ eval_field(expr, code) else { /* complex case */ tmpvar = NewLocal(pointer_size, pointer_align, reg_pointer, 0); - EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); + EVAL(leftop, LVAL, true, NO_LABEL, NO_LABEL); C_dup(pointer_size); StoreLocal(tmpvar, pointer_size); C_loi(asize); @@ -121,10 +121,10 @@ eval_field(expr, code) C_loc(bits_in_type - fd->fd_width); C_sri(asize); } - if (code == TRUE && (op == POSTINCR || op == POSTDECR)) + if (code == true && (op == POSTINCR || op == POSTDECR)) C_dup(asize); conversion(atype, rightop->ex_type); - EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); + EVAL(rightop, RVAL, true, NO_LABEL, NO_LABEL); /* the 'op' operation: */ if (op == PLUSPLUS || op == POSTINCR) assop(rightop->ex_type, PLUSAB); @@ -136,7 +136,7 @@ eval_field(expr, code) conversion(rightop->ex_type, atype); C_loc(fd->fd_mask); C_and(asize); - if (code == TRUE && op != POSTINCR && op != POSTDECR) + if (code == true && op != POSTINCR && op != POSTDECR) C_dup(asize); C_loc((arith)fd->fd_shift); if (atype->tp_unsigned) @@ -160,7 +160,7 @@ eval_field(expr, code) FreeLocal(tmpvar); } } - if (code == TRUE) { + if (code == true) { /* Take care that the effective value stored in the bit field (i.e. the value that is got on retrieval) is on top of stack. diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index 011edcd55d..81578d4c80 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -87,7 +87,7 @@ code_startswitch(expp) sh->sh_entries = (struct case_entry *) 0; /* case-entry list */ sh->sh_expr = *expp; #ifdef LINT - code_expr(sh->sh_expr, RVAL, TRUE, NO_LABEL, NO_LABEL); + code_expr(sh->sh_expr, RVAL, true, NO_LABEL, NO_LABEL); #endif sh->next = switch_stack; /* push onto switch-stack */ switch_stack = sh; @@ -106,7 +106,7 @@ code_endswitch() C_df_ilb(sh->sh_table); /* switch table entry */ /* evaluate the switch expr. */ #ifndef LINT - code_expr(sh->sh_expr, RVAL, TRUE, NO_LABEL, NO_LABEL); + code_expr(sh->sh_expr, RVAL, true, NO_LABEL, NO_LABEL); #endif tablabel = data_label(); /* the rom must have a label */ C_df_dlb(tablabel); diff --git a/lang/fortran/comp/output.c b/lang/fortran/comp/output.c index 2ff39af990..51a26de1cd 100644 --- a/lang/fortran/comp/output.c +++ b/lang/fortran/comp/output.c @@ -25,13 +25,6 @@ this software. #include "names.h" #include "output.h" -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif - char _assoc_table[] = { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }; /* Opcode table -- This array is indexed by the OP_____ macros defined in @@ -990,12 +983,12 @@ expptr len, name, args; /* It should be in place from putcall(), so we won't touch it explicitly */ } /* if ret_val */ - done_once = ret_val ? TRUE : FALSE; + done_once = ret_val ? true : false; /* Now run through the named arguments */ narg = -1; - for (cp = arglist; cp; cp = cp -> nextp, done_once = TRUE) { + for (cp = arglist; cp; cp = cp -> nextp, done_once = true) { if (done_once) nice_printf (outfile, ", "); diff --git a/lang/fortran/comp/parse_args.c b/lang/fortran/comp/parse_args.c index 193f7fd68b..0f5cd6c7b9 100644 --- a/lang/fortran/comp/parse_args.c +++ b/lang/fortran/comp/parse_args.c @@ -73,13 +73,7 @@ this software. #define arg_result_ptr(x) ((x).result_ptr) #define arg_table_size(x) ((x).table_size) -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -typedef int boolean; +typedef bool boolean; char *lower_string (/* char [], char * */); @@ -115,7 +109,7 @@ int other_count; init_store (table, entries); if (result) { - boolean use_prefix = TRUE; + boolean use_prefix = true; char *argv0; argc--; @@ -151,10 +145,10 @@ int other_count; if (length >= strlen (*argv)) { argc--; argv0 = *++argv; - use_prefix = TRUE; + use_prefix = true; } else { (*argv) += length; - use_prefix = FALSE; + use_prefix = false; } /* else */ /* Parse any necessary arguments */ @@ -169,10 +163,10 @@ int other_count; else if (length >= strlen (*argv)) { argc--; argv0 = *++argv; - use_prefix = TRUE; + use_prefix = true; } else { (*argv) += length; - use_prefix = FALSE; + use_prefix = false; } /* else */ } /* if (argv_count != P_NO_ARGS) */ else @@ -252,7 +246,7 @@ int entries; } /* for i = 0 */ - return TRUE; + return true; } /* arg_verify */ @@ -317,7 +311,7 @@ boolean use_prefix; { char *norm_prefix = arg_prefix (*entry); char *norm_string = arg_string (*entry); - boolean prefix_match = FALSE, string_match = FALSE; + boolean prefix_match = false, string_match = false; int result = 0; /* Buffers for the lowercased versions of the strings being compared. diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index 9ec3b35daa..a2d279e2f5 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -10,65 +10,69 @@ /* $Id$ */ /* Code generation for expressions and coercions -*/ - -#include "parameters.h" -#include "debug.h" - -#include -#include -#include "em_arith.h" -#include "em_label.h" -#include "em_code.h" -#include "em_abs.h" -#include "alloc.h" - -#include "code.h" -#include "type.h" -#include "error.h" -#include "LLlex.h" -#include "def.h" -#include "scope.h" -#include "desig.h" -#include "chk_expr.h" -#include "node.h" -#include "Lpars.h" -#include "tmpvar.h" -#include "standards.h" -#include "walk.h" - -extern int proclevel; -extern char options[]; -extern struct desig null_desig; -int fp_used; + */ + +#include "parameters.h" +#include "debug.h" + +#include +#include +#include "em_arith.h" +#include "em_label.h" +#include "em_code.h" +#include "em_abs.h" +#include "alloc.h" + +#include "code.h" +#include "type.h" +#include "error.h" +#include "LLlex.h" +#include "def.h" +#include "scope.h" +#include "desig.h" +#include "chk_expr.h" +#include "node.h" +#include "Lpars.h" +#include "tmpvar.h" +#include "standards.h" +#include "walk.h" + +extern int proclevel; +extern char options[]; +extern struct desig null_desig; +int fp_used; /* Forward declarations */ -static void CodeParameters(struct paramlist *, struct node *); -static void CodeStd(struct node *); +static void CodeParameters(struct paramlist*, struct node*); +static void CodeStd(struct node*); static void compare(int, label); static void truthvalue(int); -static void CodeUoper(struct node *); -static void CodeSet(struct node *, int); -static void CodeEl(struct node *, struct type *, int); -static void CodeDAddress(struct node *, int); -static void DoHIGH(struct def *); +static void CodeUoper(struct node*); +static void CodeSet(struct node*, int); +static void CodeEl(struct node*, struct type*, int); +static void CodeDAddress(struct node*, int); +static void DoHIGH(struct def*); void CodeConst(arith cst, int size) { - if (size <= (int) word_size) { + if (size <= (int)word_size) + { C_loc(cst); } - else if (size == (int) dword_size) { + else if (size == (int)dword_size) + { C_ldc(cst); } - else { + else + { crash("(CodeConst)"); } } -void CodeString(struct node *nd) +void CodeString(struct node* nd) { - if (nd->nd_type->tp_fund != T_STRING) { + if (nd->nd_type->tp_fund != T_STRING) + { /* Character constant */ CodeConst(nd->nd_INT, nd->nd_type->tp_size); return; @@ -78,104 +82,117 @@ void CodeString(struct node *nd) c_lae_dlb(data_label); } -void CodeExpr(struct node *nd, struct desig *ds, label true_label, label false_label) +void CodeExpr(struct node* nd, struct desig* ds, label true_label, label false_label) { - struct type *tp = nd->nd_type; + struct type* tp = nd->nd_type; DoLineno(nd); - if (tp->tp_fund == T_REAL) fp_used = 1; - switch(nd->nd_class) { - case Def: - if (nd->nd_def->df_kind & (D_PROCEDURE|D_PROCHEAD)) { - C_lpi(nd->nd_def->prc_name); - ds->dsg_kind = DSG_LOADED; - break; - } - /* Fall through */ - - case Link: - case Arrsel: - case Arrow: - CodeDesig(nd, ds); - break; + if (tp->tp_fund == T_REAL) + fp_used = 1; + switch (nd->nd_class) + { + case Def: + if (nd->nd_def->df_kind & (D_PROCEDURE | D_PROCHEAD)) + { + C_lpi(nd->nd_def->prc_name); + ds->dsg_kind = DSG_LOADED; + break; + } + /* Fall through */ - case Oper: - CodeOper(nd, true_label, false_label); - ds->dsg_kind = DSG_LOADED; - true_label = NO_LABEL; - break; + case Link: + case Arrsel: + case Arrow: + CodeDesig(nd, ds); + break; - case Uoper: - CodeUoper(nd); - ds->dsg_kind = DSG_LOADED; - break; + case Oper: + CodeOper(nd, true_label, false_label); + ds->dsg_kind = DSG_LOADED; + true_label = NO_LABEL; + break; - case Value: - switch(nd->nd_symb) { - case REAL: - C_df_dlb(++data_label); - if (! nd->nd_RSTR) { - static char buf[FLT_STRLEN]; + case Uoper: + CodeUoper(nd); + ds->dsg_kind = DSG_LOADED; + break; - flt_flt2str(&nd->nd_RVAL, buf, FLT_STRLEN); - C_rom_fcon(buf, tp->tp_size); + case Value: + switch (nd->nd_symb) + { + case REAL: + C_df_dlb(++data_label); + if (!nd->nd_RSTR) + { + static char buf[FLT_STRLEN]; + + flt_flt2str(&nd->nd_RVAL, buf, FLT_STRLEN); + C_rom_fcon(buf, tp->tp_size); + } + else + C_rom_fcon(nd->nd_RSTR, tp->tp_size); + c_lae_dlb(data_label); + C_loi(tp->tp_size); + break; + case STRING: + CodeString(nd); + break; + case INTEGER: + CodeConst(nd->nd_INT, (int)(tp->tp_size)); + break; + default: + crash("Value error"); } - else C_rom_fcon(nd->nd_RSTR, tp->tp_size); - c_lae_dlb(data_label); - C_loi(tp->tp_size); - break; - case STRING: - CodeString(nd); - break; - case INTEGER: - CodeConst(nd->nd_INT, (int) (tp->tp_size)); + ds->dsg_kind = DSG_LOADED; break; - default: - crash("Value error"); - } - ds->dsg_kind = DSG_LOADED; - break; - case Call: - CodeCall(nd); - ds->dsg_kind = DSG_LOADED; - break; + case Call: + CodeCall(nd); + ds->dsg_kind = DSG_LOADED; + break; - case Set: { - unsigned i = (unsigned) (tp->tp_size) / (int) word_size; - arith *st = nd->nd_set + i; - int null_set = 1; + case Set: + { + unsigned i = (unsigned)(tp->tp_size) / (int)word_size; + arith* st = nd->nd_set + i; + int null_set = 1; - ds->dsg_kind = DSG_LOADED; - for (; i; i--) { - if (*--st != 0) null_set = 0; - } - if (! null_set) { - i = (unsigned) (tp->tp_size) / (int) word_size; - st = nd->nd_set + i; - for (; i; i--) { - C_loc(*--st); + ds->dsg_kind = DSG_LOADED; + for (; i; i--) + { + if (*--st != 0) + null_set = 0; } - } - FreeSet(nd->nd_set); - CodeSet(nd, null_set); + if (!null_set) + { + i = (unsigned)(tp->tp_size) / (int)word_size; + st = nd->nd_set + i; + for (; i; i--) + { + C_loc(*--st); + } + } + FreeSet(nd->nd_set); + nd->nd_set = NULL; + CodeSet(nd, null_set); } break; - default: - crash("(CodeExpr) bad node type"); + default: + crash("(CodeExpr) bad node type"); } - if (true_label != NO_LABEL) { + if (true_label != NO_LABEL) + { /* Only for boolean expressions - */ + */ CodeValue(ds, tp); C_zne(true_label); c_bra(false_label); } } -void CodeCoercion(struct type *t1, struct type *t2) +void CodeCoercion(struct type* t1, struct type* t2) { int fund1, fund2; int sz1 = t1->tp_size; @@ -184,470 +201,537 @@ void CodeCoercion(struct type *t1, struct type *t2) t1 = BaseType(t1); t2 = BaseType(t2); sz2 = t2->tp_size; - switch(fund1 = t1->tp_fund) { - case T_WORD: - fund1 = T_INTEGER; - break; - case T_CHAR: - case T_ENUMERATION: - case T_CARDINAL: - case T_INTORCARD: - if (sz1 < (int) word_size) sz1 = word_size; - /* fall through */ - case T_EQUAL: - case T_POINTER: - fund1 = T_CARDINAL; - break; - } - switch(fund2 = t2->tp_fund) { - case T_WORD: - fund2 = T_INTEGER; - break; - case T_CHAR: - case T_ENUMERATION: - sz2 = word_size; - /* fall through */ - case T_EQUAL: - case T_POINTER: - fund2 = T_CARDINAL; - break; - } - - switch(fund1) { - case T_INTEGER: - if (sz1 < (int) word_size) { - c_loc(sz1); - c_loc((int) word_size); - C_cii(); - sz1 = word_size; - } - c_loc(sz1); - c_loc(sz2); - switch(fund2) { - case T_REAL: - C_cif(); - break; - case T_INTEGER: - C_cii(); - break; - case T_CARDINAL: - C_ciu(); - break; - default: - crash("Funny integer conversion"); - } - break; - - case T_CARDINAL: - case T_INTORCARD: - c_loc(sz1); - c_loc(sz2); - switch(fund2) { - case T_REAL: - C_cuf(); + switch (fund1 = t1->tp_fund) + { + case T_WORD: + fund1 = T_INTEGER; break; + case T_CHAR: + case T_ENUMERATION: case T_CARDINAL: case T_INTORCARD: - C_cuu(); + if (sz1 < (int)word_size) + sz1 = word_size; + /* fall through */ + case T_EQUAL: + case T_POINTER: + fund1 = T_CARDINAL; break; - case T_INTEGER: - C_cui(); + } + switch (fund2 = t2->tp_fund) + { + case T_WORD: + fund2 = T_INTEGER; break; - default: - crash("Funny cardinal conversion"); - } - break; - - case T_REAL: - switch(fund2) { - case T_REAL: - c_loc(sz1); - c_loc(sz2); - C_cff(); + case T_CHAR: + case T_ENUMERATION: + sz2 = word_size; + /* fall through */ + case T_EQUAL: + case T_POINTER: + fund2 = T_CARDINAL; break; + } + + switch (fund1) + { case T_INTEGER: + if (sz1 < (int)word_size) + { + c_loc(sz1); + c_loc((int)word_size); + C_cii(); + sz1 = word_size; + } c_loc(sz1); c_loc(sz2); - C_cfi(); + switch (fund2) + { + case T_REAL: + C_cif(); + break; + case T_INTEGER: + C_cii(); + break; + case T_CARDINAL: + C_ciu(); + break; + default: + crash("Funny integer conversion"); + } break; + case T_CARDINAL: - if (! options['R']) { - label lb = ++text_label; - arith asz1 = sz1; - - C_dup(asz1); - C_zrf(asz1); - C_cmf(asz1); - C_zge(lb); - c_loc(ECONV); - C_trp(); - def_ilb(lb); - } + case T_INTORCARD: c_loc(sz1); c_loc(sz2); - C_cfu(); + switch (fund2) + { + case T_REAL: + C_cuf(); + break; + case T_CARDINAL: + case T_INTORCARD: + C_cuu(); + break; + case T_INTEGER: + C_cui(); + break; + default: + crash("Funny cardinal conversion"); + } + break; + + case T_REAL: + switch (fund2) + { + case T_REAL: + c_loc(sz1); + c_loc(sz2); + C_cff(); + break; + case T_INTEGER: + c_loc(sz1); + c_loc(sz2); + C_cfi(); + break; + case T_CARDINAL: + if (!options['R']) + { + label lb = ++text_label; + arith asz1 = sz1; + + C_dup(asz1); + C_zrf(asz1); + C_cmf(asz1); + C_zge(lb); + c_loc(ECONV); + C_trp(); + def_ilb(lb); + } + c_loc(sz1); + c_loc(sz2); + C_cfu(); + break; + default: + crash("Funny REAL conversion"); + } break; - default: - crash("Funny REAL conversion"); - } - break; } } -void CodeCall(struct node *nd) +void CodeCall(struct node* nd) { - struct node *left = nd->nd_LEFT; - struct type *result_tp; + struct node* left = nd->nd_LEFT; + struct type* result_tp; int needs_fn; - if (left->nd_type == std_type) { + if (left->nd_type == std_type) + { CodeStd(nd); return; - } + } assert(IsProc(left)); result_tp = ResultType(left->nd_type); #ifdef BIG_RESULT_ON_STACK - if (result_tp && TooBigForReturnArea(result_tp)) { + if (result_tp && TooBigForReturnArea(result_tp)) + { C_asp(-WA(result_tp->tp_size)); } #endif - if (nd->nd_RIGHT) { + if (nd->nd_RIGHT) + { CodeParameters(ParamList(left->nd_type), nd->nd_RIGHT); } - switch(left->nd_class) { - case Def: { - struct def *df = left->nd_def; + switch (left->nd_class) + { + case Def: + { + struct def* df = left->nd_def; - if (df->df_kind == D_CONST) { - /* a procedure address */ - df = df->con_const.tk_data.tk_def; - } - if (df->df_kind & (D_PROCEDURE|D_PROCHEAD)) { - int level = df->df_scope->sc_level; + if (df->df_kind == D_CONST) + { + /* a procedure address */ + df = df->con_const.tk_data.tk_def; + } + if (df->df_kind & (D_PROCEDURE | D_PROCHEAD)) + { + int level = df->df_scope->sc_level; - if (level > 0) { - C_lxl((arith) (proclevel - level)); + if (level > 0) + { + C_lxl((arith)(proclevel - level)); + } + needs_fn = df->df_scope->sc_defmodule; + C_cal(df->prc_name); + break; } - needs_fn = df->df_scope->sc_defmodule; - C_cal(df->prc_name); - break; - }} - /* Fall through */ - default: - needs_fn = 1; - CodePExpr(left); - C_cai(); + } + /* Fall through */ + default: + needs_fn = 1; + CodePExpr(left); + C_cai(); } C_asp(left->nd_type->prc_nbpar); - if (result_tp) { + if (result_tp) + { arith sz = WA(result_tp->tp_size); - if (TooBigForReturnArea(result_tp)) { + if (TooBigForReturnArea(result_tp)) + { #ifndef BIG_RESULT_ON_STACK C_lfr(pointer_size); C_loi(sz); #endif } - else C_lfr(sz); + else + C_lfr(sz); } DoFilename(needs_fn); DoLineno(nd); } /* Generates code to setup the parameters of a procedure call. */ -static void CodeParameters(struct paramlist *param, struct node *arg) +static void CodeParameters(struct paramlist* param, struct node* arg) { - struct type *tp; - struct type *arg_type; + struct type* tp; + struct type* arg_type; assert(param != 0 && arg != 0); - if (param->par_next) { + if (param->par_next) + { CodeParameters(param->par_next, arg->nd_RIGHT); } tp = TypeOfParam(param); arg = arg->nd_LEFT; arg_type = arg->nd_type; - if (IsConformantArray(tp)) { - struct type *elem = tp->arr_elem; + if (IsConformantArray(tp)) + { + struct type* elem = tp->arr_elem; C_loc(tp->arr_elsize); - if (IsConformantArray(arg_type)) { + if (IsConformantArray(arg_type)) + { DoHIGH(arg->nd_def); - if (elem->tp_size != arg_type->arr_elem->tp_size) { + if (elem->tp_size != arg_type->arr_elem->tp_size) + { /* This can only happen if the formal type is ARRAY OF (WORD|BYTE) */ C_loc(arg_type->arr_elem->tp_size); C_mlu(word_size); - if (elem == word_type) { - c_loc((int) word_size - 1); + if (elem == word_type) + { + c_loc((int)word_size - 1); C_adu(word_size); - c_loc((int) word_size - 1); + c_loc((int)word_size - 1); C_and(word_size); } - else { + else + { assert(elem == byte_type); } } } - else if (arg->nd_symb == STRING) { - c_loc((int) arg->nd_SLE - 1); + else if (arg->nd_symb == STRING) + { + c_loc((int)arg->nd_SLE - 1); } - else if (elem == word_type) { - C_loc((arg_type->tp_size+word_size-1) / word_size - 1); + else if (elem == word_type) + { + C_loc((arg_type->tp_size + word_size - 1) / word_size - 1); } - else if (elem == byte_type) { + else if (elem == byte_type) + { C_loc(arg_type->tp_size - 1); } - else { + else + { C_loc(arg_type->arr_high - arg_type->arr_low); } c_loc(0); } - if (IsConformantArray(tp) || IsVarParam(param)) { - if (arg->nd_symb == STRING) { + if (IsConformantArray(tp) || IsVarParam(param)) + { + if (arg->nd_symb == STRING) + { CodeString(arg); } - else switch(arg->nd_class) { - case Arrsel: - case Arrow: - case Def: - CodeDAddress(arg, IsVarParam(param)); - break; - default:{ - arith tmp; - arith sz = WA(arg->nd_type->tp_size); - - CodePExpr(arg); - tmp = TmpSpace(sz, arg->nd_type->tp_align); - STL(tmp, sz); - C_lal(tmp); + else + switch (arg->nd_class) + { + case Arrsel: + case Arrow: + case Def: + CodeDAddress(arg, IsVarParam(param)); + break; + default: + { + arith tmp; + arith sz = WA(arg->nd_type->tp_size); + + CodePExpr(arg); + tmp = TmpSpace(sz, arg->nd_type->tp_align); + STL(tmp, sz); + C_lal(tmp); + } + break; } - break; - } return; } - if (arg_type->tp_fund == T_STRING) { + if (arg_type->tp_fund == T_STRING) + { CodePString(arg, tp); return; } CodePExpr(arg); } -void CodePString(struct node *nd, struct type *tp) +void CodePString(struct node* nd, struct type* tp) { arith szarg = WA(nd->nd_type->tp_size); arith zersz = WA(tp->tp_size) - szarg; - if (zersz) { + if (zersz) + { /* null padding required */ assert(zersz > 0); C_zer(zersz); } - CodeString(nd); /* push address of string */ + CodeString(nd); /* push address of string */ C_loi(szarg); } - - static void subu(int sz) { - if (! options['R']) { - C_cal(sz == (int) word_size ? "subuchk" : "subulchk"); + if (!options['R']) + { + C_cal(sz == (int)word_size ? "subuchk" : "subulchk"); } - C_sbu((arith) sz); + C_sbu((arith)sz); } static void addu(int sz) { - if (! options['R']) { - C_cal(sz == (int) word_size ? "adduchk" : "addulchk"); + if (!options['R']) + { + C_cal(sz == (int)word_size ? "adduchk" : "addulchk"); } C_adu((arith)sz); } -static int complex_lhs(struct node *nd) +static int complex_lhs(struct node* nd) { - switch(nd->nd_class) { - case Value: - case Name: - case Set: - case Def: - return 0; - case Select: - return complex_lhs(nd->nd_NEXT); - default: - return 1; + switch (nd->nd_class) + { + case Value: + case Name: + case Set: + case Def: + return 0; + case Select: + return complex_lhs(nd->nd_NEXT); + default: + return 1; } } /* Generate code for internal procedures */ -static void CodeStd(struct node *nd) +static void CodeStd(struct node* nd) { - struct node *arg = nd->nd_RIGHT; - struct node *left = 0; - struct type *tp = 0; + struct node* arg = nd->nd_RIGHT; + struct node* left = 0; + struct type* tp = 0; int std = nd->nd_LEFT->nd_def->df_value.df_stdname; - if (arg) { + if (arg) + { left = arg->nd_LEFT; tp = BaseType(left->nd_type); arg = arg->nd_RIGHT; } - switch(std) { - case S_ORD: - case S_VAL: - CodePExpr(left); - break; - - case S_ABS: - CodePExpr(left); - if (tp->tp_fund == T_INTEGER) { - CAL((int)(tp->tp_size) == (int)int_size ? "absi" : "absl", (int)(tp->tp_size)); - } - else if (tp->tp_fund == T_REAL) { - CAL((int)(tp->tp_size) == (int)float_size ? "absf" : "absd", (int)(tp->tp_size)); - } - C_lfr(tp->tp_size); - break; - - case S_CAP: - CodePExpr(left); - C_cal("cap"); - break; + switch (std) + { + case S_ORD: + case S_VAL: + CodePExpr(left); + break; - case S_HIGH: - assert(IsConformantArray(tp)); - DoHIGH(left->nd_def); - break; + case S_ABS: + CodePExpr(left); + if (tp->tp_fund == T_INTEGER) + { + CAL((int)(tp->tp_size) == (int)int_size ? "absi" : "absl", (int)(tp->tp_size)); + } + else if (tp->tp_fund == T_REAL) + { + CAL((int)(tp->tp_size) == (int)float_size ? "absf" : "absd", (int)(tp->tp_size)); + } + C_lfr(tp->tp_size); + break; - case S_SIZE: - case S_TSIZE: - assert(IsConformantArray(tp)); - DoHIGH(left->nd_def); - C_inc(); - C_loc(tp->arr_elem->tp_size); - C_mlu(word_size); - break; + case S_CAP: + CodePExpr(left); + C_cal("cap"); + break; - case S_ODD: - CodePExpr(left); - if ((int) tp->tp_size == (int) word_size) { - c_loc(1); - C_and(word_size); - } - else { - assert(tp->tp_size == dword_size); - C_ldc((arith) 1); - C_and(dword_size); - C_ior(word_size); - } - break; + case S_HIGH: + assert(IsConformantArray(tp)); + DoHIGH(left->nd_def); + break; - case S_ADR: - CodeDAddress(left, 1); - break; + case S_SIZE: + case S_TSIZE: + assert(IsConformantArray(tp)); + DoHIGH(left->nd_def); + C_inc(); + C_loc(tp->arr_elem->tp_size); + C_mlu(word_size); + break; - case S_DEC: - case S_INC: { - arith size; - int compl = complex_lhs(left); - arith tmp = 0; + case S_ODD: + CodePExpr(left); + if ((int)tp->tp_size == (int)word_size) + { + c_loc(1); + C_and(word_size); + } + else + { + assert(tp->tp_size == dword_size); + C_ldc((arith)1); + C_and(dword_size); + C_ior(word_size); + } + break; - size = left->nd_type->tp_size; - if ((int) size < (int) word_size) size = word_size; - if (compl) { - tmp = NewPtr(); + case S_ADR: CodeDAddress(left, 1); - STL(tmp, pointer_size); - LOL(tmp, pointer_size); - C_loi(left->nd_type->tp_size); - } - else CodePExpr(left); - CodeCoercion(left->nd_type, tp); - if (arg) { - CodePExpr(arg->nd_LEFT); - CodeCoercion(arg->nd_LEFT->nd_type, tp); - } - else { - c_loc(1); - CodeCoercion(intorcard_type, tp); - } - if (std == S_DEC) { - if (tp->tp_fund == T_INTEGER) C_sbi(size); - else subu((int) size); - } - else { - if (tp->tp_fund == T_INTEGER) C_adi(size); - else addu((int) size); - } - if ((int) size == (int) word_size) { - RangeCheck(left->nd_type, tp->tp_fund == T_INTEGER ? - int_type : card_type); - } - if (compl) { - LOL(tmp, pointer_size); - C_sti(left->nd_type->tp_size); - FreePtr(tmp); - } - else CodeDStore(left); - break; - } + break; - case S_HALT: - C_cal("halt"); - break; + case S_DEC: + case S_INC: + { + arith size; + int compl = complex_lhs(left); + arith tmp = 0; + + size = left->nd_type->tp_size; + if ((int)size < (int)word_size) + size = word_size; + if (compl) + { + tmp = NewPtr(); + CodeDAddress(left, 1); + STL(tmp, pointer_size); + LOL(tmp, pointer_size); + C_loi(left->nd_type->tp_size); + } + else + CodePExpr(left); + CodeCoercion(left->nd_type, tp); + if (arg) + { + CodePExpr(arg->nd_LEFT); + CodeCoercion(arg->nd_LEFT->nd_type, tp); + } + else + { + c_loc(1); + CodeCoercion(intorcard_type, tp); + } + if (std == S_DEC) + { + if (tp->tp_fund == T_INTEGER) + C_sbi(size); + else + subu((int)size); + } + else + { + if (tp->tp_fund == T_INTEGER) + C_adi(size); + else + addu((int)size); + } + if ((int)size == (int)word_size) + { + RangeCheck(left->nd_type, tp->tp_fund == T_INTEGER ? int_type : card_type); + } + if (compl) + { + LOL(tmp, pointer_size); + C_sti(left->nd_type->tp_size); + FreePtr(tmp); + } + else + CodeDStore(left); + break; + } - case S_INCL: - case S_EXCL: { - int compl = complex_lhs(left); - arith tmp = 0; + case S_HALT: + C_cal("halt"); + break; - if (compl) { - tmp = NewPtr(); - CodeDAddress(left, 1); - STL(tmp, pointer_size); - LOL(tmp, pointer_size); - C_loi(left->nd_type->tp_size); - } - else CodePExpr(left); - CodePExpr(arg->nd_LEFT); - C_loc(tp->set_low); - C_sbi(word_size); - C_set(tp->tp_size); - if (std == S_INCL) { - C_ior(tp->tp_size); - } - else { - C_com(tp->tp_size); - C_and(tp->tp_size); - } - if (compl) { - LOL(tmp, pointer_size); - C_sti(left->nd_type->tp_size); - FreePtr(tmp); - } - else CodeDStore(left); - break; + case S_INCL: + case S_EXCL: + { + int compl = complex_lhs(left); + arith tmp = 0; + + if (compl) + { + tmp = NewPtr(); + CodeDAddress(left, 1); + STL(tmp, pointer_size); + LOL(tmp, pointer_size); + C_loi(left->nd_type->tp_size); + } + else + CodePExpr(left); + CodePExpr(arg->nd_LEFT); + C_loc(tp->set_low); + C_sbi(word_size); + C_set(tp->tp_size); + if (std == S_INCL) + { + C_ior(tp->tp_size); + } + else + { + C_com(tp->tp_size); + C_and(tp->tp_size); + } + if (compl) + { + LOL(tmp, pointer_size); + C_sti(left->nd_type->tp_size); + FreePtr(tmp); + } + else + CodeDStore(left); + break; } - default: - crash("(CodeStd)"); + default: + crash("(CodeStd)"); } } -static int needs_rangecheck(struct type *tpl, struct type *tpr) +static int needs_rangecheck(struct type* tpl, struct type* tpr) { arith rlo, rhi; - if (bounded(tpl)) { + if (bounded(tpl)) + { /* In this case we might need a range check. If both types are restricted. check the bounds to see wether we need a range check. @@ -655,9 +739,11 @@ static int needs_rangecheck(struct type *tpl, struct type *tpr) right hand side is a subset of the range of values of the left hand side. */ - if (bounded(tpr)) { + if (bounded(tpr)) + { getbounds(tpr, &rlo, &rhi); - if (in_range(rlo, tpl) && in_range(rhi, tpl)) { + if (in_range(rlo, tpl) && in_range(rhi, tpl)) + { return 0; } } @@ -666,19 +752,22 @@ static int needs_rangecheck(struct type *tpl, struct type *tpr) return 0; } -void RangeCheck(struct type *tpl, struct type *tpr) +void RangeCheck(struct type* tpl, struct type* tpr) { arith rlo, rhi; - if (options['R']) return; + if (options['R']) + return; - if (needs_rangecheck(tpl, tpr)) { + if (needs_rangecheck(tpl, tpr)) + { genrck(tpl); return; } tpr = BaseType(tpr); - if ((tpl->tp_fund == T_INTEGER && tpr->tp_fund == T_CARDINAL) || - (tpr->tp_fund == T_INTEGER && tpl->tp_fund == T_CARDINAL)) { + if ((tpl->tp_fund == T_INTEGER && tpr->tp_fund == T_CARDINAL) + || (tpr->tp_fund == T_INTEGER && tpl->tp_fund == T_CARDINAL)) + { label lb = ++text_label; C_dup(tpr->tp_size); @@ -691,7 +780,7 @@ void RangeCheck(struct type *tpl, struct type *tpr) } } -void Operands(struct node *nd) +void Operands(struct node* nd) { CodePExpr(nd->nd_LEFT); @@ -700,439 +789,479 @@ void Operands(struct node *nd) } void CodeOper( - struct node *expr, /* the expression tree itself */ - label true_label, - label false_label /* labels to jump to in logical expr's */ + struct node* expr, /* the expression tree itself */ + label true_label, + label false_label /* labels to jump to in logical expr's */ ) { - struct node *leftop = expr->nd_LEFT; - struct node *rightop = expr->nd_RIGHT; + struct node* leftop = expr->nd_LEFT; + struct node* rightop = expr->nd_RIGHT; int fund = expr->nd_type->tp_fund; arith size = expr->nd_type->tp_size; - switch (expr->nd_symb) { - case '+': - Operands(expr); - switch (fund) { - case T_INTEGER: - C_adi(size); - break; - case T_REAL: - C_adf(size); - break; - case T_POINTER: - case T_EQUAL: - C_ads(rightop->nd_type->tp_size); - break; - case T_CARDINAL: - case T_INTORCARD: - addu((int) size); - break; - case T_SET: - C_ior(size); - break; - default: - crash("bad type +"); - } - break; - case '-': - Operands(expr); - switch (fund) { - case T_INTEGER: - C_sbi(size); - break; - case T_REAL: - C_sbf(size); - break; - case T_POINTER: - case T_EQUAL: - if (rightop->nd_type == address_type) { - C_sbs(size); - break; + switch (expr->nd_symb) + { + case '+': + Operands(expr); + switch (fund) + { + case T_INTEGER: + C_adi(size); + break; + case T_REAL: + C_adf(size); + break; + case T_POINTER: + case T_EQUAL: + C_ads(rightop->nd_type->tp_size); + break; + case T_CARDINAL: + case T_INTORCARD: + addu((int)size); + break; + case T_SET: + C_ior(size); + break; + default: + crash("bad type +"); } - C_ngi(rightop->nd_type->tp_size); - C_ads(rightop->nd_type->tp_size); break; - case T_INTORCARD: - case T_CARDINAL: - subu((int) size); - break; - case T_SET: - C_com(size); - C_and(size); - break; - default: - crash("bad type -"); - } - break; - case '*': - Operands(expr); - switch (fund) { - case T_INTEGER: - C_mli(size); - break; - case T_POINTER: - case T_EQUAL: - case T_CARDINAL: - case T_INTORCARD: - if (! options['R']) { - C_cal((int)(size) <= (int)word_size ? - "muluchk" : - "mululchk"); + case '-': + Operands(expr); + switch (fund) + { + case T_INTEGER: + C_sbi(size); + break; + case T_REAL: + C_sbf(size); + break; + case T_POINTER: + case T_EQUAL: + if (rightop->nd_type == address_type) + { + C_sbs(size); + break; + } + C_ngi(rightop->nd_type->tp_size); + C_ads(rightop->nd_type->tp_size); + break; + case T_INTORCARD: + case T_CARDINAL: + subu((int)size); + break; + case T_SET: + C_com(size); + C_and(size); + break; + default: + crash("bad type -"); } - C_mlu(size); - break; - case T_REAL: - C_mlf(size); break; - case T_SET: - C_and(size); - break; - default: - crash("bad type *"); - } - break; - case '/': - Operands(expr); - switch (fund) { - case T_REAL: - C_dvf(size); - break; - case T_SET: - C_xor(size); - break; - default: - crash("bad type /"); - } - break; - case DIV: - Operands(expr); - switch(fund) { - case T_INTEGER: - C_cal((int)(size) == (int)word_size - ? "dvi" - : "dvil"); - C_asp(2*size); - C_lfr(size); - break; - case T_POINTER: - case T_EQUAL: - case T_CARDINAL: - case T_INTORCARD: - C_dvu(size); - break; - default: - crash("bad type DIV"); - } - break; - case MOD: - Operands(expr); - switch(fund) { - case T_INTEGER: - C_cal((int)(size) == (int)word_size - ? "rmi" - : "rmil"); - C_asp(2*size); - C_lfr(size); - break; - case T_POINTER: - case T_EQUAL: - case T_CARDINAL: - case T_INTORCARD: - C_rmu(size); - break; - default: - crash("bad type MOD"); - } - break; - case '<': - case LESSEQUAL: - case '>': - case GREATEREQUAL: - case '=': - case '#': { - struct type *tp; - - Operands(expr); - tp = BaseType(leftop->nd_type); - if (tp->tp_fund == T_INTORCARD) tp = BaseType(rightop->nd_type); - size = tp->tp_size; - switch (tp->tp_fund) { - case T_INTEGER: - C_cmi(size); - break; - case T_POINTER: - case T_HIDDEN: - case T_EQUAL: - C_cmp(); + case '*': + Operands(expr); + switch (fund) + { + case T_INTEGER: + C_mli(size); + break; + case T_POINTER: + case T_EQUAL: + case T_CARDINAL: + case T_INTORCARD: + if (!options['R']) + { + C_cal((int)(size) <= (int)word_size ? "muluchk" : "mululchk"); + } + C_mlu(size); + break; + case T_REAL: + C_mlf(size); + break; + case T_SET: + C_and(size); + break; + default: + crash("bad type *"); + } break; - case T_CARDINAL: - case T_INTORCARD: - C_cmu(size); + case '/': + Operands(expr); + switch (fund) + { + case T_REAL: + C_dvf(size); + break; + case T_SET: + C_xor(size); + break; + default: + crash("bad type /"); + } break; - case T_ENUMERATION: - case T_CHAR: - C_cmu(word_size); + case DIV: + Operands(expr); + switch (fund) + { + case T_INTEGER: + C_cal((int)(size) == (int)word_size ? "dvi" : "dvil"); + C_asp(2 * size); + C_lfr(size); + break; + case T_POINTER: + case T_EQUAL: + case T_CARDINAL: + case T_INTORCARD: + C_dvu(size); + break; + default: + crash("bad type DIV"); + } break; - case T_REAL: - C_cmf(size); + case MOD: + Operands(expr); + switch (fund) + { + case T_INTEGER: + C_cal((int)(size) == (int)word_size ? "rmi" : "rmil"); + C_asp(2 * size); + C_lfr(size); + break; + case T_POINTER: + case T_EQUAL: + case T_CARDINAL: + case T_INTORCARD: + C_rmu(size); + break; + default: + crash("bad type MOD"); + } break; - case T_SET: - if (expr->nd_symb == GREATEREQUAL) { - /* A >= B is the same as A equals A + B - */ - C_dup(size << 1); - C_asp(size); - C_ior(size); - expr->nd_symb = '='; + case '<': + case LESSEQUAL: + case '>': + case GREATEREQUAL: + case '=': + case '#': + { + struct type* tp; + + Operands(expr); + tp = BaseType(leftop->nd_type); + if (tp->tp_fund == T_INTORCARD) + tp = BaseType(rightop->nd_type); + size = tp->tp_size; + switch (tp->tp_fund) + { + case T_INTEGER: + C_cmi(size); + break; + case T_POINTER: + case T_HIDDEN: + case T_EQUAL: + C_cmp(); + break; + case T_CARDINAL: + case T_INTORCARD: + C_cmu(size); + break; + case T_ENUMERATION: + case T_CHAR: + C_cmu(word_size); + break; + case T_REAL: + C_cmf(size); + break; + case T_SET: + if (expr->nd_symb == GREATEREQUAL) + { + /* A >= B is the same as A equals A + B + */ + C_dup(size << 1); + C_asp(size); + C_ior(size); + expr->nd_symb = '='; + } + else if (expr->nd_symb == LESSEQUAL) + { + /* A <= B is the same as A - B = {} + */ + C_com(size); + C_and(size); + C_zer(size); + expr->nd_symb = '='; + } + C_cms(size); + break; + default: + crash("bad type COMPARE"); } - else if (expr->nd_symb == LESSEQUAL) { - /* A <= B is the same as A - B = {} - */ - C_com(size); - C_and(size); - C_zer(size); - expr->nd_symb = '='; + if (true_label != NO_LABEL) + { + compare(expr->nd_symb, true_label); + c_bra(false_label); + break; } - C_cms(size); + truthvalue(expr->nd_symb); break; - default: - crash("bad type COMPARE"); - } - if (true_label != NO_LABEL) { - compare(expr->nd_symb, true_label); - c_bra(false_label); - break; - } - truthvalue(expr->nd_symb); - break; } - case IN: { - /* In this case, evaluate right hand side first! The - INN instruction expects the bit number on top of the - stack - */ - label l_toolarge = NO_LABEL, l_cont = NO_LABEL; - struct type *ltp = leftop->nd_type; - - if (leftop->nd_symb == COERCION) { - /* Could be coercion to word_type. */ - ltp = leftop->nd_RIGHT->nd_type; - } - if (leftop->nd_class == Value) { - if (! in_range(leftop->nd_INT, ElementType(rightop->nd_type))) { - if (true_label != NO_LABEL) { - c_bra(false_label); + case IN: + { + /* In this case, evaluate right hand side first! The + INN instruction expects the bit number on top of the + stack + */ + label l_toolarge = NO_LABEL, l_cont = NO_LABEL; + struct type* ltp = leftop->nd_type; + + if (leftop->nd_symb == COERCION) + { + /* Could be coercion to word_type. */ + ltp = leftop->nd_RIGHT->nd_type; + } + if (leftop->nd_class == Value) + { + if (!in_range(leftop->nd_INT, ElementType(rightop->nd_type))) + { + if (true_label != NO_LABEL) + { + c_bra(false_label); + } + else + c_loc(0); + break; } - else c_loc(0); - break; + CodePExpr(rightop); + C_loc(leftop->nd_INT - rightop->nd_type->set_low); } - CodePExpr(rightop); - C_loc(leftop->nd_INT - rightop->nd_type->set_low); - } - else { - CodePExpr(rightop); - CodePExpr(leftop); - C_loc(rightop->nd_type->set_low); - C_sbu(word_size); - if (needs_rangecheck(ElementType(rightop->nd_type), ltp)) { - l_toolarge = ++text_label; - C_dup(word_size); - C_loc(rightop->nd_type->tp_size*8); - C_cmu(word_size); - C_zge(l_toolarge); + else + { + CodePExpr(rightop); + CodePExpr(leftop); + C_loc(rightop->nd_type->set_low); + C_sbu(word_size); + if (needs_rangecheck(ElementType(rightop->nd_type), ltp)) + { + l_toolarge = ++text_label; + C_dup(word_size); + C_loc(rightop->nd_type->tp_size * 8); + C_cmu(word_size); + C_zge(l_toolarge); + } } - } - C_inn(rightop->nd_type->tp_size); - if (true_label != NO_LABEL) { - C_zne(true_label); - c_bra(false_label); - } - else { - l_cont = ++text_label; - c_bra(l_cont); - } - if (l_toolarge != NO_LABEL) { - def_ilb(l_toolarge); - C_asp(word_size+rightop->nd_type->tp_size); - if (true_label != NO_LABEL) { + C_inn(rightop->nd_type->tp_size); + if (true_label != NO_LABEL) + { + C_zne(true_label); c_bra(false_label); } - else c_loc(0); - } - if (l_cont != NO_LABEL) { - def_ilb(l_cont); - } - break; - } - case OR: - case AND: { - label l_maybe = ++text_label, l_end = NO_LABEL; - struct desig Des; - - Des = null_desig; - - if (true_label == NO_LABEL) { - true_label = ++text_label; - false_label = ++text_label; - l_end = ++text_label; + else + { + l_cont = ++text_label; + c_bra(l_cont); + } + if (l_toolarge != NO_LABEL) + { + def_ilb(l_toolarge); + C_asp(word_size + rightop->nd_type->tp_size); + if (true_label != NO_LABEL) + { + c_bra(false_label); + } + else + c_loc(0); + } + if (l_cont != NO_LABEL) + { + def_ilb(l_cont); + } + break; } + case OR: + case AND: + { + label l_maybe = ++text_label, l_end = NO_LABEL; + struct desig Des; + + Des = null_desig; + + if (true_label == NO_LABEL) + { + true_label = ++text_label; + false_label = ++text_label; + l_end = ++text_label; + } - if (expr->nd_symb == OR) { - CodeExpr(leftop, &Des, true_label, l_maybe); - } - else CodeExpr(leftop, &Des, l_maybe, false_label); - def_ilb(l_maybe); - Des = null_desig; - CodeExpr(rightop, &Des, true_label, false_label); - if (l_end != NO_LABEL) { - def_ilb(true_label); - c_loc(1); - c_bra(l_end); - def_ilb(false_label); - c_loc(0); - def_ilb(l_end); - } - break; + if (expr->nd_symb == OR) + { + CodeExpr(leftop, &Des, true_label, l_maybe); + } + else + CodeExpr(leftop, &Des, l_maybe, false_label); + def_ilb(l_maybe); + Des = null_desig; + CodeExpr(rightop, &Des, true_label, false_label); + if (l_end != NO_LABEL) + { + def_ilb(true_label); + c_loc(1); + c_bra(l_end); + def_ilb(false_label); + c_loc(0); + def_ilb(l_end); + } + break; } - default: - crash("(CodeOper) Bad operator"); + default: + crash("(CodeOper) Bad operator"); } } /* Serves as an auxiliary function of CodeOper */ static void compare(int relop, label lbl) { - switch (relop) { - case '<': - C_zlt(lbl); - break; - case LESSEQUAL: - C_zle(lbl); - break; - case '>': - C_zgt(lbl); - break; - case GREATEREQUAL: - C_zge(lbl); - break; - case '=': - C_zeq(lbl); - break; - case '#': - C_zne(lbl); - break; - default: - crash("(compare)"); + switch (relop) + { + case '<': + C_zlt(lbl); + break; + case LESSEQUAL: + C_zle(lbl); + break; + case '>': + C_zgt(lbl); + break; + case GREATEREQUAL: + C_zge(lbl); + break; + case '=': + C_zeq(lbl); + break; + case '#': + C_zne(lbl); + break; + default: + crash("(compare)"); } } /* Serves as an auxiliary function of CodeOper */ static void truthvalue(int relop) { - switch (relop) { - case '<': - C_tlt(); - break; - case LESSEQUAL: - C_tle(); - break; - case '>': - C_tgt(); - break; - case GREATEREQUAL: - C_tge(); - break; - case '=': - C_teq(); - break; - case '#': - C_tne(); - break; - default: - crash("(truthvalue)"); + switch (relop) + { + case '<': + C_tlt(); + break; + case LESSEQUAL: + C_tle(); + break; + case '>': + C_tgt(); + break; + case GREATEREQUAL: + C_tge(); + break; + case '=': + C_teq(); + break; + case '#': + C_tne(); + break; + default: + crash("(truthvalue)"); } } - /* Generates code for an unary expression */ -void CodeUoper(struct node *nd) +void CodeUoper(struct node* nd) { - struct type *tp = nd->nd_type; + struct type* tp = nd->nd_type; CodePExpr(nd->nd_RIGHT); - switch(nd->nd_symb) { - case NOT: - C_teq(); - break; - case '-': - switch(tp->tp_fund) { - case T_INTEGER: - case T_INTORCARD: - C_ngi(tp->tp_size); + switch (nd->nd_symb) + { + case NOT: + C_teq(); break; - case T_REAL: - C_ngf(tp->tp_size); + case '-': + switch (tp->tp_fund) + { + case T_INTEGER: + case T_INTORCARD: + C_ngi(tp->tp_size); + break; + case T_REAL: + C_ngf(tp->tp_size); + break; + default: + crash("Bad operand to unary -"); + } + break; + case COERCION: + CodeCoercion(nd->nd_RIGHT->nd_type, tp); + RangeCheck(tp, nd->nd_RIGHT->nd_type); + break; + case CAST: break; default: - crash("Bad operand to unary -"); - } - break; - case COERCION: - CodeCoercion(nd->nd_RIGHT->nd_type, tp); - RangeCheck(tp, nd->nd_RIGHT->nd_type); - break; - case CAST: - break; - default: - crash("Bad unary operator"); + crash("Bad unary operator"); } } -static void CodeSet(struct node *nd, int null_set) +static void CodeSet(struct node* nd, int null_set) { - struct type *tp = nd->nd_type; + struct type* tp = nd->nd_type; nd = nd->nd_NEXT; - while (nd) { + while (nd) + { assert(nd->nd_class == Link && nd->nd_symb == ','); - if (nd->nd_LEFT) { + if (nd->nd_LEFT) + { CodeEl(nd->nd_LEFT, tp, null_set); null_set = 0; } nd = nd->nd_RIGHT; } - if (null_set) C_zer(tp->tp_size); + if (null_set) + C_zer(tp->tp_size); } -static void CodeEl(struct node *nd, struct type *tp, int null_set) +static void CodeEl(struct node* nd, struct type* tp, int null_set) { - struct type *eltype = ElementType(tp); + struct type* eltype = ElementType(tp); - if (nd->nd_class == Link && nd->nd_symb == UPTO) { - if (null_set) C_zer(tp->tp_size); + if (nd->nd_class == Link && nd->nd_symb == UPTO) + { + if (null_set) + C_zer(tp->tp_size); C_loc(tp->set_low); - C_loc(tp->tp_size); /* push size */ - if (eltype->tp_fund == T_SUBRANGE) { + C_loc(tp->tp_size); /* push size */ + if (eltype->tp_fund == T_SUBRANGE) + { C_loc(eltype->sub_ub); } - else C_loc(eltype->enm_ncst - 1); + else + C_loc(eltype->enm_ncst - 1); Operands(nd); - CAL("LtoUset", 5 * (int) word_size); + CAL("LtoUset", 5 * (int)word_size); /* library routine to fill set */ } - else { + else + { CodePExpr(nd); C_loc(tp->set_low); C_sbi(word_size); C_set(tp->tp_size); - if (! null_set) C_ior(tp->tp_size); + if (!null_set) + C_ior(tp->tp_size); } } -void CodePExpr(struct node *nd) +void CodePExpr(struct node* nd) { struct desig designator; @@ -1142,36 +1271,36 @@ void CodePExpr(struct node *nd) CodeValue(&designator, nd->nd_type); } -static void CodeDAddress(struct node *nd, int chk_controlvar) +static void CodeDAddress(struct node* nd, int chk_controlvar) { /* Generate code to push the address of the designator "nd" - on the stack. + on the stack. */ struct desig designator; int chkptr; designator = null_desig; - if (chk_controlvar) ChkForFOR(nd); + if (chk_controlvar) + ChkForFOR(nd); CodeDesig(nd, &designator); - chkptr = designator.dsg_kind==DSG_PLOADED || - designator.dsg_kind==DSG_PFIXED; + chkptr = designator.dsg_kind == DSG_PLOADED || designator.dsg_kind == DSG_PFIXED; CodeAddress(&designator); /* Generate dummy use of pointer, to get possible error message - as soon as possible + as soon as possible */ - if (chkptr && ! options['R']) { + if (chkptr && !options['R']) + { C_dup(pointer_size); - C_loi((arith) 1); + C_loi((arith)1); C_asp(word_size); } } -void CodeDStore(struct node *nd) +void CodeDStore(struct node* nd) { - struct desig designator; designator = null_desig; @@ -1180,48 +1309,50 @@ void CodeDStore(struct node *nd) CodeStore(&designator, nd->nd_type); } -static void DoHIGH(struct def *df) +static void DoHIGH(struct def* df) { /* Get the high index of a conformant array, indicated by "nd". - The high index is the second field in the descriptor of - the array, so it is easily found. + The high index is the second field in the descriptor of + the array, so it is easily found. */ arith highoff; assert(df->df_kind == D_VARIABLE); assert(IsConformantArray(df->df_type)); - highoff = df->var_off /* base address and descriptor */ - + word_size + pointer_size; - /* skip base and first field of - descriptor - */ - if (df->df_scope->sc_level < proclevel) { - C_lxa((arith) (proclevel - df->df_scope->sc_level)); + highoff = df->var_off /* base address and descriptor */ + + word_size + pointer_size; + /* skip base and first field of + descriptor + */ + if (df->df_scope->sc_level < proclevel) + { + C_lxa((arith)(proclevel - df->df_scope->sc_level)); C_lof(highoff); } - else C_lol(highoff); + else + C_lol(highoff); } #ifdef SQUEEZE void c_bra(label l) { - C_bra((label) l); + C_bra((label)l); } void c_loc(int n) { - C_loc((arith) n); + C_loc((arith)n); } void c_lae_dlb(label l) { - C_lae_dlb(l, (arith) 0); + C_lae_dlb(l, (arith)0); } -void CAL(char *name, int ssp) +void CAL(char* name, int ssp) { C_cal(name); - C_asp((arith) ssp); + C_asp((arith)ssp); } #endif diff --git a/lang/occam/comp/keytab.c b/lang/occam/comp/keytab.c index 20ef3e2b08..07f343c107 100644 --- a/lang/occam/comp/keytab.c +++ b/lang/occam/comp/keytab.c @@ -27,7 +27,7 @@ KTAB keytab[] = { { PLACED, "PLACED" }, { PORT, "PORT" }, { PRI, "PRI" }, { PROC, "PROC" }, { SEQ, "SEQ" }, { SKIP, "SKIP" }, - { TABLE, "TABLE" }, { TRUE, "TRUE" }, + { TABLE, "TABLE" }, { true, "true" }, { VALUE, "VALUE" }, { VAR, "VAR" }, { WAIT, "WAIT" }, { WHILE, "WHILE" }, }; diff --git a/mach/arm/top/table b/mach/arm/top/table index b2c5cfb1ed..d6300ffcb2 100644 --- a/mach/arm/top/table +++ b/mach/arm/top/table @@ -9,13 +9,13 @@ ZERO {strcmp(VAL,"#0") ==0}; CONST,C1,C2,C3,C4 {VAL[0] == '#'}; REG,REG1,REG2 {is_register(VAL)}; LAB {VAL[0] == 'I'}; -LL,X,Y,Z,W,LOG1,LOG2 {TRUE}; +LL,X,Y,Z,W,LOG1,LOG2 {true}; XX {no_side_effects(VAL)}; -YY,ZZ,VV,WW {TRUE}; +YY,ZZ,VV,WW {true}; RL11 {is_reglist_11(VAL)}; RL1,RL2,RL3,RL4 {is_reglist1(VAL)}; RL13 {is_local(VAL)}; -X1,X2,Y1,Y2,Z1,Z2,V1,V2 {TRUE}; +X1,X2,Y1,Y2,Z1,Z2,V1,V2 {true}; %%; @@ -682,7 +682,7 @@ char *s; if (*s++ == '1' && (*s >= '0' && *s <= '5')) s++; return *s == '\0'; } - return FALSE; + return false; } int is_byte(s,t) @@ -692,9 +692,9 @@ char *s, *t; s++; /* skip # */ arg = atol(s); - if (arg<1 || arg>256) return(FALSE); + if (arg<1 || arg>256) return(false); sprintf(t,"%d",arg-1); - return(TRUE); + return(true); } int is_byte2(s,t1,t2) @@ -704,14 +704,14 @@ char *s,*t1,*t2; s++; arg = atol(s); - if (arg<1 || arg>255) return(FALSE); + if (arg<1 || arg>255) return(false); if (arg & 0x80) { shift = arg << 24; sprintf(t1,"%ld",shift); sprintf(t2,"%d", 24); - return(TRUE); + return(true); } - return(FALSE); + return(false); } int no_side_effects(s) @@ -719,9 +719,9 @@ char *s; { for (;;) { switch(*s++) { - case '\0': return(TRUE); - case ']' : return(FALSE); - case '<' : return(FALSE); + case '\0': return(true); + case ']' : return(false); + case '<' : return(false); } } } @@ -737,42 +737,42 @@ char *s1, *s2, *rl; a2 = atol(s2); if (a1 > a2) { sprintf(rl, "{R%d,R%d}", a2, a1); - return(TRUE); + return(true); } - return(FALSE); + return(false); } int is_local(s) char *s; { - if (strcmp(s, "[R13") == 0) return(TRUE); - return(FALSE); + if (strcmp(s, "[R13") == 0) return(true); + return(false); } int is_reglist_11(s) char *s; { if (strcmp(s, "{R11}") == 0){ - return(TRUE); + return(true); } - return(FALSE); + return(false); } int is_reglist(s) char *s; { - if (*s == '{') return(TRUE); - return(FALSE); + if (*s == '{') return(true); + return(false); } int is_reglist1(s) char *s; { - if (*s != '{') return(FALSE); + if (*s != '{') return(false); for (;;) { switch(*s++) { - case '\0': return(TRUE); - case ',' : return(FALSE); + case '\0': return(true); + case ',' : return(false); } } } @@ -780,14 +780,14 @@ char *s; int is_lams(s) char *s; { -/* if (strcmp(s,"LDR") == 0) return(TRUE); - if (strcmp(s,"ADD") == 0) return(TRUE); - if (strcmp(s,"ADR") == 0) return(TRUE); - if (strcmp(s,"MOV") == 0) return(TRUE); - if (strcmp(s,"SUB") == 0) return(TRUE); - return(FALSE); +/* if (strcmp(s,"LDR") == 0) return(true); + if (strcmp(s,"ADD") == 0) return(true); + if (strcmp(s,"ADR") == 0) return(true); + if (strcmp(s,"MOV") == 0) return(true); + if (strcmp(s,"SUB") == 0) return(true); + return(false); */ -return(TRUE); +return(true); } int is_unequal(s1, s2) @@ -798,8 +798,8 @@ char *s1, *s2; s1++; s2++; a1 = atol(s1); a2 = atol(s2); - if (a1 == a2) return(FALSE); - return(TRUE); + if (a1 == a2) return(false); + return(true); } int is_unequal3(s1, s2, s3) @@ -811,31 +811,31 @@ char *s1, *s2, *s3; a1 = atol(s1); a2 = atol(s2); a3 = atol(s3); - if (a1 == a2) return(FALSE); - if (a3 == a2) return(FALSE); - if (a1 == a3) return(FALSE); - return(TRUE); + if (a1 == a2) return(false); + if (a3 == a2) return(false); + if (a1 == a3) return(false); + return(true); } int list_f_10(s) char *s; { sprintf(s,"{R10,R11}"); - return(TRUE); + return(true); } int list_f_9(s) char *s; { sprintf(s,"{R9,R10,R11}"); - return(TRUE); + return(true); } int list_f_8(s) char *s; { sprintf(s,"{R8,R9,R10,R11}"); - return(TRUE); + return(true); } int ok_regcheck1(r, s1) @@ -845,11 +845,11 @@ int r; int a1; if (*s1 == '[') s1++; - if (*s1 != 'R') return(TRUE); + if (*s1 != 'R') return(true); s1++; /* skip R */ a1 = atoi(s1); - if (a1 >= r && a1 <= 11) return(FALSE); - return(TRUE); + if (a1 >= r && a1 <= 11) return(false); + return(true); } int ok_regcheck2(r, s1, s2) @@ -858,8 +858,8 @@ int r; { if (ok_regcheck1(r,s1)) if (ok_regcheck1(r,s2)) - return(TRUE); - return(FALSE); + return(true); + return(false); } int ok_regcheck3(r, s1, s2, s3) @@ -868,8 +868,8 @@ int r; { if (ok_regcheck1(r,s1)) if (ok_regcheck2(r,s2,s3)) - return(TRUE); - return(FALSE); + return(true); + return(false); } int ok_regcheck4(r, s1, s2, s3, s4) @@ -878,8 +878,8 @@ int r; { if (ok_regcheck2(r,s1,s2)) if (ok_regcheck2(r,s3,s4)) - return(TRUE); - return(FALSE); + return(true); + return(false); } int ok_regcheck5(r, s1, s2, s3, s4, s5) @@ -888,8 +888,8 @@ int r; { if (ok_regcheck2(r,s1,s2)) if (ok_regcheck3(r,s3,s4,s5)) - return(TRUE); - return(FALSE); + return(true); + return(false); } int ok_regcheck6(r, s1, s2, s3, s4, s5, s6) @@ -898,8 +898,8 @@ int r; { if (ok_regcheck2(r,s1,s2)) if (ok_regcheck4(r,s3,s4,s5,s6)) - return(TRUE); - return(FALSE); + return(true); + return(false); } int ok_regcheck7(r, s1, s2, s3, s4, s5, s6, s7) @@ -908,8 +908,8 @@ int r; { if (ok_regcheck4(r,s1,s2,s3,s4)) if (ok_regcheck3(r,s5,s6,s7)) - return(TRUE); - return(FALSE); + return(true); + return(false); } int ok_regcheck8(r, s1, s2, s3, s4, s5, s6, s7, s8) @@ -918,8 +918,8 @@ int r; { if (ok_regcheck4(r,s1,s2,s3,s4)) if (ok_regcheck4(r,s5,s6,s7,s8)) - return(TRUE); - return(FALSE); + return(true); + return(false); } diff --git a/mach/i386/ce/as.c b/mach/i386/ce/as.c index f3074b8ff8..7a300ff028 100644 --- a/mach/i386/ce/as.c +++ b/mach/i386/ce/as.c @@ -118,11 +118,11 @@ struct t_operand *op; while (p->regstr) { if (! strcmp(p->regstr, str)) { op->reg = p->regval; - return TRUE; + return true; } p++; } - return FALSE; + return false; } #include @@ -134,7 +134,7 @@ char *str; while( !isletter( *str) && *str != '\0') if ( *str == '$') if ( arg_type( str) == STRING) - return( TRUE); + return( true); else str += 2; else diff --git a/mach/i386/ce/as.h b/mach/i386/ce/as.h index 3f10deef08..e80e7d567a 100644 --- a/mach/i386/ce/as.h +++ b/mach/i386/ce/as.h @@ -27,9 +27,6 @@ #define ADDR( op) ( op->type & IS_ADDR) #define EADDR( op) ( op->type & ( IS_ADDR | IS_MEM | IS_REG)) -#define TRUE 1 -#define FALSE 0 - struct t_operand { unsigned type; int reg; diff --git a/mach/i386/ce/mach.c b/mach/i386/ce/mach.c index 2dbe88997b..aa864c9b7c 100644 --- a/mach/i386/ce/mach.c +++ b/mach/i386/ce/mach.c @@ -12,7 +12,7 @@ int arg; } #endif -int push_waiting = FALSE; +int push_waiting = false; int fit_byte( val) int val; @@ -32,8 +32,8 @@ do_open(filename) char *filename; { if (filename == 0 || ! sys_open(filename, OP_WRITE, &codefile)) - return FALSE; + return false; - fprintf( codefile, ".sect .text; .sect .rom; .sect .data; .sect .bss\n"); return TRUE; + fprintf( codefile, ".sect .text; .sect .rom; .sect .data; .sect .bss\n"); return true; } */ diff --git a/mach/i386/ce/mach.h b/mach/i386/ce/mach.h index e5e98c0689..8a50cd2ea3 100644 --- a/mach/i386/ce/mach.h +++ b/mach/i386/ce/mach.h @@ -38,10 +38,7 @@ #define COMM_FMT ".comm %s,%ld\n" #define GENLAB 'I' -#define TRUE 1 -#define FALSE 0 - -#define clean_push_buf() if(push_waiting){text1(0x50);push_waiting=FALSE;} +#define clean_push_buf() if(push_waiting){text1(0x50);push_waiting=false;} #define assign( l, r) l = r extern int push_waiting; diff --git a/mach/i80/top/table b/mach/i80/top/table index 3423c37918..d059f0c2b3 100644 --- a/mach/i80/top/table +++ b/mach/i80/top/table @@ -5,7 +5,7 @@ MAXOP 2; %%; -X, Y, Z { TRUE }; +X, Y, Z { true }; %%; mvi X, Y : mov X, Z -> mov X, Z ; diff --git a/mach/i86/ce/as.c b/mach/i86/ce/as.c index fe088343fb..03c267a761 100644 --- a/mach/i86/ce/as.c +++ b/mach/i86/ce/as.c @@ -108,57 +108,57 @@ struct t_operand *op; case 'x' : case 'l' : switch( *str) { case 'a' : op->reg = 0; - return( TRUE); + return( true); case 'c' : op->reg = 1; - return( TRUE); + return( true); case 'd' : op->reg = 2; - return( TRUE); + return( true); case 'b' : op->reg = 3; - return( TRUE); + return( true); - default : return( FALSE); + default : return( false); } case 'h' : switch( *str) { case 'a' : op->reg = 4; - return( TRUE); + return( true); case 'c' : op->reg = 5; - return( TRUE); + return( true); case 'd' : op->reg = 6; - return( TRUE); + return( true); case 'b' : op->reg = 7; - return( TRUE); + return( true); - default : return( FALSE); + default : return( false); } case 'p' : switch ( *str) { case 's' : op->reg = 4; - return( TRUE); + return( true); case 'b' : op->reg = 5; - return( TRUE); + return( true); - default : return( FALSE); + default : return( false); } case 'i' : switch ( *str) { case 's' : op->reg = 6; - return( TRUE); + return( true); case 'd' : op->reg = 7; - return( TRUE); + return( true); - default : return( FALSE); + default : return( false); } - default : return( FALSE); + default : return( false); } } @@ -171,7 +171,7 @@ char *str; while( !isletter( *str) && *str != '\0') if ( *str == '$') if ( arg_type( str) == STRING) - return( TRUE); + return( true); else str += 2; else diff --git a/mach/i86/ce/as.h b/mach/i86/ce/as.h index e39e6871c1..6fd636dc01 100644 --- a/mach/i86/ce/as.h +++ b/mach/i86/ce/as.h @@ -28,9 +28,6 @@ #define MOVS( op) ( op->type & IS_LABEL&&strcmp("\"movs\"", op->lab) == 0) #define IMMEDIATE( op) ( op->type & ( IS_DATA | IS_LABEL)) -#define TRUE 1 -#define FALSE 0 - struct t_operand { unsigned type; int reg; diff --git a/mach/i86/ce/mach.c b/mach/i86/ce/mach.c index ee30345c22..6e5590bd76 100644 --- a/mach/i86/ce/mach.c +++ b/mach/i86/ce/mach.c @@ -12,7 +12,7 @@ int arg; } #endif -int push_waiting = FALSE; +int push_waiting = false; int fit_byte( val) int val; diff --git a/mach/i86/ce/mach.h b/mach/i86/ce/mach.h index 5860f682e2..0e2cd9f008 100644 --- a/mach/i86/ce/mach.h +++ b/mach/i86/ce/mach.h @@ -18,10 +18,7 @@ #define GENLAB 'I' -#define TRUE 1 -#define FALSE 0 - -#define clean_push_buf() if(push_waiting){text1(0x50);push_waiting=FALSE;} +#define clean_push_buf() if(push_waiting){text1(0x50);push_waiting=false;} #define assign( l, r) l = r extern int push_waiting; diff --git a/mach/m68020/top/table b/mach/m68020/top/table index 961c4b1b22..b29ca60da4 100644 --- a/mach/m68020/top/table +++ b/mach/m68020/top/table @@ -13,7 +13,7 @@ CONST {VAL[0] == '#' }; /* constant */ NUM {is_number(VAL) }; A,B {no_side_effects(VAL) }; D {VAL[0] != '#' && !is_areg(VAL) }; /* not an addr. reg */ -X,Y {TRUE }; +X,Y {true }; DREG,DREG2 {is_dreg(VAL) }; /* data register */ DSREG {is_dsreg(VAL) }; /* data register */ AREG {is_areg(VAL) }; /* addressregister */ @@ -21,7 +21,7 @@ FPREG,FPREG2 {is_fpreg(VAL) }; /* fp register */ LAB,L1,L2 {VAL[0] == 'I' }; /* label */ NO32 {no_part("div",VAL) && no_part("mul",VAL) && no_part(".l",VAL)}; /* for move.w ... */ -BITNO {TRUE }; +BITNO {true }; %%; @@ -185,9 +185,9 @@ int no_side_effects(s) for(;;) { switch(*s++) { - case '\0': return TRUE; - case '-': if (*s == '(') return FALSE; break; - case ')': if (*s == '+') return FALSE; break; + case '\0': return true; + case '-': if (*s == '(') return false; break; + case ')': if (*s == '+') return false; break; } } /* NOTREACHED */ @@ -283,13 +283,13 @@ int no_part(part,s) while (*s != '\0') { if (*s == *part) { for (tmp1=part,tmp2=s;; tmp1++,tmp2++) { - if (*tmp1== '\0') return FALSE; + if (*tmp1== '\0') return false; if (*tmp1 != *tmp2) break; } } s++; } - return TRUE; + return true; } @@ -305,9 +305,9 @@ int is_number(s) register char *s; { while (*s != '\0') { - if (*s < '0' || *s++ > '9') return FALSE; + if (*s < '0' || *s++ > '9') return false; } - return TRUE; + return true; } int bitno(s,no) @@ -316,15 +316,15 @@ int bitno(s,no) int n,i; n = atoi(s); - if (n < 1 || n > 128) return FALSE; + if (n < 1 || n > 128) return false; for (i = 0; i < 8 ; i++) { if (n == 1) { sprintf(no,"%d",i); - return TRUE; + return true; } n >>= 1; } - return FALSE; + return false; } int combines_to_double(a,b) @@ -347,7 +347,7 @@ int combines_to_double(a,b) *a++ == 'a' && *a++ && *a++ == ')' && !*a; } - return FALSE; + return false; } while (*a && *a == *b) { a++; @@ -355,7 +355,7 @@ int combines_to_double(a,b) } if (*b++ == ')' && ! *b && *a++ == '+' && *a++ == '4' && *a++ == ')' && !*a) - return TRUE; + return true; } - return FALSE; + return false; } diff --git a/mach/m68k2/top/table b/mach/m68k2/top/table index dd07678b2c..c7843aae00 100644 --- a/mach/m68k2/top/table +++ b/mach/m68k2/top/table @@ -13,12 +13,12 @@ CONST {VAL[0] == '#' }; /* constant */ NUM {is_number(VAL) }; A,B {no_side_effects(VAL) }; D {VAL[0] != '#' && !is_areg(VAL) }; /* not an addr. reg */ -X,Y {TRUE }; +X,Y {true }; DREG,DREG2 {is_dreg(VAL) }; /* data register */ DSREG {is_dsreg(VAL) }; /* data register */ AREG {is_areg(VAL) }; /* addressregister */ LAB,L1,L2 {VAL[0] == 'I' }; /* label */ -BITNO {TRUE }; +BITNO {true }; %%; @@ -147,9 +147,9 @@ int no_side_effects(s) for(;;) { switch(*s++) { - case '\0': return TRUE; - case '-': if (*s == '(') return FALSE; break; - case ')': if (*s == '+') return FALSE; break; + case '\0': return true; + case '-': if (*s == '(') return false; break; + case ')': if (*s == '+') return false; break; } } /* NOTREACHED */ @@ -182,13 +182,13 @@ int no_part(part,s) while (*s != '\0') { if (*s == *part) { for (tmp1=part,tmp2=s;; tmp1++,tmp2++) { - if (*tmp1== '\0') return FALSE; + if (*tmp1== '\0') return false; if (*tmp1 != *tmp2) break; } } s++; } - return TRUE; + return true; } @@ -204,9 +204,9 @@ int is_number(s) register char *s; { while (*s != '\0') { - if (*s < '0' || *s++ > '9') return FALSE; + if (*s < '0' || *s++ > '9') return false; } - return TRUE; + return true; } int bitno(s,no) @@ -215,13 +215,13 @@ int bitno(s,no) int n,i; n = atoi(s); - if (n < 1 || n > 128) return FALSE; + if (n < 1 || n > 128) return false; for (i = 0; i < 8 ; i++) { if (n == 1) { sprintf(no,"%d",i); - return TRUE; + return true; } n >>= 1; } - return FALSE; + return false; } diff --git a/mach/minix/libsys/_exec.c b/mach/minix/libsys/_exec.c index f77cf6fc42..8e428a0f21 100644 --- a/mach/minix/libsys/_exec.c +++ b/mach/minix/libsys/_exec.c @@ -80,28 +80,28 @@ int nenvps; /* number of environment strings */ #if ARG_MAX > INT_MAX #error /* overflow checks and sbrk depend on sizes being ints */ #endif - overflow = FALSE; + overflow = false; npointers = 1 + nargs + 1 + nenvps + 1; /* 1's for argc and NULLs */ stackbytes = 0; /* changed because _len is used now */ if (nargs < 0 || nenvps < 0 || nargs+nenvps < 0 || npointers < 0) - overflow = TRUE; + overflow = true; for (i = PTRSIZE; i != 0; i--) { temp = stackbytes + npointers; - if (temp < stackbytes) overflow = TRUE; + if (temp < stackbytes) overflow = true; stackbytes = temp; } for (i = 0, ap = argv; i < nargs; i++) { temp = stackbytes + _len(*ap++); - if (temp < stackbytes) overflow = TRUE; + if (temp < stackbytes) overflow = true; stackbytes = temp; } for (i = 0, ap = envp; i < nenvps; i++) { temp = stackbytes + _len(*ap++); - if (temp < stackbytes) overflow = TRUE; + if (temp < stackbytes) overflow = true; stackbytes = temp; } temp = stackbytes + PTRSIZE - 1; - if (temp < stackbytes) overflow = TRUE; + if (temp < stackbytes) overflow = true; stackbytes = (temp / PTRSIZE) * PTRSIZE; /* Check for overflow before committing sbrk. */ diff --git a/mach/mips/top/table b/mach/mips/top/table index 655f288c73..c40f21e3e4 100644 --- a/mach/mips/top/table +++ b/mach/mips/top/table @@ -10,8 +10,8 @@ int plus(const char *, const char *, char *); %%; -X, Y, Z { TRUE }; -R { TRUE }; +X, Y, Z { true }; +R { true }; %%; diff --git a/mach/pdp/top/table b/mach/pdp/top/table index 5cb1ff52f3..2c7d182981 100644 --- a/mach/pdp/top/table +++ b/mach/pdp/top/table @@ -21,7 +21,7 @@ ZERO {strcmp(VAL,"$00") == 0 }; ONE {strcmp(VAL,"$01") == 0 }; CONST {VAL[0] == '$' }; /* constant */ A,B {no_side_effects(VAL) }; -X,Y {TRUE }; +X,Y {true }; REG {is_register(VAL) }; /* register */ SREG {is_scratchreg(VAL) }; /* scratch reg */ M_ONE {strcmp(VAL,"$-1") == 0 }; /* -1 */ @@ -76,9 +76,9 @@ int no_side_effects(char* s) for(;;) { switch(*s++) { - case '\0': return TRUE; - case '-': if (*s == '(') return FALSE; break; - case ')': if (*s == '+') return FALSE; break; + case '\0': return true; + case '-': if (*s == '(') return false; break; + case ')': if (*s == '+') return false; break; } } /* NOTREACHED */ @@ -105,6 +105,6 @@ int carry_dead(char* s) case 's': /* sbc and sbcb */ return *s++ != 'b' || *s != 'c'; default: - return TRUE; + return true; } } diff --git a/mach/powerpc/top/table b/mach/powerpc/top/table index b606fd0c58..ea8ad5092b 100644 --- a/mach/powerpc/top/table +++ b/mach/powerpc/top/table @@ -16,7 +16,7 @@ int plus(const char *, const char *, char *); L1, L2, L3, L4, L5 { not_using_sp(VAL) }; RNZ { strcmp(VAL, "r0") }; /* not r0 */ UP { positive(VAL) }; -X, Y, Z { TRUE }; +X, Y, Z { true }; %%; diff --git a/mach/proto/as/comm0.h b/mach/proto/as/comm0.h index e2f42a311f..2a59bb0012 100644 --- a/mach/proto/as/comm0.h +++ b/mach/proto/as/comm0.h @@ -21,6 +21,7 @@ _include #include #include #include +#include #include #include #endif diff --git a/mach/proto/cg/codegen.c b/mach/proto/cg/codegen.c index 4fdafa0463..2c8f31d9f3 100644 --- a/mach/proto/cg/codegen.c +++ b/mach/proto/cg/codegen.c @@ -4,6 +4,7 @@ * * Author: Hans van Staveren */ +#include #include "assert.h" #include "param.h" #include "tables.h" @@ -117,7 +118,7 @@ unsigned int codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, switch ((*codep++) & 037) { default: - assert(FALSE); + assert(false); UNREACHABLE_CODE; case DO_NEXTEM: DEBUG("NEXTEM") @@ -203,7 +204,7 @@ unsigned int codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, mincost = costlimit - totalcost + 1; for (i = 0; i < npos; i++) { - t = codegen(&coderules[pos[i]], ply, FALSE, + t = codegen(&coderules[pos[i]], ply, false, costlimit < MAXINT ? mincost : MAXINT, 0); #ifndef NDEBUG @@ -419,14 +420,14 @@ unsigned int codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, #endif ntup = tup->p_next; for (i = 0, t = 0; i < nregneeded && t < mincost; i++) - t += docoerc(regtp[i], regcp[i], ply, FALSE, + t += docoerc(regtp[i], regcp[i], ply, false, tup->p_rar[i]); #ifndef NDEBUG if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t); #endif if (t < mincost) - t += codegen(codep, ply, FALSE, + t += codegen(codep, ply, false, mincost < MAXINT ? mincost - t : MAXINT, 0); if (t < mincost) { @@ -534,13 +535,13 @@ unsigned int codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, ; instance(tinstno, &token); if (token.t_token == -1) - chrefcount(token.t_att[0].ar, -1, TRUE); + chrefcount(token.t_att[0].ar, -1, true); else { tdp = &tokens[token.t_token]; for (i = 0; i < TOKENSIZE; i++) if (tdp->t_type[i] == EV_REG) - chrefcount(token.t_att[i].ar, -1, TRUE); + chrefcount(token.t_att[i].ar, -1, true); } break; case DO_REALLOCATE: @@ -573,7 +574,7 @@ unsigned int codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, { npos = exactmatch = 0; for (rpp = reglist[propno]; (rp = *rpp); rpp++) - if (getrefcount((int) (rp - machregs), FALSE) == 0) + if (getrefcount((int) (rp - machregs), false) == 0) { pos[npos++] = rp - machregs; if (eqtoken(&rp->r_contents, &token)) @@ -644,18 +645,18 @@ unsigned int codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, mincost = costlimit - totalcost + 1; for (j = 0; j < npos2; j++) { - chrefcount(pos2[j], 1, FALSE); + chrefcount(pos2[j], 1, false); token2.t_att[0].ar = pos2[j]; allreg[nallreg++] = pos2[j]; if (token.t_token != 0) - t = move(&token, &token2, ply, FALSE, mincost); + t = move(&token, &token2, ply, false, mincost); else { t = 0; erasereg(pos2[j]); } if (t < mincost) - t += codegen(codep, ply, FALSE, + t += codegen(codep, ply, false, mincost < MAXINT ? mincost - t : MAXINT, 0); if (t < mincost) @@ -675,14 +676,14 @@ unsigned int codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, else { decision = forced; - if (getrefcount(decision, FALSE) != 0) + if (getrefcount(decision, false) != 0) { totalcost = INFINITY; BROKE(); } token2.t_token = -1; } - chrefcount(decision, 1, FALSE); + chrefcount(decision, 1, false); token2.t_att[0].ar = decision; if (token.t_token != 0) { @@ -770,7 +771,7 @@ unsigned int codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, */ } for (i = 0; i < nallreg; i++) - chrefcount(allreg[i], -1, FALSE); + chrefcount(allreg[i], -1, false); break; case DO_EMREPLACE: DEBUG("EMREPLACE") @@ -796,7 +797,7 @@ unsigned int codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, switch (result.e_typ) { default: - assert(FALSE); + assert(false); case 0: emp[i].em_optyp = OPNO; emp[i].em_soper = 0; diff --git a/mach/proto/cg/compute.c b/mach/proto/cg/compute.c index 8ca6be8bbe..39fa22d74b 100644 --- a/mach/proto/cg/compute.c +++ b/mach/proto/cg/compute.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include "assert.h" #include "param.h" @@ -132,7 +133,7 @@ result_t compute(node_p node) } result.e_typ=EV_INT; switch(node->ex_operator) { - default: assert(FALSE); + default: assert(false); case EX_TOKFIELD: if (node->ex_lnode!=0) tp = &fakestack[stackheight-node->ex_lnode]; @@ -140,7 +141,7 @@ result_t compute(node_p node) tp = curtoken; switch(result.e_typ = tokens[tp->t_token].t_type[node->ex_rnode-1]) { default: - assert(FALSE); + assert(false); case EV_INT: result.e_v.e_con = tp->t_att[node->ex_rnode-1].aw; break; diff --git a/mach/proto/cg/equiv.c b/mach/proto/cg/equiv.c index ba56945bc6..72cb05eac3 100644 --- a/mach/proto/cg/equiv.c +++ b/mach/proto/cg/equiv.c @@ -4,6 +4,7 @@ * * Author: Hans van Staveren */ +#include #include "assert.h" #include "equiv.h" #include "param.h" @@ -40,7 +41,7 @@ struct perm* tuples(rl_p* regls, int nregneeded) for (i = 0; i < NREGS; i++) { regclass[i] = class ++; - if (getrefcount(i, FALSE) == 0) + if (getrefcount(i, false) == 0) { for (j = 0; j < i; j++) { diff --git a/mach/proto/cg/fillem.c b/mach/proto/cg/fillem.c index c2ca92d8d6..dc2a317b8a 100644 --- a/mach/proto/cg/fillem.c +++ b/mach/proto/cg/fillem.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include "assert.h" #include @@ -250,7 +251,7 @@ void dopseudo(void) { case sp_ilb1: case sp_ilb2: swtxt(); - dummy = stackupto(&fakestack[stackheight-1],maxply,TRUE); + dummy = stackupto(&fakestack[stackheight-1],maxply,true); cleanregs(); strarg(savetab1); newilb(argstr); @@ -339,7 +340,7 @@ void dopseudo(void) { getarg(ptyp(sp_cend)); if (!regallowed) error("mes 3 not allowed here"); - fixregvars(TRUE); + fixregvars(true); regallowed=0; } else if (argval == ms_reg) { long r_off; @@ -348,7 +349,7 @@ void dopseudo(void) { if (!regallowed) error("mes 3 not allowed here"); if(getarg(ptyp(sp_cst2)|ptyp(sp_cend)) == sp_cend) { - fixregvars(FALSE); + fixregvars(false); regallowed=0; } else { r_off = argval; @@ -647,7 +648,7 @@ static long con(int t) { con_float(); return(argval); } - assert(FALSE); + assert(false); UNREACHABLE_CODE; } diff --git a/mach/proto/cg/gencode.c b/mach/proto/cg/gencode.c index 16b0b8c1bf..1339b9a430 100644 --- a/mach/proto/cg/gencode.c +++ b/mach/proto/cg/gencode.c @@ -6,6 +6,7 @@ */ #include "assert.h" #include +#include #include "param.h" #include "tables.h" #include "types.h" @@ -83,7 +84,7 @@ void gencode(char *code) assert(tp->t_token != -1); switch(tokens[tp->t_token].t_type[fldno-1]) { default: - assert(FALSE); + assert(false); case EV_INT: fprintf(codefile,WRD_FMT,tp->t_att[fldno-1].aw); break; @@ -136,7 +137,7 @@ void genexpr(int nodeno) result= compute(&enodes[nodeno]); switch(result.e_typ) { - default: assert(FALSE); + default: assert(false); case EV_INT: fprintf(codefile,WRD_FMT,result.e_v.e_con); break; @@ -170,7 +171,7 @@ void prtoken(token_p tp) assert(c>0 && c<=TOKENSIZE); switch(tdp->t_type[c-1]) { default: - assert(FALSE); + assert(false); case EV_INT: fprintf(codefile,WRD_FMT,tp->t_att[c-1].aw); break; diff --git a/mach/proto/cg/main.c b/mach/proto/cg/main.c index ac4c721e00..0d504467cd 100644 --- a/mach/proto/cg/main.c +++ b/mach/proto/cg/main.c @@ -5,6 +5,7 @@ * Author: Hans van Staveren */ #include +#include #include "tables.h" #include "types.h" #include @@ -81,7 +82,7 @@ int main(int argc, char **argv) in_init(argv[0]); out_init(argv[1]); in_start(); - codegen(startupcode,maxply,TRUE,MAXINT,0); + codegen(startupcode,maxply,true,MAXINT,0); in_finish(); if (!endofprog) error("Bombed out of codegen"); diff --git a/mach/proto/cg/param.h b/mach/proto/cg/param.h index b3c43f6feb..e2e722942a 100644 --- a/mach/proto/cg/param.h +++ b/mach/proto/cg/param.h @@ -7,9 +7,6 @@ #define BMASK 0377 #define BSHIFT 8 -#define TRUE 1 -#define FALSE 0 - #define MAXINT 32767 #define INFINITY (MAXINT+100) diff --git a/mach/proto/cg/salloc.c b/mach/proto/cg/salloc.c index 354a37ad0b..145fc76757 100644 --- a/mach/proto/cg/salloc.c +++ b/mach/proto/cg/salloc.c @@ -5,6 +5,7 @@ * Author: Hans van Staveren */ #include +#include #include "assert.h" #include "param.h" #include "tables.h" @@ -112,7 +113,7 @@ void garbage_collect(void) { return; qsort(stab,nstab,sizeof (char *),compar); for (i=0;iem_soper,used); for (tp= fakestack;tp<&fakestack[stackheight];tp++) { diff --git a/mach/proto/cg/subr.c b/mach/proto/cg/subr.c index 071b979fc8..3913d4e5da 100644 --- a/mach/proto/cg/subr.c +++ b/mach/proto/cg/subr.c @@ -5,6 +5,7 @@ * Author: Hans van Staveren */ #include +#include #include #include #include "assert.h" @@ -36,7 +37,7 @@ int match(token_p tp, set_p tep, int optexp) if (tp->t_token == -1) { /* register frame */ bitno = tp->t_att[0].ar+1; if (tep->set_val[bitno>>4]&(1<<(bitno&017))) - if (tep->set_val[0]&1 || getrefcount(tp->t_att[0].ar, FALSE)<=1) + if (tep->set_val[0]&1 || getrefcount(tp->t_att[0].ar, false)<=1) goto oklabel; return(0); } else { /* token frame */ @@ -72,7 +73,7 @@ void instance(int instno, token_p token) inp= &tokeninstances[instno]; switch(inp->in_which) { default: - assert(FALSE); + assert(false); case IN_COPY: tp= &fakestack[stackheight-inp->in_info[0]]; if (inp->in_info[1]==0) { @@ -147,7 +148,7 @@ void cinstance(int instno, token_p token, inp= &tokeninstances[instno]; switch(inp->in_which) { default: - assert(FALSE); + assert(false); case IN_COPY: assert(inp->in_info[0] == 1); if (inp->in_info[1]==0) { @@ -320,7 +321,7 @@ int instsize(int tinstno,token_p tp) { inp = &tokeninstances[tinstno]; switch(inp->in_which) { default: - assert(FALSE); + assert(false); case IN_COPY: assert(inp->in_info[0]==1); #if MAXMEMBERS!=0 @@ -337,7 +338,7 @@ int instsize(int tinstno,token_p tp) { case IN_RIDENT: return(machregs[inp->in_info[0]].r_size); case IN_ALLOC: - assert(FALSE); /* cannot occur in splitting coercion */ + assert(false); /* cannot occur in splitting coercion */ case IN_DESCR: return(tokens[inp->in_info[0]].t_size); } @@ -349,12 +350,12 @@ void tref(token_p tp,int amount) { tkdef_p tdp; if (tp->t_token==-1) - chrefcount(tp->t_att[0].ar,amount,FALSE); + chrefcount(tp->t_att[0].ar,amount,false); else { tdp= &tokens[tp->t_token]; for(i=0;it_type[i]==EV_REG) - chrefcount(tp->t_att[i].ar,amount,FALSE); + chrefcount(tp->t_att[i].ar,amount,false); } } @@ -445,7 +446,7 @@ unsigned stackupto(token_p limit,int ply,int toplevel) if (cp->c1_prop>=0) { for (rpp=reglist[cp->c1_prop]; (rp = *rpp)!=0 && - getrefcount((int)(rp-machregs), TRUE)!=0; + getrefcount((int)(rp-machregs), true)!=0; rpp++) ; if (rp==0) @@ -465,7 +466,7 @@ unsigned stackupto(token_p limit,int ply,int toplevel) areg[i] = allreg[i]; if (cp->c1_prop>=0) { nallreg=1; allreg[0] = rp-machregs; - chrefcount(allreg[0],1,FALSE); + chrefcount(allreg[0],1,false); } else nallreg=0; totalcost+= codegen(&coderules[cp->c1_codep],ply,toplevel,MAXINT,0); @@ -479,7 +480,7 @@ unsigned stackupto(token_p limit,int ply,int toplevel) goto contin; } } - assert(FALSE); + assert(false); contin: ; } return(totalcost); diff --git a/mach/proto/fp/adder.c b/mach/proto/fp/adder.c index 581d271253..f76b640847 100644 --- a/mach/proto/fp/adder.c +++ b/mach/proto/fp/adder.c @@ -15,8 +15,6 @@ # include "FP_types.h" # define UNKNOWN -1 -# define TRUE 1 -# define FALSE 0 # define MAXBIT 0x80000000L /* @@ -45,6 +43,6 @@ register B64 *e1,*e2; fflush(stdout); # endif if ((carry) && (++e1->h_32 == 0)) - return(TRUE); /* had a 64 bit overflow */ + return(true); /* had a 64 bit overflow */ return(overflow); /* return status from higher add */ } diff --git a/mach/proto/ncg/codegen.c b/mach/proto/ncg/codegen.c index 6e7451a339..5f2fb799b4 100644 --- a/mach/proto/ncg/codegen.c +++ b/mach/proto/ncg/codegen.c @@ -6,6 +6,7 @@ static char rcsid[] = "$Id$"; #include #include #include +#include #include "param.h" #include "tables.h" #include "types.h" @@ -96,7 +97,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for switch ((*codep++) & 037) { default: - assert(FALSE); + assert(false); UNREACHABLE_CODE; #ifdef TABLEDEBUG case DO_DLINE: @@ -243,7 +244,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for assert(mincost <= INFINITY); for (i = 0; i < npos; i++) { - t = codegen(&coderules[pos[i]], ply, FALSE, + t = codegen(&coderules[pos[i]], ply, false, costlimit < MAXINT ? mincost : MAXINT, 0); #ifndef NDEBUG if (Debug) @@ -486,7 +487,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for #endif ntup = tup->p_next; for (i = 0, t = 0; i < nregneeded && t < mincost; i++) - t += docoerc(regtp[i], regcp[i], ply, FALSE, tup->p_rar[i]); + t += docoerc(regtp[i], regcp[i], ply, false, tup->p_rar[i]); #ifndef NDEBUG if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t); @@ -497,7 +498,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for if (Debug > 2) fprintf(stderr, "Continuing match after coercions\n"); #endif - t += codegen(codep, ply, FALSE, mincost < MAXINT ? mincost - t : MAXINT, 0); + t += codegen(codep, ply, false, mincost < MAXINT ? mincost - t : MAXINT, 0); } if (t < mincost && tokpatlen <= stackheight) { @@ -653,13 +654,13 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for getint(tinstno, codep); instance(tinstno, &token); if (token.t_token == -1) - chrefcount(token.t_att[0].ar, -1, TRUE); + chrefcount(token.t_att[0].ar, -1, true); else { tdp = &tokens[token.t_token]; for (i = 0; i < TOKENSIZE; i++) if (tdp->t_type[i] == EV_REG) - chrefcount(token.t_att[i].ar, -1, TRUE); + chrefcount(token.t_att[i].ar, -1, true); } break; } @@ -707,7 +708,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for { npos = exactmatch = 0; for (rpp = reglist[propno]; (rp = *rpp) != NULL; rpp++) - if (getrefcount((int)(rp - machregs), FALSE) == 0) + if (getrefcount((int)(rp - machregs), false) == 0) { pos[npos++] = rp - machregs; if (eqtoken(&rp->r_contents, &token)) @@ -792,18 +793,18 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for mincost = costlimit - totalcost + 1; for (j = 0; j < npos2; j++) { - chrefcount(pos2[j], 1, FALSE); + chrefcount(pos2[j], 1, false); token2.t_att[0].ar = pos2[j]; allreg[nallreg++] = pos2[j]; if (token.t_token != 0) - t = move(&token, &token2, ply, FALSE, mincost); + t = move(&token, &token2, ply, false, mincost); else { t = 0; erasereg(pos2[j]); } if (t < mincost) - t += codegen(codep, ply, FALSE, mincost < MAXINT ? mincost - t : MAXINT, 0); + t += codegen(codep, ply, false, mincost < MAXINT ? mincost - t : MAXINT, 0); if (t < mincost) { mincost = t; @@ -819,11 +820,11 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for else { decision = forced; - if (getrefcount(decision, FALSE) != 0) + if (getrefcount(decision, false) != 0) BROKE(); token2.t_token = -1; } - chrefcount(decision, 1, FALSE); + chrefcount(decision, 1, false); token2.t_att[0].ar = decision; if (token.t_token != 0) { @@ -956,7 +957,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for fakestack[stackheight++] = reptoken[i]; } for (i = 0; i < nallreg; i++) - chrefcount(allreg[i], -1, FALSE); + chrefcount(allreg[i], -1, false); break; } case DO_EMREPLACE: @@ -990,7 +991,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for switch (result[i].e_typ) { default: - assert(FALSE); + assert(false); case 0: emp[i].em_optyp = OPNO; emp[i].em_soper = 0; diff --git a/mach/proto/ncg/compute.c b/mach/proto/ncg/compute.c index 4dfc86d1f6..27fd7eb705 100644 --- a/mach/proto/ncg/compute.c +++ b/mach/proto/ncg/compute.c @@ -5,6 +5,7 @@ static char rcsid[] = "$Id$"; #include #include #include +#include #include #include "param.h" #include "tables.h" @@ -143,7 +144,7 @@ void compute(node_p node, result_t *presult) { } presult->e_typ=EV_INT; switch(node->ex_operator) { - default: assert(FALSE); + default: assert(false); case EX_TOKFIELD: if (node->ex_lnode==0) if (curtoken) tp = curtoken; @@ -151,7 +152,7 @@ void compute(node_p node, result_t *presult) { else tp = &fakestack[stackheight-node->ex_lnode]; switch(presult->e_typ = tokens[tp->t_token].t_type[node->ex_rnode-1]) { default: - assert(FALSE); + assert(false); case EV_INT: presult->e_v.e_con = tp->t_att[node->ex_rnode-1].aw; break; diff --git a/mach/proto/ncg/equiv.c b/mach/proto/ncg/equiv.c index 01a518bd45..411d517475 100644 --- a/mach/proto/ncg/equiv.c +++ b/mach/proto/ncg/equiv.c @@ -5,6 +5,7 @@ static char rcsid[] = "$Id$"; #include #include #include +#include #include "param.h" #include "tables.h" #include "types.h" @@ -40,7 +41,7 @@ struct perm *tuples(rl_p *regls, int nregneeded) { for (i=NREGS, rp = &machregs[NREGS-1];--i>=0;rp--) { regclass[i] = class++; - if (getrefcount(i, FALSE) == 0) { + if (getrefcount(i, false) == 0) { for (j=NREGS;--j>i;) { if (eqregclass(i,j) && eqtoken(&rp->r_contents, diff --git a/mach/proto/ncg/fillem.c b/mach/proto/ncg/fillem.c index 270c9442a2..be724242a6 100644 --- a/mach/proto/ncg/fillem.c +++ b/mach/proto/ncg/fillem.c @@ -5,6 +5,7 @@ static char rcsid2[] = "$Id$"; #include #include #include +#include #include #include #include @@ -263,7 +264,7 @@ dopseudo(void) { case sp_ilb1: case sp_ilb2: swtxt(); - /* dummy = */stackupto(&fakestack[stackheight-1],maxply,TRUE); + /* dummy = */stackupto(&fakestack[stackheight-1],maxply,true); cleanregs(); strarg(savetab1); newilb(argstr); @@ -371,7 +372,7 @@ dopseudo(void) { getarg(ptyp(sp_cend)); if (!regallowed) error("mes 3 not allowed here"); - fixregvars(TRUE); + fixregvars(true); regallowed=0; } else if (argval == ms_reg) { long r_off; @@ -380,7 +381,7 @@ dopseudo(void) { if (!regallowed) error("mes 3 not allowed here"); if(getarg(ptyp(sp_cst2)|ptyp(sp_cend)) == sp_cend) { - fixregvars(FALSE); + fixregvars(false); regallowed=0; } else { r_off = argval; @@ -686,7 +687,7 @@ static long con(int t) { con_float(); return(argval); } - assert(FALSE); + assert(false); UNREACHABLE_CODE; } diff --git a/mach/proto/ncg/gencode.c b/mach/proto/ncg/gencode.c index a0550fde13..d995a5206b 100644 --- a/mach/proto/ncg/gencode.c +++ b/mach/proto/ncg/gencode.c @@ -4,6 +4,7 @@ static char rcsid[] = "$Id$"; #include #include +#include #include /* isatty */ #include "param.h" #include "tables.h" @@ -126,7 +127,7 @@ void prtoken(token_p tp, int leadingchar) { assert(c>0 && c<=TOKENSIZE); switch(tdp->t_type[c-1]) { default: - assert(FALSE); + assert(false); case EV_INT: fprintf(codefile,WRD_FMT,tp->t_att[c-1].aw); break; diff --git a/mach/proto/ncg/label.c b/mach/proto/ncg/label.c index 21eb6b6e2b..06d4c52f60 100644 --- a/mach/proto/ncg/label.c +++ b/mach/proto/ncg/label.c @@ -1,3 +1,4 @@ +#include #include "tables.h" #ifdef USE_TES #include "types.h" @@ -11,7 +12,7 @@ void add_label(int num, int height, int flth) label_p lbl = (label_p)0; if (height <= 0) return; - if (flth != TRUE && flth != FALSE) + if (flth != true && flth != false) fatal("incorrect value for fallthrough"); lbl = (label_p) myalloc(sizeof(struct label)); diff --git a/mach/proto/ncg/main.c b/mach/proto/ncg/main.c index 80915e94db..fba617983f 100644 --- a/mach/proto/ncg/main.c +++ b/mach/proto/ncg/main.c @@ -3,6 +3,7 @@ static char rcsid[] = "$Id$"; #endif #include /* atoi */ +#include #include "param.h" #include "tables.h" #include "types.h" @@ -82,7 +83,7 @@ int main(int argc, char **argv) { readcodebytes(); itokcost(); in_start(); - codegen(startupcode,maxply,TRUE,MAXINT,0); + codegen(startupcode,maxply,true,MAXINT,0); error("Bombed out of codegen"); } diff --git a/mach/proto/ncg/param.h b/mach/proto/ncg/param.h index 1a6c844150..374216e4ac 100644 --- a/mach/proto/ncg/param.h +++ b/mach/proto/ncg/param.h @@ -7,9 +7,6 @@ #define BMASK 0377 #define BSHIFT 8 -#define TRUE 1 -#define FALSE 0 - #define MAXINT 32767 #define INFINITY (MAXINT+100) diff --git a/mach/proto/ncg/salloc.c b/mach/proto/ncg/salloc.c index 0f9fa28f89..ae70ea3bd1 100644 --- a/mach/proto/ncg/salloc.c +++ b/mach/proto/ncg/salloc.c @@ -5,6 +5,7 @@ static char rcsid[] = "$Id$"; #include #include #include +#include #include "param.h" #include "tables.h" #include "types.h" @@ -89,7 +90,7 @@ void garbage_collect(void) { return; qsort((char *)stab,nstab,sizeof (char *),compar); for (i=0;iem_soper,used); for (tp= fakestack;tp<&fakestack[stackheight];tp++) { diff --git a/mach/proto/ncg/subr.c b/mach/proto/ncg/subr.c index 0dc0459737..97505e252f 100644 --- a/mach/proto/ncg/subr.c +++ b/mach/proto/ncg/subr.c @@ -6,6 +6,7 @@ static char rcsid[] = "$Id$"; #include #include #include +#include #include /* strcmp */ #include "param.h" #include "tables.h" @@ -38,7 +39,7 @@ int match(token_p tp, set_p tep, int optexp) { if (tp->t_token == -1) { /* register frame */ bitno = tp->t_att[0].ar; if (tep->set_val[bitno>>4]&(1<<(bitno&017))) - if (tep->set_val[0]&1 || getrefcount(bitno, FALSE)<=1) + if (tep->set_val[0]&1 || getrefcount(bitno, false)<=1) goto oklabel; return(0); } else { /* token frame */ @@ -75,7 +76,7 @@ void instance(int instno, token_p token) { inp= &tokeninstances[instno]; switch (inp->in_which) { default: - assert(FALSE); + assert(false); case IN_COPY: if (inp->in_info[0] == 0) if (curtoken) tp = curtoken; @@ -90,7 +91,7 @@ void instance(int instno, token_p token) { rp = &machregs[tp->t_att[0].ar]; token->t_att[0].ar=rp->r_members[inp->in_info[1]-1]; #else - assert(FALSE); + assert(false); #endif } return; @@ -167,7 +168,7 @@ static void cinstance(int instno, token_p token, token_p tp, int regno) { inp= &tokeninstances[instno]; switch (inp->in_which) { default: - assert(FALSE); + assert(false); case IN_COPY: assert(inp->in_info[0] <= 1); if (inp->in_info[1]==0) { @@ -179,7 +180,7 @@ static void cinstance(int instno, token_p token, token_p tp, int regno) { rp = &machregs[tp->t_att[0].ar]; token->t_att[0].ar=rp->r_members[inp->in_info[1]-1]; #else - assert(FALSE); + assert(false); #endif } return; @@ -401,7 +402,7 @@ static int instsize(int tinstno, token_p tp) { inp = &tokeninstances[tinstno]; switch (inp->in_which) { default: - assert(FALSE); + assert(false); case IN_COPY: assert(inp->in_info[0]<=1); #if MAXMEMBERS!=0 @@ -418,7 +419,7 @@ static int instsize(int tinstno, token_p tp) { case IN_RIDENT: return(machregs[inp->in_info[0]].r_size); case IN_ALLOC: - assert(FALSE); /* cannot occur in splitting coercion */ + assert(false); /* cannot occur in splitting coercion */ case IN_DESCR: case IN_S_DESCR: case IN_D_DESCR: @@ -432,12 +433,12 @@ void tref(token_p tp, int amount) { byte *tdpb; if (tp->t_token==-1) - chrefcount(tp->t_att[0].ar,amount,FALSE); + chrefcount(tp->t_att[0].ar,amount,false); else { tdpb= &tokens[tp->t_token].t_type[0]; for(i=0;it_att[i].ar,amount,FALSE); + chrefcount(tp->t_att[i].ar,amount,false); } } @@ -574,7 +575,7 @@ unsigned stackupto(token_p limit, int ply, int toplevel) { if (cp->c1_prop>=0) { for (rpp=reglist[cp->c1_prop]; (rp = *rpp)!=0 && - getrefcount((int)(rp-machregs), TRUE)!=0; + getrefcount((int)(rp-machregs), true)!=0; rpp++) ; if (rp==0) @@ -594,7 +595,7 @@ unsigned stackupto(token_p limit, int ply, int toplevel) { areg[i] = allreg[i]; if (cp->c1_prop>=0) { nallreg=1; allreg[0] = rp-machregs; - chrefcount(allreg[0],1,FALSE); + chrefcount(allreg[0],1,false); } else nallreg=0; totalcost+= codegen(&coderules[cp->c1_codep],ply,toplevel,MAXINT,0); @@ -614,7 +615,7 @@ unsigned stackupto(token_p limit, int ply, int toplevel) { goto contin; } } - assert(FALSE); + assert(false); contin: ; } return(totalcost); diff --git a/mach/proto/top/top.c b/mach/proto/top/top.c index 849453264c..45834eb13f 100644 --- a/mach/proto/top/top.c +++ b/mach/proto/top/top.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "gen.h" #include "top.h" #include "queue.h" @@ -125,10 +126,10 @@ static bool try_hashentry(int *list, queue window) check_operands(p,window) && check_constraint(*pp)) { xform(p,window); - return TRUE; + return true; } } - return FALSE; + return false; } @@ -170,7 +171,7 @@ static void fill_window(queue w, int len) instr_p ip; while(qlength(w) < len) { - if ((ip = read_instr()) == NIL) break; + if ((ip = read_instr()) == NULL) break; ip->rest_line = ip->line; set_opcode(ip); add(w,ip); @@ -228,16 +229,16 @@ static bool check_pattern(patdescr_p p, queue w) ANY.vstate = UNINSTANTIATED; idlim = &p->pat[p->patlen]; for (id_p = p->pat; id_p < idlim; id_p++) { - if (ip == NIL || ip->state == JUNK) return FALSE; + if (ip == NULL || ip->state == JUNK) return false; if (id_p->opcode == (char *) 0) { unify(ip->opc,&ANY); } else { - if (strcmp(ip->opc,id_p->opcode) != 0) return FALSE; + if (strcmp(ip->opc,id_p->opcode) != 0) return false; } ip = next(ip); } REST = ip->opc; - return TRUE; + return true; } @@ -252,19 +253,19 @@ static bool check_operands(patdescr_p p, queue w) clear_vars(); for (id_p = p->pat, ip = qhead(w); id_p < &p->pat[p->patlen]; id_p++, ip = next(ip)) { - assert(ip != NIL); + assert(ip != NULL); if (ip->state == JUNK || (ip->state == ONLY_OPC && !split_operands(ip))) { - return FALSE; + return false; } for (n = 0; n < MAXOP; n++) { if (!opmatch(&id_p->templates[n],ip->op[n])) { - return FALSE; + return false; } } } /* fprintf(stderr,"yes\n"); */ - return TRUE; + return true; } @@ -298,12 +299,12 @@ static bool opmatch(templ_p t, const char *s) } was_instantiated = (var[vno].vstate == INSTANTIATED); strcpy(buf,s); - if ( (l=lstrip(buf,t->lctxt)) != NULLSTRING && rstrip(l,t->rctxt)) { + if ( (l=lstrip(buf,t->lctxt)) != NULL && rstrip(l,t->rctxt)) { return (vno == 0 && *l == '\0') || (vno != 0 && unify(l,&var[vno]) && (was_instantiated || tok_chk(vno))); } - return FALSE; + return false; } @@ -367,11 +368,11 @@ static bool operand(instr_p ip, int n) p++; } oplen = p - ip->rest_line; - if (oplen == 0 || oplen > MAXOPLEN) return FALSE; + if (oplen == 0 || oplen > MAXOPLEN) return false; strncpy(ip->op[n],ip->rest_line,oplen); ip->op[n][oplen] = '\0'; ip->rest_line = p; - return TRUE; + return true; #ifdef nesting #undef nesting #endif @@ -396,12 +397,12 @@ static bool remainder_empty(instr_p ip) static char *lstrip(char *str, const char *ctxt) { - assert(ctxt != NULLSTRING); + assert(ctxt != NULL); while (*str != '\0' && *str == *ctxt) { str++; ctxt++; } - return (*ctxt == '\0' ? str : NULLSTRING); + return (*ctxt == '\0' ? str : NULL); } @@ -418,10 +419,10 @@ static bool rstrip(char *str, const char *ctxt) for (s = str; *s != '\0'; s++); for (c = ctxt; *c != '\0'; c++); while (c >= ctxt) { - if (s < str || *s != *c--) return FALSE; + if (s < str || *s != *c--) return false; *s-- = '\0'; } - return TRUE; + return true; } @@ -437,7 +438,7 @@ static bool unify(const char *str, struct variable *v) if (v->vstate == UNINSTANTIATED) { v->vstate = INSTANTIATED; strcpy(v->value,str); - return TRUE; + return true; } else { return strcmp(v->value,str) == 0; } @@ -498,13 +499,13 @@ static instr_p gen_instr(idescr_p id_p) opc = id_p->opcode; if (opc == (char *) 0) opc = ANY.value; if (strcmp(opc,"labdef") == 0) { - islabdef = TRUE; + islabdef = true; s[0] = '\0'; } else { strcpy(s,opc); tmp[0] = OPC_TERMINATOR; strcat(s,tmp); - islabdef = FALSE; + islabdef = false; } for (n = 0; n < MAXOP;) { t = &id_p->templates[n++]; @@ -537,7 +538,7 @@ static instr_p gen_instr(idescr_p id_p) * each such struct is set to JUNK (so it will not be optimized). */ -static bool junk_state = FALSE; /* TRUE while processing a very long line */ +static bool junk_state = false; /* true while processing a very long line */ static instr_p read_instr(void) { @@ -548,13 +549,13 @@ static instr_p read_instr(void) ip = newinstr(); plim = &ip->line[MAXLINELEN]; - if (( c = getc(inp)) == EOF) return NIL; + if (( c = getc(inp)) == EOF) return NULL; for (p = ip->line; p < plim;) { *p++ = c; if (c == '\n') { *p = '\0'; if (junk_state) ip->state = JUNK; - junk_state = FALSE; + junk_state = false; return ip; } c = getc(inp); @@ -582,16 +583,16 @@ static instr_p newinstr(void) instr_p ip; int i; - if (instr_pool == NIL) { + if (instr_pool == NULL) { instr_pool = (instr_p) malloc(sizeof(struct instruction)); instr_pool->fw = 0; nr_mallocs++; } - assert(instr_pool != NIL); + assert(instr_pool != NULL); ip = instr_pool; instr_pool = instr_pool->fw; - ip->fw = ip->bw = NIL; - ip->rest_line = NULLSTRING; + ip->fw = ip->bw = NULL; + ip->rest_line = NULL; ip->line[0] = ip->opc[0] = '\0'; ip->state = ONLY_OPC; for (i = 0; i < MAXOP; i++) ip->op[i][0] = '\0'; @@ -613,9 +614,9 @@ static bool op_separator(instr_p ip) skip_white(ip); if (*(ip->rest_line) == OP_SEPARATOR) { ip->rest_line++; - return TRUE; + return true; } else { - return FALSE; + return false; } } diff --git a/mach/proto/top/top.h b/mach/proto/top/top.h index 5474f9cd7f..a292378166 100644 --- a/mach/proto/top/top.h +++ b/mach/proto/top/top.h @@ -5,8 +5,6 @@ */ /* Tunable constants; may be overruled by machine descriptor table */ -#include - #ifndef OP_SEPARATOR #define OP_SEPARATOR ',' #endif @@ -83,9 +81,3 @@ struct instr_descr { char *opcode; struct templat templates[MAXOP]; }; - -#define TRUE 1 -#define FALSE 0 - -#define NIL (instr_p) 0 -#define NULLSTRING (char *) 0 diff --git a/mach/sparc/ce/back.src/const.h b/mach/sparc/ce/back.src/const.h index 0a2068341f..e69de29bb2 100644 --- a/mach/sparc/ce/back.src/const.h +++ b/mach/sparc/ce/back.src/const.h @@ -1,2 +0,0 @@ -#define TRUE 1 -#define FALSE 0 diff --git a/mach/sparc/top/table b/mach/sparc/top/table index 3dc338bc1e..3f8bac7e60 100644 --- a/mach/sparc/top/table +++ b/mach/sparc/top/table @@ -9,7 +9,7 @@ OPC_TERMINATOR '\t'; NUM,NUM1,NUM2 {is_number(VAL) }; REG {VAL[0] == '%' }; -A,B,X,Y,Z {TRUE }; +A,B,X,Y,Z {true }; REG_NO_O7 {VAL[0] == '%' && (VAL[1] != 'o' || VAL[2] != '7')}; NO_O7 {no_o7(VAL) }; @@ -86,9 +86,9 @@ int is_number(s) register char *s; { while (*s != '\0') { - if (*s < '0' || *s++ > '9') return FALSE; + if (*s < '0' || *s++ > '9') return false; } - return TRUE; + return true; } int bigger(s,s1,s2) @@ -98,9 +98,9 @@ int bigger(s,s1,s2) if (n >= n1) { sprintf(s2,"%d",n-n1); - return TRUE; + return true; } - return FALSE; + return false; } int smaller(s,s1,s2) @@ -110,9 +110,9 @@ int smaller(s,s1,s2) if (n < n1) { sprintf(s2,"%d",n1-n); - return TRUE; + return true; } - return FALSE; + return false; } int no_delay(s) @@ -129,10 +129,10 @@ int no_o7(s) while (*s && *s != '%') s++; if (*s) { if (*++s == 'o') { - if (*++s == '7') return FALSE; + if (*++s == '7') return false; } } else break; } - return TRUE; + return true; } diff --git a/mach/vax4/ce/as.c b/mach/vax4/ce/as.c index 011c60e1fa..3086e4f41b 100644 --- a/mach/vax4/ce/as.c +++ b/mach/vax4/ce/as.c @@ -154,29 +154,29 @@ int *num; { if ( ( *str == 'a') && ( *(str+1) == 'p')) { *num = 12; - return( TRUE); + return( true); } else if ( ( *str == 'f') && ( *(str+1) == 'p')) { *num = 13; - return( TRUE); + return( true); } else if ( ( *str == 's') && ( *(str+1) == 'p')) { *num = 14; - return( TRUE); + return( true); } if ( *str == 'r') { if ( isdigit( *(str+1)) && isdigit( *(str+2))) { *num = ( *(str+1) - '0') * 10 + *(str+2) - '0'; - return( TRUE); + return( true); } else if ( isdigit( *(str+1))) { *num = *(str+1) - '0'; - return( TRUE); + return( true); } else - return( FALSE); + return( false); } - return( FALSE); + return( false); } diff --git a/mach/vax4/ce/as.h b/mach/vax4/ce/as.h index 205dec3a9a..4750280906 100644 --- a/mach/vax4/ce/as.h +++ b/mach/vax4/ce/as.h @@ -14,9 +14,6 @@ #define LABEL 6 #define L_ILB 7 -#define TRUE 1 -#define FALSE 0 - #define PC_REL 1 struct t_operand { diff --git a/mach/vax4/top/table b/mach/vax4/top/table index 099e82203b..4da1b2d954 100644 --- a/mach/vax4/top/table +++ b/mach/vax4/top/table @@ -20,7 +20,7 @@ SREG {is_scratchreg(VAL)}; LAB,LAB2 {VAL[0] == LABEL_STARTER}; A,B {no_side_effects(VAL) }; NO_INDEX {strchr(VAL, '[') == 0}; -X,Y,LOG {TRUE}; +X,Y,LOG {true}; %%; @@ -267,9 +267,9 @@ int no_side_effects(s) for(;;) { switch(*s++) { - case '\0': return TRUE; - case '-': if (*s == '(') return FALSE; break; - case ')': if (*s == '+') return FALSE; break; + case '\0': return true; + case '-': if (*s == '(') return false; break; + case ')': if (*s == '+') return false; break; } } /* NOTREACHED */ @@ -282,7 +282,7 @@ int is_register(s) if (*s++ == '1' && (*s == '0' || *s == '1')) s++; return *s == '\0'; } - return FALSE; + return false; } int is_scratchreg(s) diff --git a/mach/z80/top/table b/mach/z80/top/table index b871286430..7db1af213d 100644 --- a/mach/z80/top/table +++ b/mach/z80/top/table @@ -5,7 +5,7 @@ MAXOP 2; %%; -X, Y, Z { TRUE }; +X, Y, Z { true }; %%; /* Whitespace is significant here! */ diff --git a/plat/linux68k/emu/musashi/m68kcpu.c b/plat/linux68k/emu/musashi/m68kcpu.c index 1505dc08d9..646e8e78ba 100755 --- a/plat/linux68k/emu/musashi/m68kcpu.c +++ b/plat/linux68k/emu/musashi/m68kcpu.c @@ -1046,7 +1046,7 @@ void m68k_set_irq(unsigned int int_level) /* A transition from < 7 to 7 always interrupts (NMI) */ /* Note: Level 7 can also level trigger like a normal IRQ */ if(old_level != 0x0700 && CPU_INT_LEVEL == 0x0700) - m68ki_cpu.nmi_pending = TRUE; + m68ki_cpu.nmi_pending = true; } void m68k_set_virq(unsigned int level, unsigned int active) diff --git a/plat/linux68k/emu/musashi/m68kcpu.h b/plat/linux68k/emu/musashi/m68kcpu.h index 7cd04c5850..5783a646d0 100755 --- a/plat/linux68k/emu/musashi/m68kcpu.h +++ b/plat/linux68k/emu/musashi/m68kcpu.h @@ -41,6 +41,7 @@ extern "C" { #include +#include #include /* ======================================================================== */ @@ -2135,7 +2136,7 @@ static inline void m68ki_check_interrupts(void) { if(m68ki_cpu.nmi_pending) { - m68ki_cpu.nmi_pending = FALSE; + m68ki_cpu.nmi_pending = false; m68ki_exception_interrupt(7); } else if(CPU_INT_LEVEL > FLAG_INT_MASK) diff --git a/plat/linux68k/emu/musashi/m68kfpu.c b/plat/linux68k/emu/musashi/m68kfpu.c index 9cb1136861..de554dea97 100644 --- a/plat/linux68k/emu/musashi/m68kfpu.c +++ b/plat/linux68k/emu/musashi/m68kfpu.c @@ -1554,7 +1554,7 @@ static void fscc(void) if ((REG_IR & 0x38) == 0) { // If the specified floating-point condition is true, sets the byte integer operand at - // the destination to TRUE (all ones); otherwise, sets the byte to FALSE (all zeros). + // the destination to true (all ones); otherwise, sets the byte to false (all zeros). REG_D[REG_IR & 7] = (REG_D[REG_IR & 7] & 0xFFFFFF00) | (cc ? 0xff : 0x00); } diff --git a/plat/minix/include/minix/const.h b/plat/minix/include/minix/const.h index 791d6064f3..8da78b2732 100644 --- a/plat/minix/include/minix/const.h +++ b/plat/minix/include/minix/const.h @@ -9,9 +9,6 @@ #define PUBLIC /* PUBLIC is the opposite of static */ #define FORWARD static /* some compilers require this to be 'static'*/ -#define TRUE 1 /* used for turning integers into Booleans */ -#define FALSE 0 /* used for turning integers into Booleans */ - #define HZ 60 /* clock freq (software settable on IBM-PC) */ #define BLOCK_SIZE 1024 /* # bytes in a disk block */ #define SUPER_USER (uid_t)0 /* uid_t of superuser */ diff --git a/plat/minix68k/include/a.out.h b/plat/minix68k/include/a.out.h index 64f5ac9d5e..b67c6e53bc 100644 --- a/plat/minix68k/include/a.out.h +++ b/plat/minix68k/include/a.out.h @@ -38,8 +38,8 @@ struct exec { /* a.out header */ #define A_NS16K 0x0C /* national semiconductor 16032 */ #define A_I80386 0x10 /* intel i80386 */ -#define A_BLR(cputype) ((cputype&0x01)!=0) /* TRUE if bytes left-to-right */ -#define A_WLR(cputype) ((cputype&0x02)!=0) /* TRUE if words left-to-right */ +#define A_BLR(cputype) ((cputype&0x01)!=0) /* true if bytes left-to-right */ +#define A_WLR(cputype) ((cputype&0x02)!=0) /* true if words left-to-right */ /* flags: */ #define A_EXEC 0x10 /* executable */ diff --git a/plat/minix68k/libsys/_exec.c b/plat/minix68k/libsys/_exec.c index 2ca33ea792..a192175168 100644 --- a/plat/minix68k/libsys/_exec.c +++ b/plat/minix68k/libsys/_exec.c @@ -81,35 +81,35 @@ PUBLIC int __execve( #if ARG_MAX > INT_MAX #error /* overflow checks and sbrk depend on sizes being ints */ #endif - overflow = FALSE; + overflow = false; npointers = 1 + nargs + 1 + nenvps + 1; /* 1's for argc and NULLs */ stackbytes = 0; /* changed because _len is used now */ if (nargs < 0 || nenvps < 0 || nargs + nenvps < 0 || npointers < 0) - overflow = TRUE; + overflow = true; for (i = PTRSIZE; i != 0; i--) { temp = stackbytes + npointers; if (temp < stackbytes) - overflow = TRUE; + overflow = true; stackbytes = temp; } for (i = 0, ap = argv; i < nargs; i++) { temp = stackbytes + _len(*ap++); if (temp < stackbytes) - overflow = TRUE; + overflow = true; stackbytes = temp; } for (i = 0, ap = envp; i < nenvps; i++) { temp = stackbytes + _len(*ap++); if (temp < stackbytes) - overflow = TRUE; + overflow = true; stackbytes = temp; } temp = stackbytes + PTRSIZE - 1; if (temp < stackbytes) - overflow = TRUE; + overflow = true; stackbytes = (temp / PTRSIZE) * PTRSIZE; /* Check for overflow before committing sbrk. */ diff --git a/plat/pc86/emu/x86emu/debug.c b/plat/pc86/emu/x86emu/debug.c index 576ace55e9..06b446ffb8 100644 --- a/plat/pc86/emu/x86emu/debug.c +++ b/plat/pc86/emu/x86emu/debug.c @@ -327,7 +327,7 @@ x86emu_single_step(void) return; case 'P': noDecode = (noDecode) ? 0 : 1; - printk("Toggled decoding to %s\n", (noDecode) ? "FALSE" : "TRUE"); + printk("Toggled decoding to %s\n", (noDecode) ? "false" : "TRUE"); break; case 't': case 0: diff --git a/util/arch/archiver.c b/util/arch/archiver.c index 3d7b218f6e..5d5eeac184 100644 --- a/util/arch/archiver.c +++ b/util/arch/archiver.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -71,10 +72,6 @@ unsigned int tabsz, strtabsz; #define odd(nr) (nr & 01) #define even(nr) (odd(nr) ? nr + 1 : nr) -typedef char BOOL; -#define FALSE 0 -#define TRUE 1 - #define READ 0 #define APPEND 2 #define CREATE 1 @@ -89,19 +86,19 @@ typedef char BOOL; #define equal(str1, str2) (!strncmp((str1), (str2), AR_NAME_MAX)) -BOOL verbose; -BOOL app_fl; -BOOL ex_fl; -BOOL show_fl; +bool verbose; +bool app_fl; +bool ex_fl; +bool show_fl; /* print files found in archive. */ -BOOL pr_fl; -BOOL u_fl; -BOOL rep_fl; -BOOL del_fl; -BOOL nocr_fl; -BOOL local_fl; +bool pr_fl; +bool u_fl; +bool rep_fl; +bool del_fl; +bool nocr_fl; +bool local_fl; #ifdef DISTRIBUTION -BOOL distr_fl; +bool distr_fl; time_t distr_time; #endif @@ -125,14 +122,14 @@ void do_names(struct outhead* headp); void enter_name(struct outname* namep); void write_symdef(FILE* ar); -void error(BOOL quit, char* str1, char* str2); +void error(bool quit, char* str1, char* str2); FILE* open_archive(char* name, int mode); void catch (int param); MEMBER* get_member(FILE*); void get(int argc, char* argv[]); void add(char* name, FILE* ar, FILE* dst, char* mess); void extract(FILE* ar, MEMBER* member); -void copy_member(MEMBER* member, FILE* from, FILE* to, BOOL extracting); +void copy_member(MEMBER* member, FILE* from, FILE* to, bool extracting); char* get_mode(int mode); void wr_fatal(void); void rd_fatal(void); @@ -196,11 +193,11 @@ static short mode2ar(mode_t mode) static void usage(void) { - error(TRUE, "usage: %s [qdprtxl][vc] archive [file] ...\n", progname); + error(true, "usage: %s [qdprtxl][vc] archive [file] ...\n", progname); } /*VARARGS2*/ -void error(BOOL quit, char* str1, char* str2) +void error(bool quit, char* str1, char* str2) { char errbuf[256]; @@ -223,7 +220,7 @@ FILE* open_archive(char* name, int mode) { file = fopen(name, "wb+"); if (file == NULL) - error(TRUE, "cannot create %s\n", name); + error(true, "cannot create %s\n", name); magic = MAGIC_NUMBER; wr_int2(file, magic); return file; @@ -237,10 +234,10 @@ FILE* open_archive(char* name, int mode) { fclose(open_archive(name, CREATE)); if (!nocr_fl) - error(FALSE, "creating %s\n", name); + error(false, "creating %s\n", name); return open_archive(name, APPEND); } - error(TRUE, "cannot open %s\n", name); + error(true, "cannot open %s\n", name); } else /* file already exists, simply open it for appending */ @@ -254,7 +251,7 @@ FILE* open_archive(char* name, int mode) fseek(file, 0, SEEK_SET); magic = rd_unsigned2(file); if (magic != AALMAG && magic != ARMAG) - error(TRUE, "%s is not in ar format\n", name); + error(true, "%s is not in ar format\n", name); return file; } @@ -280,39 +277,39 @@ int main(int argc, char* argv[]) switch (*ptr) { case 't': - show_fl = TRUE; + show_fl = true; break; case 'v': - verbose = TRUE; + verbose = true; break; case 'x': - ex_fl = TRUE; + ex_fl = true; break; case 'q': needs_arg = 1; - app_fl = TRUE; + app_fl = true; break; case 'c': - nocr_fl = TRUE; + nocr_fl = true; break; case 'u': - u_fl = TRUE; + u_fl = true; break; case 'p': needs_arg = 1; - pr_fl = TRUE; + pr_fl = true; break; case 'd': needs_arg = 1; - del_fl = TRUE; + del_fl = true; break; case 'r': needs_arg = 1; - rep_fl = TRUE; + rep_fl = true; break; #ifdef DISTRIBUTION case 'D': - distr_fl = TRUE; + distr_fl = true; break; #endif #ifdef AAL @@ -355,7 +352,7 @@ int main(int argc, char* argv[]) tab = (struct ranlib*)malloc(512 * sizeof(struct ranlib)); tstrtab = malloc(4096); if (!tab || !tstrtab) - error(TRUE, "Out of core\n", NULL); + error(true, "Out of core\n", NULL); tabsz = 512; strtabsz = 4096; #endif @@ -376,7 +373,7 @@ MEMBER* get_member(FILE* f) return NIL_MEM; if (member.ar_size < 0) { - error(TRUE, "archive has member with negative size\n", NULL); + error(true, "archive has member with negative size\n", NULL); } if (equal(SYMDEF, member.ar_name)) { @@ -428,7 +425,7 @@ void get(int argc, char* argv[]) } #endif wr_arhdr(temp_fd, member); - copy_member(member, ar_f, temp_fd, FALSE); + copy_member(member, ar_f, temp_fd, false); } else { @@ -549,23 +546,23 @@ void add(char* name, FILE* ar, FILE* dst, char* mess) if (stat(name, &status) < 0) { - error(FALSE, "cannot find %s\n", name); + error(false, "cannot find %s\n", name); return; } else if (S_ISDIR(status.st_mode)) { - error(FALSE, "%s is a directory (ignored)\n", name); + error(false, "%s is a directory (ignored)\n", name); return; } else if (u_fl && status.st_mtime <= member.ar_date) { wr_arhdr(dst, &member); - copy_member(&member, ar, dst, FALSE); + copy_member(&member, ar, dst, false); return; } else if ((src_fd = fopen(name, "rb")) == NULL) { - error(FALSE, "cannot open %s\n", name); + error(false, "cannot open %s\n", name); return; } @@ -607,7 +604,7 @@ void add(char* name, FILE* ar, FILE* dst, char* mess) status.st_size -= x; if (fread(io_buffer, 1, read_chars, src_fd) != read_chars) { - error(FALSE, "%s seems to shrink\n", name); + error(false, "%s seems to shrink\n", name); break; } mwrite(dst, io_buffer, x); @@ -629,37 +626,37 @@ void extract(FILE* ar, MEMBER* member) strncpy(buf, member->ar_name, sizeof(member->ar_name)); buf[sizeof(member->ar_name)] = 0; - if (pr_fl == FALSE) + if (pr_fl == false) { file = fopen(buf, "wb"); if (file == NULL) { - error(FALSE, "cannot create %s\n", buf); + error(false, "cannot create %s\n", buf); file = NULL; } }; if (verbose) { - if (pr_fl == FALSE) + if (pr_fl == false) show("x - %s\n", buf); else show("\n<%s>\n\n", buf); } - copy_member(member, ar, file, TRUE); + copy_member(member, ar, file, true); if (file != NULL) fclose(file); - if (pr_fl == FALSE) + if (pr_fl == false) chmod(buf, ar2mode(member->ar_mode)); } -void copy_member(MEMBER* member, FILE* from, FILE* to, BOOL extracting) +void copy_member(MEMBER* member, FILE* from, FILE* to, bool extracting) { size_t rest; long mem_size = member->ar_size; - BOOL is_odd = odd(mem_size) ? TRUE : FALSE; + bool is_odd = odd(mem_size) ? true : false; #ifdef AAL if (!extracting) @@ -680,7 +677,7 @@ void copy_member(MEMBER* member, FILE* from, FILE* to, BOOL extracting) strncpy(buf, member->ar_name, sizeof(member->ar_name)); buf[sizeof(member->ar_name)] = 0; - error(TRUE, "read error on %s\n", buf); + error(true, "read error on %s\n", buf); } if (to != NULL) mwrite(to, io_buffer, rest); @@ -690,7 +687,7 @@ void copy_member(MEMBER* member, FILE* from, FILE* to, BOOL extracting) if (is_odd) { fseek(from, 1L, SEEK_CUR); - if ((to != NULL) && (extracting == FALSE)) + if ((to != NULL) && (extracting == false)) fseek(to, 1L, SEEK_CUR); } } @@ -718,18 +715,18 @@ char* get_mode(int mode) void wr_fatal(void) { - error(TRUE, "write error\n", NULL); + error(true, "write error\n", NULL); } void rd_fatal(void) { - error(TRUE, "read error\n", NULL); + error(true, "read error\n", NULL); } void mwrite(FILE* f, void* address, size_t bytes) { if (fwrite(address, 1, bytes, f) != bytes) - error(TRUE, "write error\n", NULL); + error(true, "write error\n", NULL); } void show(char* s, char* name) @@ -846,7 +843,7 @@ void do_names(struct outhead* headp) if ((headp->oh_nchar != (unsigned int)headp->oh_nchar) || ((strings = malloc((unsigned int)headp->oh_nchar))) == NULL) { - error(TRUE, "string table too big\n", NULL); + error(true, "string table too big\n", NULL); } rd_string(strings, headp->oh_nchar); while (nnames) @@ -889,7 +886,7 @@ void enter_name(struct outname* namep) { tab = (struct ranlib*)realloc((char*)tab, (tabsz += 512) * sizeof(struct ranlib)); if (!tab) - error(TRUE, "Out of core\n", NULL); + error(true, "Out of core\n", NULL); } tab[tnum].ran_off = tssiz; tab[tnum].ran_pos = offset; @@ -900,7 +897,7 @@ void enter_name(struct outname* namep) { tstrtab = realloc(tstrtab, (strtabsz += 4096)); if (!tstrtab) - error(TRUE, "string table overflow\n", NULL); + error(true, "string table overflow\n", NULL); } tstrtab[tssiz++] = *cp; if (!*cp) diff --git a/util/ass/ass00.c b/util/ass/ass00.c index ba3ad42dc7..3a05007480 100644 --- a/util/ass/ass00.c +++ b/util/ass/ass00.c @@ -1,10 +1,12 @@ -#include -#include -#include "ass00.h" -#include "assex.h" -#include "assci.h" -#include "asscm.h" -#include "assrl.h" +#include +#include +#include +#include +#include "ass00.h" +#include "assex.h" +#include "assci.h" +#include "asscm.h" +#include "assrl.h" /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. @@ -16,10 +18,10 @@ char oflag; static int memflg; /* Forward declarations. */ -static siz_t* getsizes(char *); +static siz_t* getsizes(char*); static void getcore(void); -static void argument(char *); -static void flags(char *); +static void argument(char*); +static void flags(char*); static void skipentry(void); static void enmd_pro(void); static void enmd_glo(void); @@ -28,7 +30,7 @@ static void finish_up(void); static void check_def(void); static void c_print(void); -static void c_dprint(char *, char*); +static void c_dprint(char*, char*); /* External definitions */ void pass_3(void); @@ -39,7 +41,7 @@ void pass_5(void); ** Main routine of EM1-assembler/loader */ -int main(int argc, char **argv) +int main(int argc, char** argv) { /* * Usage: ass [-[d][p][m][u][U]] [-s(s/m/l/x)] [ [file] [flag] ] ... @@ -47,7 +49,7 @@ int main(int argc, char **argv) * debugging information. */ char workspace[6000]; - char *cp; + char* cp; int argno; progname = argv[0]; @@ -64,7 +66,7 @@ int main(int argc, char **argv) } /* A piece of the interpreter's stack frame is used as free area initially */ - freearea((area_t) workspace, (unsigned) sizeof workspace); + freearea((area_t)workspace, (unsigned)sizeof workspace); getcore(); init_files(); init_vars(); @@ -76,10 +78,10 @@ int main(int argc, char **argv) static void getcore(void) { - siz_t *p; + siz_t* p; siz_t bytes; unsigned n; - char *base; + char* base; /* * xglobs[] should be located in front of mglobs[], see upd_reloc() @@ -106,7 +108,7 @@ static void getcore(void) base += bytes.n_proc; } -static siz_t* getsizes(char *str) +static siz_t* getsizes(char* str) { /* * accepts -ss (small), -sm (medium), -sl (large), -sx (extra large) @@ -114,20 +116,20 @@ static siz_t* getsizes(char *str) switch (LC(*str)) { - default: - error("bad size option %s", str); - case 's': - return &sizes[0]; - break; - case 'm': - return &sizes[1]; - break; - case 'l': - return &sizes[2]; - break; - case 'x': - return &sizes[3]; - break; + default: + error("bad size option %s", str); + case 's': + return &sizes[0]; + break; + case 'm': + return &sizes[1]; + break; + case 'l': + return &sizes[2]; + break; + case 'x': + return &sizes[3]; + break; } } @@ -137,7 +139,7 @@ static siz_t* getsizes(char *str) * Furthermore, it knows a library when it sees it and * call archive() to split it apart. */ -static void argument(char *arg) +static void argument(char* arg) { int w; @@ -163,9 +165,9 @@ static void argument(char *arg) read_compact(); else if (w == ARMAG || w == AALMAG) { - archmode = TRUE; + archmode = true; archive(); - archmode = FALSE; + archmode = false; } else error("%s: bad format", arg); @@ -177,9 +179,9 @@ static void argument(char *arg) /* ** process flag arguments */ -static void flags(char *arg) +static void flags(char* arg) { - char *argp; + char* argp; int on; argp = arg; @@ -187,84 +189,84 @@ static void flags(char *arg) { switch (LC(*argp)) { - case 'd': - d_flag++; - break; - case 'r': - r_flag++; - break; - case 's': - return; /* s-flag is already scanned */ + case 'd': + d_flag++; + break; + case 'r': + r_flag++; + break; + case 's': + return; /* s-flag is already scanned */ #ifdef MEMUSE - case 'm': - memflg++; - break; + case 'm': + memflg++; + break; #endif - case 'p': - ++procflag; - break; + case 'p': + ++procflag; + break; #ifdef DUMP - case 'u': - ++c_flag; - break; + case 'u': + ++c_flag; + break; #endif - case 'o': - ++oflag; - break; - case 'w': - ++wflag; - break; + case 'o': + ++oflag; + break; + case 'w': + ++wflag; + break; #ifdef JOHAN - case 'j': - ++jflag; - break; + case 'j': + ++jflag; + break; #endif - case 'U': - ++Uflag; - break; - case '-': - case '+': - on = (*argp == '+'); - while (*++argp) - switch (LC(*argp)) - { - case 't': - if (on) - intflags |= 01; - else - intflags &= ~01; - break; - case 'p': - if (on) - intflags |= 02; - else - intflags &= ~02; - break; - case 'f': - if (on) - intflags |= 04; - else - intflags &= ~04; - break; - case 'c': - if (on) - intflags |= 010; - else - intflags &= ~010; - case 'e': - if (on) - intflags |= 040; - else - intflags &= ~040; - break; - default: - error("bad interpreter option %s", argp); - } - --argp; - break; - default: - error("bad flag %s", argp); - break; + case 'U': + ++Uflag; + break; + case '-': + case '+': + on = (*argp == '+'); + while (*++argp) + switch (LC(*argp)) + { + case 't': + if (on) + intflags |= 01; + else + intflags &= ~01; + break; + case 'p': + if (on) + intflags |= 02; + else + intflags &= ~02; + break; + case 'f': + if (on) + intflags |= 04; + else + intflags &= ~04; + break; + case 'c': + if (on) + intflags |= 010; + else + intflags &= ~010; + case 'e': + if (on) + intflags |= 040; + else + intflags &= ~040; + break; + default: + error("bad interpreter option %s", argp); + } + --argp; + break; + default: + error("bad flag %s", argp); + break; } } } @@ -295,7 +297,7 @@ void do_proc(void) static void archive(void) { int i; - char *p; + char* p; /* * Read a library. @@ -314,7 +316,7 @@ static void archive(void) { /* no use for this library anymore */ return; } - p = chp_cast &archhdr; + p = chp_cast & archhdr; if ((i = fgetc(ifile)) == EOF) { return; @@ -324,7 +326,7 @@ static void archive(void) *p++ = get8(); for (i = 0; i < 8; i++) get8(); - archhdr.ar_size = ((long) get16() << 16); + archhdr.ar_size = ((long)get16() << 16); archhdr.ar_size += getu16(); inpoff = 0; libeof = archhdr.ar_size; @@ -368,7 +370,6 @@ void init_vars(void) * This occurs only for those that couldn't be initialized * at compile-time. */ - } void init_files(void) @@ -398,7 +399,7 @@ void initproc(void) * Called at the start of assembly of every procedure. */ - stat_t *prevstate; + stat_t* prevstate; prevstate = pst_cast getarea(sizeof pstate); *prevstate = pstate; @@ -406,10 +407,8 @@ void initproc(void) pstate.s_curpro = prp_cast 0; pstate.s_fline = lnp_cast 0; pstate.s_fdata = l_data; - pstate.s_locl = (locl_t (*)[]) getarea( - LOCLABSIZE * sizeof((*(pstate.s_locl))[0])); - memset(chp_cast pstate.s_locl, 0, - LOCLABSIZE * (unsigned) sizeof((*(pstate.s_locl))[0])); + pstate.s_locl = (locl_t(*)[])getarea(LOCLABSIZE * sizeof((*(pstate.s_locl))[0])); + memset(chp_cast pstate.s_locl, 0, LOCLABSIZE * (unsigned)sizeof((*(pstate.s_locl))[0])); if (memflg > 2) memuse(); } @@ -417,10 +416,10 @@ void initproc(void) void endproc(void) { /* Throw the contents of the line and local label table away */ - line_t *lnp1; + line_t* lnp1; locl_t *lbhead, *lbp, *lbp_next; int kind; - stat_t *prevstate; + stat_t* prevstate; while ((lnp1 = pstate.s_fline) != NULL) { @@ -428,24 +427,22 @@ void endproc(void) kind = lnp1->type1; if (kind > VALLOW) kind = VALLOW; - freearea((area_t) lnp1, (unsigned) linesize[kind]); + freearea((area_t)lnp1, (unsigned)linesize[kind]); } prevstate = pstate.s_prevstat; if (prevstate != pst_cast 0) { - for (lbhead = *pstate.s_locl; lbhead < &(*pstate.s_locl)[LOCLABSIZE]; - lbhead++) + for (lbhead = *pstate.s_locl; lbhead < &(*pstate.s_locl)[LOCLABSIZE]; lbhead++) { for (lbp = lbhead->l_chain; lbp != lbp_cast 0; lbp = lbp_next) { lbp_next = lbp->l_chain; - freearea((area_t) lbp, (unsigned) sizeof *lbp); + freearea((area_t)lbp, (unsigned)sizeof *lbp); } } - freearea((area_t) (*pstate.s_locl), - LOCLABSIZE * (sizeof((*pstate.s_locl)[0]))); + freearea((area_t)(*pstate.s_locl), LOCLABSIZE * (sizeof((*pstate.s_locl)[0]))); pstate = *prevstate; - freearea((area_t) prevstate, (unsigned) sizeof *prevstate); + freearea((area_t)prevstate, (unsigned)sizeof *prevstate); } } @@ -496,7 +493,7 @@ static void enmd_pro(void) if ((p->p_status & DEF) == 0) error("undefined local procedure '%s'", p->p_name); } - memset(chp_cast mprocs, 0, (limit - mprocs) * (unsigned ) sizeof *mprocs); + memset(chp_cast mprocs, 0, (limit - mprocs) * (unsigned)sizeof *mprocs); /* Clobber all flags indicating that external procedures * were used in this module. @@ -538,16 +535,16 @@ static void enmd_glo(void) xg = xglolookup(mg->g_name, ENTERING); switch (xg->g_status & (EXT | DEF)) { - case 0: /* new symbol */ - if ((mg->g_status & DEF) == 0) - ++unresolved; - break; - case EXT: /* already used but not defined */ - if (mg->g_status & DEF) - { - --unresolved; - } - break; + case 0: /* new symbol */ + if ((mg->g_status & DEF) == 0) + ++unresolved; + break; + case EXT: /* already used but not defined */ + if (mg->g_status & DEF) + { + --unresolved; + } + break; } xg->g_status |= mg->g_status; if (mg->g_status & DEF) @@ -556,7 +553,7 @@ static void enmd_glo(void) mg->g_val.g_gp = xg; /* used by upd_reloc */ } /* up to the next symbol */ upd_reloc(); - memset(chp_cast mglobs, 0, (limit - mglobs) * (unsigned ) sizeof *mglobs); + memset(chp_cast mglobs, 0, (limit - mglobs) * (unsigned)sizeof *mglobs); } static void finish_up(void) @@ -584,7 +581,7 @@ static void c_print(void) c_dprint("extra long", opcnt3); } -static void c_dprint(char *str, char* cnt) +static void c_dprint(char* str, char* cnt) { int first, curr; printf("unused %s opcodes\n", str); @@ -616,8 +613,8 @@ static void c_dprint(char *str, char* cnt) static void check_def(void) { - proc_t *p; - glob_t *g; + proc_t* p; + glob_t* g; int count; /* diff --git a/util/ass/ass00.h b/util/ass/ass00.h index 7354b2b1d1..16b694e296 100644 --- a/util/ass/ass00.h +++ b/util/ass/ass00.h @@ -12,27 +12,27 @@ #include "arch.h" #include "local.h" -#define RCS_ASS "$Id$" +#define RCS_ASS "$Id$" /* * compile time options */ -#define DUMP 1 /* dump between passes */ -/* #define TIMING 1 */ /* some timing measurements */ -#define JOHAN 1 /* dump the loaded instructions */ -#define MEMUSE 1 /* print memory usage statistics */ +#define DUMP 1 /* dump between passes */ +/* #define TIMING 1 */ /* some timing measurements */ +#define JOHAN 1 /* dump the loaded instructions */ +#define MEMUSE 1 /* print memory usage statistics */ #ifndef DUMP -#define dump(x) /* nothing */ +#define dump(x) /* nothing */ #endif #ifndef TIMING -#define timing() /* nothing */ +#define timing() /* nothing */ #endif #ifndef MEMUSE -#define memuse() /* nothing */ +#define memuse() /* nothing */ #endif /* Used to clear the upper byte(s) of characters. @@ -40,159 +40,166 @@ */ #ifdef CPM -# define LC(ch) ( ((ch)<'A' | (ch)>'Z' ) ? (ch) : ((ch)-('A'-'a'))) +#define LC(ch) (((ch) < 'A' | (ch) > 'Z') ? (ch) : ((ch) - ('A' - 'a'))) #else -# define LC(ch) (ch) +#define LC(ch) (ch) #endif -#define ctrunc(val) ( (val)&0377 ) - -#define odd(n) ((n)&1) /* Boolean odd function */ - -#define lnp_cast (line_t *) -#define gbp_cast (glob_t *) -#define lbp_cast (locl_t *) -#define prp_cast (proc_t *) -#define ptp_cast (ptab_t *) -#define rlp_cast (relc_t *) -#define pst_cast (stat_t *) -#define chp_cast (char *) -#define ipp_cast (int **) -#define iip_cast (int *) -#define int_cast (int ) - -typedef struct lines line_t; -typedef struct loc_label locl_t; -typedef struct glob_label glob_t; -typedef struct rel relc_t; -typedef struct procstat stat_t; -typedef struct sizes siz_t; -typedef struct ar_hdr arch_t; -typedef struct procs proc_t; -typedef struct proctab ptab_t; -typedef char * area_t; -typedef long cons_t; - -typedef union { - cons_t ad_i; - locl_t *ad_lp; - glob_t *ad_gp; - proc_t *ad_pp; - struct sad_ln { - short ln_extra; - short ln_first; - } ad_ln ; - struct sad_df { - cons_t df_i; - glob_t *df_gp; - } ad_df; -} addr_u; - -typedef union { - cons_t rel_i; - locl_t *rel_lp; - glob_t *rel_gp; +#define ctrunc(val) ((val) & 0377) + +#define odd(n) ((n) & 1) /* Boolean odd function */ + +#define lnp_cast (line_t*) +#define gbp_cast (glob_t*) +#define lbp_cast (locl_t*) +#define prp_cast (proc_t*) +#define ptp_cast (ptab_t*) +#define rlp_cast (relc_t*) +#define pst_cast (stat_t*) +#define chp_cast (char*) +#define ipp_cast (int**) +#define iip_cast (int*) +#define int_cast (int) + +typedef struct lines line_t; +typedef struct loc_label locl_t; +typedef struct glob_label glob_t; +typedef struct rel relc_t; +typedef struct procstat stat_t; +typedef struct sizes siz_t; +typedef struct ar_hdr arch_t; +typedef struct procs proc_t; +typedef struct proctab ptab_t; +typedef char* area_t; +typedef long cons_t; + +typedef union +{ + cons_t ad_i; + locl_t* ad_lp; + glob_t* ad_gp; + proc_t* ad_pp; + struct sad_ln + { + short ln_extra; + short ln_first; + } ad_ln; + struct sad_df + { + cons_t df_i; + glob_t* df_gp; + } ad_df; +} addr_u; + +typedef union +{ + cons_t rel_i; + locl_t* rel_lp; + glob_t* rel_gp; } rel_u; -#define FOFFSET long /* offset into file */ +#define FOFFSET long /* offset into file */ /* * Global variables and definitions for EM1-assembler/loader */ -#define DEFINING 0 /* parameters for glolookup */ -#define OCCURRING 1 -#define INTERNING 2 -#define EXTERNING 3 -#define SEARCHING 4 -#define ENTERING 5 +#define DEFINING 0 /* parameters for glolookup */ +#define OCCURRING 1 +#define INTERNING 2 +#define EXTERNING 3 +#define SEARCHING 4 +#define ENTERING 5 -#define PRO_OCC 0 /* parameters for prolookup */ -#define PRO_DEF 1 -#define PRO_INT 2 -#define PRO_EXT 3 - -#define TRUE 1 -#define FALSE 0 +#define PRO_OCC 0 /* parameters for prolookup */ +#define PRO_DEF 1 +#define PRO_INT 2 +#define PRO_EXT 3 #define MAXBYTE 255 -#define MAXSTRING 200 /* Maximum string length accepted */ -#define LOCLABSIZE 128 /* size of local label hash table */ - /* may not be smaller */ -#define ABSSIZE 8 - -struct lines { - char instr_num; /* index into mnemon[] */ - char type1; /* see below */ - line_t *l_next; /* next in chain */ - char *opoff; /* pointer into opchoice[] */ - addr_u ad; /* depending on type, various pointers */ +#define MAXSTRING 200 /* Maximum string length accepted */ +#define LOCLABSIZE 128 /* size of local label hash table */ +/* may not be smaller */ +#define ABSSIZE 8 + +struct lines +{ + char instr_num; /* index into mnemon[] */ + char type1; /* see below */ + line_t* l_next; /* next in chain */ + char* opoff; /* pointer into opchoice[] */ + addr_u ad; /* depending on type, various pointers */ }; /* contents of type1 */ -#define MISSING 0 /* no operand */ -#define CONST 1 /* ad contains operand */ -#define PROCNAME 2 /* ad contains struct procs pointer */ -#define GLOSYM 3 /* ad contains pointer into mproc[] */ -#define LOCSYM 4 /* ad contains pointer into locs[] */ -#define GLOOFF 5 /* ad contains CONST and GLOSYM in ad_df */ -#define LINES 6 /* Line number setting, only param of pseudo*/ -#define VALLOW 7 /* value's between LOW and HIGH are x-MID */ -#define VALMID 50 -#define VALHIGH 127 /* to avoid sign extension problems */ - -#define VAL1(x) ((x)-VALMID) +#define MISSING 0 /* no operand */ +#define CONST 1 /* ad contains operand */ +#define PROCNAME 2 /* ad contains struct procs pointer */ +#define GLOSYM 3 /* ad contains pointer into mproc[] */ +#define LOCSYM 4 /* ad contains pointer into locs[] */ +#define GLOOFF 5 /* ad contains CONST and GLOSYM in ad_df */ +#define LINES 6 /* Line number setting, only param of pseudo*/ +#define VALLOW 7 /* value's between LOW and HIGH are x-MID */ +#define VALMID 50 +#define VALHIGH 127 /* to avoid sign extension problems */ + +#define VAL1(x) ((x) - VALMID) /* Used to indicate a invalid contents of opoff */ -#define NO_OFF ((char *)-1) - -struct loc_label { - locl_t *l_chain; /* The next label with same low order bits */ - char l_hinum; /* high bits of number of label */ - char l_defined; /* see below */ - int l_min,l_max; /* boundaries of value */ +#define NO_OFF ((char*)-1) + +struct loc_label +{ + locl_t* l_chain; /* The next label with same low order bits */ + char l_hinum; /* high bits of number of label */ + char l_defined; /* see below */ + int l_min, l_max; /* boundaries of value */ }; /* The structure containing procedure pertinent data */ /* Used for environment stacking for nested PRO's */ -struct procstat { - line_t *s_fline; /* points to first line of procedure */ - locl_t (*s_locl)[1]; /* pointer to local labels */ - proc_t *s_curpro; /* identifies current procedure */ - relc_t *s_fdata; /* last datareloc before procedure */ - stat_t *s_prevstat; /* backward chain of nested procedures */ -} ; +struct procstat +{ + line_t* s_fline; /* points to first line of procedure */ + locl_t (*s_locl)[1]; /* pointer to local labels */ + proc_t* s_curpro; /* identifies current procedure */ + relc_t* s_fdata; /* last datareloc before procedure */ + stat_t* s_prevstat; /* backward chain of nested procedures */ +}; /* contents of l_defined */ -#define EMPTY 0 /* Empty slot */ -#define NO 1 /* not defined yet */ -#define YES 2 /* defined */ -#define SEEN 3 /* intermediate state */ -#define NOTPRESENT 4 /* Undefined and error message given */ - -struct glob_label { - char *g_name; - char g_status; /* see below */ - union { - cons_t g_addr; /* value if status&DEF */ - struct glob_label *g_gp; /* ref. to xglobs */ - } g_val ; +#define EMPTY 0 /* Empty slot */ +#define NO 1 /* not defined yet */ +#define YES 2 /* defined */ +#define SEEN 3 /* intermediate state */ +#define NOTPRESENT 4 /* Undefined and error message given */ + +struct glob_label +{ + char* g_name; + char g_status; /* see below */ + union + { + cons_t g_addr; /* value if status&DEF */ + struct glob_label* g_gp; /* ref. to xglobs */ + } g_val; }; -#define glostring(gl) ((gl)->g_name) +#define glostring(gl) ((gl)->g_name) /* contents of g_status */ -#define DEF 01 /* defined */ -#define OCC 02 /* used */ -#define EXT 04 /* external */ - -struct rel { /* for relocation tables */ - relc_t *r_next; /* chain */ - FOFFSET r_off; /* offset in text/data of word to relocate */ - rel_u r_val; /* constant or pointer to global symbol */ - int r_typ; /* different use in text or data */ +#define DEF 01 /* defined */ +#define OCC 02 /* used */ +#define EXT 04 /* external */ + +struct rel +{ /* for relocation tables */ + relc_t* r_next; /* chain */ + FOFFSET r_off; /* offset in text/data of word to relocate */ + rel_u r_val; /* constant or pointer to global symbol */ + int r_typ; /* different use in text or data */ }; /* @@ -200,59 +207,62 @@ struct rel { /* for relocation tables */ * in ip_spec.h together with the RELMNS bit if r_val contains an integer */ -#define RELMNS 020000 /* indicates integer i.s.o. glob */ +#define RELMNS 020000 /* indicates integer i.s.o. glob */ /* Contents of r_typ when used with data relocation */ -#define RELNULL 0 -#define RELGLO 1 -#define RELHEAD 2 -#define RELLOC 3 -#define RELADR 4 +#define RELNULL 0 +#define RELGLO 1 +#define RELHEAD 2 +#define RELLOC 3 +#define RELADR 4 /* modes of data output */ -#define DATA_NUL 0 -#define DATA_REP 1 -#define DATA_CONST 2 -#define DATA_BSS 3 -#define DATA_DPTR 4 -#define DATA_IPTR 5 -#define DATA_ICON 6 -#define DATA_UCON 7 -#define DATA_FCON 8 -#define DATA_BYTES 9 +#define DATA_NUL 0 +#define DATA_REP 1 +#define DATA_CONST 2 +#define DATA_BSS 3 +#define DATA_DPTR 4 +#define DATA_IPTR 5 +#define DATA_ICON 6 +#define DATA_UCON 7 +#define DATA_FCON 8 +#define DATA_BYTES 9 /* name of procedure to be called first */ -#define MAIN "_m_a_i_n" +#define MAIN "_m_a_i_n" /* headers of datablocks written */ -#define HEADREP 0 -#define HEADBSS 1 -#define HEADBYTE 2 -#define HEADCONST 3 -#define HEADDPTR 4 -#define HEADIPTR 5 -#define HEADICON 6 -#define HEADUCON 7 -#define HEADFCON 8 - -#define NDEFAULT 4 /* number of different sizes available */ -struct sizes { - int n_mlab; /* # of global labels per module */ - int n_glab; /* # of extern global labels */ - int n_mproc; /* # of local procs per module */ - int n_xproc; /* # of external procs */ - int n_proc; /* total # of procedures */ +#define HEADREP 0 +#define HEADBSS 1 +#define HEADBYTE 2 +#define HEADCONST 3 +#define HEADDPTR 4 +#define HEADIPTR 5 +#define HEADICON 6 +#define HEADUCON 7 +#define HEADFCON 8 + +#define NDEFAULT 4 /* number of different sizes available */ +struct sizes +{ + int n_mlab; /* # of global labels per module */ + int n_glab; /* # of extern global labels */ + int n_mproc; /* # of local procs per module */ + int n_xproc; /* # of external procs */ + int n_proc; /* total # of procedures */ }; -struct procs { /* format of mprocs[] and xprocs[] */ - char *p_name; - char p_status; /* same bits as g_status except REL */ - int p_num; /* unique procedure descriptor */ +struct procs +{ /* format of mprocs[] and xprocs[] */ + char* p_name; + char p_status; /* same bits as g_status except REL */ + int p_num; /* unique procedure descriptor */ }; -struct proctab { - cons_t pr_off; /* distance from pb */ - cons_t pr_loc; /* number of bytes locals */ +struct proctab +{ + cons_t pr_off; /* distance from pb */ + cons_t pr_loc; /* number of bytes locals */ }; extern void error(const char* string1, ...); diff --git a/util/ass/ass30.c b/util/ass/ass30.c index dd0427aa9c..71f86dd8a7 100644 --- a/util/ass/ass30.c +++ b/util/ass/ass30.c @@ -4,12 +4,14 @@ * */ -#include -#include "ass00.h" -#include "assex.h" -#include "assci.h" -#include "asscm.h" -#include "ip_spec.h" +#include +#include +#include +#include "ass00.h" +#include "assex.h" +#include "assci.h" +#include "asscm.h" +#include "ip_spec.h" short opt_line; /* max_line_no - # lines removed from end after perfoming exc's. @@ -18,9 +20,9 @@ short opt_line; /* max_line_no - # lines removed from end */ /* Forward declarations. */ -static int valid(line_t *); -static char *findfit(int, cons_t); -static char *findnop(int); +static int valid(line_t*); +static char* findfit(int, cons_t); +static char* findnop(int); /* ** Determine the exact instruction length & format where possible, and the @@ -29,8 +31,8 @@ static char *findnop(int); void pass_3(void) { line_t *lnp, *rev_lnp; - line_t *tmp_lnp; - locl_t *lbp; + line_t* tmp_lnp; + locl_t* lbp; int min_l, max_l, min_bytes; short last_line; short hol_err_line; @@ -47,54 +49,53 @@ void pass_3(void) insno = ctrunc(lnp->instr_num); switch (insno) { - case sp_fpseu: - last_line = line_num; - line_num = lnp->ad.ad_ln.ln_first; - opt_line -= lnp->ad.ad_ln.ln_extra; - lnp->ad.ad_ln.ln_first = last_line; - break; - case sp_ilb1: - lbp = lnp->ad.ad_lp; - lbp->l_defined = SEEN; - lbp->l_min = min_bytes; - lbp->l_max = max_bytes; - break; - default: - if (lnp->type1 == CONST && (em_flag[insno] & EM_PAR) == PAR_G) - { - if (holbase != 0) + case sp_fpseu: + last_line = line_num; + line_num = lnp->ad.ad_ln.ln_first; + opt_line -= lnp->ad.ad_ln.ln_extra; + lnp->ad.ad_ln.ln_first = last_line; + break; + case sp_ilb1: + lbp = lnp->ad.ad_lp; + lbp->l_defined = SEEN; + lbp->l_min = min_bytes; + lbp->l_max = max_bytes; + break; + default: + if (lnp->type1 == CONST && (em_flag[insno] & EM_PAR) == PAR_G) { - if (lnp->ad.ad_i >= holsize) + if (holbase != 0) { - hol_err_line = line_num; + if (lnp->ad.ad_i >= holsize) + { + hol_err_line = line_num; + } + lnp->ad.ad_i += holbase; } - lnp->ad.ad_i += holbase; } - } - else if (lnp->type1 >= VALLOW && (em_flag[insno] & EM_PAR) == PAR_G) - { - if (holbase != 0) + else if (lnp->type1 >= VALLOW && (em_flag[insno] & EM_PAR) == PAR_G) { - pstate.s_fline = lnp->l_next; - newline(CONST); - pstate.s_fline->instr_num = insno; - pstate.s_fline->ad.ad_i = - VAL1(lnp->type1) + holbase; - freearea((area_t) lnp, (unsigned) linesize[VALLOW]); - lnp = pstate.s_fline; - if ( VAL1(lnp->type1) >= holsize) + if (holbase != 0) { - hol_err_line = line_num; + pstate.s_fline = lnp->l_next; + newline(CONST); + pstate.s_fline->instr_num = insno; + pstate.s_fline->ad.ad_i = VAL1(lnp->type1) + holbase; + freearea((area_t)lnp, (unsigned)linesize[VALLOW]); + lnp = pstate.s_fline; + if (VAL1(lnp->type1) >= holsize) + { + hol_err_line = line_num; + } } } - } - if (!valid(lnp)) - fatal("Invalid operand"); + if (!valid(lnp)) + fatal("Invalid operand"); - determine_props(lnp, &min_l, &max_l); - min_bytes += min_l; - max_bytes += max_l; - break; + determine_props(lnp, &min_l, &max_l); + min_bytes += min_l; + max_bytes += max_l; + break; } tmp_lnp = lnp->l_next; lnp->l_next = rev_lnp; @@ -118,23 +119,23 @@ int oplength(int flag) cnt++; switch (flag & OPTYPE) { - case OPNO: - case OPMINI: - break; - case OP8: - case OPSHORT: - cnt++; - break; - case OP16U: - case OP16: - cnt += 2; - break; - case OP32: - cnt += 5; - break; - case OP64: - cnt += 9; - break; + case OPNO: + case OPMINI: + break; + case OP8: + case OPSHORT: + cnt++; + break; + case OP16U: + case OP16: + cnt += 2; + break; + case OP32: + cnt += 5; + break; + case OP64: + cnt += 9; + break; } return cnt; } @@ -144,7 +145,7 @@ int oplength(int flag) ** depending on its offsets */ -void determine_props(line_t *lnp, int *min_len, int *max_len) +void determine_props(line_t* lnp, int* min_len, int* max_len) { cons_t val; int insno; @@ -157,31 +158,31 @@ void determine_props(line_t *lnp, int *min_len, int *max_len) { switch (em_flag[insno] & EM_PAR) { - case PAR_NO: - case PAR_W: - f_off = findnop(insno); - break; - case PAR_G: - /* We want the maximum address that is a multiple - of the wordsize. - Assumption: there is no shortie for - intr max_word_multiple - where intr is a instruction allowing parameters - that are not a word multiple (PAR_G). - */ - f_off = findfit(insno, maxadr & (~(wordsize - 1))); - break; - case PAR_B: - f_off = findfit(insno, (cons_t) 0); - l_off = findfit(insno, val); - if (f_off != l_off) - { - *min_len = oplength(*f_off); - *max_len = oplength(*l_off); - lnp->opoff = NO_OFF; - return; - } - break; + case PAR_NO: + case PAR_W: + f_off = findnop(insno); + break; + case PAR_G: + /* We want the maximum address that is a multiple + of the wordsize. + Assumption: there is no shortie for + intr max_word_multiple + where intr is a instruction allowing parameters + that are not a word multiple (PAR_G). + */ + f_off = findfit(insno, maxadr & (~(wordsize - 1))); + break; + case PAR_B: + f_off = findfit(insno, (cons_t)0); + l_off = findfit(insno, val); + if (f_off != l_off) + { + *min_len = oplength(*f_off); + *max_len = oplength(*l_off); + lnp->opoff = NO_OFF; + return; + } + break; } } else @@ -192,11 +193,11 @@ void determine_props(line_t *lnp, int *min_len, int *max_len) *min_len = *max_len = oplength(*f_off); } -static char *findfit(int instr, cons_t val) +static char* findfit(int instr, cons_t val) { char *currc, *endc; int found, flags, number; - char *opc; + char* opc; endc = opindex[instr + 1]; for (currc = opindex[instr], found = 0; !found && currc < endc; currc++) @@ -205,11 +206,11 @@ static char *findfit(int instr, cons_t val) flags = ctrunc(*currc++); switch (flags & OPTYPE) { - case OPNO: - continue; - case OPMINI: - case OPSHORT: - number = ctrunc(*++currc); + case OPNO: + continue; + case OPMINI: + case OPSHORT: + number = ctrunc(*++currc); } found = opfit(flags, number, val, em_flag[instr] & EM_PAR); } @@ -225,13 +226,13 @@ static char* findnop(int instr) endc = opindex[instr + 1]; for (currc = opindex[instr]; currc < endc; currc++) { - switch ( ctrunc(*currc) & OPTYPE) + switch (ctrunc(*currc) & OPTYPE) { - case OPNO: - return currc; - case OPSHORT: - case OPMINI: - currc++; + case OPNO: + return currc; + case OPSHORT: + case OPMINI: + currc++; } currc++; } @@ -245,14 +246,14 @@ int opfit(int flag, int number, cons_t val, int i_flag) /* Number is invalid if flag does not contain MINI or SHORT */ switch (flag & OPRANGE) { - case OP_POS: - if (val < 0) - return 0; - break; - case OP_NEG: - if (val >= 0) - return 0; - break; + case OP_POS: + if (val < 0) + return 0; + break; + case OP_NEG: + if (val >= 0) + return 0; + break; } if (flag & OPWORD) { @@ -268,113 +269,113 @@ int opfit(int flag, int number, cons_t val, int i_flag) } switch (flag & OPTYPE) { - case OPMINI: - if (val < 0) - val = -1 - val; - return val >= 0 && val < number; - case OPSHORT: - if (val < 0) - val = -1 - val; - return val >= 0 && val < number * 256; - case OP16U: - return val >= 0 && val <= 65535L && (i_flag != PAR_G || val <= maxadr); - case OP16: - return val >= -32768 && val <= 32767; - case OP32: - return TRUE; - default: - fatal("illegal OPTYPE value"); - return -1; - UNREACHABLE_CODE; + case OPMINI: + if (val < 0) + val = -1 - val; + return val >= 0 && val < number; + case OPSHORT: + if (val < 0) + val = -1 - val; + return val >= 0 && val < number * 256; + case OP16U: + return val >= 0 && val <= 65535L && (i_flag != PAR_G || val <= maxadr); + case OP16: + return val >= -32768 && val <= 32767; + case OP32: + return true; + default: + fatal("illegal OPTYPE value"); + return -1; + UNREACHABLE_CODE; } } /* ** return estimation of value of parameter */ -cons_t parval(line_t *lnp, char *defined) +cons_t parval(line_t* lnp, char* defined) { int type; - locl_t *lbp; - glob_t *gbp; + locl_t* lbp; + glob_t* gbp; cons_t offs; - *defined = TRUE; + *defined = true; type = lnp->type1; switch (type) { - default: - if (type >= VALLOW && type <= VALHIGH) - return VAL1(type); - error("bad type during parval"); - break; - case CONST: - return (lnp->ad.ad_i); - case GLOSYM: - case GLOOFF: - if (type != GLOOFF) - { - gbp = lnp->ad.ad_gp; - offs = 0; - } - else - { - gbp = lnp->ad.ad_df.df_gp; - offs = lnp->ad.ad_df.df_i; - } - if (gbp->g_status & DEF) - return (gbp->g_val.g_addr + offs); - else - { - *defined = FALSE; - return offs; - } - case LOCSYM: - lbp = lnp->ad.ad_lp; - switch (pass) - { default: - error("bad pass in parval"); - case 3: - *defined = FALSE; - switch (lbp->l_defined) + if (type >= VALLOW && type <= VALHIGH) + return VAL1(type); + error("bad type during parval"); + break; + case CONST: + return (lnp->ad.ad_i); + case GLOSYM: + case GLOOFF: + if (type != GLOOFF) { - default: - fatal("Illegal local label"); - case NO: - error("Undefined local label"); - lbp->l_defined = NOTPRESENT; - case NOTPRESENT: - return max_bytes; - case SEEN: - return max_bytes - lbp->l_min; - case YES: - /* l_min contains line_num - adjusted for exc's. - */ - return (lbp->l_min - opt_line - 1) * maxinsl; + gbp = lnp->ad.ad_gp; + offs = 0; + } + else + { + gbp = lnp->ad.ad_df.df_gp; + offs = lnp->ad.ad_df.df_i; + } + if (gbp->g_status & DEF) + return (gbp->g_val.g_addr + offs); + else + { + *defined = false; + return offs; + } + case LOCSYM: + lbp = lnp->ad.ad_lp; + switch (pass) + { + default: + error("bad pass in parval"); + case 3: + *defined = false; + switch (lbp->l_defined) + { + default: + fatal("Illegal local label"); + case NO: + error("Undefined local label"); + lbp->l_defined = NOTPRESENT; + case NOTPRESENT: + return max_bytes; + case SEEN: + return max_bytes - lbp->l_min; + case YES: + /* l_min contains line_num + adjusted for exc's. + */ + return (lbp->l_min - opt_line - 1) * maxinsl; + } + case 4: + if (lbp->l_defined == YES) + return (lbp->l_min - prog_size - maxinsl); + return max_bytes - lbp->l_max - prog_size; + case 5: + if (lbp->l_defined == YES) + return lbp->l_min; + *defined = false; + break; } - case 4: - if (lbp->l_defined == YES) - return (lbp->l_min - prog_size - maxinsl); - return max_bytes - lbp->l_max - prog_size; - case 5: - if (lbp->l_defined == YES) - return lbp->l_min; - *defined = FALSE; break; - } - break; - case MISSING: - *defined = FALSE; - break; - case PROCNAME: - return (lnp->ad.ad_pp->p_num); + case MISSING: + *defined = false; + break; + case PROCNAME: + return (lnp->ad.ad_pp->p_num); } return (0); } -static int valid(line_t *lnp) +static int valid(line_t* lnp) { cons_t val; int type; @@ -389,50 +390,50 @@ static int valid(line_t *lnp) val = lnp->ad.ad_i; switch (em_flag[ctrunc(lnp->instr_num)] & EM_PAR) { - case PAR_NO: - return type == MISSING; - case PAR_C: - if (type != CONST) - return FALSE; - if (val > maxint && val <= maxunsig) - { - lnp->ad.ad_i = val - maxunsig - 1; - } - return TRUE; - case PAR_D: - if (type != CONST) - return FALSE; - if (val > maxdint && val <= maxdunsig) - { - lnp->ad.ad_i = val - maxdunsig - 1; - } - return TRUE; - case PAR_L: - case PAR_F: - return type == CONST; - case PAR_N: - return type == CONST && val >= 0; - case PAR_G: - return type == CONST || type == GLOSYM || type == GLOOFF; - case PAR_W: - if (type == MISSING) - return TRUE; - case PAR_S: - return type == CONST && val > 0 && val % wordsize == 0; - case PAR_Z: - return type == CONST && val >= 0 && val % wordsize == 0; - case PAR_O: - return type == CONST && val >= 0 - && (val >= wordsize ? val % wordsize : wordsize % val) == 0; - case PAR_P: - return type == PROCNAME; - case PAR_B: - return type == LOCSYM; - case PAR_R: - return type == CONST && val >= 0 && val <= 3; - default: - fatal("Unknown parameter type"); - return -1; - UNREACHABLE_CODE; + case PAR_NO: + return type == MISSING; + case PAR_C: + if (type != CONST) + return false; + if (val > maxint && val <= maxunsig) + { + lnp->ad.ad_i = val - maxunsig - 1; + } + return true; + case PAR_D: + if (type != CONST) + return false; + if (val > maxdint && val <= maxdunsig) + { + lnp->ad.ad_i = val - maxdunsig - 1; + } + return true; + case PAR_L: + case PAR_F: + return type == CONST; + case PAR_N: + return type == CONST && val >= 0; + case PAR_G: + return type == CONST || type == GLOSYM || type == GLOOFF; + case PAR_W: + if (type == MISSING) + return true; + case PAR_S: + return type == CONST && val > 0 && val % wordsize == 0; + case PAR_Z: + return type == CONST && val >= 0 && val % wordsize == 0; + case PAR_O: + return type == CONST && val >= 0 + && (val >= wordsize ? val % wordsize : wordsize % val) == 0; + case PAR_P: + return type == PROCNAME; + case PAR_B: + return type == LOCSYM; + case PAR_R: + return type == CONST && val >= 0 && val <= 3; + default: + fatal("Unknown parameter type"); + return -1; + UNREACHABLE_CODE; } } diff --git a/util/ass/ass40.c b/util/ass/ass40.c index b823cd2f3f..d3d9b883e7 100644 --- a/util/ass/ass40.c +++ b/util/ass/ass40.c @@ -4,10 +4,10 @@ * */ -#include "ass00.h" -#include "assex.h" - - +#include +#include +#include "ass00.h" +#include "assex.h" /* ** Make scans to do final assignment of instruction sizes & formats @@ -15,23 +15,27 @@ */ void pass_4(void) { - line_t *lnp; - locl_t *lbp; - int min_l, max_l; - int instr; + line_t* lnp; + locl_t* lbp; + int min_l, max_l; + int instr; pass = 4; - prog_size= 0 ; - for (lnp = pstate.s_fline ; lnp ; lnp= lnp->l_next, line_num++) { + prog_size = 0; + for (lnp = pstate.s_fline; lnp; lnp = lnp->l_next, line_num++) + { instr = ctrunc(lnp->instr_num); - if ( instr==sp_fpseu ) { - line_num = lnp->ad.ad_ln.ln_first ; - continue ; + if (instr == sp_fpseu) + { + line_num = lnp->ad.ad_ln.ln_first; + continue; } - if ( instr==sp_ilb1 ) { + if (instr == sp_ilb1) + { lbp = lnp->ad.ad_lp; - lbp->l_min= prog_size; lbp->l_defined = YES; - continue ; + lbp->l_min = prog_size; + lbp->l_defined = YES; + continue; } if (lnp->opoff == NO_OFF) @@ -39,9 +43,11 @@ void pass_4(void) determine_props(lnp, &min_l, &max_l); if (min_l != max_l) fatal("no size known"); - } else { - min_l = oplength(*(lnp->opoff)) ; } - prog_size += min_l ; + else + { + min_l = oplength(*(lnp->opoff)); + } + prog_size += min_l; } } diff --git a/util/ass/ass50.c b/util/ass/ass50.c index bd562b5db5..dff318a8a9 100644 --- a/util/ass/ass50.c +++ b/util/ass/ass50.c @@ -4,10 +4,12 @@ * */ -#include "ass00.h" -#include "assex.h" -#include "assrl.h" -#include "ip_spec.h" +#include +#include +#include "ass00.h" +#include "assex.h" +#include "assrl.h" +#include "ip_spec.h" /* ** Pass 5 of EM1 assembler/loader @@ -17,172 +19,197 @@ static void patchcase(void); - - void pass_5(void) { - line_t *lnp; + line_t* lnp; cons_t off1; - char defined ; - int afterlength, partype ; + char defined; + int afterlength, partype; int inslength, ope; - char *op_curr ; + char* op_curr; pass = 5; afterlength = 0; - for (lnp = pstate.s_fline ; lnp ; lnp= lnp->l_next, line_num++ ) { + for (lnp = pstate.s_fline; lnp; lnp = lnp->l_next, line_num++) + { ope = ctrunc(lnp->instr_num); - if ( ope==sp_ilb1 ) continue ; - if ( ope==sp_fpseu ) { - line_num = lnp->ad.ad_ln.ln_first ; - continue ; + if (ope == sp_ilb1) + continue; + if (ope == sp_fpseu) + { + line_num = lnp->ad.ad_ln.ln_first; + continue; } - off1 = parval(lnp,&defined); - if ( (op_curr = lnp->opoff)==NO_OFF ) { - fatal("opoff assertion failed") ; + off1 = parval(lnp, &defined); + if ((op_curr = lnp->opoff) == NO_OFF) + { + fatal("opoff assertion failed"); } - inslength = oplength(*op_curr) ; - afterlength += inslength ; + inslength = oplength(*op_curr); + afterlength += inslength; /* * Change absolute offset to a relative for branches. */ - - partype= em_flag[ope]&EM_PAR ; - if ( partype==PAR_B && defined ) { + partype = em_flag[ope] & EM_PAR; + if (partype == PAR_B && defined) + { off1 -= afterlength; } #ifdef JOHAN - if ( jflag ) { - extern char em_mnem[][4] ; - printf("%s %ld\n",em_mnem[ope],off1) ; + if (jflag) + { + extern char em_mnem[][4]; + printf("%s %ld\n", em_mnem[ope], off1); } #endif - if ( !defined && partype==PAR_G ) { /* must be external */ - text_reloc((lnp->type1==GLOSYM ? - lnp->ad.ad_gp:lnp->ad.ad_df.df_gp), - (FOFFSET)(textbytes+afterlength-inslength) , - op_curr-opchoice); - xputarb(inslength,off1,tfile); - textoff += inslength ; - } else { - genop(op_curr,off1,partype) ; + if (!defined && partype == PAR_G) + { /* must be external */ + text_reloc( + (lnp->type1 == GLOSYM ? lnp->ad.ad_gp : lnp->ad.ad_df.df_gp), + (FOFFSET)(textbytes + afterlength - inslength), op_curr - opchoice); + xputarb(inslength, off1, tfile); + textoff += inslength; + } + else + { + genop(op_curr, off1, partype); } } /* end forloop */ - line_num-- ; + line_num--; patchcase(); textbytes += prog_size; - if ( textbytes>maxadr ) fatal("Maximum code area size exceeded") ; + if (textbytes > maxadr) + fatal("Maximum code area size exceeded"); } /* end pass_5 */ - /** * Real code generation. */ -void genop(char *startc,cons_t value,int i_flag) +void genop(char* startc, cons_t value, int i_flag) { - char *currc ; - int flag ; - char opc ; + char* currc; + int flag; + char opc; - currc= startc ; + currc = startc; flag = ctrunc(*currc++); - opc = *currc++; - if ( (flag&OPTYPE)!=OPNO ) { + opc = *currc++; + if ((flag & OPTYPE) != OPNO) + { - if ( !opfit(flag,*currc,value,i_flag) ) { - fatal("parameter value unsuitable for selected opcode") ; + if (!opfit(flag, *currc, value, i_flag)) + { + fatal("parameter value unsuitable for selected opcode"); } - if ( flag&OPWORD ) { - if ( value%wordsize!=0 ) { + if (flag & OPWORD) + { + if (value % wordsize != 0) + { error("parameter not word multiple"); } - value /= wordsize ; + value /= wordsize; } - if ( flag&OPNZ ) { - if ( value<=0 ) error("negative parameter"); - value-- ; + if (flag & OPNZ) + { + if (value <= 0) + error("negative parameter"); + value--; } } - if ( flag&OPESC ) put8(ESC) ; - - switch ( flag&OPTYPE ) { - case OPMINI : - opc += value<0 ? -1-value : value ; - break ; - case OPSHORT : - if ( value<0 ) { - opc += -1-(value>>8) ; - } else { - opc += value>>8 ; - } - break ; - case OP32 : - case OP64 : - put8(ESC_L) ; + if (flag & OPESC) + put8(ESC); + + switch (flag & OPTYPE) + { + case OPMINI: + opc += value < 0 ? -1 - value : value; + break; + case OPSHORT: + if (value < 0) + { + opc += -1 - (value >> 8); + } + else + { + opc += value >> 8; + } + break; + case OP32: + case OP64: + put8(ESC_L); } #ifdef DUMP - if ( c_flag ) { - switch(flag&OPTYPE) { - case OP32 : - case OP64 : - opcnt3[opc&0377]= 1 ; - break ; - default : - if ( flag&OPESC ) opcnt2[opc&0377]= 1 ; - else opcnt1[opc&0377]= 1 ; - break ; + if (c_flag) + { + switch (flag & OPTYPE) + { + case OP32: + case OP64: + opcnt3[opc & 0377] = 1; + break; + default: + if (flag & OPESC) + opcnt2[opc & 0377] = 1; + else + opcnt1[opc & 0377] = 1; + break; } } #endif - put8(opc) ; - switch( flag&OPTYPE ) { - case OPNO: - case OPMINI: - break ; - case OPSHORT: - case OP8: - put8((char)value) ; - break ; - case OP16: - case OP16U: - put16(int_cast value) ; - break ; - case OP32: - put32(value) ; - break ; - case OP64: - put64(value) ; - break ; + put8(opc); + switch (flag & OPTYPE) + { + case OPNO: + case OPMINI: + break; + case OPSHORT: + case OP8: + put8((char)value); + break; + case OP16: + case OP16U: + put16(int_cast value); + break; + case OP32: + put32(value); + break; + case OP64: + put64(value); + break; } } static void patchcase(void) { - relc_t *r; - locl_t *k; + relc_t* r; + locl_t* k; - if ( (r= pstate.s_fdata) ) { - r= r->r_next ; - } else { - r= f_data ; + if ((r = pstate.s_fdata)) + { + r = r->r_next; + } + else + { + r = f_data; } - for( ; r ; r= r->r_next ) { - if (r->r_typ == RELLOC) { + for (; r; r = r->r_next) + { + if (r->r_typ == RELLOC) + { r->r_typ = RELADR; k = r->r_val.rel_lp; - if (k->l_defined==YES) + if (k->l_defined == YES) r->r_val.rel_i = k->l_min + textbytes; else - error("case label at line %d undefined", - k->l_min); + error("case label at line %d undefined", k->l_min); } } } diff --git a/util/ass/ass60.c b/util/ass/ass60.c index 2e9dcf1026..c09c8941d7 100644 --- a/util/ass/ass60.c +++ b/util/ass/ass60.c @@ -4,66 +4,64 @@ * */ -#include "ass00.h" -#include "assex.h" -#include "ip_spec.h" - +#include +#include +#include "ass00.h" +#include "assex.h" +#include "ip_spec.h" #ifdef DUMP -static char *typestr[] = -{ "missing", "const", "procname", "glosym", "locsym", "glosym+off", "pseudo" }; -static char *labstr[] = -{ "EMPTY", "no", "yes", "seen", "notpresent" }; -static char formstr[] = -{ 'm', 's', '-', '1', '2', '4', '8' }; -static char *r_data[] = -{ "null", "glob", "head", "loc", "adr" }; +static char* typestr[] + = { "missing", "const", "procname", "glosym", "locsym", "glosym+off", "pseudo" }; +static char* labstr[] = { "EMPTY", "no", "yes", "seen", "notpresent" }; +static char formstr[] = { 'm', 's', '-', '1', '2', '4', '8' }; +static char* r_data[] = { "null", "glob", "head", "loc", "adr" }; -cons_t nicepr(int typ, addr_u *ap) +cons_t nicepr(int typ, addr_u* ap) { - proc_t *pl; + proc_t* pl; switch (typ) { - case CONST: - return (ap->ad_i); - case LOCSYM: - return (int_cast (intptr_t)ap->ad_lp); - case GLOOFF: - return (ap->ad_df.df_gp - mglobs); - case GLOSYM: - return (ap->ad_gp - mglobs); - case PROCNAME: - pl = ap->ad_pp; - ; - if (pl->p_status & EXT) - return ((pl - xprocs) + 1000); - else - return (pl - mprocs); - default: - if (typ >= VALLOW && typ <= VALHIGH) - return VAL1(typ); - break; + case CONST: + return (ap->ad_i); + case LOCSYM: + return (int_cast(intptr_t) ap->ad_lp); + case GLOOFF: + return (ap->ad_df.df_gp - mglobs); + case GLOSYM: + return (ap->ad_gp - mglobs); + case PROCNAME: + pl = ap->ad_pp; + ; + if (pl->p_status & EXT) + return ((pl - xprocs) + 1000); + else + return (pl - mprocs); + default: + if (typ >= VALLOW && typ <= VALHIGH) + return VAL1(typ); + break; } return (0); } -char *pflags(int flg) +char* pflags(int flg) { static char res[9]; - char *cp; + char* cp; cp = res; if (flg & OPESC) *cp++ = 'e'; switch (flg & OPRANGE) { - case OP_NEG: - *cp++ = 'N'; - break; - case OP_POS: - *cp++ = 'P'; - break; + case OP_NEG: + *cp++ = 'N'; + break; + case OP_POS: + *cp++ = 'P'; + break; } if (flg & OPWORD) *cp++ = 'w'; @@ -76,26 +74,23 @@ char *pflags(int flg) void dump(int n) { - glob_t *gb; - line_t *ln; - locl_t *lbp; - locl_t *lbhead; - proc_t *pl; + glob_t* gb; + line_t* ln; + locl_t* lbp; + locl_t* lbhead; + proc_t* pl; int i; int insno; extern char em_mnem[][4]; if (d_flag == 0) return; - if ((n == 0 && d_flag) || (n == 4 && d_flag >= 2) - || (n < 100 && d_flag >= 3)) + if ((n == 0 && d_flag) || (n == 4 && d_flag >= 2) || (n < 100 && d_flag >= 3)) { printf("\nEM1-assembler ***** pass %1d complete:\n", n); printf("current size %ld\n", prog_size); - printf(" %9.9s%9.9s%14.14s%8.8s%8.8s\n", "instr_nr", "type1", "addr1", - "length", "format"); - for (ln = pstate.s_fline; ln; - ln = ln->l_next, n >= 3 || n == 0 ? i++ : i--) + printf(" %9.9s%9.9s%14.14s%8.8s%8.8s\n", "instr_nr", "type1", "addr1", "length", "format"); + for (ln = pstate.s_fline; ln; ln = ln->l_next, n >= 3 || n == 0 ? i++ : i--) { insno = ctrunc(ln->instr_num); if (insno == sp_fpseu) @@ -106,26 +101,24 @@ void dump(int n) printf("%4d ", i); switch (insno) { - default: - printf(" %3.3s", em_mnem[insno]); - break; - case sp_ilb1: - printf("l "); - break; - case sp_fpseu: - printf("p "); - break; + default: + printf(" %3.3s", em_mnem[insno]); + break; + case sp_ilb1: + printf("l "); + break; + case sp_fpseu: + printf("p "); + break; } - printf(" %9.9s%14ld", - typestr[ln->type1 < VALLOW ? ln->type1 : CONST], - nicepr(ln->type1, &ln->ad)); + printf( + " %9.9s%14ld", typestr[ln->type1 < VALLOW ? ln->type1 : CONST], + nicepr(ln->type1, &ln->ad)); if (ln->opoff != NO_OFF) - printf("%5d %.6s", oplength(*(ln->opoff)), - pflags(*(ln->opoff))); + printf("%5d %.6s", oplength(*(ln->opoff)), pflags(*(ln->opoff))); printf("\n"); } - printf("\n %8s%8s%8s%8s%8s\n", "labnum", "labid", "minval", "maxval", - "defined"); + printf("\n %8s%8s%8s%8s%8s\n", "labnum", "labid", "minval", "maxval", "defined"); for (i = 0, lbhead = *pstate.s_locl; i < LOCLABSIZE; lbhead++, i++) { if (lbhead->l_defined != EMPTY) @@ -133,10 +126,10 @@ void dump(int n) for (lbp = lbhead; lbp != lbp_cast 0; lbp = lbp->l_chain) { if (lbp->l_defined != EMPTY) - printf(" %8d%8d%8d%8d %-s\n", - lbp->l_hinum * LOCLABSIZE + i, - int_cast (intptr_t)lbp, lbp->l_min, lbp->l_max, - labstr[(unsigned char)lbp->l_defined]); + printf( + " %8d%8d%8d%8d %-s\n", lbp->l_hinum * LOCLABSIZE + i, + int_cast(intptr_t) lbp, lbp->l_min, lbp->l_max, + labstr[(unsigned char)lbp->l_defined]); } } } @@ -166,34 +159,28 @@ void dump(int n) printf(" %8o %8ld\n", gb->g_status, gb->g_val.g_addr); } printf("\n\nLocal procedures\n"); - printf("\n\t%8.8s%8s%8s\t%8s%8s\n", "name", "status", "num", "off", - "locals"); + printf("\n\t%8.8s%8s%8s\t%8s%8s\n", "name", "status", "num", "off", "locals"); for (pl = mprocs; pl < &mprocs[oursize->n_mproc]; pl++) if (pl->p_name) { - printf("%4d\t%-8s%8o%8d", pl - mprocs, pl->p_name, pl->p_status, - pl->p_num); + printf("%4d\t%-8s%8o%8d", pl - mprocs, pl->p_name, pl->p_status, pl->p_num); if (pl->p_status & DEF) - printf("\t%8ld%8ld", proctab[pl->p_num].pr_off, - proctab[pl->p_num].pr_loc); + printf("\t%8ld%8ld", proctab[pl->p_num].pr_off, proctab[pl->p_num].pr_loc); printf("\n"); } printf("\nGlobal procedures\n"); - printf("\n\t%8s%8s%8s\t%8s%8s\n", "name", "status", "num", "off", - "locals"); + printf("\n\t%8s%8s%8s\t%8s%8s\n", "name", "status", "num", "off", "locals"); for (pl = xprocs; pl < &xprocs[oursize->n_xproc]; pl++) if (pl->p_name) { - printf("%4d\t%-8s%8o%8d", pl - xprocs, pl->p_name, pl->p_status, - pl->p_num); + printf("%4d\t%-8s%8o%8d", pl - xprocs, pl->p_name, pl->p_status, pl->p_num); if (pl->p_status & DEF) - printf("\t%8ld%8ld", proctab[pl->p_num].pr_off, - proctab[pl->p_num].pr_loc); + printf("\t%8ld%8ld", proctab[pl->p_num].pr_off, proctab[pl->p_num].pr_loc); printf("\n"); } if (r_flag) { - relc_t *rl; + relc_t* rl; printf("\nData relocation\n"); printf("\n\t%10s %10s %10s\n", "offset", "type", "value"); for (rl = f_data; rl; rl = rl->r_next) @@ -201,34 +188,32 @@ void dump(int n) printf("\t%10ld %10s ", rl->r_off, r_data[rl->r_typ]); switch (rl->r_typ) { - case RELADR: - case RELHEAD: - printf("%10ld\n", rl->r_val.rel_i); - break; - case RELGLO: - printf("%8.8s\n", rl->r_val.rel_gp->g_name); - break; - case RELLOC: - printf("%10d\n", rl->r_val.rel_lp); - break; - case RELNULL: - printf("\n"); - break; + case RELADR: + case RELHEAD: + printf("%10ld\n", rl->r_val.rel_i); + break; + case RELGLO: + printf("%8.8s\n", rl->r_val.rel_gp->g_name); + break; + case RELLOC: + printf("%10d\n", rl->r_val.rel_lp); + break; + case RELNULL: + printf("\n"); + break; } } printf("\n\nText relocation\n"); printf("\n\t%10s %10s %10s\n", "offset", "flags", "value"); for (rl = f_text; rl; rl = rl->r_next) { - printf("\t%10ld %10s ", rl->r_off, - pflags(opchoice[rl->r_typ & ~RELMNS])); + printf("\t%10ld %10s ", rl->r_off, pflags(opchoice[rl->r_typ & ~RELMNS])); if (rl->r_typ & RELMNS) printf("%10ld\n", rl->r_val.rel_i); else printf("\n"); } } - } } #endif diff --git a/util/ass/ass70.c b/util/ass/ass70.c index 0a8331ba14..1454eb44e7 100644 --- a/util/ass/ass70.c +++ b/util/ass/ass70.c @@ -4,11 +4,13 @@ * */ -#include -#include -#include "ass00.h" -#include "assex.h" -#include "asscm.h" +#include +#include +#include +#include +#include "ass00.h" +#include "assex.h" +#include "asscm.h" /* ** utilities of EM1-assembler/loader @@ -16,14 +18,13 @@ static int globstep; - /* * glohash returns an index in table and leaves a stepsize in globstep * */ -static int glohash(char *aname ,int size) +static int glohash(char* aname, int size) { - char *p; + char* p; int i; int sum; @@ -32,11 +33,11 @@ static int glohash(char *aname ,int size) * Algorithm is adding all the characters after shifting some way. */ - for(sum=i=0,p=aname;*p;i += 3) - sum += (*p++)<<(i&07); + for (sum = i = 0, p = aname; *p; i += 3) + sum += (*p++) << (i & 07); sum &= 077777; globstep = (sum / size) % (size - 7) + 7; - return(sum % size); + return (sum % size); } /* @@ -44,23 +45,24 @@ static int glohash(char *aname ,int size) * return index in labeltable */ -glob_t *glo2lookup(char *name ,int status) +glob_t* glo2lookup(char* name, int status) { - return(glolookup(name,status,mglobs,oursize->n_mlab)); + return (glolookup(name, status, mglobs, oursize->n_mlab)); } -glob_t *xglolookup(char *name,int status) +glob_t* xglolookup(char* name, int status) { - return(glolookup(name,status,xglobs,oursize->n_glab)); + return (glolookup(name, status, xglobs, oursize->n_glab)); } -static void findext(glob_t *g) +static void findext(glob_t* g) { - glob_t *x; + glob_t* x; - x = xglolookup(g->g_name,ENTERING); - if (x && (x->g_status&DEF)) { + x = xglolookup(g->g_name, ENTERING); + if (x && (x->g_status & DEF)) + { g->g_status |= DEF; g->g_val.g_addr = x->g_val.g_addr; } @@ -85,68 +87,71 @@ static void findext(glob_t *g) * ENTERING: * Lookup or enter the symbol, don't check */ -glob_t *glolookup(char *name,int status,glob_t *table, int size) +glob_t* glolookup(char* name, int status, glob_t* table, int size) { - glob_t *g; - int rem,j; + glob_t* g; + int rem, j; int new; - - rem = glohash(name,size); - j = 0; new=0; + rem = glohash(name, size); + j = 0; + new = 0; g = &table[rem]; - while (g->g_name != 0 && strcmp(name,g->g_name) != 0) { + while (g->g_name != 0 && strcmp(name, g->g_name) != 0) + { j++; - if (j>size) + if (j > size) fatal("global label table overflow"); rem = (rem + globstep) % size; g = &table[rem]; } - if (g->g_name == 0) { + if (g->g_name == 0) + { /* * This symbol is shining new. * Enter it in table except for status = SEARCHING */ if (status == SEARCHING) - return(0); - g->g_name = (char *) getarea((unsigned) (strlen(name) + 1)); - strcpy(g->g_name,name); + return (0); + g->g_name = (char*)getarea((unsigned)(strlen(name) + 1)); + strcpy(g->g_name, name); g->g_status = 0; - g->g_val.g_addr=0; + g->g_val.g_addr = 0; new++; } - switch(status) { - case SEARCHING: /* nothing special */ - case ENTERING: - break; - case INTERNING: - if (!new && (g->g_status&EXT)) - werror("INA must be first occurrence of '%s'",name); - break; - case EXTERNING: /* lookup in other table */ - /* - * The If statement is removed to be friendly - * to Backend writers having to deal with assemblers - * not following our conventions. - if (!new) - error("EXA must be first occurrence of '%s'",name); - */ - findext(g); - break; - case DEFINING: /* Thou shalt not redefine */ - if (g->g_status&DEF) - error("global symbol '%s' redefined",name); - g->g_status |= DEF; - break; - case OCCURRING: - if ( new ) + switch (status) + { + case SEARCHING: /* nothing special */ + case ENTERING: + break; + case INTERNING: + if (!new && (g->g_status & EXT)) + werror("INA must be first occurrence of '%s'", name); + break; + case EXTERNING: /* lookup in other table */ + /* + * The If statement is removed to be friendly + * to Backend writers having to deal with assemblers + * not following our conventions. + if (!new) + error("EXA must be first occurrence of '%s'",name); + */ findext(g); - g->g_status |= OCC; - break; - default: - fatal("bad status in glolookup"); + break; + case DEFINING: /* Thou shalt not redefine */ + if (g->g_status & DEF) + error("global symbol '%s' redefined", name); + g->g_status |= DEF; + break; + case OCCURRING: + if (new) + findext(g); + g->g_status |= OCC; + break; + default: + fatal("bad status in glolookup"); } - return(g); + return (g); } /* @@ -157,43 +162,55 @@ glob_t *glolookup(char *name,int status,glob_t *table, int size) * Lookup or enter the symbol, check for mult. def. * */ -locl_t *loclookup(unsigned int an,int status) +locl_t* loclookup(unsigned int an, int status) { - locl_t *lbp,*l_lbp; + locl_t *lbp, *l_lbp; unsigned int num; char hinum; - if ( !pstate.s_locl ) fatal("label outside procedure"); + if (!pstate.s_locl) + fatal("label outside procedure"); num = an; - if ( num/LOCLABSIZE>255 ) fatal("local label number too large"); - hinum = num/LOCLABSIZE; - l_lbp= lbp= &(*pstate.s_locl)[num%LOCLABSIZE]; - if ( lbp->l_defined==EMPTY ) { - lbp= lbp_cast 0 ; - } else { - while ( lbp!= lbp_cast 0 && lbp->l_hinum != hinum ) { - l_lbp = lbp ; + if (num / LOCLABSIZE > 255) + fatal("local label number too large"); + hinum = num / LOCLABSIZE; + l_lbp = lbp = &(*pstate.s_locl)[num % LOCLABSIZE]; + if (lbp->l_defined == EMPTY) + { + lbp = lbp_cast 0; + } + else + { + while (lbp != lbp_cast 0 && lbp->l_hinum != hinum) + { + l_lbp = lbp; lbp = lbp->l_chain; } } - if ( lbp == lbp_cast 0 ) { - if ( l_lbp->l_defined!=EMPTY ) { + if (lbp == lbp_cast 0) + { + if (l_lbp->l_defined != EMPTY) + { lbp = lbp_cast getarea(sizeof *lbp); - l_lbp->l_chain= lbp ; - } else lbp= l_lbp ; - lbp->l_chain= lbp_cast 0 ; - lbp->l_hinum=hinum; - lbp->l_defined = (status==OCCURRING ? NO : YES); - lbp->l_min= line_num; - } else - if (status == DEFINING) { - if (lbp->l_defined == YES) - error("multiple defined local symbol"); - else - lbp->l_defined = YES; + l_lbp->l_chain = lbp; } - if ( status==DEFINING ) lbp->l_min= line_num ; - return(lbp); + else + lbp = l_lbp; + lbp->l_chain = lbp_cast 0; + lbp->l_hinum = hinum; + lbp->l_defined = (status == OCCURRING ? NO : YES); + lbp->l_min = line_num; + } + else if (status == DEFINING) + { + if (lbp->l_defined == YES) + error("multiple defined local symbol"); + else + lbp->l_defined = YES; + } + if (status == DEFINING) + lbp->l_min = line_num; + return (lbp); } /* @@ -212,105 +229,111 @@ locl_t *loclookup(unsigned int an,int status) * The EXT bit in this table indicates the the name is used * as external in this module. */ -proc_t *prolookup(char *name,int status) +proc_t* prolookup(char* name, int status) { - proc_t *p= NULL; + proc_t* p = NULL; int pstat = 0; + switch (status) + { + case PRO_OCC: + p = searchproc(name, mprocs, oursize->n_mproc); + if (p->p_name) + { + p->p_status |= OCC; + return (p); + } + p = searchproc(name, xprocs, oursize->n_xproc); + if (p->p_name) + { + p->p_status |= OCC; + return (p); + } + pstat = OCC | EXT; + unresolved++; + break; + case PRO_INT: + p = searchproc(name, xprocs, oursize->n_xproc); + if (p->p_name && (p->p_status & EXT)) + error("pro '%s' conflicting use", name); - switch(status) { - case PRO_OCC: - p = searchproc(name,mprocs,oursize->n_mproc); - if (p->p_name) { - p->p_status |= OCC; - return(p); - } - p = searchproc(name,xprocs,oursize->n_xproc); - if (p->p_name) { - p->p_status |= OCC; - return(p); - } - pstat = OCC|EXT; - unresolved++ ; - break; - case PRO_INT: - p = searchproc(name,xprocs,oursize->n_xproc); - if (p->p_name && (p->p_status&EXT) ) - error("pro '%s' conflicting use",name); - - p = searchproc(name,mprocs,oursize->n_mproc); - if (p->p_name) - werror("INP must be first occurrence of '%s'",name); - pstat = 0; - break; - case PRO_EXT: - p = searchproc(name,mprocs,oursize->n_mproc); - if (p->p_name) - error("pro '%s' exists already localy",name); - p = searchproc(name,xprocs,oursize->n_xproc); - if (p->p_name) { - /* - * The If statement is removed to be friendly - * to Backend writers having to deal with assemblers - * not following our conventions. - if ( p->p_status&EXT ) - werror("EXP must be first occurrence of '%s'", - name) ; - */ - p->p_status |= EXT; - return(p); - } - pstat = EXT; - unresolved++; - break; - case PRO_DEF: - p = searchproc(name,xprocs,oursize->n_xproc); - if (p->p_name && (p->p_status&EXT) ) { - if (p->p_status&DEF) - error("global pro '%s' redeclared",name); - else - unresolved-- ; - p->p_status |= DEF; - return(p); - } else { - p = searchproc(name,mprocs,oursize->n_mproc); - if (p->p_name) { - if (p->p_status&DEF) - error("local pro '%s' redeclared", - name); + p = searchproc(name, mprocs, oursize->n_mproc); + if (p->p_name) + werror("INP must be first occurrence of '%s'", name); + pstat = 0; + break; + case PRO_EXT: + p = searchproc(name, mprocs, oursize->n_mproc); + if (p->p_name) + error("pro '%s' exists already localy", name); + p = searchproc(name, xprocs, oursize->n_xproc); + if (p->p_name) + { + /* + * The If statement is removed to be friendly + * to Backend writers having to deal with assemblers + * not following our conventions. + if ( p->p_status&EXT ) + werror("EXP must be first occurrence of '%s'", + name) ; + */ + p->p_status |= EXT; + return (p); + } + pstat = EXT; + unresolved++; + break; + case PRO_DEF: + p = searchproc(name, xprocs, oursize->n_xproc); + if (p->p_name && (p->p_status & EXT)) + { + if (p->p_status & DEF) + error("global pro '%s' redeclared", name); + else + unresolved--; p->p_status |= DEF; - return(p); + return (p); } - } - pstat = DEF; - break; - default: - fatal("bad status in prolookup"); + else + { + p = searchproc(name, mprocs, oursize->n_mproc); + if (p->p_name) + { + if (p->p_status & DEF) + error("local pro '%s' redeclared", name); + p->p_status |= DEF; + return (p); + } + } + pstat = DEF; + break; + default: + fatal("bad status in prolookup"); } - return(enterproc(name,pstat,p)); + return (enterproc(name, pstat, p)); } /* * return a pointer into table to the place where the procedure * name is or should be if in the table. */ -proc_t *searchproc(char *name,proc_t *table,int size) +proc_t* searchproc(char* name, proc_t* table, int size) { - proc_t *p; - int rem,j; - + proc_t* p; + int rem, j; - rem = glohash(name,size); + rem = glohash(name, size); j = 0; p = &table[rem]; - while (p->p_name != 0 && strcmp(name,p->p_name) != 0) { + while (p->p_name != 0 && strcmp(name, p->p_name) != 0) + { j++; - if (j>size) + if (j > size) fatal("procedure table overflow"); rem = (rem + globstep) % size; p = &table[rem]; } - return(p); + return (p); } /* @@ -325,16 +348,16 @@ proc_t *searchproc(char *name,proc_t *table,int size) * Two local procedures with the same name in different * modules have different numbers. */ -proc_t *enterproc(char *name,int status,proc_t *place) +proc_t* enterproc(char* name, int status, proc_t* place) { - proc_t *p; + proc_t* p; - p=place; - p->p_name = (char *) getarea((unsigned) (strlen(name) + 1)); - strcpy(p->p_name,name); + p = place; + p->p_name = (char*)getarea((unsigned)(strlen(name) + 1)); + strcpy(p->p_name, name); p->p_status = status; - if (procnum>=oursize->n_proc) + if (procnum >= oursize->n_proc) fatal("too many procedures"); p->p_num = procnum++; - return(p); + return (p); } diff --git a/util/ass/ass80.c b/util/ass/ass80.c index 39ba1b555c..d7b897939d 100644 --- a/util/ass/ass80.c +++ b/util/ass/ass80.c @@ -4,6 +4,8 @@ * */ +#include +#include #include "ass00.h" #include "assex.h" #include "assrl.h" @@ -12,32 +14,33 @@ #include #include "system.h" - /* * this file contains several library routines. */ static char* filename; - /* VARARGS1 */ -static void pr_error(const char* string1, va_list ap) { +static void pr_error(const char* string1, va_list ap) +{ /* * diagnostic output */ - fprintf(stderr,"%s: ",progname); - if (curfile) { - fprintf(stderr,"file %s",curfile); + fprintf(stderr, "%s: ", progname); + if (curfile) + { + fprintf(stderr, "file %s", curfile); if (archmode) - fprintf(stderr," (%.14s)",archhdr.ar_name); - fprintf(stderr,": "); + fprintf(stderr, " (%.14s)", archhdr.ar_name); + fprintf(stderr, ": "); } - if ( pstate.s_curpro ) { - fprintf(stderr,"proc %s, ",pstate.s_curpro->p_name); + if (pstate.s_curpro) + { + fprintf(stderr, "proc %s, ", pstate.s_curpro->p_name); } - fprintf(stderr,"line %d: ",line_num); - vfprintf(stderr,string1,ap); - fprintf(stderr,"\n"); + fprintf(stderr, "line %d: ", line_num); + vfprintf(stderr, string1, ap); + fprintf(stderr, "\n"); } /* VARARGS1 */ @@ -47,85 +50,89 @@ void error(const char* string1, ...) va_start(ap, string1); pr_error(string1, ap); va_end(ap); - nerrors++ ; + nerrors++; } /* VARARGS1 */ void werror(const char* string1, ...) { va_list ap; - if ( wflag ) return ; + if (wflag) + return; va_start(ap, string1); pr_error(string1, ap); va_end(ap); } -void fatal(char *s) +void fatal(char* s) { /* * handle fatal errors */ - error("Fatal error: %s",s); + error("Fatal error: %s", s); dump(0); exit(EXIT_FAILURE); } - - -int xgetc(FILE *af) +int xgetc(FILE* af) { int nextc; - nextc=fgetc(af) ; - if ( feof(af) ) - fatal("unexpected end of file"); - return nextc ; + nextc = fgetc(af); + if (feof(af)) + fatal("unexpected end of file"); + return nextc; } -void xputc(int c, FILE *af) +void xputc(int c, FILE* af) { - fputc(c,af) ; - if ( ferror(af) ) fatal("write error") ; + fputc(c, af); + if (ferror(af)) + fatal("write error"); } - -void putblk(FILE *stream, char *from, int amount) +void putblk(FILE* stream, char* from, int amount) { - for ( ; amount-- ; from++ ) { - fputc(*from,stream) ; - if ( ferror(stream) ) fatal("write error") ; + for (; amount--; from++) + { + fputc(*from, stream); + if (ferror(stream)) + fatal("write error"); } } -int getblk(FILE *stream, char *from, int amount) +int getblk(FILE* stream, char* from, int amount) { - for ( ; amount-- ; from++ ) { - *from = fgetc(stream) ; - if ( feof(stream) ) return 1 ; + for (; amount--; from++) + { + *from = fgetc(stream); + if (feof(stream)) + return 1; } - return 0 ; + return 0; } -void xput16(int w,FILE *f) +void xput16(int w, FILE* f) { /* * two times xputc */ - xputc(w,f); - xputc(w>>8,f); + xputc(w, f); + xputc(w >> 8, f); } -void xputarb(int l,cons_t w, FILE* f) +void xputarb(int l, cons_t w, FILE* f) { - while ( l-- ) { - xputc( int_cast w,f) ; - w >>=8 ; + while (l--) + { + xputc(int_cast w, f); + w >>= 8; } } void put8(int n) { - xputc(n,tfile); + xputc(n, tfile); textoff++; } @@ -135,20 +142,20 @@ void put16(int n) * note reversed order of bytes. * this is done for faster interpretation. */ - xputc(n>>8,tfile); - xputc(n&0377,tfile); + xputc(n >> 8, tfile); + xputc(n & 0377, tfile); textoff += 2; } void put32(cons_t n) { - put16( int_cast (n>>16)) ; - put16( int_cast n) ; + put16(int_cast(n >> 16)); + put16(int_cast n); } void put64(cons_t n) { - fatal("put64 called") ; + fatal("put64 called"); } int xget8(void) @@ -157,9 +164,9 @@ int xget8(void) * Read one byte from ifile. */ if (libeof && inpoff >= libeof) - return EOF ; + return EOF; inpoff++; - return fgetc(ifile) ; + return fgetc(ifile); } unsigned int get8(void) @@ -168,40 +175,46 @@ unsigned int get8(void) /* * Read one byte from ifile. */ - nextc=xget8(); - if ( nextc==EOF ) { + nextc = xget8(); + if (nextc == EOF) + { if (libeof) fatal("Tried to read past end of arentry\n"); else fatal("end of file on input"); } - return nextc ; + return nextc; } -cons_t xgetarb(int l,FILE *f) +cons_t xgetarb(int l, FILE* f) { - cons_t val ; - int shift ; + cons_t val; + int shift; int c; - shift=0 ; val=0 ; - while ( l-- ) { + shift = 0; + val = 0; + while (l--) + { /* val += ((cons_t)(c = ctrunc(xgetc(f))))< 8 && ((shift>>3)&1)) { - while (shift < 8*sizeof(cons_t)) { - val += ((cons_t)c)< 8 && ((shift >> 3) & 1)) + { + while (shift < 8 * sizeof(cons_t)) + { + val += ((cons_t)c) << shift; shift += 8; } } - return val ; + return val; } void ext8(int b) @@ -210,7 +223,7 @@ void ext8(int b) * Handle one byte of data. */ ++dataoff; - xputc(b,dfile); + xputc(b, dfile); } void extword(cons_t w) @@ -218,10 +231,11 @@ void extword(cons_t w) /* Assemble the word constant w. * NOTE: The bytes are written low to high. */ - int i ; - for ( i=wordsize ; i-- ; ) { - ext8( int_cast w) ; - w >>= 8 ; + int i; + for (i = wordsize; i--;) + { + ext8(int_cast w); + w >>= 8; } } @@ -230,10 +244,11 @@ void extarb(int size, long value) /* Assemble the 'size' constant value. * The bytes are again written low to high. */ - int i ; - for ( i=size ; i-- ; ) { - ext8( int_cast value ) ; - value >>=8 ; + int i; + for (i = size; i--;) + { + ext8(int_cast value); + value >>= 8; } } @@ -242,146 +257,157 @@ void extadr(cons_t a) /* Assemble the pointer constant a. * NOTE: The bytes are written low to high. */ - int i ; - for ( i=ptrsize ; i-- ; ) { - ext8( int_cast a) ; - a >>= 8 ; + int i; + for (i = ptrsize; i--;) + { + ext8(int_cast a); + a >>= 8; } } -void xputa(cons_t a,FILE* f) +void xputa(cons_t a, FILE* f) { - int i ; - for ( i=ptrsize ; i-- ; ) { - xputc( int_cast a,f) ; - a >>= 8 ; + int i; + for (i = ptrsize; i--;) + { + xputc(int_cast a, f); + a >>= 8; } } cons_t xgeta(FILE* f) { - int i, shift ; - cons_t val ; - val = 0 ; shift=0 ; - for ( i=ptrsize ; i-- ; ) { - val += ((cons_t)xgetc(f))<MAXBYTE) fatal("Descriptor overflow"); - return amount ; + int amount; + amount = (dataoff - lastoff) / size; + if (amount > MAXBYTE) + fatal("Descriptor overflow"); + return amount; } void set_mode(int mode) { - if (datamode==mode) { /* in right mode already */ - switch ( datamode ) { + if (datamode == mode) + { /* in right mode already */ + switch (datamode) + { + case DATA_CONST: + if ((dataoff - lastoff) / wordsize < MAXBYTE) + return; + break; + case DATA_BYTES: + if (dataoff - lastoff < MAXBYTE) + return; + break; + case DATA_IPTR: + case DATA_DPTR: + if ((dataoff - lastoff) / ptrsize < MAXBYTE) + return; + break; + case DATA_ICON: + case DATA_FCON: + case DATA_UCON: + case DATA_BSS: + break; + default: + return; + } + set_mode(DATA_NUL); /* flush current descriptor */ + set_mode(mode); + return; + } + switch (datamode) + { /* terminate current mode */ + case DATA_NUL: + break; /* nothing to terminate */ case DATA_CONST: - if ( (dataoff-lastoff)/wordsize < MAXBYTE ) return ; - break ; + lastheader->r_val.rel_i = icount(wordsize); + lastheader->r_typ = RELHEAD; + datablocks++; + break; case DATA_BYTES: - if ( dataoff-lastoff < MAXBYTE ) return ; - break ; + lastheader->r_val.rel_i = icount(1); + lastheader->r_typ = RELHEAD; + datablocks++; + break; + case DATA_DPTR: case DATA_IPTR: + lastheader->r_val.rel_i = icount(ptrsize); + lastheader->r_typ = RELHEAD; + datablocks++; + break; + default: + datablocks++; + break; + } + datamode = mode; + switch (datamode) + { + case DATA_NUL: + break; + case DATA_CONST: + ext8(HEADCONST); + lastheader = data_reloc(chp_cast 0, dataoff, RELNULL); + ext8(0); + lastoff = dataoff; + break; + case DATA_BYTES: + ext8(HEADBYTE); + lastheader = data_reloc(chp_cast 0, dataoff, RELNULL); + ext8(0); + lastoff = dataoff; + break; + case DATA_IPTR: + ext8(HEADIPTR); + lastheader = data_reloc(chp_cast 0, dataoff, RELNULL); + ext8(0); + lastoff = dataoff; + break; case DATA_DPTR: - if ( (dataoff-lastoff)/ptrsize < MAXBYTE ) return ; - break ; + ext8(HEADDPTR); + lastheader = data_reloc(chp_cast 0, dataoff, RELNULL); + ext8(0); + lastoff = dataoff; + break; case DATA_ICON: + ext8(HEADICON); + ext8(int_cast consiz); + break; case DATA_FCON: + ext8(HEADFCON); + ext8(int_cast consiz); + break; case DATA_UCON: + ext8(HEADUCON); + ext8(int_cast consiz); + break; + case DATA_REP: + ext8(HEADREP); + break; case DATA_BSS: - break ; + ext8(HEADBSS); + break; default: - return ; - } - set_mode(DATA_NUL) ; /* flush current descriptor */ - set_mode(mode) ; - return; - } - switch(datamode) { /* terminate current mode */ - case DATA_NUL: - break; /* nothing to terminate */ - case DATA_CONST: - lastheader->r_val.rel_i=icount(wordsize) ; - lastheader->r_typ = RELHEAD; - datablocks++; - break; - case DATA_BYTES: - lastheader->r_val.rel_i=icount(1) ; - lastheader->r_typ = RELHEAD; - datablocks++; - break; - case DATA_DPTR: - case DATA_IPTR: - lastheader->r_val.rel_i=icount(ptrsize) ; - lastheader->r_typ = RELHEAD; - datablocks++; - break; - default: - datablocks++; - break; - } - datamode=mode; - switch(datamode) { - case DATA_NUL: - break; - case DATA_CONST: - ext8(HEADCONST); - lastheader=data_reloc( chp_cast 0,dataoff,RELNULL); - ext8(0); - lastoff=dataoff; - break; - case DATA_BYTES: - ext8(HEADBYTE); - lastheader=data_reloc( chp_cast 0,dataoff,RELNULL); - ext8(0); - lastoff=dataoff; - break; - case DATA_IPTR: - ext8(HEADIPTR); - lastheader=data_reloc( chp_cast 0,dataoff,RELNULL); - ext8(0); - lastoff=dataoff; - break; - case DATA_DPTR: - ext8(HEADDPTR); - lastheader=data_reloc( chp_cast 0,dataoff,RELNULL); - ext8(0); - lastoff=dataoff; - break; - case DATA_ICON: - ext8(HEADICON) ; - ext8( int_cast consiz) ; - break; - case DATA_FCON: - ext8(HEADFCON) ; - ext8( int_cast consiz) ; - break; - case DATA_UCON: - ext8(HEADUCON) ; - ext8( int_cast consiz) ; - break; - case DATA_REP: - ext8(HEADREP) ; - break ; - case DATA_BSS: - ext8(HEADBSS) ; - break; - default: - fatal("Unknown mode in set_mode") ; + fatal("Unknown mode in set_mode"); } } - char* tmpfil(void) { return sys_maketempfile("ack-ass", "dat"); diff --git a/util/ass/assci.c b/util/ass/assci.c index 4fa7c5198f..9cd2caf817 100644 --- a/util/ass/assci.c +++ b/util/ass/assci.c @@ -4,14 +4,16 @@ * */ -#include "ass00.h" -#include "assex.h" -#include "assci.h" -#include "asscm.h" -#include "assrl.h" -#include -#include -#include +#include +#include +#include "ass00.h" +#include "assex.h" +#include "assci.h" +#include "asscm.h" +#include "assrl.h" +#include +#include +#include /* * read compact code and fill in tables @@ -22,27 +24,23 @@ static cons_t argval; static int oksizes; /* MES EMX,.,. seen */ -static enum m_type -{ - CON, ROM, HOLBSS -} memtype; +static enum m_type { CON, ROM, HOLBSS } memtype; static int valtype; /* Transfer of type information between valsize, inpseudo and putval */ - /* Forward declarations * Yes, there is a better way to reorder to avoid these forward * declarations, but its complex to do, so we use the lazy way */ static int getarg(int); static cons_t getint(void); -static glob_t *getlab(int); -static char *getdig(char *, unsigned int); +static glob_t* getlab(int); +static char* getdig(char*, unsigned int); static void make_string(unsigned int); static void getstring(void); static void inident(void); -static char *inproname(void); +static char* inproname(void); static int needed(void); static cons_t valsize(void); static void setline(void); @@ -51,82 +49,81 @@ static void compact_line(void); static cons_t maxval(int); static void setsizes(void); static void exchange(int, int); -static void doinsert(line_t *, int, int); +static void doinsert(line_t*, int, int); static void putval(void); static void chkstart(void); static void typealign(enum m_type); static void sizealign(cons_t); static void extconst(cons_t); static void extbss(cons_t); -static void extloc(locl_t *); -static void extglob(glob_t *, cons_t); -static void extpro(proc_t *); +static void extloc(locl_t*); +static void extglob(glob_t*, cons_t); +static void extpro(proc_t*); static void extstring(void); static void extxcon(int); -static long myatol(char *); +static long myatol(char*); static void extvcon(int); - static int table3(int i) { switch (i) { - case sp_ilb1: - tabval = get8(); - break; - case sp_dlb1: - make_string(get8()); - i = sp_dnam; - break; - case sp_dlb2: - tabval = get16(); - if (tabval < 0) - { - error("illegal data label .%d", tabval); - tabval = 0; - } - make_string(tabval); - i = sp_dnam; - break; - case sp_cst2: - argval = get16(); - break; - case sp_ilb2: - tabval = get16(); - if (tabval < 0) - { - error("illegal instruction label %d", tabval); - tabval = 0; - } - i = sp_ilb1; - break; - case sp_cst4: - i = sp_cst2; - argval = get32(); - break; - case sp_dnam: - case sp_pnam: - inident(); - break; - case sp_scon: - getstring(); - break; - case sp_doff: - getarg(sym_ptyp); - getarg(cst_ptyp); - break; - case sp_icon: - case sp_ucon: - case sp_fcon: - getarg(cst_ptyp); - consiz = argval; - if (consiz < wordsize ? wordsize % consiz != 0 : consiz % wordsize != 0) - { - fatal("illegal object size"); - } - getstring(); - break; + case sp_ilb1: + tabval = get8(); + break; + case sp_dlb1: + make_string(get8()); + i = sp_dnam; + break; + case sp_dlb2: + tabval = get16(); + if (tabval < 0) + { + error("illegal data label .%d", tabval); + tabval = 0; + } + make_string(tabval); + i = sp_dnam; + break; + case sp_cst2: + argval = get16(); + break; + case sp_ilb2: + tabval = get16(); + if (tabval < 0) + { + error("illegal instruction label %d", tabval); + tabval = 0; + } + i = sp_ilb1; + break; + case sp_cst4: + i = sp_cst2; + argval = get32(); + break; + case sp_dnam: + case sp_pnam: + inident(); + break; + case sp_scon: + getstring(); + break; + case sp_doff: + getarg(sym_ptyp); + getarg(cst_ptyp); + break; + case sp_icon: + case sp_ucon: + case sp_fcon: + getarg(cst_ptyp); + consiz = argval; + if (consiz < wordsize ? wordsize % consiz != 0 : consiz % wordsize != 0) + { + fatal("illegal object size"); + } + getstring(); + break; } return (i); } @@ -157,7 +154,7 @@ cons_t get32(void) int h_byte; l = get8(); - l |= (unsigned) get8() * 256; + l |= (unsigned)get8() * 256; l |= get8() * 256L * 256L; h_byte = get8(); if (h_byte >= 128) @@ -220,13 +217,13 @@ static cons_t getint(void) return (argval); } -static glob_t *getlab(int status) +static glob_t* getlab(int status) { getarg(sym_ptyp); return (glo2lookup(string, status)); } -static char *getdig(char *str, unsigned int number) +static char* getdig(char* str, unsigned int number) { int remain; @@ -246,7 +243,7 @@ static void make_string(unsigned int n) static void getstring(void) { - char *p; + char* p; int n; getarg(cst_ptyp); @@ -264,7 +261,7 @@ static void inident(void) getstring(); } -static char *inproname(void) +static char* inproname(void) { getarg(ptyp(sp_pnam)); return (string); @@ -272,40 +269,40 @@ static char *inproname(void) static int needed(void) { - glob_t *g; - proc_t *p; + glob_t* g; + proc_t* p; for (;;) { switch (table2()) { - case sp_dnam: - if ( (g = xglolookup(string, SEARCHING)) != NULL) - { - if ((g->g_status & DEF) != 0) + case sp_dnam: + if ((g = xglolookup(string, SEARCHING)) != NULL) + { + if ((g->g_status & DEF) != 0) + continue; + } + else continue; - } - else - continue; - break; - case sp_pnam: - p = searchproc(string, xprocs, oursize->n_xproc); - if (p->p_name) - { - if ((p->p_status & DEF) != 0) + break; + case sp_pnam: + p = searchproc(string, xprocs, oursize->n_xproc); + if (p->p_name) + { + if ((p->p_status & DEF) != 0) + continue; + } + else continue; - } - else - continue; - break; - default: - error("Unexpected byte after ms_ext"); - case sp_cend: - return FALSE; + break; + default: + error("Unexpected byte after ms_ext"); + case sp_cend: + return false; } while (table2() != sp_cend) ; - return TRUE; + return true; } } @@ -313,35 +310,35 @@ static cons_t valsize(void) { switch (valtype = table2()) { /* valtype is used by putval and inpseudo */ - case sp_cst2: - return wordsize; - case sp_ilb1: - case sp_dnam: - case sp_doff: - case sp_pnam: - return ptrsize; - case sp_scon: - return strlngth; - case sp_fcon: - case sp_icon: - case sp_ucon: - return consiz; - case sp_cend: - return 0; - default: - fatal("value expected"); - return 0; - UNREACHABLE_CODE; + case sp_cst2: + return wordsize; + case sp_ilb1: + case sp_dnam: + case sp_doff: + case sp_pnam: + return ptrsize; + case sp_scon: + return strlngth; + case sp_fcon: + case sp_icon: + case sp_ucon: + return consiz; + case sp_cend: + return 0; + default: + fatal("value expected"); + return 0; + UNREACHABLE_CODE; } } void newline(int type) { - line_t *n_lnp; + line_t* n_lnp; if (type > VALLOW) type = VALLOW; - n_lnp = lnp_cast getarea((unsigned) linesize[type]); + n_lnp = lnp_cast getarea((unsigned)linesize[type]); n_lnp->l_next = pstate.s_fline; pstate.s_fline = n_lnp; n_lnp->type1 = type; @@ -353,8 +350,7 @@ static void setline(void) /* Get line numbers correct */ - if (pstate.s_fline && - ctrunc(pstate.s_fline->instr_num) == sp_fpseu) + if (pstate.s_fline && ctrunc(pstate.s_fline->instr_num) == sp_fpseu) { /* Already one present */ pstate.s_fline->ad.ad_ln.ln_extra++; @@ -366,16 +362,15 @@ static void setline(void) pstate.s_fline->ad.ad_ln.ln_extra = 0; pstate.s_fline->ad.ad_ln.ln_first = line_num; } - } static void inpseudo(int instr_no) { cons_t cst; - proc_t *prptr; + proc_t* prptr; cons_t objsize; cons_t par1, par2; - char *pars; + char* pars; /* * get operands of pseudo (if needed) and process it. @@ -383,155 +378,156 @@ static void inpseudo(int instr_no) switch (ctrunc(instr_no)) { - case ps_bss: - chkstart(); - typealign(HOLBSS); - cst = getint(); /* number of bytes */ - extbss(cst); - break; - case ps_hol: - chkstart(); - typealign(HOLBSS); - holsize = getint(); - holbase = databytes; - extbss(holsize); - break; - case ps_rom: - case ps_con: - chkstart(); - typealign( ctrunc(instr_no) == ps_rom ? ROM : CON); - while ((objsize = valsize()) != 0) - { - if (valtype != sp_scon) - sizealign(objsize); - putval(); - databytes += objsize; - } - break; - case ps_end: - prptr = pstate.s_curpro; - if (prptr == prp_cast 0) - fatal("unexpected END"); - proctab[prptr->p_num].pr_off = textbytes; - if (procflag) - { - printf("%6lu\t%6lo\t%5d\t%-12s\t%s", textbytes, textbytes, - prptr->p_num, prptr->p_name, curfile); - if (archmode) - printf("(%.14s)", archhdr.ar_name); - printf("\n"); - } - par2 = proctab[prptr->p_num].pr_loc; - if (getarg(cst_ptyp | ptyp(sp_cend)) == sp_cend) - { - if (par2 == -1) + case ps_bss: + chkstart(); + typealign(HOLBSS); + cst = getint(); /* number of bytes */ + extbss(cst); + break; + case ps_hol: + chkstart(); + typealign(HOLBSS); + holsize = getint(); + holbase = databytes; + extbss(holsize); + break; + case ps_rom: + case ps_con: + chkstart(); + typealign(ctrunc(instr_no) == ps_rom ? ROM : CON); + while ((objsize = valsize()) != 0) { - fatal("size of local area unspecified"); + if (valtype != sp_scon) + sizealign(objsize); + putval(); + databytes += objsize; } - } - else - { - if (par2 != -1 && argval != par2) + break; + case ps_end: + prptr = pstate.s_curpro; + if (prptr == prp_cast 0) + fatal("unexpected END"); + proctab[prptr->p_num].pr_off = textbytes; + if (procflag) { - fatal("inconsistent local area size"); + printf( + "%6lu\t%6lo\t%5d\t%-12s\t%s", textbytes, textbytes, prptr->p_num, prptr->p_name, + curfile); + if (archmode) + printf("(%.14s)", archhdr.ar_name); + printf("\n"); } - proctab[prptr->p_num].pr_loc = argval; - } - setline(); - do_proc(); - break; - case ps_mes: - switch ( int_cast getint()) - { - case ms_err: - error("module with error"); - ertrap(); - UNREACHABLE_CODE; - case ms_emx: - if (oksizes) + par2 = proctab[prptr->p_num].pr_loc; + if (getarg(cst_ptyp | ptyp(sp_cend)) == sp_cend) { - if (wordsize != getint()) + if (par2 == -1) { - fatal("Inconsistent word size"); - } - if (ptrsize != getint()) - { - fatal("Inconsistent pointer size"); + fatal("size of local area unspecified"); } } else { - oksizes++; - wordsize = getint(); - ptrsize = getint(); - if (wordsize != 2 && wordsize != 4) - { - fatal("Illegal word size"); - } - if (ptrsize != 2 && ptrsize != 4) + if (par2 != -1 && argval != par2) { - fatal("Illegal pointer size"); + fatal("inconsistent local area size"); } - setsizes(); + proctab[prptr->p_num].pr_loc = argval; + } + setline(); + do_proc(); + break; + case ps_mes: + switch (int_cast getint()) + { + case ms_err: + error("module with error"); + ertrap(); + UNREACHABLE_CODE; + case ms_emx: + if (oksizes) + { + if (wordsize != getint()) + { + fatal("Inconsistent word size"); + } + if (ptrsize != getint()) + { + fatal("Inconsistent pointer size"); + } + } + else + { + oksizes++; + wordsize = getint(); + ptrsize = getint(); + if (wordsize != 2 && wordsize != 4) + { + fatal("Illegal word size"); + } + if (ptrsize != 2 && ptrsize != 4) + { + fatal("Illegal pointer size"); + } + setsizes(); + } + ++mod_sizes; + break; + case ms_src: + break; + case ms_flt: + intflags |= 020; + break; /*floats used*/ + case ms_ext: + if (!needed()) + { + eof_seen++; + } + if (line_num > 2) + { + werror("mes ms_ext must be first or second pseudo"); + } + return; } - ++mod_sizes; + while (table2() != sp_cend) + ; + break; + case ps_exc: + par1 = getint(); + par2 = getint(); + if (par1 == 0 || par2 == 0) + break; + exchange((int)par2, (int)par1); break; - case ms_src: + case ps_exa: + getlab(EXTERNING); break; - case ms_flt: - intflags |= 020; - break; /*floats used*/ - case ms_ext: - if (!needed()) + case ps_ina: + getlab(INTERNING); + break; + case ps_pro: + chkstart(); + initproc(); + pars = inproname(); + if (getarg(cst_ptyp | ptyp(sp_cend)) == sp_cend) { - eof_seen++; + par2 = -1; } - if (line_num > 2) + else { - werror("mes ms_ext must be first or second pseudo"); + par2 = argval; } - return; - } - while (table2() != sp_cend) - ; - break; - case ps_exc: - par1 = getint(); - par2 = getint(); - if (par1 == 0 || par2 == 0) + prptr = prolookup(pars, PRO_DEF); + proctab[prptr->p_num].pr_loc = par2; + pstate.s_curpro = prptr; break; - exchange((int) par2, (int) par1); - break; - case ps_exa: - getlab(EXTERNING); - break; - case ps_ina: - getlab(INTERNING); - break; - case ps_pro: - chkstart(); - initproc(); - pars = inproname(); - if (getarg(cst_ptyp | ptyp(sp_cend)) == sp_cend) - { - par2 = -1; - } - else - { - par2 = argval; - } - prptr = prolookup(pars, PRO_DEF); - proctab[prptr->p_num].pr_loc = par2; - pstate.s_curpro = prptr; - break; - case ps_inp: - prptr = prolookup(inproname(), PRO_INT); - break; - case ps_exp: - prptr = prolookup(inproname(), PRO_EXT); - break; - default: - fatal("unknown pseudo"); + case ps_inp: + prptr = prolookup(inproname(), PRO_INT); + break; + case ps_exp: + prptr = prolookup(inproname(), PRO_EXT); + break; + default: + fatal("unknown pseudo"); } if (!mod_sizes) fatal("Missing size specification"); @@ -546,56 +542,56 @@ static void compact_line(void) { int instr_no; - curglosym = 0; switch (table1()) { - default: - fatal("unknown byte at start of \"line\""); UNREACHABLE_CODE; - case EOF: - eof_seen++; - while (pstate.s_prevstat != pst_cast 0) - { - error("missing end"); - do_proc(); - } - return; - case sp_fmnem: - if (pstate.s_curpro == prp_cast 0) - { - error("instruction outside procedure"); - } - instr_no = tabval; - if ((em_flag[instr_no] & EM_PAR) == PAR_NO) - { - newline(MISSING); - pstate.s_fline->instr_num = instr_no; + default: + fatal("unknown byte at start of \"line\""); + UNREACHABLE_CODE; + case EOF: + eof_seen++; + while (pstate.s_prevstat != pst_cast 0) + { + error("missing end"); + do_proc(); + } + return; + case sp_fmnem: + if (pstate.s_curpro == prp_cast 0) + { + error("instruction outside procedure"); + } + instr_no = tabval; + if ((em_flag[instr_no] & EM_PAR) == PAR_NO) + { + newline(MISSING); + pstate.s_fline->instr_num = instr_no; + return; + } + /* + * This instruction should have an opcode, so read it after + * this switch. + */ + break; + case sp_dnam: + chkstart(); + align(wordsize); + curglosym = glo2lookup(string, DEFINING); + curglosym->g_val.g_addr = databytes; + lastglosym = curglosym; + setline(); + line_num++; + if (table1() != sp_fpseu) + fatal("no pseudo after data label"); + case sp_fpseu: + inpseudo(tabval); + setline(); + return; + case sp_ilb1: + newline(LOCSYM); + pstate.s_fline->ad.ad_lp = loclookup(tabval, DEFINING); + pstate.s_fline->instr_num = sp_ilb1; return; - } - /* - * This instruction should have an opcode, so read it after - * this switch. - */ - break; - case sp_dnam: - chkstart(); - align(wordsize); - curglosym = glo2lookup(string, DEFINING); - curglosym->g_val.g_addr = databytes; - lastglosym = curglosym; - setline(); - line_num++; - if (table1() != sp_fpseu) - fatal("no pseudo after data label"); - case sp_fpseu: - inpseudo(tabval); - setline(); - return; - case sp_ilb1: - newline(LOCSYM); - pstate.s_fline->ad.ad_lp = loclookup(tabval, DEFINING); - pstate.s_fline->instr_num = sp_ilb1; - return; } /* @@ -604,60 +600,60 @@ static void compact_line(void) switch (table2()) { - default: - fatal("unknown byte at start of argument"); UNREACHABLE_CODE; - case sp_cst2: - if ((em_flag[instr_no] & EM_PAR) == PAR_B) - { - /* value indicates a label */ - newline(LOCSYM); - pstate.s_fline->ad.ad_lp = loclookup((int) argval, OCCURRING); - } - else - { - if (argval >= VAL1(VALLOW) && argval <= VAL1(VALHIGH)) + default: + fatal("unknown byte at start of argument"); + UNREACHABLE_CODE; + case sp_cst2: + if ((em_flag[instr_no] & EM_PAR) == PAR_B) { - newline(VALLOW); - pstate.s_fline->type1 = argval + VALMID; + /* value indicates a label */ + newline(LOCSYM); + pstate.s_fline->ad.ad_lp = loclookup((int)argval, OCCURRING); } else { - newline(CONST); - pstate.s_fline->ad.ad_i = argval; - pstate.s_fline->type1 = CONST; + if (argval >= VAL1(VALLOW) && argval <= VAL1(VALHIGH)) + { + newline(VALLOW); + pstate.s_fline->type1 = argval + VALMID; + } + else + { + newline(CONST); + pstate.s_fline->ad.ad_i = argval; + pstate.s_fline->type1 = CONST; + } } - } - break; - case sp_ilb1: - newline(LOCSYM); - pstate.s_fline->ad.ad_lp = loclookup(tabval, OCCURRING); - break; - case sp_dnam: - newline(GLOSYM); - pstate.s_fline->ad.ad_gp = glo2lookup(string, OCCURRING); - break; - case sp_pnam: - newline(PROCNAME); - pstate.s_fline->ad.ad_pp = prolookup(string, PRO_OCC); - break; - case sp_cend: - if ((em_flag[instr_no] & EM_PAR) != PAR_W) - { - fatal("missing operand"); - } - newline(MISSING); - break; - case sp_doff: - newline(GLOOFF); - pstate.s_fline->ad.ad_df.df_i = argval; - pstate.s_fline->ad.ad_df.df_gp = glo2lookup(string, OCCURRING); - break; + break; + case sp_ilb1: + newline(LOCSYM); + pstate.s_fline->ad.ad_lp = loclookup(tabval, OCCURRING); + break; + case sp_dnam: + newline(GLOSYM); + pstate.s_fline->ad.ad_gp = glo2lookup(string, OCCURRING); + break; + case sp_pnam: + newline(PROCNAME); + pstate.s_fline->ad.ad_pp = prolookup(string, PRO_OCC); + break; + case sp_cend: + if ((em_flag[instr_no] & EM_PAR) != PAR_W) + { + fatal("missing operand"); + } + newline(MISSING); + break; + case sp_doff: + newline(GLOOFF); + pstate.s_fline->ad.ad_df.df_i = argval; + pstate.s_fline->ad.ad_df.df_gp = glo2lookup(string, OCCURRING); + break; } pstate.s_fline->instr_num = instr_no; return; } - void read_compact(void) { init_module(); @@ -674,11 +670,6 @@ void read_compact(void) /* mod_sizes is only false for rejected library modules */ } - - - - - static cons_t maxval(int bits) { /* find the maximum positive value, @@ -730,13 +721,13 @@ static void exchange(int p1, int p2) line--; switch (ctrunc(a_lnp->instr_num)) { - case sp_fpseu: - line = a_lnp->ad.ad_ln.ln_first; - size += a_lnp->ad.ad_ln.ln_extra; - break; - case sp_ilb1: - a_lnp->ad.ad_lp->l_min -= p2; - break; + case sp_fpseu: + line = a_lnp->ad.ad_ln.ln_first; + size += a_lnp->ad.ad_ln.ln_extra; + break; + case sp_ilb1: + a_lnp->ad.ad_lp->l_min -= p2; + break; } size++; if (size >= p1) @@ -744,7 +735,7 @@ static void exchange(int p1, int p2) } if ((size -= p1) > 0) { - if ( ctrunc(a_lnp->instr_num) != sp_fpseu) + if (ctrunc(a_lnp->instr_num) != sp_fpseu) { fatal("EXC inconsistency"); } @@ -764,13 +755,13 @@ static void exchange(int p1, int p2) line--; switch (ctrunc(b_lnp->instr_num)) { - case sp_fpseu: - size += b_lnp->ad.ad_ln.ln_extra; - line = b_lnp->ad.ad_ln.ln_first; - break; - case sp_ilb1: - b_lnp->ad.ad_lp->l_min += p1; - break; + case sp_fpseu: + size += b_lnp->ad.ad_ln.ln_extra; + line = b_lnp->ad.ad_ln.ln_first; + break; + case sp_ilb1: + b_lnp->ad.ad_lp->l_min += p1; + break; } size++; if (size >= p2) @@ -782,7 +773,7 @@ static void exchange(int p1, int p2) } if ((size -= p2) > 0) { - if ( ctrunc(b_lnp->instr_num) != sp_fpseu) + if (ctrunc(b_lnp->instr_num) != sp_fpseu) { fatal("EXC inconsistency"); } @@ -799,10 +790,10 @@ static void exchange(int p1, int p2) a_lnp->l_next = t_lnp; } -static void doinsert(line_t *lnp, int first, int extra) +static void doinsert(line_t* lnp, int first, int extra) { /* Beware : s_fline will be clobbered and restored */ - line_t *t_lnp; + line_t* t_lnp; t_lnp = pstate.s_fline; pstate.s_fline = lnp->l_next; @@ -818,36 +809,36 @@ static void putval(void) { switch (valtype) { - case sp_cst2: - extconst(argval); - return; - case sp_ilb1: - extloc(loclookup(tabval, OCCURRING)); - return; - case sp_dnam: - extglob(glo2lookup(string, OCCURRING), (cons_t) 0); - return; - case sp_doff: - extglob(glo2lookup(string, OCCURRING), argval); - return; - case sp_pnam: - extpro(prolookup(string, PRO_OCC)); - return; - case sp_scon: - extstring(); - return; - case sp_fcon: - extxcon(DATA_FCON); - return; - case sp_icon: - extvcon(DATA_ICON); - return; - case sp_ucon: - extvcon(DATA_UCON); - return; - default: - fatal("putval notreached"); - UNREACHABLE_CODE; + case sp_cst2: + extconst(argval); + return; + case sp_ilb1: + extloc(loclookup(tabval, OCCURRING)); + return; + case sp_dnam: + extglob(glo2lookup(string, OCCURRING), (cons_t)0); + return; + case sp_doff: + extglob(glo2lookup(string, OCCURRING), argval); + return; + case sp_pnam: + extpro(prolookup(string, PRO_OCC)); + return; + case sp_scon: + extstring(); + return; + case sp_fcon: + extxcon(DATA_FCON); + return; + case sp_icon: + extvcon(DATA_ICON); + return; + case sp_ucon: + extvcon(DATA_UCON); + return; + default: + fatal("putval notreached"); + UNREACHABLE_CODE; } } @@ -860,13 +851,13 @@ static void chkstart(void) if (!oksizes) fatal("missing size specification"); set_mode(DATA_CONST); - extconst((cons_t) 0); + extconst((cons_t)0); databytes = wordsize; set_mode(DATA_REP); if (wordsize < ABSSIZE) { int factor = ABSSIZE / wordsize - 1; - extadr((cons_t) factor); + extadr((cons_t)factor); databytes += factor * wordsize; } absout++; @@ -883,7 +874,7 @@ static void typealign(enum m_type new) static void sizealign(cons_t size) { - align(size > wordsize ? wordsize : (int) size); + align(size > wordsize ? wordsize : (int)size); } void align(int size) @@ -955,11 +946,11 @@ static void extbss(cons_t n) n -= MAXBYTE; } set_mode(DATA_BSS); - ext8((int) n); + ext8((int)n); } } -static void extloc(locl_t *lbp) +static void extloc(locl_t* lbp) { /* @@ -967,13 +958,13 @@ static void extloc(locl_t *lbp) * For example con *1 */ set_mode(DATA_IPTR); - data_reloc( chp_cast lbp, dataoff, RELLOC); - extadr((cons_t) 0); + data_reloc(chp_cast lbp, dataoff, RELLOC); + extadr((cons_t)0); } -static void extglob(glob_t *agbp, cons_t off) +static void extglob(glob_t* agbp, cons_t off) { - glob_t *gbp; + glob_t* gbp; /* * generate a word of data that is defined by a global symbol. @@ -987,24 +978,24 @@ static void extglob(glob_t *agbp, cons_t off) } else { - data_reloc( chp_cast gbp, dataoff, RELGLO); + data_reloc(chp_cast gbp, dataoff, RELGLO); extadr(off); } } -static void extpro(proc_t *aprp) +static void extpro(proc_t* aprp) { /* * generate a address that is defined by a procedure descriptor. */ consiz = ptrsize; set_mode(DATA_UCON); - extarb((int) ptrsize, (long) (aprp->p_num)); + extarb((int)ptrsize, (long)(aprp->p_num)); } -static void extstring(void ) +static void extstring(void) { - char *s; + char* s; int n; /* @@ -1020,7 +1011,7 @@ static void extstring(void ) static void extxcon(int header) { - char *s; + char* s; int n; /* @@ -1040,7 +1031,7 @@ static void extxcon(int header) } /* Added atol() that ignores overflow. --Ceriel */ -static long myatol(char *s) +static long myatol(char* s) { long total = 0; unsigned digit; @@ -1074,6 +1065,6 @@ static void extvcon(int header) { error("Size of initializer exceeds loader capability"); } - extarb((int) consiz, myatol(string)); + extarb((int)consiz, myatol(string)); return; } diff --git a/util/ass/assci.h b/util/ass/assci.h index ea25a6175f..d426e2d82d 100644 --- a/util/ass/assci.h +++ b/util/ass/assci.h @@ -1,14 +1,13 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-03-12 - * + * */ #ifndef ASSCI_H_ #define ASSCI_H_ - /* * read module in compact EM1 code and fill in the table in memory * with all the specified data as a linked list. diff --git a/util/ass/asscm.c b/util/ass/asscm.c index 26d99e9be7..c6886a3fdc 100644 --- a/util/ass/asscm.c +++ b/util/ass/asscm.c @@ -18,6 +18,8 @@ The algorithm is first fit. */ +#include +#include #include "ass00.h" #include "assex.h" #include "asscm.h" @@ -29,23 +31,20 @@ static unsigned m_free = 0; struct freeblock { - struct freeblock *f_next; + struct freeblock* f_next; unsigned f_size; }; -static struct freeblock freexx[2] = -{ -{ freexx, 0 }, -{ freexx + 1, 0 } }; +static struct freeblock freexx[2] = { { freexx, 0 }, { freexx + 1, 0 } }; #define freehead freexx[1] -#define CHUNK 2048 /* Smallest chunk to be gotten from UNIX */ +#define CHUNK 2048 /* Smallest chunk to be gotten from UNIX */ area_t getarea(unsigned int size) { struct freeblock *c_ptr, *l_ptr; - char *ptr; + char* ptr; unsigned rqsize; size = ((size + (sizeof(int) - 1)) / sizeof(int)) * sizeof(int); @@ -55,34 +54,34 @@ area_t getarea(unsigned int size) #endif for (;;) { - for (l_ptr = &freehead, c_ptr= freehead.f_next; - c_ptr!= &freehead; c_ptr = c_ptr->f_next ) + for (l_ptr = &freehead, c_ptr = freehead.f_next; c_ptr != &freehead; c_ptr = c_ptr->f_next) { - if ( size==c_ptr->f_size ) + if (size == c_ptr->f_size) { - l_ptr->f_next= c_ptr->f_next; - return (area_t) c_ptr; + l_ptr->f_next = c_ptr->f_next; + return (area_t)c_ptr; } - if ( size+sizeof freehead <= c_ptr->f_size ) + if (size + sizeof freehead <= c_ptr->f_size) { c_ptr->f_size -= size; - return (area_t) ((char *) c_ptr + c_ptr->f_size); + return (area_t)((char*)c_ptr + c_ptr->f_size); } l_ptr = c_ptr; } - rqsize = sizef_next ) + for (l_ptr = &freehead, c_ptr = freehead.f_next; c_ptr != &freehead; c_ptr = c_ptr->f_next) { - if ( (area_t)c_ptr>ptr ) break; - l_ptr= c_ptr; + if ((area_t)c_ptr > ptr) + break; + l_ptr = c_ptr; } /* now insert between l_ptr and c_ptr */ /* Beware they may both point to freehead */ #ifdef MEMUSE - if (((char *) l_ptr) + l_ptr->f_size > (char *) ptr - && (char *) l_ptr <= (char *) ptr) + if (((char*)l_ptr) + l_ptr->f_size > (char*)ptr && (char*)l_ptr <= (char*)ptr) fatal("Double freed"); - if (((char *) ptr) + size > (char *) c_ptr - && (char *) ptr <= (char *) c_ptr) + if (((char*)ptr) + size > (char*)c_ptr && (char*)ptr <= (char*)c_ptr) fatal("Frreed double"); #endif /* Is the block before this one adjacent ? */ - if (((char *) l_ptr) + l_ptr->f_size == (char *) ptr) + if (((char*)l_ptr) + l_ptr->f_size == (char*)ptr) { l_ptr->f_size += size; /* yes */ @@ -125,13 +122,13 @@ void freearea(area_t ptr, unsigned int size) else { /* No, create an entry */ - ((struct freeblock *) ptr)->f_next = c_ptr; - ((struct freeblock *) ptr)->f_size = size; - l_ptr->f_next = (struct freeblock *) ptr; - l_ptr = (struct freeblock *) ptr; + ((struct freeblock*)ptr)->f_next = c_ptr; + ((struct freeblock*)ptr)->f_size = size; + l_ptr->f_next = (struct freeblock*)ptr; + l_ptr = (struct freeblock*)ptr; } /* Are the two entries adjacent ? */ - if ((char *) l_ptr + l_ptr->f_size == (char *) c_ptr) + if ((char*)l_ptr + l_ptr->f_size == (char*)c_ptr) { /* the two entries are adjacent */ l_ptr->f_next = c_ptr->f_next; diff --git a/util/ass/asscm.h b/util/ass/asscm.h index bdc8decb21..008ed8b3ff 100644 --- a/util/ass/asscm.h +++ b/util/ass/asscm.h @@ -1,9 +1,9 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-03-12 - * + * */ #ifndef ASSCM_H_ #define ASSCM_H_ diff --git a/util/ass/assda.c b/util/ass/assda.c index e6c2b1f286..020d781620 100644 --- a/util/ass/assda.c +++ b/util/ass/assda.c @@ -2,132 +2,133 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -#include "ass00.h" -#include "assex.h" - +#include +#include +#include "ass00.h" +#include "assex.h" /* * global data */ -int wordsize ; -int ptrsize ; -cons_t maxadr ; -cons_t maxint; -cons_t maxdint; -cons_t maxunsig; -cons_t maxdunsig; +int wordsize; +int ptrsize; +cons_t maxadr; +cons_t maxint; +cons_t maxdint; +cons_t maxunsig; +cons_t maxdunsig; /* - The structure containing used for procedure environment stacking + The structure containing used for procedure environment stacking */ -stat_t pstate ; +stat_t pstate; /* * pointers to not yet allocated storage */ -glob_t *mglobs; /* pointer to module symbols */ -glob_t *xglobs; /* pointer to extern symbols */ -proc_t *mprocs; /* pointer to local procs */ -proc_t *xprocs; /* pointer to external procs */ -ptab_t *proctab; /* pointer to proctab[] */ +glob_t* mglobs; /* pointer to module symbols */ +glob_t* xglobs; /* pointer to extern symbols */ +proc_t* mprocs; /* pointer to local procs */ +proc_t* xprocs; /* pointer to external procs */ +ptab_t* proctab; /* pointer to proctab[] */ /* * some array and structures of known size */ -FILE *ifile; /* input file buffer */ -FILE *tfile; /* code file buffer */ -FILE *dfile; /* data file buffer */ -FILE *rtfile; /* code file buffer */ -FILE *rdfile; /* data file buffer */ -char string[MAXSTRING]; +FILE* ifile; /* input file buffer */ +FILE* tfile; /* code file buffer */ +FILE* dfile; /* data file buffer */ +FILE* rtfile; /* code file buffer */ +FILE* rdfile; /* data file buffer */ +char string[MAXSTRING]; /* * some other pointers */ -glob_t *lastglosym; /* last global symbol */ -glob_t *curglosym; /* current global symbol */ -relc_t *f_data = (relc_t *)0 ; /* first data reloc pointer */ -relc_t *l_data = (relc_t *)0 ; /* last data reloc pointer */ -relc_t *f_text = (relc_t *)0 ; /* first text reloc pointer */ -relc_t *l_text = (relc_t *)0 ; /* last text reloc pointer */ +glob_t* lastglosym; /* last global symbol */ +glob_t* curglosym; /* current global symbol */ +relc_t* f_data = (relc_t*)0; /* first data reloc pointer */ +relc_t* l_data = (relc_t*)0; /* last data reloc pointer */ +relc_t* f_text = (relc_t*)0; /* first text reloc pointer */ +relc_t* l_text = (relc_t*)0; /* last text reloc pointer */ /* * some indices */ -int strlngth; /* index in string[] */ -FOFFSET inpoff; /* offset in current input file */ -FOFFSET libeof; /* ceiling for above number */ +int strlngth; /* index in string[] */ +FOFFSET inpoff; /* offset in current input file */ +FOFFSET libeof; /* ceiling for above number */ /* * some other counters */ -int procnum; /* generic for unique proc-descr. */ -cons_t prog_size; /* length of current proc */ -int max_bytes; -int pass; -int line_num; /* line number for error messages */ -int nerrors; /* number of nonfatal errors */ -cons_t consiz; /* size of U,I or F value */ -cons_t textbytes; /* size of code file */ -cons_t databytes; /* highwater mark in data */ -FOFFSET dataoff; /* size of data file */ -FOFFSET textoff; /* size of text file */ -FOFFSET lastoff; /* previous size before last block */ -int datamode; /* what kind of data */ -int datablocks; /* number of datablocks written out */ -relc_t *lastheader; /* pointer into datareloc */ -cons_t holbase; -cons_t holsize; -int unresolved; /* # of unresolved references */ -int sourcelines; /* number of lines in source program*/ -int intflags = 1; /* flags for interpreter */ +int procnum; /* generic for unique proc-descr. */ +cons_t prog_size; /* length of current proc */ +int max_bytes; +int pass; +int line_num; /* line number for error messages */ +int nerrors; /* number of nonfatal errors */ +cons_t consiz; /* size of U,I or F value */ +cons_t textbytes; /* size of code file */ +cons_t databytes; /* highwater mark in data */ +FOFFSET dataoff; /* size of data file */ +FOFFSET textoff; /* size of text file */ +FOFFSET lastoff; /* previous size before last block */ +int datamode; /* what kind of data */ +int datablocks; /* number of datablocks written out */ +relc_t* lastheader; /* pointer into datareloc */ +cons_t holbase; +cons_t holsize; +int unresolved; /* # of unresolved references */ +int sourcelines; /* number of lines in source program*/ +int intflags = 1; /* flags for interpreter */ /* * some flags */ -int archmode; /* reading library ? */ -int procflag; /* print "namelist" of procedures */ -#ifdef DUMP -int c_flag; /* print unused opcodes */ -char opcnt1[256]; /* count primary opcodes */ -char opcnt2[256]; /* count secondary opcodes */ -char opcnt3[256]; /* count long opcodes */ +int archmode; /* reading library ? */ +int procflag; /* print "namelist" of procedures */ +#ifdef DUMP +int c_flag; /* print unused opcodes */ +char opcnt1[256]; /* count primary opcodes */ +char opcnt2[256]; /* count secondary opcodes */ +char opcnt3[256]; /* count long opcodes */ #endif -int d_flag = 0; /* don't dump */ -int r_flag = 0; /* don't dump relocation tables */ +int d_flag = 0; /* don't dump */ +int r_flag = 0; /* don't dump relocation tables */ #ifdef JOHAN -int jflag; +int jflag; #endif -int wflag = 0; /* don't issue warning messages */ -int Uflag = 0; /* exit status 0 on unresolved refs */ -int eof_seen; -int mod_sizes; /* Size info in current module ok? */ +int wflag = 0; /* don't issue warning messages */ +int Uflag = 0; /* exit status 0 on unresolved refs */ +int eof_seen; +int mod_sizes; /* Size info in current module ok? */ -#define BASE (sizeof (struct lines) - sizeof (addr_u)) +#define BASE (sizeof(struct lines) - sizeof(addr_u)) -char linesize[VALLOW+1] = { - BASE, /* MISSING */ - BASE + sizeof (cons_t), /* CONST */ - BASE + sizeof prp_cast, /* PROCNAME */ - BASE + sizeof gbp_cast, /* GLOSYM */ - BASE + sizeof lbp_cast, /* LOCSYM */ - BASE + sizeof (struct sad_df), /* GLOOFF */ - BASE + sizeof (struct sad_ln), /* LINES */ - BASE /* VALLOW */ -} ; +char linesize[VALLOW + 1] = { + BASE, /* MISSING */ + BASE + sizeof(cons_t), /* CONST */ + BASE + sizeof prp_cast, /* PROCNAME */ + BASE + sizeof gbp_cast, /* GLOSYM */ + BASE + sizeof lbp_cast, /* LOCSYM */ + BASE + sizeof(struct sad_df), /* GLOOFF */ + BASE + sizeof(struct sad_ln), /* LINES */ + BASE /* VALLOW */ +}; /* * miscellaneous */ -char *progname; /* argv[0] */ -char *curfile = 0; /* name of current file */ -char *eout = "e.out"; -arch_t archhdr; -siz_t sizes[NDEFAULT] = { -/* mlab, glab,mproc,xproc, proc */ - { 151, 29, 31, 73, 130 }, /* small */ - { 307, 127, 151, 401, 460 }, /* medium */ - { 601, 251, 151, 401, 600 }, /* large */ - {1601, 1601, 1601, 1601, 2000 } /* extra large */ +char* progname; /* argv[0] */ +char* curfile = 0; /* name of current file */ +char* eout = "e.out"; +arch_t archhdr; +siz_t sizes[NDEFAULT] = { + /* mlab, glab,mproc,xproc, proc */ + { 151, 29, 31, 73, 130 }, /* small */ + { 307, 127, 151, 401, 460 }, /* medium */ + { 601, 251, 151, 401, 600 }, /* large */ + { 1601, 1601, 1601, 1601, 2000 } /* extra large */ }; -siz_t *oursize = &sizes[2] ; /* point to selected sizes */ +siz_t* oursize = &sizes[2]; /* point to selected sizes */ diff --git a/util/ass/assex.h b/util/ass/assex.h index fe16a42d92..ba6245ea83 100644 --- a/util/ass/assex.h +++ b/util/ass/assex.h @@ -8,151 +8,144 @@ #include -extern int wordsize; -extern int ptrsize; -extern cons_t maxadr; -extern cons_t maxint; -extern cons_t maxdint; -extern cons_t maxunsig; -extern cons_t maxdunsig; +extern int wordsize; +extern int ptrsize; +extern cons_t maxadr; +extern cons_t maxint; +extern cons_t maxdint; +extern cons_t maxunsig; +extern cons_t maxdunsig; /* * tables loaded from em_libraries */ -extern char em_flag[]; +extern char em_flag[]; /* - The structure containing used for procedure environment stacking + The structure containing used for procedure environment stacking */ -extern stat_t pstate ; +extern stat_t pstate; /* * pointers to not yet allocated storage */ -extern glob_t *mglobs; -extern glob_t *xglobs; -extern proc_t *mprocs; -extern proc_t *xprocs; -extern ptab_t *proctab; +extern glob_t* mglobs; +extern glob_t* xglobs; +extern proc_t* mprocs; +extern proc_t* xprocs; +extern ptab_t* proctab; -extern FILE *ifile; -extern FILE *tfile; -extern FILE *dfile; -extern FILE *rtfile; -extern FILE *rdfile; -extern char string[]; +extern FILE* ifile; +extern FILE* tfile; +extern FILE* dfile; +extern FILE* rtfile; +extern FILE* rdfile; +extern char string[]; /* * some other pointers */ -extern glob_t *lastglosym; -extern glob_t *curglosym; -extern siz_t *oursize; -extern relc_t *f_data; -extern relc_t *l_data; -extern relc_t *f_text; -extern relc_t *l_text; +extern glob_t* lastglosym; +extern glob_t* curglosym; +extern siz_t* oursize; +extern relc_t* f_data; +extern relc_t* l_data; +extern relc_t* f_text; +extern relc_t* l_text; /* * some indices */ -extern int strlngth; -extern FOFFSET inpoff; -extern FOFFSET libeof; +extern int strlngth; +extern FOFFSET inpoff; +extern FOFFSET libeof; /* * some other counters */ -extern int procnum; -extern cons_t prog_size; -extern int max_bytes; -extern int pass; -extern int line_num; -extern int nerrors; -extern cons_t textbytes; -extern cons_t databytes; -extern FOFFSET dataoff; -extern FOFFSET textoff; -extern FOFFSET lastoff; -extern int datamode; -extern int datablocks; -extern relc_t *lastheader; -extern cons_t holbase; -extern cons_t holsize; -extern int unresolved; -extern int sourcelines; -extern int intflags; +extern int procnum; +extern cons_t prog_size; +extern int max_bytes; +extern int pass; +extern int line_num; +extern int nerrors; +extern cons_t textbytes; +extern cons_t databytes; +extern FOFFSET dataoff; +extern FOFFSET textoff; +extern FOFFSET lastoff; +extern int datamode; +extern int datablocks; +extern relc_t* lastheader; +extern cons_t holbase; +extern cons_t holsize; +extern int unresolved; +extern int sourcelines; +extern int intflags; /* * some flags */ -extern int archmode; -extern int procflag; -#ifdef DUMP -extern int c_flag; -extern char opcnt1[]; -extern char opcnt2[]; -extern char opcnt3[]; +extern int archmode; +extern int procflag; +#ifdef DUMP +extern int c_flag; +extern char opcnt1[]; +extern char opcnt2[]; +extern char opcnt3[]; #endif -extern int d_flag; -extern int r_flag; +extern int d_flag; +extern int r_flag; #ifdef JOHAN -extern int jflag; +extern int jflag; #endif -extern int wflag; -extern int Uflag; -extern int eof_seen; -extern int mod_sizes; +extern int wflag; +extern int Uflag; +extern int eof_seen; +extern int mod_sizes; /* * miscellaneous */ -extern cons_t consiz; -extern char *progname; -extern char *curfile; -extern char *eout; -extern arch_t archhdr; -extern siz_t sizes[]; +extern cons_t consiz; +extern char* progname; +extern char* curfile; +extern char* eout; +extern arch_t archhdr; +extern siz_t sizes[]; -extern char linesize[]; +extern char linesize[]; /* * from asstb.c */ -extern char *opindex[] ; -extern char opchoice[] ; -extern int maxinsl ; +extern char* opindex[]; +extern char opchoice[]; +extern int maxinsl; /* Generate temporary filename. Fatal error in case of error. */ -extern char *tmpfil(void); - +extern char* tmpfil(void); /* Read next byte from "af" file, fatal error if there isn't one. */ -extern int xgetc(FILE *af); +extern int xgetc(FILE* af); /* Read a value of length "l" bytes from file "f", * fatal error if cannot be read. */ -extern cons_t xgetarb(int l,FILE *f); +extern cons_t xgetarb(int l, FILE* f); /* Read the pointer constant a from file "f". * NOTE: The bytes were written low to high (little-endian). */ extern cons_t xgeta(FILE* f); - - /* Output one byte into file "af" and fatal error if it gives an error */ -extern void xputc(int c, FILE *af); +extern void xputc(int c, FILE* af); /* Output a 16-bit value into file "f" in little-endian, fatal error if it gives an error. */ -extern void xput16(int w,FILE *f); +extern void xput16(int w, FILE* f); /* Output a value of "l" bytes into file "f" and fatal error if it gives an error. */ -extern void xputarb(int l,cons_t w, FILE* f); +extern void xputarb(int l, cons_t w, FILE* f); /* Assemble the pointer constant a into file "f". * NOTE: The bytes are written low to high (little-endian). */ -extern void xputa(cons_t a,FILE* f); - - - - +extern void xputa(cons_t a, FILE* f); /* Write a byte value into the code temporary file. */ extern void put8(int n); @@ -163,7 +156,6 @@ extern void put32(cons_t n); /* Write a 64-bit value into the code temporary file. */ extern void put64(cons_t n); - /* Read a byte from the input file, return EOF upon error of EOF */ extern int xget8(void); /* Read a byte from the input file, fatal error upon error or EOF. */ @@ -181,8 +173,6 @@ extern int getu16(void); */ extern cons_t get32(void); - - /* Write a byte to the data file. */ extern void ext8(int b); /* Write a 16-bit value to the data file. @@ -198,17 +188,14 @@ extern void extarb(int size, long value); */ extern void extadr(cons_t a); - - /* Returns the opcode length in bytes */ -extern int oplength(int); -extern void genop(char *,cons_t,int ); - -extern void putblk(FILE *stream, char *from, int amount); -extern int getblk(FILE *stream, char *from, int amount); +extern int oplength(int); +extern void genop(char*, cons_t, int); +extern void putblk(FILE* stream, char* from, int amount); +extern int getblk(FILE* stream, char* from, int amount); -extern void set_mode(int mode); +extern void set_mode(int mode); /* Dump current information to screen if dump flag is enabled. */ void dump(int n); @@ -218,18 +205,17 @@ extern char *findnop(); extern char *findfit(); */ -extern glob_t *glolookup(char *name,int status,glob_t *table, int size); -extern proc_t *searchproc(char *name,proc_t *table,int size); -extern glob_t *glo2lookup(char *name ,int status); -extern glob_t *xglolookup(char *name,int status); -extern proc_t *prolookup(char *name,int status); -extern locl_t *loclookup(unsigned int an,int status); -extern proc_t *enterproc(char *name,int status,proc_t *place); -extern cons_t parval(line_t *lnp,char *defined); - - -extern void determine_props(line_t *lnp, int *min_len, int *max_len); -extern int opfit(int flag,int number,cons_t val,int i_flag); +extern glob_t* glolookup(char* name, int status, glob_t* table, int size); +extern proc_t* searchproc(char* name, proc_t* table, int size); +extern glob_t* glo2lookup(char* name, int status); +extern glob_t* xglolookup(char* name, int status); +extern proc_t* prolookup(char* name, int status); +extern locl_t* loclookup(unsigned int an, int status); +extern proc_t* enterproc(char* name, int status, proc_t* place); +extern cons_t parval(line_t* lnp, char* defined); + +extern void determine_props(line_t* lnp, int* min_len, int* max_len); +extern int opfit(int flag, int number, cons_t val, int i_flag); extern void initproc(void); extern void endproc(void); @@ -242,6 +228,4 @@ extern void init_vars(void); extern void error(const char* string1, ...); extern void werror(const char* string1, ...); -extern void fatal(char *s); - - +extern void fatal(char* s); diff --git a/util/ass/assrl.c b/util/ass/assrl.c index b96568b547..d9d7e4f191 100644 --- a/util/ass/assrl.c +++ b/util/ass/assrl.c @@ -4,26 +4,25 @@ * */ -#include -#include "ass00.h" -#include "assex.h" -#include "asscm.h" -#include "assrl.h" +#include +#include +#include +#include "ass00.h" +#include "assex.h" +#include "asscm.h" +#include "assrl.h" - - -#define COPYFINAL 1 -#define COPYTEMP 0 +#define COPYFINAL 1 +#define COPYTEMP 0 /* * collection of routines to deal with relocation business */ +static void dataprocess(FILE*, FILE*); +static void textprocess(FILE*, FILE*); -static void dataprocess(FILE *, FILE *); -static void textprocess(FILE *, FILE *); - -relc_t * text_reloc(glob_t *glosym, FOFFSET off, int typ) +relc_t* text_reloc(glob_t* glosym, FOFFSET off, int typ) { /* @@ -36,7 +35,7 @@ relc_t * text_reloc(glob_t *glosym, FOFFSET off, int typ) * into the one in xglobs[] later. */ - relc_t *nxtextreloc; + relc_t* nxtextreloc; nxtextreloc = rlp_cast getarea(sizeof *nxtextreloc); if (!f_text) @@ -55,14 +54,14 @@ relc_t * text_reloc(glob_t *glosym, FOFFSET off, int typ) return (nxtextreloc); } -relc_t * data_reloc(char *arg ,FOFFSET off, int typ) +relc_t* data_reloc(char* arg, FOFFSET off, int typ) { /* * Same as above. */ - relc_t *nxdatareloc; + relc_t* nxdatareloc; nxdatareloc = rlp_cast getarea(sizeof *nxdatareloc); if (!f_data) @@ -142,13 +141,13 @@ void copyout(void) xput16(0, ifile); xput16(0, ifile); xputa(textbytes + remtext, ifile); - xputa((cons_t) datablocks, ifile); - xputa((cons_t) procnum, ifile); - xputa((cons_t) searchproc(MAIN, xprocs, oursize->n_xproc)->p_num, ifile); - xputa((cons_t) sourcelines, ifile); - xputa((cons_t) databytes, ifile); - xputa((cons_t) 0, ifile); - xputa((cons_t) 0, ifile); + xputa((cons_t)datablocks, ifile); + xputa((cons_t)procnum, ifile); + xputa((cons_t)searchproc(MAIN, xprocs, oursize->n_xproc)->p_num, ifile); + xputa((cons_t)sourcelines, ifile); + xputa((cons_t)databytes, ifile); + xputa((cons_t)0, ifile); + xputa((cons_t)0, ifile); textprocess(tfile, ifile); while (remtext--) @@ -164,61 +163,60 @@ void copyout(void) ; } -static void dataprocess(FILE *f1, FILE *outf) +static void dataprocess(FILE* f1, FILE* outf) { relc_t datareloc; FOFFSET i; int ieof; rewind(rdfile); - ieof = getblk(rdfile, (char *) (&datareloc.r_off), - sizeof datareloc - sizeof datareloc.r_next); + ieof = getblk(rdfile, (char*)(&datareloc.r_off), sizeof datareloc - sizeof datareloc.r_next); for (i = 0; i < dataoff && !ieof; i++) { if (i == datareloc.r_off) { switch (datareloc.r_typ) { - case RELADR: - xputa(xgeta(f1) + datareloc.r_val.rel_i, outf); - i += ptrsize - 1; - break; - case RELGLO: - if (datareloc.r_val.rel_gp->g_status & DEF) - { - xputa(xgeta(f1) + datareloc.r_val.rel_gp->g_val.g_addr, outf); + case RELADR: + xputa(xgeta(f1) + datareloc.r_val.rel_i, outf); i += ptrsize - 1; break; - } - if (unresolved == 0) - fatal("Definition botch"); - case RELHEAD: - xputc((int) (xgetc(f1) + datareloc.r_val.rel_i), outf); - break; - default: - fatal("Bad r_typ in dataprocess"); + case RELGLO: + if (datareloc.r_val.rel_gp->g_status & DEF) + { + xputa(xgeta(f1) + datareloc.r_val.rel_gp->g_val.g_addr, outf); + i += ptrsize - 1; + break; + } + if (unresolved == 0) + fatal("Definition botch"); + case RELHEAD: + xputc((int)(xgetc(f1) + datareloc.r_val.rel_i), outf); + break; + default: + fatal("Bad r_typ in dataprocess"); } - ieof = getblk(rdfile, (char *) (&datareloc.r_off), - sizeof datareloc - sizeof datareloc.r_next); + ieof = getblk( + rdfile, (char*)(&datareloc.r_off), sizeof datareloc - sizeof datareloc.r_next); } else xputc(xgetc(f1), outf); } for (; i < dataoff; i++) xputc(xgetc(f1), outf); - if (!ieof && !getblk(rdfile, (char *) &datareloc, 1)) + if (!ieof && !getblk(rdfile, (char*)&datareloc, 1)) fatal("data relocation botch"); } -static void textprocess(FILE *f1, FILE *outf) +static void textprocess(FILE* f1, FILE* outf) { relc_t textreloc; cons_t n; FOFFSET i; - FILE *otfile; + FILE* otfile; int insl; int ieof; - char *op_curr; + char* op_curr; FOFFSET keep; rewind(rtfile); @@ -227,8 +225,7 @@ static void textprocess(FILE *f1, FILE *outf) otfile = tfile; tfile = outf; /* This redirects the output of genop */ - ieof = getblk(rtfile, (char *) (&textreloc.r_off), - sizeof textreloc - sizeof textreloc.r_next); + ieof = getblk(rtfile, (char*)(&textreloc.r_off), sizeof textreloc - sizeof textreloc.r_next); for (i = 0; i < keep && !ieof; i++) { if (i == textreloc.r_off) @@ -248,8 +245,9 @@ static void textprocess(FILE *f1, FILE *outf) if (unresolved == 0) fatal("Definition botch"); xputc(xgetc(f1), outf); - ieof = getblk(rtfile, (char *) (&textreloc.r_off), - sizeof textreloc - sizeof textreloc.r_next); + ieof = getblk( + rtfile, (char*)(&textreloc.r_off), + sizeof textreloc - sizeof textreloc.r_next); continue; } } @@ -257,8 +255,8 @@ static void textprocess(FILE *f1, FILE *outf) insl = oplength(*op_curr); genop(op_curr, n + xgetarb(insl, f1), PAR_G); i += insl - 1; - ieof = getblk(rtfile, (char *) (&textreloc.r_off), - sizeof textreloc - sizeof textreloc.r_next); + ieof = getblk( + rtfile, (char*)(&textreloc.r_off), sizeof textreloc - sizeof textreloc.r_next); } else { @@ -267,7 +265,7 @@ static void textprocess(FILE *f1, FILE *outf) } for (; i < keep; i++) xputc(xgetc(f1), outf); - if (!ieof && !getblk(rtfile, (char *) &textreloc, 1)) + if (!ieof && !getblk(rtfile, (char*)&textreloc, 1)) fatal("text relocation botch"); textoff = keep; tfile = otfile; @@ -275,8 +273,8 @@ static void textprocess(FILE *f1, FILE *outf) void upd_reloc(void) { - relc_t *p; - glob_t *gbp; + relc_t* p; + glob_t* gbp; /* * Change reloc-tables such that for every pointer into mglobs @@ -287,7 +285,7 @@ void upd_reloc(void) * see also getcore() */ - while ( (p = f_text) != NULL) + while ((p = f_text) != NULL) { gbp = p->r_val.rel_gp; if (gbp->g_status & DEF) @@ -297,12 +295,12 @@ void upd_reloc(void) } else p->r_val.rel_gp = gbp->g_val.g_gp; - putblk(rtfile, (char *) (&(p->r_off)), sizeof *p - sizeof p); + putblk(rtfile, (char*)(&(p->r_off)), sizeof *p - sizeof p); f_text = p->r_next; - freearea((area_t) p, sizeof *p); + freearea((area_t)p, sizeof *p); } - while ( (p = f_data) != NULL) + while ((p = f_data) != NULL) { if (p->r_typ == RELGLO) { @@ -315,9 +313,9 @@ void upd_reloc(void) else p->r_val.rel_gp = gbp->g_val.g_gp; } - putblk(rdfile, (char *) (&(p->r_off)), sizeof *p - sizeof p); + putblk(rdfile, (char*)(&(p->r_off)), sizeof *p - sizeof p); f_data = p->r_next; - freearea((area_t) p, sizeof *p); + freearea((area_t)p, sizeof *p); } l_data = rlp_cast 0; } diff --git a/util/ass/assrl.h b/util/ass/assrl.h index d222f9d092..fbeeb9c14d 100644 --- a/util/ass/assrl.h +++ b/util/ass/assrl.h @@ -1,9 +1,9 @@ /* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, + * See the copyright notice in the ACK home directory, * in the file "Copyright". * * Created on: 2019-03-13 - * + * */ #ifndef ASSRL_H_ #define ASSRL_H_ @@ -15,7 +15,7 @@ void copyout(void); /* Update the relocation entries and place them into "rtfile" and "rdfile". */ void upd_reloc(void); -relc_t * data_reloc(char *arg ,FOFFSET off, int typ); -relc_t * text_reloc(glob_t *glosym, FOFFSET off, int typ); +relc_t* data_reloc(char* arg, FOFFSET off, int typ); +relc_t* text_reloc(glob_t* glosym, FOFFSET off, int typ); #endif /* ASSRL_H_ */ diff --git a/util/ass/maktab.c b/util/ass/maktab.c index 15e7abfaf8..9f8070d35d 100644 --- a/util/ass/maktab.c +++ b/util/ass/maktab.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include #include @@ -17,11 +19,11 @@ translated by a C-compiler. */ -#define NOTAB 600 /* The max no of interpreter specs */ -#define ESCAP 256 +#define NOTAB 600 /* The max no of interpreter specs */ +#define ESCAP 256 struct opform intable[NOTAB]; -struct opform *lastform = intable - 1; +struct opform* lastform = intable - 1; int nerror = 0; int atend = 0; @@ -30,33 +32,30 @@ int maxinsl = 0; extern char em_mnem[][4]; char esca[] = "escape"; -#define ename(no) ((no)==ESCAP?esca:em_mnem[(no)]) +#define ename(no) ((no) == ESCAP ? esca : em_mnem[(no)]) extern char em_flag[]; - /* Forward declarations */ static int readchar(void); static void pushback(int); static void readin(void); -static char *ident(void); -static int getmnem(char *); +static char* ident(void); +static int getmnem(char*); static void writeout(void); static void checkall(void); static void chkc(int, int, int); static void ckop(int, int, int, int); -static int oplength(struct opform *); +static int oplength(struct opform*); static void check(int); -static int decflag(char *); -int compare(const void *, const void *); - -static void error(char *format, ...); -static void mess(char *format, ...); -static void fatal(char *format, ...); - +static int decflag(char*); +int compare(const void*, const void*); +static void error(char* format, ...); +static void mess(char* format, ...); +static void fatal(char* format, ...); -int main(int argc, char **argv) +int main(int argc, char** argv) { if (argc > 1) { @@ -89,8 +88,8 @@ int main(int argc, char **argv) static void readin(void) { - struct opform *nextform; - char *firstid; + struct opform* nextform; + char* firstid; int maxl; maxl = 0; @@ -104,10 +103,10 @@ static void readin(void) nextform->i_flag = decflag(ident()); switch (nextform->i_flag & OPTYPE) { - case OPMINI: - case OPSHORT: - nextform->i_num = atoi(ident()); - break; + case OPMINI: + case OPSHORT: + nextform->i_num = atoi(ident()); + break; } nextform->i_low = atoi(ident()); if (*ident() != '\n') @@ -126,7 +125,7 @@ static void readin(void) maxinsl = maxl; } -static char *ident(void) +static char* ident(void) { /* skip spaces and tabs, anything up to space,tab or eof is a identifier. @@ -136,7 +135,7 @@ static char *ident(void) static char array[200]; int c; - char *cc; + char* cc; do { @@ -167,7 +166,7 @@ static char *ident(void) return array; } -static int getmnem(char *str) +static int getmnem(char* str) { char (*ptr)[4]; @@ -181,44 +180,44 @@ static int getmnem(char *str) } /* VARARGS1 */ -static void error(char *format, ...) +static void error(char* format, ...) { - va_list argptr; + va_list argptr; if (!atend) fprintf(stderr, "line %d: ", line); - va_start(argptr, format); - vfprintf(stderr, format, argptr); - va_end(argptr); + va_start(argptr, format); + vfprintf(stderr, format, argptr); + va_end(argptr); fprintf(stderr, "\n"); nerror++; } /* VARARGS1 */ -static void mess(char *format, ...) +static void mess(char* format, ...) { - va_list argptr; + va_list argptr; if (!atend) fprintf(stderr, "line %d: ", line); - va_start(argptr, format); - vfprintf(stderr, format, argptr); - va_end(argptr); + va_start(argptr, format); + vfprintf(stderr, format, argptr); + va_end(argptr); fprintf(stderr, "\n"); } /* VARARGS1 */ -static void fatal(char *format, ...) +static void fatal(char* format, ...) { - va_list argptr; + va_list argptr; if (!atend) fprintf(stderr, "line %d: ", line); - va_start(argptr, format); - vfprintf(stderr, format, argptr); - va_end(argptr); + va_start(argptr, format); + vfprintf(stderr, format, argptr); + va_end(argptr); fprintf(stderr, "\n"); exit(EXIT_FAILURE); } -#define ILLGL -1 +#define ILLGL -1 static void check(int val) { @@ -226,7 +225,7 @@ static void check(int val) error("Illegal flag combination"); } -static int decflag(char *str) +static int decflag(char* str) { int type; int escape; @@ -238,81 +237,81 @@ static int decflag(char *str) while (*str) switch (*str++) { - case 'm': - check(type); - type = OPMINI; - break; - case 's': - check(type); - type = OPSHORT; - break; - case '-': - check(type); - type = OPNO; - break; - case '1': - check(type); - type = OP8; - break; - case '2': - check(type); - type = OP16; - break; - case '4': - check(type); - type = OP32; - break; - case '8': - check(type); - type = OP64; - break; - case 'u': - check(type); - type = OP16U; - break; - case 'e': - check(escape); - escape = 0; - break; - case 'N': - check(range); - range = 2; - break; - case 'P': - check(range); - range = 1; - break; - case 'w': - check(wordm); - wordm = 0; - break; - case 'o': - check(notzero); - notzero = 0; - break; - default: - error("Unknown flag"); + case 'm': + check(type); + type = OPMINI; + break; + case 's': + check(type); + type = OPSHORT; + break; + case '-': + check(type); + type = OPNO; + break; + case '1': + check(type); + type = OP8; + break; + case '2': + check(type); + type = OP16; + break; + case '4': + check(type); + type = OP32; + break; + case '8': + check(type); + type = OP64; + break; + case 'u': + check(type); + type = OP16U; + break; + case 'e': + check(escape); + escape = 0; + break; + case 'N': + check(range); + range = 2; + break; + case 'P': + check(range); + range = 1; + break; + case 'w': + check(wordm); + wordm = 0; + break; + case 'o': + check(notzero); + notzero = 0; + break; + default: + error("Unknown flag"); } if (type == ILLGL) error("Type must be specified"); switch (type) { - case OP64: - case OP32: - if (escape != ILLGL) - error("Conflicting escapes"); - escape = ILLGL; - case OP16: - case OP16U: - case OP8: - case OPSHORT: - case OPNO: - if (notzero != ILLGL) - mess("Improbable OPNZ"); - if (type == OPNO && range != ILLGL) - { - mess("No operand in range"); - } + case OP64: + case OP32: + if (escape != ILLGL) + error("Conflicting escapes"); + escape = ILLGL; + case OP16: + case OP16U: + case OP8: + case OPSHORT: + case OPNO: + if (notzero != ILLGL) + mess("Improbable OPNZ"); + if (type == OPNO && range != ILLGL) + { + mess("No operand in range"); + } } if (escape != ILLGL) type |= OPESC; @@ -320,17 +319,17 @@ static int decflag(char *str) type |= OPWORD; switch (range) { - case ILLGL: - type |= OP_BOTH; - if (type == OPMINI || type == OPSHORT) - error("Minies and shorties must have P or N"); - break; - case 1: - type |= OP_POS; - break; - case 2: - type |= OP_NEG; - break; + case ILLGL: + type |= OP_BOTH; + if (type == OPMINI || type == OPSHORT) + error("Minies and shorties must have P or N"); + break; + case 1: + type |= OP_POS; + break; + case 2: + type |= OP_NEG; + break; } if (notzero != ILLGL) type |= OPNZ; @@ -339,7 +338,7 @@ static int decflag(char *str) static void writeout(void) { - struct opform *next; + struct opform* next; int elem[sp_lmnem - sp_fmnem + 1 + 1]; /* for each op points to first of descr. */ int i, currop; @@ -366,10 +365,10 @@ static void writeout(void) nch += 2; switch (next->i_flag & OPTYPE) { - case OPMINI: - case OPSHORT: - printf("%d,", next->i_num & 0377); - nch++; + case OPMINI: + case OPSHORT: + printf("%d,", next->i_num & 0377); + nch++; } printf("\n"); } @@ -384,15 +383,16 @@ static void writeout(void) { printf(" &opchoice[%d], /* %d = %s */\n", elem[i], i, em_mnem[i]); } - printf(" &opchoice[%d], /* %d = %s */\n", elem[sp_lmnem - sp_fmnem + 1], - sp_lmnem - sp_fmnem + 1, ""); + printf( + " &opchoice[%d], /* %d = %s */\n", elem[sp_lmnem - sp_fmnem + 1], sp_lmnem - sp_fmnem + 1, + ""); printf("} ;\n"); } -int compare(const void *a1, const void *b1) +int compare(const void* a1, const void* b1) { - struct opform *a = (struct opform *)(a1); - struct opform *b = (struct opform *)(b1); + struct opform* a = (struct opform*)(a1); + struct opform* b = (struct opform*)(b1); if (a->i_opcode != b->i_opcode) { @@ -401,7 +401,7 @@ int compare(const void *a1, const void *b1) return oplength(a) - oplength(b); } -static int oplength(struct opform *a) +static int oplength(struct opform* a) { int cnt; @@ -410,23 +410,23 @@ static int oplength(struct opform *a) cnt++; switch (a->i_flag & OPTYPE) { - case OPNO: - case OPMINI: - break; - case OP8: - case OPSHORT: - cnt++; - break; - case OP16U: - case OP16: - cnt += 2; - break; - case OP32: - cnt += 5; - break; - case OP64: - cnt += 9; - break; + case OPNO: + case OPMINI: + break; + case OP8: + case OPSHORT: + cnt++; + break; + case OP16U: + case OP16: + cnt += 2; + break; + case OP32: + cnt += 5; + break; + case OP64: + cnt += 9; + break; } return cnt; } @@ -435,17 +435,17 @@ static int oplength(struct opform *a) int ecodes[256], codes[256], lcodes[256]; -#define NMNEM (sp_lmnem-sp_fmnem+1) -#define MUST 1 -#define MAY 2 -#define FORB 3 +#define NMNEM (sp_lmnem - sp_fmnem + 1) +#define MUST 1 +#define MAY 2 +#define FORB 3 char negc[NMNEM], zc[NMNEM], posc[NMNEM]; static void checkall(void) { int i, flag; - struct opform *next; + struct opform* next; int opc, low; for (i = 0; i < NMNEM; i++) @@ -465,36 +465,36 @@ static void checkall(void) chkc(flag, low, opc); switch (flag & OPTYPE) { - case OPNO: - zc[opc]++; - break; - case OPMINI: - case OPSHORT: - for (i = 1; i < ((next->i_num) & 0377); i++) - { - chkc(flag, low + i, opc); - } - if (!(em_flag[opc] & PAR_G) && (flag & OPRANGE) == OP_BOTH) - { - mess("Mini's and shorties should have P or N"); - } - break; - case OP8: - error("OP8 is removed"); - break; - case OP16: - if (flag & OP_NEG) - negc[opc]++; - else if (flag & OP_POS) - posc[opc]++; - break; - case OP16U: - case OP32: - case OP64: - break; - default: - error("Illegal type"); - break; + case OPNO: + zc[opc]++; + break; + case OPMINI: + case OPSHORT: + for (i = 1; i < ((next->i_num) & 0377); i++) + { + chkc(flag, low + i, opc); + } + if (!(em_flag[opc] & PAR_G) && (flag & OPRANGE) == OP_BOTH) + { + mess("Mini's and shorties should have P or N"); + } + break; + case OP8: + error("OP8 is removed"); + break; + case OP16: + if (flag & OP_NEG) + negc[opc]++; + else if (flag & OP_POS) + posc[opc]++; + break; + case OP16U: + case OP32: + case OP64: + break; + default: + error("Illegal type"); + break; } } atend = 1; @@ -507,35 +507,35 @@ static void checkall(void) { switch (em_flag[opc] & EM_PAR) { - case PAR_NO: - ckop(opc, MUST, FORB, FORB); - break; - case PAR_C: - case PAR_D: - case PAR_F: - case PAR_B: - ckop(opc, FORB, MAY, MAY); - break; - case PAR_N: - case PAR_G: - case PAR_S: - case PAR_Z: - case PAR_O: - case PAR_P: - ckop(opc, FORB, MAY, FORB); - break; - case PAR_R: - ckop(opc, FORB, MAY, FORB); - break; - case PAR_L: - ckop(opc, FORB, MUST, MUST); - break; - case PAR_W: - ckop(opc, MUST, MAY, FORB); - break; - default: - error("Unknown instruction type of %s", ename(opc)); - break; + case PAR_NO: + ckop(opc, MUST, FORB, FORB); + break; + case PAR_C: + case PAR_D: + case PAR_F: + case PAR_B: + ckop(opc, FORB, MAY, MAY); + break; + case PAR_N: + case PAR_G: + case PAR_S: + case PAR_Z: + case PAR_O: + case PAR_P: + ckop(opc, FORB, MAY, FORB); + break; + case PAR_R: + ckop(opc, FORB, MAY, FORB); + break; + case PAR_L: + ckop(opc, FORB, MUST, MUST); + break; + case PAR_W: + ckop(opc, MUST, MAY, FORB); + break; + default: + error("Unknown instruction type of %s", ename(opc)); + break; } } } @@ -546,31 +546,29 @@ static void chkc(int flag, int icode, int emc) { if (ecodes[icode] != -1) { - mess("Escaped opcode %d used by %s and %s", icode, ename(emc), - ename(ecodes[icode])); + mess("Escaped opcode %d used by %s and %s", icode, ename(emc), ename(ecodes[icode])); } ecodes[icode] = emc; } else switch (flag & OPTYPE) { - default: - if (codes[icode] != -1) - { - mess("Opcode %d used by %s and %s", icode, ename(emc), - ename(codes[icode])); - } - codes[icode] = emc; - break; - case OP32: - case OP64: - if (lcodes[icode] != -1) - { - mess("Long opcode %d used by %s and %s", icode, ename(emc), - ename(codes[icode])); - } - lcodes[icode] = emc; - break; + default: + if (codes[icode] != -1) + { + mess("Opcode %d used by %s and %s", icode, ename(emc), ename(codes[icode])); + } + codes[icode] = emc; + break; + case OP32: + case OP64: + if (lcodes[icode] != -1) + { + mess( + "Long opcode %d used by %s and %s", icode, ename(emc), ename(codes[icode])); + } + lcodes[icode] = emc; + break; } } @@ -584,36 +582,36 @@ static void ckop(int emc, int zf, int pf, int nf) mess("More then one OP16(neg) for %s", ename(emc)); switch (zf) { - case MUST: - if (zc[emc] == 0) - mess("No OPNO for %s", ename(emc)); - break; - case FORB: - if (zc[emc] == 1) - mess("Forbidden OPNO for %s", ename(emc)); - break; + case MUST: + if (zc[emc] == 0) + mess("No OPNO for %s", ename(emc)); + break; + case FORB: + if (zc[emc] == 1) + mess("Forbidden OPNO for %s", ename(emc)); + break; } switch (pf) { - case MUST: - if (posc[emc] == 0) - mess("No OP16(pos) for %s", ename(emc)); - break; - case FORB: - if (posc[emc] == 1) - mess("Forbidden OP16(pos) for %s", ename(emc)); - break; + case MUST: + if (posc[emc] == 0) + mess("No OP16(pos) for %s", ename(emc)); + break; + case FORB: + if (posc[emc] == 1) + mess("Forbidden OP16(pos) for %s", ename(emc)); + break; } switch (nf) { - case MUST: - if (negc[emc] == 0) - mess("No OP16(neg) for %s", ename(emc)); - break; - case FORB: - if (negc[emc] == 1) - mess("Forbidden OP16(neg) for %s", ename(emc)); - break; + case MUST: + if (negc[emc] == 0) + mess("No OP16(neg) for %s", ename(emc)); + break; + case FORB: + if (negc[emc] == 1) + mess("Forbidden OP16(neg) for %s", ename(emc)); + break; } } diff --git a/util/ceg/EM_parser/as_EM_pars/em_decl.h b/util/ceg/EM_parser/as_EM_pars/em_decl.h index 24b258f0d0..c46fae2aa7 100644 --- a/util/ceg/EM_parser/as_EM_pars/em_decl.h +++ b/util/ceg/EM_parser/as_EM_pars/em_decl.h @@ -7,10 +7,6 @@ #define UNKNOWN (-1) -#define TRUE 1 -#define FALSE 0 - - #define STRING 0 #define LABEL 1 #define ARITH 2 diff --git a/util/ceg/EM_parser/common/C_instr2.c b/util/ceg/EM_parser/common/C_instr2.c index 782e1a9337..7c42028ca5 100644 --- a/util/ceg/EM_parser/common/C_instr2.c +++ b/util/ceg/EM_parser/common/C_instr2.c @@ -429,7 +429,7 @@ char *instr; low = 0; high = N_INSTR - 1; - while ( TRUE) { + while ( true) { mid = ( low + high) / 2; rel = strcmp( instr, EM_instr[mid].name); diff --git a/util/ceg/EM_parser/common/decl.h b/util/ceg/EM_parser/common/decl.h index dec63c8181..282c40d541 100644 --- a/util/ceg/EM_parser/common/decl.h +++ b/util/ceg/EM_parser/common/decl.h @@ -4,10 +4,6 @@ #define UNKNOWN (-1) -#define TRUE 1 -#define FALSE 0 - - #define MAX_ARGS 4 /* All the different types of C_INSTR's, based on types of the arguments. */ diff --git a/util/ceg/EM_parser/common/default.c b/util/ceg/EM_parser/common/default.c index a4386ddea0..184409fcf1 100644 --- a/util/ceg/EM_parser/common/default.c +++ b/util/ceg/EM_parser/common/default.c @@ -141,7 +141,7 @@ char *instr; low = C_DEE; high = C_ZRE; - while ( TRUE) { + while ( true) { mid = ( low + high) / 6 * 3; rel = strncmp( instr, def_info[mid].name, 5); @@ -188,7 +188,7 @@ handle_defaults() set_outfile( def_info[i].name); header( def_info[i].name); - CD_pos = TRUE; /* Set mylex() in correct state */ + CD_pos = true; /* Set mylex() in correct state */ if ( bss_or_hol_instr( i)) { extnd_header(); @@ -223,7 +223,7 @@ char *instr; low = _ICON; high = C_ZRE + 2; - while ( TRUE) { + while ( true) { mid = ( low + high) / 2; rel = strcmp( instr, def_info[mid].name); diff --git a/util/ceg/EM_parser/common/mylex.c b/util/ceg/EM_parser/common/mylex.c index d8d01bee02..8d707fb769 100644 --- a/util/ceg/EM_parser/common/mylex.c +++ b/util/ceg/EM_parser/common/mylex.c @@ -29,17 +29,14 @@ char yytext[YYTEXT], /* string-buffer for the token */ *next; /* points to the first free posistion in yytext[] */ extern char scanc(); -#define FALSE 0 -#define TRUE 1 - -int CD_pos = FALSE; /* 'CD_pos' is used as a flag to signal if it is +int CD_pos = false; /* 'CD_pos' is used as a flag to signal if it is * possible to match a CONDITION or DEFAULT-token at * this moment. Thus mylex() knows about the grammar * of the "EM_table"!! * This flag is needed because CALL is a subset of * CONDITION. */ -int CALL_pos = FALSE; /* Needed to distinguish between +int CALL_pos = false; /* Needed to distinguish between * C_INSTR CONDITION and CALL */ @@ -51,7 +48,7 @@ int mylex() { char c; - static int special = FALSE; /* rule with conditions + default ? */ + static int special = false; /* rule with conditions + default ? */ next = yytext; c = *next++ = skip_space(); @@ -68,8 +65,8 @@ int mylex() * '..icon'. */ if ( special) - CD_pos = TRUE; - CALL_pos = FALSE; + CD_pos = true; + CALL_pos = false; return( '.'); } break; @@ -77,15 +74,15 @@ int mylex() case ';' : return( ';'); case '=' : if ( arrow()) { - CD_pos = FALSE; - CALL_pos = TRUE; + CD_pos = false; + CALL_pos = true; return( ARROW); } break; case 'd' : if ( CD_pos && _default()) { - CD_pos = FALSE; - special = FALSE; + CD_pos = false; + special = false; return( DEFAULT); } break; @@ -96,8 +93,8 @@ int mylex() if ( CD_pos) { read_condition(); - CD_pos = FALSE; - special = TRUE; + CD_pos = false; + special = true; return( CONDITION); } if ( isalpha( c)) { @@ -116,11 +113,11 @@ int mylex() } else { if ( is_DEF_C_INSTR( yytext)) { - CD_pos = TRUE; + CD_pos = true; return( DEF_C_INSTR); } if ( is_C_INSTR( yytext)) { - CD_pos = TRUE; + CD_pos = true; return( C_INSTR); } return( ERROR); @@ -132,7 +129,7 @@ int mylex() *next++ = '.'; read_ident(); if ( is_DEF_C_INSTR( yytext)) { - CD_pos = TRUE; + CD_pos = true; return( DEF_C_INSTR); } return( ERROR); @@ -180,12 +177,12 @@ int arrow() /* '==>' */ { if ( ( *next++ = scanc()) == '=') if ( ( *next++ = scanc()) == '>') - return( TRUE); + return( true); else backc( *--next); else backc( *--next); - return( FALSE); + return( false); } int _default() /* 'default' */ @@ -200,7 +197,7 @@ int _default() /* 'default' */ if ( ( *next++ = scanc()) == 't') if ( !isletter( c = skip_space())) { backc( c); - return( TRUE); + return( true); } else backc( c); @@ -216,7 +213,7 @@ int _default() /* 'default' */ backc( *--next); else backc( *--next); - return( FALSE); + return( false); } read_ident() @@ -232,7 +229,7 @@ read_call() { int n = 1; - while ( TRUE) + while ( true) switch( *next++ = scanc()) { case EOF : return; @@ -251,7 +248,7 @@ read_condition() /* A CONDITION is followed by '==>' */ { - while ( TRUE) { + while ( true) { switch ( *next++ = scanc()) { case EOF : return; @@ -271,9 +268,9 @@ is_C_INSTR( str) char *str; { if ( *str == 'C' && *(str+1) == '_') /* C_xxx */ - return( TRUE); + return( true); else - return( FALSE); + return( false); } is_DEF_C_INSTR( str) @@ -294,5 +291,5 @@ char *str; backc( *--next); else backc( *--next); - return( FALSE); + return( false); } diff --git a/util/ceg/EM_parser/obj_EM_pars/dist.c b/util/ceg/EM_parser/obj_EM_pars/dist.c index 944b1e31c2..09c3401306 100644 --- a/util/ceg/EM_parser/obj_EM_pars/dist.c +++ b/util/ceg/EM_parser/obj_EM_pars/dist.c @@ -14,8 +14,6 @@ char *lab; #define MAX_LABEL 10 -#define TRUE 1 -#define FALSE 0 struct t_label { diff --git a/util/ceg/as_parser/const.h b/util/ceg/as_parser/const.h index e5acbcc436..2f32f9e0a5 100644 --- a/util/ceg/as_parser/const.h +++ b/util/ceg/as_parser/const.h @@ -1,7 +1,3 @@ -#define Bool int - -#define TRUE 1 -#define FALSE 0 #define MAX_OPERANDS 4 #define MAX_MNEMONICS 100 diff --git a/util/ceg/as_parser/help.c b/util/ceg/as_parser/help.c index 3714925dc3..23a48f87bb 100644 --- a/util/ceg/as_parser/help.c +++ b/util/ceg/as_parser/help.c @@ -22,7 +22,7 @@ static int n_ops = 0; /* Number of opertands of current * assembly instruction. */ static char *assem_instr = 0; /* Name of the current assembly instr */ -static Bool restriction = FALSE; /* Is there a restriction on the +static Bool restriction = false; /* Is there a restriction on the * current operand? */ FILE* outfile; @@ -46,7 +46,7 @@ char *type; int len; { op_info[ n_ops].type = strdup( type); - restriction = TRUE; + restriction = true; } pr_header() @@ -81,7 +81,7 @@ param_list() pr_restriction() { int i; - Bool more = FALSE; + Bool more = false; if ( !restriction) return; @@ -92,7 +92,7 @@ pr_restriction() if ( more) out( " &&"); out( " %s( %s)", op_info[i].type, op_info[i].name); - more = TRUE; + more = true; } out( ") "); } @@ -101,12 +101,12 @@ pr_warning() { if ( restriction) out( "else\nerror( \"No match for %s\");\n", assem_instr); - restriction = FALSE; + restriction = false; } clear_restriction() { - restriction = FALSE; + restriction = false; } char *skip_string( str) diff --git a/util/ceg/assemble/obj_assemble/assemble.c b/util/ceg/assemble/obj_assemble/assemble.c index d83e25f03b..6ef7bd64d7 100644 --- a/util/ceg/assemble/obj_assemble/assemble.c +++ b/util/ceg/assemble/obj_assemble/assemble.c @@ -206,7 +206,7 @@ char *mnem; low = 0; high = n_mnems-1; - while ( TRUE) { + while ( true) { mid = ( low + high) / 2; rel = strcmp(mnem, mnemonic[ mid]); diff --git a/util/ceg/assemble/obj_assemble/const.h b/util/ceg/assemble/obj_assemble/const.h index fc24538a5e..7eec66815c 100644 --- a/util/ceg/assemble/obj_assemble/const.h +++ b/util/ceg/assemble/obj_assemble/const.h @@ -1,6 +1,2 @@ -#define Bool int - -#define TRUE 1 -#define FALSE 0 #define MAX_OPERANDS 4 #define MAX_MNEMONICS 100 diff --git a/util/cgg/booth.h b/util/cgg/booth.h index 704f0aab68..c05872a683 100644 --- a/util/cgg/booth.h +++ b/util/cgg/booth.h @@ -45,9 +45,6 @@ EXTERN char *iname; /* stdin */ #define BMASK 0377 #define BSHIFT 8 -#define TRUE 1 -#define FALSE 0 - #define MAXPATLEN 7 /* Maximum length of tokenpatterns */ typedef char byte; diff --git a/util/ego/bo/bo.c b/util/ego/bo/bo.c index a8292dc430..f46fc5c980 100644 --- a/util/ego/bo/bo.c +++ b/util/ego/bo/bo.c @@ -199,7 +199,7 @@ static void mv_code(bblock_p b1, bblock_p b2) { line_p l, x; - l = last_code(b2->b_start, TRUE); + l = last_code(b2->b_start, true); assert(INSTR(l) == op_bra); DLINK(l, b1->b_start); x = l->l_next; @@ -220,12 +220,12 @@ static void bo_switch(bblock_p b) { s = (bblock_p)Lelem(Lfirst(b->b_succ)); if (b->b_start != (line_p)0 && s->b_start != (line_p)0 && Lnrelems(s->b_pred) == 1 - && (bra = last_code(b->b_start, TRUE)) != (line_p)0 && INSTR(bra) == op_bra + && (bra = last_code(b->b_start, true)) != (line_p)0 && INSTR(bra) == op_bra && (s->b_next == (bblock_p)0 || !Lis_elem(s->b_next, s->b_succ) - || ((bra = last_code(s->b_start, TRUE)) != (line_p)0 + || ((bra = last_code(s->b_start, true)) != (line_p)0 && (em_flag[INSTR(bra) - sp_fmnem] & EM_FLO) == FLO_T))) { - l = last_code(s->b_start, FALSE); + l = last_code(s->b_start, false); if (INSTR(l) == ps_end) { if (PREV(l) == (line_p)0) diff --git a/util/ego/ca/ca.c b/util/ego/ca/ca.c index 64d56af48d..ec2bc86e37 100644 --- a/util/ego/ca/ca.c +++ b/util/ego/ca/ca.c @@ -52,7 +52,7 @@ static line_p get_ca_lines(FILE* lf, proc_p* p_out) pp = &head; mp = &headm; headm = (line_p)0; - while (TRUE) + while (true) { l = read_line(p_out); if (feof(curinp)) diff --git a/util/ego/ca/ca_put.c b/util/ego/ca/ca_put.c index dd25181760..930f619938 100644 --- a/util/ego/ca/ca_put.c +++ b/util/ego/ca/ca_put.c @@ -270,7 +270,7 @@ static void cputargs(line_p lnp) cputstr(&ap->a_a.a_con.ac_con); break; default: - assert(FALSE); + assert(false); } ap = ap->a_next; /* Avoid generating extremely long CON or ROM statements */ @@ -344,7 +344,7 @@ static void outoperand(line_p lnp) } break; default: - assert(FALSE); + assert(false); } } diff --git a/util/ego/cf/cf.c b/util/ego/cf/cf.c index 24b6768fa0..55f9c0e5fb 100644 --- a/util/ego/cf/cf.c +++ b/util/ego/cf/cf.c @@ -226,11 +226,11 @@ static bool getbblocks(FILE* fp, short* kind_out, short* n_out, bblock_p* g_out, *n_out = (short)lastbid; /* number of basic blocks */ } - return TRUE; + return true; case INIT: lnp = doread_line(&curproc); if (feof(curinp)) - return FALSE; + return false; if (INSTR(lnp) == ps_pro) { state = AFTERPRO; @@ -391,7 +391,7 @@ static bool add_info(proc_p q, proc_p p) change_p chp, chq; use_p usp, usq; - bool diff = FALSE; + bool diff = false; chp = p->p_change; chq = q->p_change; @@ -405,13 +405,13 @@ static bool add_info(proc_p q, proc_p p) */ if (CALLS_UNKNOWN(p)) { - return FALSE; + return false; /* p already called an unknown procedure */ } else { p->p_flags1 |= PF_CALUNKNOWN; - return TRUE; + return true; } } if (CALLS_UNKNOWN(q)) @@ -422,13 +422,13 @@ static bool add_info(proc_p q, proc_p p) if (!CALLS_UNKNOWN(p)) { p->p_flags1 |= PF_CALUNKNOWN; - diff = TRUE; + diff = true; } } if (IS_CALLED_IN_LOOP(p) && !IS_CALLED_IN_LOOP(q)) { CALLED_IN_LOOP(q); - diff = TRUE; + diff = true; } if (!Cis_subset(chq->c_ext, chp->c_ext)) { @@ -437,7 +437,7 @@ static bool add_info(proc_p q, proc_p p) * changed by q to the c_ext set of p. */ Cjoin(chq->c_ext, &chp->c_ext); - diff = TRUE; + diff = true; } if (CH_CHANGE_INDIR(chq) && !CH_CHANGE_INDIR(chp)) { @@ -445,7 +445,7 @@ static bool add_info(proc_p q, proc_p p) * and p did not (yet). */ chp->c_flags |= CF_INDIR; - diff = TRUE; + diff = true; } if (USE_INDIR(usq) && !USE_INDIR(usp)) { @@ -453,7 +453,7 @@ static bool add_info(proc_p q, proc_p p) * and p dis not (yet). */ usp->u_flags |= UF_INDIR; - diff = TRUE; + diff = true; } if (ENVIRON(q) && !ENVIRON(p)) { @@ -461,7 +461,7 @@ static bool add_info(proc_p q, proc_p p) * environment while p does not (yet). */ p->p_flags1 |= PF_ENVIRON; - diff = TRUE; + diff = true; } return diff; } @@ -474,11 +474,11 @@ static void trans_clos(proc_p head) proc_p p, q; Cindex i; - bool changes = TRUE; + bool changes = true; while (changes) { - changes = FALSE; + changes = false; for (p = head; p != (proc_p)0; p = p->p_next) { if (!BODY_KNOWN(p)) @@ -488,7 +488,7 @@ static void trans_clos(proc_p head) q = pmap[Celem(i)]; if (add_info(q, p)) { - changes = TRUE; + changes = true; } } } @@ -600,6 +600,6 @@ int main(int argc, char* argv[]) { error("cannot open %s", pname_out); } - putptable(fproc, f, TRUE); + putptable(fproc, f, true); exit(0); } diff --git a/util/ego/cf/cf_loop.c b/util/ego/cf/cf_loop.c index 557d97de05..1022f3d51c 100644 --- a/util/ego/cf/cf_loop.c +++ b/util/ego/cf/cf_loop.c @@ -252,9 +252,9 @@ static bool does_exit(bblock_p b, loop_p lp) for (i = Lfirst(b->b_succ); i != (Lindex)0; i = Lnext(i, b->b_succ)) { if (!INSIDE_LOOP(Lelem(i), lp)) - return TRUE; + return true; } - return FALSE; + return false; } static void mark_succ(bblock_p b, loop_p lp) @@ -372,7 +372,7 @@ void loop_detection(proc_p p) * edges; such a loop is called a messy * loop. */ - org->LP_MESSY = TRUE; + org->LP_MESSY = true; Ldeleteset(lp->LP_BLOCKS); oldcflpx(lp->lp_extend); oldloop(lp); diff --git a/util/ego/cj/cj.c b/util/ego/cj/cj.c index c229ae71f8..77cc268b99 100644 --- a/util/ego/cj/cj.c +++ b/util/ego/cj/cj.c @@ -65,9 +65,9 @@ static bool same_instr(line_p l1, line_p l2) /* See if l1 and l2 are the same instruction */ if (l1 == 0 || l2 == 0 || TYPE(l1) != TYPE(l2)) - return FALSE; + return false; if (INSTR(l1) != INSTR(l2)) - return FALSE; + return false; switch (TYPE(l1)) { case OPSHORT: @@ -81,9 +81,9 @@ static bool same_instr(line_p l1, line_p l2) case OPINSTRLAB: return INSTRLAB(l1) == INSTRLAB(l2); case OPNO: - return TRUE; + return true; default: - return FALSE; + return false; } } @@ -125,20 +125,20 @@ static bool is_desirable(line_p text) case op_cal: case op_asp: case op_bra: - return TRUE; + return true; } line_change(l, &ok, &pop, &push); /* printf("instr %d, pop %d, push %d, ok %d\n",INSTR(l),pop,push,ok); */ if (!ok || (stack_diff -= pop) < 0) { - return FALSE; + return false; } else { stack_diff += push; } } - return TRUE; + return true; } static void cp_loops(bblock_p b1, bblock_p b2) @@ -240,11 +240,11 @@ static bool try_tail(bblock_p b1, bblock_p b2) /* printf("try block %d and %d\n",b1->b_id,b2->b_id); */ if (b1->b_start == (line_p)0 || b2->b_start == (line_p)0) - return FALSE; + return false; l1 = last_mnem(b1); l2 = last_mnem(b2); if (l1 == (line_p)0 || l2 == (line_p)0) - return FALSE; + return false; /* printf("consider:\n"); showinstr(l1); showinstr(l2); */ if (INSTR(l1) == op_bra) { @@ -280,10 +280,10 @@ static bool try_tail(bblock_p b1, bblock_p b2) jump_cross(l1, l2, b1, b2); Scj++; } - return TRUE; + return true; } } - return FALSE; + return false; } static bool try_pred(bblock_p b) @@ -307,11 +307,11 @@ static bool try_pred(bblock_p b) if (b1 != b2 && Lnrelems(b2->b_succ) == 1) { if (try_tail(b1, b2)) - return TRUE; + return true; } } } - return FALSE; + return false; } void cj_optimize(void* vp) @@ -325,19 +325,19 @@ void cj_optimize(void* vp) proc_p p = vp; bblock_p b; - bool changes = TRUE; + bool changes = true; if (IS_ENTERED_WITH_GTO(p)) return; while (changes) { - changes = FALSE; + changes = false; b = p->p_start; while (b != (bblock_p)0) { if (try_pred(b)) { - changes = TRUE; + changes = true; } else { diff --git a/util/ego/cs/cs_avail.c b/util/ego/cs/cs_avail.c index 6c47152c6b..37a29666af 100644 --- a/util/ego/cs/cs_avail.c +++ b/util/ego/cs/cs_avail.c @@ -37,9 +37,9 @@ static bool commutative(int instr) case op_mlf: case op_mli: case op_mlu: - return TRUE; + return true; default: - return FALSE; + return false; } } @@ -51,14 +51,14 @@ static bool same_avail(byte kind, avail_p avp1, avail_p avp2) * does not matter. */ if (avp1->av_instr != avp2->av_instr) - return FALSE; + return false; if (avp1->av_size != avp2->av_size) - return FALSE; + return false; switch (kind) { default: - assert(FALSE); + assert(false); break; case EXPENSIVE_LOAD: case UNAIR_OP: @@ -127,7 +127,7 @@ static void copy_avail(int kind, avail_p src, avail_p dst) switch (kind) { default: - assert(FALSE); + assert(false); break; case EXPENSIVE_LOAD: case UNAIR_OP: diff --git a/util/ego/cs/cs_elim.c b/util/ego/cs/cs_elim.c index ddc0ab6933..5b3b5751de 100644 --- a/util/ego/cs/cs_elim.c +++ b/util/ego/cs/cs_elim.c @@ -56,9 +56,9 @@ static bool contained(occur_p ocp1, occur_p ocp2) next = lnp != ocp2->oc_llast ? lnp->l_next : (line_p)0; if (lnp == ocp1->oc_llast) - return TRUE; + return true; } - return FALSE; + return false; } static void delete(occur_p ocp, avail_p start) @@ -179,11 +179,11 @@ static void replace(occur_p ocp, offset tmp, avail_p avp) break; case op_dvi: if (instr == op_rmi) - complete_dv_as_rm(lol, avp, FALSE); + complete_dv_as_rm(lol, avp, false); break; case op_dvu: if (instr == op_rmu) - complete_dv_as_rm(lol, avp, FALSE); + complete_dv_as_rm(lol, avp, false); break; } @@ -255,14 +255,14 @@ static void append(avail_p avp, offset tmp) case op_dvi: if (instr == op_rmi) { - complete_dv_as_rm(lol, avp, TRUE); + complete_dv_as_rm(lol, avp, true); avp->av_found->l_instr = op_dvi; } break; case op_dvu: if (instr == op_rmu) { - complete_dv_as_rm(lol, avp, TRUE); + complete_dv_as_rm(lol, avp, true); avp->av_found->l_instr = op_dvu; } break; diff --git a/util/ego/cs/cs_entity.c b/util/ego/cs/cs_entity.c index 3b91ed9507..470f45a99f 100644 --- a/util/ego/cs/cs_entity.c +++ b/util/ego/cs/cs_entity.c @@ -36,11 +36,11 @@ entity_p find_entity(valnum vn) static bool same_entity(entity_p enp1, entity_p enp2) { if (enp1->en_kind != enp2->en_kind) - return FALSE; + return false; if (enp1->en_size != enp2->en_size) - return FALSE; + return false; if (enp1->en_size == UNKNOWN_SIZE) - return FALSE; + return false; switch (enp1->en_kind) { @@ -66,7 +66,7 @@ static bool same_entity(entity_p enp1, entity_p enp2) return enp1->en_arbase == enp2->en_arbase && enp1->en_index == enp2->en_index && enp1->en_adesc == enp2->en_adesc; default: - return TRUE; + return true; } } diff --git a/util/ego/cs/cs_getent.c b/util/ego/cs/cs_getent.c index 82aa7374ea..6f1972746c 100644 --- a/util/ego/cs/cs_getent.c +++ b/util/ego/cs/cs_getent.c @@ -77,12 +77,12 @@ entity_p getentity(line_p lnp, line_p* l_out) { offset off = off_set(lnp); - en.en_static = FALSE; + en.en_static = false; en.en_size = ps; switch ((int)off == off ? (int)off : 3) { default: - assert(FALSE); + assert(false); break; case 0: en.en_kind = ENLOCBASE; @@ -102,21 +102,21 @@ entity_p getentity(line_p lnp, line_p* l_out) /* Lil and sil refer to two entities. */ if (INSTR(lnp) == op_lil || INSTR(lnp) == op_sil) { - en.en_static = FALSE; + en.en_static = false; en.en_kind = ENLOCAL; en.en_size = ps; /* Local must be a pointer. */ en.en_loc = off_set(lnp); vn = en_enter(&en)->en_vn; } - en.en_static = FALSE; + en.en_static = false; en.en_kind = ENKIND(ip); /* Fill in the size of the entity. */ switch (SIZEINF(ip)) { default: - assert(FALSE); + assert(false); break; case WS1: en.en_size = ws; @@ -165,19 +165,19 @@ entity_p getentity(line_p lnp, line_p* l_out) switch (en.en_kind) { case ENFZER: - en.en_static = TRUE; + en.en_static = true; break; case ENCONST: - en.en_static = TRUE; + en.en_static = true; en.en_val = off_set(lnp); break; case ENALOCAL: - en.en_static = TRUE; + en.en_static = true; case ENLOCAL: en.en_loc = off_set(lnp); break; case ENAEXTERNAL: - en.en_static = TRUE; + en.en_static = true; case ENEXTERNAL: en.en_ext = OBJ(lnp); break; @@ -191,7 +191,7 @@ entity_p getentity(line_p lnp, line_p* l_out) en.en_ind = vn; break; case ENAOFFSETTED: - en.en_static = TRUE; + en.en_static = true; case ENOFFSETTED: Pop(&tk, (offset)ps); *l_out = tk.tk_lfirst; @@ -204,7 +204,7 @@ entity_p getentity(line_p lnp, line_p* l_out) if (en.en_levels == 0) { /* otherwise the program could change it */ - en.en_static = TRUE; + en.en_static = true; } break; case ENPROC: diff --git a/util/ego/cs/cs_kill.c b/util/ego/cs/cs_kill.c index b1b3a65d30..f41006b745 100644 --- a/util/ego/cs/cs_kill.c +++ b/util/ego/cs/cs_kill.c @@ -26,7 +26,7 @@ static valnum base_valno(entity_p enp) switch (enp->en_kind) { default: - assert(FALSE); + assert(false); break; case ENINDIR: return enp->en_ind; @@ -108,7 +108,7 @@ static bool addr_local(entity_p enp) /* Is enp the address of a stack item. */ if (enp == (entity_p)0) - return FALSE; + return false; return enp->en_kind == ENALOCAL || enp->en_kind == ENALOCBASE || enp->en_kind == ENAARGBASE; } @@ -183,7 +183,7 @@ static bool loc_overlap(entity_p enp1, entity_p enp2) enp2 = tmp; } if (enp1->en_loc < 0 && enp2->en_loc >= 0) - return FALSE; /* Locals and parameters do not overlap. */ + return false; /* Locals and parameters do not overlap. */ else return enp1->en_size == UNKNOWN_SIZE || enp1->en_loc + enp1->en_size > enp2->en_loc; } @@ -273,13 +273,13 @@ void kill_direct(entity_p enp) switch (enp->en_kind) { default: - assert(FALSE); + assert(false); break; case ENEXTERNAL: - kill_external(enp->en_ext, FALSE); + kill_external(enp->en_ext, false); break; case ENLOCAL: - kill_local(enp, FALSE); + kill_local(enp, false); break; case ENIGNMASK: kill_sim(); @@ -310,13 +310,13 @@ void kill_indir(entity_p enp) { case ENAEXTERNAL: /* An indirect store into global data. */ - kill_external(p->en_ext, TRUE); + kill_external(p->en_ext, true); break; case ENALOCAL: case ENALOCBASE: case ENAARGBASE: /* An indirect store into stack data. */ - kill_local(p, TRUE); + kill_local(p, true); break; } } @@ -363,7 +363,7 @@ static void kill_globset(cset s) OUTTRACE("kill globset", 0); for (i = Cfirst(s); i != (Cindex)0; i = Cnext(i, s)) { - kill_external(omap[Celem(i)], FALSE); + kill_external(omap[Celem(i)], false); } } diff --git a/util/ego/cs/cs_partit.c b/util/ego/cs/cs_partit.c index acfef9f5bd..14159b4232 100644 --- a/util/ego/cs/cs_partit.c +++ b/util/ego/cs/cs_partit.c @@ -742,9 +742,9 @@ bool stack_group(int instr) case BINAIR_OP: case TERNAIR_OP: case REMAINDER: - return TRUE; + return true; default: - return FALSE; + return false; } } @@ -782,7 +782,7 @@ offset op11size(line_p lnp) case PS: return ps; default: - assert(FALSE); + assert(false); } UNREACHABLE_CODE; } @@ -798,7 +798,7 @@ offset op12size(line_p lnp) case PS: return ps; default: - assert(FALSE); + assert(false); } UNREACHABLE_CODE; } @@ -814,7 +814,7 @@ offset op22size(line_p lnp) case PS: return ps; default: - assert(FALSE); + assert(false); } UNREACHABLE_CODE; } @@ -886,7 +886,7 @@ offset avsize(line_p lnp) else return UNKNOWN_SIZE; default: - assert(FALSE); + assert(false); break; } UNREACHABLE_CODE; @@ -903,7 +903,7 @@ int regtype(byte instr) case FLT: return reg_float; default: - assert(FALSE); + assert(false); } UNREACHABLE_CODE; } diff --git a/util/ego/cs/cs_profit.c b/util/ego/cs/cs_profit.c index 6967587342..bac1bf1eec 100644 --- a/util/ego/cs/cs_profit.c +++ b/util/ego/cs/cs_profit.c @@ -132,10 +132,10 @@ bool may_become_aar(avail_p avp) sz = array_elemsize(avp->av_othird); if (sz == UNKNOWN_SIZE) - return FALSE; + return false; if (time_space_ratio < 50) return sz <= AR_limit; - return TRUE; + return true; } bool may_become_dv(void) @@ -162,7 +162,7 @@ static bool gains(avail_p avp) * heuristics with some user-supplied stuff. */ if (Cis_elem(avp->av_instr & BMASK, forbidden)) - return FALSE; + return false; if (avp->av_instr == (byte)op_lxa || avp->av_instr == (byte)op_lxl) return off_set(avp->av_found) >= LX_threshold; @@ -180,7 +180,7 @@ static bool gains(avail_p avp) if (Cis_elem(avp->av_instr & BMASK, cheaps)) return avp->av_saveloc != (entity_p)0; - return TRUE; + return true; } static bool okay_lines(avail_p avp, occur_p ocp) @@ -195,15 +195,15 @@ static bool okay_lines(avail_p avp, occur_p ocp) next = lnp != ocp->oc_llast ? lnp->l_next : (line_p)0; if (INSTR(lnp) < sp_fmnem || INSTR(lnp) > sp_lmnem) - return FALSE; + return false; if (!stack_group(INSTR(lnp))) { /* Check for SAR-instruction. */ if (INSTR(lnp) != op_sar || next != (line_p)0) - return FALSE; + return false; } } - return TRUE; + return true; } bool desirable(avail_p avp) @@ -214,7 +214,7 @@ bool desirable(avail_p avp) { OUTTRACE("no gain", 0); SHOWAVAIL(avp); - return FALSE; + return false; } /* Walk through the occurrences to see whether it is okay to diff --git a/util/ego/cs/cs_vnm.c b/util/ego/cs/cs_vnm.c index e9ba079b9c..bffe1efd88 100644 --- a/util/ego/cs/cs_vnm.c +++ b/util/ego/cs/cs_vnm.c @@ -175,7 +175,7 @@ static void fiddle_stack(line_p lnp) switch (INSTR(lnp)) { default: - assert(FALSE); + assert(false); break; case op_lor: dummy.tk_vn = newvalnum(); @@ -293,7 +293,7 @@ static void hopeless(int instr) switch (instr) { default: - assert(FALSE); + assert(false); break; case op_mon: case op_str: @@ -385,7 +385,7 @@ void vnm(bblock_p bp) fiddle_stack(lnp); break; default: - assert(FALSE); + assert(false); break; } } diff --git a/util/ego/ic/ic.c b/util/ego/ic/ic.c index 8e131c39ad..52f2028f97 100644 --- a/util/ego/ic/ic.c +++ b/util/ego/ic/ic.c @@ -119,7 +119,7 @@ int main(int argc, char* argv[]) dfile = openfile(dname_out, "wb"); putdtable(fdblock, dfile); pfile = openfile(pname_out, "wb"); - putptable(fproc, pfile, FALSE); + putptable(fproc, pfile, false); exit(0); } @@ -163,7 +163,7 @@ static void process_lines(FILE* fout) * when we come accross its defining occurrence. */ - eof = FALSE; + eof = false; firstline = (line_p)0; lastline = (line_p)0; while (!eof) @@ -186,7 +186,7 @@ static void process_lines(FILE* fout) lastline = lnp; break; case EOFILE: - eof = TRUE; + eof = true; fragm_type = DUNKNOWN; if (firstline != (line_p)0) { @@ -391,7 +391,7 @@ static line_p readoperand(short instr) VP(PROC(lnp)); break; default: - assert(FALSE); + assert(false); } return lnp; } @@ -578,7 +578,7 @@ static line_p inpseudo(short n) } return lnp; default: - assert(FALSE); + assert(false); } UNREACHABLE_CODE; } diff --git a/util/ego/ic/ic_aux.c b/util/ego/ic/ic_aux.c index 8cbe9bc069..5a3185df0e 100644 --- a/util/ego/ic/ic_aux.c +++ b/util/ego/ic/ic_aux.c @@ -87,7 +87,7 @@ static offset argsize(arg_p arg) case ARGFCN: return arg->a_a.a_con.ac_length; default: - assert(FALSE); + assert(false); } UNREACHABLE_CODE; } @@ -118,7 +118,7 @@ static offset blocksize(byte pseudo, arg_p args) } return sum; default: - assert(FALSE); + assert(false); } UNREACHABLE_CODE; } @@ -181,7 +181,7 @@ void dblockdef(dblock_p db, int n, line_p lnp) m = DROM; break; default: - assert(FALSE); + assert(false); } db->d_pseudo = m; db->d_size = blocksize(m, ARG(lnp)); @@ -272,7 +272,7 @@ line_p arglist(int n) lnp = newline(OPLIST); app = &ARG(lnp); - moretocome = TRUE; + moretocome = true; do { switch (table2()) @@ -330,10 +330,10 @@ line_p arglist(int n) app = &ap->a_next; break; case sp_cend: - moretocome = FALSE; + moretocome = false; } if (n && (--n) == 0) - moretocome = FALSE; + moretocome = false; } while (moretocome); return (lnp); } diff --git a/util/ego/ic/ic_aux.h b/util/ego/ic/ic_aux.h index 8a4463f627..038dfeb100 100644 --- a/util/ego/ic/ic_aux.h +++ b/util/ego/ic/ic_aux.h @@ -31,7 +31,7 @@ line_p arglist(int m); /* * then terminated by a cend symbol. */ bool is_datalabel(line_p l); /* - * TRUE if l is a data label defining + * true if l is a data label defining * occurrence (i.e. its l_instr * field is ps_sym). */ diff --git a/util/ego/ic/ic_lib.c b/util/ego/ic/ic_lib.c index f9ab285bc6..178795943a 100644 --- a/util/ego/ic/ic_lib.c +++ b/util/ego/ic/ic_lib.c @@ -70,11 +70,11 @@ static bool proc_wanted(const char* name) if ((p = proclookup(name, IMPORTING)) != (proc_p)0 && !(p->p_flags1 & PF_BODYSEEN)) { - return TRUE; + return true; } else { - return FALSE; + return false; } } @@ -89,11 +89,11 @@ static bool data_wanted(const char* name) if ((db = symlookup(name, IMPORTING)) != (dblock_p)0 && db->d_pseudo == DUNKNOWN) { - return TRUE; + return true; } else { - return FALSE; + return false; } } @@ -103,7 +103,7 @@ static bool wanted_names(void) * appearing in a 'MES ms_ext' pseudo. Those are * the names of entities that are imported by * a library module. - * If any of them is wanted, return TRUE. + * If any of them is wanted, return true. * A name is wanted if it is the name of a procedure * or data block for which applied occurrences but * no defining occurrence has been met. @@ -116,7 +116,7 @@ static bool wanted_names(void) case DLBX: if (data_wanted(string)) { - return TRUE; + return true; } /* A data entity with the name * string is available. @@ -125,11 +125,11 @@ static bool wanted_names(void) case sp_pnam: if (proc_wanted(string)) { - return TRUE; + return true; } break; case sp_cend: - return FALSE; + return false; default: error("wrong argument of MES %d", ms_ext); } diff --git a/util/ego/il/il.c b/util/ego/il/il.c index db569120a2..1cbe7d2c36 100644 --- a/util/ego/il/il.c +++ b/util/ego/il/il.c @@ -81,10 +81,10 @@ static void pass1(const char* lnam, const char* bnam, const char* cnam) /* use information from the procedure table to * see which calls certainly cannot be expanded. */ - while (TRUE) + while (true) { laddr = ftell(f); - if (!getunit(gf, f, &kind, &g, &l, &curproc, TRUE)) + if (!getunit(gf, f, &kind, &g, &l, &curproc, true)) break; /* Read the control flow graph and EM text of * one procedure and analyze it. @@ -181,7 +181,7 @@ static void pass2(const char* cnam, long space) void pass3(const char* lnam, const char* lnam2) { - bool verbose = TRUE; + bool verbose = true; FILE *lfile, *lfilerand, *lfile2, *sfile; call_p c, next; line_p l, startscan, cal; @@ -347,7 +347,7 @@ int main(int argc, char* argv[]) il_cleanptab(fproc); /* remove extended data structures */ putdtable(fdblock, f); f = openfile(files->pname_out, "wb"); - putptable(fproc, f, FALSE); + putptable(fproc, f, false); report("inline substitutions", Ssubst); #ifdef VERBOSE if (verbose_flag) diff --git a/util/ego/il/il.h b/util/ego/il/il.h index 47f06df363..102bb211a6 100644 --- a/util/ego/il/il.h +++ b/util/ego/il/il.h @@ -42,7 +42,7 @@ struct actual line_p ac_exp; /* copy of EM text */ /* 0 for actuals that are not inline */ offset ac_size; /* number of bytes of parameter */ - bool ac_inl; /* TRUE if it may be expanded in line */ + bool ac_inl; /* true if it may be expanded in line */ actual_p ac_next; /* link */ }; diff --git a/util/ego/il/il1_anal.c b/util/ego/il/il1_anal.c index 325ca20a05..460537d78e 100644 --- a/util/ego/il/il1_anal.c +++ b/util/ego/il/il1_anal.c @@ -35,7 +35,7 @@ /* #define CALLS_UNKNOWN(p) (p->p_flags1 & (byte) PF_CALUNKNOWN) */ -#define CALLS_UNKNOWN(p) (FALSE) +#define CALLS_UNKNOWN(p) (false) void apriori(proc_p proctab) { @@ -156,14 +156,14 @@ void anal_proc(proc_p p, FILE* cf, FILE* ccf) */ bblock_p b; - bool fallthrough = TRUE; + bool fallthrough = true; cchead = (calcnt_p)0; for (b = p->p_start; b != (bblock_p)0; b = b->b_next) { if (RETURN_BLOCK(b) && !LAST_BLOCK(b)) { - fallthrough = FALSE; + fallthrough = false; /* p contains a RET instruction somewhere * in the middle of its code. */ diff --git a/util/ego/il/il1_aux.c b/util/ego/il/il1_aux.c index d5cd58604d..07022e0a42 100644 --- a/util/ego/il/il1_aux.c +++ b/util/ego/il/il1_aux.c @@ -45,10 +45,10 @@ static bool is_reg(offset off, int s) arg = ((line_p)Lelem(i))->l_a.la_arg->a_next; if (arg->a_a.a_offset == off && arg->a_next->a_a.a_offset == s) { - return TRUE; + return true; } } - return FALSE; + return false; } void rem_actuals(actual_p acts) @@ -130,7 +130,7 @@ bool par_overlap(offset off1, int t1, offset off2, int t2) } else { - return TRUE; + return true; } } } diff --git a/util/ego/il/il2_aux.c b/util/ego/il/il2_aux.c index 8db450f080..aa040039e0 100644 --- a/util/ego/il/il2_aux.c +++ b/util/ego/il/il2_aux.c @@ -28,8 +28,8 @@ #define OFTEN_USED(f) ((f->f_flags & FF_OFTENUSED) == FF_OFTENUSED) #define CHANGE_EXT(p) (Cnrelems(p->p_change->c_ext) > 0) -#define NOT_INLINE(a) (a->ac_inl = FALSE) -#define INLINE(a) (a->ac_inl = TRUE) +#define NOT_INLINE(a) (a->ac_inl = false) +#define INLINE(a) (a->ac_inl = true) #define CHANGED(p) p->p_flags2 |= PF_CHANGED #define IS_CHANGED(p) (p->p_flags2 & PF_CHANGED) @@ -49,12 +49,12 @@ static bool match_pars(formal_p fm, actual_p act) { if (fm == (formal_p)0 || tsize(fm->f_type) != act->ac_size) { - return FALSE; + return false; } act = act->ac_next; fm = fm->f_next; } - return (fm == (formal_p)0 ? TRUE : FALSE); + return (fm == (formal_p)0 ? true : false); } static bool change_act(proc_p p, actual_p act) @@ -78,25 +78,25 @@ static bool change_act(proc_p p, actual_p act) case op_loi: case op_los: case op_ldf: - return TRUE; + return true; /* assume worst case */ case op_lol: case op_ldl: if (CHANGE_INDIR(p)) { - return TRUE; + return true; } break; case op_loe: case op_lde: if (CHANGE_INDIR(p) || CHANGE_EXT(p)) { - return TRUE; + return true; } break; } } - return FALSE; + return false; } static bool is_simple(line_p expr) @@ -116,10 +116,10 @@ static bool is_simple(line_p expr) case op_ldl: case op_loe: case op_lde: - return TRUE; + return true; } } - return FALSE; + return false; } static bool too_expensive(formal_p fm, actual_p act) @@ -146,14 +146,14 @@ bool anal_params(call_p c) p = c->cl_proc; /* the called procedure */ if (!match_pars(p->P_FORMALS, c->cl_actuals)) - return FALSE; + return false; if (!INLINE_PARS(p)) { for (act = c->cl_actuals; act != (actual_p)0; act = act->ac_next) { NOT_INLINE(act); } - return TRUE; /* "# of inline pars." field in cl_flags remains 0 */ + return true; /* "# of inline pars." field in cl_flags remains 0 */ } for (act = c->cl_actuals, form = p->P_FORMALS; act != (actual_p)0; act = act->ac_next, form = form->f_next) @@ -171,7 +171,7 @@ bool anal_params(call_p c) if (inlpars > 15) inlpars = 15; /* We've only got 4 bits! */ c->cl_flags |= inlpars; /* number of inline parameters */ - return TRUE; + return true; } static short space_saved(call_p c) @@ -325,12 +325,12 @@ static bool is_dispensable(proc_p callee, FILE* ccf) #ifdef VERBOSE Spremoved++; #endif - return TRUE; + return true; } else { adjust_counts(callee, ccf); - return FALSE; + return false; } } @@ -376,7 +376,7 @@ static call_p find_origin(call_p c) if (x->cl_id == c->cl_id) return x; } - assert(FALSE); + assert(false); UNREACHABLE_CODE; } @@ -729,7 +729,7 @@ static void Sstatist(call_p list, long space) else if (c->cl_ratio == 0) Szeroratio++; else - assert(FALSE); + assert(false); } } } diff --git a/util/ego/il/il2_aux.h b/util/ego/il/il2_aux.h index 17b5540b58..97309ba9c7 100644 --- a/util/ego/il/il2_aux.h +++ b/util/ego/il/il2_aux.h @@ -7,7 +7,7 @@ bool anal_params(call_p c); /* * See which parameters of the call * may be expanded in line. * If the formals and actuals do not - * match, return FALSE + * match, return false */ void assign_ratio(call_p c); /* * Assigna ratio number to the call, diff --git a/util/ego/il/il3_change.c b/util/ego/il/il3_change.c index fb6f3cbf4e..bd643c36be 100644 --- a/util/ego/il/il3_change.c +++ b/util/ego/il/il3_change.c @@ -220,7 +220,7 @@ static void act_info(offset off, actual_p acts, offset ab_off, actual_p* act_out } sum += act->ac_size; } - assert(FALSE); + assert(false); } static void store_off(offset off, line_p l) diff --git a/util/ego/il/il_aux.c b/util/ego/il/il_aux.c index 14b4f73064..8e0bc3e50e 100644 --- a/util/ego/il/il_aux.c +++ b/util/ego/il/il_aux.c @@ -40,7 +40,7 @@ int tsize(int type) case POINTER: return ps; default: - assert(FALSE); + assert(false); } UNREACHABLE_CODE; } @@ -75,7 +75,7 @@ line_p duplicate(line_p lnp) PROC(l) = PROC(lnp); break; default: - assert(FALSE); /* cannot copy pseudo */ + assert(false); /* cannot copy pseudo */ } return l; } @@ -218,7 +218,7 @@ call_p getcall(FILE* cf) m = getshort(); act->ac_size = getoff(); act->ac_inl = getbyte(); - act->ac_exp = getlines(cf, m, &voided, FALSE); + act->ac_exp = getlines(cf, m, &voided, false); *app = act; app = &act->ac_next; } diff --git a/util/ego/lv/lv.c b/util/ego/lv/lv.c index 7cb41f9e42..4c53883272 100644 --- a/util/ego/lv/lv.c +++ b/util/ego/lv/lv.c @@ -37,7 +37,7 @@ short nrvars; static int Slv; -static bool mesgflag = FALSE; /* Suppress generation of live/dead info */ +static bool mesgflag = false; /* Suppress generation of live/dead info */ static void app_block(line_p l, bblock_p b); @@ -77,9 +77,9 @@ static bool is_dir_use(line_p l) case op_loe: case op_lol: case op_sil: - return TRUE; + return true; default: - return FALSE; + return false; } UNREACHABLE_CODE; } @@ -103,9 +103,9 @@ static bool is_indir_use(line_p l) case op_loi: case op_los: case op_mon: - return TRUE; + return true; default: - return FALSE; + return false; } UNREACHABLE_CODE; } @@ -122,9 +122,9 @@ static bool is_def(line_p l) case op_stl: case op_zre: case op_zrl: - return TRUE; + return true; default: - return FALSE; + return false; } UNREACHABLE_CODE; } @@ -226,7 +226,7 @@ static void solve_lv(proc_p p) bblock_p b; cset newout = Cempty_set(nrvars); - bool change = TRUE; + bool change = true; for (b = p->p_start; b != (bblock_p)0; b = b->b_next) { @@ -236,13 +236,13 @@ static void solve_lv(proc_p p) } while (change) { - change = FALSE; + change = false; for (b = p->p_start; b != (bblock_p)0; b = b->b_next) { unite_ins(b->b_succ, &newout); if (!Cequal(newout, L_OUT(b))) { - change = TRUE; + change = true; Ccopy_set(newout, &L_OUT(b)); Ccopy_set(newout, &L_IN(b)); Csubtract(DEF(b), &L_IN(b)); @@ -378,7 +378,7 @@ static void definition(line_p l, bool* useless_out, short* v_out, bool mesgflag) bool found; local_p loc; - *useless_out = FALSE; + *useless_out = false; var_nr(l, &v, &found); if (found && IS_LOCAL(v)) { @@ -412,7 +412,7 @@ static void definition(line_p l, bool* useless_out, short* v_out, bool mesgflag) { appnd_line(make_mesg(ego_dead, loc), l); } - *useless_out = TRUE; + *useless_out = true; } } } @@ -590,7 +590,7 @@ void lv_flags(void* vp) switch (*p) { case 'N': - mesgflag = TRUE; + mesgflag = true; break; } } diff --git a/util/ego/ra/ra_allocl.c b/util/ego/ra/ra_allocl.c index 0f4c5002d2..5586c16cf4 100644 --- a/util/ego/ra/ra_allocl.c +++ b/util/ego/ra/ra_allocl.c @@ -216,11 +216,11 @@ static bool updates_needed(loop_p lp, item_p item) s = (bblock_p)Lelem(si); if (!Lis_elem(s, lp->LP_BLOCKS) && MUST_UPDATE(item, s)) { - return TRUE; + return true; } } } - return FALSE; + return false; } static short countuses(lset usage, bblock_p b) @@ -261,7 +261,7 @@ static void allocs_of_item( whole_lifetime(item, &ini, <); wholeproc = cons_alloc( item, lt, Lnrelems(item->it_usage), Lnrelems(item->it_usage), proc_inits(p, item, ini), - (alloc_p)0, FALSE, TRUE); + (alloc_p)0, false, true); insert_alloc(wholeproc, alloc_list_p); for (li = Lfirst(loops); li != (Lindex)0; li = Lnext(li, loops)) { @@ -290,8 +290,8 @@ static void allocs_of_item( } insert_alloc( cons_alloc( - item, lt, susecount, dusecount, loop_inits(lp, item, header), wholeproc, TRUE, - FALSE), + item, lt, susecount, dusecount, loop_inits(lp, item, header), wholeproc, true, + false), alloc_list_p); } else if (sloopcnt[lp->lp_id] != 0) diff --git a/util/ego/ra/ra_interv.c b/util/ego/ra/ra_interv.c index 0f14971b84..7c931f297c 100644 --- a/util/ego/ra/ra_interv.c +++ b/util/ego/ra/ra_interv.c @@ -197,10 +197,10 @@ bool not_disjoint(interv_p list1, interv_p list2) } else { - return TRUE; /* not disjoint */ + return true; /* not disjoint */ } } - return FALSE; /* disjoint */ + return false; /* disjoint */ } bool contains(short t, interv_p timespan) @@ -212,7 +212,7 @@ bool contains(short t, interv_p timespan) if (t <= iv->i_stop) return (t >= iv->i_start); } - return FALSE; + return false; } interv_p copy_timespan(interv_p list) diff --git a/util/ego/ra/ra_items.c b/util/ego/ra/ra_items.c index e1468ad6d8..e16950b443 100644 --- a/util/ego/ra/ra_items.c +++ b/util/ego/ra/ra_items.c @@ -79,7 +79,7 @@ item_p item_of(offset off, item_p items[]) void fill_item(item_p item, line_p l) { item->it_type = item_type(l); - item->it_desirable = TRUE; + item->it_desirable = true; switch (item->it_type) { case GLOBL_ADDR: @@ -108,10 +108,10 @@ static bool desirable(line_p l) case op_aar: case op_lar: case op_sar: - return FALSE; + return false; } } - return TRUE; + return true; } static int cmp_items(item_p a, item_p b) @@ -184,7 +184,7 @@ static short reg_type(item_p item) case DCONST: return reg_any; default: - assert(FALSE); + assert(false); } UNREACHABLE_CODE; } @@ -207,7 +207,7 @@ static short item_size(item_p item) case DCONST: return 2 * ws; /* 2 * word size */ default: - assert(FALSE); + assert(false); } UNREACHABLE_CODE; } @@ -248,7 +248,7 @@ static void add_item(item_p item, time_p t, item_p items[]) /* found */ if (!item->it_desirable) { - x->it_desirable = FALSE; + x->it_desirable = false; } Ladd(t, &x->it_usage); return; /* done */ @@ -280,7 +280,7 @@ static void add_usage(line_p l, bblock_p b, item_p items[]) fill_item(&thisitem, l); /* fill in some fields */ if (!desirable(l)) { - thisitem.it_desirable = FALSE; /* don't put item in reg. */ + thisitem.it_desirable = false; /* don't put item in reg. */ } if (thisitem.it_type == LOCALVAR && !is_regvar(thisitem.i_t.it_off)) { diff --git a/util/ego/ra/ra_pack.c b/util/ego/ra/ra_pack.c index 2a542da985..0f7b3a189a 100644 --- a/util/ego/ra/ra_pack.c +++ b/util/ego/ra/ra_pack.c @@ -58,7 +58,7 @@ static bool fits_in(alloc_p a, alloc_p b, bool* cont_item) * allocation. */ - *cont_item = FALSE; + *cont_item = false; if (a->al_regtype == b->al_regtype) { while (b != (alloc_p)0) @@ -68,7 +68,7 @@ static bool fits_in(alloc_p a, alloc_p b, bool* cont_item) b = b->al_mates; if (b != (alloc_p)0 && a->al_item == b->al_item) { - *cont_item = TRUE; + *cont_item = true; } } } @@ -253,7 +253,7 @@ static void account_regsave(alloc_p packed, alloc_p unpacked) initregcount(); checked = make_dummy(); - while (TRUE) + while (true) { best_cumprofits(packed, &x, &prev); if (x == (alloc_p)0) @@ -292,7 +292,7 @@ static bool in_single_reg(item_p item, alloc_p packed) */ alloc_p x, m; - bool seen = FALSE; + bool seen = false; for (x = packed->al_next; x != (alloc_p)0; x = x->al_next) { @@ -301,13 +301,13 @@ static bool in_single_reg(item_p item, alloc_p packed) if (m->al_item == item) { if (seen) - return FALSE; - seen = TRUE; + return false; + seen = true; break; } } } - return TRUE; + return true; } static alloc_p find_prev(alloc_p alloc, alloc_p list) diff --git a/util/ego/ra/ra_profits.c b/util/ego/ra/ra_profits.c index 112ee24929..711cd9fc26 100644 --- a/util/ego/ra/ra_profits.c +++ b/util/ego/ra/ra_profits.c @@ -23,7 +23,7 @@ static bool test_cond(short cond, offset val) switch (cond) { case DEFAULT: - return TRUE; + return true; case FITBYTE: return val >= -128 && val < 128; case IN_0_63: @@ -96,8 +96,8 @@ static void allocscore( break; } } - *time_out = (m == (cond_p)0 ? -1 : map_value(m, off, TRUE)); - *space_out = (m == (cond_p)0 ? -1 : map_value(m, off, FALSE)); + *time_out = (m == (cond_p)0 ? -1 : map_value(m, off, true)); + *space_out = (m == (cond_p)0 ? -1 : map_value(m, off, false)); /* fprintf(stderr,"itemtyp = %d, localtyp = %d off = %ld\n",itemtyp,localtyp,off); fprintf(stderr,"ALLOCSCORE = (%d,%d)\n",*time_out,*space_out); @@ -132,8 +132,8 @@ opening_cost(short itemtyp, short localtyp, offset off, short* time_out, short* m = oproctab; break; } - *time_out = (m == (cond_p)0 ? 1000 : map_value(m, off, TRUE)); - *space_out = (m == (cond_p)0 ? 1000 : map_value(m, off, FALSE)); + *time_out = (m == (cond_p)0 ? 1000 : map_value(m, off, true)); + *space_out = (m == (cond_p)0 ? 1000 : map_value(m, off, false)); /* fprintf(stderr,"itemtyp = %d, localtyp = %d off = %ld\n",itemtyp,localtyp,off); fprintf(stderr,"OPEN_COST = (%d,%d)\n",*time_out,*space_out); @@ -150,8 +150,8 @@ void regsave_cost(short regs[], short* time_out, short* space_out) short n = regs[reg_any] + regs[reg_pointer] + regs[reg_float]; /* #registers */ - *time_out = index_value(regsav_cost, n, TRUE); - *space_out = index_value(regsav_cost, n, FALSE); + *time_out = index_value(regsav_cost, n, true); + *space_out = index_value(regsav_cost, n, false); /* fprintf(stderr,"REGSAVE COST, n=%d, (%d,%d)\n",n,*time_out,*space_out); */ diff --git a/util/ego/ra/ra_xform.c b/util/ego/ra/ra_xform.c index ef7c568be9..ca626ff5cd 100644 --- a/util/ego/ra/ra_xform.c +++ b/util/ego/ra/ra_xform.c @@ -125,7 +125,7 @@ void init_replacements(short psize, short wsize) */ break; default: - assert(FALSE); + assert(false); } } } @@ -485,11 +485,11 @@ bool always_in_reg(offset off, alloc_p allocs, short* size_out) if (m->al_iswholeproc && item->it_type == LOCALVAR && item->i_t.it_off == off) { *size_out = item->it_size; - return TRUE; + return true; } } } - return FALSE; + return false; } void rem_locals(proc_p p, alloc_p allocs) diff --git a/util/ego/share/cset.c b/util/ego/share/cset.c index 99bc0c1b2b..1d83fb93f6 100644 --- a/util/ego/share/cset.c +++ b/util/ego/share/cset.c @@ -50,11 +50,11 @@ bool Cis_elem(Celem_t x, cset s) mask = (1 << MODWL(x - 1)); if ((s->v_bits[n] & mask) == 0) { - return FALSE; + return false; } else { - return TRUE; + return true; } } @@ -176,15 +176,15 @@ bool Cis_subset(cset s1, cset s2) assert(s1->v_size == s2->v_size); if (s1->v_size == 0) - return TRUE; + return true; for (i = 0; i <= DIVWL(s1->v_size - 1); i++) { if ((s1->v_bits[i] & ~(s2->v_bits[i])) != 0) { - return FALSE; + return false; } } - return TRUE; + return true; } void Cclear_set(cset* s_p) @@ -234,9 +234,9 @@ bool Cequal(cset s1, cset s2) for (i = 0; i <= DIVWL(s1->v_size - 1); i++) { if (s1->v_bits[i] != s2->v_bits[i]) - return FALSE; + return false; } - return TRUE; + return true; } short Cnrelems(cset s) diff --git a/util/ego/share/debug.c b/util/ego/share/debug.c index 804de31503..dab3378162 100644 --- a/util/ego/share/debug.c +++ b/util/ego/share/debug.c @@ -19,7 +19,7 @@ #include "global.h" int linecount; /* # lines in this file */ -bool verbose_flag = FALSE; /* generate verbose output ? */ +bool verbose_flag = false; /* generate verbose output ? */ /* VARARGS1 */ NORETURN void error(const char* s, ...) diff --git a/util/ego/share/get.c b/util/ego/share/get.c index a52a3267c8..5d4012fa3b 100644 --- a/util/ego/share/get.c +++ b/util/ego/share/get.c @@ -250,7 +250,7 @@ dblock_p getdtable(const char* dname) /* total number of objects */ omap = (obj_p*)newmap(olength); /* allocate omap table */ - while (TRUE) + while (true) { n = getmark(); if (feof(curinp)) @@ -285,7 +285,7 @@ dblock_p getdtable(const char* dname) arg->a_a.a_offset = getoff(); break; default: - assert(FALSE); + assert(false); } } OUTTRACE("have read data table, %d objects", olength); @@ -360,7 +360,7 @@ static arg_p readargs(void) argstring(getshort(), &arg->a_a.a_con.ac_con); break; default: - assert(FALSE); + assert(false); } } } @@ -509,14 +509,14 @@ bool getunit( curinp = gf; blength = getshort(); /* # basic blocks in this procedure */ if (feof(curinp)) - return FALSE; + return false; if (blength == 0) { /* data unit */ *kind_out = LDATA; n = getshort(); *l_out = getlines(lf, n, p_out, collect_mes); - return TRUE; + return true; } *kind_out = LTEXT; bmap = (bblock_p*)newmap(blength); /* maps block_id on bblock_p */ @@ -552,5 +552,5 @@ bool getunit( Ladd((Lelem_t)lp, &curproc->p_loops); } *g_out = head; - return TRUE; + return true; } diff --git a/util/ego/share/get.h b/util/ego/share/get.h index 9aeb62645b..861f4d5dc7 100644 --- a/util/ego/share/get.h +++ b/util/ego/share/get.h @@ -56,7 +56,7 @@ bool getunit( /* * Read the control flow graph * (from file gf) and the EM text - * (from lf). If collect_mes is TRUE, + * (from lf). If collect_mes is true, * all register messages will be * collected and put in the global * variable 'mesregs'. The proc read diff --git a/util/ego/share/go.c b/util/ego/share/go.c index 2fdf8468e6..2e055541e0 100644 --- a/util/ego/share/go.c +++ b/util/ego/share/go.c @@ -22,9 +22,9 @@ #include "go.h" #include "files.h" -static bool report_flag = FALSE; /* report #optimizations found? */ +static bool report_flag = false; /* report #optimizations found? */ #ifdef DEBUG -static bool core_flag = FALSE; /* report core usage? */ +static bool core_flag = false; /* report core usage? */ #endif static void mach_init(char* machfile, void (*phase_machinit)(void*)) @@ -59,7 +59,7 @@ void go( short kind; int i; char* p; - bool time_opt = TRUE; + bool time_opt = true; linecount = 0; opterr = 0; @@ -72,11 +72,11 @@ void go( switch (opt) { case 'S': - time_opt = FALSE; + time_opt = false; break; case 'T': - time_opt = TRUE; + time_opt = true; break; case 'M': @@ -85,16 +85,16 @@ void go( case 'C': #ifdef DEBUG - core_flag = TRUE; + core_flag = true; #endif break; case 'Q': - report_flag = TRUE; + report_flag = true; break; case 'V': - verbose_flag = TRUE; + verbose_flag = true; break; case '?': @@ -113,7 +113,7 @@ void go( f2 = openfile(files->lname_out, "wb"); gf2 = openfile(files->bname_out, "wb"); mesregs = Lempty_set(); - while (getunit(gf, f, &kind, &g, &l, &curproc, TRUE)) + while (getunit(gf, f, &kind, &g, &l, &curproc, true)) { /* Read the control flow graph and EM text of * one procedure and optimize it. @@ -143,7 +143,7 @@ void go( putdtable(fdblock, f); /* fclose(f); done by putdtable */ f = openfile(files->pname_out, "wb"); - putptable(fproc, f, TRUE); + putptable(fproc, f, true); /* fclose(f); done by putptable */ core_usage(); } diff --git a/util/ego/share/locals.c b/util/ego/share/locals.c index 7ee72c7b43..351eac08fe 100644 --- a/util/ego/share/locals.c +++ b/util/ego/share/locals.c @@ -78,7 +78,7 @@ static void check_message(line_p l, local_p* locs) arg = ARG(l); if (aoff(arg, 0) == ms_reg && arg->a_next != (arg_p)0) { - localvar(aoff(arg, 1), (short)aoff(arg, 2), locs, TRUE, aoff(arg, 4)); + localvar(aoff(arg, 1), (short)aoff(arg, 2), locs, true, aoff(arg, 4)); } } @@ -114,7 +114,7 @@ static void check_local_use(line_p l, local_p* locs) /* volatile */ return; } - localvar(off_set(l), sz, locs, FALSE, (offset)0); + localvar(off_set(l), sz, locs, false, (offset)0); } void make_localtab(proc_p p) @@ -200,12 +200,12 @@ void find_local(offset off, short* nr_out, bool* found_out) break; if (locals[v]->lc_off == off) { - *found_out = TRUE; + *found_out = true; *nr_out = v; return; } } - *found_out = FALSE; + *found_out = false; } void var_nr(line_p l, short* nr_out, bool* found_out) @@ -224,12 +224,12 @@ void var_nr(line_p l, short* nr_out, bool* found_out) if (OBJ(l)->o_globnr == 0) { /* We don't maintain ud-info for this var */ - *found_out = FALSE; + *found_out = false; } else { *nr_out = GLOB_TO_VARNR(OBJ(l)->o_globnr); - *found_out = TRUE; + *found_out = true; } return; case OPSHORT: @@ -239,7 +239,7 @@ void var_nr(line_p l, short* nr_out, bool* found_out) off = OFFSET(l); break; default: - assert(FALSE); + assert(false); } /* Its's a local variable */ find_local(off, &nr, found_out); diff --git a/util/ego/share/lset.c b/util/ego/share/lset.c index c1e4927842..7e2d69bc0e 100644 --- a/util/ego/share/lset.c +++ b/util/ego/share/lset.c @@ -40,11 +40,11 @@ bool Lis_elem(Lelem_t x, lset s) { if (s->e_elem == x) { - return TRUE; + return true; } s = s->e_next; } - return FALSE; + return false; } void Ladd(Lelem_t x, lset* s_p) @@ -180,9 +180,9 @@ bool Lis_subset(lset s1, lset s2) for (i = Lfirst(s1); i != (Lindex)0; i = Lnext(i, s1)) { if (!Lis_elem(Lelem(i), s2)) - return FALSE; + return false; } - return TRUE; + return true; } short Lnrelems(lset s) diff --git a/util/ego/share/parser.c b/util/ego/share/parser.c index bc5d1cd953..d49a01e006 100644 --- a/util/ego/share/parser.c +++ b/util/ego/share/parser.c @@ -48,13 +48,13 @@ static bool classes(int instr, int* src_out, int* res_out) class_p c; if (instr < sp_fmnem || instr > sp_lmnem) - return FALSE; + return false; c = &classtab[instr]; if (c->src_class == NOCLASS) - return FALSE; + return false; *src_out = c->src_class; *res_out = c->res_class; - return TRUE; + return true; } static bool uses_arg(int class) @@ -71,9 +71,9 @@ static bool uses_arg(int class) case CLASS4: case CLASS11: case CLASS12: - return TRUE; + return true; default: - return FALSE; + return false; } UNREACHABLE_CODE; } @@ -93,9 +93,9 @@ static bool parse_locs(line_p l, offset* c1_out, offset* c2_out) { *c1_out = off_set(l); *c2_out = off_set(PREV(l)); - return TRUE; + return true; } - return FALSE; + return false; } static bool check_args(line_p l, int src_class, int res_class, offset* arg1_out, offset* arg2_out) @@ -121,7 +121,7 @@ static bool check_args(line_p l, int src_class, int res_class, offset* arg1_out, if (TYPE(l) == OPSHORT) { *arg1_out = (offset)SHORT(l); - return TRUE; + return true; } else { @@ -131,11 +131,11 @@ static bool check_args(line_p l, int src_class, int res_class, offset* arg1_out, } else { - return FALSE; + return false; } } } - return TRUE; /* no argument needed */ + return true; /* no argument needed */ } static offset nrbytes(int class, offset arg1, offset arg2) @@ -171,7 +171,7 @@ static offset nrbytes(int class, offset arg1, offset arg2) case CLASS12: return (arg1 < ws ? ws : arg1); default: - assert(FALSE); + assert(false); } return 0; } @@ -182,7 +182,7 @@ static void attrib(line_p l, offset* expect_out, offset* srcb_out, offset* resb_ * instruction appearing in an expression. * If it is something we don't * expect in such expression (e.g. a store) - * expect_out is set to FALSE. Else we + * expect_out is set to false. Else we * determine the number of bytes popped from * the stack by the instruction and the * number of bytes pushed on the stack as @@ -195,11 +195,11 @@ static void attrib(line_p l, offset* expect_out, offset* srcb_out, offset* resb_ if (l == (line_p)0 || !classes(INSTR(l), &src_class, &res_class) || !check_args(l, src_class, res_class, &arg1, &arg2)) { - *expect_out = FALSE; + *expect_out = false; } else { - *expect_out = TRUE; + *expect_out = true; *srcb_out = nrbytes(src_class, arg1, arg2); *resb_out = nrbytes(res_class, arg1, arg2); } @@ -216,7 +216,7 @@ bool parse( * As EM is essentially postfix, this instruction * can be regarded as the root node of an expression * tree. The EM code is traversed from right to left, - * i.e. top down. On success, TRUE is returned and + * i.e. top down. On success, true is returned and * 'l_out' will point to the first instruction * of the recognized code. On toplevel, when an * expression has been recognized, the procedure-parameter @@ -239,7 +239,7 @@ bool parse( * (e.g. 'adi 2' pops 4 bytes and pushes 2 bytes). */ if (!expected || (more -= resultbytes) < 0) - return FALSE; + return false; if (sourcebytes == 0) { /* a leaf of the expression tree */ @@ -249,7 +249,7 @@ bool parse( { if (!parse(PREV(l), sourcebytes, &lnp, level + 1, action0)) { - return FALSE; + return false; } } if (level == 0) @@ -263,5 +263,5 @@ bool parse( * together push nbytes on the stack. */ *l_out = lnp; - return TRUE; + return true; } diff --git a/util/ego/share/show.c b/util/ego/share/show.c index 13ae9cae19..ec4dd50e98 100644 --- a/util/ego/share/show.c +++ b/util/ego/share/show.c @@ -157,7 +157,7 @@ showp() short all; printf("total number of procs: %d\n\n", getshort()); all = getshort(); - while (TRUE) + while (true) { n = getshort(); if (feof(f)) @@ -193,7 +193,7 @@ showd() { short n; printf("total number of objects: %d\n\n", getshort()); - while (TRUE) + while (true) { n = getbyte(); if (feof(f)) @@ -240,7 +240,7 @@ showinstr() instr = (short)getbyte(); if (feof(f)) - return FALSE; + return false; if (instr >= sp_fmnem && instr <= sp_lmnem) { s = &(em_mnem[(instr - sp_fmnem) * 4]); @@ -284,7 +284,7 @@ showinstr() break; } printf("\n"); - return TRUE; + return true; } showl() @@ -351,7 +351,7 @@ showb() short n, m; - while (TRUE) + while (true) { n = getshort(); if (feof(f)) @@ -398,7 +398,7 @@ showc() int n, m, cnt, t; cnt = 1; - while (TRUE) + while (true) { t = getshort(); if (feof(f)) diff --git a/util/ego/share/stack_chg.c b/util/ego/share/stack_chg.c index 7ae265ee1b..1b760a5790 100644 --- a/util/ego/share/stack_chg.c +++ b/util/ego/share/stack_chg.c @@ -42,11 +42,11 @@ static int stack_change(line_p l, char sign) */ arg = ws; } - argdef = TRUE; + argdef = true; } else { - argdef = FALSE; + argdef = false; } s = pop_push[i]; if (*s == '0') @@ -94,7 +94,7 @@ static int stack_change(line_p l, char sign) case '?': return -1; default: - assert(FALSE); + assert(false); } } s++; diff --git a/util/ego/share/types.h b/util/ego/share/types.h index ba415b19de..ffff35a338 100644 --- a/util/ego/share/types.h +++ b/util/ego/share/types.h @@ -59,9 +59,6 @@ typedef struct local* local_p; typedef struct cond_tab* cond_p; -#define TRUE 1 -#define FALSE 0 - /* DATABLOCKS */ /* A datablock is a block of global data, declared by means of @@ -186,7 +183,7 @@ union lpext_t { lset lpx_blocks; /* basic blocks constituting the loop */ bblock_p lpx_header; /* header block, 0 if no one allocated yet */ - bool lpx_done; /* TRUE if we've processed this loop */ + bool lpx_done; /* true if we've processed this loop */ line_p lpx_instr; /* current last instruction in header block*/ } lpx_sr; struct lpext_ra diff --git a/util/ego/share/utils.c b/util/ego/share/utils.c index 0677f7dcb4..b888bf5874 100644 --- a/util/ego/share/utils.c +++ b/util/ego/share/utils.c @@ -28,7 +28,7 @@ offset off_set(line_p lnp) case OPOFFSET: return OFFSET(lnp); default: - assert(FALSE); + assert(false); } UNREACHABLE_CODE; } @@ -114,9 +114,9 @@ bool dom(bblock_p b1, bblock_p b2) * of b2 in the immediate dominator tree. */ if (b == b1) - return TRUE; + return true; } - return FALSE; + return false; } bblock_p common_dom(bblock_p a, bblock_p b) diff --git a/util/ego/sp/sp.c b/util/ego/sp/sp.c index 8a0db7a2a8..c73df250b5 100644 --- a/util/ego/sp/sp.c +++ b/util/ego/sp/sp.c @@ -84,7 +84,7 @@ static void stack_pollution(bblock_p b) line_p l; line_p asp, next = b->b_start; - bool asp_seen = FALSE; + bool asp_seen = false; int stack_diff, pop, push; bool ok; @@ -108,7 +108,7 @@ static void stack_pollution(bblock_p b) if (!ok || (stack_diff -= pop) < 0) { /* can't eliminate last ASP */ - asp_seen = FALSE; + asp_seen = false; } else { @@ -139,7 +139,7 @@ static void stack_pollution(bblock_p b) } } asp = l; - asp_seen = TRUE; /* use new ASP for next try! */ + asp_seen = true; /* use new ASP for next try! */ } while (asp != (line_p)0); } @@ -162,7 +162,7 @@ static bool block_save(bblock_p b) /* printf("instr %d, pop %d,push %d,ok %d\n",INSTR(l),pop,push,ok); */ if (!ok || (stack_diff -= pop) < 0) { - return FALSE; + return false; } else { diff --git a/util/ego/sr/sr.c b/util/ego/sr/sr.c index ea5ae9ed03..bf972e2bb8 100644 --- a/util/ego/sr/sr.c +++ b/util/ego/sr/sr.c @@ -153,7 +153,7 @@ static void opt_proc(proc_p p) if (!outermost) break; do_loop(outermost); - outermost->LP_DONE = TRUE; + outermost->LP_DONE = true; OUTTRACE("loop %d processed", outermost->lp_id); } } diff --git a/util/ego/sr/sr_aux.c b/util/ego/sr/sr_aux.c index 977f665fc5..505e12e79f 100644 --- a/util/ego/sr/sr_aux.c +++ b/util/ego/sr/sr_aux.c @@ -28,15 +28,15 @@ bool is_loopconst(line_p lnp, lset vars) assert(TYPE(lnp) == OPSHORT || TYPE(lnp) == OPOFFSET); if (!is_regvar(off_set(lnp))) - return FALSE; + return false; for (i = Lfirst(vars); i != (Lindex)0; i = Lnext(i, vars)) { if (same_local(Lelem(i), lnp)) { - return FALSE; /* variable was changed */ + return false; /* variable was changed */ } } - return TRUE; + return true; } bool is_caddress(line_p lnp, lset vars) /* variables changed in loop */ @@ -47,18 +47,18 @@ bool is_caddress(line_p lnp, lset vars) /* variables changed in loop */ */ if (lnp == (line_p)0) - return FALSE; + return false; switch (INSTR(lnp)) { case op_lae: case op_lal: - return TRUE; + return true; case op_lol: return ps == ws && is_loopconst(lnp, vars); case op_ldl: return ps == 2 * ws && is_loopconst(lnp, vars); default: - return FALSE; + return false; } UNREACHABLE_CODE; } diff --git a/util/ego/sr/sr_cand.c b/util/ego/sr/sr_cand.c index a278bba8fa..104da1c81f 100644 --- a/util/ego/sr/sr_cand.c +++ b/util/ego/sr/sr_cand.c @@ -75,10 +75,10 @@ static bool is_cand(line_p lnp) { if (same_local(lnp, Lelem(i))) { - return TRUE; + return true; } } - return FALSE; + return false; } static void make_cand(line_p lnp) @@ -114,10 +114,10 @@ static bool not_dismissed(line_p lnp) { if (same_local(Lelem(i), lnp)) { - return FALSE; /* variable was dismissed */ + return false; /* variable was dismissed */ } } - return TRUE; + return true; } static void try_cand(line_p lnp, bblock_p b) diff --git a/util/ego/sr/sr_expr.c b/util/ego/sr/sr_expr.c index 59a017eb75..b129cd6f60 100644 --- a/util/ego/sr/sr_expr.c +++ b/util/ego/sr/sr_expr.c @@ -50,11 +50,11 @@ static bool is_loadiv(line_p lnp) if (iv->iv_off == off) { last_iv = iv; - return TRUE; + return true; } } } - return FALSE; + return false; } #define size_ok(l) (TYPE(l) == OPSHORT && SHORT(l) == ws) @@ -141,9 +141,9 @@ static bool match_expr(line_p l, bool iv_allowed, line_p* lbegin, bool* iv_seen, { *lbegin = l1; *iv_seen = iv_insubexpr; - return TRUE; + return true; } - return FALSE; + return false; case ME_BINAIR: /* binairy operator, match two subexpressions */ if (match_expr(PREV(l), iv_allowed, &l1, &iv_insubexpr, sign2)) @@ -154,24 +154,24 @@ static bool match_expr(line_p l, bool iv_allowed, line_p* lbegin, bool* iv_seen, { *lbegin = l1; *iv_seen = !iv_allowed || iv_insubexpr; - return TRUE; + return true; } } - return FALSE; /* subexpression not recognized */ + return false; /* subexpression not recognized */ case ME_LOOPCONST: *lbegin = l; /* expression is a loop constant */ - *iv_seen = FALSE; - return TRUE; + *iv_seen = false; + return true; case ME_IV: if (iv_allowed) { - *iv_seen = TRUE; + *iv_seen = true; *lbegin = l; - return TRUE; + return true; } /* fall through ... */ default: - return FALSE; + return false; } } @@ -182,7 +182,7 @@ bool is_ivexpr(line_p l, lset ivs, lset vars, line_p* lbegin_out, iv_p* iv_out, loopvars = vars; ivars = ivs; - if (match_expr(l, TRUE, &l2, &iv_seen, 1)) + if (match_expr(l, true, &l2, &iv_seen, 1)) { if (iv_seen) { @@ -190,8 +190,8 @@ bool is_ivexpr(line_p l, lset ivs, lset vars, line_p* lbegin_out, iv_p* iv_out, *lbegin_out = l2; *iv_out = last_iv; *sign_out = iv_sign; - return TRUE; + return true; } } - return FALSE; + return false; } diff --git a/util/ego/sr/sr_iv.c b/util/ego/sr/sr_iv.c index 987fb0c1c1..354d9a2fac 100644 --- a/util/ego/sr/sr_iv.c +++ b/util/ego/sr/sr_iv.c @@ -98,7 +98,7 @@ static int sign(line_p lnp) case op_sbu: return (-1); default: - assert(FALSE); + assert(false); } UNREACHABLE_CODE; } diff --git a/util/ego/sr/sr_reduce.c b/util/ego/sr/sr_reduce.c index 5a7971f946..ed9f0f1eb5 100644 --- a/util/ego/sr/sr_reduce.c +++ b/util/ego/sr/sr_reduce.c @@ -104,7 +104,7 @@ static line_p newcode(code_p code, offset tmp) l->l_instr = op_sil; break; default: - assert(FALSE); + assert(false); } return l; } @@ -211,7 +211,7 @@ static void init_code(code_p code, offset tmp) l->l_next = move_pointer(tmp, STORE); break; default: - assert(FALSE); /* non-reducible instruction */ + assert(false); /* non-reducible instruction */ } PREV(l->l_next) = l; @@ -287,7 +287,7 @@ static void incr_code(code_p code, offset tmp) store_tmp = move_pointer(tmp, STORE); break; default: - assert(FALSE); + assert(false); } /* Now we've got pieces of code to load the temp. local, * load the constant, add the two and store the result in @@ -324,7 +324,7 @@ static bool same_address(line_p l1, line_p l2, lset vars) /* See if l1 and l2 load the same address */ if (INSTR(l1) != INSTR(l2)) - return FALSE; + return false; switch (INSTR(l1)) { case op_lae: @@ -336,7 +336,7 @@ static bool same_address(line_p l1, line_p l2, lset vars) case op_ldl: return ps == 2 * ws && off_set(l1) == off_set(l2) && is_loopconst(l1, vars); default: - return FALSE; + return false; } } @@ -353,26 +353,26 @@ static bool same_expr(line_p lb1, line_p le1, line_p lb2, line_p le2) for (;;) { if (INSTR(l1) != INSTR(l2)) - return FALSE; + return false; switch (TYPE(l1)) { case OPSHORT: if (TYPE(l2) != OPSHORT || SHORT(l1) != SHORT(l2)) - return FALSE; + return false; break; case OPOFFSET: if (TYPE(l2) != OPOFFSET || OFFSET(l1) != OFFSET(l2)) - return FALSE; + return false; break; case OPNO: break; default: - return FALSE; + return false; } if (l1 == le1) return l2 == le2; if (l2 == le2) - return FALSE; + return false; l1 = l1->l_next; l2 = l2->l_next; } @@ -402,7 +402,7 @@ static bool same_code(code_p c1, code_p c2, lset vars) && same_address(c1->c_o.co_desc, c2->c_o.co_desc, vars) && same_address(c1->co_lfirst, c2->co_lfirst, vars); default: - assert(FALSE); + assert(false); } UNREACHABLE_CODE; } diff --git a/util/ego/ud/ud.c b/util/ego/ud/ud.c index 6bda5340c4..4a29e3ee9e 100644 --- a/util/ego/ud/ud.c +++ b/util/ego/ud/ud.c @@ -76,11 +76,11 @@ static bool test_cond(short cond, offset val) switch (cond) { case DEFAULT: - return TRUE; + return true; case FITBYTE: return val >= -128 && val < 128; } - assert(FALSE); + assert(false); UNREACHABLE_CODE; } @@ -169,18 +169,18 @@ static void solve_equations(proc_p p) /* Global variables and parameters have already a value * at the procedure entry block. */ - change = TRUE; + change = true; /* main loop */ while (change) { - change = FALSE; + change = false; for (b = p->p_start->b_next; b != (bblock_p)0; b = b->b_next) { unite_outs(b->b_pred, &newin); /* newin = OUT(p1) + .. + OUT(pn) */ if (!Cequal(newin, IN(b))) { - change = TRUE; + change = true; Ccopy_set(newin, &IN(b)); Ccopy_set(IN(b), &OUT(b)); Csubtract(KILL(b), &OUT(b)); @@ -199,13 +199,13 @@ static void solve_equations(proc_p p) short global_addr_cost(void) { return add_timespace( - map_value(globl_cond_tab, (offset)0, TRUE), map_value(globl_cond_tab, (offset)0, FALSE)); + map_value(globl_cond_tab, (offset)0, true), map_value(globl_cond_tab, (offset)0, false)); } short local_addr_cost(offset off) { return add_timespace( - map_value(local_cond_tab, off, TRUE), map_value(local_cond_tab, off, FALSE)); + map_value(local_cond_tab, off, true), map_value(local_cond_tab, off, false)); } static bool fold_is_desirable(line_p old, line_p new) @@ -309,7 +309,7 @@ pr_defs() fprintf(stderr, "%d\n", OBJ(l)->o_id); break; default: - assert(FALSE); + assert(false); } } } @@ -439,7 +439,7 @@ static bool try_optim(line_p l, bblock_p b) fold_var(l, PREV(def), b); OUTVERBOSE("vp:variable folded in proc %d", curproc->p_id, 0); Svariable++; - return TRUE; + return true; } } else @@ -449,11 +449,11 @@ static bool try_optim(line_p l, bblock_p b) fold_const(l, b, val); OUTVERBOSE("vp:value folded in proc %d", curproc->p_id, 0); Svalue++; - return TRUE; + return true; } } } - return FALSE; + return false; } static void value_propagation(proc_p p) @@ -464,7 +464,7 @@ static void value_propagation(proc_p p) bblock_p b; line_p l, next; - changes = TRUE; + changes = true; /* If a statement like A := B is folded to A := constant, * new opportunities for constant folding may arise, * e.g. the value of A might be statically known too now. @@ -472,7 +472,7 @@ static void value_propagation(proc_p p) while (changes) { - changes = FALSE; + changes = false; for (b = p->p_start; b != (bblock_p)0; b = b->b_next) { for (l = b->b_start; l != (line_p)0; l = next) @@ -480,7 +480,7 @@ static void value_propagation(proc_p p) next = l->l_next; if (try_optim(l, b)) { - changes = TRUE; + changes = true; } } } diff --git a/util/ego/ud/ud_const.c b/util/ego/ud/ud_const.c index bd4412a91f..bc64fca70e 100644 --- a/util/ego/ud/ud_const.c +++ b/util/ego/ud/ud_const.c @@ -35,9 +35,9 @@ bool is_use(line_p l) case op_ldl: case op_loe: case op_lol: - return TRUE; + return true; default: - return FALSE; + return false; } /* NOTREACHED */ } @@ -59,7 +59,7 @@ bool value_known(line_p def, offset* val_out) case op_ine: case op_del: case op_dee: - return FALSE; + return false; case op_zrl: case op_zre: v = (offset)0; @@ -72,7 +72,7 @@ bool value_known(line_p def, offset* val_out) case op_ste: l = PREV(def); if (l == (line_p)0) - return FALSE; + return false; sz2 = ws; switch (INSTR(l)) { @@ -82,7 +82,7 @@ bool value_known(line_p def, offset* val_out) v = (offset)0; break; } - return FALSE; + return false; case op_ldc: sz2 += ws; /* fall through ...*/ @@ -94,14 +94,14 @@ bool value_known(line_p def, offset* val_out) } /* fall through ... */ default: - return FALSE; + return false; } break; default: - assert(FALSE); + assert(false); } *val_out = v; - return TRUE; + return true; } bool affected(line_p use, short v, line_p l) @@ -134,18 +134,18 @@ static void search_backwards(line_p use, short v, bool* found, line_p* def) { if (does_expl_def(l) && same_var(use, l)) { - *found = TRUE; + *found = true; *def = l; return; } if (does_impl_def(l) && affected(use, v, l)) { - *found = TRUE; + *found = true; *def = (line_p)0; return; } } - *found = FALSE; + *found = false; } static short outer_def(cset vdefs, cset in) @@ -222,7 +222,7 @@ void fold_const(line_p l, bblock_p b, offset val) n->l_instr = op_ldc; break; default: - assert(FALSE); + assert(false); } repl_line(l, n, b); } diff --git a/util/ego/ud/ud_copy.c b/util/ego/ud/ud_copy.c index 79492f974e..2e4df7640f 100644 --- a/util/ego/ud/ud_copy.c +++ b/util/ego/ud/ud_copy.c @@ -112,16 +112,16 @@ static bool is_changed(line_p varl, line_p start, line_p stop) var_nr(varl, &v, &found); if (!found) { - return TRUE; /* We don't maintain ud-info for this variable */ + return true; /* We don't maintain ud-info for this variable */ } for (l = start; l != (line_p)0 && l != stop; l = l->l_next) { if (does_expl_def(l) && same_var(varl, l)) - return TRUE; + return true; if (does_impl_def(l) && affected(varl, v, l)) - return TRUE; + return true; } - return FALSE; + return false; } static void gen_kill_copies(proc_p p) @@ -249,18 +249,18 @@ static void solve_cin(proc_p p) } newin = Cempty_set(nrcopies); init_cin(p, full_set); - change = TRUE; + change = true; /* main loop */ while (change) { - change = FALSE; + change = false; for (b = p->p_start->b_next; b != (bblock_p)0; b = b->b_next) { intersect_outs(b->b_pred, &newin, full_set); /* newin = C_OUT(p1) * .. * C_OUT(pn) */ if (!Cequal(newin, C_IN(b))) { - change = TRUE; + change = true; Ccopy_set(newin, &C_IN(b)); Ccopy_set(C_IN(b), &C_OUT(b)); Csubtract(C_KILL(b), &C_OUT(b)); @@ -295,7 +295,7 @@ bool is_copy(line_p def) lhs = PREV(def); if (lhs == (line_p)0) - return FALSE; + return false; instr = INSTR(def); switch (INSTR(lhs)) { @@ -306,7 +306,7 @@ bool is_copy(line_p def) case op_lde: return instr == op_sdl || instr == op_sde; default: - return FALSE; + return false; } UNREACHABLE_CODE; } @@ -363,7 +363,7 @@ void fold_var(line_p old, line_p new, bblock_p b) OFFSET(l) = OFFSET(new); break; default: - assert(FALSE); + assert(false); } } diff --git a/util/ego/ud/ud_defs.c b/util/ego/ud/ud_defs.c index 877bbb0432..9af72c4c99 100644 --- a/util/ego/ud/ud_defs.c +++ b/util/ego/ud/ud_defs.c @@ -46,9 +46,9 @@ bool does_expl_def(line_p l) case op_dee: case op_zrl: case op_zre: - return TRUE; + return true; default: - return FALSE; + return false; } UNREACHABLE_CODE; } @@ -70,9 +70,9 @@ bool does_impl_def(line_p l) case op_blm: case op_bls: case op_zrf: - return TRUE; + return true; default: - return FALSE; + return false; } } diff --git a/util/grind/expr.c b/util/grind/expr.c index 065be46d20..4bbfe5c1b0 100644 --- a/util/grind/expr.c +++ b/util/grind/expr.c @@ -4,8 +4,8 @@ routines: - int eval_cond(p_tree p) This routine evaluates the conditional expression indicated by p - and returns 1 if it evaluates to TRUE, or 0 if it could not be - evaluated for some reason or if it evalutes to FALSE. + and returns 1 if it evaluates to true, or 0 if it could not be + evaluated for some reason or if it evalutes to false. If the expression cannot be evaluated, an error message is given. - int eval_desig(p_tree p, t_addr *paddr, long **psize, p_type *ptp) This routine evaluates the expression indicated by p, which should diff --git a/util/grind/expr.h b/util/grind/expr.h index 8e35a83bfb..02b664b630 100644 --- a/util/grind/expr.h +++ b/util/grind/expr.h @@ -59,8 +59,8 @@ extern int put_real(); /* int eval_cond(p_tree p) This routine evaluates the conditional expression indicated by p - and returns 1 if it evaluates to TRUE, or 0 if it could not be - evaluated for some reason or if it evalutes to FALSE. + and returns 1 if it evaluates to true, or 0 if it could not be + evaluated for some reason or if it evalutes to false. If the expression cannot be evaluated, an error message is given. */ extern int eval_cond(); diff --git a/util/led/archive.c b/util/led/archive.c index b4cf692e0c..09f16dfadb 100644 --- a/util/led/archive.c +++ b/util/led/archive.c @@ -104,7 +104,7 @@ void arch(void) debug("(re)scan ranlib table\n", 0, 0, 0, 0); ranindex = (ind_t)0; count = nran; - resolved = FALSE; + resolved = false; while (count > 0) { struct ranlib* ran; @@ -125,7 +125,7 @@ void arch(void) get_archive_header(&arhdr); modulname = arhdr.ar_name; verbose("defines %s", string, 0, 0, 0); - resolved = TRUE; + resolved = true; /* * This archive member is going to be linked, * so we don't need to know what else it defines. diff --git a/util/led/const.h b/util/led/const.h index 8c91f16acd..9cb62bccf8 100644 --- a/util/led/const.h +++ b/util/led/const.h @@ -7,9 +7,6 @@ #ifndef __CONST_H_INCLUDED__ #define __CONST_H_INCLUDED__ -#define FALSE 0 -#define TRUE 1 - #define WIDTH 8 /* Number of bits in a byte. */ #define BYTEMASK 0xFF /* Mask to get low order byte. */ diff --git a/util/led/main.c b/util/led/main.c index 62bfba47a6..e953a6a7e0 100644 --- a/util/led/main.c +++ b/util/led/main.c @@ -413,7 +413,7 @@ static void norm_commons(void) { struct outname* name; int cnt; - int und = FALSE; + int und = false; name = (struct outname*)address(ALLOGLOB, (ind_t)0); cnt = NGlobals; @@ -423,7 +423,7 @@ static void norm_commons(void) { if (!und) { - und = TRUE; + und = true; if (!(flagword & RFLAG)) { exitstatus = 1; @@ -553,12 +553,12 @@ bool setbit(int indx, char string[]) byte = string[byte_index]; byte >>= bit_index; if (byte & BIT) - return TRUE; + return true; byte = BIT; byte <<= bit_index; string[byte_index] |= byte; - return FALSE; + return false; } /* diff --git a/util/led/memory.c b/util/led/memory.c index 2fd7bf53a4..9710ce942d 100644 --- a/util/led/memory.c +++ b/util/led/memory.c @@ -52,12 +52,12 @@ static void free_saved_moduls(void); struct memory mems[NMEMS]; -bool incore = TRUE; /* TRUE while everything can be kept in core. */ +bool incore = true; /* true while everything can be kept in core. */ ind_t core_position = (ind_t)0; /* Index of current module. */ #ifdef USEMALLOC static size_t modl_initial_size; -static bool frozen = FALSE; /* TRUE after freeze_core(). */ +static bool frozen = false; /* true after freeze_core(). */ #else /* ifndef USEMALLOC */ #define GRANULE 64 /* power of 2 */ @@ -119,7 +119,7 @@ void init_core(void) } if (failed_mem != NULL) { - incore = FALSE; /* In core strategy failed. */ + incore = false; /* In core strategy failed. */ /* Undo allocations. */ for (mem = mems; mem != failed_mem; mem++) free(mem->mem_base); @@ -188,7 +188,7 @@ void init_core(void) if (sbreak(total_size) == -1) { - incore = FALSE; /* In core strategy failed. */ + incore = false; /* In core strategy failed. */ if (sbreak(AT_LEAST) == -1) fatal("no core at all"); @@ -337,22 +337,22 @@ static bool compact(int piece, ind_t incr, int flag) } newsize -= INCRSIZE < newsize ? INCRSIZE : newsize; } - frozen = TRUE; /* Prevent later realloc(). */ + frozen = true; /* Prevent later realloc(). */ } /* Now grow our piece. */ if (incr == 0) - return TRUE; + return true; mem = &mems[piece]; oldsize = mem->mem_full + mem->mem_left; newsize = oldsize + incr; if (newsize < mem->mem_full) - return FALSE; /* The size overflowed. */ + return false; /* The size overflowed. */ newbase = realloc(mem->mem_base, newsize); if (newbase == NULL) - return FALSE; + return false; mem->mem_base = newbase; mem->mem_left += incr; - return TRUE; + return true; #else /* ifndef USEMALLOC */ ind_t gain, size; @@ -604,7 +604,7 @@ ind_t alloc(int piece, size_t size) } else { - incore = FALSE; + incore = false; return BADOFF; } } diff --git a/util/led/scan.c b/util/led/scan.c index f6289f15fc..ffd7a392ec 100644 --- a/util/led/scan.c +++ b/util/led/scan.c @@ -270,12 +270,12 @@ static bool indirect_alloc(struct outhead* head) for (allopiece = ALLOEMIT; allopiece < ALLOEMIT + nsect; allopiece++) { if (!putemitindex(sectindex, emitoff, allopiece)) - return FALSE; + return false; sectindex += sizeof(struct outsect); emitoff += sizeof(ind_t); } if (nrelo > SIZE_MAX / sizeof(struct outrelo)) - return FALSE; /* nrelo * size would overflow */ + return false; /* nrelo * size would overflow */ #ifdef SYMDBUG return putreloindex(relooff, nrelo * sizeof(struct outrelo)) && putdbugindex(dbugoff, dbugsize); #else /* SYMDBUG */ @@ -306,7 +306,7 @@ static bool putemitindex(ind_t sectindex, ind_t emitoff, int allopiece) if (flen && zero) { if (zero != (size_t)zero) - return FALSE; + return false; if ((emitindex = alloc(allopiece, zero)) != BADOFF) { char* p = address(allopiece, emitindex); @@ -316,18 +316,18 @@ static bool putemitindex(ind_t sectindex, ind_t emitoff, int allopiece) *p++ = 0; } else - return FALSE; + return false; zero = 0; } zeros[allopiece - ALLOEMIT] = zero + ((struct outsect*)modulptr(sectindex))->os_size - flen; if (flen != (size_t)flen) - return FALSE; + return false; if ((emitindex = alloc(allopiece, flen)) != BADOFF) { *(ind_t*)modulptr(emitoff) = emitindex; - return TRUE; + return true; } - return FALSE; + return false; } /* @@ -341,9 +341,9 @@ static bool putreloindex(ind_t relooff, size_t nrelobytes) if ((reloindex = alloc(ALLORELO, nrelobytes)) != BADOFF) { *(ind_t*)modulptr(relooff) = reloindex; - return TRUE; + return true; } - return FALSE; + return false; } #ifdef SYMDBUG /* @@ -356,9 +356,9 @@ static bool putdbugindex(ind_t dbugoff, size_t ndbugbytes) if ((dbugindex = alloc(ALLODBUG, ndbugbytes)) != BADOFF) { *(ind_t*)modulptr(dbugoff) = dbugindex; - return TRUE; + return true; } - return FALSE; + return false; } #endif /* SYMDBUG */ diff --git a/util/make/h.h b/util/make/h.h index c83f5b2a90..52c809ad5f 100644 --- a/util/make/h.h +++ b/util/make/h.h @@ -11,10 +11,6 @@ #include -#define bool int -#define TRUE (1) -#define FALSE (0) - #define DEFN1 "makefile" /* Default names */ #define DEFN2 "Makefile" diff --git a/util/make/input.c b/util/make/input.c index 573fdb3480..d013b006d5 100644 --- a/util/make/input.c +++ b/util/make/input.c @@ -126,7 +126,7 @@ struct cmd *newcmd(char *str, struct cmd *cp) */ void newline(struct name *np, struct depend *dp, struct cmd *cp, int flag) { - bool hascmds = FALSE; /* Target has commands */ + bool hascmds = false; /* Target has commands */ struct line * rp; struct line * rrp; @@ -147,7 +147,7 @@ void newline(struct name *np, struct depend *dp, struct cmd *cp, int flag) for (rp = np->n_line, rrp = (struct line *) 0; rp; rrp = rp, rp = rp->l_next) if (rp->l_cmd) - hascmds = TRUE; + hascmds = true; if (hascmds && cp && !(np->n_flag & N_DOUBLE)) /* Handle the implicit rules redefinition case */ @@ -274,7 +274,7 @@ void input(FILE *fd) /* Need two nulls for gettok (Remember separation) */ cp = (struct cmd *) 0; - if (mgetline(str2, fd) == FALSE) /* Get commands */ + if (mgetline(str2, fd) == false) /* Get commands */ { while (*str2 == '\t') { diff --git a/util/make/macro.c b/util/make/macro.c index fafa6f715a..afb21f2084 100644 --- a/util/make/macro.c +++ b/util/make/macro.c @@ -60,7 +60,7 @@ struct macro * setmacro(char* name, char* val, int prio) rp->m_next = macrohead; macrohead = rp; - rp->m_flag = FALSE; + rp->m_flag = false; if ((cp = malloc((unsigned)(strlen(name)+1))) == (char *)0) fatal("No memory for macro",NULL); @@ -124,11 +124,11 @@ static void doexp(char **to, char* from, int* len, char* buf) mp = setmacro(buf, "", 2); if (mp->m_flag) fatal("Infinitely recursive macro %s", mp->m_name); - mp->m_flag = TRUE; + mp->m_flag = true; *to = p; doexp(to, mp->m_val, len, buf); p = *to; - mp->m_flag = FALSE; + mp->m_flag = false; } if (*len <= 0) error("Expanded line too line", NULL); diff --git a/util/make/main.c b/util/make/main.c index c878ce059d..c007f15f6c 100644 --- a/util/make/main.c +++ b/util/make/main.c @@ -29,13 +29,13 @@ unsigned memspace = MEMSPACE; #endif FILE * ifd; /* Input file desciptor */ -bool domake = TRUE; /* Go through the motions option */ -bool ignore = FALSE; /* Ignore exit status option */ -bool silent = FALSE; /* Silent option */ -bool print = FALSE; /* Print debuging information */ -bool rules = TRUE; /* Use inbuilt rules */ -bool dotouch = FALSE;/* Touch files instead of making */ -bool quest = FALSE; /* Question up-to-dateness of file */ +bool domake = true; /* Go through the motions option */ +bool ignore = false; /* Ignore exit status option */ +bool silent = false; /* Silent option */ +bool print = false; /* Print debuging information */ +bool rules = true; /* Use inbuilt rules */ +bool dotouch = false;/* Touch files instead of making */ +bool quest = false; /* Question up-to-dateness of file */ static void usage(void); @@ -66,25 +66,25 @@ int main(int argc, char** argv) fflag = 1; break; case 'n': /* Pretend mode */ - domake = FALSE; + domake = false; break; case 'i': /* Ignore fault mode */ - ignore = TRUE; + ignore = true; break; case 's': /* Silent about commands */ - silent = TRUE; + silent = true; break; case 'p': - print = TRUE; + print = true; break; case 'r': - rules = FALSE; + rules = false; break; case 't': - dotouch = TRUE; + dotouch = true; break; case 'q': - quest = TRUE; + quest = true; break; case 'k': break; @@ -149,11 +149,11 @@ int main(int argc, char** argv) np = newname(".SILENT"); if (np->n_flag & N_TARG) - silent = TRUE; + silent = true; np = newname(".IGNORE"); if (np->n_flag & N_TARG) - ignore = TRUE; + ignore = true; precious(); diff --git a/util/make/make.c b/util/make/make.c index 1b6ba4ff3b..9a50af44d9 100644 --- a/util/make/make.c +++ b/util/make/make.c @@ -79,9 +79,9 @@ static void docmds1(struct name *np, struct line *lp) while ((*q == '@') || (*q == '-')) { if (*q == '@') /* Specific silent */ - ssilent = TRUE; + ssilent = true; else /* Specific ignore */ - signore = TRUE; + signore = true; q++; /* Not part of the command */ } diff --git a/util/make/reader.c b/util/make/reader.c index 425a7ac343..533c017c1d 100644 --- a/util/make/reader.c +++ b/util/make/reader.c @@ -40,7 +40,7 @@ void error(char *msg, char* a1) /* * Read a line into the supplied string of length LZ. Remove * comments, ignore blank lines. Deal with quoted (\) #, and - * quoted newlines. If EOF return TRUE. + * quoted newlines. If EOF return true. */ bool mgetline(char* str, FILE* fd) { @@ -52,7 +52,7 @@ bool mgetline(char* str, FILE* fd) for (;;) { if (fgets(str+pos, LZ-pos, fd) == (char *)0) - return TRUE; /* EOF */ + return true; /* EOF */ lineno++; @@ -88,7 +88,7 @@ bool mgetline(char* str, FILE* fd) p++; if (*p != '\0') - return FALSE; + return false; pos = 0; } } diff --git a/util/make/rules.c b/util/make/rules.c index c8cd658bd8..108d79b661 100644 --- a/util/make/rules.c +++ b/util/make/rules.c @@ -22,7 +22,7 @@ char *suffix(char *name) * Dynamic dependency. This routine applies the suffis rules * to try and find a source and a set of rules for a missing * target. If found, np is made into a target with the implicit - * source name, and rules. Returns TRUE if np was made into + * source name, and rules. Returns true if np was made into * a target. */ bool dyndep(struct name *np) @@ -41,14 +41,14 @@ bool dyndep(struct name *np) p = str1; q = np->n_name; if (!(suff = suffix(q))) - return FALSE; /* No suffix */ + return false; /* No suffix */ while (q < suff) *p++ = *q++; *p = '\0'; basename = setmacro("*", str1, 4)->m_val; if (!((sp = newname(".SUFFIXES"))->n_flag & N_TARG)) - return FALSE; + return false; for (lp = sp->n_line; lp; lp = lp->l_next) for (dp = lp->l_dep; dp; dp = dp->d_next) @@ -85,11 +85,11 @@ bool dyndep(struct name *np) dp = newdep(op, (struct depend *)0); newline(np, dp, sp->n_line->l_cmd, 0); setmacro("<", op->n_name, 4); - return TRUE; + return true; } } } - return FALSE; + return false; } diff --git a/util/opt/flow.c b/util/opt/flow.c index 11e243c087..2d1af81c2f 100644 --- a/util/opt/flow.c +++ b/util/opt/flow.c @@ -108,7 +108,7 @@ static void cleaninstrs(void) lpp = &instrs; lastbra = (line_p *) 0; - reachable = TRUE; + reachable = true; while ((lp = *lpp) != (line_p) 0) { instr = lp->l_instr & BMASK; @@ -116,7 +116,7 @@ static void cleaninstrs(void) { if ((lp->l_a.la_np->n_flags & NUMREACH) != 0) { - reachable = TRUE; + reachable = true; if (lastbra != (line_p *) 0 && (*lastbra)->l_next == lp && (*lastbra)->l_a.la_np->n_repl == lp->l_a.la_np) { @@ -131,12 +131,12 @@ static void cleaninstrs(void) if (lp->l_a.la_np->n_repl != lp->l_a.la_np || ((lp->l_a.la_np->n_flags & NUMDATA) == 0 && lp->l_a.la_np->n_jumps == 0)) - superfluous = TRUE; + superfluous = true; else - superfluous = FALSE; + superfluous = false; } else - superfluous = FALSE; + superfluous = false; if ((!reachable) || superfluous) { if (instr == op_lab) @@ -159,7 +159,7 @@ static void cleaninstrs(void) if (instr <= sp_lmnem && (em_flag[instr - sp_fmnem] & EM_FLO) == FLO_T) { - reachable = FALSE; + reachable = false; if ((lp->l_instr & BMASK) == op_bra) lastbra = lpp; } diff --git a/util/opt/getline.c b/util/opt/getline.c index 2eeed984a8..7001056d39 100644 --- a/util/opt/getline.c +++ b/util/opt/getline.c @@ -262,7 +262,7 @@ static line_p arglist(int n) lnp = newline(OPLIST); app = &lnp->l_a.la_arg; - moretocome = TRUE; + moretocome = true; do { switch (table2()) @@ -321,10 +321,10 @@ static line_p arglist(int n) app = &ap->a_next; break; case sp_cend: - moretocome = FALSE; + moretocome = false; } if (n && (--n) == 0) - moretocome = FALSE; + moretocome = false; } while (moretocome); return (lnp); } @@ -405,7 +405,7 @@ static int inpseudo(short n) draininput(); exit(-1); case ms_opt: - nflag = TRUE; + nflag = true; break; case ms_emx: wordsize = aoff(lnp->l_a.la_arg, 1); diff --git a/util/opt/main.c b/util/opt/main.c index ac7ebcf1c7..eb217817c0 100644 --- a/util/opt/main.c +++ b/util/opt/main.c @@ -26,16 +26,16 @@ void flags(char *s) switch (*s) { case 'L': - Lflag = TRUE; + Lflag = true; break; case 'n': - nflag = TRUE; + nflag = true; break; case 'm': if (*(s + 1) == 'l') { s++; - repl_longmuls = TRUE; + repl_longmuls = true; } repl_muls = atoi(s + 1); break; diff --git a/util/opt/mktab.y b/util/opt/mktab.y index 54588f06a8..bd4cfea665 100644 --- a/util/opt/mktab.y +++ b/util/opt/mktab.y @@ -363,8 +363,8 @@ void initio(void) printf("#include \"pattern.h\"\n\n"); for(i=0;in_repl = np->n_line->l_next->l_a.la_np; else if (basicblock(&np->n_line->l_next)) - madeopt = TRUE; + madeopt = true; } return madeopt; } @@ -284,7 +284,7 @@ static eval_t compute(expr_p pexp) switch (nparam[pexp->ex_operator]) { default: - assert(FALSE); + assert(false); case 2: leaf2 = compute(&enodes[pexp->ex_rnode]); if (leaf2.e_typ == EV_UNDEF @@ -306,7 +306,7 @@ static eval_t compute(expr_p pexp) switch (pexp->ex_operator) { default: - assert(FALSE); + assert(false); break; case EX_CON: res.e_v.e_con = (offset) pexp->ex_lnode; @@ -544,7 +544,7 @@ static bool tryrepl(line_p *lpp, byte *bp, int patlen) oldline(lp); lp = tp; } - return (TRUE); + return (true); } static bool trypat(line_p *lpp, byte *bp, int len) @@ -563,12 +563,12 @@ static bool trypat(line_p *lpp, byte *bp, int len) if (len == 3) { if (patlen < 3) - return (FALSE); + return (false); } else { if (patlen != len) - return (FALSE); + return (false); } /* @@ -577,9 +577,9 @@ static bool trypat(line_p *lpp, byte *bp, int len) for (i = 0, lp = *lpp; i < patlen && lp != (line_p) 0; i++, lp = lp->l_next) if (lp->l_instr != *bp++) - return (FALSE); + return (false); if (i != patlen) - return (FALSE); + return (false); /* * opcodes are also correct, now comes the hard part @@ -642,7 +642,7 @@ static bool trypat(line_p *lpp, byte *bp, int len) /* there is a condition */ result = compute(&enodes[i]); if (result.e_typ != EV_CONST || result.e_v.e_con == 0) - return (FALSE); + return (false); } return (tryrepl(lpp, bp, patlen)); } @@ -659,7 +659,7 @@ static int basicblock(line_p *alpp) int count = 0; lpp = alpp; - madeopt = FALSE; + madeopt = false; while ((*lpp) != (line_p) 0 && ((*lpp)->l_instr & BMASK) != op_lab) { lp = *lpp; @@ -694,7 +694,7 @@ static int basicblock(line_p *alpp) if ((bp[PO_HASH] & BMASK) == (hash[i] >> 8)) if (trypat(lpp, &bp[PO_MATCH], i + 1)) { - madeopt = TRUE; + madeopt = true; next = lpp; i = 0; /* dirty way of double break */ break; @@ -742,7 +742,7 @@ static int basicblock(line_p *alpp) oldline(lp->l_next); oldline(lp); lpp = &e_repl->l_next; - madeopt = TRUE; + madeopt = true; } else { diff --git a/util/opt/process.c b/util/opt/process.c index 21e06918ea..9e9cdbbacd 100644 --- a/util/opt/process.c +++ b/util/opt/process.c @@ -117,7 +117,7 @@ static void symvalue(void) switch (lp->l_instr & BMASK) { default: - assert(FALSE); + assert(false); break; case ps_sym: sp = lp->l_a.la_sp; @@ -140,7 +140,7 @@ static void symvalue(void) switch (ap->a_typ) { default: - assert(FALSE); + assert(false); case ARGOFF: count = align(count, wordsize) + wordsize; break; diff --git a/util/opt/putline.c b/util/opt/putline.c index 30b506150e..ba5574464d 100644 --- a/util/opt/putline.c +++ b/util/opt/putline.c @@ -210,7 +210,7 @@ static void putargs(arg_p ap) switch (ap->a_typ) { default: - assert(FALSE); + assert(false); break; case ARGOFF: outoff(ap->a_a.a_offset); diff --git a/util/opt/reg.c b/util/opt/reg.c index 9bf3f3a9f2..0bd086c0b7 100644 --- a/util/opt/reg.c +++ b/util/opt/reg.c @@ -36,7 +36,7 @@ void regvar(arg_p ap) switch (i) { default: - assert(FALSE); + assert(false); break; case 0: case 1: @@ -59,8 +59,8 @@ int inreg(offset off) for (rp = curpro.freg; rp != (reg_p) 0; rp = rp->r_next) if (rp->r_par[0] == off) - return (TRUE); - return (FALSE); + return (true); + return (false); } void outregs(void) diff --git a/util/opt/special.c b/util/opt/special.c index 3679e00b10..3b125a4f56 100644 --- a/util/opt/special.c +++ b/util/opt/special.c @@ -12,6 +12,6 @@ bool special(line_p *lpp,byte *bp,int patlen) { - return(FALSE); + return(false); } #endif diff --git a/util/opt/tes.c b/util/opt/tes.c index a79f4fe2e5..e9bdf884a1 100644 --- a/util/opt/tes.c +++ b/util/opt/tes.c @@ -106,7 +106,7 @@ void tes_instr(line_p lnp, line_p x, line_p y) arg = SHORT(lnp); if (arg < wordsize) arg = wordsize; - argdef = TRUE; + argdef = true; } else if (IS_MINI(lnp)) { @@ -115,11 +115,11 @@ void tes_instr(line_p lnp, line_p x, line_p y) arg = wordsize; if (arg < 0 && -arg < wordsize) arg = -wordsize; - argdef = TRUE; + argdef = true; } else { - argdef = FALSE; + argdef = false; } switch (*s++) { @@ -133,7 +133,7 @@ void tes_instr(line_p lnp, line_p x, line_p y) stacktop = pointersize; break; case 'a': - if (argdef == FALSE || instr == op_ass) + if (argdef == false || instr == op_ass) { stacktop = 0; } @@ -172,7 +172,7 @@ void tes_instr(line_p lnp, line_p x, line_p y) stacktop = 0; break; default: - assert(FALSE); + assert(false); } } /*